summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-17 16:53:05 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-17 16:53:05 +0100
commitc9200dfbece69507e7a9a22af5a73d3f010bc14f (patch)
tree2db8f6cafb3a877aa502037ca48e39b2c0ce3428
parentNew lock-free RendererSectionData parsing (diff)
downloadAltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar.gz
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar.bz2
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar.lz
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar.xz
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.tar.zst
AltCraft-c9200dfbece69507e7a9a22af5a73d3f010bc14f.zip
Diffstat (limited to '')
-rw-r--r--src/RendererSection.cpp45
-rw-r--r--src/RendererSection.hpp2
-rw-r--r--src/RendererWorld.cpp20
3 files changed, 35 insertions, 32 deletions
diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp
index 0311171..21c2714 100644
--- a/src/RendererSection.cpp
+++ b/src/RendererSection.cpp
@@ -108,26 +108,8 @@ RendererSection::RendererSection(const RendererSectionData &data) {
}
glBindVertexArray(0);
glCheckError();
-
-
- //Upload data to VRAM
- glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]);
- glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.data(), GL_DYNAMIC_DRAW);
-
- glBindBuffer(GL_ARRAY_BUFFER, Vbo[MODELS]);
- glBufferData(GL_ARRAY_BUFFER, data.models.size() * sizeof(glm::mat4), data.models.data(), GL_DYNAMIC_DRAW);
-
- glBindBuffer(GL_ARRAY_BUFFER, Vbo[COLORS]);
- glBufferData(GL_ARRAY_BUFFER, data.colors.size() * sizeof(glm::vec3), data.colors.data(), GL_DYNAMIC_DRAW);
-
- glBindBuffer(GL_ARRAY_BUFFER, Vbo[LIGHTS]);
- glBufferData(GL_ARRAY_BUFFER, data.lights.size() * sizeof(glm::vec2), data.lights.data(), GL_DYNAMIC_DRAW);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- numOfFaces = data.textures.size();
- sectionPos = data.sectionPos;
- hash = data.hash;
+
+ UpdateData(data);
}
RendererSection::RendererSection(RendererSection && other) {
@@ -168,4 +150,25 @@ Vector RendererSection::GetPosition() {
size_t RendererSection::GetHash() {
return hash;
-} \ No newline at end of file
+}
+
+void RendererSection::UpdateData(const RendererSectionData & data) {
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]);
+ glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.data(), GL_DYNAMIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[MODELS]);
+ glBufferData(GL_ARRAY_BUFFER, data.models.size() * sizeof(glm::mat4), data.models.data(), GL_DYNAMIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[COLORS]);
+ glBufferData(GL_ARRAY_BUFFER, data.colors.size() * sizeof(glm::vec3), data.colors.data(), GL_DYNAMIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[LIGHTS]);
+ glBufferData(GL_ARRAY_BUFFER, data.lights.size() * sizeof(glm::vec2), data.lights.data(), GL_DYNAMIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glCheckError();
+
+ numOfFaces = data.textures.size();
+ sectionPos = data.sectionPos;
+ hash = data.hash;
+}
diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp
index c9137ce..f172a12 100644
--- a/src/RendererSection.hpp
+++ b/src/RendererSection.hpp
@@ -41,4 +41,6 @@ public:
size_t numOfFaces;
friend void swap(RendererSection &lhs, RendererSection &rhs);
+
+ void UpdateData(const RendererSectionData &data);
}; \ No newline at end of file
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index 6349573..628680c 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -170,17 +170,15 @@ RendererWorld::RendererWorld(GameState* ptr) {
auto it = sections.find(parsing[id].renderer.sectionPos);
- if (it != sections.end() && parsing[id].renderer.hash == it->second.GetHash() && !parsing[id].renderer.forced) {
- LOG(WARNING) << "Generated not necessary RendererSectionData: " << parsing[id].renderer.sectionPos;
- return;
- }
-
- if (it != sections.end())
- sections.erase(it);
-
- const RendererSectionData &data = parsing[id].renderer;
-
- sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(data)));
+ if (it != sections.end()) {
+ if (parsing[id].renderer.hash == it->second.GetHash() && !parsing[id].renderer.forced) {
+ LOG(WARNING) << "Generated not necessary RendererSectionData: " << parsing[id].renderer.sectionPos;
+ parsing[id] = RendererWorld::SectionParsing();
+ return;
+ }
+ it->second.UpdateData(parsing[id].renderer);
+ } else
+ sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(parsing[id].renderer)));
parsing[id] = RendererWorld::SectionParsing();
});