aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2016-02-28 23:58:04 +0100
committerJohannes Schickel2016-03-16 20:29:30 +0100
commit26f106497a863b84c502d122b5ba749176b2c426 (patch)
tree1cb6290feea5a889f2401587e92ec67841208f11
parent8a4938f82b05b86c8f0ed010210eb6d1847c04c9 (diff)
downloadscummvm-rg350-26f106497a863b84c502d122b5ba749176b2c426.tar.gz
scummvm-rg350-26f106497a863b84c502d122b5ba749176b2c426.tar.bz2
scummvm-rg350-26f106497a863b84c502d122b5ba749176b2c426.zip
OPENGL: Implement CLUT8 look up as Pipeline.
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp1
-rw-r--r--backends/graphics/opengl/pipelines/clut8.cpp53
-rw-r--r--backends/graphics/opengl/pipelines/clut8.h48
-rw-r--r--backends/graphics/opengl/pipelines/fixed.cpp6
-rw-r--r--backends/graphics/opengl/pipelines/fixed.h5
-rw-r--r--backends/graphics/opengl/pipelines/pipeline.cpp27
-rw-r--r--backends/graphics/opengl/pipelines/pipeline.h25
-rw-r--r--backends/graphics/opengl/pipelines/shader.cpp2
-rw-r--r--backends/graphics/opengl/pipelines/shader.h6
-rw-r--r--backends/graphics/opengl/texture.cpp28
-rw-r--r--backends/graphics/opengl/texture.h4
-rw-r--r--backends/module.mk1
12 files changed, 175 insertions, 31 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 3322ff5c55..c5bc99eb70 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -866,7 +866,6 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def
#if !USE_FORCED_GLES
if (g_context.shadersSupported) {
ShaderMan.notifyCreate();
-
g_context.getActivePipeline()->setShader(ShaderMan.query(ShaderManager::kDefault));
}
#endif
diff --git a/backends/graphics/opengl/pipelines/clut8.cpp b/backends/graphics/opengl/pipelines/clut8.cpp
new file mode 100644
index 0000000000..69dd0a3e28
--- /dev/null
+++ b/backends/graphics/opengl/pipelines/clut8.cpp
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "backends/graphics/opengl/pipelines/clut8.h"
+#include "backends/graphics/opengl/shader.h"
+#include "backends/graphics/opengl/framebuffer.h"
+
+namespace OpenGL {
+
+#if !USE_FORCED_GLES
+CLUT8LookUpPipeline::CLUT8LookUpPipeline()
+ : _paletteTexture(nullptr) {
+ ShaderPipeline::setShader(ShaderMan.query(ShaderManager::kCLUT8LookUp));
+}
+
+Shader *CLUT8LookUpPipeline::setShader(Shader *shader) {
+ return ShaderPipeline::setShader(ShaderMan.query(ShaderManager::kCLUT8LookUp));
+}
+
+void CLUT8LookUpPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
+ _activeShader->setUniformI(_activeShader->getUniformLocation("palette"), 1);
+
+ // Set the palette texture.
+ GL_CALL(glActiveTexture(GL_TEXTURE1));
+ if (_paletteTexture) {
+ _paletteTexture->bind();
+ }
+
+ GL_CALL(glActiveTexture(GL_TEXTURE0));
+ ShaderPipeline::drawTexture(texture, coordinates);
+}
+#endif // !USE_FORCED_GLES
+
+} // End of namespace OpenGL
diff --git a/backends/graphics/opengl/pipelines/clut8.h b/backends/graphics/opengl/pipelines/clut8.h
new file mode 100644
index 0000000000..fed6cbfe32
--- /dev/null
+++ b/backends/graphics/opengl/pipelines/clut8.h
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_GRAPHICS_OPENGL_PIPELINES_CLUT8_H
+#define BACKENDS_GRAPHICS_OPENGL_PIPELINES_CLUT8_H
+
+#include "backends/graphics/opengl/pipelines/shader.h"
+
+namespace OpenGL {
+
+#if !USE_FORCED_GLES
+class CLUT8LookUpPipeline : public ShaderPipeline {
+public:
+ CLUT8LookUpPipeline();
+
+ virtual Shader *setShader(Shader *shader);
+
+ void setPaletteTexture(const GLTexture *paletteTexture) { _paletteTexture = paletteTexture; }
+
+ virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates);
+
+private:
+ const GLTexture *_paletteTexture;
+};
+#endif // !USE_FORCED_GLES
+
+} // End of namespace OpenGL
+
+#endif
diff --git a/backends/graphics/opengl/pipelines/fixed.cpp b/backends/graphics/opengl/pipelines/fixed.cpp
index 1d671d112e..8e3bd7eaee 100644
--- a/backends/graphics/opengl/pipelines/fixed.cpp
+++ b/backends/graphics/opengl/pipelines/fixed.cpp
@@ -25,7 +25,7 @@
namespace OpenGL {
#if !USE_FORCED_GLES2
-void FixedPipeline::activate() {
+void FixedPipeline::activateInternal() {
GL_CALL(glDisable(GL_LIGHTING));
GL_CALL(glDisable(GL_FOG));
GL_CALL(glShadeModel(GL_FLAT));
@@ -55,6 +55,10 @@ void FixedPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordin
}
void FixedPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) {
+ if (!isActive()) {
+ return;
+ }
+
GL_CALL(glMatrixMode(GL_PROJECTION));
GL_CALL(glLoadMatrixf(projectionMatrix));
diff --git a/backends/graphics/opengl/pipelines/fixed.h b/backends/graphics/opengl/pipelines/fixed.h
index f344ef1364..6bfe140c19 100644
--- a/backends/graphics/opengl/pipelines/fixed.h
+++ b/backends/graphics/opengl/pipelines/fixed.h
@@ -30,13 +30,14 @@ namespace OpenGL {
#if !USE_FORCED_GLES2
class FixedPipeline : public Pipeline {
public:
- virtual void activate();
-
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates);
virtual void setProjectionMatrix(const GLfloat *projectionMatrix);
+
+protected:
+ virtual void activateInternal();
};
#endif // !USE_FORCED_GLES2
diff --git a/backends/graphics/opengl/pipelines/pipeline.cpp b/backends/graphics/opengl/pipelines/pipeline.cpp
index 64121d512a..f79a923f86 100644
--- a/backends/graphics/opengl/pipelines/pipeline.cpp
+++ b/backends/graphics/opengl/pipelines/pipeline.cpp
@@ -26,17 +26,38 @@
namespace OpenGL {
Pipeline::Pipeline()
- : _activeFramebuffer(nullptr) {
+ : _activeFramebuffer(nullptr), _isActive(false) {
+}
+
+void Pipeline::activate() {
+ _isActive = true;
+
+ if (_activeFramebuffer) {
+ _activeFramebuffer->activate();
+ setProjectionMatrix(_activeFramebuffer->getProjectionMatrix());
+ }
+
+ activateInternal();
+}
+
+void Pipeline::deactivate() {
+ deactivateInternal();
+
+ if (_activeFramebuffer) {
+ _activeFramebuffer->deactivate();
+ }
+
+ _isActive = false;
}
Framebuffer *Pipeline::setFramebuffer(Framebuffer *framebuffer) {
Framebuffer *oldFramebuffer = _activeFramebuffer;
- if (oldFramebuffer) {
+ if (_isActive && oldFramebuffer) {
oldFramebuffer->deactivate();
}
_activeFramebuffer = framebuffer;
- if (_activeFramebuffer) {
+ if (_isActive && _activeFramebuffer) {
_activeFramebuffer->activate();
setProjectionMatrix(_activeFramebuffer->getProjectionMatrix());
}
diff --git a/backends/graphics/opengl/pipelines/pipeline.h b/backends/graphics/opengl/pipelines/pipeline.h
index 8509a26f8f..8545ef2101 100644
--- a/backends/graphics/opengl/pipelines/pipeline.h
+++ b/backends/graphics/opengl/pipelines/pipeline.h
@@ -50,7 +50,12 @@ public:
* This sets the OpenGL state to make use of drawing with the given
* OpenGL pipeline.
*/
- virtual void activate() = 0;
+ void activate();
+
+ /**
+ * Deactivate the pipeline.
+ */
+ void deactivate();
/**
* Set framebuffer to render to.
@@ -113,7 +118,25 @@ public:
virtual void setProjectionMatrix(const GLfloat *projectionMatrix) = 0;
protected:
+ /**
+ * Activate the pipeline.
+ *
+ * This sets the OpenGL state to make use of drawing with the given
+ * OpenGL pipeline.
+ */
+ virtual void activateInternal() = 0;
+
+ /**
+ * Deactivate the pipeline.
+ */
+ virtual void deactivateInternal() {}
+
+ bool isActive() const { return _isActive; }
+
Framebuffer *_activeFramebuffer;
+
+private:
+ bool _isActive;
};
} // End of namespace OpenGL
diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp
index 42f511d147..f408b682ab 100644
--- a/backends/graphics/opengl/pipelines/shader.cpp
+++ b/backends/graphics/opengl/pipelines/shader.cpp
@@ -31,7 +31,7 @@ ShaderPipeline::ShaderPipeline()
: _activeShader(nullptr) {
}
-void ShaderPipeline::activate() {
+void ShaderPipeline::activateInternal() {
GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation));
GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation));
diff --git a/backends/graphics/opengl/pipelines/shader.h b/backends/graphics/opengl/pipelines/shader.h
index 96e15803f0..a5b94e89f5 100644
--- a/backends/graphics/opengl/pipelines/shader.h
+++ b/backends/graphics/opengl/pipelines/shader.h
@@ -32,8 +32,6 @@ class ShaderPipeline : public Pipeline {
public:
ShaderPipeline();
- virtual void activate();
-
virtual Shader *setShader(Shader *shader);
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
@@ -42,7 +40,9 @@ public:
virtual void setProjectionMatrix(const GLfloat *projectionMatrix);
-private:
+protected:
+ virtual void activateInternal();
+
Shader *_activeShader;
};
#endif // !USE_FORCED_GLES
diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp
index b0e474d415..79e3acc7c0 100644
--- a/backends/graphics/opengl/texture.cpp
+++ b/backends/graphics/opengl/texture.cpp
@@ -23,6 +23,7 @@
#include "backends/graphics/opengl/texture.h"
#include "backends/graphics/opengl/shader.h"
#include "backends/graphics/opengl/pipelines/pipeline.h"
+#include "backends/graphics/opengl/pipelines/clut8.h"
#include "backends/graphics/opengl/framebuffer.h"
#include "common/rect.h"
@@ -489,15 +490,19 @@ void TextureRGB555::updateTexture() {
TextureCLUT8GPU::TextureCLUT8GPU()
: _clut8Texture(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE),
_paletteTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
- _target(new TextureTarget()), _clut8Vertices(), _paletteLocation(-1),
- _clut8Data(), _userPixelData(), _palette(), _paletteDirty(false) {
+ _target(new TextureTarget()), _clut8Pipeline(new CLUT8LookUpPipeline()),
+ _clut8Vertices(), _clut8Data(), _userPixelData(), _palette(),
+ _paletteDirty(false) {
// Allocate space for 256 colors.
_paletteTexture.setSize(256, 1);
- _paletteLocation = ShaderMan.query(ShaderManager::kCLUT8LookUp)->getUniformLocation("palette");
+ // Setup pipeline.
+ _clut8Pipeline->setFramebuffer(_target);
+ _clut8Pipeline->setPaletteTexture(&_paletteTexture);
}
TextureCLUT8GPU::~TextureCLUT8GPU() {
+ delete _clut8Pipeline;
delete _target;
_clut8Data.free();
}
@@ -511,7 +516,6 @@ void TextureCLUT8GPU::destroy() {
void TextureCLUT8GPU::recreate() {
_clut8Texture.create();
_paletteTexture.create();
- _paletteLocation = ShaderMan.query(ShaderManager::kCLUT8LookUp)->getUniformLocation("palette");
_target->create();
// In case image date exists assure it will be completely refreshed next
@@ -614,24 +618,14 @@ void TextureCLUT8GPU::updateGLTexture() {
}
void TextureCLUT8GPU::lookUpColors() {
- // Save old state.
- Framebuffer *oldFramebuffer = g_context.getActivePipeline()->setFramebuffer(_target);
-
- Shader *lookUpShader = ShaderMan.query(ShaderManager::kCLUT8LookUp);
- Shader *oldShader = g_context.getActivePipeline()->setShader(lookUpShader);
- lookUpShader->setUniformI(_paletteLocation, 1);
-
- // Set the palette texture.
- GL_CALL(glActiveTexture(GL_TEXTURE1));
- _paletteTexture.bind();
- GL_CALL(glActiveTexture(GL_TEXTURE0));
+ // Setup pipeline to do color look up.
+ Pipeline *oldPipeline = g_context.setPipeline(_clut8Pipeline);
// Do color look up.
g_context.getActivePipeline()->drawTexture(_clut8Texture, _clut8Vertices);
// Restore old state.
- g_context.getActivePipeline()->setShader(oldShader);
- g_context.getActivePipeline()->setFramebuffer(oldFramebuffer);
+ g_context.setPipeline(oldPipeline);
}
#endif // !USE_FORCED_GLES
diff --git a/backends/graphics/opengl/texture.h b/backends/graphics/opengl/texture.h
index 847c76db88..97e99b4b37 100644
--- a/backends/graphics/opengl/texture.h
+++ b/backends/graphics/opengl/texture.h
@@ -321,6 +321,7 @@ private:
#if !USE_FORCED_GLES
class TextureTarget;
+class CLUT8LookUpPipeline;
class TextureCLUT8GPU : public Surface {
public:
@@ -365,11 +366,10 @@ private:
GLTexture _paletteTexture;
TextureTarget *_target;
+ CLUT8LookUpPipeline *_clut8Pipeline;
GLfloat _clut8Vertices[4*2];
- GLint _paletteLocation;
-
Graphics::Surface _clut8Data;
Graphics::Surface _userPixelData;
diff --git a/backends/module.mk b/backends/module.mk
index fd97e19417..70e3ca7ab2 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -58,6 +58,7 @@ MODULE_OBJS += \
graphics/opengl/opengl-graphics.o \
graphics/opengl/shader.o \
graphics/opengl/texture.o \
+ graphics/opengl/pipelines/clut8.o \
graphics/opengl/pipelines/fixed.o \
graphics/opengl/pipelines/pipeline.o \
graphics/opengl/pipelines/shader.o