summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/graphics/Shader.hpp (renamed from src/graphics/Shader.hpp)0
-rw-r--r--include/graphics/Widget.hpp (renamed from src/graphics/Widget.hpp)0
-rw-r--r--old/graphics/Gui.hpp (renamed from src/graphics/Gui.hpp)0
-rw-r--r--old/graphics/RenderSection.hpp (renamed from src/graphics/RenderSection.hpp)6
-rw-r--r--old/graphics/Texture.hpp (renamed from src/graphics/Texture.hpp)0
-rw-r--r--src/graphics/RenderSection.cpp54
6 files changed, 21 insertions, 39 deletions
diff --git a/src/graphics/Shader.hpp b/include/graphics/Shader.hpp
index 17a434e..17a434e 100644
--- a/src/graphics/Shader.hpp
+++ b/include/graphics/Shader.hpp
diff --git a/src/graphics/Widget.hpp b/include/graphics/Widget.hpp
index c4d5dc1..c4d5dc1 100644
--- a/src/graphics/Widget.hpp
+++ b/include/graphics/Widget.hpp
diff --git a/src/graphics/Gui.hpp b/old/graphics/Gui.hpp
index e22a0a7..e22a0a7 100644
--- a/src/graphics/Gui.hpp
+++ b/old/graphics/Gui.hpp
diff --git a/src/graphics/RenderSection.hpp b/old/graphics/RenderSection.hpp
index 5973909..7f97624 100644
--- a/src/graphics/RenderSection.hpp
+++ b/old/graphics/RenderSection.hpp
@@ -7,9 +7,9 @@
#include <glm/gtx/transform.hpp>
#include <easylogging++.h>
-#include <core/AssetManager.hpp>
-#include <world/Section.hpp>
-#include <world/World.hpp>
+#include "../core/AssetManager.hpp"
+#include "../world/Section.hpp"
+#include "../world/World.hpp"
class RenderState {
GLuint ActiveVao;
diff --git a/src/graphics/Texture.hpp b/old/graphics/Texture.hpp
index 5b2afcf..5b2afcf 100644
--- a/src/graphics/Texture.hpp
+++ b/old/graphics/Texture.hpp
diff --git a/src/graphics/RenderSection.cpp b/src/graphics/RenderSection.cpp
index ae072d6..b07759a 100644
--- a/src/graphics/RenderSection.cpp
+++ b/src/graphics/RenderSection.cpp
@@ -1,5 +1,4 @@
#include <graphics/RenderSection.hpp>
-#include <thread>
const GLfloat vertices[] = {
0, 0, 0,
@@ -43,6 +42,7 @@ std::map<GLuint, int> RenderSection::refCounterVao;
RenderSection::RenderSection(World *world, Vector position) : sectionPosition(position), world(world) {
+
if (VboVertices == magicUniqueConstant) {
glGenBuffers(1, &VboVertices);
glGenBuffers(1, &VboUvs);
@@ -138,7 +138,6 @@ RenderSection::~RenderSection() {
refCounterVao[Vao]--;
if (refCounterVbo[VboTextures] <= 0)
glDeleteBuffers(1, &VboTextures);
-
if (refCounterVbo[VboModels] <= 0)
glDeleteBuffers(1, &VboTextures);
if (refCounterVbo[VboColors] <= 0)
@@ -150,9 +149,9 @@ RenderSection::~RenderSection() {
void RenderSection::UpdateState(const std::map<BlockTextureId, glm::vec4> &textureAtlas) {
Section &section = world->GetSection(sectionPosition);
- models.clear();
- textures.clear();
- colors.clear();
+ std::vector<glm::mat4> models;
+ std::vector<glm::vec4> textures;
+ std::vector<glm::vec3> colors;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
@@ -296,27 +295,24 @@ void RenderSection::UpdateState(const std::map<BlockTextureId, glm::vec4> &textu
}
}
}
- numOfFaces = textures.size();
- hash = section.GetHash();
-}
-void RenderSection::Render(RenderState &state) {
- if (!isEnabled) return;
- if (!models.empty()) {
- glBindBuffer(GL_ARRAY_BUFFER, VboTextures);
- glBufferData(GL_ARRAY_BUFFER, textures.size() * sizeof(glm::vec4), textures.data(), GL_DYNAMIC_DRAW);
- textures.clear();
+ glBindBuffer(GL_ARRAY_BUFFER, VboTextures);
+ glBufferData(GL_ARRAY_BUFFER, textures.size() * sizeof(glm::vec4), textures.data(), GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, VboModels);
- glBufferData(GL_ARRAY_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_DYNAMIC_DRAW);
- models.clear();
+ glBindBuffer(GL_ARRAY_BUFFER, VboModels);
+ glBufferData(GL_ARRAY_BUFFER, models.size() * sizeof(glm::mat4), models.data(), GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, VboColors);
- glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec3), colors.data(), GL_DYNAMIC_DRAW);
- colors.clear();
+ glBindBuffer(GL_ARRAY_BUFFER, VboColors);
+ glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec3), colors.data(), GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ glCheckError();
+
+ numOfFaces = textures.size();
+}
+
+void RenderSection::Render(RenderState &state) {
state.SetActiveVao(Vao);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, numOfFaces);
glCheckError();
@@ -334,23 +330,9 @@ RenderSection::RenderSection(const RenderSection &other) {
this->sectionPosition = other.sectionPosition;
this->Vao = other.Vao;
this->numOfFaces = other.numOfFaces;
- this->models = other.models;
- this->textures = other.textures;
- this->colors = other.colors;
- this->hash = other.hash;
refCounterVbo[VboTextures]++;
refCounterVbo[VboModels]++;
refCounterVbo[VboColors]++;
refCounterVao[Vao]++;
}
-
-void RenderSection::SetEnabled(bool isEnabled) {
- this->isEnabled = isEnabled;
-}
-
-bool RenderSection::IsNeedUpdate() {
- size_t currentHash = world->GetSection(sectionPosition).GetHash();
- bool isNeedUpdate = currentHash != hash;
- return isNeedUpdate;
-} \ No newline at end of file