[Scummvm-git-logs] scummvm master -> c257251e8f077e7d93d418dbab4918f5de17b043

lephilousophe noreply at scummvm.org
Sun Oct 16 17:43:23 UTC 2022


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

Summary:
82cd971aca OPENGL: Add more texture wrap modes detection
73f48341c0 BACKENDS: OPENGL: Allow to set texture wrapping mode
8047aef666 BACKENDS: OPENGL: Add support for wrap mode in libretro
c257251e8f BACKENDS: OPENGL: Implement FrameCount uniform


Commit: 82cd971acaf8b3c59bdd43046e9a7bfb53fee0be
    https://github.com/scummvm/scummvm/commit/82cd971acaf8b3c59bdd43046e9a7bfb53fee0be
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-16T19:43:05+02:00

Commit Message:
OPENGL: Add more texture wrap modes detection

Changed paths:
    graphics/opengl/context.cpp
    graphics/opengl/context.h


diff --git a/graphics/opengl/context.cpp b/graphics/opengl/context.cpp
index 3172e7c33b7..91ba6e02036 100644
--- a/graphics/opengl/context.cpp
+++ b/graphics/opengl/context.cpp
@@ -69,6 +69,8 @@ void Context::reset() {
 	unpackSubImageSupported = false;
 	OESDepth24 = false;
 	textureEdgeClampSupported = false;
+	textureBorderClampSupported = false;
+	textureMirrorRepeatSupported = false;
 }
 
 void Context::initialize(ContextType contextType) {
@@ -180,6 +182,10 @@ void Context::initialize(ContextType contextType) {
 			OESDepth24 = true;
 		} else if (token == "GL_SGIS_texture_edge_clamp") {
 			textureEdgeClampSupported = true;
+		} else if (token == "GL_SGIS_texture_border_clamp") {
+			textureBorderClampSupported = true;
+		} else if (token == "GL_ARB_texture_mirrored_repeat") {
+			textureMirrorRepeatSupported = true;
 		}
 	}
 
