Moving shader management completely into graphics.
This commit is contained in:
parent
64aeae8143
commit
f38ced6603
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
32
graphics.cc
32
graphics.cc
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user