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

lephilousophe noreply at scummvm.org
Mon Oct 17 20:09:49 UTC 2022


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

Summary:
396d5fb425 BACKENDS: OPENGL: ALlow the use of software scalers with LibRetro
ef9eb436a0 BACKENDS: OPENGL: Apply parameters globally and load the preset ones


Commit: 396d5fb4252c97fb438548af2a922e2af6597086
    https://github.com/scummvm/scummvm/commit/396d5fb4252c97fb438548af2a922e2af6597086
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-17T22:09:35+02:00

Commit Message:
BACKENDS: OPENGL: ALlow the use of software scalers with LibRetro

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp


diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 7b8f152e4c3..196af99d233 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -536,7 +536,10 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() {
 		if (_libretroPipeline) {
 			_gameScreenTarget = new TextureTarget();
 			_gameScreenTarget->create();
-			_gameScreenTarget->setSize(_currentState.gameWidth, _currentState.gameHeight);
+			// To take software scaler into account we need to create a framebuffer matching the size of the _gameScreen output texture
+			// We cheat a little because ScaledTexture does everything it can to hide the real size
+			const GLTexture &gameScreenTexture = _gameScreen->getGLTexture();
+			_gameScreenTarget->setSize(gameScreenTexture.getLogicalWidth(), gameScreenTexture.getLogicalHeight());
 		}
 #endif
 	}