@@ -211,6 +217,8 @@ void Context::initialize(ContextType contextType) {
 
 		packedPixelsSupported = true;
 		textureEdgeClampSupported = true;
+		// No border clamping in GLES2
+		textureMirrorRepeatSupported = true;
 		debug(5, "OpenGL: GLES2 context initialized");
 	} else if (type == kContextGLES) {
 		// GLES doesn't support shaders natively
@@ -228,6 +236,8 @@ void Context::initialize(ContextType contextType) {
 
 		packedPixelsSupported = true;
 		textureEdgeClampSupported = true;
+		// No border clamping in GLES
+		// No mirror repeat in GLES
 		debug(5, "OpenGL: GLES context initialized");
 	} else if (type == kContextGL) {
 		shadersSupported = glslVersion >= 100;
@@ -259,6 +269,14 @@ void Context::initialize(ContextType contextType) {
 			packedPixelsSupported = true;
 			textureEdgeClampSupported = true;
 		}
+		// OpenGL 1.3 adds texture border clamp support
+		if (isGLVersionOrHigher(1, 3)) {
+			textureBorderClampSupported = true;
+		}
+		// OpenGL 1.4 adds texture mirror repeat support
+		if (isGLVersionOrHigher(1, 4)) {
+			textureMirrorRepeatSupported = true;
+		}
 		debug(5, "OpenGL: GL context initialized");
 	} else {
 		warning("OpenGL: Unknown context initialized");
diff --git a/graphics/opengl/context.h b/graphics/opengl/context.h
index d00a0ab1ab8..4ca34f9879c 100644
--- a/graphics/opengl/context.h
+++ b/graphics/opengl/context.h
@@ -111,6 +111,12 @@ public:
 	/** Whether texture coordinate edge clamping is available or not. */
 	bool textureEdgeClampSupported;
 
+	/** Whether texture coordinate border clamping is available or not. */
+	bool textureBorderClampSupported;
+
+	/** Whether texture coordinate mirrored repeat is available or not. */
+	bool textureMirrorRepeatSupported;
+
 private:
 	/**
 	 * Returns the native GLSL version supported by the driver.


Commit: 73f48341c00d555f158278d8477a9137f967398d
    https://github.com/scummvm/scummvm/commit/73f48341c00d555f158278d8477a9137f967398d
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-16T19:43:05+02:00

Commit Message:
BACKENDS: OPENGL: Allow to set texture wrapping mode

Changed paths:
    backends/graphics/opengl/texture.cpp
    backends/graphics/opengl/texture.h


diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp
index cd8ad7e7f4f..79c485ae82b 100644
--- a/backends/graphics/opengl/texture.cpp
+++ b/backends/graphics/opengl/texture.cpp
@@ -64,6 +64,51 @@ void GLTexture::enableLinearFiltering(bool enable) {
 	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _glFilter));
 }
 
+void GLTexture::setWrapMode(WrapMode wrapMode) {
+	GLuint glwrapMode;
+
+	switch(wrapMode) {
+		case kWrapModeBorder:
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+			if (OpenGLContext.textureBorderClampSupported) {
+				glwrapMode = GL_CLAMP_TO_BORDER;
+				break;
+			}
+#endif
+		// fall through
+		case kWrapModeEdge:
+			if (OpenGLContext.textureEdgeClampSupported) {
+				glwrapMode = GL_CLAMP_TO_EDGE;
+				break;
+			} else {
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+				// Fallback on clamp
+				glwrapMode = GL_CLAMP;
+#else
+				// This fallback should never happen in real life (GLES/GLES2 have border/edge clamp)
+				glwrapMode = GL_REPEAT;
+#endif
+				break;
+			}
+		case kWrapModeMirroredRepeat:
+#if !USE_FORCED_GLES
+			if (OpenGLContext.textureMirrorRepeatSupported) {
+				glwrapMode = GL_MIRRORED_REPEAT;
+				break;
+			}
+#endif
+		// fall through
+		case kWrapModeRepeat:
+			glwrapMode = GL_REPEAT;
+	}
+
+
+	bind();
+
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glwrapMode));
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glwrapMode));
+}
+
 void GLTexture::destroy() {
 	GL_CALL(glDeleteTextures(1, &_glTexture));
 	_glTexture = 0;
diff --git a/backends/graphics/opengl/texture.h b/backends/graphics/opengl/texture.h
index dd19ca36efe..58f6cd397fe 100644
--- a/backends/graphics/opengl/texture.h
+++ b/backends/graphics/opengl/texture.h
@@ -34,6 +34,13 @@ class Scaler;
 
 namespace OpenGL {
 
+enum WrapMode {
+	kWrapModeBorder,
+	kWrapModeEdge,
+	kWrapModeRepeat,
+	kWrapModeMirroredRepeat
+};
+
 /**
  * A simple GL texture object abstraction.
  *
@@ -63,6 +70,13 @@ public:
 	 */
 	bool isLinearFilteringEnabled() const { return (_glFilter == GL_LINEAR); }
 
+	/**
+	 * Enable or disable linear texture filtering.
+	 *
+	 * @param enable true to enable and false to disable.
+	 */
+	void setWrapMode(WrapMode wrapMode);
+
 	/**
 	 * Destroy the OpenGL texture name.
 	 */


Commit: 8047aef666cc95f0cba97e733de14ab58714794a
    https://github.com/scummvm/scummvm/commit/8047aef666cc95f0cba97e733de14ab58714794a
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-16T19:43:05+02:00

Commit Message:
BACKENDS: OPENGL: Add support for wrap mode in libretro

Changed paths:
    backends/graphics/opengl/pipelines/libretro.cpp
    backends/graphics/opengl/pipelines/libretro/parser.cpp
    backends/graphics/opengl/pipelines/libretro/types.h


diff --git a/backends/graphics/opengl/pipelines/libretro.cpp b/backends/graphics/opengl/pipelines/libretro.cpp
index 7ef5cc8aa9b..d5cb418cae1 100644
--- a/backends/graphics/opengl/pipelines/libretro.cpp
+++ b/backends/graphics/opengl/pipelines/libretro.cpp
@@ -249,6 +249,7 @@ bool LibRetroPipeline::loadTextures() {
 		}
 
 		texture.glTexture->enableLinearFiltering(i->filteringMode == LibRetro::kFilteringModeLinear);
+		texture.glTexture->setWrapMode(i->wrapMode);
 		_textures.push_back(texture);
 	}
 	return true;
@@ -398,6 +399,7 @@ bool LibRetroPipeline::loadPasses() {
 		if (passId > 0) {
 			GLTexture *const texture = _passes[passId - 1].target->getTexture();
 			texture->enableLinearFiltering(i->filteringMode == LibRetro::kFilteringModeLinear);
+			texture->setWrapMode(i->wrapMode);
 			pass.inputTexture = texture;
 		}
 	}
diff --git a/backends/graphics/opengl/pipelines/libretro/parser.cpp b/backends/graphics/opengl/pipelines/libretro/parser.cpp
index d6801ef59b2..e345a501b48 100644
--- a/backends/graphics/opengl/pipelines/libretro/parser.cpp
+++ b/backends/graphics/opengl/pipelines/libretro/parser.cpp
@@ -51,6 +51,7 @@ private:
 	bool lookUpValue(const Common::String &key, FilteringMode *value, const FilteringMode defaultValue);
 	bool lookUpValue(const Common::String &key, ScaleType *value, const ScaleType defaultValue);
 	bool lookUpValueScale(const Common::String &key, float *floatValue, uint *uintValue, const ScaleType scaleType);
+	bool lookUpValue(const Common::String &key, WrapMode *value, const WrapMode defaultValue);
 
 	template<typename T, typename DefaultT>
 	bool lookUpValue(const Common::String &key, T *value, const DefaultT &defaultValue) {
@@ -285,6 +286,31 @@ bool PresetParser::lookUpValueScale(const Common::String &key, float *floatValue
 	}
 }
 
+bool PresetParser::lookUpValue(const Common::String &key, WrapMode *value, const WrapMode defaultValue) {
+	StringMap::const_iterator iter = _entries.find(key);
+	if (iter != _entries.end()) {
+		if (iter->_value == "clamp_to_border") {
+			*value = kWrapModeBorder;
+			return true;
+		} else if (iter->_value == "clamp_to_edge") {
+			*value = kWrapModeEdge;
+			return true;
+		} else if (iter->_value == "repeat") {
+			*value = kWrapModeRepeat;
+			return true;
+		} else if (iter->_value == "mirrored_repeat") {
+			*value = kWrapModeMirroredRepeat;
+			return true;
+		} else {
+			_errorDesc = "Invalid wrap mode for key '" + key + "': '" + iter->_value + '\'';
+			return false;
+		}
+	} else {
+		*value = defaultValue;
+		return true;
+	}
+}
+
 bool PresetParser::parseTextures() {
 	Common::String textures;
 	if (!lookUpValue("textures", &textures)) {
@@ -314,7 +340,12 @@ bool PresetParser::parseTexture(const Common::String &id) {
 		return false;
 	}
 
-	_shader->textures.push_back(ShaderTexture(id, fileName, filteringMode));
+	WrapMode wrapMode;
+	if (!lookUpValue(id + "_wrap_mode", &wrapMode, kWrapModeBorder)) {
+		return false;
+	}
+
+	_shader->textures.push_back(ShaderTexture(id, fileName, filteringMode, wrapMode));
 	return true;
 }
 
@@ -351,6 +382,10 @@ bool PresetParser::parsePass(const uint id, const bool isLast) {
 		return false;
 	}
 
+	if (!lookUpValue(passKey("wrap_mode"), &pass.wrapMode, kWrapModeBorder)) {
+		return false;
+	}
+
 	if (!lookUpValue(passKey("mipmap_input"), &pass.mipmapInput, false)) {
 		return false;
 	}
diff --git a/backends/graphics/opengl/pipelines/libretro/types.h b/backends/graphics/opengl/pipelines/libretro/types.h
index 489b53adeb4..3a9be02a4cb 100644
--- a/backends/graphics/opengl/pipelines/libretro/types.h
+++ b/backends/graphics/opengl/pipelines/libretro/types.h
@@ -23,6 +23,7 @@
 #define BACKENDS_GRAPHICS_OPENGL_PIPELINES_LIBRETRO_TYPES_H
 
 #include "graphics/opengl/system_headers.h"
+#include "backends/graphics/opengl/texture.h"
 
 #if !USE_FORCED_GLES
 #include "common/str.h"
@@ -40,12 +41,13 @@ enum FilteringMode {
 
 struct ShaderTexture {
 	ShaderTexture() : id(), fileName(), filteringMode(kFilteringModeUnspecified) {}
-	ShaderTexture(const Common::String &i, const Common::String &fN, FilteringMode fM)
-		: id(i), fileName(fN), filteringMode(fM) {}
+	ShaderTexture(const Common::String &i, const Common::String &fN, FilteringMode fM, WrapMode wM)
+		: id(i), fileName(fN), filteringMode(fM), wrapMode(wM) {}
 
 	Common::String id;
 	Common::String fileName;
 	FilteringMode filteringMode;
+	WrapMode wrapMode;
 };
 
 enum ScaleType {
@@ -83,6 +85,7 @@ struct ShaderPass {
 	Common::String alias;
 
 	FilteringMode filteringMode;
+	WrapMode wrapMode;
 	bool mipmapInput;
 
 	bool floatFBO;


Commit: c257251e8f077e7d93d418dbab4918f5de17b043
    https://github.com/scummvm/scummvm/commit/c257251e8f077e7d93d418dbab4918f5de17b043
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-16T19:43:05+02:00

Commit Message:
BACKENDS: OPENGL: Implement FrameCount uniform

Changed paths:
    backends/graphics/opengl/pipelines/libretro.cpp
    backends/graphics/opengl/pipelines/libretro.h


diff --git a/backends/graphics/opengl/pipelines/libretro.cpp b/backends/graphics/opengl/pipelines/libretro.cpp
index d5cb418cae1..be1bacb0ab0 100644
--- a/backends/graphics/opengl/pipelines/libretro.cpp
+++ b/backends/graphics/opengl/pipelines/libretro.cpp
@@ -116,13 +116,13 @@ static const char *g_compatFragment =
 LibRetroPipeline::LibRetroPipeline()
 	: ShaderPipeline(ShaderMan.query(ShaderManager::kDefault)),
 	  _shaderPreset(nullptr), _applyProjectionChanges(false),
-	  _inputWidth(0), _inputHeight(0), _outputWidth(0), _outputHeight(0) {
+	  _inputWidth(0), _inputHeight(0), _outputWidth(0), _outputHeight(0), _frameCount(0) {
 }
 
 LibRetroPipeline::LibRetroPipeline(const Common::FSNode &shaderPreset)
 	: ShaderPipeline(ShaderMan.query(ShaderManager::kDefault)),
 	  _shaderPreset(nullptr), _applyProjectionChanges(false),
-	  _inputWidth(0), _inputHeight(0), _outputWidth(0), _outputHeight(0) {
+	  _inputWidth(0), _inputHeight(0), _outputWidth(0), _outputHeight(0), _frameCount(0) {
 	open(shaderPreset);
 }
 
@@ -168,6 +168,8 @@ void LibRetroPipeline::drawTexture(const GLTexture &texture, const GLfloat *coor
 	ShaderPipeline::activateInternal();
 	ShaderPipeline::drawTexture(*_passes[_passes.size() - 1].target->getTexture(), coordinates, texcoords);
 	ShaderPipeline::deactivateInternal();
+
+	_frameCount++;
 }
 
 void LibRetroPipeline::setProjectionMatrix(const GLfloat *projectionMatrix) {
@@ -394,6 +396,8 @@ bool LibRetroPipeline::loadPasses() {
 		Pass &pass = _passes[_passes.size() - 1];
 		const uint passId = _passes.size() - 1;
 
+		pass.hasFrameCount = shader->getUniformLocation("FrameCount") != -1;
+
 		pass.buildTexCoords(passId, aliases);
 		pass.buildTexSamplers(passId, _textures, aliases);
 		if (passId > 0) {
@@ -642,6 +646,14 @@ void LibRetroPipeline::renderPass(const Pass &pass) {
 	pass.shader->use();
 	setFramebuffer(pass.target);
 
+	if (pass.hasFrameCount) {
+		uint frameCount = _frameCount;
+		if (pass.shaderPass->frameCountMod) {
+			frameCount %= pass.shaderPass->frameCountMod;
+		}
+		pass.shader->setUniform("FrameCount", frameCount);
+	}
+
 	// Activate attribute arrays and setup matching attributes.
 	renderPassSetupCoordinates(pass);
 
diff --git a/backends/graphics/opengl/pipelines/libretro.h b/backends/graphics/opengl/pipelines/libretro.h
index 5f270a554f2..7a1f67a6e4f 100644
--- a/backends/graphics/opengl/pipelines/libretro.h
+++ b/backends/graphics/opengl/pipelines/libretro.h
@@ -91,6 +91,8 @@ private:
 	uint _outputWidth;
 	uint _outputHeight;
 
+	uint _frameCount;
+
 	struct Texture {
 		Texture() : textureData(nullptr), glTexture(nullptr) {}
 		Texture(Graphics::Surface *tD, GLTexture *glTex) : textureData(tD), glTexture(glTex) {}
@@ -107,10 +109,10 @@ private:
 	struct Pass {
 		Pass()
 			: shaderPass(nullptr), shader(nullptr), target(nullptr),
-			  texCoords(), texSamplers(), inputTexture(nullptr), vertexCoord() {}
+			  texCoords(), texSamplers(), inputTexture(nullptr), vertexCoord(), hasFrameCount(false) {}
 		Pass(const LibRetro::ShaderPass *sP, Shader *s, TextureTarget *t)
 			: shaderPass(sP), shader(s), target(t), texCoords(),
-			  texSamplers(), inputTexture(nullptr), vertexCoord() {}
+			  texSamplers(), inputTexture(nullptr), vertexCoord(), hasFrameCount(false) {}
 
 		const LibRetro::ShaderPass *shaderPass;
 		Shader *shader;
@@ -230,6 +232,12 @@ private:
 		 * Vertex coordinates used for drawing.
 		 */
 		GLfloat vertexCoord[2*4];
+
+		/**
+		 * Whether the shader has a FrameCount uniform or not
+		 * Allows to speed up if it is not here
+		 */
+		bool hasFrameCount;
 	};
 
 	typedef Common::Array<Pass> PassArray;




More information about the Scummvm-git-logs mailing list