1
0
Fork 0

Adding Spectre/GfxDriver/ShaderProgram base class.

This commit is contained in:
Henrik Hautakoski 2022-09-18 12:26:01 +02:00
parent b91bc22db1
commit cd9114bfd0
2 changed files with 146 additions and 0 deletions

View file

@ -0,0 +1,77 @@
#ifndef SPECTRE_GFXDRIVER_SHADERPROGRAM_H
#define SPECTRE_GFXDRIVER_SHADERPROGRAM_H
#include <Spectre/Math/Matrix4.h>
#include <Spectre/Math/Color.h>
namespace sp {
enum ShaderType {
Vertex,
Fragment
};
class ShaderProgram
{
public:
virtual ~ShaderProgram();
// Load a shader program from file.
virtual bool loadFromFile(const std::string& filename);
// Load a shader from file.
virtual bool loadFromFile(const std::string& filename, ShaderType type);
// Load a shader from memory.
virtual bool loadFromMemory(const std::string& source, ShaderType type) = 0;
// Link the program.
virtual bool link() = 0;
// Returns true if the program was linked successfully
virtual bool isLinked() const;
// Enable this shader
// All shader operations after this call will affect this shader.
virtual void enable() const = 0;
// Disable this shader
// Operations will no longer affect this shader after this call.
virtual void disable() const = 0;
// Get the last shader error.
virtual std::string getLastError() const;
// ---------------------
// Variables.
// ---------------------
// TODO: Move this to a ShaderParameter class
virtual bool setMVPMatrix(const Matrix4f& matrix) = 0;
// ---------------------
// General Variables.
// ---------------------
virtual bool setAttribute(const std::string& name, float value) const = 0;
virtual bool setAttribute(const std::string& name, const Matrix4f& matrix) const = 0;
virtual bool setUniform(const std::string& name, const Matrix4f& matrix) const = 0;
virtual bool setUniform(const std::string& name, const Color& color) const = 0;
protected:
std::string m_extension;
mutable std::string m_error;
bool m_linked;
};
} // namespace sp
#endif /* SECTRE_GRAPHICS_SHADERPROGRAM_H */