Moving shader management completely into graphics.

This commit is contained in:
Faerbit 2014-12-01 17:49:59 +01:00
parent b49f93afd4
commit eb90142e81
5 changed files with 29 additions and 29 deletions

View File

@ -1,6 +1,5 @@
#include "application.hh"
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
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<ACGL::OpenGL::ArrayBuffer>();
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<ACGL::OpenGL::VertexArrayObject>();
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;
}

View File

@ -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

View File

@ -3,9 +3,32 @@
#include <iomanip>
#include <sstream>
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
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<ACGL::OpenGL::ArrayBuffer>();
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<ACGL::OpenGL::VertexArrayObject>();
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);

View File

@ -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

View File

@ -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();