Performance optimization
This commit is contained in:
@@ -42,7 +42,8 @@ void Engine::initGL()
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClearDepth(1.0f);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
//glDepthRange(-0.5f,0.5f);
|
||||
}
|
||||
|
||||
|
@@ -40,9 +40,10 @@ void Render::render() {
|
||||
glLoadIdentity();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
//TODO: *Always* render the camera first.
|
||||
glCullFace(GL_BACK);
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
if (e->draw)
|
||||
e->render();
|
||||
@@ -75,11 +76,11 @@ void Render::render_loop() {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
|
||||
dT += remaining;
|
||||
}
|
||||
|
||||
//Decrease framerate when focus is lost.
|
||||
if (!engine->window->getFlag(RWindowFlags::IN_FOCUS)) {
|
||||
dT = 41666.67f - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds((int) dT));
|
||||
int remaining = 41666.67f - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
|
||||
dT += remaining;
|
||||
}
|
||||
engine->frameDelta = (dT / 1000000);
|
||||
}
|
||||
|
@@ -18,7 +18,9 @@ void Skybox::render() {
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y, position.z);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureID());
|
||||
glCullFace(GL_FRONT);
|
||||
getGeometry()->draw();
|
||||
glCullFace(GL_BACK);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
@@ -64,18 +64,16 @@ void VertexArray::load (const std::string& filename) {
|
||||
void VertexArray::draw() {
|
||||
if (!indices.empty()) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (size_t i = 0; i < indices.size(); i += 3) {
|
||||
glTexCoord2f(vertices[indices[i]].u, vertices[indices[i]].v);
|
||||
glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTexCoord2f(vertices[indices[i + 1]].u, vertices[indices[i + 1]].v);
|
||||
glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &vertices[0].u);
|
||||
|
||||
glTexCoord2f(vertices[indices[i + 2]].u, vertices[indices[i + 2]].v);
|
||||
glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);
|
||||
}
|
||||
glEnd();
|
||||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, &indices[0]);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user