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

bluegr noreply at scummvm.org
Sat Nov 30 16:21:51 UTC 2024


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:
20b41fc8d9 GRAPHICS: OPENGL: Separate the GLTexture class from the graphics manager
a9ca83819d BACKENDS: OPENGL: Use the shared Texture class for the overlay in 3D games


Commit: 20b41fc8d9df6f9dcb169a88f257acee004f348d
    https://github.com/scummvm/scummvm/commit/20b41fc8d9df6f9dcb169a88f257acee004f348d
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-11-30T18:21:47+02:00

Commit Message:
GRAPHICS: OPENGL: Separate the GLTexture class from the graphics manager

Changed paths:
  A graphics/opengl/texture.cpp
  A graphics/opengl/texture.h
    backends/graphics/opengl/framebuffer.cpp
    backends/graphics/opengl/framebuffer.h
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/pipelines/clut8.cpp
    backends/graphics/opengl/pipelines/clut8.h
    backends/graphics/opengl/pipelines/fixed.cpp
    backends/graphics/opengl/pipelines/fixed.h
    backends/graphics/opengl/pipelines/libretro.cpp
    backends/graphics/opengl/pipelines/libretro.h
    backends/graphics/opengl/pipelines/libretro/types.h
    backends/graphics/opengl/pipelines/pipeline.h
    backends/graphics/opengl/pipelines/shader.cpp
    backends/graphics/opengl/pipelines/shader.h
    backends/graphics/opengl/texture.cpp
    backends/graphics/opengl/texture.h
    graphics/module.mk


diff --git a/backends/graphics/opengl/framebuffer.cpp b/backends/graphics/opengl/framebuffer.cpp
index 1163a28e07a..f0d08630aa9 100644
--- a/backends/graphics/opengl/framebuffer.cpp
+++ b/backends/graphics/opengl/framebuffer.cpp
@@ -21,8 +21,8 @@
 
 #include "backends/graphics/opengl/framebuffer.h"
 #include "backends/graphics/opengl/pipelines/pipeline.h"
-#include "backends/graphics/opengl/texture.h"
 #include "graphics/opengl/debug.h"
+#include "graphics/opengl/texture.h"
 #include "common/rotationmode.h"
 
 namespace OpenGL {
@@ -266,7 +266,7 @@ bool Backbuffer::setSize(uint width, uint height, Common::RotationMode rotation)
 
 #if !USE_FORCED_GLES
 TextureTarget::TextureTarget()
-	: _texture(new GLTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE)), _glFBO(0), _needUpdate(true) {
+	: _texture(new Texture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE)), _glFBO(0), _needUpdate(true) {
 }
 
 TextureTarget::~TextureTarget() {
diff --git a/backends/graphics/opengl/framebuffer.h b/backends/graphics/opengl/framebuffer.h
index f9bb5825d44..445984034a4 100644
--- a/backends/graphics/opengl/framebuffer.h
+++ b/backends/graphics/opengl/framebuffer.h
@@ -192,7 +192,7 @@ protected:
 };
 
 #if !USE_FORCED_GLES
-class GLTexture;
+class Texture;
 
 /**
  * Render to texture framebuffer implementation.
@@ -223,13 +223,13 @@ public:
 	/**
 	 * Query pointer to underlying GL texture.
 	 */
-	GLTexture *getTexture() const { return _texture; }
+	Texture *getTexture() const { return _texture; }
 
 protected:
 	void activateInternal() override;
 
 private:
-	GLTexture *_texture;
+	Texture *_texture;
 	GLuint _glFBO;
 	bool _needUpdate;
 };
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index b8899fc4bbb..462e18b7d99 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -1492,12 +1492,12 @@ Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &forma
 	if (wantScaler) {
 		// TODO: Ensure that the requested pixel format is supported by the scaler
 		if (getGLPixelFormat(format, glIntFormat, glFormat, glType)) {
-			return new ScaledTexture(glIntFormat, glFormat, glType, format, format);
+			return new ScaledTextureSurface(glIntFormat, glFormat, glType, format, format);
 		} else {
 #ifdef SCUMM_LITTLE_ENDIAN
-			return new ScaledTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), format);
+			return new ScaledTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), format);
 #else
-			return new ScaledTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), format);
+			return new ScaledTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), format);
 #endif
 		}
 	}
@@ -1505,8 +1505,8 @@ Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &forma
 
 	if (format.bytesPerPixel == 1) {
 #if !USE_FORCED_GLES
-		if (TextureCLUT8GPU::isSupportedByContext() && !wantMask) {
-			return new TextureCLUT8GPU();
+		if (TextureSurfaceCLUT8GPU::isSupportedByContext() && !wantMask) {
+			return new TextureSurfaceCLUT8GPU();
 		}
 #endif
 
@@ -1515,27 +1515,27 @@ Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &forma
 		if (!supported) {
 			return nullptr;
 		} else {
-			return new FakeTexture(glIntFormat, glFormat, glType, virtFormat, format);
+			return new FakeTextureSurface(glIntFormat, glFormat, glType, virtFormat, format);
 		}
 	} else if (getGLPixelFormat(format, glIntFormat, glFormat, glType)) {
-		return new Texture(glIntFormat, glFormat, glType, format);
+		return new TextureSurface(glIntFormat, glFormat, glType, format);
 	} else if (OpenGLContext.packedPixelsSupported && format == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) {
 		// OpenGL ES does not support a texture format usable for RGB555.
 		// Since SCUMM uses this pixel format for some games (and there is no
 		// hope for this to change anytime soon) we use pixel format
 		// conversion to a supported texture format.
-		return new TextureRGB555();
+		return new TextureSurfaceRGB555();
 #ifdef SCUMM_LITTLE_ENDIAN
 	} else if (format == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
 #else
 	} else if (format == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
 #endif
-		return new TextureRGBA8888Swap();
+		return new TextureSurfaceRGBA8888Swap();
 	} else {
 #ifdef SCUMM_LITTLE_ENDIAN
-		return new FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), format);
+		return new FakeTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), format);
 #else
-		return new FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), format);
+		return new FakeTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), format);
 #endif
 	}
 }
@@ -1655,7 +1655,7 @@ void OpenGLGraphicsManager::recalculateDisplayAreas() {
 
 #if !USE_FORCED_GLES
 	if (_libretroPipeline) {
-		const GLTexture &gameScreenTexture = _gameScreen->getGLTexture();
+		const Texture &gameScreenTexture = _gameScreen->getGLTexture();
 		_libretroPipeline->setDisplaySizes(gameScreenTexture.getLogicalWidth(), gameScreenTexture.getLogicalHeight(),
 				_gameDrawRect);
 	}
diff --git a/backends/graphics/opengl/pipelines/clut8.cpp b/backends/graphics/opengl/pipelines/clut8.cpp
index 2f6b5cb07b5..b08535fd952 100644
--- a/backends/graphics/opengl/pipelines/clut8.cpp
+++ b/backends/graphics/opengl/pipelines/clut8.cpp
@@ -31,7 +31,7 @@ CLUT8LookUpPipeline::CLUT8LookUpPipeline()
 	: ShaderPipeline(ShaderMan.query(ShaderManager::kCLUT8LookUp)), _paletteTexture(nullptr) {
 }
 
-void CLUT8LookUpPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
+void CLUT8LookUpPipeline::drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
 	assert(isActive());
 
 	// Set the palette texture.
diff --git a/backends/graphics/opengl/pipelines/clut8.h b/backends/graphics/opengl/pipelines/clut8.h
index 1b19a0ad5e3..15da0633044 100644
--- a/backends/graphics/opengl/pipelines/clut8.h
+++ b/backends/graphics/opengl/pipelines/clut8.h
@@ -31,13 +31,13 @@ class CLUT8LookUpPipeline : public ShaderPipeline {
 public:
 	CLUT8LookUpPipeline();
 
-	void setPaletteTexture(const GLTexture *paletteTexture) { _paletteTexture = paletteTexture; }
+	void setPaletteTexture(const Texture *paletteTexture) { _paletteTexture = paletteTexture; }
 
 protected:
-	void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
+	void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
 
 private:
-	const GLTexture *_paletteTexture;
+	const Texture *_paletteTexture;
 };
 #endif // !USE_FORCED_GLES
 
diff --git a/backends/graphics/opengl/pipelines/fixed.cpp b/backends/graphics/opengl/pipelines/fixed.cpp
index 370438a37e4..2f9c33236c1 100644
--- a/backends/graphics/opengl/pipelines/fixed.cpp
+++ b/backends/graphics/opengl/pipelines/fixed.cpp
@@ -56,7 +56,7 @@ void FixedPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
 	}
 }
 
-void FixedPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
+void FixedPipeline::drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
 	assert(isActive());
 
 	texture.bind();
diff --git a/backends/graphics/opengl/pipelines/fixed.h b/backends/graphics/opengl/pipelines/fixed.h
index 7de0979a099..f270ba575ec 100644
--- a/backends/graphics/opengl/pipelines/fixed.h
+++ b/backends/graphics/opengl/pipelines/fixed.h
@@ -37,7 +37,7 @@ public:
 
 protected:
 	void activateInternal() override;
-	void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
+	void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
 
 	GLfloat _r, _g, _b, _a;
 };
diff --git a/backends/graphics/opengl/pipelines/libretro.cpp b/backends/graphics/opengl/pipelines/libretro.cpp
index 635dcf8b5a8..a30d649afff 100644
--- a/backends/graphics/opengl/pipelines/libretro.cpp
+++ b/backends/graphics/opengl/pipelines/libretro.cpp
@@ -138,7 +138,7 @@ static const char *const g_compatFragment =
 class LibRetroTextureTarget : public TextureTarget {
 public:
 	bool setScaledSize(uint width, uint height, const Common::Rect &scalingRect) {
-		GLTexture *texture = getTexture();
+		Texture *texture = getTexture();
 		if (!texture->setSize(width, height)) {
 			return false;
 		}
@@ -196,7 +196,7 @@ public:
 protected:
 	void activateInternal() override {}
 	void deactivateInternal() override {}
-	void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override { }
+	void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override { }
 };
 
 LibRetroPipeline::LibRetroPipeline()
@@ -228,7 +228,7 @@ static void setLinearFiltering(GLuint glTexture, bool enable) {
 	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter));
 }
 
