From e9a47db9626dfb65c3fbfd7552ceb7a93dd0567a Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 15 Dec 2014 01:12:51 +0100 Subject: [PATCH] Made getLights return a pointer to avoid copying around large amounts of light data every frame. --- graphics.cc | 22 +++++++++++----------- level.cc | 4 ++-- level.hh | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/graphics.cc b/graphics.cc index 4e7534d..9028507 100644 --- a/graphics.cc +++ b/graphics.cc @@ -145,28 +145,28 @@ void Graphics::render() lightingShader->setTexture("shadowMap_far", depthTexture_far, 3); //set lighting parameters - if (level->getLights().size() > 0) { - lightingShader->setUniform("lightCount", (int) level->getLights().size()); + if (level->getLights()->size() > 0) { + lightingShader->setUniform("lightCount", (int) level->getLights()->size()); // TODO look into doing this less often // Build light position array - glm::vec3 lightSources[level->getLights().size()]; - for(unsigned int i = 0; igetLights().size(); i++) { - lightSources[i] = level->getLights()[i].getPosition(); + glm::vec3 lightSources[level->getLights()->size()]; + for(unsigned int i = 0; igetLights()->size(); i++) { + lightSources[i] = level->getLights()->at(i).getPosition(); } glUniform3fv(lightingShader->getUniformLocation("lightSources"), sizeof(lightSources), (GLfloat*) lightSources); // Build light colour array - glm::vec3 lightColours[level->getLights().size()]; - for(unsigned int i = 0; igetLights().size(); i++) { - lightColours[i] = level->getLights()[i].getColour(); + glm::vec3 lightColours[level->getLights()->size()]; + for(unsigned int i = 0; igetLights()->size(); i++) { + lightColours[i] = level->getLights()->at(i).getColour(); } glUniform3fv(lightingShader->getUniformLocation("lightColors"), sizeof(lightColours), (GLfloat*) lightColours); // Build light attenuation array - float lightIntensities[level->getLights().size()]; - for(unsigned int i = 0; igetLights().size(); i++) { - lightIntensities[i] = level->getLights()[i].getIntensity(); + float lightIntensities[level->getLights()->size()]; + for(unsigned int i = 0; igetLights()->size(); i++) { + lightIntensities[i] = level->getLights()->at(i).getIntensity(); } glUniform1fv(lightingShader->getUniformLocation("lightIntensities"), sizeof(lightIntensities), (GLfloat*) lightIntensities); diff --git a/level.cc b/level.cc index 2b39792..c78b7c7 100644 --- a/level.cc +++ b/level.cc @@ -349,8 +349,8 @@ glm::vec3 Level::getAmbientLight() { return ambientLight; } -std::vector Level::getLights() { - return lights; +std::vector* Level::getLights() { + return &lights; } Camera* Level::getCamera() { diff --git a/level.hh b/level.hh index dfe7a28..0ceb9c5 100644 --- a/level.hh +++ b/level.hh @@ -21,7 +21,7 @@ class Level { void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass); glm::vec3 getAmbientLight(); Light* getDirectionalLight(); - std::vector getLights(); + std::vector* getLights(); Object* getCameraCenter(); Camera* getCamera(); glm::vec3 getCameraPosition();