Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-13 Thread Freddie Witherden

Hi all,

On 12 Apr 2009, at 22:24, Dennis Schridde wrote:

tmp = malloc(texture_width * texture_height * 4);

glGenTextures(1, video_texture);
   glBindTexture(GL_TEXTURE_2D, video_texture);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
texture_height,
   0, GL_RGBA, GL_UNSIGNED_BYTE, tmp);

Why not use a PBO instead?


GL 2.1.

Regards, Freddie.



PGP.sig
Description: This is a digitally signed message part
___
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev


Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-13 Thread Christian Ohm
On Sunday, 12 April 2009 at 22:47, Per Inge Mathisen wrote:
 I don't understand this part of the patch (new since first version):
 
   tmp = malloc(texture_width * texture_height * 4);
 
   glGenTextures(1, video_texture);
 glBindTexture(GL_TEXTURE_2D, video_texture);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
 texture_height,
 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
 GL_NEAREST);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
 free(tmp);
 
 Do you upload an uninitialized buffer here?

Yes. I'm uploading the video image via glTexSubImage, but before I can do that,
I need to call glTexImage once to initialize the texture. The content of the
buffer is completely irrelevant, since the part of the texture that is shown on
screen is updated with the video before being displayed.

That part was there in the first patch, btw, in the if(!initialized) block in
video_write (where it doesn't make that much sense code-wise, but perhaps
illustrates the order of things better).

___
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev


Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-13 Thread Christian Ohm
On Sunday, 12 April 2009 at 23:24, Dennis Schridde wrote:
 Why not use a PBO instead?

Because I just adapted the existing code to use regular textures, since my main
target for this patch is 2.2. I don't want to rewrite large part of the code,
and I don't want to introduce newer GL functionality that 2.2 doesn't depend on
right now (and which my drivers may not support, and I'm not familiar with).

___
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev


Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-13 Thread Per Inge Mathisen
On Mon, Apr 13, 2009 at 12:49 PM, Christian Ohm chr@gmx.net wrote:
 On Sunday, 12 April 2009 at 22:47, Per Inge Mathisen wrote:
 I don't understand this part of the patch (new since first version):

                       tmp = malloc(texture_width * texture_height * 4);

                       glGenTextures(1, video_texture);
                 glBindTexture(GL_TEXTURE_2D, video_texture);
                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
 texture_height,
                                 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp);
                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 GL_LINEAR);
                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
 GL_NEAREST);
                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

                 free(tmp);

 Do you upload an uninitialized buffer here?

 Yes. I'm uploading the video image via glTexSubImage, but before I can do 
 that,
 I need to call glTexImage once to initialize the texture. The content of the
 buffer is completely irrelevant, since the part of the texture that is shown 
 on
 screen is updated with the video before being displayed.

Ah. But there is no need to upload an uninitialized buffer to do this.
Just use glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

  - Per

___
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev


Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-13 Thread Christian Ohm
On Monday, 13 April 2009 at 14:59, Per Inge Mathisen wrote:
 Ah. But there is no need to upload an uninitialized buffer to do this.
 Just use glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
 texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

Nice. I thought about that as well, but missed the part where it is mentioned
as valid in the glTexImage man page, and didn't try it yet (since my drivers
tend to lock up when I do something they don't like).

So, patch without useless malloc.
 lib/ivis_opengl/screen.c |5 --
 lib/sequence/sequence.c  |   94 +
 2 files changed, 44 insertions(+), 55 deletions(-)

diff --git a/lib/ivis_opengl/screen.c b/lib/ivis_opengl/screen.c
index 94bb657..216ef15 100644
--- a/lib/ivis_opengl/screen.c
+++ b/lib/ivis_opengl/screen.c
@@ -184,11 +184,6 @@ BOOL screenInitialise(
 	debug(LOG_3D,   * Rectangular texture %s supported., GLEE_ARB_texture_rectangle ? is : is NOT);
 	debug(LOG_3D,   * FrameBuffer Object (FBO) %s supported., GLEE_EXT_framebuffer_object  ? is : is NOT);
 
-	if (!GLEE_ARB_texture_rectangle)
-	{
-		debug(LOG_ERROR, Radar will not be displayed without support for texture rectangle extension!);
-	}
-
 	glViewport(0, 0, width, height);
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
diff --git a/lib/sequence/sequence.c b/lib/sequence/sequence.c
index a1ce37b..a535fd9 100644
--- a/lib/sequence/sequence.c
+++ b/lib/sequence/sequence.c
@@ -133,7 +133,6 @@ static bool audiobuf_ready = false;		// single 'frame' audio buffer ready for pr
 // file handle
 static PHYSFS_file* fpInfile = NULL;
 
-static GLuint backDropTexture2 = ~0;	// GL texture ID
 static char* RGBAframe = NULL;	// texture buffer
 
 #if !defined(WZ_NOSOUND)
@@ -277,36 +276,30 @@ static void Allocate_videoFrame(void)
 	RGBAframe = malloc(videodata.ti.frame_width * videodata.ti.frame_height * 4);
 }
 
