It can render the chunks now, but it definitely can ue more optimizations

This commit is contained in:
Evert Prants 2018-06-07 08:07:54 +03:00
parent 47fe269c76
commit 84721968ae
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 23 additions and 34 deletions

View File

@ -262,11 +262,11 @@ void Application::run()
pl->tick(m_camera, deltaTime);
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
pl->draw(m_camera, &chunkShader);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
//glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
// END TEST CODE

View File

@ -294,38 +294,27 @@ void Shader::setUniform(const std::string& name, int val)
void Shader::use()
{
if (!m_valid)
// Bind the shader
start();
// Bind the buffers needed
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
// Enable all attributes
for (auto it(m_attributes.begin()); it != m_attributes.end(); ++it)
{
m_valid = true;
// Bind the shader
start();
// Bind the buffers needed
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
// Enable all attributes
for (auto it(m_attributes.begin()); it != m_attributes.end(); ++it)
{
GLuint location = getAttribLocation(it->first);
glEnableVertexAttribArray(location);
glVertexAttribPointer(
location,
it->second.size,
it->second.type,
it->second.normalized,
it->second.stride * sizeof(GLfloat),
(void*)(it->second.offset * sizeof(GLfloat))
);
}
} else {
start();
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
GLuint location = getAttribLocation(it->first);
glEnableVertexAttribArray(location);
glVertexAttribPointer(
location,
it->second.size,
it->second.type,
it->second.normalized,
it->second.stride * sizeof(GLfloat),
(void*)(it->second.offset * sizeof(GLfloat))
);
}
}

View File

@ -68,7 +68,7 @@ ChunkManager::ChunkManager(PlanetFace* face, GLuint chunkCount) : m_face(face)
{
for (int z = 0; z < (int)chunkCount; z++)
{
m_chunks.push_back(new Chunk(m_face->getPlanet(), m_face, x, y, z));
m_chunks.push_back(new Chunk(m_face->getPlanet(), m_face, x * CHUNK_SIZE, y * CHUNK_SIZE, z * CHUNK_SIZE));
}
}
}