[SDL] Bugs in RenderTarget, fixes, and floating-point buffers

Jonathan Thambidurai jonthambi at comcast.net
Sun Feb 20 00:55:15 PST 2005


Attached is a diff against SDL 1.3 CVS.  It fixes some bugs which I will
explain and adds support for nVidia's floating-point buffer extension.

The bugs are concerned with attributes.  Look at the following code from
SDL_GL_CreateRenderTarget() in SDL_video.c:

if ( attrib ) {
	int i, j;
	for ( i = 0; attrib[i]; i += 2 ) {
		for ( j = 0; complete_attrib[j]; j += 2 ) {
			if ( attrib[i] == complete_attrib[j] ) {
				complete_attrib[i+1] = attrib[j+1];
				break;
			}
		}
	}
}

The 1st, most obvious problem is in "complete_attrib[i+1] =
attrib[j+1];"  I believe that complete_attrib should not be indexed by
"i", but rather by "j" and vice-versa for attrib.  The 2nd, more
difficult problem is that both the loops (over attrib and
complete_attrib) end when a value of zero is found, assuming that it is
a null-terminator of the array.  However, a valid value is
SDL_GL_RED_SIZE, an enum which evaluates to a value of zero; thus, the
loops terminate prematurely whenever they arrive at SDL_GL_RED_SIZE. 
See my patch for how I dealt with this (I know it requires more zeros
than necessary at the end and is not robust).

Lastly, the bulk of my patch hacks in support for GL_NV_float_buffer,
which requires GL_NV_texture_rectangle for glCopyTexImage2D (for
framerates greater than 5 fps), which in turn requires a fragment
program to be used (NV_texture_rectangle targets can only be used by
fragment programs, not the fixed-function pipeline).  I created a
program to test these floating-point programs based on the existing
testrendertarget.c; I used nVidia's Cg language to implement the
fragment program and thus had to link to the Cg libs to compile it.  I
have not attached the program, but if anyone would like it, tell me and
I'll post it and the associated cg files on a website.

If someone is actually thinking about commiting the float_buffer
changes, they should know that the ARB_color_buffer_float extension
coupled with ARB_texture_float should be more robust and more
widely-supported in the future (both are scheduled for implementation in
the next nVidia driver release), so it may be wise to wait for that.

This code was only tested on a GeForce 6800.

Regards,
Jonathan Thambidurai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SDL-main-cvs.diff
Type: application/octet-stream
Size: 9955 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050220/55db2e1d/attachment.obj>


More information about the SDL mailing list