From f38ced6603004327508d15618a14a20a83b8d050 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 1 Dec 2014 17:49:59 +0100 Subject: [PATCH] Moving shader management completely into graphics. --- application.cc | 18 +----------------- application.hh | 2 -- graphics.cc | 32 ++++++++++++++++++++++++-------- graphics.hh | 4 +++- main.cc | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/application.cc b/application.cc index 339e8b7..8356f16 100644 --- a/application.cc +++ b/application.cc @@ -1,6 +1,5 @@ #include "application.hh" -#include Application::Application() { graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f); @@ -20,18 +19,7 @@ void Application::init() ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/"); ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/"); - // construct VAO to give shader correct Attribute locations - ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared(); - ab->defineAttribute("aPosition", GL_FLOAT, 3); - ab->defineAttribute("aTexCoord", GL_FLOAT, 2); - ab->defineAttribute("aNormal", GL_FLOAT, 3); - ACGL::OpenGL::SharedVertexArrayObject vao = std::make_shared(); - vao->attachAllAttributes(ab); - - // look up all shader files starting with 'phong' and build a ShaderProgram from it: - shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations( - vao->getAttributeLocations()).create(); - shader->use(); + graphics.init(); // load Level level.load(); @@ -48,10 +36,6 @@ Level* Application::getLevel() { return &level; } -ACGL::OpenGL::SharedShaderProgram Application::getShader() { - return shader; -} - void Application::setFocused(bool focused) { this->focused = focused; } diff --git a/application.hh b/application.hh index 60fa7d8..4de5007 100644 --- a/application.hh +++ b/application.hh @@ -10,7 +10,6 @@ class Application { Application(); Graphics* getGraphics(); Level* getLevel(); - ACGL::OpenGL::SharedShaderProgram getShader(); void init(); void setFocused(bool focused); bool isFocused(); @@ -25,7 +24,6 @@ class Application { bool cameraLock; Graphics graphics; Level level; - ACGL::OpenGL::SharedShaderProgram shader; }; #endif diff --git a/graphics.cc b/graphics.cc index 9385ccc..aa9bc6a 100644 --- a/graphics.cc +++ b/graphics.cc @@ -3,9 +3,32 @@ #include #include +#include + +Graphics::Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane) { + this->windowSize = windowSize; + this->nearPlane = nearPlane; + this->farPlane = farPlane; +} + Graphics::Graphics() { } +void Graphics::init() { + // construct VAO to give shader correct Attribute locations + ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared(); + ab->defineAttribute("aPosition", GL_FLOAT, 3); + ab->defineAttribute("aTexCoord", GL_FLOAT, 2); + ab->defineAttribute("aNormal", GL_FLOAT, 3); + ACGL::OpenGL::SharedVertexArrayObject vao = std::make_shared(); + vao->attachAllAttributes(ab); + + // look up all shader files starting with 'phong' and build a ShaderProgram from it: + shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations( + vao->getAttributeLocations()).create(); + shader->use(); +} + GLFWwindow* Graphics::getWindow() { return window; } @@ -68,14 +91,7 @@ bool Graphics::createWindow() return true; } -Graphics::Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane) { - this->windowSize = windowSize; - this->nearPlane = nearPlane; - this->farPlane = farPlane; -} - - -void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader) +void Graphics::render(Level* level) { // clear the framebuffer: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/graphics.hh b/graphics.hh index f3be1aa..0e0d26a 100644 --- a/graphics.hh +++ b/graphics.hh @@ -10,7 +10,8 @@ class Graphics { public: Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane); Graphics(); - void render(Level* level, ACGL::OpenGL::SharedShaderProgram shader); + void init(); + void render(Level* level); // to build the projection matrix: glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio); glm::mat4 buildViewMatrix(Level* level); @@ -25,6 +26,7 @@ class Graphics { float nearPlane; float farPlane; GLFWwindow* window; + ACGL::OpenGL::SharedShaderProgram shader; }; #endif diff --git a/main.cc b/main.cc index acf86c9..8ac7a9b 100644 --- a/main.cc +++ b/main.cc @@ -123,7 +123,7 @@ int main( int argc, char *argv[] ) } lastUpdate = now; - app.getGraphics()->render(app.getLevel(), app.getShader()); + app.getGraphics()->render(app.getLevel()); openGLCriticalError();