Removed own Shader wrapper, because it does nothing useful.

This commit is contained in:
Faerbit 2014-11-08 02:45:32 +01:00
parent 0754ad09db
commit c38629823d
9 changed files with 23 additions and 92 deletions

View File

@ -1,11 +1,11 @@
#include "graphics.hh" #include "graphics.hh"
#include "model.hh" #include "model.hh"
#include "shader.hh" #include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
using namespace std; using namespace std;
Shader shader; ACGL::OpenGL::SharedShaderProgram shader;
Level level; Level level;
// gets called after the OpenGL window is prepared: // gets called after the OpenGL window is prepared:
@ -22,7 +22,9 @@ void initCustomResources()
Model model = Model("Bunny.obj"); Model model = Model("Bunny.obj");
// look up all shader files starting with 'phong' and build a ShaderProgram from it: // look up all shader files starting with 'phong' and build a ShaderProgram from it:
shader = Shader("phong", model); shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
model.getReference()->getAttributeLocations()).create();
shader->use();
// load Level // load Level
level.load(shader); level.load(shader);
@ -43,40 +45,40 @@ void draw( float runTime )
// set view and projection matrix: // set view and projection matrix:
glm::mat4 viewMatrix = glm::translate(glm::vec3(0.0f, -1.0f, -2.0f)) * glm::rotate<float>(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale<float>(glm::vec3(0.25f)); glm::mat4 viewMatrix = glm::translate(glm::vec3(0.0f, -1.0f, -2.0f)) * glm::rotate<float>(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale<float>(glm::vec3(0.25f));
shader.getReference()->setUniform( "uViewMatrix", viewMatrix ); shader->setUniform( "uViewMatrix", viewMatrix );
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) ); shader->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
//set lighting parameters //set lighting parameters
if (level.getLights().size() > 0) { if (level.getLights().size() > 0) {
shader.getReference()->setUniform("lightCount", (int) level.getLights().size()); shader->setUniform("lightCount", (int) level.getLights().size());
// TODO look into doing this less often // TODO look into doing this less often
// Build light position array // Build light position array
glm::vec3 lightSources[level.getLights().size()]; glm::vec3 lightSources[level.getLights().size()];
for(int i = 0; i<level.getLights().size(); i++) { for(unsigned int i = 0; i<level.getLights().size(); i++) {
lightSources[i] = level.getLights()[i].getPosition(); lightSources[i] = level.getLights()[i].getPosition();
} }
glUniform3fv(shader.getReference()->getUniformLocation("lightSources"), glUniform3fv(shader->getUniformLocation("lightSources"),
sizeof(lightSources), (GLfloat*) lightSources); sizeof(lightSources), (GLfloat*) lightSources);
// Build light colour array // Build light colour array
glm::vec3 lightColours[level.getLights().size()]; glm::vec3 lightColours[level.getLights().size()];
for(int i = 0; i<level.getLights().size(); i++) { for(unsigned int i = 0; i<level.getLights().size(); i++) {
lightColours[i] = level.getLights()[i].getColour(); lightColours[i] = level.getLights()[i].getColour();
} }
glUniform3fv(shader.getReference()->getUniformLocation("lightColors"), glUniform3fv(shader->getUniformLocation("lightColors"),
sizeof(lightColours), (GLfloat*) lightColours); sizeof(lightColours), (GLfloat*) lightColours);
// Build light attenuation array // Build light attenuation array
float lightIntensities[level.getLights().size()]; float lightIntensities[level.getLights().size()];
for(int i = 0; i<level.getLights().size(); i++) { for(unsigned int i = 0; i<level.getLights().size(); i++) {
lightIntensities[i] = level.getLights()[i].getIntensity(); lightIntensities[i] = level.getLights()[i].getIntensity();
} }
glUniform1fv(shader.getReference()->getUniformLocation("lightIntensities"), glUniform1fv(shader->getUniformLocation("lightIntensities"),
sizeof(lightIntensities), (GLfloat*) lightIntensities); sizeof(lightIntensities), (GLfloat*) lightIntensities);
} }
// set Material Parameters // set Material Parameters
shader.getReference()->setUniform("ambientColor", level.getAmbientLight()); shader->setUniform("ambientColor", level.getAmbientLight());
shader.getReference()->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f)); shader->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f));
// render the level(currently only a bunny): // render the level(currently only a bunny):
level.render(); level.render();

