1
0
Fork 0
spectre/include/Spectre/Graphics/ShaderProgram.h
Henrik Hautakoski e10daeaaa6
Move everything from global namespace to "sp" namespace
When writing the X11 (linux) implementation there was a problem with X11 defining a "Display" type and we also have a Display class in the engine.

So to fix that problem and minimize the risk for running into other name conflicts. We move everything from global namespace.
2019-09-30 19:10:17 +02:00

90 lines
2 KiB
C++

#ifndef SPECTRE_GRAPHICS_SHADER_PROGRAM_H
#define SPECTRE_GRAPHICS_SHADER_PROGRAM_H
#include <string>
#include <Spectre/Math/Matrix4.h>
#include "Shader.h"
namespace sp {
struct Color;
class ShaderProgram
{
public :
ShaderProgram();
~ShaderProgram();
void create();
void destroy();
void addShader(const Shader& shader);
// Load a shader program from file.
//
// The following naming conventions are supported:
// <name>.glsl - Virtual file, will load all real shader files with the same name.
// <name>.vert.glsl - Vertex shader.
// <name>.frag.glsl - Fragment shader.
bool loadFromFile(const std::string& filename);
// Load a shader from file.
bool loadFromFile(const std::string& filename, Shader::Type type);
// Load a shader from memory.
bool loadFromMemory(const std::string& source, Shader::Type type);
// Link the program.
bool link();
// Returns true if the program was linked successfully
bool isLinked() const;
// Enable this shader
// All shader operations after this call will affect this shader.
void enable() const;
// Disable this shader
// Operations will no longer affect this shader after this call.
void disable() const;
// Get the last shader error.
std::string getLastError() const;
// ---------------------
// Variables.
// ---------------------
bool setMVPMatrix(const Matrix4f& matrix);
// ---------------------
// General Variables.
// ---------------------
bool setAttribute(const std::string& name, float value) const;
bool setAttribute(const std::string& name, const Matrix4f& matrix) const;
bool setUniform(const std::string& name, const Matrix4f& matrix) const;
bool setUniform(const std::string& name, const Color& color) const;
protected :
bool getAttribLoc(const std::string& name, int& loc) const;
bool getUniformLoc(const std::string& name, int& loc) const;
std::string fetchErrorLog();
protected :
unsigned int m_id; // program id
mutable std::string m_error;
};
} // namespace sp
#endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */