[Scummvm-git-logs] scummvm master -> 66c0c57d10222ad58d3e726f66bd4f209b5d5b2b

ccawley2011 ccawley2011 at gmail.com
Wed Jun 16 22:16:04 UTC 2021


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:
66c0c57d10 BACKENDS: Add support for OpenGL 1.1 contexts


Commit: 66c0c57d10222ad58d3e726f66bd4f209b5d5b2b
    https://github.com/scummvm/scummvm/commit/66c0c57d10222ad58d3e726f66bd4f209b5d5b2b
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-06-16T23:16:01+01:00

Commit Message:
BACKENDS: Add support for OpenGL 1.1 contexts

Changed paths:
    backends/graphics/opengl/context.cpp
    backends/graphics/opengl/opengl-defs.h
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/opengl-sys.h
    backends/graphics/opengl/texture.cpp
    backends/graphics/opengl/texture.h


diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp
index 564007bd2c..adedb5442c 100644
--- a/backends/graphics/opengl/context.cpp
+++ b/backends/graphics/opengl/context.cpp
@@ -34,10 +34,15 @@ namespace OpenGL {
 void Context::reset() {
 	maxTextureSize = 0;
 
+	majorVersion = 0;
+	minorVersion = 0;
+
 	NPOTSupported = false;
 	shadersSupported = false;
 	multitextureSupported = false;
 	framebufferObjectSupported = false;
+	packedPixelsSupported = false;
+	textureEdgeClampSupported = false;
 
 #define GL_FUNC_DEF(ret, name, param) name = nullptr;
 #include "backends/graphics/opengl/opengl-func.h"
@@ -112,6 +117,21 @@ void OpenGLGraphicsManager::initializeGLContext() {
 	GL_CALL(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &g_context.maxTextureSize));
 	debug(5, "OpenGL maximum texture size: %d", g_context.maxTextureSize);
 
+	const char *verString = (const char *)g_context.glGetString(GL_VERSION);
+	debug(5, "OpenGL version: %s", verString);
+
+	const char *glVersionFormat;
+	if (g_context.type == kContextGL) {
+		glVersionFormat = "%d.%d";
+	} else {
+		glVersionFormat = "OpenGL ES %d.%d";
+	}
+
+	if (sscanf(verString, glVersionFormat, &g_context.majorVersion, &g_context.minorVersion) != 2) {
+		g_context.majorVersion = g_context.minorVersion = 0;
+		warning("Could not parse GL version '%s'", verString);
+	}
+
 	const char *extString = (const char *)g_context.glGetString(GL_EXTENSIONS);
 	debug(5, "OpenGL extensions: %s", extString);
 
@@ -138,6 +158,10 @@ void OpenGLGraphicsManager::initializeGLContext() {
 			g_context.multitextureSupported = true;
 		} else if (token == "GL_EXT_framebuffer_object") {
 			g_context.framebufferObjectSupported = true;
+		} else if (token == "GL_EXT_packed_pixels" || token == "GL_APPLE_packed_pixels") {
+			g_context.packedPixelsSupported = true;
+		} else if (token == "GL_SGIS_texture_edge_clamp") {
+			g_context.textureEdgeClampSupported = true;
 		}
 	}
 
@@ -157,6 +181,12 @@ void OpenGLGraphicsManager::initializeGLContext() {
 		g_context.shadersSupported = ARBShaderObjects & ARBShadingLanguage100 & ARBVertexShader & ARBFragmentShader;
 	}
 
+	// OpenGL 1.2 and later always has packed pixels and texture edge clamp support
+	if (g_context.type != kContextGL || g_context.isGLVersionOrHigher(1, 2)) {
+		g_context.packedPixelsSupported = true;
+		g_context.textureEdgeClampSupported = true;
+	}
+
 	// Log context type.
 	switch (g_context.type) {
 	case kContextGL:
@@ -181,6 +211,8 @@ void OpenGLGraphicsManager::initializeGLContext() {
 	debug(5, "OpenGL: Shader support: %d", g_context.shadersSupported);
 	debug(5, "OpenGL: Multitexture support: %d", g_context.multitextureSupported);
 	debug(5, "OpenGL: FBO support: %d", g_context.framebufferObjectSupported);
+	debug(5, "OpenGL: Packed pixels support: %d", g_context.packedPixelsSupported);
+	debug(5, "OpenGL: Texture edge clamping support: %d", g_context.textureEdgeClampSupported);
 }
 
 } // End of namespace OpenGL
diff --git a/backends/graphics/opengl/opengl-defs.h b/backends/graphics/opengl/opengl-defs.h
index 733fc2933c..0bf83fed1e 100644
--- a/backends/graphics/opengl/opengl-defs.h
+++ b/backends/graphics/opengl/opengl-defs.h
@@ -224,6 +224,7 @@ typedef GLhandleARB GLshader;
 #define GL_TEXTURE_WRAP_T                 0x2803
 
 /* TextureWrapMode */
+#define GL_CLAMP                          0x2900
 #define GL_REPEAT                         0x2901
 #define GL_CLAMP_TO_EDGE                  0x812F
 
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index f522259cb5..e02e35d618 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -1108,27 +1108,26 @@ Surface *OpenGLGraphicsManager::createSurface(const Graphics::PixelFormat &forma
 		} else {
 			return new TextureCLUT8(glIntFormat, glFormat, glType, virtFormat);
 		}
-#if !USE_FORCED_GL
-	} else if (isGLESContext() && format == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) {
+	} else if (getGLPixelFormat(format, glIntFormat, glFormat, glType)) {
+		return new Texture(glIntFormat, glFormat, glType, format);
+	} else if (g_context.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();
 #ifdef SCUMM_LITTLE_ENDIAN
-	} else if (isGLESContext() && format == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
+	} else if (format == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
 #else
-	} else if (isGLESContext() && format == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
+	} else if (format == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
 #endif
 		return new TextureRGBA8888Swap();
-#endif // !USE_FORCED_GL
 	} else {
-		const bool supported = getGLPixelFormat(format, glIntFormat, glFormat, glType);
-		if (!supported) {
-			return nullptr;
-		} else {
-			return new Texture(glIntFormat, glFormat, glType, format);
-		}
+#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);
+#else
+		return new FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), format);
+#endif
 	}
 }
 
