File: ShaderProgram.h

package info (click to toggle)
freeorion 0.5.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 194,920 kB
  • sloc: cpp: 186,821; python: 40,979; ansic: 1,164; xml: 721; makefile: 32; sh: 7
file content (75 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _ShaderProgram_h_
#define _ShaderProgram_h_

#include <GG/Base.h>

#include <memory>
#include <string>
#include <vector>

class ShaderProgram {
private:
    ShaderProgram();    // default ctor forbidden, makes no sense

public:
    // Use shaderProgramFactory() to construct.
    ShaderProgram(const std::string& vertex_shader, const std::string& fragment_shader);

    // shader factory -- will return nullptr if OpenGL version is too low
    static std::unique_ptr<ShaderProgram> shaderProgramFactory(
        const std::string& vertex_shader, const std::string& fragment_shader);

    ~ShaderProgram();

    GLuint              ProgramID() const;
    bool                LinkSucceeded() const;
    const std::string&  ProgramInfoLog() const;
    const std::string&  ProgramValidityInfoLog() const;
    const std::string&  VertexShaderInfoLog() const;
    const std::string&  FragmentShaderInfoLog() const;

    // These bind the value of the uniform float(s) referred called \a name in
    // the program.  Multi-float overloads are for when \a name is a vec.
    void                Bind(const std::string& name, float f);
    void                Bind(const std::string& name, float f0, float f1);
    void                Bind(const std::string& name, float f0, float f1, float f2);
    void                Bind(const std::string& name, float f0, float f1, float f2, float f3);

    // Binds the given array of values to the int array \a name in the
    // program.  \a element_size indicates the number of
    // ints in each element of the array, and must be 1, 2, 3, or 4
    // (corresponding to GLSL types float, vec2, vec3, and vec4).
    void                Bind(const std::string& name, std::size_t element_size, const std::vector<float> &floats);

    void                Bind(const std::string& name, GLuint texture_id);

    // These bind the value of the uniform int(s) referred called \a name in
    // the program.  Multi-int overloads are for when \a name is an ivec.
    void                BindInt(const std::string& name, int i);
    void                BindInts(const std::string& name, int i0, int i1);
    void                BindInts(const std::string& name, int i0, int i1, int i2);
    void                BindInts(const std::string& name, int i0, int i1, int i2, int i3);

    // Binds the given array of values to the int array \a name in the
    // program.  \a element_size indicates the number of
    // ints in each element of the array, and must be 1, 2, 3, or 4
    // (corresponding to GLSL types int, ivec2, ivec3, and ivec4).
    void                BindInts(const std::string& name, std::size_t element_size, const std::vector<GLint> &ints);

    bool                AllValuesBound();

    void                Use();
    void                stopUse();

private:
    GLuint      m_program_id;
    GLuint      m_vertex_shader_id;
    GLuint      m_fragment_shader_id;
    bool        m_link_succeeded;
    std::string m_program_log;
    std::string m_program_validity_log;
    std::string m_vertex_shader_log;
    std::string m_fragment_shader_log;
};

#endif