View File

@ -11,7 +11,7 @@ Level::Level() {
Level::~Level() { Level::~Level() {
} }
void Level::load(Shader shader) { void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
//this->terrain.load(); //this->terrain.load();
@ -35,7 +35,7 @@ void Level::load(Shader shader) {
} }
void Level::render() { void Level::render() {
for(int i = 0; i<objects.size(); i++) { for(unsigned int i = 0; i<objects.size(); i++) {
objects[i].render(); objects[i].render();
} }
//this->terrain.render(); //this->terrain.render();

View File

@ -7,14 +7,13 @@
#include "entity.hh" #include "entity.hh"
#include "terrain.hh" #include "terrain.hh"
#include "material.hh" #include "material.hh"
#include "shader.hh"
class Level { class Level {
public: public:
Level(std::string filePath); Level(std::string filePath);
Level(); Level();
~Level(); ~Level();
void load(Shader shader); // Shader is necessary for correct texture assigning void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning
void render(); void render();
glm::vec3 getAmbientLight(); glm::vec3 getAmbientLight();
std::vector<Light> getLights(); std::vector<Light> getLights();

View File

@ -1,13 +1,13 @@
#include "object.hh" #include "object.hh"
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
glm::vec3 velocity, glm::vec3 angularVelocity, Shader shader) : glm::vec3 velocity, glm::vec3 angularVelocity, ACGL::OpenGL::SharedShaderProgram shader) :
Entity(position, rotation) { Entity(position, rotation) {
this->model = model.getReference(); this->model = model.getReference();
this->material = material; this->material = material;
this->velocity = velocity; this->velocity = velocity;
this->angularVelocity = angularVelocity; this->angularVelocity = angularVelocity;
this->shader = shader.getReference(); this->shader = shader;
} }
Object::Object() { Object::Object() {

View File

@ -4,7 +4,6 @@
#include "entity.hh" #include "entity.hh"
#include "model.hh" #include "model.hh"
#include "material.hh" #include "material.hh"
#include "shader.hh"
#include <string> #include <string>
#include <ACGL/Math/Math.hh> #include <ACGL/Math/Math.hh>
#include <ACGL/OpenGL/Managers.hh> #include <ACGL/OpenGL/Managers.hh>
@ -13,7 +12,8 @@
class Object : public Entity { class Object : public Entity {
public: public:
Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation,
glm::vec3 velocity, glm::vec3 angularVelocity, Shader shader); glm::vec3 velocity, glm::vec3 angularVelocity,
ACGL::OpenGL::SharedShaderProgram shader);
Object(); Object();
~Object(); ~Object();
void render(); void render();

View File

@ -1,17 +0,0 @@
#include "ourShader.hh"
OurShader::OurShader(std::string filePath, Model model) {
reference = ACGL::OpenGL::ShaderProgramCreator(filePath).attributeLocations(
model.getReference()->getAttributeLocations()).create();
reference->use();
}
OurShader::OurShader() {
}
OurShader::~OurShader() {
}
ACGL::OpenGL::SharedShaderProgram OurShader::getReference() {
return reference;
}

View File

@ -1,18 +0,0 @@
#ifndef SHADER_HH_INCLUDED
#define SHADER_HH_INCLUDED
#include "model.hh"
#include <string>
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
class OurShader {
public:
OurShader(std::string filePath, Model model);
OurShader();
ACGL::OpenGL::SharedShaderProgram getReference();
~OurShader();
private:
ACGL::OpenGL::SharedShaderProgram reference;
};
#endif

View File

@ -1,17 +0,0 @@
#include "shader.hh"
Shader::Shader(std::string filePath, Model model) {
reference = ACGL::OpenGL::ShaderProgramCreator(filePath).attributeLocations(
model.getReference()->getAttributeLocations()).create();
reference->use();
}
Shader::Shader() {
}
Shader::~Shader() {
}
ACGL::OpenGL::SharedShaderProgram Shader::getReference() {
return reference;
}

View File

@ -1,18 +0,0 @@
#ifndef SHADER_HH_INCLUDED
#define SHADER_HH_INCLUDED
#include "model.hh"
#include <string>
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
class Shader {
public:
Shader(std::string filePath, Model model);
Shader();
ACGL::OpenGL::SharedShaderProgram getReference();
~Shader();
private:
ACGL::OpenGL::SharedShaderProgram reference;
};
#endif