aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl/shader.h
diff options
context:
space:
mode:
authorJohannes Schickel2015-12-20 09:30:11 +0100
committerJohannes Schickel2016-03-16 20:29:25 +0100
commitfee1aa550203c3f46ff19afbe19a7baa4771a5cd (patch)
tree86f44f6b8f838f196eb2db5e7e824353c47c7c48 /backends/graphics/opengl/shader.h
parent19abd8ccbba339c2ea9691ef017a447b7c47701e (diff)
downloadscummvm-rg350-fee1aa550203c3f46ff19afbe19a7baa4771a5cd.tar.gz
scummvm-rg350-fee1aa550203c3f46ff19afbe19a7baa4771a5cd.tar.bz2
scummvm-rg350-fee1aa550203c3f46ff19afbe19a7baa4771a5cd.zip
OPENGL: Add support for shaders with GL contexts.
Diffstat (limited to 'backends/graphics/opengl/shader.h')
-rw-r--r--backends/graphics/opengl/shader.h77
1 files changed, 68 insertions, 9 deletions
diff --git a/backends/graphics/opengl/shader.h b/backends/graphics/opengl/shader.h
index e8535e0225..8c457f8f91 100644
--- a/backends/graphics/opengl/shader.h
+++ b/backends/graphics/opengl/shader.h
@@ -25,7 +25,7 @@
#include "backends/graphics/opengl/opengl-sys.h"
-#if !USE_FORCED_GL && !USE_FORCED_GLES
+#if !USE_FORCED_GLES
#include "common/str.h"
@@ -38,12 +38,18 @@ enum {
};
extern const char *const g_defaultVertexShader;
-extern const char *const g_defaultFragmentShader;
+#if !USE_FORCED_GLES2
+extern const char *const g_defaultFragmentShaderGL;
+#endif
+#if !USE_FORCED_GL
+extern const char *const g_defaultFragmentShaderGLES2;
+#endif
class Shader {
public:
- Shader(const Common::String &vertex, const Common::String &fragment);
- ~Shader() { destroy(); }
+ Shader(const Common::String &vertex, const Common::String &fragment)
+ : _vertex(vertex), _fragment(fragment) {}
+ virtual ~Shader() {}
/**
* Destroy the shader program.
@@ -51,22 +57,22 @@ public:
* This keeps the vertex and fragment shader sources around and thus
* allows for recreating the shader on context recreation.
*/
- void destroy();
+ virtual void destroy() = 0;
/**
* Recreate shader program.
*
* @return true on success, false on failure.
*/
- bool recreate();
+ virtual bool recreate() = 0;
/**
* Make shader active.
*
* @param projectionMatrix Projection matrix to use.
*/
- void activate(const GLfloat *projectionMatrix);
-private:
+ virtual void activate(const GLfloat *projectionMatrix) = 0;
+protected:
/**
* Vertex shader sources.
*/
@@ -76,7 +82,59 @@ private:
* Fragment shader sources.
*/
const Common::String _fragment;
+};
+
+#if !USE_FORCED_GLES2
+class ShaderARB : public Shader {
+public:
+ ShaderARB(const Common::String &vertex, const Common::String &fragment);
+ virtual ~ShaderARB() { destroy(); }
+
+ virtual void destroy();
+
+ virtual bool recreate();
+ virtual void activate(const GLfloat *projectionMatrix);
+private:
+ /**
+ * Shader program handle.
+ */
+ GLhandleARB _program;
+
+ /**
+ * Location of the matrix uniform in the shader program.
+ */
+ GLint _projectionLocation;
+
+ /**
+ * Location of the texture sampler location in the shader program.
+ */
+ GLint _textureLocation;
+
+ /**
+ * Compile a vertex or fragment shader.
+ *
+ * @param source Sources to the shader.
+ * @param shaderType Type of shader to compile (GL_FRAGMENT_SHADER_ARB or
+ * GL_VERTEX_SHADER_ARB)
+ * @return The shader object or 0 on failure.
+ */
+ static GLhandleARB compileShader(const char *source, GLenum shaderType);
+};
+#endif // !USE_FORCED_GLES2
+
+#if !USE_FORCED_GL
+class ShaderGLES2 : public Shader {
+public:
+ ShaderGLES2(const Common::String &vertex, const Common::String &fragment);
+ virtual ~ShaderGLES2() { destroy(); }
+
+ virtual void destroy();
+
+ virtual bool recreate();
+
+ virtual void activate(const GLfloat *projectionMatrix);
+private:
/**
* Shader program handle.
*/
@@ -102,9 +160,10 @@ private:
*/
static GLuint compileShader(const char *source, GLenum shaderType);
};
+#endif
} // End of namespace OpenGL
-#endif // !USE_FORCED_GL && !USE_FORCED_GLES
+#endif // !USE_FORCED_GLES
#endif