Moving shader management completely into graphics.
This commit is contained in:
parent
b49f93afd4
commit
eb90142e81
@ -1,6 +1,5 @@
|
|||||||
#include "application.hh"
|
#include "application.hh"
|
||||||
|
|
||||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
|
||||||
|
|
||||||
Application::Application() {
|
Application::Application() {
|
||||||
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
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()->setTexturePath("Levels/Textures/");
|
||||||
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
||||||
|
|
||||||
// construct VAO to give shader correct Attribute locations
|
graphics.init();
|
||||||
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();
|
|
||||||
|
|
||||||
// load Level
|
// load Level
|
||||||
level.load();
|
level.load();
|
||||||
@ -48,10 +36,6 @@ Level* Application::getLevel() {
|
|||||||
return &level;
|
return &level;
|
||||||
}
|
}
|
||||||
|
|
||||||
ACGL::OpenGL::SharedShaderProgram Application::getShader() {
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::setFocused(bool focused) {
|
void Application::setFocused(bool focused) {
|
||||||
this->focused = focused;
|
this->focused = focused;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ class Application {
|
|||||||
Application();
|
Application();
|
||||||
Graphics* getGraphics();
|
Graphics* getGraphics();
|
||||||
Level* getLevel();
|
Level* getLevel();
|
||||||
ACGL::OpenGL::SharedShaderProgram getShader();
|
|
||||||
void init();
|
void init();
|
||||||
void setFocused(bool focused);
|
void setFocused(bool focused);
|
||||||
bool isFocused();
|
bool isFocused();
|
||||||
@ -25,7 +24,6 @@ class Application {
|
|||||||
bool cameraLock;
|
bool cameraLock;
|
||||||
Graphics graphics;
|
Graphics graphics;
|
||||||
Level level;
|
Level level;
|
||||||
ACGL::OpenGL::SharedShaderProgram shader;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
32
graphics.cc
32
graphics.cc
@ -3,9 +3,32 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#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() {
|
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() {
|
GLFWwindow* Graphics::getWindow() {
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@ -68,14 +91,7 @@ bool Graphics::createWindow()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics::Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane) {
|
void Graphics::render(Level* level)
|
||||||
this->windowSize = windowSize;
|
|
||||||
this->nearPlane = nearPlane;
|
|
||||||
this->farPlane = farPlane;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Graphics::render(Level* level, ACGL::OpenGL::SharedShaderProgram shader)
|
|
||||||
{
|
{
|
||||||
// clear the framebuffer:
|
// clear the framebuffer:
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
@ -10,7 +10,8 @@ class Graphics {
|
|||||||
public:
|
public:
|
||||||
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane);
|
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane);
|
||||||
Graphics();
|
Graphics();
|
||||||
void render(Level* level, ACGL::OpenGL::SharedShaderProgram shader);
|
void init();
|
||||||
|
void render(Level* level);
|
||||||
// to build the projection matrix:
|
// to build the projection matrix:
|
||||||
glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio);
|
glm::mat4 buildFrustum( float phiInDegree, float near, float far, float aspectRatio);
|
||||||
glm::mat4 buildViewMatrix(Level* level);
|
glm::mat4 buildViewMatrix(Level* level);
|
||||||
@ -25,6 +26,7 @@ class Graphics {
|
|||||||
float nearPlane;
|
float nearPlane;
|
||||||
float farPlane;
|
float farPlane;
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
|
ACGL::OpenGL::SharedShaderProgram shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user