[Scummvm-cvs-logs] SF.net SVN: scummvm:[53803] scummvm/trunk/backends/platform/android/video. cpp

anguslees at users.sourceforge.net anguslees at users.sourceforge.net
Mon Oct 25 09:35:41 CEST 2010


Revision: 53803
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53803&view=rev
Author:   anguslees
Date:     2010-10-25 07:35:40 +0000 (Mon, 25 Oct 2010)

Log Message:
-----------
ANDROID: Provide an alternate partial texture update for stride != width

The new one copies into a temp buffer and only does one
glTexSubImage2D.  I'm led to believe that this is faster on some
devices (but slower on others).  Disabled for now, but someone might
want to try both versions on their slow device.

Also manually set glColor before calling DrawTexiOES, following
mention of a bug in a discussion I stumbled across.  DrawTexiOES-use
is disabled for now, so this is a noop.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/android/video.cpp

Modified: scummvm/trunk/backends/platform/android/video.cpp
===================================================================
--- scummvm/trunk/backends/platform/android/video.cpp	2010-10-25 07:29:12 UTC (rev 53802)
+++ scummvm/trunk/backends/platform/android/video.cpp	2010-10-25 07:35:40 UTC (rev 53803)
@@ -38,6 +38,9 @@
 
 #include "backends/platform/android/video.h"
 
+// Unfortunately, Android devices are too varied to make broad assumptions :/
+#define TEXSUBIMAGE_IS_EXPENSIVE 0
+
 #undef LOG_TAG
 #define LOG_TAG "ScummVM-video"
 
@@ -158,13 +161,11 @@
 	// later (perhaps with multiple TexSubImage2D operations).
 	CHECK_GL_ERROR();
 	glBindTexture(GL_TEXTURE_2D, _texture_name);
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 	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(),
@@ -177,6 +178,7 @@
 							   const void* buf, int pitch) {
 	ENTER("updateBuffer(%u, %u, %u, %u, %p, %d)", x, y, w, h, buf, pitch);
 	glBindTexture(GL_TEXTURE_2D, _texture_name);
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
 	setDirtyRect(Common::Rect(x, y, x+w, y+h));
 
@@ -185,24 +187,41 @@
 						glFormat(), glType(), buf);
 	} else {
 		// GLES removed the ability to specify pitch, so we
-		// have to do this row by row.
+		// have to do this ourselves.
+		if (h == 0)
+			return;
+
+#if TEXSUBIMAGE_IS_EXPENSIVE
+		byte tmpbuf[w * h * bytesPerPixel()];
 		const byte* src = static_cast<const byte*>(buf);
+		byte* dst = tmpbuf;
+		GLuint count = h;
 		do {
+			memcpy(dst, src, w * bytesPerPixel());
+			dst += w * bytesPerPixel();
+			src += pitch;
+		} while (--count);
+		glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
+						glFormat(), glType(), tmpbuf);
+#else
+		// This version avoids the intermediate copy at the expense of
+		// repeat glTexSubImage2D calls.  On some devices this is worse.
+		const byte* src = static_cast<const byte*>(buf);
+		do {
 			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
 							w, 1, glFormat(), glType(), src);
 			++y;
 			src += pitch;
 		} while (--h);
+#endif
 	}
 }
 
 void GLESTexture::fillBuffer(byte x) {
-	byte tmpbuf[_surface.h * _surface.w * bytesPerPixel()];
-	memset(tmpbuf, 0, _surface.h * _surface.w * bytesPerPixel());
-	glBindTexture(GL_TEXTURE_2D, _texture_name);
-	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _surface.w, _surface.h,
-					glFormat(), glType(), tmpbuf);
-	setDirty();
+	int rowbytes = _surface.w * bytesPerPixel();
+	byte tmpbuf[_surface.h * rowbytes];
+	memset(tmpbuf, x, _surface.h * rowbytes);
+	updateBuffer(0, 0, _surface.w, _surface.h, tmpbuf, rowbytes);
 }
 
 void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
@@ -215,6 +234,7 @@
 		//glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 		const GLint crop[4] = {0, _surface.h, _surface.w, -_surface.h};
 		glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+		glColor4ub(0xff, 0xff, 0xff, 0xff);   // Android GLES bug?
 		glDrawTexiOES(x, y, 0, w, h);
 	} else
 #endif


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