[Scummvm-cvs-logs] SF.net SVN: scummvm:[51559] scummvm/branches/gsoc2010-opengl/backends

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Sun Aug 1 00:54:10 CEST 2010


Revision: 51559
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51559&view=rev
Author:   vgvgf
Date:     2010-07-31 22:54:10 +0000 (Sat, 31 Jul 2010)

Log Message:
-----------
OPENGL: Add support for BGR and rgb(a) reversed formats (Not available for GLES). General cleanup and commenting.

Modified Paths:
--------------
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
    scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h
    scummvm/branches/gsoc2010-opengl/backends/platform/sdl/sdl.cpp

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-31 22:54:10 UTC (rev 51559)
@@ -56,7 +56,7 @@
 void GLTexture::initGLExtensions() {
 	static bool inited = false;
 
-	// Return if extensions already checked
+	// Return if extensions were already checked
 	if (inited)
 		return;
 
@@ -75,9 +75,10 @@
 	inited = true;
 }
 
-GLTexture::GLTexture(byte bpp, GLenum format, GLenum type)
+GLTexture::GLTexture(byte bpp, GLenum internalFormat, GLenum format, GLenum type)
 	:
 	_bytesPerPixel(bpp),
+	_internalFormat(internalFormat),
 	_glFormat(format),
 	_glType(type),
 	_textureWidth(0),
@@ -131,7 +132,7 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
 
 	// Allocate room for the texture
-	glTexImage2D(GL_TEXTURE_2D, 0, _glFormat,
+	glTexImage2D(GL_TEXTURE_2D, 0, _internalFormat,
 		_textureWidth, _textureHeight, 0, _glFormat, _glType, NULL); CHECK_GL_ERROR();
 
 	_refresh = false;

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-31 22:54:10 UTC (rev 51559)
@@ -58,7 +58,7 @@
 	 */
 	static void initGLExtensions();
 
-	GLTexture(byte bpp, GLenum format, GLenum type);
+	GLTexture(byte bpp, GLenum internalFormat, GLenum format, GLenum type);
 	virtual ~GLTexture();
 
 	/**
@@ -95,12 +95,13 @@
 
 	/**
 	 * Set the texture filter.
-	 * GL_NEAREST or GL_LINEAR should be passed.
+	 * @filter the filter type, GL_NEAREST or GL_LINEAR
 	 */
 	void setFilter(GLint filter) { _filter = filter; }
 
 protected:
 	const byte _bytesPerPixel;
+	const GLenum _internalFormat;
 	const GLenum _glFormat;
 	const GLenum _glType;
 

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-31 22:54:10 UTC (rev 51559)
@@ -188,7 +188,6 @@
 	assert(_transactionMode == kTransactionActive);
 
 #ifdef USE_RGB_COLOR
-	// Avoid redundant format changes
 	Graphics::PixelFormat newFormat;
 	if (!format)
 		newFormat = Graphics::PixelFormat::createFormatCLUT8();
@@ -197,6 +196,7 @@
 
 	assert(newFormat.bytesPerPixel > 0);
 
+	// Avoid redundant format changes
 	if (newFormat != _videoMode.format) {
 		_videoMode.format = newFormat;
 		_transactionDetails.formatChanged = true;
@@ -283,11 +283,7 @@
 		}
 	}
 
-#ifdef USE_RGB_COLOR
-	if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged || _transactionDetails.needHotswap) {
-#else
 	if (_transactionDetails.sizeChanged || _transactionDetails.needHotswap) {
-#endif
 		unloadGFXMode();
 		if (!loadGFXMode()) {
 			if (_oldVideoMode.setup) {
@@ -300,7 +296,11 @@
 			_videoMode.setup = true;
 			_screenChangeCount++;
 		}
+#ifdef USE_RGB_COLOR
+	} else if (_transactionDetails.filterChanged || _transactionDetails.formatChanged) {
+#else
 	} else if (_transactionDetails.filterChanged) {
+#endif
 		loadTextures();
 		internUpdateScreen();
 	} else if (_transactionDetails.needUpdatescreen) {
@@ -462,6 +462,7 @@
 }
 
 void OpenGLGraphicsManager::clearOverlay() {
+	// Set all pixels to 0
 	memset(_overlayData.pixels, 0, _overlayData.h * _overlayData.pitch);
 	_overlayNeedsRedraw = true;
 }
@@ -470,6 +471,7 @@
 	assert(_overlayData.bytesPerPixel == sizeof(buf[0]));
 	const byte *src = (byte *)_overlayData.pixels;
 	for (int i = 0; i < _overlayData.h; i++) {
+		// Copy overlay data to buffer
 		memcpy(buf, src, _overlayData.pitch);
 		buf += pitch;
 		src += _overlayData.pitch;
@@ -565,12 +567,13 @@
 
 void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
 #ifdef USE_RGB_COLOR
-	if (!format)
+	if (format)
+		_cursorFormat = *format;
+	else
 		_cursorFormat = Graphics::PixelFormat::createFormatCLUT8();
-	else
-		_cursorFormat = *format;
 #else
 	assert(keycolor <= 255);
+	_cursorFormat = Graphics::PixelFormat::createFormatCLUT8();
 #endif
 
 	// Allocate space for cursor data
@@ -845,42 +848,97 @@
 	float aspectRatio = (float)_videoMode.hardwareWidth / _videoMode.hardwareHeight;
 	float desiredAspectRatio = getAspectRatio();
 
+	// Adjust one screen dimension for mantaining the aspect ratio
 	if (aspectRatio < desiredAspectRatio)
 		_aspectHeight = (int)(_aspectWidth / desiredAspectRatio + 0.5f);
 	else if (aspectRatio > desiredAspectRatio)
 		_aspectWidth = (int)(_aspectHeight * desiredAspectRatio + 0.5f);
 
+	// Adjust x and y for centering the screen
 	_aspectX = (_videoMode.hardwareWidth - _aspectWidth) / 2;
 	_aspectY = (_videoMode.hardwareHeight - _aspectHeight) / 2;
 }
 
-void OpenGLGraphicsManager::getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &glFormat, GLenum &gltype) {
+void OpenGLGraphicsManager::getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &intFormat, GLenum &glFormat, GLenum &gltype) {
 	if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
 		bpp = 4;
+		intFormat = GL_RGBA;
 		glFormat = GL_RGBA;
 		gltype = GL_UNSIGNED_BYTE;
 	} else if (pixelFormat == Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0)) { // RGB888
 		bpp = 3;
+		intFormat = GL_RGB;
 		glFormat = GL_RGB;
 		gltype = GL_UNSIGNED_BYTE;
 	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)) { // RGB565
 		bpp = 2;
+		intFormat = GL_RGB;
 		glFormat = GL_RGB;
 		gltype = GL_UNSIGNED_SHORT_5_6_5;
 	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)) { // RGB5551
 		bpp = 2;
+		intFormat = GL_RGBA;
 		glFormat = GL_RGBA;
 		gltype = GL_UNSIGNED_SHORT_5_5_5_1;
 	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0)) { // RGBA4444
 		bpp = 2;
+		intFormat = GL_RGBA;
 		glFormat = GL_RGBA;
 		gltype = GL_UNSIGNED_SHORT_4_4_4_4;
 	} else if (pixelFormat.bytesPerPixel == 1) { // CLUT8
 		// If uses a palette, create texture as RGB888. The pixel data will be converted
 		// later.
 		bpp = 3;
+		intFormat = GL_RGB;
 		glFormat = GL_RGB;
 		gltype = GL_UNSIGNED_BYTE;
+#ifndef USE_GLES
+	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24)) { // ARGB8888
+		bpp = 4;
+		intFormat = GL_RGBA;
+		glFormat = GL_BGRA;
+		gltype = GL_UNSIGNED_INT_8_8_8_8_REV;
+	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)) { // ARGB4444
+		bpp = 2;
+		intFormat = GL_RGBA;
+		glFormat = GL_BGRA;
+		gltype = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
+		bpp = 4;
+		intFormat = GL_RGBA;
+		glFormat = GL_RGBA;
+		gltype = GL_UNSIGNED_INT_8_8_8_8_REV;
+	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0)) { // BGRA8888
+		bpp = 4;
+		intFormat = GL_RGBA;
+		glFormat = GL_BGRA;
+		gltype = GL_UNSIGNED_BYTE;
+	} else if (pixelFormat == Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0)) { // BGR888
+		bpp = 3;
+		intFormat = GL_RGB;
+		glFormat = GL_BGR;
+		gltype = GL_UNSIGNED_BYTE;
+	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0)) { // BGR565
+		bpp = 2;
+		intFormat = GL_RGB;
+		glFormat = GL_BGR;
+		gltype = GL_UNSIGNED_SHORT_5_6_5;
+	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 1, 6, 11, 0)) { // BGRA5551
+		bpp = 2;
+		intFormat = GL_RGBA;
+		glFormat = GL_BGRA;
+		gltype = GL_UNSIGNED_SHORT_5_5_5_1;
+	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12)) { // ABGR4444
+		bpp = 2;
+		intFormat = GL_RGBA;
+		glFormat = GL_RGBA;
+		gltype = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)) { // BGRA4444
+		bpp = 2;
+		intFormat = GL_RGBA;
+		glFormat = GL_BGRA;
+		gltype = GL_UNSIGNED_SHORT_4_4_4_4;
+#endif
 	} else {
 		error("OpenGLGraphicsManager: Pixel format not supported");
 	}
@@ -898,6 +956,7 @@
 
 	glPushMatrix();
 
+	// Adjust game screen shake position
 	glTranslatef(0, _shakePos * scaleFactor, 0); CHECK_GL_ERROR();
 
 	// Draw the game screen
@@ -920,6 +979,8 @@
 			refreshCursor();
 
 		glPushMatrix();
+
+		// Adjust mouse shake position, unless the overlay is visible
 		glTranslatef(0, _overlayVisible ? 0 : _shakePos * scaleFactor, 0); CHECK_GL_ERROR();
 
 		// Draw the cursor
@@ -1004,28 +1065,30 @@
 
 	if (!_gameTexture) {
 		byte bpp;
+		GLenum intformat;
 		GLenum format;
 		GLenum type;
 #ifdef USE_RGB_COLOR
-		getGLPixelFormat(_screenFormat, bpp, format, type);
+		getGLPixelFormat(_screenFormat, bpp, intformat, format, type);
 #else
-		getGLPixelFormat(Graphics::PixelFormat::createFormatCLUT8(), bpp, format, type);
+		getGLPixelFormat(Graphics::PixelFormat::createFormatCLUT8(), bpp, intformat, format, type);
 #endif
-		_gameTexture = new GLTexture(bpp, format, type);
+		_gameTexture = new GLTexture(bpp, intformat, format, type);
 	} 
 
 	_overlayFormat = Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0);
 
 	if (!_overlayTexture) {
 		byte bpp;
+		GLenum intformat;
 		GLenum format;
 		GLenum type;
-		getGLPixelFormat(_overlayFormat, bpp, format, type);
-		_overlayTexture = new GLTexture(bpp, format, type);
+		getGLPixelFormat(_overlayFormat, bpp, intformat, format, type);
+		_overlayTexture = new GLTexture(bpp, intformat, format, type);
 	}
 
 	if (!_cursorTexture)
-		_cursorTexture = new GLTexture(4, GL_RGBA, GL_UNSIGNED_BYTE);
+		_cursorTexture = new GLTexture(4, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
 		
 	GLint filter = _videoMode.antialiasing ? GL_LINEAR : GL_NEAREST;
 	_gameTexture->setFilter(filter);
@@ -1062,7 +1125,7 @@
 
 #ifdef USE_OSD
 	if (!_osdTexture)
-		_osdTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
+		_osdTexture = new GLTexture(2, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
 
 	if (_transactionDetails.newContext || _transactionDetails.filterChanged)
 		_osdTexture->refresh();
@@ -1115,6 +1178,7 @@
 
 	if (_transactionMode == kTransactionActive) {
 		if (ratio == -1)
+			// If -1, switch to next mode
 			_videoMode.aspectRatioCorrection = (_videoMode.aspectRatioCorrection + 1) % 5;
 		else
 			_videoMode.aspectRatioCorrection = ratio;
@@ -1220,7 +1284,7 @@
 	// Allocate space for screenshot
 	uint8 *pixels = new uint8[width * height * 3];
 
-	// Get pixel data from opengl buffer
+	// Get pixel data from OpenGL buffer
 #ifdef USE_GLES
 	glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); CHECK_GL_ERROR();
 #else

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-31 22:54:10 UTC (rev 51559)
@@ -34,7 +34,8 @@
 #define USE_OSD	1
 
 namespace OpenGL {
-
+// The OpenGL GFX modes. They have to be inside the OpenGL namespace so they
+// do not clash with the SDL GFX modes.
 enum {
 	GFX_NORMAL = 0,
 	GFX_DOUBLESIZE = 1,
@@ -44,7 +45,11 @@
 }
 
 /**
- * Open GL graphics manager
+ * Open GL graphics manager. This is an abstract class, it does not do the
+ * window and OpenGL context initialization.
+ * Derived classes should at least override internUpdateScreen for doing
+ * the buffers swap, and implement loadGFXMode for handling the window/context if
+ * needed. If USE_RGB_COLOR is enabled, getSupportedFormats must be implemented.
  */
 class OpenGLGraphicsManager : public GraphicsManager, public Common::EventObserver {
 public:
@@ -105,8 +110,14 @@
 	bool notifyEvent(const Common::Event &event);
 
 protected:
+	/**
+	 * Setup OpenGL settings
+	 */
+	virtual void initGL();
 
-	virtual void initGL();
+	/**
+	 * Creates and refreshs OpenGL textures.
+	 */
 	virtual void loadTextures();
 
 	//
@@ -159,7 +170,10 @@
 	};
 	VideoState _videoMode, _oldVideoMode;
 
-	virtual void getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &glFormat, GLenum &type);
+	/**
+	 * Sets the OpenGL texture format for the given pixel format. If format is not support will raise an error.
+	 */
+	virtual void getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &intFormat, GLenum &glFormat, GLenum &type);
 
 	virtual void internUpdateScreen();
 	virtual bool loadGFXMode();
@@ -167,12 +181,18 @@
 
 	virtual void setScale(int newScale);
 
+	// Drawing coordinates for the current aspect ratio
 	int _aspectX;
 	int _aspectY;
 	int _aspectWidth;
 	int _aspectHeight;
 
+	/**
+	 * Sets the aspect ratio mode.
+	 * @mode the aspect ratio mode, if -1 it will switch to next mode.
+	 */
 	virtual void setAspectRatioCorrection(int mode);
+
 	virtual void refreshAspectRatio();
 	virtual Common::String getAspectRatioName();
 	virtual float getAspectRatio();
@@ -222,13 +242,11 @@
 		int16 w, h;
 		int16 hotX, hotY;
 
-		// The size and hotspot of the scaled cursor, in real
-		// coordinates.
+		// The size and hotspot of the scaled cursor, in real coordinates.
 		int16 rW, rH;
 		int16 rHotX, rHotY;
 
-		// The size and hotspot of the scaled cursor, in game
-		// coordinates.
+		// The size and hotspot of the scaled cursor, in game coordinates.
 		int16 vW, vH;
 		int16 vHotX, vHotY;
 
@@ -239,9 +257,7 @@
 
 	GLTexture* _cursorTexture;
 	Graphics::Surface _cursorData;
-#ifdef USE_RGB_COLOR
 	Graphics::PixelFormat _cursorFormat;
-#endif
 	byte *_cursorPalette;
 	bool _cursorPaletteDisabled;
 	MousePos _cursorState;

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-31 22:54:10 UTC (rev 51559)
@@ -33,10 +33,12 @@
 	_hwscreen(0),
 	_screenResized(false) {
 
+	// Initialize SDL video subsystem
 	if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) {
 		error("Could not initialize SDL: %s", SDL_GetError());
 	}
 
+	// Disable OS cursor
 	SDL_ShowCursor(SDL_DISABLE);
 }
 
@@ -68,25 +70,54 @@
 
 #ifdef USE_RGB_COLOR
 
-const Graphics::PixelFormat RGBList[] = {
-#if defined(ENABLE_32BIT)
-	Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0),	// RGBA8888
-	Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),	// RGB888
-#endif
-	Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),	// RGB565
-	Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0),	// RGB555
-	Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),	// RGBA4444
-};
-
 Common::List<Graphics::PixelFormat> OpenGLSdlGraphicsManager::getSupportedFormats() const {
-	static Common::List<Graphics::PixelFormat> list;
-	static bool inited = false;
+	assert(!_supportedFormats.empty());
+	return _supportedFormats;
+}
 
-	if (inited)
-		return list;
+void OpenGLSdlGraphicsManager::detectSupportedFormats() {
 
-	int listLength = ARRAYSIZE(RGBList);
+	// Clear old list
+	_supportedFormats.clear();
 
+	// Some tables with standard formats that we always list
+	// as "supported". If frontend code tries to use one of
+	// these, we will perform the necessary format
+	// conversion in the background. Of course this incurs a
+	// performance hit, but on desktop ports this should not
+	// matter. We still push the currently active format to
+	// the front, so if frontend code just uses the first
+	// available format, it will get one that is "cheap" to
+	// use.
+	const Graphics::PixelFormat RGBList[] = {
+#if defined(ENABLE_32BIT)
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0),	// RGBA8888
+#ifndef USE_GLES
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24), // ARGB8888
+#endif
+		Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),	// RGB888
+#endif
+		Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),	// RGB565
+		Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0),	// RGB5551
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),	// RGBA4444
+#ifndef USE_GLES
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)   // ARGB4444
+#endif
+	};
+#ifndef USE_GLES
+	const Graphics::PixelFormat BGRList[] = {
+#ifdef ENABLE_32BIT
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), // ABGR8888
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0), // BGRA8888
+		Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),  // BGR888
+#endif
+		Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0),  // BGR565
+		Graphics::PixelFormat(2, 5, 5, 5, 1, 1, 6, 11, 0),  // BGRA5551
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12),  // ABGR4444
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)   // BGRA4444
+	};
+#endif
+
 	Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
 	if (_hwscreen) {
 		// Get our currently set hardware format
@@ -100,26 +131,40 @@
 		if (_hwscreen->format->Amask == 0)
 			format.aLoss = 8;
 
-		// Push it first, as the prefered format.
-		for (int i = 0; i < listLength; i++) {
+		// Push it first, as the prefered format if available
+		for (int i = 0; i < ARRAYSIZE(RGBList); i++) {
 			if (RGBList[i] == format) {
-				list.push_back(format);
+				_supportedFormats.push_back(format);
 				break;
 			}
 		}
-
-		// Mark that we don't need to do this any more.
-		inited = true;
+#ifndef USE_GLES
+		for (int i = 0; i < ARRAYSIZE(BGRList); i++) {
+			if (BGRList[i] == format) {
+				_supportedFormats.push_back(format);
+				break;
+			}
+		}
+#endif
 	}
 
-	for (int i = 0; i < listLength; i++) {
-		if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
+	// Push some RGB formats
+	for (int i = 0; i < ARRAYSIZE(RGBList); i++) {
+		if (_hwscreen && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
 			continue;
 		if (RGBList[i] != format)
-			list.push_back(RGBList[i]);
+			_supportedFormats.push_back(RGBList[i]);
 	}
-	list.push_back(Graphics::PixelFormat::createFormatCLUT8());
-	return list;
+
+	// Push some BGR formats
+	for (int i = 0; i < ARRAYSIZE(BGRList); i++) {
+		if (_hwscreen && (BGRList[i].bytesPerPixel > format.bytesPerPixel))
+			continue;
+		if (BGRList[i] != format)
+			_supportedFormats.push_back(BGRList[i]);
+	}
+
+	_supportedFormats.push_back(Graphics::PixelFormat::createFormatCLUT8());
 }
 
 #endif
@@ -227,6 +272,10 @@
 	_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
 		_videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : (SDL_OPENGL | SDL_RESIZABLE)
 	);
+#ifdef USE_RGB_COLOR
+	detectSupportedFormats();
+#endif
+
 	if (_hwscreen == NULL) {
 		// DON'T use error(), as this tries to bring up the debug
 		// console, which WON'T WORK now that _hwscreen is hosed.

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h	2010-07-31 22:54:10 UTC (rev 51559)
@@ -63,6 +63,21 @@
 
 	virtual bool handleScalerHotkeys(Common::KeyCode key);
 	virtual bool isScalerHotkey(const Common::Event &event);
+
+#ifdef USE_RGB_COLOR
+	Common::List<Graphics::PixelFormat> _supportedFormats;
+
+	/**
+	 * Update the list of supported pixel formats.
+	 * This method is invoked by loadGFXMode().
+	 */
+	void detectSupportedFormats();
+#endif
+
+	/**
+	 * Toggles fullscreen.
+	 * @loop if true loop to next supported fullscreen mode
+	 */
 	virtual void toggleFullScreen(bool loop);
 
 	// Hardware screen

Modified: scummvm/branches/gsoc2010-opengl/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/platform/sdl/sdl.cpp	2010-07-31 22:48:49 UTC (rev 51558)
+++ scummvm/branches/gsoc2010-opengl/backends/platform/sdl/sdl.cpp	2010-07-31 22:54:10 UTC (rev 51559)
@@ -313,6 +313,7 @@
 }
 
 int OSystem_SDL::getDefaultGraphicsMode() const {
+	// Return the default graphics mode from the current graphics manager
 	if (_graphicsMode < _sdlModesCount)
 		return _graphicsManager->getDefaultGraphicsMode();
 	else
@@ -322,6 +323,7 @@
 bool OSystem_SDL::setGraphicsMode(int mode) {
 	const OSystem::GraphicsMode *srcMode;
 	int i;
+	// Check if mode is from SDL or OpenGL
 	if (mode < _sdlModesCount) {
 		srcMode = SdlGraphicsManager::supportedGraphicsModes();
 		i = 0;
@@ -329,8 +331,11 @@
 		srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes();
 		i = _sdlModesCount;
 	}
+	// Loop through modes
 	while (srcMode->name) {
 		if (i == mode) {
+			// If the new mode and the current mode are not from the same graphics
+			// manager, delete and create the new mode graphics manager
 			if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) {
 				delete _graphicsManager;
 				_graphicsManager = new SdlGraphicsManager();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list