[Scummvm-git-logs] scummvm master -> 4f0e5ed3c0e6b59c5ef4f20b61d35de5de1db5dc

aquadran noreply at scummvm.org
Mon Jan 10 02:34:52 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4f0e5ed3c0 GRAPHICS: Moved shader code where it's actually used


Commit: 4f0e5ed3c0e6b59c5ef4f20b61d35de5de1db5dc
    https://github.com/scummvm/scummvm/commit/4f0e5ed3c0e6b59c5ef4f20b61d35de5de1db5dc
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2022-01-10T03:34:48+01:00

Commit Message:
GRAPHICS: Moved shader code where it's actually used

Changed paths:
  R graphics/opengl/box_shaders.cpp
  R graphics/opengl/compat_shaders.cpp
  R graphics/opengl/control_shaders.cpp
    backends/graphics3d/android/texture.cpp
    backends/graphics3d/opengl/surfacerenderer.cpp
    backends/platform/android3d/texture.cpp
    graphics/module.mk
    graphics/opengl/shader.cpp
    graphics/opengl/shader.h


diff --git a/backends/graphics3d/android/texture.cpp b/backends/graphics3d/android/texture.cpp
index cd23cb13234..14b098da7c5 100644
--- a/backends/graphics3d/android/texture.cpp
+++ b/backends/graphics3d/android/texture.cpp
@@ -75,12 +75,43 @@ static const GLfloat vertices[] = {
 	1.0, 1.0,
 };
 
