From 8a4938f82b05b86c8f0ed010210eb6d1847c04c9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 28 Feb 2016 18:15:00 +0100 Subject: OPENGL: Move pipeline code to pipelines/. --- backends/graphics/opengl/pipelines/shader.cpp | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 backends/graphics/opengl/pipelines/shader.cpp (limited to 'backends/graphics/opengl/pipelines/shader.cpp') diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp new file mode 100644 index 0000000000..42f511d147 --- /dev/null +++ b/backends/graphics/opengl/pipelines/shader.cpp @@ -0,0 +1,73 @@ +/* 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/shader.h" +#include "backends/graphics/opengl/shader.h" +#include "backends/graphics/opengl/framebuffer.h" + +namespace OpenGL { + +#if !USE_FORCED_GLES +ShaderPipeline::ShaderPipeline() + : _activeShader(nullptr) { +} + +void ShaderPipeline::activate() { + GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation)); + GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); + + if (g_context.multitextureSupported) { + GL_CALL(glActiveTexture(GL_TEXTURE0)); + } +} + +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)); +} + +void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) { + texture.bind(); + + GL_CALL(glVertexAttribPointer(kTexCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texture.getTexCoords())); + GL_CALL(glVertexAttribPointer(kPositionAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, coordinates)); + GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); +} + +void ShaderPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) { + if (_activeShader) { + _activeShader->activate(projectionMatrix); + } +} +#endif // !USE_FORCED_GLES + +} // End of namespace OpenGL -- cgit v1.2.3 From 26f106497a863b84c502d122b5ba749176b2c426 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 28 Feb 2016 23:58:04 +0100 Subject: OPENGL: Implement CLUT8 look up as Pipeline. --- backends/graphics/opengl/pipelines/shader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/opengl/pipelines/shader.cpp') 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)); -- cgit v1.2.3 From 3f9852eb202b55b93f6e3121ce473951bff033cd Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 29 Feb 2016 00:04:33 +0100 Subject: OPENGL: Make shader pipelines use fixed shaders. --- backends/graphics/opengl/pipelines/shader.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'backends/graphics/opengl/pipelines/shader.cpp') diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp index f408b682ab..69af911fc6 100644 --- a/backends/graphics/opengl/pipelines/shader.cpp +++ b/backends/graphics/opengl/pipelines/shader.cpp @@ -27,8 +27,8 @@ namespace OpenGL { #if !USE_FORCED_GLES -ShaderPipeline::ShaderPipeline() - : _activeShader(nullptr) { +ShaderPipeline::ShaderPipeline(Shader *shader) + : _activeShader(shader) { } void ShaderPipeline::activateInternal() { @@ -40,17 +40,6 @@ void ShaderPipeline::activateInternal() { } } -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)); } @@ -64,7 +53,7 @@ void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordi } void ShaderPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) { - if (_activeShader) { + if (isActive() && _activeShader) { _activeShader->activate(projectionMatrix); } } -- cgit v1.2.3 From baca885cfce10acaa7a9892133aaa5b82c7183f7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 2 Mar 2016 15:16:05 +0100 Subject: OPENGL: Let Shader store the uniform state. --- backends/graphics/opengl/pipelines/shader.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'backends/graphics/opengl/pipelines/shader.cpp') diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp index 69af911fc6..46e81423c5 100644 --- a/backends/graphics/opengl/pipelines/shader.cpp +++ b/backends/graphics/opengl/pipelines/shader.cpp @@ -38,6 +38,12 @@ void ShaderPipeline::activateInternal() { if (g_context.multitextureSupported) { GL_CALL(glActiveTexture(GL_TEXTURE0)); } + + _activeShader->activate(); +} + +void ShaderPipeline::deactivateInternal() { + _activeShader->deactivate(); } void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { @@ -53,9 +59,7 @@ void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordi } void ShaderPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) { - if (isActive() && _activeShader) { - _activeShader->activate(projectionMatrix); - } + _activeShader->setUniform("projection", new ShaderUniformMatrix44(projectionMatrix)); } #endif // !USE_FORCED_GLES -- cgit v1.2.3 From 39100b613272523c2e36be213cc827857a08f824 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 4 Mar 2016 00:14:22 +0100 Subject: OPENGL: Do not hardcode any uniform/attribute handling in Shader. --- backends/graphics/opengl/pipelines/shader.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'backends/graphics/opengl/pipelines/shader.cpp') diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp index 46e81423c5..c7befe22b8 100644 --- a/backends/graphics/opengl/pipelines/shader.cpp +++ b/backends/graphics/opengl/pipelines/shader.cpp @@ -29,11 +29,14 @@ namespace OpenGL { #if !USE_FORCED_GLES ShaderPipeline::ShaderPipeline(Shader *shader) : _activeShader(shader) { + _vertexAttribLocation = shader->getAttributeLocation("position"); + _texCoordAttribLocation = shader->getAttributeLocation("texCoordIn"); + _colorAttribLocation = shader->getAttributeLocation("blendColorIn"); } void ShaderPipeline::activateInternal() { - GL_CALL(glEnableVertexAttribArray(kPositionAttribLocation)); - GL_CALL(glEnableVertexAttribArray(kTexCoordAttribLocation)); + GL_CALL(glEnableVertexAttribArray(_vertexAttribLocation)); + GL_CALL(glEnableVertexAttribArray(_texCoordAttribLocation)); if (g_context.multitextureSupported) { GL_CALL(glActiveTexture(GL_TEXTURE0)); @@ -43,18 +46,21 @@ void ShaderPipeline::activateInternal() { } void ShaderPipeline::deactivateInternal() { + GL_CALL(glDisableVertexAttribArray(_vertexAttribLocation)); + GL_CALL(glDisableVertexAttribArray(_texCoordAttribLocation)); + _activeShader->deactivate(); } void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { - GL_CALL(glVertexAttrib4f(kColorAttribLocation, r, g, b, a)); + GL_CALL(glVertexAttrib4f(_colorAttribLocation, r, g, b, a)); } void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) { texture.bind(); - GL_CALL(glVertexAttribPointer(kTexCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texture.getTexCoords())); - GL_CALL(glVertexAttribPointer(kPositionAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, coordinates)); + GL_CALL(glVertexAttribPointer(_texCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texture.getTexCoords())); + GL_CALL(glVertexAttribPointer(_vertexAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, coordinates)); GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } -- cgit v1.2.3