@@ -1142,6 +1141,8 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF
 		glFormat = GL_RGBA;
 		glType = GL_UNSIGNED_BYTE;
 		return true;
+	} else if (!g_context.packedPixelsSupported) {
+		return false;
 	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)) { // RGB565
 		glIntFormat = GL_RGB;
 		glFormat = GL_RGB;
diff --git a/backends/graphics/opengl/opengl-sys.h b/backends/graphics/opengl/opengl-sys.h
index 5e754bb328..dc6f66ac71 100644
--- a/backends/graphics/opengl/opengl-sys.h
+++ b/backends/graphics/opengl/opengl-sys.h
@@ -103,6 +103,14 @@ struct Context {
 	 */
 	void reset();
 
+	/** Helper function for checking the GL version supported by the context. */
+	inline bool isGLVersionOrHigher(int major, int minor) {
+		return ((majorVersion > major) || ((majorVersion == major) && (minorVersion >= minor)));
+	}
+
+	/** The GL version supported by the context. */
+	int majorVersion, minorVersion;
+
 	/** The maximum texture size supported by the context. */
 	GLint maxTextureSize;
 
@@ -118,6 +126,12 @@ struct Context {
 	/** Whether FBO support is available or not. */
 	bool framebufferObjectSupported;
 
+	/** Whether packed pixels support is available or not. */
+	bool packedPixelsSupported;
+
+	/** Whether texture coordinate edge clamping is available or not. */
+	bool textureEdgeClampSupported;
+
 #define GL_FUNC_DEF(ret, name, param) ret (GL_CALL_CONV *name)param
 #include "backends/graphics/opengl/opengl-func.h"
 #undef GL_FUNC_DEF
diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp
index 5001aab82b..7f08b81110 100644
--- a/backends/graphics/opengl/texture.cpp
+++ b/backends/graphics/opengl/texture.cpp
@@ -31,6 +31,8 @@
 #include "common/rect.h"
 #include "common/textconsole.h"
 
+#include "graphics/conversion.h"
+
 namespace OpenGL {
 
 GLTexture::GLTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType)
@@ -75,8 +77,13 @@ void GLTexture::create() {
 	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));
-	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));
+	if (g_context.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 {
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
+		GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
+	}
 
 	// If a size is specified, allocate memory for it.
 	if (_width != 0 && _height != 0) {
@@ -419,9 +426,9 @@ void TextureCLUT8::updateGLTexture() {
 	Texture::updateGLTexture();
 }
 
-#if !USE_FORCED_GL
-FakeTexture::FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format)
+FakeTexture::FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat)
 	: Texture(glIntFormat, glFormat, glType, format),
