22 #ifndef GRAPHICS_OPENGL_SHADER_H 23 #define GRAPHICS_OPENGL_SHADER_H 25 #include "common/file.h" 26 #include "common/array.h" 27 #include "common/ptr.h" 29 #include "math/matrix3.h" 30 #include "math/matrix4.h" 31 #include "math/vector2d.h" 32 #include "math/vector3d.h" 33 #include "math/vector4d.h" 35 #include "graphics/opengl/debug.h" 36 #include "graphics/opengl/system_headers.h" 42 _enabled(
false), _idx(idx), _name(name), _vbo(0), _size(0),
43 _type(GL_FLOAT), _normalized(
false), _stride(0), _pointer(0) {}
66 void use(
bool forceReload =
false);
68 bool setUniform(
const Common::String &uniform,
const Math::Matrix4 &m) {
69 GLint pos = getUniformLocation(uniform);
72 GL_CALL(glUniformMatrix4fv(pos, 1, GL_FALSE, m.getData()));
79 bool setUniform(
const Common::String &uniform,
const Math::Matrix3 &m) {
80 GLint pos = getUniformLocation(uniform);
83 GL_CALL(glUniformMatrix3fv(pos, 1, GL_FALSE, m.getData()));
90 bool setUniform(
const Common::String &uniform,
const Math::Vector4d &v) {
91 GLint pos = getUniformLocation(uniform);
94 GL_CALL(glUniform4fv(pos, 1, v.getData()));
101 bool setUniform(
const Common::String &uniform,
const Math::Vector3d &v) {
102 GLint pos = getUniformLocation(uniform);
105 GL_CALL(glUniform3fv(pos, 1, v.getData()));
112 bool setUniform(
const Common::String &uniform,
const Math::Vector2d &v) {
113 GLint pos = getUniformLocation(uniform);
116 GL_CALL(glUniform2fv(pos, 1, v.getData()));
124 GLint pos = getUniformLocation(uniform);
127 GL_CALL(glUniform1i(pos, x));
134 bool setUniform(
const Common::String &uniform,
const int size,
const int *array) {
135 GLint pos = getUniformLocation(uniform);
138 GL_CALL(glUniform1iv(pos, size, array));
147 GLint pos = getUniformLocation(uniform);
150 GL_CALL(glUniform1f(pos, f));
158 UniformsMap::iterator kv = _uniforms->find(uniform);
159 if (kv == _uniforms->end()) {
161 GL_ASSIGN(ret, glGetUniformLocation(*_shaderNo, uniform.c_str()));
162 _uniforms->setVal(uniform, ret);
169 void enableVertexAttribute(
const char *attrib, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
const void *pointer);
170 void enableVertexAttribute(
const char *attrib, GLuint vbo, GLint size, GLenum type, GLboolean normalized, GLsizei stride, uint32 offset);
171 void disableVertexAttribute(
const char *attrib,
int size,
const float *data);
173 void disableVertexAttribute(
const char *attrib,
const Math::Matrix<r,1> &m) {
174 disableVertexAttribute(attrib, r, m.getData());
176 bool addAttribute(
const char *attrib);
180 static GLuint createBuffer(GLenum target, GLsizeiptr size,
const GLvoid* data, GLenum usage = GL_STATIC_DRAW);
181 static void freeBuffer(GLuint vbo);
197 static Shader *fromFiles(
const char *vertex,
const char *fragment,
const char *
const *attributes,
int compatGLSLVersion = 120);
198 static Shader *fromFiles(
const char *shared,
const char *
const *attributes,
int compatGLSLVersion = 120) {
199 return fromFiles(shared, shared, attributes, compatGLSLVersion);
216 static Shader *fromStrings(
const Common::String &name,
const char *vertex,
const char *fragment,
const char *
const *attributes,
int compatGLSLVersion = 0);
218 bool loadFromFiles(
const char *vertex,
const char *fragment,
const char *
const *attributes,
int compatGLSLVersion = 120);
219 bool loadFromStrings(
const Common::String &name,
const char *vertex,
const char *fragment,
const char *
const *attributes,
int compatGLSLVersion = 0);
236 size_t vertexCount,
const char *
const *vertex,
237 size_t fragmentCount,
const char *
const *fragment,
238 const char *
const *attributes);
243 bool hasError() {
return !_error.empty(); }
246 bool loadShader(
const Common::String &name, GLuint vertexShader, GLuint fragmentShader,
const char *
const *attributes);
248 GLuint createCompatShader(
const char *shaderSource, GLenum shaderType,
const Common::String &name,
int compatGLSLVersion);
249 GLuint createDirectShader(
size_t shaderSourcesCount,
const char *
const *shaderSources, GLenum shaderType,
const Common::String &name);
250 GLuint loadShaderFromFile(
const char *base,
const char *extension, GLenum shaderType,
int compatGLSLVersion);
262 static Shader *_previousShader;
263 static uint32 previousNumAttributes;
Definition: renderbuffer.h:27