implemented material interface, added texture class
This commit is contained in:
parent
9e19c2211d
commit
f9c77feac3
21
material.cpp
21
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)));
|
||||
}
|
||||
|
17
material.h
17
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
|
||||
|
@ -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
|
||||
|
||||
|
12
texture.cpp
Normal file
12
texture.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "texture.h"
|
||||
|
||||
Texture::Texture()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user