summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-06-27 18:31:00 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-27 18:31:00 +0200
commit5a6aaf633ce217f828d981cd8c55951ada67e2df (patch)
tree4719852bbba79f005a95be8d632a32200abcf142 /src
parentMerge pull request #63 from LaG1924/ftr/cmake-minor-improvements (diff)
downloadAltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar.gz
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar.bz2
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar.lz
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar.xz
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.tar.zst
AltCraft-5a6aaf633ce217f828d981cd8c55951ada67e2df.zip
Diffstat (limited to 'src')
-rw-r--r--src/RendererSection.cpp73
-rw-r--r--src/RendererSection.hpp4
-rw-r--r--src/RendererSectionData.cpp10
-rw-r--r--src/RendererSectionData.hpp2
4 files changed, 41 insertions, 48 deletions
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 &sections) {
}
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;