-void LibRetroPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
+void LibRetroPipeline::drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
 	if (!_needsScaling) {
 		_outputPipeline.drawTexture(texture, coordinates, texcoords);
 		return;
@@ -397,7 +397,7 @@ bool LibRetroPipeline::loadTextures(Common::SearchSet &archSet) {
 	for (LibRetro::ShaderPreset::TextureArray::const_iterator
 		 i = _shaderPreset->textures.begin(), end = _shaderPreset->textures.end();
 		 i != end; ++i) {
-		Texture texture = loadTexture(_shaderPreset->basePath.join(i->fileName).normalize(), _shaderPreset->container, archSet);
+		LibRetroTexture texture = loadTexture(_shaderPreset->basePath.join(i->fileName).normalize(), _shaderPreset->container, archSet);
 		texture.id = i->id;
 
 		if (!texture.textureData || !texture.glTexture) {
@@ -577,7 +577,7 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
 		pass.buildTexCoords(passId, aliases);
 		pass.buildTexSamplers(passId, _textures, aliases);
 		if (passId > 0) {
-			GLTexture *const texture = _passes[passId - 1].target->getTexture();
+			Texture *const texture = _passes[passId - 1].target->getTexture();
 			texture->enableLinearFiltering(i->filteringMode == LibRetro::kFilteringModeLinear);
 			texture->setWrapMode(i->wrapMode);
 			pass.inputTexture = texture;
@@ -736,12 +736,12 @@ void LibRetroPipeline::setupPassUniforms(const uint id) {
 	}
 }
 
-void LibRetroPipeline::setShaderTexUniforms(const Common::String &prefix, Shader *shader, const GLTexture &texture) {
+void LibRetroPipeline::setShaderTexUniforms(const Common::String &prefix, Shader *shader, const Texture &texture) {
 	shader->setUniform(prefix + "InputSize", Math::Vector2d(texture.getLogicalWidth(), texture.getLogicalHeight()));
 	shader->setUniform(prefix + "TextureSize", Math::Vector2d(texture.getWidth(), texture.getHeight()));
 }
 
-LibRetroPipeline::Texture LibRetroPipeline::loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet) {
+LibRetroPipeline::LibRetroTexture LibRetroPipeline::loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet) {
 	Common::String baseName(fileName.baseName());
 	const char *extension = nullptr;
 	for (int dotPos = baseName.size() - 1; dotPos >= 0; --dotPos) {
@@ -753,7 +753,7 @@ LibRetroPipeline::Texture LibRetroPipeline::loadTexture(const Common::Path &file
 
 	if (!extension) {
 		warning("LibRetroPipeline::loadTexture: File name '%s' misses extension", fileName.toString().c_str());
-		return Texture();
+		return LibRetroTexture();
 	}
 
 	for (const ImageLoader *loader = s_imageLoaders; loader->extension; ++loader) {
@@ -761,18 +761,18 @@ LibRetroPipeline::Texture LibRetroPipeline::loadTexture(const Common::Path &file
 			Graphics::Surface *textureData = loader->load(fileName, container, archSet);
 			if (!textureData) {
 				warning("LibRetroPipeline::loadTexture: Loader for '%s' could not load file '%s'", loader->extension, fileName.toString().c_str());
-				return Texture();
+				return LibRetroTexture();
 			}
 
-			GLTexture *texture = new GLTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+			Texture *texture = new Texture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
 			texture->setSize(textureData->w, textureData->h);
 			texture->updateArea(Common::Rect(textureData->w, textureData->h), *textureData);
-			return Texture(textureData, texture);
+			return LibRetroTexture(textureData, texture);
 		}
 	}
 
 	warning("LibRetroPipeline::loadTexture: No loader for file '%s' present", fileName.toString().c_str());
-	return Texture();
+	return LibRetroTexture();
 }
 
 void LibRetroPipeline::Pass::buildTexCoords(const uint id, const Common::StringArray &aliases) {
@@ -940,7 +940,7 @@ void LibRetroPipeline::renderPassSetupTextures(const Pass &pass) {
 
 	for (Pass::TextureSamplerArray::const_iterator i = pass.texSamplers.begin(), end = pass.texSamplers.end();
 		 i != end; ++i) {
-		const GLTexture *texture = nullptr;
+		const Texture *texture = nullptr;
 
 		switch (i->type) {
 		case Pass::TextureSampler::kTypeTexture:
diff --git a/backends/graphics/opengl/pipelines/libretro.h b/backends/graphics/opengl/pipelines/libretro.h
index a8b82a163a8..5a8ea684968 100644
--- a/backends/graphics/opengl/pipelines/libretro.h
+++ b/backends/graphics/opengl/pipelines/libretro.h
@@ -77,7 +77,7 @@ public:
 private:
 	void activateInternal() override;
 	void deactivateInternal() override;
-	void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
+	void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
 
 	bool loadTextures(Common::SearchSet &archSet);
 	bool loadPasses(Common::SearchSet &archSet);
@@ -85,7 +85,7 @@ private:
 	void setPipelineState();
 	bool setupFBOs();
 	void setupPassUniforms(const uint id);
-	void setShaderTexUniforms(const Common::String &prefix, Shader *shader, const GLTexture &texture);
+	void setShaderTexUniforms(const Common::String &prefix, Shader *shader, const Texture &texture);
 
 	/* Pipelines used to draw all layers
 	 * First before the scaler then after it to draw on screen
@@ -109,17 +109,17 @@ private:
 	Common::Array<LibRetroTextureTarget> _inputTargets;
 	uint _currentTarget;
 
-	struct Texture {
-		Texture() : textureData(nullptr), glTexture(nullptr) {}
-		Texture(Graphics::Surface *tD, GLTexture *glTex) : textureData(tD), glTexture(glTex) {}
+	struct LibRetroTexture {
+		LibRetroTexture() : textureData(nullptr), glTexture(nullptr) {}
+		LibRetroTexture(Graphics::Surface *tD, Texture *glTex) : textureData(tD), glTexture(glTex) {}
 
 		Common::String id;
 		Graphics::Surface *textureData;
-		GLTexture *glTexture;
+		Texture *glTexture;
 	};
-	Texture loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet);
+	LibRetroTexture loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet);
 
-	typedef Common::Array<Texture> TextureArray;
+	typedef Common::Array<LibRetroTexture> TextureArray;
 	TextureArray _textures;
 
 	struct Pass {
@@ -242,7 +242,7 @@ private:
 		/**
 		 * Input texture of the pass.
 		 */
-		const GLTexture *inputTexture;
+		const Texture *inputTexture;
 
 		/**
 		 * Vertex coordinates used for drawing.
diff --git a/backends/graphics/opengl/pipelines/libretro/types.h b/backends/graphics/opengl/pipelines/libretro/types.h
index 92054566600..fcf205c1ca1 100644
--- a/backends/graphics/opengl/pipelines/libretro/types.h
+++ b/backends/graphics/opengl/pipelines/libretro/types.h
@@ -23,7 +23,7 @@
 #define BACKENDS_GRAPHICS_OPENGL_PIPELINES_LIBRETRO_TYPES_H
 
 #include "graphics/opengl/system_headers.h"
-#include "backends/graphics/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 
 #if !USE_FORCED_GLES
 #include "common/str.h"
diff --git a/backends/graphics/opengl/pipelines/pipeline.h b/backends/graphics/opengl/pipelines/pipeline.h
index ecab37851b0..d6d1f042ed4 100644
--- a/backends/graphics/opengl/pipelines/pipeline.h
+++ b/backends/graphics/opengl/pipelines/pipeline.h
@@ -25,7 +25,7 @@
 #include "graphics/opengl/system_headers.h"
 
 #include "backends/graphics/opengl/framebuffer.h"
-#include "backends/graphics/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 
 #include "math/matrix4.h"
 
@@ -83,15 +83,15 @@ public:
 	 * @param texture     Texture to use for drawing.
 	 * @param coordinates x1, y1, x2, y2 coordinates where to draw the texture.
 	 */
-	inline void drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
+	inline void drawTexture(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
 		drawTextureInternal(texture, coordinates, texcoords);
 	}
 
-	inline void drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
+	inline void drawTexture(const Texture &texture, const GLfloat *coordinates) {
 		drawTextureInternal(texture, coordinates, texture.getTexCoords());
 	}
 
-	inline void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
+	inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
 		const GLfloat coordinates[4*2] = {
 			x,     y,
 			x + w, y,
@@ -101,7 +101,7 @@ public:
 		drawTextureInternal(texture, coordinates, texture.getTexCoords());
 	}
 
-	inline void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h, const Common::Rect &clip) {
+	inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h, const Common::Rect &clip) {
 		const GLfloat coordinates[4*2] = {
 			x,     y,
 			x + w, y,
@@ -148,7 +148,7 @@ protected:
 	 */
 	virtual void deactivateInternal();
 
-	virtual void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) = 0;
+	virtual void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) = 0;
 
 	bool isActive() const { return activePipeline == this; }
 
diff --git a/backends/graphics/opengl/pipelines/shader.cpp b/backends/graphics/opengl/pipelines/shader.cpp
index ac352a0c2e8..708a6111e08 100644
--- a/backends/graphics/opengl/pipelines/shader.cpp
+++ b/backends/graphics/opengl/pipelines/shader.cpp
@@ -76,7 +76,7 @@ void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
 	_colorDirty = true;
 }
 
-void ShaderPipeline::drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
+void ShaderPipeline::drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
 	assert(isActive());
 
 	texture.bind();
diff --git a/backends/graphics/opengl/pipelines/shader.h b/backends/graphics/opengl/pipelines/shader.h
index 4130bb0e684..560b65871c5 100644
--- a/backends/graphics/opengl/pipelines/shader.h
+++ b/backends/graphics/opengl/pipelines/shader.h
@@ -41,7 +41,7 @@ public:
 protected:
 	void activateInternal() override;
 	void deactivateInternal() override;
-	void drawTextureInternal(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
+	void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
 
 	GLuint _coordsVBO;
 	GLuint _texcoordsVBO;
diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp
index 4c36455569d..bd48a3650b7 100644
--- a/backends/graphics/opengl/texture.cpp
+++ b/backends/graphics/opengl/texture.cpp
@@ -39,188 +39,6 @@
 
 namespace OpenGL {
 
-GLTexture::GLTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType)
-	: _glIntFormat(glIntFormat), _glFormat(glFormat), _glType(glType),
-	  _width(0), _height(0), _logicalWidth(0), _logicalHeight(0),
-	  _texCoords(), _glFilter(GL_NEAREST),
-	  _glTexture(0) {
-	create();
-}
-
-GLTexture::~GLTexture() {
-	GL_CALL_SAFE(glDeleteTextures, (1, &_glTexture));
-}
-
-void GLTexture::enableLinearFiltering(bool enable) {
-	if (enable) {
-		_glFilter = GL_LINEAR;
-	} else {
-		_glFilter = GL_NEAREST;
-	}
-
-	bind();
-
-	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _glFilter));
-	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:
-		default:
-			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;
-}
-
-void GLTexture::create() {
-	// Release old texture name in case it exists.
-	destroy();
-
-	// Get a new texture name.
-	GL_CALL(glGenTextures(1, &_glTexture));
-
-	// Set up all texture parameters.
-	bind();
-	GL_CALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
-	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _glFilter));
-	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _glFilter));
-	if (OpenGLContext.textureEdgeClampSupported) {
-		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
-		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
-	} else {
-#if !USE_FORCED_GLES && !USE_FORCED_GLES2
-		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
-		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
-#endif
-	}
-
-	// If a size is specified, allocate memory for it.
-	if (_width != 0 && _height != 0) {
-		// Allocate storage for OpenGL texture.
-		GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, _glIntFormat, _width, _height,
-		                     0, _glFormat, _glType, nullptr));
-	}
-}
-
-void GLTexture::bind() const {
-	GL_CALL(glBindTexture(GL_TEXTURE_2D, _glTexture));
-}
-
-bool GLTexture::setSize(uint width, uint height) {
-	const uint oldWidth  = _width;
-	const uint oldHeight = _height;
-
-	_logicalWidth  = width;
-	_logicalHeight = height;
-
-	if (!OpenGLContext.NPOTSupported) {
-		_width  = Common::nextHigher2(width);
-		_height = Common::nextHigher2(height);
-	} else {
-		_width  = width;
-		_height = height;
-	}
-
-	// If a size is specified, allocate memory for it.
-	if (width != 0 && height != 0) {
-		const GLfloat texWidth = (GLfloat)width / _width;
-		const GLfloat texHeight = (GLfloat)height / _height;
-
-		_texCoords[0] = 0;
-		_texCoords[1] = 0;
-
-		_texCoords[2] = texWidth;
-		_texCoords[3] = 0;
-
-		_texCoords[4] = 0;
-		_texCoords[5] = texHeight;
-
-		_texCoords[6] = texWidth;
-		_texCoords[7] = texHeight;
-
-		// Allocate storage for OpenGL texture if necessary.
-		if (oldWidth != _width || oldHeight != _height) {
-			bind();
-			bool error;
-			GL_CALL_CHECK(error, glTexImage2D(GL_TEXTURE_2D, 0, _glIntFormat, _width, _height,
-			             0, _glFormat, _glType, nullptr));
-			if (error) {
-				return false;
-			}
-		}
-	}
-	return true;
-}
-
-void GLTexture::updateArea(const Common::Rect &area, const Graphics::Surface &src) {
-	// Set the texture on the active texture unit.
-	bind();
-
-	// Update the actual texture.
-	// Although we have the area of the texture buffer we want to update we
-	// cannot take advantage of the left/right boundaries here because it is
-	// not possible to specify a pitch to glTexSubImage2D. To be precise, with
-	// plain OpenGL we could set GL_UNPACK_ROW_LENGTH to achieve this. However,
-	// OpenGL ES 1.0 does not support GL_UNPACK_ROW_LENGTH. Thus, we are left
-	// with the following options:
-	//
-	// 1) (As we do right now) Simply always update the whole texture lines of
-	//    rect changed. This is simplest to implement. In case performance is
-	//    really an issue we can think of switching to another method.
-	//
-	// 2) Copy the dirty rect to a temporary buffer and upload that by using
-	//    glTexSubImage2D. This is what the Android backend does. It is more
-	//    complicated though.
-	//
-	// 3) Use glTexSubImage2D per line changed. This is what the old OpenGL
-	//    graphics manager did but it is much slower! Thus, we do not use it.
-	GL_CALL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, area.top, src.w, area.height(),
-	                       _glFormat, _glType, src.getBasePtr(0, area.top)));
-}
-
 //
 // Surface
 //
