PDA

View Full Version : RTTCBB glCopyTexSubImage2D Proper Usage



cournia
05-20-2004, 02:24 PM
I'm trying to implement render to texture by copying the back buffer. My psuedo-code looks something like this:


int main() {
glGenTexture(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex); //do once!
glTexImage2D(...)

while(!quit) {
glClear(GL_COLOR_BUFFER_BIT);
renderTexScene();
glBindTexture(GL_TEXTURE_2D, tex);
glCopyTexSubImage2D(...);
renderRealScene();
swapBuffers();
}
}This works great on the several types of NVIDIA FX Quadro cards I have access to. However, the above code does not work on my ancient ATI FireGL card.

The FireGL renders the scene correctly on the first iteration of the loop, but produces a corrupted RTT on all following iterations.

The FireGL card will work if the code is modified as follows:


int main() {
glGenTexture(1, &tex);

while(!quit) {
glClear(GL_COLOR_BUFFER_BIT);
renderTexScene();
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(...); //do once per iteration!
glCopyTexSubImage2D(...);
renderRealScene();
swapBuffers();
}
}I now call glTexImage2D every frame! This leads me to a couple of questions:

What's the correct way to handle RTTCBB? Should glTex2D be called every frame or only once?

If glTex2D is to be called every frame, will this lead to memory leaks?

Thanks.

nathan