From b57a26a7112d19fdee27c99028092463e550119c Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 27 Jan 2019 18:57:47 +0500 Subject: More advanced textures animation support --- src/AssetManager.cpp | 2 +- src/AssetManager.hpp | 3 ++- src/RendererSection.cpp | 11 +++++++++++ src/RendererSection.hpp | 1 + src/RendererSectionData.cpp | 1 + src/RendererSectionData.hpp | 1 + src/RendererWorld.cpp | 5 +++++ src/RendererWorld.hpp | 1 + 8 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 9fd49bb..71800d7 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -508,7 +508,6 @@ void ParseBlockModels() { AssetTexture *assetTexture = AssetManager::GetAsset(textureName); texture = atlas->GetTexture(assetTexture->id); textureFrames = assetTexture->frames; - texture.h /= textureFrames; if (!(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,16,0,16 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,0,0 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,16,16 })) { @@ -533,6 +532,7 @@ void ParseBlockModels() { } parsedFace.texture = glm::vec4{ texture.x,texture.y,texture.w,texture.h }; parsedFace.layer = texture.layer; + parsedFace.frames = textureFrames; if (face.second.tintIndex) parsedFace.color = glm::vec3(0.275, 0.63, 0.1); else diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 6c5cb49..de3881e 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -41,7 +41,8 @@ struct ParsedFace { glm::mat4 transform; glm::vec4 texture; float layer; - glm::vec3 color; + float frames; + glm::vec3 color; }; struct BlockFaces { diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index bbf24ff..1521c6f 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -81,6 +81,14 @@ RendererSection::RendererSection(const RendererSectionData &data) { glVertexAttribDivisor(layerAttribPos, 1); glCheckError(); + //TextureFrames + GLuint framesAttribPos = 15; + glBindBuffer(GL_ARRAY_BUFFER, Vbo[FRAMES]); + glVertexAttribPointer(framesAttribPos, 1, GL_FLOAT, GL_FALSE, sizeof(GLfloat), nullptr); + glEnableVertexAttribArray(framesAttribPos); + glVertexAttribDivisor(framesAttribPos, 1); + glCheckError(); + //Blocks models GLuint matAttribPos = 8; size_t sizeOfMat4 = 4 * 4 * sizeof(GLfloat); @@ -167,6 +175,9 @@ void RendererSection::UpdateData(const RendererSectionData & data) { glBindBuffer(GL_ARRAY_BUFFER, Vbo[LAYERS]); glBufferData(GL_ARRAY_BUFFER, data.textureLayers.size() * 1* sizeof(GLfloat), data.textureLayers.data(), GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, Vbo[FRAMES]); + glBufferData(GL_ARRAY_BUFFER, data.textureFrames.size() * 1 * sizeof(GLfloat), data.textureFrames.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); diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp index c760678..29b5db1 100644 --- a/src/RendererSection.hpp +++ b/src/RendererSection.hpp @@ -13,6 +13,7 @@ class RendererSection { MODELS = 0, TEXTURES, LAYERS, + FRAMES, COLORS, LIGHTS, VBOCOUNT, diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index e72a369..3b51809 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -39,6 +39,7 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co data.models.push_back(transform * model.transform * face.transform); data.textures.push_back(face.texture); data.textureLayers.push_back(face.layer); + data.textureFrames.push_back(face.frames); data.lights.push_back(lightness); data.colors.push_back(face.color); } diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index 7153b05..cedb51b 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -34,6 +34,7 @@ struct RendererSectionData { std::vector models; std::vector textures; std::vector textureLayers; + std::vector textureFrames; std::vector colors; std::vector lights; size_t hash = 0; diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index e0a28a4..7f7c850 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -153,6 +153,8 @@ RendererWorld::RendererWorld(std::shared_ptr ptr) { listener = std::make_unique(); + globalTimeStart = std::chrono::high_resolution_clock::now(); + PrepareRender(); listener->RegisterHandler("DeleteSectionRender", [this](const Event& eventData) { @@ -377,10 +379,13 @@ void RendererWorld::Render(RenderState & renderState) { glCheckError(); //Render sections + auto rawGlobalTime = (std::chrono::high_resolution_clock::now() - globalTimeStart); + float globalTime = rawGlobalTime.count() / 1000000000.0f; Shader *blockShader = AssetManager::GetAsset("/altcraft/shaders/face")->shader.get(); blockShader->Activate(); blockShader->SetUniform("DayTime", mixLevel); blockShader->SetUniform("projView", projView); + blockShader->SetUniform("GlobalTime", globalTime); glCheckError(); Frustum frustum(projView); diff --git a/src/RendererWorld.hpp b/src/RendererWorld.hpp index 5148964..913e510 100644 --- a/src/RendererWorld.hpp +++ b/src/RendererWorld.hpp @@ -44,6 +44,7 @@ class RendererWorld { std::vector renderList; std::map sections; void UpdateAllSections(VectorF playerPos); + std::chrono::time_point globalTimeStart; //Entities std::vector entities; //Sky -- cgit v1.2.3