+static const char *controlVertex =
+	"#version 100\n"
+	"attribute vec2 position;\n"
+	"attribute vec2 texcoord;\n"
+	"uniform vec2 offsetXY;\n"
+	"uniform vec2 sizeWH;\n"
+	"uniform vec4 clip;\n"
+	"uniform bool flipY;\n"
+	"varying vec2 Texcoord;\n"
+	"void main() {\n"
+		"Texcoord = clip.xy + texcoord * (clip.zw - clip.xy);\n"
+		"vec2 pos = offsetXY + position * sizeWH;\n"
+		"pos.x = pos.x * 2.0 - 1.0;\n"
+		"pos.y = pos.y * 2.0 - 1.0;\n"
+		"if (flipY)\n"
+			"pos.y *= -1.0;\n"
+		"gl_Position = vec4(pos, 0.0, 1.0);\n"
+	"}\n";
+
+static const char *controlFragment =
+	"#version 100\n"
+	"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
+		"precision highp float;\n"
+	"#else\n"
+		"precision mediump float;\n"
+	"#endif\n"
+	"varying vec2 Texcoord;\n"
+	"uniform sampler2D tex;\n"
+	"void main() {\n"
+		"gl_FragColor = texture2D(tex, Texcoord);\n"
+	"}\n";
+
 void GLESBaseTexture::initGL() {
 	_npot_supported = OpenGLContext.NPOTSupported;
 
 	const char *attributes[] = { "position", "texcoord", NULL };
-	_box_shader = OpenGL::ShaderGL::fromStrings("control", OpenGL::BuiltinShaders::controlVertex,
-	              OpenGL::BuiltinShaders::controlFragment, attributes);
+	_box_shader = OpenGL::ShaderGL::fromStrings("control", controlVertex, controlFragment, attributes);
 	_verticesVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
 	_box_shader->enableVertexAttribute("position", _verticesVBO, 2, GL_FLOAT, GL_TRUE,
 	                                   2 * sizeof(float), 0);
diff --git a/backends/graphics3d/opengl/surfacerenderer.cpp b/backends/graphics3d/opengl/surfacerenderer.cpp
index 85af0895fef..6e6ac1c8207 100644
--- a/backends/graphics3d/opengl/surfacerenderer.cpp
+++ b/backends/graphics3d/opengl/surfacerenderer.cpp
@@ -172,6 +172,38 @@ void FixedSurfaceRenderer::restorePreviousState() {
 
 #if defined(USE_OPENGL_SHADERS)
 
+static const char *boxVertex =
+	"attribute vec2 position;\n"
+	"attribute vec2 texcoord;\n"
+	"uniform vec2 offsetXY;\n"
+	"uniform vec2 sizeWH;\n"
+	"uniform vec2 texcrop;\n"
+	"uniform bool flipY;\n"
+	"varying vec2 Texcoord;\n"
+	"void main() {\n"
+		"Texcoord = texcoord * texcrop;\n"
+		"vec2 pos = offsetXY + position * sizeWH;\n"
+		"pos.x = pos.x * 2.0 - 1.0;\n"
+		"pos.y = pos.y * 2.0 - 1.0;\n"
+		"if (flipY)\n"
+			"pos.y *= -1.0;\n"
+		"gl_Position = vec4(pos, 0.0, 1.0);\n"
+	"}\n";
+
+static const char *boxFragment =
+	"#ifdef GL_ES\n"
+		"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
+			"precision highp float;\n"
+		"#else\n"
+			"precision mediump float;\n"
+		"#endif\n"
+	"#endif\n"
+	"varying vec2 Texcoord;\n"
+	"uniform sampler2D tex;\n"
+	"void main() {\n"
+		"gl_FragColor = texture2D(tex, Texcoord);\n"
+	"}\n";
+
 ShaderSurfaceRenderer::ShaderSurfaceRenderer() {
 	const GLfloat vertices[] = {
 		0.0, 0.0,
@@ -182,7 +214,7 @@ ShaderSurfaceRenderer::ShaderSurfaceRenderer() {
 
 	// Setup the box shader used to render the overlay
 	const char *attributes[] = { "position", "texcoord", nullptr };
-	_boxShader = ShaderGL::fromStrings("box", BuiltinShaders::boxVertex, BuiltinShaders::boxFragment, attributes);
+	_boxShader = ShaderGL::fromStrings("box", boxVertex, boxFragment, attributes);
 	_boxVerticesVBO = ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
 	_boxShader->enableVertexAttribute("position", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
 	_boxShader->enableVertexAttribute("texcoord", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
diff --git a/backends/platform/android3d/texture.cpp b/backends/platform/android3d/texture.cpp
index cedd95dae7b..6654d3b1764 100644
--- a/backends/platform/android3d/texture.cpp
+++ b/backends/platform/android3d/texture.cpp
@@ -76,11 +76,43 @@ const GLfloat vertices[] = {
 	1.0, 1.0,
 };
 
+static const char *controlVertex =
+	"#version 100\n"
+	"attribute vec2 position;\n"
+	"attribute vec2 texcoord;\n"
+	"uniform vec2 offsetXY;\n"
+	"uniform vec2 sizeWH;\n"
+	"uniform vec4 clip;\n"
+	"uniform bool flipY;\n"
+	"varying vec2 Texcoord;\n"
+	"void main() {\n"
+		"Texcoord = clip.xy + texcoord * (clip.zw - clip.xy);\n"
+		"vec2 pos = offsetXY + position * sizeWH;\n"
+		"pos.x = pos.x * 2.0 - 1.0;\n"
+		"pos.y = pos.y * 2.0 - 1.0;\n"
+		"if (flipY)\n"
+			"pos.y *= -1.0;\n"
+		"gl_Position = vec4(pos, 0.0, 1.0);\n"
+	"}\n";
+
+static const char *controlFragment =
+	"#version 100\n"
+	"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
+		"precision highp float;\n"
+	"#else\n"
+		"precision mediump float;\n"
+	"#endif\n"
+	"varying vec2 Texcoord;\n"
+	"uniform sampler2D tex;\n"
+	"void main() {\n"
+		"gl_FragColor = texture2D(tex, Texcoord);\n"
+	"}\n";
+
 void GLESBaseTexture::initGL() {
 	npot_supported = OpenGLContext.NPOTSupported;
 
 	const char* attributes[] = { "position", "texcoord", NULL };
-	g_box_shader = OpenGL::ShaderGL::fromStrings("control", OpenGL::BuiltinShaders::controlVertex, OpenGL::BuiltinShaders::controlFragment, attributes);
+	g_box_shader = OpenGL::ShaderGL::fromStrings("control", controlVertex, controlFragment, attributes);
 	g_verticesVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
 	g_box_shader->enableVertexAttribute("position", g_verticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
 	g_box_shader->enableVertexAttribute("texcoord", g_verticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
diff --git a/graphics/module.mk b/graphics/module.mk
index 5c8686f6b1d..70ec14520ca 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -29,10 +29,7 @@ MODULE_OBJS := \
 	macgui/macwindowmanager.o \
 	managed_surface.o \
 	nine_patch.o \
-	opengl/box_shaders.o \
 	opengl/context.o \
-	opengl/control_shaders.o \
-	opengl/compat_shaders.o \
 	opengl/shader.o \
 	pixelformat.o \
 	primitives.o \
diff --git a/graphics/opengl/box_shaders.cpp b/graphics/opengl/box_shaders.cpp
deleted file mode 100644
index a41038c79fb..00000000000
--- a/graphics/opengl/box_shaders.cpp
+++ /dev/null
@@ -1,64 +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 3 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "common/scummsys.h"
-
-#if defined(USE_OPENGL_SHADERS)
-
-namespace OpenGL {
-namespace BuiltinShaders {
-
-const char *boxVertex =
-	"attribute vec2 position;\n"
-	"attribute vec2 texcoord;\n"
-	"uniform vec2 offsetXY;\n"
-	"uniform vec2 sizeWH;\n"
-	"uniform vec2 texcrop;\n"
-	"uniform bool flipY;\n"
-	"varying vec2 Texcoord;\n"
-	"void main() {\n"
-		"Texcoord = texcoord * texcrop;\n"
-		"vec2 pos = offsetXY + position * sizeWH;\n"
-		"pos.x = pos.x * 2.0 - 1.0;\n"
-		"pos.y = pos.y * 2.0 - 1.0;\n"
-		"if (flipY)\n"
-			"pos.y *= -1.0;\n"
-		"gl_Position = vec4(pos, 0.0, 1.0);\n"
-	"}\n";
-
-const char *boxFragment =
-	"#ifdef GL_ES\n"
-		"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
-			"precision highp float;\n"
-		"#else\n"
-			"precision mediump float;\n"
-		"#endif\n"
-	"#endif\n"
-	"varying vec2 Texcoord;\n"
-	"uniform sampler2D tex;\n"
-	"void main() {\n"
-		"gl_FragColor = texture2D(tex, Texcoord);\n"
-	"}\n";
-
-}
-} // End of namespace OpenGL
-
-#endif
diff --git a/graphics/opengl/compat_shaders.cpp b/graphics/opengl/compat_shaders.cpp
deleted file mode 100644
index 2c090058e5d..00000000000
--- a/graphics/opengl/compat_shaders.cpp
+++ /dev/null
@@ -1,66 +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 3 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "common/scummsys.h"
-
-#if defined(USE_OPENGL_SHADERS)
-
-namespace OpenGL {
-namespace BuiltinShaders {
-
-const char *compatVertex =
-	"#if defined(GL_ES)\n"
-		"#define ROUND(x) (sign(x) * floor(abs(x) + .5))\n"
-		"#define in attribute\n"
-		"#define out varying\n"
-	"#elif __VERSION__ < 130\n"
-		"#define ROUND(x) (sign(x) * floor(abs(x) + .5))\n"
-		"#define highp\n"
-		"#define in attribute\n"
-		"#define out varying\n"
-	"#else\n"
-		"#define ROUND(x) round(x)\n"
-	"#endif\n";
-
-const char *compatFragment =
-	"#if defined(GL_ES)\n"
-		"#define in varying\n"
-		"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
-			"precision highp float;\n"
-		"#else\n"
-			"precision mediump float;\n"
-		"#endif\n"
-		"#define OUTPUT\n"
-		"#define outColor gl_FragColor\n"
-		"#define texture texture2D\n"
-	"#elif __VERSION__ < 130\n"
-		"#define in varying\n"
-		"#define OUTPUT\n"
-		"#define outColor gl_FragColor\n"
-		"#define texture texture2D\n"
-	"#else\n"
-		"#define OUTPUT out vec4 outColor;\n"
-	"#endif\n";
-
-}
-} // End of namespace OpenGL
-
-#endif
diff --git a/graphics/opengl/control_shaders.cpp b/graphics/opengl/control_shaders.cpp
deleted file mode 100644
index a57c0aae688..00000000000
--- a/graphics/opengl/control_shaders.cpp
+++ /dev/null
@@ -1,64 +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 3 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, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "common/scummsys.h"
-
-#if defined(USE_OPENGL_SHADERS)
-
-namespace OpenGL {
-namespace BuiltinShaders {
-
-const char *controlVertex =
-	"#version 100\n"
-	"attribute vec2 position;\n"
-	"attribute vec2 texcoord;\n"
-	"uniform vec2 offsetXY;\n"
-	"uniform vec2 sizeWH;\n"
-	"uniform vec4 clip;\n"
-	"uniform bool flipY;\n"
-	"varying vec2 Texcoord;\n"
-	"void main() {\n"
-		"Texcoord = clip.xy + texcoord * (clip.zw - clip.xy);\n"
-		"vec2 pos = offsetXY + position * sizeWH;\n"
-		"pos.x = pos.x * 2.0 - 1.0;\n"
-		"pos.y = pos.y * 2.0 - 1.0;\n"
-		"if (flipY)\n"
-			"pos.y *= -1.0;\n"
-		"gl_Position = vec4(pos, 0.0, 1.0);\n"
-	"}\n";
-
-const char *controlFragment =
-	"#version 100\n"
-	"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
-		"precision highp float;\n"
-	"#else\n"
-		"precision mediump float;\n"
-	"#endif\n"
-	"varying vec2 Texcoord;\n"
-	"uniform sampler2D tex;\n"
-	"void main() {\n"
-		"gl_FragColor = texture2D(tex, Texcoord);\n"
-	"}\n";
-
-}
-} // End of namespace OpenGL
-
-#endif
diff --git a/graphics/opengl/shader.cpp b/graphics/opengl/shader.cpp
index 4f375f022b0..146d1ac4c18 100644
--- a/graphics/opengl/shader.cpp
+++ b/graphics/opengl/shader.cpp
@@ -30,6 +30,40 @@
 
 namespace OpenGL {
 
+static const char *compatVertex =
+	"#if defined(GL_ES)\n"
+		"#define ROUND(x) (sign(x) * floor(abs(x) + .5))\n"
+		"#define in attribute\n"
+		"#define out varying\n"
+	"#elif __VERSION__ < 130\n"
+		"#define ROUND(x) (sign(x) * floor(abs(x) + .5))\n"
+		"#define highp\n"
+		"#define in attribute\n"
+		"#define out varying\n"
+	"#else\n"
+		"#define ROUND(x) round(x)\n"
+	"#endif\n";
+
+static const char *compatFragment =
+	"#if defined(GL_ES)\n"
+		"#define in varying\n"
+		"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
+			"precision highp float;\n"
+		"#else\n"
+			"precision mediump float;\n"
+		"#endif\n"
+		"#define OUTPUT\n"
+		"#define outColor gl_FragColor\n"
+		"#define texture texture2D\n"
+	"#elif __VERSION__ < 130\n"
+		"#define in varying\n"
+		"#define OUTPUT\n"
+		"#define outColor gl_FragColor\n"
+		"#define texture texture2D\n"
+	"#else\n"
+		"#define OUTPUT out vec4 outColor;\n"
+	"#endif\n";
+
 static const GLchar *readFile(const Common::String &filename) {
 	Common::File file;
 
@@ -83,7 +117,7 @@ static GLuint createDirectShader(const char *shaderSource, GLenum shaderType, co
 static GLuint createCompatShader(const char *shaderSource, GLenum shaderType, const Common::String &name) {
 	const GLchar *versionSource = OpenGLContext.type == kOGLContextGLES2 ? "#version 100\n" : "#version 120\n";
 	const GLchar *compatSource =
-			shaderType == GL_VERTEX_SHADER ? OpenGL::BuiltinShaders::compatVertex : OpenGL::BuiltinShaders::compatFragment;
+			shaderType == GL_VERTEX_SHADER ? compatVertex : compatFragment;
 	const GLchar *shaderSources[] = {
 		versionSource,
 		compatSource,
@@ -167,7 +201,6 @@ ShaderGL *ShaderGL::fromStrings(const Common::String &name, const char *vertex,
 	return new ShaderGL(name, vertexShader, fragmentShader, attributes);
 }
 
-
 ShaderGL *ShaderGL::fromFiles(const char *vertex, const char *fragment, const char **attributes) {
 	GLuint vertexShader = loadShaderFromFile(vertex, "vertex", GL_VERTEX_SHADER);
 	GLuint fragmentShader = loadShaderFromFile(fragment, "fragment", GL_FRAGMENT_SHADER);
diff --git a/graphics/opengl/shader.h b/graphics/opengl/shader.h
index aef2d18b3be..4875f4d2c0e 100644
--- a/graphics/opengl/shader.h
+++ b/graphics/opengl/shader.h
@@ -36,12 +36,6 @@
 
 namespace OpenGL {
 
-namespace BuiltinShaders {
-	extern const char *boxVertex, *boxFragment;
-	extern const char *compatVertex, *compatFragment;
-	extern const char *controlVertex, *controlFragment;
-}
-
 struct VertexAttrib {
 	VertexAttrib(uint32 idx, const char *name) :
 		_enabled(false), _idx(idx), _name(name), _vbo(0), _size(0),
@@ -112,7 +106,6 @@ public:
 			glUniform1f(pos, f);
 	}
 
-
 	GLint getUniformLocation(const char *uniform) const {
 		UniformsMap::iterator kv = _uniforms->find(uniform);
 		if (kv == _uniforms->end()) {




More information about the Scummvm-git-logs mailing list