@@ -652,7 +655,8 @@ void OpenGLGraphicsManager::updateScreen() {
 	if (_libretroPipeline && _libretroPipeline->isInitialized()) {
 		Framebuffer *lastFramebuffer = Pipeline::getActivePipeline()->setFramebuffer(_gameScreenTarget);
 		_gameScreenTarget->enableBlend(Framebuffer::kBlendModeDisabled);
-		Pipeline::getActivePipeline()->drawTexture(_gameScreen->getGLTexture(), 0, 0, _gameScreen->getWidth(), _gameScreen->getHeight());
+		const GLTexture &gameScreenTexture = _gameScreen->getGLTexture();
+		Pipeline::getActivePipeline()->drawTexture(gameScreenTexture, 0, 0, gameScreenTexture.getLogicalWidth(), gameScreenTexture.getLogicalHeight());
 
 		// Draw the cursor if necessary.
 		if (needsCursor && !_overlayVisible) {


Commit: ef9eb436a026410c77fa0762aaa3a83b0d522e75
    https://github.com/scummvm/scummvm/commit/ef9eb436a026410c77fa0762aaa3a83b0d522e75
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-10-17T22:09:35+02:00

Commit Message:
BACKENDS: OPENGL: Apply parameters globally and load the preset ones

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 be1bacb0ab0..2d3ee249d82 100644
--- a/backends/graphics/opengl/pipelines/libretro.cpp
+++ b/backends/graphics/opengl/pipelines/libretro.cpp
@@ -41,6 +41,8 @@
 
 namespace OpenGL {
 
+using LibRetro::UniformsMap;
+
 template<typename DecoderType>
 static Graphics::Surface *loadViaImageDecoder(const Common::FSNode &fileNode) {
 	Common::SeekableReadStream *stream = fileNode.createReadStream();
@@ -257,8 +259,6 @@ bool LibRetroPipeline::loadTextures() {
 	return true;
 }
 
-typedef Common::HashMap<Common::String, float, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> UniformsMap;
-
 static void stripShaderParameters(char *source, UniformsMap &uniforms) {
 	char uniformId[64], desc[64];
 	float initial, minimum, maximum, step;
@@ -295,6 +295,8 @@ bool LibRetroPipeline::loadPasses() {
 		}
 	}
 
+	// parameters are shared among all passes so we load them first and apply them to all shaders
+	UniformsMap uniformParams;
 	for (LibRetro::ShaderPreset::PassArray::const_iterator
 		 i = _shaderPreset->passes.begin(), end = _shaderPreset->passes.end();
 		 i != end; ++i) {
@@ -339,7 +341,6 @@ bool LibRetroPipeline::loadPasses() {
 					shaderFileVersion, shaderFileVersionExtra);
 		}
 
-		UniformsMap uniformParams;
 		stripShaderParameters(shaderFileStart, uniformParams);
 
 		Common::String shimsDetected;
@@ -384,10 +385,6 @@ bool LibRetroPipeline::loadPasses() {
 		// Input texture is always bound at sampler 0.
 		shader->setUniform("Texture", 0);
 
-		for(UniformsMap::iterator it = uniformParams.begin(); it != uniformParams.end(); it++) {
-			shader->setUniform1f(it->_key, it->_value);
-		}
-
 		TextureTarget *target = nullptr;
 		// TODO: float and sRGB FBO handling.
 		target = new TextureTarget();
@@ -408,6 +405,19 @@ bool LibRetroPipeline::loadPasses() {
 		}
 	}
 
+	// Apply preset parameters last to override all others
+	for(UniformsMap::iterator it = _shaderPreset->parameters.begin(); it != _shaderPreset->parameters.end(); it++) {
+		uniformParams[it->_key] = it->_value;
+	}
+
+	// Finally apply parameters to all shaders as uniforms
+	for(PassArray::iterator i = _passes.begin(); i != _passes.end(); i++) {
+		for(UniformsMap::iterator it = uniformParams.begin(); it != uniformParams.end(); it++) {
+			i->shader->setUniform1f(it->_key, it->_value);
+		}
+	}
+
+
 	// Now try to setup FBOs with some dummy size to make sure it could work
 	uint bakInputWidth = _inputWidth;
 	uint bakInputHeight = _inputHeight;
diff --git a/backends/graphics/opengl/pipelines/libretro/parser.cpp b/backends/graphics/opengl/pipelines/libretro/parser.cpp
index e345a501b48..e9d9b16ea0f 100644
--- a/backends/graphics/opengl/pipelines/libretro/parser.cpp
+++ b/backends/graphics/opengl/pipelines/libretro/parser.cpp
@@ -73,6 +73,8 @@ private:
 	bool parsePassScale(const uint id, ShaderPass *pass);
 	bool computeDefaultScale(const Common::String &key, float *floatValue, uint *uintValue, const ScaleType scaleType);
 
+	bool parseParameters();
+
 	typedef Common::HashMap<Common::String, Common::String> StringMap;
 	StringMap _entries;
 
@@ -98,6 +100,10 @@ ShaderPreset *PresetParser::parseStream(Common::SeekableReadStream &stream) {
 		return nullptr;
 	}
 
+	if (!parseParameters()) {
+		return nullptr;
+	}
+
 	return _shader.release();
 }
 
@@ -505,6 +511,26 @@ bool PresetParser::computeDefaultScale(const Common::String &key, float *floatVa
 	}
 }
 
+bool PresetParser::parseParameters() {
+	Common::String parameters;
+	if (!lookUpValue("parameters", &parameters)) {
+		return true;
+	}
+
+	// Parse all texture information from preset.
+	Common::StringTokenizer tokenizer(parameters, ";");
+	while (!tokenizer.empty()) {
+		Common::String key = tokenizer.nextToken();
+		float value;
+		if (!lookUpValue(key, &value)) {
+			return false;
+		}
+		_shader->parameters[key] = value;
+	}
+
+	return true;
+}
+
 ShaderPreset *parsePreset(const Common::FSNode &shaderPreset) {
 	if (!shaderPreset.exists() || !shaderPreset.isReadable() || shaderPreset.isDirectory()) {
 		warning("LibRetro Preset Parsing: No such readable file '%s'", shaderPreset.getName().c_str());
diff --git a/backends/graphics/opengl/pipelines/libretro/types.h b/backends/graphics/opengl/pipelines/libretro/types.h
index 3a9be02a4cb..72949229d9f 100644
--- a/backends/graphics/opengl/pipelines/libretro/types.h
+++ b/backends/graphics/opengl/pipelines/libretro/types.h
@@ -33,6 +33,8 @@
 namespace OpenGL {
 namespace LibRetro {
 
+typedef Common::HashMap<Common::String, float, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> UniformsMap;
+
 enum FilteringMode {
 	kFilteringModeUnspecified,
 	kFilteringModeNearest,
@@ -118,6 +120,8 @@ struct ShaderPreset {
 
 	typedef Common::Array<ShaderPass> PassArray;
 	PassArray passes;
+
+	UniformsMap parameters;
 };
 
 } // End of namespace LibRetro




More information about the Scummvm-git-logs mailing list