From f942405184c2d6067fb5303b58a225edf7e452b1 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 29 Jul 2017 19:55:16 +0500 Subject: 2017-07-29 --- src/graphics/Gui.hpp | 8 ------- src/graphics/RenderSection.cpp | 54 ++++++++++++++---------------------------- src/graphics/RenderSection.hpp | 52 ---------------------------------------- src/graphics/Shader.hpp | 24 ------------------- src/graphics/Texture.hpp | 14 ----------- src/graphics/Widget.hpp | 8 ------- 6 files changed, 18 insertions(+), 142 deletions(-) delete mode 100644 src/graphics/Gui.hpp delete mode 100644 src/graphics/RenderSection.hpp delete mode 100644 src/graphics/Shader.hpp delete mode 100644 src/graphics/Texture.hpp delete mode 100644 src/graphics/Widget.hpp (limited to 'src/graphics') diff --git a/src/graphics/Gui.hpp b/src/graphics/Gui.hpp deleted file mode 100644 index e22a0a7..0000000 --- a/src/graphics/Gui.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -class Gui { - -public: - int WHY=0; - -}; 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 -#include const GLfloat vertices[] = { 0, 0, 0, @@ -43,6 +42,7 @@ std::map 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 &textureAtlas) { Section §ion = world->GetSection(sectionPosition); - models.clear(); - textures.clear(); - colors.clear(); + std::vector models; + std::vector textures; + std::vector 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 &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 diff --git a/src/graphics/RenderSection.hpp b/src/graphics/RenderSection.hpp deleted file mode 100644 index 5973909..0000000 --- a/src/graphics/RenderSection.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -class RenderState { - GLuint ActiveVao; - GLuint ActiveShader; -public: - void SetActiveVao(GLuint Vao); - void SetActiveShader(GLuint Shader); -}; - -class RenderSection { - Vector sectionPosition; - World *world; - GLuint Vao, VboTextures, VboModels, VboColors; - std::vector models; - std::vector textures; - std::vector colors; - - static GLuint VboVertices, VboUvs; - static std::map refCounterVbo; - static std::map refCounterVao; - - size_t numOfFaces = 0; - - bool isEnabled = true; - - size_t hash = 0; -public: - RenderSection(World *world, Vector position); - RenderSection(const RenderSection &other); - ~RenderSection(); - - void UpdateState(const std::map &textureAtlas); - void Render(RenderState &state); - - void SetEnabled(bool isEnabled); - - Section *GetSection(); - - bool IsNeedUpdate(); -}; \ No newline at end of file diff --git a/src/graphics/Shader.hpp b/src/graphics/Shader.hpp deleted file mode 100644 index 17a434e..0000000 --- a/src/graphics/Shader.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include - -class Shader -{ -private: - const GLchar *vertex; - const GLchar *fragment; -public: - // Идентификатор программы - GLuint Program; - // Конструктор считывает и собирает шейдер - Shader(const GLchar* vertexPath, const GLchar* fragmentPath, const GLchar* geometryPath = nullptr); - // Использование программы - void Use(); - - void Reload(); -}; \ No newline at end of file diff --git a/src/graphics/Texture.hpp b/src/graphics/Texture.hpp deleted file mode 100644 index 5b2afcf..0000000 --- a/src/graphics/Texture.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include -#include - -class Texture { - Texture(Texture&); - Texture&operator=(Texture&); -public: - GLuint texture; - Texture(std::string filename, GLenum textureWrapping = GL_CLAMP_TO_BORDER, GLenum textureFiltering = GL_NEAREST); - ~Texture(); -}; \ No newline at end of file diff --git a/src/graphics/Widget.hpp b/src/graphics/Widget.hpp deleted file mode 100644 index c4d5dc1..0000000 --- a/src/graphics/Widget.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -class Widget { - unsigned int x,y,w,h; -public: - Widget(Widget *parent); - ~Widget(); -}; -- cgit v1.2.3