+static int texture_width = 512;
+static int texture_height = 512;
+static GLuint video_texture;
+
 #define Vclip( x )	( (x  0) ? ((x  255) ? x : 255) : 0 )
 // main routine to display video on screen.
 static void video_write(bool update)
 {
 	unsigned int x = 0, y = 0;
-	static bool unsupportedExtention = false;
+	const int video_width = videodata.ti.frame_width;
+	const int video_height = videodata.ti.frame_height;
 	yuv_buffer yuv;
 
-	// don't bother continuing if they don't have correct openGL extention.
-	if (unsupportedExtention)
-	{
-		return;
-	}
-	if (!GLEE_ARB_texture_rectangle)
-	{
-		// bail out, and complain about crappy hardware *once*.
-		debug(LOG_WARNING , You got some really crappy hardware! GL_TEXTURE_RECTANGLE_ARB not supported!);
-		debug(LOG_WARNING , Video will not show!);
-		unsupportedExtention = true;
-		return;
-	}
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, video_texture);
 
 	if (update)
 	{
 		theora_decode_YUVout(videodata.td, yuv);
 
 		// fill the RGBA buffer
-		for (y = 0; y  videodata.ti.frame_height; y++)
+		for (y = 0; y  video_height; y++)
 		{
-			for (x = 0; x  videodata.ti.frame_width; x++)
+			for (x = 0; x  video_width; x++)
 			{
 int Y = yuv.y[x + y * yuv.y_stride];
 int U = yuv.u[x / 2 + (y / 2) * yuv.uv_stride];
@@ -320,43 +313,21 @@ static void video_write(bool update)
 int G = Vclip((298 * C - 100 * D - 208 * E + 128)  8);
 int B = Vclip((298 * C + 516 * D + 128)  8);
 
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 0] = R;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 1] = G;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 2] = B;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 3] = 0xFF;
+RGBAframe[x * 4 + y * video_width * 4 + 0] = R;
+RGBAframe[x * 4 + y * video_width * 4 + 1] = G;
+RGBAframe[x * 4 + y * video_width * 4 + 2] = B;
+RGBAframe[x * 4 + y * video_width * 4 + 3] = 0xFF;
 			}
 		}
 
-		if (backDropTexture2 != (GLuint)~0)
-		{
-			glDeleteTextures(1, backDropTexture2);
-		}
-
-		glGenTextures(1, backDropTexture2);
-		glEnable(GL_TEXTURE_RECTANGLE_ARB);
-		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, backDropTexture2);
-		glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, videodata.ti.frame_width,
-		videodata.ti.frame_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
-
-		glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
-		glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
-		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
-		glDisable(GL_TEXTURE_RECTANGLE_ARB);
-
+		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, video_width,
+video_height, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
 	}
 
 	glDisable(GL_DEPTH_TEST);
 	glDepthMask(GL_FALSE);
 
-	// Make sure the current texture page is reloaded after we are finished
-	// Otherwise WZ will think it is still loaded and not load it again
-	pie_SetTexturePage(-1);

Re: [Warzone-dev] [PATCH] Don't use the texture rectangle extension for video display

2009-04-11 Thread Christian Ohm
Argh. Forgot the patch, and replied to the wrong mail...

Updated patch.

I've moved texture creation from video_write() into seq_Play(), where it makes
more sense, and added a check for the video size. I've also removed the radar
warning message, and added a check for the YUV420 format (though those should
be committed separately).
 lib/ivis_opengl/screen.c |5 --
 lib/sequence/sequence.c  |   99 +++---
 2 files changed, 49 insertions(+), 55 deletions(-)

