Welcome! Log In Create A New Profile

Advanced

Render to texture

Posted by dancinninja 
Render to texture
April 29, 2010 11:35PM
Hey all, I tried searching but I couldn't find an answer to my problem. I am trying to convert an OpenGL program to GX. I'm close, I can feel it.

What it's supposed to do: The program renders the 3D scene, then copies the buffer (which in GX would be the embeded frame buffer) to a big array (which I'll call the texture buffer). This array is then combined with the 2D array that was already rendered in another location of the program. The combined buffer is then applied as a texture and displayed on a quad. This quad is smaller than the whole screen.

The OpenGL function that copies to the array is given as:
glReadPixels(0, 0, 256,224, GL_BGRA, GL_UNSIGNED_BYTE, renderScreen3D);

I am really unsure as to how to go about doing this. I have tried several times to no avail. The copy function (that doesn't work) that I came up with was:

static u8 renderScreen3D[256*224*4];  // This is 32-bit aligned
//...
// In the copy function:
GX_SetTexCopySrc(0, 0, 256, 224);
GX_SetTexCopyDst(256, 224, GX_TF_RGB8, GX_FALSE);
GX_CopyTex((renderScreen3D), GX_TRUE);

What am I missing?

Also, since this is smaller than the whole screen, is it possible to "limit" my rendering to a smaller "screen" so to speak? Since I have to copy to a smaller "screen" anyway. Would that help preserve precious GPU clock ticks?

Thanks!
Re: Render to texture
April 30, 2010 09:40AM
The copy operation is not immediate, you need some synchronization to tell you when it's finished.

GX_PixModeSync();
GX_Flush();

usually do the job

Don't forget to also flush texture data from cache before using it since it was modified externally by the GPU

DCFlushRange(renderScreen3D, 256*224*4);
Re: Render to texture
April 30, 2010 06:54PM
Awesome! I'll try that. Thanks a bunch!
Sorry, only registered users may post in this forum.

Click here to login