+	  _fakeFormat(fakeFormat),
 	  _rgbData() {
 }
 
@@ -442,12 +449,26 @@ void FakeTexture::allocate(uint width, uint height) {
 	_rgbData.create(width, height, getFormat());
 }
 
-TextureRGB555::TextureRGB555()
-	: FakeTexture(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)) {
+void FakeTexture::updateGLTexture() {
+	if (!isDirty()) {
+		return;
+	}
+
+	// Convert color space.
+	Graphics::Surface *outSurf = Texture::getSurface();
+
+	const Common::Rect dirtyArea = getDirtyArea();
+
+	byte *dst = (byte *)outSurf->getBasePtr(dirtyArea.left, dirtyArea.top);
+	const byte *src = (const byte *)_rgbData.getBasePtr(dirtyArea.left, dirtyArea.top);
+	Graphics::crossBlit(dst, src, outSurf->pitch, _rgbData.pitch, dirtyArea.width(), dirtyArea.height(), outSurf->format, _rgbData.format);
+
+	// Do generic handling of updating the texture.
+	Texture::updateGLTexture();
 }
 
-Graphics::PixelFormat TextureRGB555::getFormat() const {
-	return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
+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)) {
 }
 
 void TextureRGB555::updateGLTexture() {
@@ -485,21 +506,13 @@ void TextureRGB555::updateGLTexture() {
 
 TextureRGBA8888Swap::TextureRGBA8888Swap()
 #ifdef SCUMM_LITTLE_ENDIAN
-	: FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) // ABGR8888
+	: 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
 #else
-	: FakeTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) // RGBA8888
+	: 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
 #endif
 	  {
 }
 
-Graphics::PixelFormat TextureRGBA8888Swap::getFormat() const {
-#ifdef SCUMM_LITTLE_ENDIAN
-	return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); // RGBA8888
-#else
-	return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); // ABGR8888
-#endif
-}
-
 void TextureRGBA8888Swap::updateGLTexture() {
 	if (!isDirty()) {
 		return;
@@ -530,7 +543,6 @@ void TextureRGBA8888Swap::updateGLTexture() {
 	// Do generic handling of updating the texture.
 	Texture::updateGLTexture();
 }
-#endif // !USE_FORCED_GL
 
 #if !USE_FORCED_GLES
 
diff --git a/backends/graphics/opengl/texture.h b/backends/graphics/opengl/texture.h
index 81adc384b9..aed42405f4 100644
--- a/backends/graphics/opengl/texture.h
+++ b/backends/graphics/opengl/texture.h
@@ -318,20 +318,22 @@ private:
 	byte *_palette;
 };
 
-#if !USE_FORCED_GL
 class FakeTexture : public Texture {
 public:
-	FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format);
+	FakeTexture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graphics::PixelFormat &format, const Graphics::PixelFormat &fakeFormat);
 	virtual ~FakeTexture();
 
 	virtual void allocate(uint width, uint height);
 
-	virtual Graphics::PixelFormat getFormat() const = 0;
+	virtual Graphics::PixelFormat getFormat() const { return _fakeFormat; }
 
 	virtual Graphics::Surface *getSurface() { return &_rgbData; }
 	virtual const Graphics::Surface *getSurface() const { return &_rgbData; }
+
+	virtual void updateGLTexture();
 protected:
 	Graphics::Surface _rgbData;
+	Graphics::PixelFormat _fakeFormat;
 };
 
 class TextureRGB555 : public FakeTexture {
@@ -339,8 +341,6 @@ public:
 	TextureRGB555();
 	virtual ~TextureRGB555() {};
 
-	virtual Graphics::PixelFormat getFormat() const;
-
 	virtual void updateGLTexture();
 };
 
@@ -349,11 +349,8 @@ public:
 	TextureRGBA8888Swap();
 	virtual ~TextureRGBA8888Swap() {};
 
-	virtual Graphics::PixelFormat getFormat() const;
-
 	virtual void updateGLTexture();
 };
-#endif // !USE_FORCED_GL
 
 #if !USE_FORCED_GLES
 class TextureTarget;




More information about the Scummvm-git-logs mailing list