class EE::Graphics::ShaderProgram

Overview

The Shader Program Class. More…

#include <shaderprogram.hpp>

class ShaderProgram {
public:
    // typedefs

    typedef std::function<void(ShaderProgram*)> ShaderProgramReloadCb;

    // construction

    virtual ~ShaderProgram();

    // methods

    static ShaderProgram* New(const std::string& Name = "");
    static ShaderProgram* New(const std::vector<Shader*>& Shaders, const std::string& Name = "");
    static ShaderProgram* New(const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& Name = "");
    static ShaderProgram* New(const char* VertexShaderData, const Uint32& VertexShaderDataSize, const char* FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& Name = "");
    static ShaderProgram* New(Pack* Pack, const std::string& VertexShaderPath, const std::string& FragmentShaderPath, const std::string& Name = "");
    static ShaderProgram* New(const char** VertexShaderData, const Uint32& NumLinesVS, const char** FragmentShaderData, const Uint32& NumLinesFS, const std::string& Name = "");
    void addShader(Shader* Shader);
    void addShaders(const std::vector<Shader*>& Shaders);
    virtual bool link();
    bool isValid() const;
    std::string getLinkLog() const;
    virtual void bind() const;
    virtual void unbind() const;
    Int32 getUniformLocation(const std::string& Name);
    Int32 getAttributeLocation(const std::string& Name);
    void invalidateLocations();
    bool setUniform(const std::string& Name, float Value);
    bool setUniform(const std::string& Name, Vector2ff Value);
    bool setUniform(const std::string& Name, Vector3ff Value);
    bool setUniform(const std::string& Name, float x, float y, float z, float w);
    bool setUniform(const std::string& Name, Int32 Value);
    bool setUniform(const Int32& Location, Int32 Value);
    bool setUniform(const Int32& Location, float Value);
    bool setUniform(const Int32& Location, Vector2ff Value);
    bool setUniform(const Int32& Location, Vector3ff Value);
    bool setUniform(const Int32& Location, float x, float y, float z, float w);
    bool setUniformMatrix(const std::string Name, const float* Value);
    bool setUniformMatrix(const Int32& Location, const float* Value);
    const Uint32& getHandler() const;
    const String::HashType& getId() const;
    void reload();
    const std::string& getName() const;
    void setName(const std::string& Name);
    void setReloadCb(ShaderProgramReloadCb Cb);
    void enableVertexAttribArray(const std::string& Name);
    void enableVertexAttribArray(const Int32& Location);
    void disableVertexAttribArray(const std::string& Name);
    void disableVertexAttribArray(const Int32& Location);
};

Detailed Documentation

The Shader Program Class.

Program is a GPU-executed program that is ready to be used for manipulating geometry and colors. * ShaderProgram can encapsulate vertex and fragment shaders or just one of them. If only either vertex or fragment shader is used, then traditional fixed-function pipeline is used for the other stage.

Methods

static ShaderProgram* New(const std::string& Name = "")

Creates an empty shader program

static ShaderProgram* New(const std::vector<Shader*>& Shaders, const std::string& Name = "")

Creates a program shader with a vector of shaders and link them.

static ShaderProgram* New(const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& Name = "")

Creates a VertexShader from file and a Fragment Shader from file, and link them.

static ShaderProgram* New(const char* VertexShaderData, const Uint32& VertexShaderDataSize, const char* FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& Name = "")

Creates a VertexShader from memory and a Fragment Shader from memory, and link them.

static ShaderProgram* New(Pack* Pack, const std::string& VertexShaderPath, const std::string& FragmentShaderPath, const std::string& Name = "")

Creates the vertex shader and fragment shader from two files inside a pack

static ShaderProgram* New(const char** VertexShaderData, const Uint32& NumLinesVS, const char** FragmentShaderData, const Uint32& NumLinesFS, const std::string& Name = "")

Creates the vertex and fragment shader from an array of strings

void addShader(Shader* Shader)

Add a new shader

void addShaders(const std::vector<Shader*>& Shaders)

Add a vector of shaders

bool isValid() const

Returns:

If the shader program is valid

std::string getLinkLog() const

Returns:

THe link log

virtual void bind() const

Binds the shader program so that it will be used for anything that is rendered

virtual void unbind() const

Unbind the program. Anything rendered after Unbind() call will be rendered using the fixed-function pipeline

Int32 getUniformLocation(const std::string& Name)

Returns:

The location of the location name

Int32 getAttributeLocation(const std::string& Name)

Returns:

The location of the attribute name

void invalidateLocations()

Clear the locations

bool setUniform(const std::string& Name, float Value)

Sets the uniform with the given name to the given value and returns true. If there is no uniform with such name then false is returned. Note that the program has to be bound before this method can be used.

bool setUniform(const std::string& Name, Vector2ff Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const std::string& Name, Vector3ff Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const std::string& Name, float x, float y, float z, float w)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const std::string& Name, Int32 Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const Int32& Location, Int32 Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const Int32& Location, float Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const Int32& Location, Vector2ff Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const Int32& Location, Vector3ff Value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniform(const Int32& Location, float x, float y, float z, float w)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool setUniformMatrix(const std::string Name, const float* Value)

Sets an uniform matrix from its name.

bool setUniformMatrix(const Int32& Location, const float* Value)

Sets an uniform matrix from its location.

const Uint32& getHandler() const

Returns:

The id of the program (the handle)

const String::HashType& getId() const

Returns:

The Id of the program ( hash of the program name )

void reload()

Reloads the shaders

const std::string& getName() const

Returns:

Name of the shader program

void setName(const std::string& Name)

Set the name of the shader program

void setReloadCb(ShaderProgramReloadCb Cb)

Set a reload callback ( needed to reset shader states ).

void enableVertexAttribArray(const std::string& Name)

Enable a vertex attribute array

void enableVertexAttribArray(const Int32& Location)

Enable a vertex attribute array

void disableVertexAttribArray(const std::string& Name)

Disable a vertex attribute array

void disableVertexAttribArray(const Int32& Location)

Disable a vertex attribute array