diff --git a/material.cpp b/material.cpp index 5590df4..782b14f 100644 --- a/material.cpp +++ b/material.cpp @@ -1,12 +1,25 @@ #include "material.h" +#include "glew/glew.h" +#include "glassert.h" +#include "glm/glm.hpp" -Material::Material() +GLuint Material::getLocation(std::string attribName) { - + glAssert(GLuint loc = glGetUniformLocation(getShader()->getProgramId(), attribName.c_str())); + return loc; } -Material::~Material() +void Material::bindFloat(GLuint location, float val) { - + glAssert(glUniform1f(location, val)); } +void Material::bindMatrix(GLuint location, glm::mat4 mat) +{ + glAssert(glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(mat))); +} + +void Material::bindVec3(GLuint location, glm::vec3 vec) +{ + glAssert(glUniform3fv(location, 1, glm::value_ptr(vec))); +} diff --git a/material.h b/material.h index bdcbd63..966061e 100644 --- a/material.h +++ b/material.h @@ -1,12 +1,25 @@ #ifndef MATERIAL_H #define MATERIAL_H +#include "shader.h" +#include "glm/fwd.hpp" class Material { public: - Material(); - ~Material(); + Material(Shader* myShader) : shader(myShader) {} + Shader* getShader() {return shader;} + + virtual void bindAttributes() = 0; + +protected: + Shader* shader; + + // utils : + GLuint getLocation(std::string attribName); + void bindFloat(GLuint location, float val); + void bindMatrix(GLuint location, glm::mat4 mat); + void bindVec3(GLuint location, glm::vec3 vec); }; #endif // MATERIAL_H diff --git a/sparrowRenderer.pro b/sparrowRenderer.pro index 17b2b75..3b40267 100644 --- a/sparrowRenderer.pro +++ b/sparrowRenderer.pro @@ -27,7 +27,8 @@ SOURCES += main.cpp\ camera.cpp \ sparrowrenderer.cpp \ scene.cpp \ - material.cpp + material.cpp \ + texture.cpp HEADERS += mainwindow.h \ myglwidget.h \ @@ -37,7 +38,8 @@ HEADERS += mainwindow.h \ sparrowrenderer.h \ glassert.h \ scene.h \ - material.h + material.h \ + texture.h FORMS += mainwindow.ui diff --git a/texture.cpp b/texture.cpp new file mode 100644 index 0000000..f0a8877 --- /dev/null +++ b/texture.cpp @@ -0,0 +1,12 @@ +#include "texture.h" + +Texture::Texture() +{ + +} + +Texture::~Texture() +{ + +} + diff --git a/texture.h b/texture.h new file mode 100644 index 0000000..7a1d64e --- /dev/null +++ b/texture.h @@ -0,0 +1,12 @@ +#ifndef TEXTURE_H +#define TEXTURE_H + + +class Texture +{ +public: + Texture(); + ~Texture(); +}; + +#endif // TEXTURE_H