summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 14:57:47 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-27 15:06:37 +0100
commitb57a26a7112d19fdee27c99028092463e550119c (patch)
tree132863eab01c9f22727bc9057da4d1bf3eb4015d /src
parentBasic animated textures support (diff)
downloadAltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar.gz
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar.bz2
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar.lz
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar.xz
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.tar.zst
AltCraft-b57a26a7112d19fdee27c99028092463e550119c.zip
Diffstat (limited to 'src')
-rw-r--r--src/AssetManager.cpp2
-rw-r--r--src/AssetManager.hpp3
-rw-r--r--src/RendererSection.cpp11
-rw-r--r--src/RendererSection.hpp1
-rw-r--r--src/RendererSectionData.cpp1
-rw-r--r--src/RendererSectionData.hpp1
-rw-r--r--src/RendererWorld.cpp5
-rw-r--r--src/RendererWorld.hpp1
8 files changed, 23 insertions, 2 deletions
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<AssetTexture>(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<glm::mat4> models;
std::vector<glm::vec4> textures;
std::vector<float> textureLayers;
+ std::vector<float> textureFrames;
std::vector<glm::vec3> colors;
std::vector<glm::vec2> 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<GameState> ptr) {
listener = std::make_unique<EventListener>();
+ 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<AssetShader>("/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<Vector> renderList;
std::map<Vector, RendererSection> sections;
void UpdateAllSections(VectorF playerPos);
+ std::chrono::time_point<std::chrono::high_resolution_clock> globalTimeStart;
//Entities
std::vector<RendererEntity> entities;
//Sky