diff --git a/lib/ivis_opengl/screen.c b/lib/ivis_opengl/screen.c
index 94bb657..216ef15 100644
--- a/lib/ivis_opengl/screen.c
+++ b/lib/ivis_opengl/screen.c
@@ -184,11 +184,6 @@ BOOL screenInitialise(
 	debug(LOG_3D,   * Rectangular texture %s supported., GLEE_ARB_texture_rectangle ? is : is NOT);
 	debug(LOG_3D,   * FrameBuffer Object (FBO) %s supported., GLEE_EXT_framebuffer_object  ? is : is NOT);
 
-	if (!GLEE_ARB_texture_rectangle)
-	{
-		debug(LOG_ERROR, Radar will not be displayed without support for texture rectangle extension!);
-	}
-
 	glViewport(0, 0, width, height);
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
diff --git a/lib/sequence/sequence.c b/lib/sequence/sequence.c
index a1ce37b..80f966c 100644
--- a/lib/sequence/sequence.c
+++ b/lib/sequence/sequence.c
@@ -133,7 +133,6 @@ static bool audiobuf_ready = false;		// single 'frame' audio buffer ready for pr
 // file handle
 static PHYSFS_file* fpInfile = NULL;
 
-static GLuint backDropTexture2 = ~0;	// GL texture ID
 static char* RGBAframe = NULL;	// texture buffer
 
 #if !defined(WZ_NOSOUND)
@@ -277,36 +276,30 @@ static void Allocate_videoFrame(void)
 	RGBAframe = malloc(videodata.ti.frame_width * videodata.ti.frame_height * 4);
 }
 
+static int texture_width = 512;
+static int texture_height = 512;
+static GLuint video_texture;
+
 #define Vclip( x )	( (x  0) ? ((x  255) ? x : 255) : 0 )
 // main routine to display video on screen.
 static void video_write(bool update)
 {
 	unsigned int x = 0, y = 0;
-	static bool unsupportedExtention = false;
+	const int video_width = videodata.ti.frame_width;
+	const int video_height = videodata.ti.frame_height;
 	yuv_buffer yuv;
 
-	// don't bother continuing if they don't have correct openGL extention.
-	if (unsupportedExtention)
-	{
-		return;
-	}
-	if (!GLEE_ARB_texture_rectangle)
-	{
-		// bail out, and complain about crappy hardware *once*.
-		debug(LOG_WARNING , You got some really crappy hardware! GL_TEXTURE_RECTANGLE_ARB not supported!);
-		debug(LOG_WARNING , Video will not show!);
-		unsupportedExtention = true;
-		return;
-	}
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, video_texture);
 
 	if (update)
 	{
 		theora_decode_YUVout(videodata.td, yuv);
 
 		// fill the RGBA buffer
-		for (y = 0; y  videodata.ti.frame_height; y++)
+		for (y = 0; y  video_height; y++)
 		{
-			for (x = 0; x  videodata.ti.frame_width; x++)
+			for (x = 0; x  video_width; x++)
 			{
 int Y = yuv.y[x + y * yuv.y_stride];
 int U = yuv.u[x / 2 + (y / 2) * yuv.uv_stride];
@@ -320,43 +313,21 @@ static void video_write(bool update)
 int G = Vclip((298 * C - 100 * D - 208 * E + 128)  8);
 int B = Vclip((298 * C + 516 * D + 128)  8);
 
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 0] = R;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 1] = G;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 2] = B;
-RGBAframe[x * 4 + y * videodata.ti.frame_width * 4 + 3] = 0xFF;
+RGBAframe[x * 4 + y * video_width * 4 + 0] = R;
+RGBAframe[x * 4 + y * video_width * 4 + 1] = G;
+RGBAframe[x * 4 + y * video_width * 4 + 2] = B;
+RGBAframe[x * 4 + y * video_width * 4 + 3] = 0xFF;
 			}
 		}
 
-		if (backDropTexture2 != (GLuint)~0)
-		{
-			glDeleteTextures(1, backDropTexture2);
-		}
-
-		glGenTextures(1, backDropTexture2);
-		glEnable(GL_TEXTURE_RECTANGLE_ARB);
-		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, backDropTexture2);
-		glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, videodata.ti.frame_width,
-		videodata.ti.frame_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
-
-		glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
-		glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
-		glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
-		glDisable(GL_TEXTURE_RECTANGLE_ARB);
-
+		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, video_width,
+video_height, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
 	}
 
 	glDisable(GL_DEPTH_TEST);
 	glDepthMask(GL_FALSE);
 
-	// Make sure the current texture page is reloaded after we are finished
-	// Otherwise WZ will think it is still loaded and not load it again
-	pie_SetTexturePage(-1);
-
 	glPushMatrix();
-	glEnable(GL_TEXTURE_RECTANGLE_ARB);
-	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, backDropTexture2);
 
 	// NOTE: 255 * width | height,