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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jul 20 09:10:25 CEST 2010


Revision: 51050
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51050&view=rev
Author:   fingolfin
Date:     2010-07-20 07:10:25 +0000 (Tue, 20 Jul 2010)

Log Message:
-----------
Change CHECK_GL_ERROR to not take a 'call statement' as parameter

Passing a 'call statement' to CHECK_GL_ERROR has various issues.
For once, it confuses code parsers in many editors and other
tools that work with C++ source directly.
Moreover, this can lead to subtle bugs if a mistake is
made with the definition of CHECK_GL_ERROR.
It also causes incorrect warnings if CHECK_GL_ERROR is
used with an "empty" call statement.

Modified Paths:
--------------
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/glerrorcheck.h
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/glerrorcheck.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/glerrorcheck.h	2010-07-20 04:32:31 UTC (rev 51049)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/glerrorcheck.h	2010-07-20 07:10:25 UTC (rev 51050)
@@ -25,13 +25,13 @@
 
 #if !defined(DEBUG)
 
-// If not in debug, just do the GL call
-#define CHECK_GL_ERROR(call) (call)
+// If not in debug, do nothing
+#define CHECK_GL_ERROR() do {} while (false)
 
 #else
 
 // If in debug, check for an error after a GL call
-#define CHECK_GL_ERROR(call) ((call), checkGlError(__FILE__, __LINE__))
+#define CHECK_GL_ERROR() checkGlError(__FILE__, __LINE__)
 
 void checkGlError(const char *file, int line);
 

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-20 04:32:31 UTC (rev 51049)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/gltexture.cpp	2010-07-20 07:10:25 UTC (rev 51050)
@@ -61,7 +61,7 @@
 
 	const char* ext_string =
 		reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
-	CHECK_GL_ERROR(0);
+	CHECK_GL_ERROR();
 	Common::StringTokenizer tokenizer(ext_string, " ");
 	while (!tokenizer.empty()) {
 		Common::String token = tokenizer.nextToken();
@@ -83,7 +83,7 @@
 	_refresh(false) {
 
 	// Generates the texture ID for GL
-	CHECK_GL_ERROR( glGenTextures(1, &_textureName) );
+	glGenTextures(1, &_textureName); CHECK_GL_ERROR();
 
 	// This all gets reset later in allocBuffer:
 	_surface.w = 0;
@@ -94,12 +94,12 @@
 }
 
 GLTexture::~GLTexture() {
-	CHECK_GL_ERROR( glDeleteTextures(1, &_textureName) );
+	glDeleteTextures(1, &_textureName); CHECK_GL_ERROR();
 }
 
 void GLTexture::refresh() {
 	// Generates the texture ID for GL
-	CHECK_GL_ERROR( glGenTextures(1, &_textureName) );
+	glGenTextures(1, &_textureName); CHECK_GL_ERROR();
 	_refresh = true;
 }
 
@@ -121,13 +121,13 @@
 
 	// Allocate room for the texture now, but pixel data gets uploaded
 	// later (perhaps with multiple TexSubImage2D operations).
-	CHECK_GL_ERROR( 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_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,
-		     _textureWidth, _textureHeight, 0, _glFormat, _glType, NULL) );
+	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_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,
+		     _textureWidth, _textureHeight, 0, _glFormat, _glType, NULL); CHECK_GL_ERROR();
 
 	if (_surface.w != _textureWidth || _surface.h != _textureHeight)
 		_surface.create(_textureWidth, _textureHeight, _bytesPerPixel);
@@ -136,17 +136,17 @@
 }
 
 void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLuint w, GLuint h) {
-	CHECK_GL_ERROR( glBindTexture(GL_TEXTURE_2D, _textureName) );
+	glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
 
 	if (static_cast<int>(w) * _bytesPerPixel == pitch) {
-		CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
-						_glFormat, _glType, buf) );
+		glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
+						_glFormat, _glType, buf); CHECK_GL_ERROR();
 		memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
 	} else {
 		const byte* src = static_cast<const byte*>(buf);
 		do {
-			CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
-							w, 1, _glFormat, _glType, src) );
+			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
+							w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
 			memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
 			++y;
 			src += pitch;
@@ -156,13 +156,13 @@
 
 void GLTexture::fillBuffer(byte x) {
 	memset(_surface.pixels, x, _surface.h * _surface.pitch);
-	CHECK_GL_ERROR( glBindTexture(GL_TEXTURE_2D, _textureName) );
-	CHECK_GL_ERROR( glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _surface.w, _surface.h,
-		_glFormat, _glType, _surface.pixels) );
+	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();
 }
 
 void GLTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
