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

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Fri Jul 23 08:57:23 CEST 2010


Revision: 51193
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51193&view=rev
Author:   vgvgf
Date:     2010-07-23 06:57:23 +0000 (Fri, 23 Jul 2010)

Log Message:
-----------
OPENGL: Add basic game screen drawing. Changed Overlay PixelFormat to RGBA5551. 

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/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-23 05:15:11 UTC (rev 51192)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-23 06:57:23 UTC (rev 51193)
@@ -104,6 +104,10 @@
 	_refresh = true;
 }
 
+void GLTexture::refreshBuffer() {
+	updateBuffer(_surface.pixels, _surface.pitch, 0, 0, _surface.w, _surface.h);
+}
+
 void GLTexture::allocBuffer(GLuint w, GLuint h) {
 	_realWidth = w;
 	_realHeight = h;
@@ -133,7 +137,7 @@
 	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);
+		refreshBuffer();
 
 	_refresh = false;
 }
@@ -147,7 +151,7 @@
 		if (buf != _surface.pixels)
 			memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
 	} else {
-		const byte* src = static_cast<const byte*>(buf);
+		const byte *src = static_cast<const byte *>(buf);
 		do {
 			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
 							w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
@@ -159,8 +163,15 @@
 	}
 }
 
-void GLTexture::fillBuffer(byte x) {
-	memset(_surface.pixels, x, _surface.h * _surface.pitch);
+void GLTexture::fillBuffer(uint32 x) {
+	if (_bytesPerPixel == 1) 
+		memset(_surface.pixels, x, _surface.w * _surface.h);
+	else {
+		for (int i = 0; i < _surface.w * _surface.h; i++) {
+			memcpy(_surface.pixels, &x, _bytesPerPixel);
+		}
+	}
+
 	glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _surface.w, _surface.h,
 		_glFormat, _glType, _surface.pixels);  CHECK_GL_ERROR();

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-23 05:15:11 UTC (rev 51192)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.h	2010-07-23 06:57:23 UTC (rev 51193)
@@ -59,9 +59,10 @@
 	virtual ~GLTexture();
 
 	virtual void refresh();
+	virtual void refreshBuffer();
 
 	virtual void allocBuffer(GLuint width, GLuint height);
-	virtual void fillBuffer(byte x);
+	virtual void fillBuffer(uint32 x);
 	virtual void updateBuffer(const void *buf, int pitch, GLuint x, GLuint y,
 		GLuint w, GLuint h);
 

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-23 05:15:11 UTC (rev 51192)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-23 06:57:23 UTC (rev 51193)
@@ -168,8 +168,7 @@
 	// Avoid redundant format changes
 	Graphics::PixelFormat newFormat;
 	if (!format)
-		newFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0);
-		//newFormat = Graphics::PixelFormat::createFormatCLUT8();
+		newFormat = Graphics::PixelFormat::createFormatCLUT8();
 	else
 		newFormat = *format;
 
@@ -327,7 +326,30 @@
 }
 
 void OpenGLGraphicsManager::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
-	_gameTexture->updateBuffer(buf, pitch, x, y, w, h);
+	if (_screenFormat == Graphics::PixelFormat::createFormatCLUT8()) {
+		// Create a temporary RGBA888 surface
+		byte *surface = new byte[w * h * 3];
+
+		// Convert the paletted buffer to RGBA888
+		const byte *src = buf;
+		byte *dst = surface;
+		for (int i = 0; i < h; i++) {
+			for (int j = 0; j < w; j++) {
+				dst[0] = _gamePalette[src[j] * 4];
+				dst[1] = _gamePalette[src[j] * 4 + 1];
+				dst[2] = _gamePalette[src[j] * 4 + 2];
+				dst += 3;
+			}
+			src += pitch;
+		}
+
+		// Update the texture
+		_gameTexture->updateBuffer(surface, w * 3, x, y, w, h);
+
+		// Free the temp surface
+		delete[] surface;
+	} else
+		_gameTexture->updateBuffer(buf, pitch, x, y, w, h);
 }
 
 Graphics::Surface *OpenGLGraphicsManager::lockScreen() {
@@ -335,7 +357,7 @@
 }
 
 void OpenGLGraphicsManager::unlockScreen() {
-	_gameTexture->refresh();
+	_gameTexture->refreshBuffer();
 }
 
 void OpenGLGraphicsManager::fillScreen(uint32 col) {
@@ -545,17 +567,18 @@
 		bpp = 2;
 		glFormat = GL_RGB;
 		gltype = GL_UNSIGNED_SHORT_5_6_5;
-	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) {  // RGB555
+	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)) {  // RGB5551
 		bpp = 2;
-		glFormat = GL_RGB;
+		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;
 		glFormat = GL_RGBA;
 		gltype = GL_UNSIGNED_SHORT_4_4_4_4;
 	} else if (pixelFormat == Graphics::PixelFormat::createFormatCLUT8()) {  // CLUT8
-		bpp = 1;
-		glFormat = GL_COLOR_INDEX;
+		// If uses a palette, create as RGBA888, then convert
+		bpp = 3;
+		glFormat = GL_RGB;
 		gltype = GL_UNSIGNED_BYTE;
 	} else {
 		error("Not supported format");
@@ -621,14 +644,23 @@
 		byte bpp;
 		GLenum format;
 		GLenum type;
+#ifdef USE_RGB_COLOR
 		getGLPixelFormat(_screenFormat, bpp, format, type);
+#else
+		getGLPixelFormat(Graphics::PixelFormat::createFormatCLUT8(), bpp, format, type);
+#endif
 		_gameTexture = new GLTexture(bpp, format, type);
 	} 
 
-	_overlayFormat = Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
+	_overlayFormat = Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0);
 
-	if (!_overlayTexture)
-		_overlayTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
+	if (!_overlayTexture) {
+		byte bpp;
+		GLenum format;
+		GLenum type;
+		getGLPixelFormat(_overlayFormat, bpp, format, type);
+		_overlayTexture = new GLTexture(bpp, format, type);
+	}
 
 	if (!_cursorTexture)
 		_cursorTexture = new GLTexture(4, GL_RGBA, GL_UNSIGNED_BYTE);

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-23 05:15:11 UTC (rev 51192)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-23 06:57:23 UTC (rev 51193)
@@ -127,8 +127,8 @@
 	_videoMode.overlayWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
 	_videoMode.overlayHeight = _videoMode.screenHeight * _videoMode.scaleFactor;
 	if (!_screenResized) {
-		_videoMode.hardwareWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
-		_videoMode.hardwareHeight = _videoMode.screenHeight * _videoMode.scaleFactor;
+		_videoMode.hardwareWidth = _videoMode.overlayWidth;
+		_videoMode.hardwareHeight = _videoMode.overlayHeight;
 	}
 	_screenResized = 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