-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.h
101 lines (80 loc) · 3.2 KB
/
Program.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef GLSLPROGRAM_H
#define GLSLPROGRAM_H
#ifdef WIN32
#pragma warning( disable : 4290 )
#endif
#ifdef OMEGALIB_MODULE
#include <omegaGl.h>
#else
#include "app/GLInclude.h"
#endif
#include <string>
using std::string;
#include <map>
#include <glm/glm.hpp>
using glm::vec2;
using glm::vec3;
using glm::vec4;
using glm::mat4;
using glm::mat3;
#include <stdexcept>
namespace tessterrain {
class GLSLProgramException : public std::runtime_error {
public:
GLSLProgramException( const string & msg ) :
std::runtime_error(msg) { }
};
namespace GLSLShader {
enum GLSLShaderType {
VERTEX = GL_VERTEX_SHADER,
FRAGMENT = GL_FRAGMENT_SHADER,
GEOMETRY = GL_GEOMETRY_SHADER,
TESS_CONTROL = GL_TESS_CONTROL_SHADER,
TESS_EVALUATION = GL_TESS_EVALUATION_SHADER,
COMPUTE = GL_COMPUTE_SHADER
};
};
class GLSLProgram
{
private:
int handle;
bool linked;
std::map<string, int> uniformLocations;
GLint getUniformLocation(const char * name );
bool fileExists( const string & fileName );
string getExtension( const char * fileName );
// Make these private in order to make the object non-copyable
GLSLProgram( const GLSLProgram & other ) { }
GLSLProgram & operator=( const GLSLProgram &other ) { return *this; }
public:
GLSLProgram();
~GLSLProgram();
void compileShader( const char *fileName ) throw (GLSLProgramException);
void compileShader( const char * fileName, GLSLShader::GLSLShaderType type ) throw (GLSLProgramException);
void compileShader( const string & source, GLSLShader::GLSLShaderType type,
const char *fileName = NULL ) throw (GLSLProgramException);
void link() throw (GLSLProgramException);
void validate() throw(GLSLProgramException);
void bind() throw (GLSLProgramException);
void unbind();
int getHandle();
bool isLinked();
void bindAttribLocation( GLuint location, const char * name);
void bindFragDataLocation( GLuint location, const char * name );
void setUniform( const char *name, float x, float y, float z);
void setUniform( const char *name, const vec2 & v);
void setUniform( const char *name, const vec3 & v);
void setUniform( const char *name, const vec4 & v);
void setUniform( const char *name, const mat4 & m);
void setUniform( const char *name, const mat3 & m);
void setUniform( const char *name, float val );
void setUniform( const char *name, int val );
void setUniform( const char *name, bool val );
void setUniform( const char *name, GLuint val );
void printActiveUniforms();
void printActiveUniformBlocks();
void printActiveAttribs();
const char * getTypeString( GLenum type );
};
}; //namespace tessterrain
#endif // GLSLPROGRAM_H