@@ -290,20 +108,20 @@ Common::Rect Surface::getDirtyArea() const {
 // Surface implementations
 //
 
-Texture::Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format)
+TextureSurface::TextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format)
 	: Surface(), _format(format), _glTexture(glIntFormat, glFormat, glType),
 	  _textureData(), _userPixelData() {
 }
 
-Texture::~Texture() {
+TextureSurface::~TextureSurface() {
 	_textureData.free();
 }
 
-void Texture::destroy() {
+void TextureSurface::destroy() {
 	_glTexture.destroy();
 }
 
-void Texture::recreate() {
+void TextureSurface::recreate() {
 	_glTexture.create();
 
 	// In case image date exists assure it will be completely refreshed next
@@ -313,11 +131,11 @@ void Texture::recreate() {
 	}
 }
 
-void Texture::enableLinearFiltering(bool enable) {
+void TextureSurface::enableLinearFiltering(bool enable) {
 	_glTexture.enableLinearFiltering(enable);
 }
 
-void Texture::allocate(uint width, uint height) {
+void TextureSurface::allocate(uint width, uint height) {
 	// Assure the texture can contain our user data.
 	_glTexture.setSize(width, height);
 
@@ -338,7 +156,7 @@ void Texture::allocate(uint width, uint height) {
 	flagDirty();
 }
 
-void Texture::updateGLTexture() {
+void TextureSurface::updateGLTexture() {
 	if (!isDirty()) {
 		return;
 	}
@@ -348,7 +166,7 @@ void Texture::updateGLTexture() {
 	updateGLTexture(dirtyArea);
 }
 
-void Texture::updateGLTexture(Common::Rect &dirtyArea) {
+void TextureSurface::updateGLTexture(Common::Rect &dirtyArea) {
 	// In case we use linear filtering we might need to duplicate the last
 	// pixel row/column to avoid glitches with filtering.
 	if (_glTexture.isLinearFilteringEnabled()) {
@@ -384,8 +202,8 @@ void Texture::updateGLTexture(Common::Rect &dirtyArea) {
 	clearDirty();
 }
 
-FakeTexture::FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat)
-	: Texture(glIntFormat, glFormat, glType, format),
+FakeTextureSurface::FakeTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat)
+	: TextureSurface(glIntFormat, glFormat, glType, format),
 	  _fakeFormat(fakeFormat),
 	  _rgbData(),
 	  _palette(nullptr),
@@ -395,15 +213,15 @@ FakeTexture::FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, con
 	}
 }
 
-FakeTexture::~FakeTexture() {
+FakeTextureSurface::~FakeTextureSurface() {
 	delete[] _palette;
 	delete[] _mask;
 	_palette = nullptr;
 	_rgbData.free();
 }
 
-void FakeTexture::allocate(uint width, uint height) {
-	Texture::allocate(width, height);
+void FakeTextureSurface::allocate(uint width, uint height) {
+	TextureSurface::allocate(width, height);
 
 	// We only need to reinitialize our surface when the output size
 	// changed.
@@ -414,7 +232,7 @@ void FakeTexture::allocate(uint width, uint height) {
 	_rgbData.create(width, height, getFormat());
 }
 
-void FakeTexture::setMask(const byte *mask) {
+void FakeTextureSurface::setMask(const byte *mask) {
 	if (mask) {
 		const uint numPixels = _rgbData.w * _rgbData.h;
 
@@ -430,7 +248,7 @@ void FakeTexture::setMask(const byte *mask) {
 	flagDirty();
 }
 
-void FakeTexture::setColorKey(uint colorKey) {
+void FakeTextureSurface::setColorKey(uint colorKey) {
 	if (!_palette)
 		return;
 
@@ -445,7 +263,7 @@ void FakeTexture::setColorKey(uint colorKey) {
 	flagDirty();
 }
 
-void FakeTexture::setPalette(uint start, uint colors, const byte *palData) {
+void FakeTextureSurface::setPalette(uint start, uint colors, const byte *palData) {
 	if (!_palette)
 		return;
 
@@ -455,13 +273,13 @@ void FakeTexture::setPalette(uint start, uint colors, const byte *palData) {
 	flagDirty();
 }
 
-void FakeTexture::updateGLTexture() {
+void FakeTextureSurface::updateGLTexture() {
 	if (!isDirty()) {
 		return;
 	}
 
 	// Convert color space.
-	Graphics::Surface *outSurf = Texture::getSurface();
+	Graphics::Surface *outSurf = TextureSurface::getSurface();
 
 	const Common::Rect dirtyArea = getDirtyArea();
 
@@ -471,10 +289,10 @@ void FakeTexture::updateGLTexture() {
 	applyPaletteAndMask(dst, src, outSurf->pitch, _rgbData.pitch, _rgbData.w, dirtyArea, outSurf->format, _rgbData.format);
 
 	// Do generic handling of updating the texture.
-	Texture::updateGLTexture();
+	TextureSurface::updateGLTexture();
 }
 
-void FakeTexture::applyPaletteAndMask(byte *dst, const byte *src, uint dstPitch, uint srcPitch, uint srcWidth, const Common::Rect &dirtyArea, const Graphics::PixelFormat &dstFormat, const Graphics::PixelFormat &srcFormat) const {
+void FakeTextureSurface::applyPaletteAndMask(byte *dst, const byte *src, uint dstPitch, uint srcPitch, uint srcWidth, const Common::Rect &dirtyArea, const Graphics::PixelFormat &dstFormat, const Graphics::PixelFormat &srcFormat) const {
 	if (_palette) {
 		Graphics::crossBlitMap(dst, src, dstPitch, srcPitch, dirtyArea.width(), dirtyArea.height(), dstFormat.bytesPerPixel, _palette);
 	} else {
@@ -508,17 +326,17 @@ void FakeTexture::applyPaletteAndMask(byte *dst, const byte *src, uint dstPitch,
 	}
 }
 
-TextureRGB555::TextureRGB555()
-	: FakeTexture(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) {
+TextureSurfaceRGB555::TextureSurfaceRGB555()
+	: FakeTextureSurface(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) {
 }
 
-void TextureRGB555::updateGLTexture() {
+void TextureSurfaceRGB555::updateGLTexture() {
 	if (!isDirty()) {
 		return;
 	}
 
 	// Convert color space.
-	Graphics::Surface *outSurf = Texture::getSurface();
+	Graphics::Surface *outSurf = TextureSurface::getSurface();
 
 	const Common::Rect dirtyArea = getDirtyArea();
 
@@ -542,25 +360,25 @@ void TextureRGB555::updateGLTexture() {
 	}
 
 	// Do generic handling of updating the texture.
-	Texture::updateGLTexture();
+	TextureSurface::updateGLTexture();
 }
 
-TextureRGBA8888Swap::TextureRGBA8888Swap()
+TextureSurfaceRGBA8888Swap::TextureSurfaceRGBA8888Swap()
 #ifdef SCUMM_LITTLE_ENDIAN
-	: FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) // RGBA8888 -> ABGR8888
+	: FakeTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) // RGBA8888 -> ABGR8888
 #else
-	: FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) // ABGR8888 -> RGBA8888
+	: FakeTextureSurface(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) // ABGR8888 -> RGBA8888
 #endif
 	  {
 }
 
-void TextureRGBA8888Swap::updateGLTexture() {
+void TextureSurfaceRGBA8888Swap::updateGLTexture() {
 	if (!isDirty()) {
 		return;
 	}
 
 	// Convert color space.
-	Graphics::Surface *outSurf = Texture::getSurface();
+	Graphics::Surface *outSurf = TextureSurface::getSurface();
 
 	const Common::Rect dirtyArea = getDirtyArea();
 
@@ -582,16 +400,16 @@ void TextureRGBA8888Swap::updateGLTexture() {
 	}
 
 	// Do generic handling of updating the texture.
-	Texture::updateGLTexture();
+	TextureSurface::updateGLTexture();
 }
 
 #ifdef USE_SCALERS
 
-ScaledTexture::ScaledTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat)
-	: FakeTexture(glIntFormat, glFormat, glType, format, fakeFormat), _convData(nullptr), _scaler(nullptr), _scalerIndex(0), _scaleFactor(1), _extraPixels(0) {
+ScaledTextureSurface::ScaledTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat)
+	: FakeTextureSurface(glIntFormat, glFormat, glType, format, fakeFormat), _convData(nullptr), _scaler(nullptr), _scalerIndex(0), _scaleFactor(1), _extraPixels(0) {
 }
 
-ScaledTexture::~ScaledTexture() {
+ScaledTextureSurface::~ScaledTextureSurface() {
 	delete _scaler;
 
 	if (_convData) {
@@ -600,8 +418,8 @@ ScaledTexture::~ScaledTexture() {
 	}
 }
 
-void ScaledTexture::allocate(uint width, uint height) {
-	Texture::allocate(width * _scaleFactor, height * _scaleFactor);
+void ScaledTextureSurface::allocate(uint width, uint height) {
+	TextureSurface::allocate(width * _scaleFactor, height * _scaleFactor);
 
 	// We only need to reinitialize our surface when the output size
 	// changed.
@@ -621,13 +439,13 @@ void ScaledTexture::allocate(uint width, uint height) {
 	}
 }
 
-void ScaledTexture::updateGLTexture() {
+void ScaledTextureSurface::updateGLTexture() {
 	if (!isDirty()) {
 		return;
 	}
 
 	// Convert color space.
-	Graphics::Surface *outSurf = Texture::getSurface();
+	Graphics::Surface *outSurf = TextureSurface::getSurface();
 
 	Common::Rect dirtyArea = getDirtyArea();
 
@@ -668,10 +486,10 @@ void ScaledTexture::updateGLTexture() {
 	dirtyArea.bottom *= _scaleFactor;
 
 	// Do generic handling of updating the texture.
-	Texture::updateGLTexture(dirtyArea);
+	TextureSurface::updateGLTexture(dirtyArea);
 }
 
-void ScaledTexture::setScaler(uint scalerIndex, int scaleFactor) {
+void ScaledTextureSurface::setScaler(uint scalerIndex, int scaleFactor) {
 	const PluginList &scalerPlugins = ScalerMan.getPlugins();
 	const ScalerPluginObject &scalerPlugin = scalerPlugins[scalerIndex]->get<ScalerPluginObject>();
 
@@ -699,7 +517,7 @@ void ScaledTexture::setScaler(uint scalerIndex, int scaleFactor) {
 // However, in practice (according to fuzzie) it's 8bit. If we run into
 // problems, we need to switch to GL_R8 and GL_RED, but that is only supported
 // for ARB_texture_rg and GLES3+ (EXT_rexture_rg does not support GL_R8).
-TextureCLUT8GPU::TextureCLUT8GPU()
+TextureSurfaceCLUT8GPU::TextureSurfaceCLUT8GPU()
 	: _clut8Texture(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE),
 	  _paletteTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
 	  _target(new TextureTarget()), _clut8Pipeline(new CLUT8LookUpPipeline()),
@@ -714,13 +532,13 @@ TextureCLUT8GPU::TextureCLUT8GPU()
 	_clut8Pipeline->setColor(1.0f, 1.0f, 1.0f, 1.0f);
 }
 
-TextureCLUT8GPU::~TextureCLUT8GPU() {
+TextureSurfaceCLUT8GPU::~TextureSurfaceCLUT8GPU() {
 	delete _clut8Pipeline;
 	delete _target;
 	_clut8Data.free();
 }
 
-void TextureCLUT8GPU::destroy() {
+void TextureSurfaceCLUT8GPU::destroy() {
 	_clut8Texture.destroy();
 	_paletteTexture.destroy();
 	_target->destroy();
@@ -728,7 +546,7 @@ void TextureCLUT8GPU::destroy() {
 	_clut8Pipeline = nullptr;
 }
 
-void TextureCLUT8GPU::recreate() {
+void TextureSurfaceCLUT8GPU::recreate() {
 	_clut8Texture.create();
 	_paletteTexture.create();
 	_target->create();
@@ -749,11 +567,11 @@ void TextureCLUT8GPU::recreate() {
 	}
 }
 
-void TextureCLUT8GPU::enableLinearFiltering(bool enable) {
+void TextureSurfaceCLUT8GPU::enableLinearFiltering(bool enable) {
 	_target->getTexture()->enableLinearFiltering(enable);
 }
 
-void TextureCLUT8GPU::allocate(uint width, uint height) {
+void TextureSurfaceCLUT8GPU::allocate(uint width, uint height) {
 	// Assure the texture can contain our user data.
 	_clut8Texture.setSize(width, height);
 	_target->setSize(width, height, Common::kRotationNormal);
@@ -788,11 +606,11 @@ void TextureCLUT8GPU::allocate(uint width, uint height) {
 	flagDirty();
 }
 
-Graphics::PixelFormat TextureCLUT8GPU::getFormat() const {
+Graphics::PixelFormat TextureSurfaceCLUT8GPU::getFormat() const {
 	return Graphics::PixelFormat::createFormatCLUT8();
 }
 
-void TextureCLUT8GPU::setColorKey(uint colorKey) {
+void TextureSurfaceCLUT8GPU::setColorKey(uint colorKey) {
 	// The key color is set to black so the color value is pre-multiplied with the alpha value
 	// to avoid color fringes due to filtering.
 	// Erasing the color data is not a problem as the palette is always fully re-initialized
@@ -805,7 +623,7 @@ void TextureCLUT8GPU::setColorKey(uint colorKey) {
 	_paletteDirty = true;
 }
 
-void TextureCLUT8GPU::setPalette(uint start, uint colors, const byte *palData) {
+void TextureSurfaceCLUT8GPU::setPalette(uint start, uint colors, const byte *palData) {
 	byte *dst = _palette + start * 4;
 
 	while (colors-- > 0) {
@@ -819,11 +637,11 @@ void TextureCLUT8GPU::setPalette(uint start, uint colors, const byte *palData) {
 	_paletteDirty = true;
 }
 
-const GLTexture &TextureCLUT8GPU::getGLTexture() const {
+const Texture &TextureSurfaceCLUT8GPU::getGLTexture() const {
 	return *_target->getTexture();
 }
 
-void TextureCLUT8GPU::updateGLTexture() {
+void TextureSurfaceCLUT8GPU::updateGLTexture() {
 	const bool needLookUp = Surface::isDirty() || _paletteDirty;
 
 	// Update CLUT8 texture if necessary.
@@ -853,7 +671,7 @@ void TextureCLUT8GPU::updateGLTexture() {
 	}
 }
 
-void TextureCLUT8GPU::lookUpColors() {
+void TextureSurfaceCLUT8GPU::lookUpColors() {
 	// Setup pipeline to do color look up.
 	_clut8Pipeline->activate();
 
diff --git a/backends/graphics/opengl/texture.h b/backends/graphics/opengl/texture.h
index ab251f3e318..edad03081f6 100644
--- a/backends/graphics/opengl/texture.h
+++ b/backends/graphics/opengl/texture.h
@@ -24,6 +24,7 @@
 
 #include "graphics/opengl/system_headers.h"
 #include "graphics/opengl/context.h"
+#include "graphics/opengl/texture.h"
 
 #include "graphics/pixelformat.h"
 #include "graphics/surface.h"
@@ -34,132 +35,6 @@ class Scaler;
 
 namespace OpenGL {
 
-enum WrapMode {
-	kWrapModeBorder,
-	kWrapModeEdge,
-	kWrapModeRepeat,
-	kWrapModeMirroredRepeat
-};
-
-/**
- * A simple GL texture object abstraction.
- *
- * This is used for low-level GL texture handling.
- */
-class GLTexture {
-public:
-	/**
-	 * Constrcut a new GL texture object.
-	 *
-	 * @param glIntFormat The internal format to use.
-	 * @param glFormat    The input format.
-	 * @param glType      The input type.
-	 */
-	GLTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType);
-	~GLTexture();
-
-	/**
-	 * Enable or disable linear texture filtering.
-	 *
-	 * @param enable true to enable and false to disable.
-	 */
-	void enableLinearFiltering(bool enable);
-
-	/**
-	 * Test whether linear filtering is enabled.
-	 */
-	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.
-	 */
-	void destroy();
-
-	/**
-	 * Create the OpenGL texture name.
-	 */
-	void create();
-
-	/**
-	 * Bind the texture to the active texture unit.
-	 */
-	void bind() const;
-
-	/**
-	 * Sets the size of the texture in pixels.
-	 *
-	 * The internal OpenGL texture might have a different size. To query the
-	 * actual size use getWidth()/getHeight().
-	 *
-	 * @param width  The desired logical width.
-	 * @param height The desired logical height.
-	 * @return Whether the call was successful
-	 */
-	bool setSize(uint width, uint height);
-
-	/**
-	 * Copy image data to the texture.
-	 *
-	 * @param area     The area to update.
-	 * @param src      Surface for the whole texture containing the pixel data
-	 *                 to upload. Only the area described by area will be
-	 *                 uploaded.
-	 */
-	void updateArea(const Common::Rect &area, const Graphics::Surface &src);
-
-	/**
-	 * Query the GL texture's width.
-	 */
-	uint getWidth() const { return _width; }
-
-	/**
-	 * Query the GL texture's height.
-	 */
-	uint getHeight() const { return _height; }
-
-	/**
-	 * Query the logical texture's width.
-	 */
-	uint getLogicalWidth() const { return _logicalWidth; }
-
-	/**
-	 * Query the logical texture's height.
-	 */
-	uint getLogicalHeight() const { return _logicalHeight; }
-
-	/**
-	 * Obtain texture coordinates for rectangular drawing.
-	 */
-	const GLfloat *getTexCoords() const { return _texCoords; }
-
-	/**
-	 * Obtain texture name.
-	 *
-	 * Beware that the texture name changes whenever create is used.
-	 * destroy will invalidate the texture name.
-	 */
-	GLuint getGLTexture() const { return _glTexture; }
-private:
-	const GLenum _glIntFormat;
-	const GLenum _glFormat;
-	const GLenum _glType;
-
-	uint _width, _height;
-	uint _logicalWidth, _logicalHeight;
-	GLfloat _texCoords[4*2];
-
-	GLint _glFilter;
-
-	GLuint _glTexture;
-};
-
 /**
  * Interface for OpenGL implementations of a 2D surface.
  */
@@ -262,7 +137,7 @@ public:
 	/**
 	 * Obtain underlying OpenGL texture.
 	 */
-	virtual const GLTexture &getGLTexture() const = 0;
+	virtual const Texture &getGLTexture() const = 0;
 protected:
 	void clearDirty() { _allDirty = false; _dirtyArea = Common::Rect(); }
 
@@ -277,7 +152,7 @@ private:
  * An OpenGL texture wrapper. It automatically takes care of all OpenGL
  * texture handling issues and also provides access to the texture data.
  */
-class Texture : public Surface {
+class TextureSurface : public Surface {
 public:
 	/**
 	 * Create a new texture with the specific internal format.
@@ -287,8 +162,8 @@ public:
 	 * @param glType      The input type.
 	 * @param format      The format used for the texture input.
 	 */
-	Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format);
-	~Texture() override;
+	TextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format);
+	~TextureSurface() override;
 
 	void destroy() override;
 
@@ -310,23 +185,23 @@ public:
 	const Graphics::Surface *getSurface() const override { return &_userPixelData; }
 
 	void updateGLTexture() override;
-	const GLTexture &getGLTexture() const override { return _glTexture; }
+	const Texture &getGLTexture() const override { return _glTexture; }
 protected:
 	const Graphics::PixelFormat _format;
 
 	void updateGLTexture(Common::Rect &dirtyArea);
 
 private:
-	GLTexture _glTexture;
+	Texture _glTexture;
 
 	Graphics::Surface _textureData;
 	Graphics::Surface _userPixelData;
 };
 
-class FakeTexture : public Texture {
+class FakeTextureSurface : public TextureSurface {
 public:
-	FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
-	~FakeTexture() override;
+	FakeTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
+	~FakeTextureSurface() override;
 
 	void allocate(uint width, uint height) override;
 	void setMask(const byte *mask) override;
@@ -351,27 +226,27 @@ protected:
 	uint8 *_mask;
 };
 
-class TextureRGB555 : public FakeTexture {
+class TextureSurfaceRGB555 : public FakeTextureSurface {
 public:
-	TextureRGB555();
-	~TextureRGB555() override {}
+	TextureSurfaceRGB555();
+	~TextureSurfaceRGB555() override {}
 
 	void updateGLTexture() override;
 };
 
-class TextureRGBA8888Swap : public FakeTexture {
+class TextureSurfaceRGBA8888Swap : public FakeTextureSurface {
 public:
-	TextureRGBA8888Swap();
-	~TextureRGBA8888Swap() override {}
+	TextureSurfaceRGBA8888Swap();
+	~TextureSurfaceRGBA8888Swap() override {}
 
 	void updateGLTexture() override;
 };
 
 #ifdef USE_SCALERS
-class ScaledTexture : public FakeTexture {
+class ScaledTextureSurface : public FakeTextureSurface {
 public:
-	ScaledTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
-	~ScaledTexture() override;
+	ScaledTextureSurface(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
+	~ScaledTextureSurface() override;
 
 	void allocate(uint width, uint height) override;
 
@@ -400,10 +275,10 @@ protected:
 class TextureTarget;
 class CLUT8LookUpPipeline;
 
-class TextureCLUT8GPU : public Surface {
+class TextureSurfaceCLUT8GPU : public Surface {
 public:
-	TextureCLUT8GPU();
-	~TextureCLUT8GPU() override;
+	TextureSurfaceCLUT8GPU();
+	~TextureSurfaceCLUT8GPU() override;
 
 	void destroy() override;
 
@@ -429,7 +304,7 @@ public:
 	const Graphics::Surface *getSurface() const override { return &_userPixelData; }
 
 	void updateGLTexture() override;
-	const GLTexture &getGLTexture() const override;
+	const Texture &getGLTexture() const override;
 
 	static bool isSupportedByContext() {
 		return OpenGLContext.shadersSupported
@@ -439,8 +314,8 @@ public:
 private:
 	void lookUpColors();
 
-	GLTexture _clut8Texture;
-	GLTexture _paletteTexture;
+	Texture _clut8Texture;
+	Texture _paletteTexture;
 
 	TextureTarget *_target;
 	CLUT8LookUpPipeline *_clut8Pipeline;
diff --git a/graphics/module.mk b/graphics/module.mk
index 775adce3df0..9672721219e 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -43,6 +43,7 @@ MODULE_OBJS := \
 	opengl/context.o \
 	opengl/debug.o \
 	opengl/shader.o \
+	opengl/texture.o \
 	palette.o \
 	pixelformat.o \
 	pm5544.o \
diff --git a/graphics/opengl/texture.cpp b/graphics/opengl/texture.cpp
new file mode 100644
index 00000000000..d6f28243c7e
--- /dev/null
+++ b/graphics/opengl/texture.cpp
@@ -0,0 +1,221 @@
+/* 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 "graphics/opengl/system_headers.h"
+
+#ifdef USE_OPENGL
+
+#include "graphics/opengl/texture.h"
+#include "graphics/opengl/debug.h"
+
+#include "common/algorithm.h"
+#include "common/endian.h"
+#include "common/rect.h"
+#include "common/textconsole.h"
+
+namespace OpenGL {
+
+Texture::Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType)
+	: _glIntFormat(glIntFormat), _glFormat(glFormat), _glType(glType),
+	  _width(0), _height(0), _logicalWidth(0), _logicalHeight(0),
+	  _texCoords(), _glFilter(GL_NEAREST),
+	  _glTexture(0) {
+	create();
+}
+
+Texture::~Texture() {
+	GL_CALL_SAFE(glDeleteTextures, (1, &_glTexture));
+}
+
+void Texture::enableLinearFiltering(bool enable) {
+	if (enable) {
+		_glFilter = GL_LINEAR;
+	} else {
+		_glFilter = GL_NEAREST;
+	}
+
+	bind();
+
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _glFilter));
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _glFilter));
+}
+
+void Texture::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:
+		default:
+			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 Texture::destroy() {
+	GL_CALL(glDeleteTextures(1, &_glTexture));
+	_glTexture = 0;
+}
+
+void Texture::create() {
+	// Release old texture name in case it exists.
+	destroy();
+
+	// Get a new texture name.
+	GL_CALL(glGenTextures(1, &_glTexture));
+
+	// Set up all texture parameters.
+	bind();
+	GL_CALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _glFilter));
+	GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _glFilter));
+	if (OpenGLContext.textureEdgeClampSupported) {
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
+	} else {
+#if !USE_FORCED_GLES && !USE_FORCED_GLES2
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
+#endif
+	}
+
+	// If a size is specified, allocate memory for it.
+	if (_width != 0 && _height != 0) {
+		// Allocate storage for OpenGL texture.
+		GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, _glIntFormat, _width, _height,
+		                     0, _glFormat, _glType, nullptr));
+	}
+}
+
+void Texture::bind() const {
+	GL_CALL(glBindTexture(GL_TEXTURE_2D, _glTexture));
+}
+
+bool Texture::setSize(uint width, uint height) {
+	const uint oldWidth  = _width;
+	const uint oldHeight = _height;
+
+	_logicalWidth  = width;
+	_logicalHeight = height;
+
+	if (!OpenGLContext.NPOTSupported) {
+		_width  = Common::nextHigher2(width);
+		_height = Common::nextHigher2(height);
+	} else {
+		_width  = width;
+		_height = height;
+	}
+
+	// If a size is specified, allocate memory for it.
+	if (width != 0 && height != 0) {
+		const GLfloat texWidth = (GLfloat)width / _width;
+		const GLfloat texHeight = (GLfloat)height / _height;
+
+		_texCoords[0] = 0;
+		_texCoords[1] = 0;
+
+		_texCoords[2] = texWidth;
+		_texCoords[3] = 0;
+
+		_texCoords[4] = 0;
+		_texCoords[5] = texHeight;
+
+		_texCoords[6] = texWidth;
+		_texCoords[7] = texHeight;
+
+		// Allocate storage for OpenGL texture if necessary.
+		if (oldWidth != _width || oldHeight != _height) {
+			bind();
+			bool error;
+			GL_CALL_CHECK(error, glTexImage2D(GL_TEXTURE_2D, 0, _glIntFormat, _width, _height,
+			             0, _glFormat, _glType, nullptr));
+			if (error) {
+				return false;
+			}
+		}
+	}
+	return true;
+}
+
+void Texture::updateArea(const Common::Rect &area, const Graphics::Surface &src) {
+	// Set the texture on the active texture unit.
+	bind();
+
+	// Update the actual texture.
+	// Although we have the area of the texture buffer we want to update we
+	// cannot take advantage of the left/right boundaries here because it is
+	// not possible to specify a pitch to glTexSubImage2D. To be precise, with
+	// plain OpenGL we could set GL_UNPACK_ROW_LENGTH to achieve this. However,
+	// OpenGL ES 1.0 does not support GL_UNPACK_ROW_LENGTH. Thus, we are left
+	// with the following options:
+	//
+	// 1) (As we do right now) Simply always update the whole texture lines of
+	//    rect changed. This is simplest to implement. In case performance is
+	//    really an issue we can think of switching to another method.
+	//
+	// 2) Copy the dirty rect to a temporary buffer and upload that by using
+	//    glTexSubImage2D. This is what the Android backend does. It is more
+	//    complicated though.
+	//
+	// 3) Use glTexSubImage2D per line changed. This is what the old OpenGL
+	//    graphics manager did but it is much slower! Thus, we do not use it.
+	GL_CALL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, area.top, src.w, area.height(),
+	                       _glFormat, _glType, src.getBasePtr(0, area.top)));
+}
+
+} // End of namespace OpenGL
+
+#endif
+
diff --git a/graphics/opengl/texture.h b/graphics/opengl/texture.h
new file mode 100644
index 00000000000..d012d4679ea
--- /dev/null
+++ b/graphics/opengl/texture.h
@@ -0,0 +1,163 @@
+/* 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/>.
+ *
+ */
+
+#ifndef GRAPHICS_OPENGL_TEXTURE_H
+#define GRAPHICS_OPENGL_TEXTURE_H
+
+#include "graphics/opengl/system_headers.h"
+#include "graphics/opengl/context.h"
+
+#include "graphics/pixelformat.h"
+#include "graphics/surface.h"
+
+#include "common/rect.h"
+
+namespace OpenGL {
+
+enum WrapMode {
+	kWrapModeBorder,
+	kWrapModeEdge,
+	kWrapModeRepeat,
+	kWrapModeMirroredRepeat
+};
+
+/**
+ * A simple GL texture object abstraction.
+ *
+ * This is used for low-level GL texture handling.
+ */
+class Texture {
+public:
+	/**
+	 * Constrcut a new GL texture object.
+	 *
+	 * @param glIntFormat The internal format to use.
+	 * @param glFormat    The input format.
+	 * @param glType      The input type.
+	 */
+	Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType);
+	~Texture();
+
+	/**
+	 * Enable or disable linear texture filtering.
+	 *
+	 * @param enable true to enable and false to disable.
+	 */
+	void enableLinearFiltering(bool enable);
+
+	/**
+	 * Test whether linear filtering is enabled.
+	 */
+	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.
+	 */
+	void destroy();
+
+	/**
+	 * Create the OpenGL texture name.
+	 */
+	void create();
+
+	/**
+	 * Bind the texture to the active texture unit.
+	 */
+	void bind() const;
+
+	/**
+	 * Sets the size of the texture in pixels.
+	 *
+	 * The internal OpenGL texture might have a different size. To query the
+	 * actual size use getWidth()/getHeight().
+	 *
+	 * @param width  The desired logical width.
+	 * @param height The desired logical height.
+	 * @return Whether the call was successful
+	 */
+	bool setSize(uint width, uint height);
+
+	/**
+	 * Copy image data to the texture.
+	 *
+	 * @param area     The area to update.
+	 * @param src      Surface for the whole texture containing the pixel data
+	 *                 to upload. Only the area described by area will be
+	 *                 uploaded.
+	 */
+	void updateArea(const Common::Rect &area, const Graphics::Surface &src);
+
+	/**
+	 * Query the GL texture's width.
+	 */
+	uint getWidth() const { return _width; }
+
+	/**
+	 * Query the GL texture's height.
+	 */
+	uint getHeight() const { return _height; }
+
+	/**
+	 * Query the logical texture's width.
+	 */
+	uint getLogicalWidth() const { return _logicalWidth; }
+
+	/**
+	 * Query the logical texture's height.
+	 */
+	uint getLogicalHeight() const { return _logicalHeight; }
+
+	/**
+	 * Obtain texture coordinates for rectangular drawing.
+	 */
+	const GLfloat *getTexCoords() const { return _texCoords; }
+
+	/**
+	 * Obtain texture name.
+	 *
+	 * Beware that the texture name changes whenever create is used.
+	 * destroy will invalidate the texture name.
+	 */
+	GLuint getGLTexture() const { return _glTexture; }
+private:
+	const GLenum _glIntFormat;
+	const GLenum _glFormat;
+	const GLenum _glType;
+
+	uint _width, _height;
+	uint _logicalWidth, _logicalHeight;
+	GLfloat _texCoords[4*2];
+
+	GLint _glFilter;
+
+	GLuint _glTexture;
+};
+
+} // End of namespace OpenGL
+
+#endif


Commit: a9ca83819dce6b6d8c3370c1f89c0b223207b65d
    https://github.com/scummvm/scummvm/commit/a9ca83819dce6b6d8c3370c1f89c0b223207b65d
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-11-30T18:21:47+02:00

Commit Message:
BACKENDS: OPENGL: Use the shared Texture class for the overlay in 3D games

Changed paths:
  R backends/graphics3d/opengl/texture.cpp
  R backends/graphics3d/opengl/texture.h
    backends/graphics3d/ios/ios-graphics3d.cpp
    backends/graphics3d/opengl/framebuffer.cpp
    backends/graphics3d/opengl/framebuffer.h
    backends/graphics3d/opengl/surfacerenderer.cpp
    backends/graphics3d/opengl/surfacerenderer.h
    backends/graphics3d/opengl/tiledsurface.cpp
    backends/graphics3d/opengl/tiledsurface.h
    backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.h
    backends/module.mk
    graphics/opengl/texture.cpp
    graphics/opengl/texture.h


diff --git a/backends/graphics3d/ios/ios-graphics3d.cpp b/backends/graphics3d/ios/ios-graphics3d.cpp
index 05e30e4804c..d61d958edf6 100644
--- a/backends/graphics3d/ios/ios-graphics3d.cpp
+++ b/backends/graphics3d/ios/ios-graphics3d.cpp
@@ -28,7 +28,7 @@
 #include "backends/graphics3d/ios/ios-graphics3d.h"
 #include "backends/platform/ios7/ios7_osys_main.h"
 #include "graphics/opengl/context.h"
-#include "backends/graphics3d/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 #include "graphics/blit.h"
 #include "common/translation.h"
 
@@ -236,7 +236,7 @@ void iOSGraphics3dManager::initSize(uint w, uint h, const Graphics::PixelFormat
 	}
 
 	_surfaceRenderer = OpenGL::createBestSurfaceRenderer();
-	_overlayFormat = OpenGL::TextureGL::getRGBAPixelFormat();
+	_overlayFormat = OpenGL::Texture::getRGBAPixelFormat();
 
 	handleResize(sys->getScreenWidth(), sys->getScreenHeight());
 }
diff --git a/backends/graphics3d/opengl/framebuffer.cpp b/backends/graphics3d/opengl/framebuffer.cpp
index 2e851a5cf6e..778dd233291 100644
--- a/backends/graphics3d/opengl/framebuffer.cpp
+++ b/backends/graphics3d/opengl/framebuffer.cpp
@@ -46,16 +46,14 @@ static bool useDepthComponent24() {
 }
 
 FrameBuffer::FrameBuffer(uint width, uint height) :
-		TextureGL(width, height) {
+		Texture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE) {
 	if (!OpenGLContext.framebufferObjectSupported) {
 		error("FrameBuffer Objects are not supported by the current OpenGL context");
 	}
 
-	init();
-}
+	setSize(width, height);
+	enableLinearFiltering(true);
 
-FrameBuffer::FrameBuffer(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height) :
-		TextureGL(texture_name, width, height, texture_width, texture_height) {
 	init();
 }
 
@@ -69,11 +67,11 @@ void FrameBuffer::init() {
 	glGenRenderbuffers(2, _renderBuffers);
 
 	glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, getGLTexture(), 0);
 
 	if (usePackedBuffer()) {
 		glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[0]);
-		glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, _texWidth, _texHeight);
+		glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, getWidth(), getHeight());
 		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]);
 		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]);
 		glBindRenderbuffer(GL_RENDERBUFFER, 0);
@@ -87,18 +85,18 @@ void FrameBuffer::init() {
 #ifndef GL_DEPTH_STENCIL
 #define GL_DEPTH_STENCIL 0x84F9
 #endif
-			glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, _texWidth, _texHeight);
+			glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, getWidth(), getHeight());
 
 #ifndef GL_DEPTH_STENCIL_ATTACHMENT
 #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
 #endif
 			glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]);
 		} else {
-			glRenderbufferStorage(GL_RENDERBUFFER, useDepthComponent24() ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16, _texWidth, _texHeight);
+			glRenderbufferStorage(GL_RENDERBUFFER, useDepthComponent24() ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16, getWidth(), getHeight());
 			glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[0]);
 
 			glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[1]);
-			glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, _texWidth, _texHeight);
+			glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWidth(), getHeight());
 			glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBuffers[1]);
 		}
 		glBindRenderbuffer(GL_RENDERBUFFER, 0);
@@ -115,7 +113,7 @@ void FrameBuffer::init() {
 
 void FrameBuffer::attach() {
 	glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer);
-	glViewport(0, 0, _width, _height);
+	glViewport(0, 0, getLogicalWidth(), getLogicalHeight());
 }
 
 void FrameBuffer::detach() {
@@ -152,11 +150,11 @@ void MultiSampleFrameBuffer::init() {
 
 	glGenRenderbuffers(1, &_msColorId);
 	glBindRenderbuffer(GL_RENDERBUFFER, _msColorId);
-	glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msSamples, GL_RGBA8, getTexWidth(), getTexHeight());
+	glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msSamples, GL_RGBA8, getWidth(), getHeight());
 
 	glGenRenderbuffers(1, &_msDepthId);
 	glBindRenderbuffer(GL_RENDERBUFFER, _msDepthId);
-	glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msSamples, GL_DEPTH24_STENCIL8, getTexWidth(), getTexHeight());
+	glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msSamples, GL_DEPTH24_STENCIL8, getWidth(), getHeight());
 
 	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _msColorId);
 	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _msDepthId);
@@ -172,13 +170,13 @@ void MultiSampleFrameBuffer::init() {
 void MultiSampleFrameBuffer::attach() {
 	glBindFramebuffer(GL_READ_FRAMEBUFFER, getFrameBufferName());
 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _msFrameBufferId);
-	glViewport(0, 0, getWidth(), getHeight());
+	glViewport(0, 0, getLogicalWidth(), getLogicalHeight());
 }
 
 void MultiSampleFrameBuffer::detach() {
 	glBindFramebuffer(GL_READ_FRAMEBUFFER, _msFrameBufferId);
 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, getFrameBufferName());
-	glBlitFramebuffer(0, 0, getWidth(), getHeight(), 0, 0, getWidth(), getHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	glBlitFramebuffer(0, 0, getLogicalWidth(), getLogicalHeight(), 0, 0, getLogicalWidth(), getLogicalHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
 	glBindFramebuffer(GL_FRAMEBUFFER, 0);
 }
 
diff --git a/backends/graphics3d/opengl/framebuffer.h b/backends/graphics3d/opengl/framebuffer.h
index 83202a0f4e8..d6baf71a935 100644
--- a/backends/graphics3d/opengl/framebuffer.h
+++ b/backends/graphics3d/opengl/framebuffer.h
@@ -24,16 +24,15 @@
 
 #include "graphics/opengl/system_headers.h"
 
-#include "backends/graphics3d/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 
 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
 
 namespace OpenGL {
 
-class FrameBuffer : public TextureGL {
+class FrameBuffer : public Texture {
 public:
 	FrameBuffer(uint width, uint height);
-	FrameBuffer(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height);
 	virtual ~FrameBuffer();
 
 	virtual void attach();
diff --git a/backends/graphics3d/opengl/surfacerenderer.cpp b/backends/graphics3d/opengl/surfacerenderer.cpp
index db4fbf47b22..6b189650cac 100644
--- a/backends/graphics3d/opengl/surfacerenderer.cpp
+++ b/backends/graphics3d/opengl/surfacerenderer.cpp
@@ -24,7 +24,7 @@
 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
 
 #include "backends/graphics3d/opengl/surfacerenderer.h"
-#include "backends/graphics3d/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 
 #include "graphics/opengl/context.h"
 
@@ -108,9 +108,9 @@ void FixedSurfaceRenderer::prepareState() {
 	glDepthMask(GL_FALSE);
 }
 
-void FixedSurfaceRenderer::render(const TextureGL *tex, const Math::Rect2d &dest) {
-	float texcropX = tex->getWidth() / float(tex->getTexWidth());
-	float texcropY = tex->getHeight() / float(tex->getTexHeight());
+void FixedSurfaceRenderer::render(const Texture *tex, const Math::Rect2d &dest) {
+	float texcropX = tex->getLogicalWidth() / float(tex->getWidth());
+	float texcropY = tex->getLogicalHeight() / float(tex->getHeight());
 	float texTop    = _flipY ? 0.0f : texcropY;
 	float texBottom = _flipY ? texcropY : 0.0f;
 
@@ -139,7 +139,7 @@ void FixedSurfaceRenderer::render(const TextureGL *tex, const Math::Rect2d &dest
 
 	glColor4f(1.0, 1.0, 1.0, 1.0);
 
-	glBindTexture(GL_TEXTURE_2D, tex->getTextureName());
+	tex->bind();
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -247,11 +247,11 @@ void ShaderSurfaceRenderer::prepareState() {
 	glDisable(GL_SCISSOR_TEST);
 }
 
-void ShaderSurfaceRenderer::render(const TextureGL *tex, const Math::Rect2d &dest) {
-	glBindTexture(GL_TEXTURE_2D, tex->getTextureName());
+void ShaderSurfaceRenderer::render(const Texture *tex, const Math::Rect2d &dest) {
+	tex->bind();
 
-	float texcropX = tex->getWidth() / float(tex->getTexWidth());
-	float texcropY = tex->getHeight() / float(tex->getTexHeight());
+	float texcropX = tex->getLogicalWidth() / float(tex->getWidth());
+	float texcropY = tex->getLogicalHeight() / float(tex->getHeight());
 	_boxShader->setUniform("texcrop", Math::Vector2d(texcropX, texcropY));
 	_boxShader->setUniform("flipY", _flipY);
 
diff --git a/backends/graphics3d/opengl/surfacerenderer.h b/backends/graphics3d/opengl/surfacerenderer.h
index f07fbfa7b20..ece185160d0 100644
--- a/backends/graphics3d/opengl/surfacerenderer.h
+++ b/backends/graphics3d/opengl/surfacerenderer.h
@@ -29,7 +29,7 @@
 namespace OpenGL {
 
 class Shader;
-class TextureGL;
+class Texture;
 
 /**
  * A renderer to draw textures as two dimensional surfaces to the screen.
@@ -52,7 +52,7 @@ public:
 	 * y: top [0.0, 1.0] bottom
 	 *
 	 */
-	virtual void render(const TextureGL *tex, const Math::Rect2d &dest) = 0;
+	virtual void render(const Texture *tex, const Math::Rect2d &dest) = 0;
 
 	/**
 	 * Pop the OpenGL state to restore it as it was before calling the prepareState method.
@@ -84,7 +84,7 @@ public:
 
 	// SurfaceRenderer API
 	void prepareState() override;
-	void render(const TextureGL *tex, const Math::Rect2d &dest) override;
+	void render(const Texture *tex, const Math::Rect2d &dest) override;
 	void restorePreviousState() override;
 };
 
@@ -99,7 +99,7 @@ public:
 
 	// SurfaceRenderer API
 	void prepareState() override;
-	void render(const TextureGL *tex, const Math::Rect2d &dest) override;
+	void render(const Texture *tex, const Math::Rect2d &dest) override;
 	void restorePreviousState() override;
 
 private:
diff --git a/backends/graphics3d/opengl/texture.cpp b/backends/graphics3d/opengl/texture.cpp
deleted file mode 100644
index b74b960c76c..00000000000
--- a/backends/graphics3d/opengl/texture.cpp
+++ /dev/null
@@ -1,153 +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/textconsole.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
-
-#include "backends/graphics3d/opengl/texture.h"
-
-#include "graphics/opengl/context.h"
-
-namespace OpenGL {
-
-template<class T>
-static T nextHigher2(T k) {
-	if (k == 0)
-		return 1;
-	--k;
-
-	for (uint i = 1; i < sizeof(T) * 8; i <<= 1)
-		k = k | k >> i;
-
-	return k + 1;
-}
-
-const Graphics::PixelFormat TextureGL::getRGBAPixelFormat() {
-#ifdef SCUMM_BIG_ENDIAN
-	return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
-#else
-	return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
-#endif
-}
-
-const Graphics::PixelFormat TextureGL::get565PixelFormat() {
-	return Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
-}
-
-TextureGL::TextureGL(const Graphics::Surface &srf) :
-		_managedTexture(true), _width(srf.w), _height(srf.h) {
-	if (OpenGLContext.NPOTSupported) {
-		_texWidth  = _width;
-		_texHeight = _height;
-	} else {
-		_texWidth  = nextHigher2(_width);
-		_texHeight = nextHigher2(_height);
-	}
-
-	const Graphics::Surface *surfaceToUpload = &srf;
-	Graphics::Surface *convertedSurface = nullptr;
-	Graphics::Surface *copiedSurface = nullptr;
-
-	GLenum type;
-	GLenum format;
-
-	if (srf.format == getRGBAPixelFormat()) {
-		type = GL_UNSIGNED_BYTE;
-		format = GL_RGBA;
-	} else if (srf.format == get565PixelFormat()) {
-		type = GL_UNSIGNED_SHORT_5_6_5;
-		format = GL_RGB;
-	} else {
-		type = GL_UNSIGNED_BYTE;
-		format = GL_RGBA;
-		convertedSurface = srf.convertTo(getRGBAPixelFormat());
-		surfaceToUpload = convertedSurface;
-	}
-
-	if (surfaceToUpload->pitch != surfaceToUpload->w * surfaceToUpload->format.bytesPerPixel) {
-		if (OpenGLContext.unpackSubImageSupported) {
-			glPixelStorei(GL_UNPACK_ROW_LENGTH, surfaceToUpload->pitch / surfaceToUpload->format.bytesPerPixel);
-		} else {
-			// When unpack sub-image is not supported we can't specify the pitch
-			// and have to copy the subimage
-			copiedSurface = new Graphics::Surface();
-			copiedSurface->copyFrom(*surfaceToUpload);
-			surfaceToUpload = copiedSurface;
-		}
-	}
-
-	glGenTextures(1, &_texture);
-	glBindTexture(GL_TEXTURE_2D, _texture);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexImage2D(GL_TEXTURE_2D, 0, format, _texWidth, _texHeight, 0, format, type, 0);
-	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _width, _height, format, type, const_cast<void *>(surfaceToUpload->getPixels()));
-
-	if (OpenGLContext.unpackSubImageSupported) {
-		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-	}
-
-	if (convertedSurface) {
-		convertedSurface->free();
-		delete convertedSurface;
-	}
-
-	if (copiedSurface) {
-		copiedSurface->free();
-		delete copiedSurface;
-	}
-}
-
-TextureGL::TextureGL(uint width, uint height) :
-		_managedTexture(true), _width(width), _height(height) {
-	if (OpenGLContext.NPOTSupported) {
-		_texWidth  = _width;
-		_texHeight = _height;
-	} else {
-		_texWidth  = nextHigher2(_width);
-		_texHeight = nextHigher2(_height);
-	}
-	glGenTextures(1, &_texture);
-	glBindTexture(GL_TEXTURE_2D, _texture);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _texWidth, _texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-}
-
-TextureGL::TextureGL(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height) :
-		_managedTexture(false), _texture(texture_name), _width(width), _height(height),
-		_texWidth(texture_width), _texHeight(texture_height) {
-}
-
-TextureGL::~TextureGL() {
-	if (_managedTexture) {
-		glDeleteTextures(1, &_texture);
-	}
-}
-
-} // End of namespace OpenGL
-
-#endif
diff --git a/backends/graphics3d/opengl/texture.h b/backends/graphics3d/opengl/texture.h
deleted file mode 100644
index 110c8aeadda..00000000000
--- a/backends/graphics3d/opengl/texture.h
+++ /dev/null
@@ -1,60 +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/>.
- *
- */
-
-#ifndef BACKENDS_GRAPHICS3D_OPENGL_TEXTURE_H
-#define BACKENDS_GRAPHICS3D_OPENGL_TEXTURE_H
-
-#include "graphics/opengl/system_headers.h"
-
-#include "graphics/surface.h"
-
-#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
-
-namespace OpenGL {
-
-class TextureGL {
-public:
-	TextureGL(const Graphics::Surface &srf);
-	TextureGL(uint width, uint height);
-	TextureGL(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height);
-	virtual ~TextureGL();
-
-	GLuint getTextureName() const { return _texture; }
-	uint getWidth() const { return _width; }
-	uint getHeight() const { return _height; }
-	uint getTexWidth() const { return _texWidth; }
-	uint getTexHeight() const { return _texHeight; }
-
-	static const Graphics::PixelFormat getRGBAPixelFormat();
-	static const Graphics::PixelFormat get565PixelFormat();
-
-protected:
-	bool _managedTexture;
-	GLuint _texture;
-	uint _width, _height;
-	uint _texWidth, _texHeight;
-};
-
-} // End of namespace OpenGL
-
-#endif
-
-#endif
diff --git a/backends/graphics3d/opengl/tiledsurface.cpp b/backends/graphics3d/opengl/tiledsurface.cpp
index 4289f4d3b29..01f19f1f74b 100644
--- a/backends/graphics3d/opengl/tiledsurface.cpp
+++ b/backends/graphics3d/opengl/tiledsurface.cpp
@@ -25,7 +25,7 @@
 
 #include "backends/graphics3d/opengl/tiledsurface.h"
 #include "backends/graphics3d/opengl/surfacerenderer.h"
-#include "backends/graphics3d/opengl/texture.h"
+#include "graphics/opengl/texture.h"
 
 namespace OpenGL {
 
@@ -42,7 +42,9 @@ TiledSurface::TiledSurface(uint width, uint height, const Graphics::PixelFormat
 			Tile &tile = _tiles.back();
 			tile.rect = Common::Rect(textureWidth, textureHeight);
 			tile.rect.translate(x, y);
-			tile.texture = nullptr;
+			tile.texture = new Texture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+			tile.texture->setSize(textureWidth, textureHeight);
+			tile.texture->enableLinearFiltering(true);
 			tile.dirty = true;
 		}
 	}
@@ -72,10 +74,16 @@ void TiledSurface::update() {
 	for (uint i = 0; i < _tiles.size(); i++) {
 		Tile &tile = _tiles[i];
 		if (tile.dirty) {
+			const Common::Rect rect(tile.rect.width(), tile.rect.height());
+
+			// TODO: Restore support for GL_UNPACK_ROW_LENGTH?
 			Graphics::Surface subSurface = _backingSurface.getSubArea(tile.rect);
+			Graphics::Surface *conv = subSurface.convertTo(OpenGL::Texture::getRGBAPixelFormat());
+
+			tile.texture->updateArea(rect, *conv);
 
-			delete tile.texture;
-			tile.texture = new TextureGL(subSurface);
+			conv->free();
+			delete conv;
 
 			tile.dirty = false;
 		}
diff --git a/backends/graphics3d/opengl/tiledsurface.h b/backends/graphics3d/opengl/tiledsurface.h
index 87788e456a8..f32717667cc 100644
--- a/backends/graphics3d/opengl/tiledsurface.h
+++ b/backends/graphics3d/opengl/tiledsurface.h
@@ -31,7 +31,7 @@
 
 namespace OpenGL {
 
-class TextureGL;
+class Texture;
 class SurfaceRenderer;
 
 /**
@@ -110,7 +110,7 @@ private:
 	static const uint maxTextureSize = 256;
 
 	struct Tile {
-		TextureGL *texture;
+		Texture *texture;
 		Common::Rect rect;
 		bool dirty;
 	};
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index eb3364c8f12..f530d599be1 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -26,7 +26,6 @@
 #include "backends/graphics3d/openglsdl/openglsdl-graphics3d.h"
 #include "backends/graphics3d/opengl/surfacerenderer.h"
 #include "backends/graphics3d/opengl/tiledsurface.h"
-#include "backends/graphics3d/opengl/texture.h"
 #include "backends/graphics3d/opengl/framebuffer.h"
 #include "backends/events/sdl/sdl-events.h"
 
@@ -39,6 +38,7 @@
 #include "graphics/blit.h"
 #include "graphics/opengl/context.h"
 #include "graphics/opengl/system_headers.h"
+#include "graphics/opengl/texture.h"
 
 #ifdef USE_PNG
 #include "image/png.h"
@@ -394,7 +394,7 @@ void OpenGLSdlGraphics3dManager::createOrUpdateScreen() {
 #endif
 
 	_surfaceRenderer = OpenGL::createBestSurfaceRenderer();
-	_overlayFormat = OpenGL::TextureGL::getRGBAPixelFormat();
+	_overlayFormat = OpenGL::Texture::getRGBAPixelFormat();
 
 	if (renderToFrameBuffer) {
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index d71df8b39ac..c022cb8dc86 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -33,7 +33,6 @@
 namespace OpenGL {
 	class FrameBuffer;
 	class SurfaceRenderer;
-	class TextureGL;
 	class TiledSurface;
 }
 
diff --git a/backends/module.mk b/backends/module.mk
index 8f0a51138f4..d1acc3d8d54 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -210,7 +210,6 @@ MODULE_OBJS += \
 	graphics/openglsdl/openglsdl-graphics.o \
 	graphics3d/opengl/framebuffer.o \
 	graphics3d/opengl/surfacerenderer.o \
-	graphics3d/opengl/texture.o \
 	graphics3d/opengl/tiledsurface.o \
 	graphics3d/openglsdl/openglsdl-graphics3d.o
 endif
@@ -308,7 +307,6 @@ MODULE_OBJS += \
 	graphics3d/android/texture.o \
 	graphics3d/opengl/framebuffer.o \
 	graphics3d/opengl/surfacerenderer.o \
-	graphics3d/opengl/texture.o \
 	graphics3d/opengl/tiledsurface.o \
 	mutex/pthread/pthread-mutex.o
 endif
@@ -396,7 +394,6 @@ MODULE_OBJS += \
 	graphics3d/ios/ios-graphics3d.o \
 	graphics3d/opengl/framebuffer.o \
 	graphics3d/opengl/surfacerenderer.o \
-	graphics3d/opengl/texture.o \
 	graphics3d/opengl/tiledsurface.o
 endif
 
diff --git a/graphics/opengl/texture.cpp b/graphics/opengl/texture.cpp
index d6f28243c7e..2ce9cde9cdb 100644
--- a/graphics/opengl/texture.cpp
+++ b/graphics/opengl/texture.cpp
@@ -215,6 +215,14 @@ void Texture::updateArea(const Common::Rect &area, const Graphics::Surface &src)
 	                       _glFormat, _glType, src.getBasePtr(0, area.top)));
 }
 
+const Graphics::PixelFormat Texture::getRGBAPixelFormat() {
+#ifdef SCUMM_BIG_ENDIAN
+	return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
+#else
+	return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
+#endif
+}
+
 } // End of namespace OpenGL
 
 #endif
diff --git a/graphics/opengl/texture.h b/graphics/opengl/texture.h
index d012d4679ea..2fb4d2d43f0 100644
--- a/graphics/opengl/texture.h
+++ b/graphics/opengl/texture.h
@@ -144,6 +144,8 @@ public:
 	 * destroy will invalidate the texture name.
 	 */
 	GLuint getGLTexture() const { return _glTexture; }
+
+	static const Graphics::PixelFormat getRGBAPixelFormat();
 private:
 	const GLenum _glIntFormat;
 	const GLenum _glFormat;




More information about the Scummvm-git-logs mailing list