-	CHECK_GL_ERROR( glBindTexture(GL_TEXTURE_2D, _textureName) );
+	glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
 
 	const GLfloat texWidth = (GLfloat)_realWidth / _textureWidth;//xdiv(_surface.w, _textureWidth);
 	const GLfloat texHeight = (GLfloat)_realHeight / _textureHeight;//xdiv(_surface.h, _textureHeight);
@@ -172,7 +172,7 @@
 		0, texHeight,
 		texWidth, texHeight,
 	};
-	CHECK_GL_ERROR( glTexCoordPointer(2, GL_FLOAT, 0, texcoords) );
+	glTexCoordPointer(2, GL_FLOAT, 0, texcoords); CHECK_GL_ERROR();
 
 	const GLshort vertices[] = {
 		x,	   y,
@@ -180,9 +180,9 @@
 		x,	   y + h,
 		x + w, y + h,
 	};
-	CHECK_GL_ERROR( glVertexPointer(2, GL_SHORT, 0, vertices) );
+	glVertexPointer(2, GL_SHORT, 0, vertices); CHECK_GL_ERROR();
 
-	CHECK_GL_ERROR( glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) );
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); CHECK_GL_ERROR();
 }
 
 #endif

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-20 04:32:31 UTC (rev 51049)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-20 07:10:25 UTC (rev 51050)
@@ -527,7 +527,7 @@
 
 void OpenGLGraphicsManager::internUpdateScreen() {
 	// Clear the screen
-	CHECK_GL_ERROR( glClear(GL_COLOR_BUFFER_BIT) );
+	glClear(GL_COLOR_BUFFER_BIT); CHECK_GL_ERROR();
 
 	// Draw the game screen
 	_gameTexture->drawTexture(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
@@ -550,33 +550,33 @@
 	GLTexture::initGLExtensions();
 
 	// Disable 3D properties
-	CHECK_GL_ERROR( glDisable(GL_CULL_FACE) );
-	CHECK_GL_ERROR( glDisable(GL_DEPTH_TEST) );
-	CHECK_GL_ERROR( glDisable(GL_LIGHTING) );
-	CHECK_GL_ERROR( glDisable(GL_FOG) );
-	CHECK_GL_ERROR( glDisable(GL_DITHER) );
-	CHECK_GL_ERROR( glShadeModel(GL_FLAT) );
-	CHECK_GL_ERROR( glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST) );
+	glDisable(GL_CULL_FACE); CHECK_GL_ERROR();
+	glDisable(GL_DEPTH_TEST); CHECK_GL_ERROR();
+	glDisable(GL_LIGHTING); CHECK_GL_ERROR();
+	glDisable(GL_FOG); CHECK_GL_ERROR();
+	glDisable(GL_DITHER); CHECK_GL_ERROR();
+	glShadeModel(GL_FLAT); CHECK_GL_ERROR();
+	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); CHECK_GL_ERROR();
 
 	// Setup alpha blend (For overlay and cursor)
-	CHECK_GL_ERROR( glEnable(GL_BLEND) );
-	CHECK_GL_ERROR( glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
+	glEnable(GL_BLEND); CHECK_GL_ERROR();
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); CHECK_GL_ERROR();
 
 	// Enable rendering with vertex and coord arrays
-	CHECK_GL_ERROR( glEnableClientState(GL_VERTEX_ARRAY) );
-	CHECK_GL_ERROR( glEnableClientState(GL_TEXTURE_COORD_ARRAY) );
+	glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR();
+	glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL_ERROR();
 
-	CHECK_GL_ERROR( glEnable(GL_TEXTURE_2D) );
+	glEnable(GL_TEXTURE_2D); CHECK_GL_ERROR();
 
 	// Setup the GL viewport
-	CHECK_GL_ERROR( glViewport(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight) );
+	glViewport(0, 0, _videoMode.hardwareWidth, _videoMode.hardwareHeight); CHECK_GL_ERROR();
 
 	// Setup coordinates system
-	CHECK_GL_ERROR( glMatrixMode(GL_PROJECTION) );
-	CHECK_GL_ERROR( glLoadIdentity() );
-	CHECK_GL_ERROR( glOrtho(0, _videoMode.hardwareWidth, _videoMode.hardwareHeight, 0, -1, 1) );
-	CHECK_GL_ERROR( glMatrixMode(GL_MODELVIEW) );
-	CHECK_GL_ERROR( glLoadIdentity() );
+	glMatrixMode(GL_PROJECTION); CHECK_GL_ERROR();
+	glLoadIdentity(); CHECK_GL_ERROR();
+	glOrtho(0, _videoMode.hardwareWidth, _videoMode.hardwareHeight, 0, -1, 1); CHECK_GL_ERROR();
+	glMatrixMode(GL_MODELVIEW); CHECK_GL_ERROR();
+	glLoadIdentity(); CHECK_GL_ERROR();
 }
 
 bool OpenGLGraphicsManager::loadGFXMode() {


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