summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cwd/shaders/block.fs179
-rw-r--r--cwd/shaders/block.gs32
-rw-r--r--cwd/shaders/block.vs31
-rw-r--r--cwd/shaders/face.fs9
-rw-r--r--cwd/shaders/face.vs11
-rw-r--r--cwd/shaders/gui.fs21
-rw-r--r--cwd/shaders/gui.vs27
-rw-r--r--cwd/shaders/simple.fs7
-rw-r--r--cwd/shaders/simple.vs9
-rw-r--r--src/RendererSection.cpp178
-rw-r--r--src/RendererSection.hpp7
-rw-r--r--src/Shader.cpp4
-rw-r--r--src/World.cpp2
13 files changed, 121 insertions, 396 deletions
diff --git a/cwd/shaders/block.fs b/cwd/shaders/block.fs
deleted file mode 100644
index 15fd217..0000000
--- a/cwd/shaders/block.fs
+++ /dev/null
@@ -1,179 +0,0 @@
-#version 330 core
-
-in VS_OUT {
- vec2 UvPosition;
- vec3 FragmentPosition;
- flat int Block;
- flat int State;
- vec4 ndcPos;
-} fs_in;
-
-uniform sampler2D textureAtlas;
-uniform float time;
-uniform int isInside;
-uniform vec2 windowSize;
-
-// TextureIndex: [most significant bit]<-...<-side[3bit]<-id[13]<-state[4]
-layout(std140) uniform TextureIndexes { // binding point: 0
- int totalTextures;
- int indexes[1023];
-};
-layout(std140) uniform TextureData { // binding point: 1
- vec4 textureData[1024];
-};
-
-vec4 GetTextureByBlockId();
-vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords);
-vec4 CheckIndexValidness();
-vec4 GetDepthColor();
-vec4 GetCheckerColor();
-vec4 VTC(int value);
-
-int GetBlockSide(){
- int side=6;
- if (fs_in.FragmentPosition.y==-0.5)
- side=0;
- else if (fs_in.FragmentPosition.y==0.5)
- side=1;
- else if (fs_in.FragmentPosition.x==-0.5)
- side = 3;
- else if (fs_in.FragmentPosition.x==0.5)
- side = 2;
- else if (fs_in.FragmentPosition.z==-0.5)
- side=4;
- else if (fs_in.FragmentPosition.z==0.5)
- side=5;
- return side;
-}
-int index,side,id,state;
-
-vec3 rgb2hsv(vec3 c)
-{
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
- vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
- vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
-
- float d = q.x - min(q.w, q.y);
- float e = 1.0e-10;
- return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
-}
-
-vec3 hsv2rgb(vec3 c)
-{
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
- vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
- return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
-}
-
-
-void main() {
- vec4 BlockTextureCoords = GetTextureByBlockId();
- vec2 AtlasCoords = TransformTextureCoord(BlockTextureCoords, fs_in.UvPosition);
- gl_FragColor = texture(textureAtlas, AtlasCoords);
- if (gl_FragColor.a<0.1) discard;
- if (fs_in.Block==2 && side==1 || fs_in.Block==18 || fs_in.Block==31 && state==1 || fs_in.Block==31 && state==2) { //Grass and leaves colorizing
- const float BiomeColor = 0.275;
- vec3 hsvColor = rgb2hsv(gl_FragColor.xyz);
- hsvColor[0]+=BiomeColor;
- hsvColor[1]=0.63;
- hsvColor[2]+=0.1;
- gl_FragColor = vec4(hsv2rgb(hsvColor),1);
- }
-}
-
-vec4 GetTextureByBlockId() {
- int BlockSide = GetBlockSide();
- for (int i = 0; i < totalTextures; i++) {
- index = indexes[i];
- side = (index & 0x70000) >> 16;
- id = (index & 0xFF0) >> 4;
- state = index & 0xF;
-
- if (id != fs_in.Block)
- continue;
- if (state != fs_in.State)
- continue;
- if (side == 6)
- return textureData[i];
- if (BlockSide == side)
- return textureData[i];
- if (side == 6)
- return textureData[i];
- else if (side == BlockSide)
- return textureData[i];
- }
- // Fallback TNT texture
- return vec4(0.0546875, 0.00442477876106194690, 0.0078125,
- 0.00442477876106194690);
-}
-
-vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords) {
- float x = TextureAtlasCoords.x;
- float y = TextureAtlasCoords.y;
- float w = TextureAtlasCoords.z;
- float h = TextureAtlasCoords.w;
- vec2 A = vec2(x, y);
- vec2 B = vec2(x + w, y + h);
-
- const bool isTextureFlippedVertically = true;
- if (isTextureFlippedVertically) {
- y = 1 - y;
- A = vec2(x, y - h);
- B = vec2(x + w, y);
- }
- return A + UvCoords * (B - A);
-}
-
-vec4 CheckIndexValidness() {
- vec4 color = vec4(0, 1, 0, 1);
- if (totalTextures != 6)
- return vec4(1, 0, 0, 1);
- if (indexes[0] != 393248)
- return vec4(1, 1, 0, 1);
- for (int i = 1; i < 20; i++)
- if (indexes[i] != 0)
- return vec4(0, 0, 1, 1);
- return vec4(0, 1, 0, 1);
-}
-
-float near = 1.0;
-float far = 100.0;
-
-float LinearizeDepth(float depth) {
- float z = depth * 2.0 - 1.0; // Back to NDC
- return (2.0 * near * far) / (far + near - z * (far - near));
-}
-
-vec4 GetDepthColor() {
- float depth =
- LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration
- return vec4(vec3(depth), 1.0f);
-}
-
-vec4 GetCheckerColor() {
- if (fs_in.UvPosition.x>0.5 && fs_in.UvPosition.y<0.5 || fs_in.UvPosition.x<0.5 && fs_in.UvPosition.y>0.5)
- return vec4(0.7,0.7,0,1);
- else
- return vec4(0,0,0,1);
-}
-
-vec4 VTC(int value){
- switch(value)
- {
- case 0:
- return vec4(0,0,0,1);
- case 1:
- return vec4(1,0,0,1);
- case 2:
- return vec4(0,1,0,1);
- case 3:
- return vec4(0,0,1,1);
- case 4:
- return vec4(1,1,0,1);
- case 5:
- return vec4(1,0,1,1);
- case 6:
- return vec4(0,1,1,1);
- }
- return vec4(1,1,1,1);
-}
diff --git a/cwd/shaders/block.gs b/cwd/shaders/block.gs
deleted file mode 100644
index 17d61c3..0000000
--- a/cwd/shaders/block.gs
+++ /dev/null
@@ -1,32 +0,0 @@
-#version 330 core
-
-in gl_Vertex
-{
- vec4 gl_Position;
- float gl_PointSize;
- float gl_ClipDistance[];
-} gl_in[];
-
-in VS_OUT {
- vec2 UvPosition;
- vec3 FragmentPosition;
- flat int Block;
- flat int State;
- vec4 ndcPos;
-} gs_in[];
-
-out GS_OUT {
- vec2 UvPosition;
- vec3 FragmentPosition;
- flat int Block;
- flat int State;
- vec4 ndcPos;
-} gs_out[];
-
-void main() {
- gs_out[0].UvPosition = gs_in[0].UvPosition;
- gs_out[0].FragmentPosition = gs_in[0].FragmentPosition;
- gs_out[0].Block = gs_in[0].Block;
- gs_out[0].State = gs_in[0].State;
- gs_out[0].ndcPos = gs_in[0].ndcPos;
-} \ No newline at end of file
diff --git a/cwd/shaders/block.vs b/cwd/shaders/block.vs
deleted file mode 100644
index 457d5dd..0000000
--- a/cwd/shaders/block.vs
+++ /dev/null
@@ -1,31 +0,0 @@
-#version 330 core
-layout (location = 0) in vec3 position;
-layout (location = 2) in vec2 UvCoordinates;
-layout (location = 7) in vec2 BlockId;
-layout (location = 8) in mat4 model;
-//layout (location = 12) in something....
-
-out VS_OUT {
- vec2 UvPosition;
- vec3 FragmentPosition;
- flat int Block;
- flat int State;
- vec4 ndcPos;
-} vs_out;
-
-uniform mat4 view;
-uniform mat4 projection;
-uniform float time;
-
-void main()
-{
- vs_out.UvPosition = vec2(UvCoordinates.x,UvCoordinates.y);
- vs_out.FragmentPosition = position;
- vs_out.Block = int(BlockId.x);
- vs_out.State = int(BlockId.y);
-
- vec4 sourcePosition = vec4(position,1.0f);
- vs_out.ndcPos = (projection*view*model) * sourcePosition;
- gl_Position = projection * view * model * sourcePosition;
-
-}
diff --git a/cwd/shaders/face.fs b/cwd/shaders/face.fs
index aa45997..ae2eb56 100644
--- a/cwd/shaders/face.fs
+++ b/cwd/shaders/face.fs
@@ -2,9 +2,10 @@
in VS_OUT {
vec2 UvPosition;
- vec4 Texture;
- vec3 Color;
- vec2 Light;
+ flat vec4 Texture;
+ flat vec3 Color;
+ flat vec2 Light;
+ flat int Face;
} fs_in;
uniform sampler2D textureAtlas;
@@ -47,4 +48,4 @@ void main() {
gl_FragColor = vec4(hsv2rgb(hsvColor),1);
//float faceLight = clamp((fs_in.Light.x + fs_in.Light.y) / 15.0,0.2,1.0);
//gl_FragColor = vec4(gl_FragColor.rgb * faceLight,gl_FragColor.a);
-} \ No newline at end of file
+}
diff --git a/cwd/shaders/face.vs b/cwd/shaders/face.vs
index 9bf2639..4cf4e75 100644
--- a/cwd/shaders/face.vs
+++ b/cwd/shaders/face.vs
@@ -2,15 +2,15 @@
layout (location = 0) in vec3 position;
layout (location = 2) in vec2 UvCoordinates;
layout (location = 7) in vec4 Texture;
-layout (location = 8) in mat4 model;
layout (location = 12) in vec3 color;
layout (location = 13) in vec2 light;
out VS_OUT {
vec2 UvPosition;
- vec4 Texture;
- vec3 Color;
- vec2 Light;
+ flat vec4 Texture;
+ flat vec3 Color;
+ flat vec2 Light;
+ flat int Face;
} vs_out;
uniform mat4 view;
@@ -19,10 +19,11 @@ uniform mat4 projection;
void main()
{
vec4 sourcePosition = vec4(position,1.0f);
- gl_Position = projection * view * model * sourcePosition;
+ gl_Position = projection * view * sourcePosition;
vs_out.UvPosition = vec2(UvCoordinates.x,UvCoordinates.y);
vs_out.Texture = Texture;
vs_out.Color = color;
vs_out.Light = light;
+ vs_out.Face = gl_VertexID / 6;
}
diff --git a/cwd/shaders/gui.fs b/cwd/shaders/gui.fs
deleted file mode 100644
index 95196b9..0000000
--- a/cwd/shaders/gui.fs
+++ /dev/null
@@ -1,21 +0,0 @@
-#version 330 core
-
-in vec2 uv;
-
-uniform vec4 widgetTexture;
-uniform sampler2D textureAtlas;
-
-vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords) {
- float x = TextureAtlasCoords.x;
- float y = TextureAtlasCoords.y;
- float w = TextureAtlasCoords.z;
- float h = TextureAtlasCoords.w;
- vec2 A = vec2(x, 1 - y - h);
- vec2 B = vec2(x + w, 1 - y);
- return A + UvCoords * (B - A);
-}
-
-void main(){
- vec4 color = texture(textureAtlas,TransformTextureCoord(widgetTexture,uv));
- gl_FragColor = color;
-} \ No newline at end of file
diff --git a/cwd/shaders/gui.vs b/cwd/shaders/gui.vs
deleted file mode 100644
index b6f848b..0000000
--- a/cwd/shaders/gui.vs
+++ /dev/null
@@ -1,27 +0,0 @@
-#version 330 core
-
-uniform vec4 transform;
-
-layout (location = 0) in vec3 position;
-layout (location = 1) in vec2 UvCoordinates;
-
-out vec2 uv;
-
-vec2 TransfromWidgetCoord() {
- vec2 origin = vec2((transform.x * 2.0f) - 1.0f, (0.5 - transform.y) * 2.0f);
-
- float x = transform.x;
- float y = transform.y;
- float w = transform.z;
- float h = transform.w;
- vec2 A = vec2(x, 1 - y - h);
- vec2 B = vec2(x + w, 1 - y);
- vec2 ret = vec2(A + position.xy * (B - A));
- return vec2(ret.x-1.0f,ret.y);
-}
-
-void main(){
- uv = UvCoordinates;
-
- gl_Position = vec4(TransfromWidgetCoord(),0,1);
-} \ No newline at end of file
diff --git a/cwd/shaders/simple.fs b/cwd/shaders/simple.fs
deleted file mode 100644
index 34cc192..0000000
--- a/cwd/shaders/simple.fs
+++ /dev/null
@@ -1,7 +0,0 @@
-#version 330 core
-
-uniform vec3 color;
-
-void main(){
- gl_FragColor = vec4(color,1);
-} \ No newline at end of file
diff --git a/cwd/shaders/simple.vs b/cwd/shaders/simple.vs
deleted file mode 100644
index 8c9f37f..0000000
--- a/cwd/shaders/simple.vs
+++ /dev/null
@@ -1,9 +0,0 @@
-#version 330 core
-
-uniform mat4 view;
-uniform mat4 projection;
-layout (location = 0) in vec3 position;
-
-void main(){
- gl_Position = vec4(position,1);//projection*view*vec4(position,1);
-} \ No newline at end of file
diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp
index 8262cef..b02f044 100644
--- a/src/RendererSection.cpp
+++ b/src/RendererSection.cpp
@@ -2,47 +2,7 @@
#include <thread>
-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,
- 0.0f, 1.0f,
-
- 0.0f, 0.0f,
- 1.0f, 0.0f,
- 1.0f, 1.0f,
-};
-
-const GLuint magicUniqueConstant = 88375;
-GLuint RendererSection::VboVertices = magicUniqueConstant;
-GLuint RendererSection::VboUvs = magicUniqueConstant;
-
RendererSection::RendererSection(RendererSectionData data) {
- if (VboVertices == magicUniqueConstant) {
- glGenBuffers(1, &VboVertices);
- 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";
- }
-
glGenVertexArrays(1, &Vao);
glGenBuffers(VBOCOUNT, Vbo);
@@ -51,13 +11,13 @@ RendererSection::RendererSection(RendererSectionData data) {
{
//Cube vertices
GLuint VertAttribPos = 0;
- glBindBuffer(GL_ARRAY_BUFFER, VboVertices);
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[VERTICES]);
glVertexAttribPointer(VertAttribPos, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(VertAttribPos);
//Cube UVs
GLuint UvAttribPos = 2;
- glBindBuffer(GL_ARRAY_BUFFER, VboUvs);
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[UV]);
glVertexAttribPointer(UvAttribPos, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(UvAttribPos);
@@ -66,39 +26,19 @@ RendererSection::RendererSection(RendererSectionData data) {
glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]);
glVertexAttribPointer(textureAttribPos, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(textureAttribPos);
- glVertexAttribDivisor(textureAttribPos, 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]);
glVertexAttribPointer(colorAttribPos, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(colorAttribPos);
- glVertexAttribDivisor(colorAttribPos, 1);
//Light
GLuint lightAttribPos = 13;
glBindBuffer(GL_ARRAY_BUFFER, Vbo[LIGHTS]);
glVertexAttribPointer(lightAttribPos, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(lightAttribPos);
- glVertexAttribDivisor(lightAttribPos, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
@@ -107,11 +47,14 @@ RendererSection::RendererSection(RendererSectionData data) {
//Upload data to VRAM
- glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]);
- glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.data(), GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[VERTICES]);
+ glBufferData(GL_ARRAY_BUFFER, data.vertices.size() * sizeof(glm::vec3), data.vertices.data(), GL_DYNAMIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, Vbo[UV]);
+ glBufferData(GL_ARRAY_BUFFER, data.uv.size() * sizeof(glm::vec2), data.uv.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[TEXTURES]);
+ glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.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);
@@ -119,11 +62,11 @@ RendererSection::RendererSection(RendererSectionData data) {
glBindBuffer(GL_ARRAY_BUFFER, Vbo[LIGHTS]);
glBufferData(GL_ARRAY_BUFFER, data.lights.size() * sizeof(glm::vec2), data.lights.data(), GL_DYNAMIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+glBindBuffer(GL_ARRAY_BUFFER, 0);
- numOfFaces = data.textures.size();
- sectionPos = data.sectionPos;
- hash = data.hash;
+numOfFaces = data.textures.size();
+sectionPos = data.sectionPos;
+hash = data.hash;
}
RendererSection::RendererSection(RendererSection && other) {
@@ -134,7 +77,7 @@ RendererSection::RendererSection(RendererSection && other) {
RendererSection::~RendererSection() {
if (Vao != 0)
glDeleteVertexArrays(1, &Vao);
-
+
for (int i = 0; i < VBOCOUNT; i++)
if (Vbo[i] != 0) {
glBindBuffer(GL_ARRAY_BUFFER, Vbo[i]);
@@ -153,9 +96,9 @@ void swap(RendererSection & lhs, RendererSection & rhs) {
}
void RendererSection::Render(RenderState &renderState) {
- renderState.SetActiveVao(Vao);
- glDrawArraysInstanced(GL_TRIANGLES, 0, 6, numOfFaces);
- glCheckError();
+ renderState.SetActiveVao(Vao);
+ glDrawArrays(GL_TRIANGLES, 0, numOfFaces);
+ glCheckError();
}
Vector RendererSection::GetPosition()
@@ -168,13 +111,13 @@ size_t RendererSection::GetHash()
return hash;
}
-RendererSectionData::RendererSectionData(World * world, Vector sectionPosition) {
+RendererSectionData::RendererSectionData(World * world, Vector sectionPosition) {
const std::map<BlockTextureId, glm::vec4> &textureAtlas = AssetManager::Instance().GetTextureAtlasIndexes();
const Section &section = world->GetSection(sectionPosition);
hash = section.GetHash();
sectionPos = sectionPosition;
- glm::mat4 baseOffset = glm::translate(glm::mat4(), (section.GetPosition() * 16).glm()),transform;
+ glm::mat4 baseOffset = glm::translate(glm::mat4(), (section.GetPosition() * 16).glm()), transform;
auto sectionsList = world->GetSectionsList();
@@ -196,12 +139,13 @@ RendererSectionData::RendererSectionData(World * world, Vector sectionPosition)
}
else {
transform = glm::translate(transform, glm::vec3(0, 1, 0));
-
+
if (block.id == 8 || block.id == 9) {
textures.push_back(AssetManager::Instance().GetTextureByAssetName("minecraft/textures/blocks/water_still"));
textures.back().w /= 32.0f;
transform = glm::translate(transform, glm::vec3(0, -0.2, 0));
- } else
+ }
+ else
textures.push_back(AssetManager::Instance().GetTextureByAssetName("minecraft/textures/blocks/tnt_side"));
models.push_back(transform);
@@ -212,9 +156,47 @@ RendererSectionData::RendererSectionData(World * world, Vector sectionPosition)
}
}
}
+
+ CreateVertices();
+ models.clear();
+
+ const int mul = 6;
+
+ textures.resize(textures.size() * mul);
+ for (int i = textures.size()/mul - 1; i > 0; i--) {
+ textures[i * mul] = textures[i];
+ }
+ for (int i = 0; i < textures.size(); i += mul) {
+ for (int j = 1; j < mul; j++) {
+ textures[i + j] = textures[i];
+ }
+ }
+
+ colors.resize(colors.size() * mul);
+ for (int i = colors.size() / mul - 1; i > 0; i--) {
+ colors[i * mul] = colors[i];
+ }
+ for (int i = 0; i < colors.size(); i += mul) {
+ for (int j = 1; j < mul; j++) {
+ colors[i + j] = colors[i];
+ }
+ }
+
+ lights.resize(lights.size() * mul);
+ for (int i = lights.size() / mul - 1; i > 0; i--) {
+ lights[i * mul] = lights[i];
+ }
+ for (int i = 0; i < lights.size(); i += mul) {
+ for (int j = 1; j < mul; j++) {
+ lights[i + j] = lights[i];
+ }
+ }
+
textures.shrink_to_fit();
models.shrink_to_fit();
colors.shrink_to_fit();
+ lights.shrink_to_fit();
+ vertices.shrink_to_fit();
}
void RendererSectionData::AddFacesByBlockModel(const std::vector<Vector> &sectionsList, World *world, Vector blockPos, const BlockModel &model, glm::mat4 transform, unsigned char light, unsigned char skyLight) {
@@ -340,4 +322,44 @@ bool RendererSectionData::TestBlockExists(const std::vector<Vector> &sectionsLis
auto blockModel = AssetManager::Instance().GetBlockModelByBlockId(world->GetSection(section).GetBlockId(blockPos));
return blockId.id != 0 && blockModel && blockModel->IsBlock;
+}
+
+void RendererSectionData::CreateVertices() {
+ const GLfloat verts[] = {
+ 0, 0, 0,
+ 1, 0, 1,
+ 1, 0, 0,
+
+ 0, 0, 0,
+ 0, 0, 1,
+ 1, 0, 1,
+ };
+
+ const GLfloat uvs[] = {
+ 0.0f, 0.0f,
+ 1.0f, 1.0f,
+ 0.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ };
+
+ for (const auto &model : models) {
+ vertices.push_back(model * glm::vec4(verts[0], verts[1], verts[2], 1.0f));
+ vertices.push_back(model * glm::vec4(verts[3], verts[4], verts[5], 1.0f));
+ vertices.push_back(model * glm::vec4(verts[6], verts[7], verts[8], 1.0f));
+
+ vertices.push_back(model * glm::vec4(verts[9], verts[10], verts[11], 1.0f));
+ vertices.push_back(model * glm::vec4(verts[12], verts[13], verts[14], 1.0f));
+ vertices.push_back(model * glm::vec4(verts[15], verts[16], verts[17], 1.0f));
+
+ uv.push_back(glm::vec2(uvs[0], uvs[1]));
+ uv.push_back(glm::vec2(uvs[2], uvs[3]));
+ uv.push_back(glm::vec2(uvs[4], uvs[5]));
+
+ uv.push_back(glm::vec2(uvs[6], uvs[7]));
+ uv.push_back(glm::vec2(uvs[8], uvs[9]));
+ uv.push_back(glm::vec2(uvs[10], uvs[11]));
+ }
} \ No newline at end of file
diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp
index 1c7fc3d..9ba694e 100644
--- a/src/RendererSection.hpp
+++ b/src/RendererSection.hpp
@@ -14,6 +14,8 @@
#include "Renderer.hpp"
struct RendererSectionData {
+ std::vector<glm::vec3> vertices;
+ std::vector<glm::vec2> uv;
std::vector<glm::mat4> models;
std::vector<glm::vec4> textures;
std::vector<glm::vec3> colors;
@@ -26,10 +28,13 @@ private:
bool TestBlockExists(const std::vector<Vector> &sectionsList, World *world, Vector blockPos);
void AddFacesByBlockModel(const std::vector<Vector> &sectionsList, World *world, Vector blockPos, const BlockModel &model, glm::mat4 transform, unsigned char light, unsigned char skyLight);
+
+ void CreateVertices();
};
class RendererSection {
enum Vbos {
- MODELS = 0,
+ VERTICES = 0,
+ UV,
TEXTURES,
COLORS,
LIGHTS,
diff --git a/src/Shader.cpp b/src/Shader.cpp
index 164da69..2b69c02 100644
--- a/src/Shader.cpp
+++ b/src/Shader.cpp
@@ -1,5 +1,7 @@
#include "Shader.hpp"
+#include "Event.hpp"
+
Shader::Shader(const GLchar *vertexPath, const GLchar *fragmentPath, const GLchar *geometryPath) {
vertex = vertexPath;
fragment = fragmentPath;
@@ -88,7 +90,7 @@ Shader::Shader(const GLchar *vertexPath, const GLchar *fragmentPath, const GLcha
glGetProgramiv(this->Program, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(this->Program, 512, NULL, infoLog);
- LOG(FATAL) << "Shader program not linked: " << infoLog;
+ EventAgregator::PushEvent(EventType::Disconnect, DisconnectData{ "Shader linking failed" });
}
glDeleteShader(vertex);
diff --git a/src/World.cpp b/src/World.cpp
index 8cff53a..80ee4b9 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -120,7 +120,7 @@ static Section fallbackSection;
const Section &World::GetSection(Vector sectionPos) {
auto result = sections.find(sectionPos);
if (result == sections.end()) {
- LOG(ERROR) << "Accessed not loaded section " << sectionPos;
+ //LOG(ERROR) << "Accessed not loaded section " << sectionPos;
return fallbackSection;
}
else {