aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl/pipeline.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2016-01-04 11:38:21 +0100
committerJohannes Schickel2016-03-16 20:29:27 +0100
commit0fe580d10c6fb73a90eccb046c8dcbf84b062b16 (patch)
tree374a7e245e5b39caa120de0ae9c4e3d19dba60ee /backends/graphics/opengl/pipeline.cpp
parent0b46af2f0e5eef939daa73d5b38b6b817c78c7d8 (diff)
downloadscummvm-rg350-0fe580d10c6fb73a90eccb046c8dcbf84b062b16.tar.gz
scummvm-rg350-0fe580d10c6fb73a90eccb046c8dcbf84b062b16.tar.bz2
scummvm-rg350-0fe580d10c6fb73a90eccb046c8dcbf84b062b16.zip
OPENGL: Make shader/framebuffer part of pipeline state.
Diffstat (limited to 'backends/graphics/opengl/pipeline.cpp')
-rw-r--r--backends/graphics/opengl/pipeline.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/backends/graphics/opengl/pipeline.cpp b/backends/graphics/opengl/pipeline.cpp
index 362f15a36b..500597cc3d 100644
--- a/backends/graphics/opengl/pipeline.cpp
+++ b/backends/graphics/opengl/pipeline.cpp
@@ -22,9 +22,29 @@
#include "backends/graphics/opengl/pipeline.h"
#include "backends/graphics/opengl/shader.h"
+#include "backends/graphics/opengl/framebuffer.h"
namespace OpenGL {
+Pipeline::Pipeline()
+ : _activeFramebuffer(nullptr) {
+}
+
+Framebuffer *Pipeline::setFramebuffer(Framebuffer *framebuffer) {
+ Framebuffer *oldFramebuffer = _activeFramebuffer;
+ if (oldFramebuffer) {
+ oldFramebuffer->deactivate();
+ }
+
+ _activeFramebuffer = framebuffer;
+ if (_activeFramebuffer) {
+ _activeFramebuffer->activate();
+ setProjectionMatrix(_activeFramebuffer->getProjectionMatrix());
+ }
+
+ return oldFramebuffer;
+}
+
#if !USE_FORCED_GLES2
void FixedPipeline::activate() {
GL_CALL(glDisable(GL_LIGHTING));
@@ -51,9 +71,21 @@ void FixedPipeline::setDrawCoordinates(const GLfloat *vertices, const GLfloat *t
GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texCoords));
GL_CALL(glVertexPointer(2, GL_FLOAT, 0, vertices));
}
+
+void FixedPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) {
+ GL_CALL(glMatrixMode(GL_PROJECTION));
+ GL_CALL(glLoadMatrixf(projectionMatrix));
+
+ GL_CALL(glMatrixMode(GL_MODELVIEW));
+ GL_CALL(glLoadIdentity());
+}
#endif // !USE_FORCED_GLES2
#if !USE_FORCED_GLES
+ShaderPipeline::ShaderPipeline()
+ : _activeShader(nullptr) {
+}
+
void ShaderPipeline::activate() {
GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation));
GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation));
@@ -63,6 +95,17 @@ void ShaderPipeline::activate() {
}
}
+Shader *ShaderPipeline::setShader(Shader *shader) {
+ Shader *oldShader = _activeShader;
+
+ _activeShader = shader;
+ if (_activeShader && _activeFramebuffer) {
+ _activeShader->activate(_activeFramebuffer->getProjectionMatrix());
+ }
+
+ return oldShader;
+}
+
void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a));
}
@@ -71,6 +114,12 @@ void ShaderPipeline::setDrawCoordinates(const GLfloat *vertices, const GLfloat *
GL_CALL(glVertexAttribPointer(kTexCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords));
GL_CALL(glVertexAttribPointer(kPositionAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, vertices));
}
+
+void ShaderPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) {
+ if (_activeShader) {
+ _activeShader->activate(projectionMatrix);
+ }
+}
#endif // !USE_FORCED_GLES
} // End of namespace OpenGL