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

aquadran noreply at scummvm.org
Fri Oct 3 18:10:57 UTC 2025


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

Summary:
c186181db0 WINTERMUTE: Release image data from surface after upload to OpenGL


Commit: c186181db073a08349b5516d1e363d1d7ee64897
    https://github.com/scummvm/scummvm/commit/c186181db073a08349b5516d1e363d1d7ee64897
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2025-10-03T20:10:52+02:00

Commit Message:
WINTERMUTE: Release image data from surface after upload to OpenGL

Changed paths:
    engines/wintermute/base/gfx/opengl/base_surface_opengl3d.cpp
    engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h


diff --git a/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.cpp b/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.cpp
index 107004cd72e..e1f198cefc0 100644
--- a/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.cpp
@@ -47,9 +47,7 @@ BaseSurfaceOpenGL3D::~BaseSurfaceOpenGL3D() {
 	}
 
 	if (_imageData) {
-		_imageData->free();
-		delete _imageData;
-		_imageData = nullptr;
+		freeImageData();
 	}
 
 	if (_maskData) {
@@ -81,7 +79,10 @@ bool BaseSurfaceOpenGL3D::prepareToDraw() {
 	_lastUsedTime = _game->_liveTimer;
 
 	if (!_valid) {
-		loadImage();
+		if (!loadImage()) {
+			return false;
+		}
+		uploadTexture();
 	}
 
 	return true;
@@ -251,10 +252,6 @@ bool BaseSurfaceOpenGL3D::loadImage() {
 		}
 	}
 
-	putSurface(*_imageData);
-
-	/* TODO: Delete _imageData if we no longer need to access the pixel data? */
-
 	_valid = true;
 
 	return true;
@@ -281,17 +278,38 @@ bool BaseSurfaceOpenGL3D::putSurface(const Graphics::Surface &surface, bool hasA
 		_imageData = new Graphics::Surface();
 	}
 
-	if (_imageData && _imageData != &surface) {
+	if (_imageData != &surface) {
 		_imageData->copyFrom(surface);
 		writeAlpha(_imageData, _maskData);
 	}
 
 	_width = surface.w;
 	_height = surface.h;
+
+	uploadTexture();
+
+	_valid = true;
+
+	return true;
+}
+
+void BaseSurfaceOpenGL3D::freeImageData() {
+	if (_imageData) {
+		_imageData->free();
+		delete _imageData;
+		_imageData = nullptr;
+	}
+}
+
+bool BaseSurfaceOpenGL3D::uploadTexture() {
+	if (!_imageData) {
+		return false;
+	}
+
 	_texWidth = Common::nextHigher2(_width);
 	_texHeight = Common::nextHigher2(_height);
 
-	if (!_valid) {
+	if (!_tex) {
 		glGenTextures(1, &_tex);
 	}
 	glBindTexture(GL_TEXTURE_2D, _tex);
@@ -302,8 +320,11 @@ bool BaseSurfaceOpenGL3D::putSurface(const Graphics::Surface &surface, bool hasA
 	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _texWidth, _texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _width, _height, GL_RGBA, GL_UNSIGNED_BYTE, _imageData->getPixels());
 	glBindTexture(GL_TEXTURE_2D, 0);
+
 	_valid = true;
 
+	freeImageData();
+
 	return true;
 }
 
@@ -350,8 +371,18 @@ bool BaseSurfaceOpenGL3D::getPixel(int x, int y, byte *r, byte *g, byte *b, byte
 }
 
 bool BaseSurfaceOpenGL3D::startPixelOp() {
-	if (!prepareToDraw())
+	if (_pixelOpReady) {
+		return true;
+	}
+	if (_valid && !_imageData) {
+		if (!loadImage()) {
+			return false;
+		}
+	}
+
+	if (!prepareToDraw()) {
 		return false;
+	}
 	_pixelOpReady = true;
 	return true;
 }
@@ -365,6 +396,7 @@ bool BaseSurfaceOpenGL3D::endPixelOp() {
 		glBindTexture(GL_TEXTURE_2D, 0);
 		_surfaceModified = false;
 	}
+	freeImageData();
 	return true;
 }
 
diff --git a/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h b/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h
index 0998e2cb3d5..f9611497ce4 100644
--- a/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h
+++ b/engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h
@@ -90,6 +90,8 @@ private:
 
 	bool loadImage();
 	void writeAlpha(Graphics::Surface *surface, const Graphics::Surface *mask);
+	bool uploadTexture();
+	void freeImageData();
 };
 
 } // End of namespace Wintermute




More information about the Scummvm-git-logs mailing list