parent
b8edab738b
commit
3c1e4ff757
|
@ -211,6 +211,8 @@
|
|||
<Text Include="todo.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\shader\BlockRenderer.frag" />
|
||||
<None Include="res\shader\BlockRenderer.vert" />
|
||||
<None Include="res\shader\Renderer2D.frag" />
|
||||
<None Include="res\shader\Renderer2D.vert" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -162,5 +162,7 @@
|
|||
<ItemGroup>
|
||||
<None Include="res\shader\Renderer2D.vert" />
|
||||
<None Include="res\shader\Renderer2D.frag" />
|
||||
<None Include="res\shader\BlockRenderer.vert" />
|
||||
<None Include="res\shader\BlockRenderer.frag" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,7 +1,7 @@
|
|||
#version 450 core
|
||||
|
||||
in vec2 TexCoords;
|
||||
in float ID;
|
||||
flat in int ID;
|
||||
|
||||
uniform sampler2DArray textures;
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ layout (location = 0) in vec3 block_vertex;
|
|||
layout (location = 1) in vec2 block_texture_coord;
|
||||
|
||||
layout (location = 2) in vec3 position;
|
||||
layout (location = 3) in float id;
|
||||
layout (location = 3) in int id;
|
||||
|
||||
out vec2 TexCoords;
|
||||
out float ID;
|
||||
out int ID;
|
||||
|
||||
uniform mat4 vp;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ void Chunk::generate(ChunkHeightProvider provider)
|
|||
float finalX = dx + (this->x << 4);
|
||||
float finalZ = dy + (this->z << 4);
|
||||
float finalY = std::floorf(provider.GetSimplex(finalX, finalZ) * 10);
|
||||
this->m_Blocks.emplace_back(GameRegistry::instance().getBlockDefByID(0), glm::vec3(finalX, finalY, finalZ));
|
||||
this->m_Blocks.emplace_back(GameRegistry::instance().getBlockDefByID(0), glm::vec3(dx, finalY, dy));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ typedef FastNoise ChunkHeightProvider;
|
|||
|
||||
struct Block
|
||||
{
|
||||
uint ID;
|
||||
short ID;
|
||||
glm::vec3 position;
|
||||
|
||||
Block(const BlockDefinition &def) : ID(def.ID) {}
|
||||
|
@ -26,8 +26,8 @@ public:
|
|||
void unload();
|
||||
|
||||
std::vector<Block> m_Blocks;
|
||||
private:
|
||||
int x, z;
|
||||
private:
|
||||
void generate(ChunkHeightProvider provider);
|
||||
};
|
||||
|
||||
|
|
|
@ -97,9 +97,9 @@ void BlockRenderer::init()
|
|||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_ChunkVBO));
|
||||
GLCall(glBufferData(GL_ARRAY_BUFFER, CHUNK_VBO_MAX_SIZE, nullptr, GL_STREAM_DRAW));
|
||||
GLCall(glEnableVertexAttribArray(2));
|
||||
GLCall(glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0));
|
||||
GLCall(glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat) + 4, 0));
|
||||
GLCall(glEnableVertexAttribArray(3));
|
||||
GLCall(glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))));
|
||||
GLCall(glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, 3 * sizeof(GLfloat) + 4, (GLvoid*)(3 * sizeof(GLfloat))));
|
||||
|
||||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
GLCall(glVertexAttribDivisor(2, 1));
|
||||
|
@ -156,7 +156,9 @@ void BlockRenderer::render(const Chunk &chunk)
|
|||
|
||||
for (const Block &bl : chunk.m_Blocks)
|
||||
{
|
||||
block->position = bl.position;
|
||||
int xoff = ((int)chunk.x) << 4;
|
||||
int zoff = ((int)chunk.z) << 4;
|
||||
block->position = bl.position + glm::vec3(xoff, 0 , zoff);
|
||||
block->id = bl.ID;
|
||||
block++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue