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

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Thu Jul 22 17:36:50 CEST 2010


Revision: 51146
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51146&view=rev
Author:   vgvgf
Date:     2010-07-22 15:36:50 +0000 (Thu, 22 Jul 2010)

Log Message:
-----------
OPENGL: Add antialiasing, hotkey: ctrl+alt+f. Fixed minor bugs.

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

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-22 14:43:19 UTC (rev 51145)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-22 15:36:50 UTC (rev 51146)
@@ -80,7 +80,8 @@
 	_textureHeight(0),
 	_realWidth(0),
 	_realHeight(0),
-	_refresh(false) {
+	_refresh(false),
+	_filter(GL_NEAREST) {
 
 	// Generates the texture ID for GL
 	glGenTextures(1, &_textureName); CHECK_GL_ERROR();
@@ -122,8 +123,8 @@
 	// Allocate room for the texture now, but pixel data gets uploaded
 	// later (perhaps with multiple TexSubImage2D operations).
 	glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); CHECK_GL_ERROR();
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _filter); CHECK_GL_ERROR();
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _filter); CHECK_GL_ERROR();
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
 	glTexImage2D(GL_TEXTURE_2D, 0, _glFormat,
@@ -131,6 +132,8 @@
 
 	if (_surface.w != _textureWidth || _surface.h != _textureHeight)
 		_surface.create(_textureWidth, _textureHeight, _bytesPerPixel);
+	else if (_refresh)
+		updateBuffer(_surface.pixels, _surface.pitch, 0, 0, _surface.w, _surface.h);
 
 	_refresh = false;
 }
@@ -141,13 +144,15 @@
 	if (static_cast<int>(w) * _bytesPerPixel == pitch) {
 		glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
 						_glFormat, _glType, buf); CHECK_GL_ERROR();
-		memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
+		if (buf != _surface.pixels)
+			memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
 	} else {
 		const byte* src = static_cast<const byte*>(buf);
 		do {
 			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
 							w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
-			memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
+			if (buf != _surface.pixels)
+				memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
 			++y;
 			src += pitch;
 		} while (--h);

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-22 14:43:19 UTC (rev 51145)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-22 15:36:50 UTC (rev 51146)
@@ -74,6 +74,8 @@
 	GLuint getHeight() const { return _realHeight; }
 	GLuint getTextureName() const { return _textureName; }
 
+	void setFilter(GLint filter) { _filter = filter; }
+
 protected:
 	const byte _bytesPerPixel;
 	const GLenum _glFormat;
@@ -86,4 +88,5 @@
 	GLuint _textureWidth;
 	GLuint _textureHeight;
 	bool _refresh;
+	GLint _filter;
 };

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-22 14:43:19 UTC (rev 51145)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-22 15:36:50 UTC (rev 51146)
@@ -48,6 +48,7 @@
 	_videoMode.mode = OpenGL::GFX_NORMAL;
 	_videoMode.scaleFactor = 1;
 	_videoMode.fullscreen = false;
+	_videoMode.antialiasing = false;
 
 	_gamePalette = (byte *)calloc(sizeof(byte) * 4, 256);
 	_cursorPalette = (byte *)calloc(sizeof(byte) * 4, 256);
@@ -112,11 +113,44 @@
 }
 
 bool OpenGLGraphicsManager::setGraphicsMode(int mode) {
+	assert(_transactionMode == kTransactionActive);
+
+	if (_oldVideoMode.setup && _oldVideoMode.mode == mode)
+		return true;
+
+	int newScaleFactor = 1;
+
+	switch (mode) {
+	case OpenGL::GFX_NORMAL:
+		newScaleFactor = 1;
+		break;
+#ifdef USE_SCALERS
+	case OpenGL::GFX_DOUBLESIZE:
+		newScaleFactor = 2;
+		break;
+	case OpenGL::GFX_TRIPLESIZE:
+		newScaleFactor = 3;
+		break;
+#endif
+	default:
+		warning("unknown gfx mode %d", mode);
+		return false;
+	}
+
+	if (_oldVideoMode.setup && _oldVideoMode.scaleFactor != newScaleFactor)
+		_transactionDetails.needHotswap = true;
+
+	_transactionDetails.needUpdatescreen = true;
+
+	_videoMode.mode = mode;
+	_videoMode.scaleFactor = newScaleFactor;
+
 	return true;
 }
 
 int OpenGLGraphicsManager::getGraphicsMode() const {
-	return OpenGL::GFX_NORMAL;
+	assert (_transactionMode == kTransactionNone);
+	return _videoMode.mode;
 }
 
 #ifdef USE_RGB_COLOR
@@ -131,7 +165,7 @@
 	assert(_transactionMode == kTransactionActive);
 
 #ifdef USE_RGB_COLOR
-	//avoid redundant format changes
+	// Avoid redundant format changes
 	Graphics::PixelFormat newFormat;
 	if (!format)
 		newFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0);
@@ -173,6 +207,8 @@
 	_transactionDetails.sizeChanged = false;
 	_transactionDetails.needHotswap = false;
 	_transactionDetails.needUpdatescreen = false;
+	_transactionDetails.newContext = false;
+	_transactionDetails.filterChanged = false;
 #ifdef USE_RGB_COLOR
 	_transactionDetails.formatChanged = false;
 #endif
@@ -237,14 +273,15 @@
 				errors |= endGFXTransaction();
 			}
 		} else {
-			//setGraphicsModeIntern();
-			//clearOverlay();
+			clearOverlay();
 
 			_videoMode.setup = true;
 			_screenChangeCount++;
 		}
+	} else if (_transactionDetails.filterChanged) {
+		loadTextures();
+		internUpdateScreen();
 	} else if (_transactionDetails.needUpdatescreen) {
-		//setGraphicsModeIntern();
 		internUpdateScreen();
 	}
 
@@ -579,35 +616,45 @@
 	glLoadIdentity(); CHECK_GL_ERROR();
 }
 
-bool OpenGLGraphicsManager::loadGFXMode() {
-	// Initialize OpenGL settings
-	initGL();
-
+void OpenGLGraphicsManager::loadTextures() {
 	if (!_gameTexture) {
 		byte bpp;
 		GLenum format;
 		GLenum type;
 		getGLPixelFormat(_screenFormat, bpp, format, type);
 		_gameTexture = new GLTexture(bpp, format, type);
-	} else if (_transactionDetails.newContext)
-		_gameTexture->refresh();
+	} 
 
 	_overlayFormat = Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
 
 	if (!_overlayTexture)
 		_overlayTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
-	else if (_transactionDetails.newContext)
-		_overlayTexture->refresh();
 
 	if (!_cursorTexture)
 		_cursorTexture = new GLTexture(4, GL_RGBA, GL_UNSIGNED_BYTE);
-	else if (_transactionDetails.newContext)
+		
+	GLint filter = _videoMode.antialiasing ? GL_LINEAR : GL_NEAREST;
+	_gameTexture->setFilter(filter);
+	_overlayTexture->setFilter(filter);
+	_cursorTexture->setFilter(filter);
+
+	if (_transactionDetails.newContext || _transactionDetails.filterChanged) {
+		_gameTexture->refresh();
+		_overlayTexture->refresh();
 		_cursorTexture->refresh();
+	}
 
 	_gameTexture->allocBuffer(_videoMode.screenWidth, _videoMode.screenHeight);
 	_overlayTexture->allocBuffer(_videoMode.overlayWidth, _videoMode.overlayHeight);
-	_cursorTexture->allocBuffer(16, 16);
+	_cursorTexture->allocBuffer(_cursorState.w, _cursorState.h);
+}
 
+bool OpenGLGraphicsManager::loadGFXMode() {
+	// Initialize OpenGL settings
+	initGL();
+
+	loadTextures();
+
 	internUpdateScreen();
 
 	return true;

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-22 14:43:19 UTC (rev 51145)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-22 15:36:50 UTC (rev 51146)
@@ -102,6 +102,7 @@
 protected:
 
 	virtual void initGL();
+	virtual void loadTextures();
 
 	//
 	// GFX and video
@@ -117,6 +118,7 @@
 		bool needHotswap;
 		bool needUpdatescreen;
 		bool newContext;
+		bool filterChanged;
 #ifdef USE_RGB_COLOR
 		bool formatChanged;
 #endif
@@ -133,6 +135,7 @@
 
 		int mode;
 		int scaleFactor;
+		bool antialiasing;
 
 		int screenWidth, screenHeight;
 		int overlayWidth, overlayHeight;

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-22 14:43:19 UTC (rev 51145)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-22 15:36:50 UTC (rev 51146)
@@ -165,7 +165,7 @@
 		}
 	}
 
-	if (_oldVideoMode.fullscreen != _videoMode.fullscreen)
+	if (_oldVideoMode.fullscreen || _videoMode.fullscreen)
 		_transactionDetails.newContext = true;
 
 	_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
@@ -224,6 +224,15 @@
 		return true;
 	}*/
 
+	// Ctrl-Alt-f toggles antialiasing
+	if (key == 'f') {
+		beginGFXTransaction();
+			_videoMode.antialiasing = !_videoMode.antialiasing;
+			_transactionDetails.filterChanged = true;
+		endGFXTransaction();
+		return true;
+	}
+
 	SDLKey sdlKey = (SDLKey)key;
 
 	// Increase/decrease the scale factor
@@ -235,7 +244,8 @@
 			beginGFXTransaction();
 				setScale(factor);
 			endGFXTransaction();
-		}	
+			return true;
+		}
 	}
 	return false;
 }
@@ -255,7 +265,7 @@
 		const bool isScaleKey = (event.kbd.keycode == Common::KEYCODE_EQUALS || event.kbd.keycode == Common::KEYCODE_PLUS || event.kbd.keycode == Common::KEYCODE_MINUS ||
 			event.kbd.keycode == Common::KEYCODE_KP_PLUS || event.kbd.keycode == Common::KEYCODE_KP_MINUS);
 
-		return (isScaleKey || event.kbd.keycode == 'a');
+		return (isScaleKey || event.kbd.keycode == 'a' || event.kbd.keycode == 'f');
 	}
 	return false;
 }


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