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

lephilousophe noreply at scummvm.org
Sat Aug 31 14:42:29 UTC 2024


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:
caf7901cb4 BACKENDS: OPENGL: Update blending color when it's dirty


Commit: caf7901cb4b64bb93207327f73c195536d88e6fa
    https://github.com/scummvm/scummvm/commit/caf7901cb4b64bb93207327f73c195536d88e6fa
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-08-31T16:41:40+02:00

Commit Message:
BACKENDS: OPENGL: Update blending color when it's dirty

This makes sure the color is updated before drawing the texture and
avoids extraneous calls when the color was already set.

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


diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp
index a30adbc1252..ac352a0c2e8 100644
--- a/backends/graphics/opengl/pipelines/shader.cpp
+++ b/backends/graphics/opengl/pipelines/shader.cpp
@@ -31,7 +31,7 @@ static const int kCoordinatesSize = 4 * 2 * sizeof(float);
 
 #if !USE_FORCED_GLES
 ShaderPipeline::ShaderPipeline(Shader *shader)
-	: _activeShader(shader), _colorAttributes() {
+	: _activeShader(shader), _colorAttributes(), _colorDirty(true) {
 	// Use the same VBO for vertices and texcoords as we modify them at the same time
 	_coordsVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, kCoordinatesSize, nullptr, GL_STATIC_DRAW);
 	_activeShader->enableVertexAttribute("position", _coordsVBO, 2, GL_FLOAT, GL_FALSE, 0, 0);
@@ -57,10 +57,6 @@ void ShaderPipeline::activateInternal() {
 	}
 
 	_activeShader->use();
-
-	GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, _colorVBO));
-	GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_colorAttributes), _colorAttributes));
-	GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
 }
 
 void ShaderPipeline::deactivateInternal() {
@@ -77,6 +73,7 @@ void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
 		*dst++ = b;
 		*dst++ = a;
 	}
+	_colorDirty = true;
 }
 
 void ShaderPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
@@ -84,6 +81,11 @@ void ShaderPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat
 
 	texture.bind();
 
+	if (_colorDirty) {
+		GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, _colorVBO));
+		GL_CALL(glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_colorAttributes), _colorAttributes));
+		_colorDirty = false;
+	}
 	GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, _coordsVBO));
 	GL_CALL(glBufferData(GL_ARRAY_BUFFER, kCoordinatesSize, coordinates, GL_STATIC_DRAW));
 	GL_CALL(glBindBuffer(GL_ARRAY_BUFFER, _texcoordsVBO));
diff --git a/backends/graphics/opengl/pipelines/shader.h b/backends/graphics/opengl/pipelines/shader.h
index 6a217d2bb1b..4130bb0e684 100644
--- a/backends/graphics/opengl/pipelines/shader.h
+++ b/backends/graphics/opengl/pipelines/shader.h
@@ -48,6 +48,7 @@ protected:
 	GLuint _colorVBO;
 
 	GLfloat _colorAttributes[4*4];
+	bool _colorDirty;
 
 	Shader *const _activeShader;
 };




More information about the Scummvm-git-logs mailing list