From 6a00886804c53883d919f008f6ec47a574d86607 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Mon, 24 Jul 2017 19:52:24 +0500 Subject: 2017-07-24 --- src/graphics/Gui.hpp | 8 +++++++ src/graphics/RenderSection.cpp | 18 +++++++-------- src/graphics/RenderSection.hpp | 52 ++++++++++++++++++++++++++++++++++++++++++ src/graphics/Shader.hpp | 24 +++++++++++++++++++ src/graphics/Texture.hpp | 14 ++++++++++++ src/graphics/Widget.hpp | 8 +++++++ 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 src/graphics/Gui.hpp create mode 100644 src/graphics/RenderSection.hpp create mode 100644 src/graphics/Shader.hpp create mode 100644 src/graphics/Texture.hpp create mode 100644 src/graphics/Widget.hpp (limited to 'src/graphics') diff --git a/src/graphics/Gui.hpp b/src/graphics/Gui.hpp new file mode 100644 index 0000000..e22a0a7 --- /dev/null +++ b/src/graphics/Gui.hpp @@ -0,0 +1,8 @@ +#pragma once + +class Gui { + +public: + int WHY=0; + +}; diff --git a/src/graphics/RenderSection.cpp b/src/graphics/RenderSection.cpp index 90d4329..ae072d6 100644 --- a/src/graphics/RenderSection.cpp +++ b/src/graphics/RenderSection.cpp @@ -138,7 +138,7 @@ RenderSection::~RenderSection() { refCounterVao[Vao]--; if (refCounterVbo[VboTextures] <= 0) glDeleteBuffers(1, &VboTextures); - + if (refCounterVbo[VboModels] <= 0) glDeleteBuffers(1, &VboTextures); if (refCounterVbo[VboColors] <= 0) @@ -297,13 +297,11 @@ void RenderSection::UpdateState(const std::map &textu } } numOfFaces = textures.size(); - hash = section.GetHash(); + hash = section.GetHash(); } void RenderSection::Render(RenderState &state) { - if (!isEnabled) { - return; - } + 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); @@ -339,7 +337,7 @@ RenderSection::RenderSection(const RenderSection &other) { this->models = other.models; this->textures = other.textures; this->colors = other.colors; - this->hash = other.hash; + this->hash = other.hash; refCounterVbo[VboTextures]++; refCounterVbo[VboModels]++; @@ -348,11 +346,11 @@ RenderSection::RenderSection(const RenderSection &other) { } void RenderSection::SetEnabled(bool isEnabled) { - this->isEnabled = isEnabled; + this->isEnabled = isEnabled; } bool RenderSection::IsNeedUpdate() { - size_t currentHash = world->GetSection(sectionPosition).GetHash(); - bool isNeedUpdate = currentHash != hash; - return 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 new file mode 100644 index 0000000..5973909 --- /dev/null +++ b/src/graphics/RenderSection.hpp @@ -0,0 +1,52 @@ +#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 new file mode 100644 index 0000000..17a434e --- /dev/null +++ b/src/graphics/Shader.hpp @@ -0,0 +1,24 @@ +#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 new file mode 100644 index 0000000..277806a --- /dev/null +++ b/src/graphics/Texture.hpp @@ -0,0 +1,14 @@ +#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 new file mode 100644 index 0000000..c4d5dc1 --- /dev/null +++ b/src/graphics/Widget.hpp @@ -0,0 +1,8 @@ +#pragma once + +class Widget { + unsigned int x,y,w,h; +public: + Widget(Widget *parent); + ~Widget(); +}; -- cgit v1.2.3