diff options
Diffstat (limited to '')
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/face.vs | 9 | ||||
-rw-r--r-- | src/RendererSection.cpp | 73 | ||||
-rw-r--r-- | src/RendererSection.hpp | 4 | ||||
-rw-r--r-- | src/RendererSectionData.cpp | 10 | ||||
-rw-r--r-- | src/RendererSectionData.hpp | 2 |
5 files changed, 44 insertions, 54 deletions
diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs index 30ae0d7..424e215 100644 --- a/cwd/assets/altcraft/shaders/vert/face.vs +++ b/cwd/assets/altcraft/shaders/vert/face.vs @@ -1,9 +1,8 @@ #version 330 core -layout (location = 0) in vec3 position; +layout (location = 3) in vec4 position[6]; layout (location = 2) in vec2 UvCoordinates; -layout (location = 7) in vec4 Texture; -layout (location = 8) in mat4 model; +layout (location = 11) in vec4 Texture; layout (location = 12) in vec3 color; layout (location = 13) in vec2 light; layout (location = 14) in float TextureLayer; @@ -22,7 +21,6 @@ uniform mat4 projView; vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer) { float x = TextureAtlasCoords.x; float y = TextureAtlasCoords.y; -// float w = TextureAtlasCoords.z; float h = TextureAtlasCoords.w; vec2 transformed = vec2(x, 1 - y - h) + UvCoords * TextureAtlasCoords.zw; return vec3(transformed.x, transformed.y, Layer); @@ -30,8 +28,7 @@ vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer) void main() { - vec4 sourcePosition = vec4(position,1.0f); - gl_Position = projView * model * sourcePosition; + gl_Position = projView * position[gl_VertexID]; vec4 texturePos = Texture; float frameHeight = texturePos.w / TextureFrames; diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index d797771..1e0a1d0 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -7,16 +7,6 @@ #include "Renderer.hpp" #include "RendererSectionData.hpp" -const GLfloat vertices[] = { - 0, 0, 0, - 1, 0, 1, - 1, 0, 0, - - 0, 0, 0, - 0, 0, 1, - 1, 0, 1, -}; - const GLfloat uv_coords[] = { 0.0f, 0.0f, 1.0f, 1.0f, @@ -28,25 +18,18 @@ const GLfloat uv_coords[] = { }; const GLuint magicUniqueConstant = 88375; -GLuint RendererSection::VboVertices = magicUniqueConstant; GLuint RendererSection::VboUvs = magicUniqueConstant; RendererSection::RendererSection(const RendererSectionData &data) { OPTICK_EVENT(); - if (VboVertices == magicUniqueConstant) { - glGenBuffers(1, &VboVertices); + if (VboUvs == magicUniqueConstant) { glGenBuffers(1, &VboUvs); - //Cube vertices - glBindBuffer(GL_ARRAY_BUFFER, VboVertices); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - //Cube UVs glBindBuffer(GL_ARRAY_BUFFER, VboUvs); glBufferData(GL_ARRAY_BUFFER, sizeof(uv_coords), uv_coords, GL_STATIC_DRAW); - LOG(INFO) << "Created VBOs with vertices (" << VboVertices << ") and UVs (" << VboUvs - << ") for faces"; + LOG(INFO) << "Created VBOs with UVs (" << VboUvs << ") for faces"; } glGenVertexArrays(1, &Vao); @@ -56,10 +39,31 @@ RendererSection::RendererSection(const RendererSectionData &data) { glBindVertexArray(Vao); { //Cube vertices - GLuint VertAttribPos = 0; - glBindBuffer(GL_ARRAY_BUFFER, VboVertices); - glVertexAttribPointer(VertAttribPos, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr); + GLuint VertAttribPos = 3; + glBindBuffer(GL_ARRAY_BUFFER, Vbo[POSITIONS]); + glVertexAttribPointer(VertAttribPos, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), nullptr); glEnableVertexAttribArray(VertAttribPos); + glVertexAttribDivisor(VertAttribPos, 1); + + glVertexAttribPointer(VertAttribPos + 1, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), (void*)(1 * 4 * sizeof(GLfloat))); + glEnableVertexAttribArray(VertAttribPos + 1); + glVertexAttribDivisor(VertAttribPos + 1, 1); + + glVertexAttribPointer(VertAttribPos + 2, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), (void*)(2 * 4 * sizeof(GLfloat))); + glEnableVertexAttribArray(VertAttribPos + 2); + glVertexAttribDivisor(VertAttribPos + 2, 1); + + glVertexAttribPointer(VertAttribPos + 3, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), (void*)(3 * 4 * sizeof(GLfloat))); + glEnableVertexAttribArray(VertAttribPos + 3); + glVertexAttribDivisor(VertAttribPos + 3, 1); + + glVertexAttribPointer(VertAttribPos + 4, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), (void*)(4 * 4 * sizeof(GLfloat))); + glEnableVertexAttribArray(VertAttribPos + 4); + glVertexAttribDivisor(VertAttribPos + 4, 1); + + glVertexAttribPointer(VertAttribPos + 5, 4, GL_FLOAT, GL_FALSE, 6 * 4 * sizeof(GLfloat), (void*)(5 * 4 * sizeof(GLfloat))); + glEnableVertexAttribArray(VertAttribPos + 5); + glVertexAttribDivisor(VertAttribPos + 5, 1); //Cube UVs GLuint UvAttribPos = 2; @@ -68,7 +72,7 @@ RendererSection::RendererSection(const RendererSectionData &data) { glEnableVertexAttribArray(UvAttribPos); //Textures - GLuint textureAttribPos = 7; + GLuint textureAttribPos = 11; glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]); glVertexAttribPointer(textureAttribPos, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), nullptr); glEnableVertexAttribArray(textureAttribPos); @@ -91,23 +95,6 @@ RendererSection::RendererSection(const RendererSectionData &data) { glVertexAttribDivisor(framesAttribPos, 1); glCheckError(); - //Blocks models - GLuint matAttribPos = 8; - size_t sizeOfMat4 = 4 * 4 * sizeof(GLfloat); - glBindBuffer(GL_ARRAY_BUFFER, Vbo[MODELS]); - glVertexAttribPointer(matAttribPos + 0, 4, GL_FLOAT, GL_FALSE, sizeOfMat4, nullptr); - glVertexAttribPointer(matAttribPos + 1, 4, GL_FLOAT, GL_FALSE, sizeOfMat4, (void *)(1 * 4 * sizeof(GLfloat))); - glVertexAttribPointer(matAttribPos + 2, 4, GL_FLOAT, GL_FALSE, sizeOfMat4, (void *)(2 * 4 * sizeof(GLfloat))); - glVertexAttribPointer(matAttribPos + 3, 4, GL_FLOAT, GL_FALSE, sizeOfMat4, (void *)(3 * 4 * sizeof(GLfloat))); - glEnableVertexAttribArray(matAttribPos + 0); - glEnableVertexAttribArray(matAttribPos + 1); - glEnableVertexAttribArray(matAttribPos + 2); - glEnableVertexAttribArray(matAttribPos + 3); - glVertexAttribDivisor(matAttribPos + 0, 1); - glVertexAttribDivisor(matAttribPos + 1, 1); - glVertexAttribDivisor(matAttribPos + 2, 1); - glVertexAttribDivisor(matAttribPos + 3, 1); - //Color GLuint colorAttribPos = 12; glBindBuffer(GL_ARRAY_BUFFER, Vbo[COLORS]); @@ -159,7 +146,7 @@ void swap(RendererSection & lhs, RendererSection & rhs) { void RendererSection::Render(RenderState &renderState) { OPTICK_EVENT(); renderState.SetActiveVao(Vao); - glDrawArraysInstanced(GL_TRIANGLES, 0, 6, numOfFaces); + glDrawArraysInstanced(GL_TRIANGLES, 0, 6, numOfFaces); glCheckError(); } @@ -182,8 +169,8 @@ void RendererSection::UpdateData(const RendererSectionData & data) { 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); + glBindBuffer(GL_ARRAY_BUFFER, Vbo[POSITIONS]); + glBufferData(GL_ARRAY_BUFFER, data.positions.size() * sizeof(glm::vec4), data.positions.data(), GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, Vbo[COLORS]); glBufferData(GL_ARRAY_BUFFER, data.colors.size() * sizeof(glm::vec3), data.colors.data(), GL_DYNAMIC_DRAW); diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp index 29b5db1..dd01c49 100644 --- a/src/RendererSection.hpp +++ b/src/RendererSection.hpp @@ -10,7 +10,7 @@ class RendererSectionData; class RendererSection { enum Vbos { - MODELS = 0, + POSITIONS = 0, TEXTURES, LAYERS, FRAMES, @@ -21,7 +21,7 @@ class RendererSection { GLuint Vao = { 0 }; GLuint Vbo[VBOCOUNT] = { 0 }; - static GLuint VboVertices, VboUvs; + static GLuint VboUvs; size_t hash; Vector sectionPos; diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index 69ed665..cf05528 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -37,7 +37,13 @@ void AddFacesByBlockModel(RendererSectionData &data, const BlockFaces &model, co continue; lightness = glm::vec2(light.face[faceDirection], skyLight.face[faceDirection]); } - data.models.push_back(transform * model.transform * face.transform); + glm::mat4 transformed = transform * model.transform * face.transform; + data.positions.push_back(transformed * glm::vec4(0, 0, 0, 1)); + data.positions.push_back(transformed * glm::vec4(1, 0, 1, 1)); + data.positions.push_back(transformed * glm::vec4(1, 0, 0, 1)); + data.positions.push_back(transformed * glm::vec4(0, 0, 0, 1)); + data.positions.push_back(transformed * glm::vec4(0, 0, 1, 1)); + data.positions.push_back(transformed * glm::vec4(1, 0, 1, 1)); data.textures.push_back(face.texture); data.textureLayers.push_back(face.layer); data.textureFrames.push_back(face.frames); @@ -137,7 +143,7 @@ RendererSectionData ParseSection(const SectionsData §ions) { } data.textures.shrink_to_fit(); data.textureLayers.shrink_to_fit(); - data.models.shrink_to_fit(); + data.positions.shrink_to_fit(); data.colors.shrink_to_fit(); return data; diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index cedb51b..3062d0c 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -31,7 +31,7 @@ struct SectionsData { }; struct RendererSectionData { - std::vector<glm::mat4> models; + std::vector<glm::vec4> positions; std::vector<glm::vec4> textures; std::vector<float> textureLayers; std::vector<float> textureFrames; |