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/context.cpp | 2 +- backends/graphics/opengl/framebuffer.cpp | 2 +- backends/graphics/opengl/opengl-graphics.cpp | 4 +- backends/graphics/opengl/pipeline.cpp | 131 -------------------- backends/graphics/opengl/pipeline.h | 154 ------------------------ backends/graphics/opengl/pipelines/fixed.cpp | 66 ++++++++++ backends/graphics/opengl/pipelines/fixed.h | 45 +++++++ backends/graphics/opengl/pipelines/pipeline.cpp | 47 ++++++++ backends/graphics/opengl/pipelines/pipeline.h | 121 +++++++++++++++++++ backends/graphics/opengl/pipelines/shader.cpp | 73 +++++++++++ backends/graphics/opengl/pipelines/shader.h | 52 ++++++++ backends/graphics/opengl/texture.cpp | 2 +- 12 files changed, 410 insertions(+), 289 deletions(-) delete mode 100644 backends/graphics/opengl/pipeline.cpp delete mode 100644 backends/graphics/opengl/pipeline.h create mode 100644 backends/graphics/opengl/pipelines/fixed.cpp create mode 100644 backends/graphics/opengl/pipelines/fixed.h create mode 100644 backends/graphics/opengl/pipelines/pipeline.cpp create mode 100644 backends/graphics/opengl/pipelines/pipeline.h create mode 100644 backends/graphics/opengl/pipelines/shader.cpp create mode 100644 backends/graphics/opengl/pipelines/shader.h (limited to 'backends/graphics') diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp index 09da353918..d93ecdc517 100644 --- a/backends/graphics/opengl/context.cpp +++ b/backends/graphics/opengl/context.cpp @@ -23,7 +23,7 @@ #include "backends/graphics/opengl/opengl-sys.h" #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/shader.h" -#include "backends/graphics/opengl/pipeline.h" +#include "backends/graphics/opengl/pipelines/pipeline.h" #include "backends/graphics/opengl/framebuffer.h" #include "common/tokenizer.h" diff --git a/backends/graphics/opengl/framebuffer.cpp b/backends/graphics/opengl/framebuffer.cpp index f3332cb469..7191aab8bc 100644 --- a/backends/graphics/opengl/framebuffer.cpp +++ b/backends/graphics/opengl/framebuffer.cpp @@ -22,7 +22,7 @@ #include "backends/graphics/opengl/framebuffer.h" #include "backends/graphics/opengl/texture.h" -#include "backends/graphics/opengl/pipeline.h" +#include "backends/graphics/opengl/pipelines/pipeline.h" namespace OpenGL { diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 6ede6a296c..3322ff5c55 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -23,7 +23,9 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/texture.h" -#include "backends/graphics/opengl/pipeline.h" +#include "backends/graphics/opengl/pipelines/pipeline.h" +#include "backends/graphics/opengl/pipelines/fixed.h" +#include "backends/graphics/opengl/pipelines/shader.h" #include "backends/graphics/opengl/shader.h" #include "common/textconsole.h" diff --git a/backends/graphics/opengl/pipeline.cpp b/backends/graphics/opengl/pipeline.cpp deleted file mode 100644 index 9ac3fe44de..0000000000 --- a/backends/graphics/opengl/pipeline.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* 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/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)); - GL_CALL(glDisable(GL_FOG)); - GL_CALL(glShadeModel(GL_FLAT)); - GL_CALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); - - GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); - GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - -#if !USE_FORCED_GLES - if (g_context.multitextureSupported) { - GL_CALL(glActiveTexture(GL_TEXTURE0)); - } -#endif - GL_CALL(glEnable(GL_TEXTURE_2D)); -} - -void FixedPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { - GL_CALL(glColor4f(r, g, b, a)); -} - -void FixedPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) { - texture.bind(); - - GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texture.getTexCoords())); - GL_CALL(glVertexPointer(2, GL_FLOAT, 0, coordinates)); - GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); -} - -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)); - - 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 diff --git a/backends/graphics/opengl/pipeline.h b/backends/graphics/opengl/pipeline.h deleted file mode 100644 index 5ec52f2f28..0000000000 --- a/backends/graphics/opengl/pipeline.h +++ /dev/null @@ -1,154 +0,0 @@ -/* 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_PIEPLINE_H -#define BACKENDS_GRAPHICS_OPENGL_PIEPLINE_H - -#include "backends/graphics/opengl/opengl-sys.h" -#include "backends/graphics/opengl/texture.h" - -namespace OpenGL { - -class Framebuffer; -#if !USE_FORCED_GLES -class Shader; -#endif - -/** - * Interface for OpenGL pipeline functionality. - * - * This encapsulates differences in various rendering pipelines used for - * OpenGL, OpenGL ES 1, and OpenGL ES 2. - */ -class Pipeline { -public: - Pipeline(); - virtual ~Pipeline() {} - - /** - * Activate the pipeline. - * - * This sets the OpenGL state to make use of drawing with the given - * OpenGL pipeline. - */ - virtual void activate() = 0; - - /** - * Set framebuffer to render to. - * - * Client is responsible for any memory management related to framebuffer. - * - * @param framebuffer Framebuffer to activate. - * @return Formerly active framebuffer. - */ - Framebuffer *setFramebuffer(Framebuffer *framebuffer); - -#if !USE_FORCED_GLES - /** - * Set shader program. - * - * Not all pipelines support shader programs. This is method exits at this - * place for convenience only. - * - * Client is responsible for any memory management related to shader. - * - * @param shader Shader program to activate. - * @return Formerly active shader program. - */ - virtual Shader *setShader(Shader *shader) { return nullptr; } -#endif - - /** - * Set modulation color. - * - * @param r Red component in [0,1]. - * @param g Green component in [0,1]. - * @param b Blue component in [0,1]. - * @param a Alpha component in [0,1]. - */ - virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = 0; - - /** - * Draw a texture rectangle to the currently active framebuffer. - * - * @param texture Texture to use for drawing. - * @param coordinates x1, y1, x2, y2 coordinates where to draw the texture. - */ - virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates) = 0; - - void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { - const GLfloat coordinates[4*2] = { - x, y, - x + w, y, - x, y + h, - x + w, y + h - }; - drawTexture(texture, coordinates); - } - - /** - * Set the projection matrix. - * - * This is intended to be only ever be used by Framebuffer subclasses. - */ - virtual void setProjectionMatrix(const GLfloat *projectionMatrix) = 0; - -protected: - Framebuffer *_activeFramebuffer; -}; - -#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); -}; -#endif // !USE_FORCED_GLES2 - -#if !USE_FORCED_GLES -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); - - virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates); - - virtual void setProjectionMatrix(const GLfloat *projectionMatrix); - -private: - Shader *_activeShader; -}; -#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 new file mode 100644 index 0000000000..1d671d112e --- /dev/null +++ b/backends/graphics/opengl/pipelines/fixed.cpp @@ -0,0 +1,66 @@ +/* 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/fixed.h" + +namespace OpenGL { + +#if !USE_FORCED_GLES2 +void FixedPipeline::activate() { + GL_CALL(glDisable(GL_LIGHTING)); + GL_CALL(glDisable(GL_FOG)); + GL_CALL(glShadeModel(GL_FLAT)); + GL_CALL(glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)); + + GL_CALL(glEnableClientState(GL_VERTEX_ARRAY)); + GL_CALL(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); + +#if !USE_FORCED_GLES + if (g_context.multitextureSupported) { + GL_CALL(glActiveTexture(GL_TEXTURE0)); + } +#endif + GL_CALL(glEnable(GL_TEXTURE_2D)); +} + +void FixedPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { + GL_CALL(glColor4f(r, g, b, a)); +} + +void FixedPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) { + texture.bind(); + + GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texture.getTexCoords())); + GL_CALL(glVertexPointer(2, GL_FLOAT, 0, coordinates)); + GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); +} + +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 + +} // End of namespace OpenGL diff --git a/backends/graphics/opengl/pipelines/fixed.h b/backends/graphics/opengl/pipelines/fixed.h new file mode 100644 index 0000000000..f344ef1364 --- /dev/null +++ b/backends/graphics/opengl/pipelines/fixed.h @@ -0,0 +1,45 @@ +/* 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_FIXED_H +#define BACKENDS_GRAPHICS_OPENGL_PIPELINES_FIXED_H + +#include "backends/graphics/opengl/pipelines/pipeline.h" + +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); +}; +#endif // !USE_FORCED_GLES2 + +} // End of namespace OpenGL + +#endif diff --git a/backends/graphics/opengl/pipelines/pipeline.cpp b/backends/graphics/opengl/pipelines/pipeline.cpp new file mode 100644 index 0000000000..64121d512a --- /dev/null +++ b/backends/graphics/opengl/pipelines/pipeline.cpp @@ -0,0 +1,47 @@ +/* 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/pipeline.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; +} + +} // End of namespace OpenGL diff --git a/backends/graphics/opengl/pipelines/pipeline.h b/backends/graphics/opengl/pipelines/pipeline.h new file mode 100644 index 0000000000..8509a26f8f --- /dev/null +++ b/backends/graphics/opengl/pipelines/pipeline.h @@ -0,0 +1,121 @@ +/* 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_PIPELINE_H +#define BACKENDS_GRAPHICS_OPENGL_PIPELINES_PIPELINE_H + +#include "backends/graphics/opengl/opengl-sys.h" +#include "backends/graphics/opengl/texture.h" + +namespace OpenGL { + +class Framebuffer; +#if !USE_FORCED_GLES +class Shader; +#endif + +/** + * Interface for OpenGL pipeline functionality. + * + * This encapsulates differences in various rendering pipelines used for + * OpenGL, OpenGL ES 1, and OpenGL ES 2. + */ +class Pipeline { +public: + Pipeline(); + virtual ~Pipeline() {} + + /** + * Activate the pipeline. + * + * This sets the OpenGL state to make use of drawing with the given + * OpenGL pipeline. + */ + virtual void activate() = 0; + + /** + * Set framebuffer to render to. + * + * Client is responsible for any memory management related to framebuffer. + * + * @param framebuffer Framebuffer to activate. + * @return Formerly active framebuffer. + */ + Framebuffer *setFramebuffer(Framebuffer *framebuffer); + +#if !USE_FORCED_GLES + /** + * Set shader program. + * + * Not all pipelines support shader programs. This is method exits at this + * place for convenience only. + * + * Client is responsible for any memory management related to shader. + * + * @param shader Shader program to activate. + * @return Formerly active shader program. + */ + virtual Shader *setShader(Shader *shader) { return nullptr; } +#endif + + /** + * Set modulation color. + * + * @param r Red component in [0,1]. + * @param g Green component in [0,1]. + * @param b Blue component in [0,1]. + * @param a Alpha component in [0,1]. + */ + virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = 0; + + /** + * Draw a texture rectangle to the currently active framebuffer. + * + * @param texture Texture to use for drawing. + * @param coordinates x1, y1, x2, y2 coordinates where to draw the texture. + */ + virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates) = 0; + + void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { + const GLfloat coordinates[4*2] = { + x, y, + x + w, y, + x, y + h, + x + w, y + h + }; + drawTexture(texture, coordinates); + } + + /** + * Set the projection matrix. + * + * This is intended to be only ever be used by Framebuffer subclasses. + */ + virtual void setProjectionMatrix(const GLfloat *projectionMatrix) = 0; + +protected: + Framebuffer *_activeFramebuffer; +}; + +} // End of namespace OpenGL + +#endif 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 diff --git a/backends/graphics/opengl/pipelines/shader.h b/backends/graphics/opengl/pipelines/shader.h new file mode 100644 index 0000000000..96e15803f0 --- /dev/null +++ b/backends/graphics/opengl/pipelines/shader.h @@ -0,0 +1,52 @@ +/* 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_SHADER_H +#define BACKENDS_GRAPHICS_OPENGL_PIPELINES_SHADER_H + +#include "backends/graphics/opengl/pipelines/pipeline.h" + +namespace OpenGL { + +#if !USE_FORCED_GLES +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); + + virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates); + + virtual void setProjectionMatrix(const GLfloat *projectionMatrix); + +private: + Shader *_activeShader; +}; +#endif // !USE_FORCED_GLES + +} // End of namespace OpenGL + +#endif diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp index 8746527d5b..b0e474d415 100644 --- a/backends/graphics/opengl/texture.cpp +++ b/backends/graphics/opengl/texture.cpp @@ -22,7 +22,7 @@ #include "backends/graphics/opengl/texture.h" #include "backends/graphics/opengl/shader.h" -#include "backends/graphics/opengl/pipeline.h" +#include "backends/graphics/opengl/pipelines/pipeline.h" #include "backends/graphics/opengl/framebuffer.h" #include "common/rect.h" -- cgit v1.2.3