1
0
Fork 0

Adding GfxDriver/OpenGL/OpenGLShaderProgram class

This commit is contained in:
Henrik Hautakoski 2022-09-18 12:26:31 +02:00
parent cd9114bfd0
commit 69e5ae22d2
2 changed files with 256 additions and 0 deletions

View file

@ -0,0 +1,70 @@
#ifndef SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H
#define SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H
#include <Graphics/GL/gl.h>
#include <Spectre/GfxDriver/ShaderProgram.h>
namespace sp {
class OpenGLShaderProgram : public ShaderProgram
{
public:
OpenGLShaderProgram();
virtual ~OpenGLShaderProgram();
// Load a shader from memory.
virtual bool loadFromMemory(const std::string& source, ShaderType type);
// Link the program.
virtual bool link();
// Enable this shader
// All shader operations after this call will affect this shader.
virtual void enable() const;
// Disable this shader
// Operations will no longer affect this shader after this call.
virtual void disable() const;
// ---------------------
// Variables.
// ---------------------
virtual bool setMVPMatrix(const Matrix4f& matrix);
// ---------------------
// General Variables.
// ---------------------
virtual bool setAttribute(const std::string& name, float value) const;
virtual bool setAttribute(const std::string& name, const Matrix4f& matrix) const;
virtual bool setUniform(const std::string& name, const Matrix4f& matrix) const;
virtual bool setUniform(const std::string& name, const Color& color) const;
protected :
// Compile a shader.
bool compileShader(GLuint id);
// Attach shader to program.
bool attachShader(GLuint id);
bool getAttribLoc(const std::string& name, int& loc) const;
bool getUniformLoc(const std::string& name, int& loc) const;
std::string fetchErrorLog() const;
protected :
// Program ID
GLuint m_id;
};
} // namespace sp
#endif /* SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H */