problem about the multi-pass Render-To-Texture

Hi,have anyone encounter the this problem?
I want to use Render-To-Texuture in my problem, but it is a multi-pass algorithm.
That’t is to say, the result of Render-To-Texture would be used in the next pass as an input texture.
In the following program, I introduce an intermediate texture as the texture of Render-To-Texture,
then swap it with the input texture. BUT NO way to realize my idea, I am nearly crazy about this.

Initially the data from texture resultTextureID is zero.
for(i=0; i<nPass; i++)
glBindTexture(_iTextureTarget, intermedTextureID);
wglReleaseTexImageARB(_hPBuffer, WGL_FRONT_LEFT_ARB);
wglMakeCurrent( _hDC, _hGLContext);///PBuffer context

	glBindTexture(_iTextureTarget, resultTextureID);
	///Here I check it, the data from texture resultTextureID is zero,
	///even in the next pass


	glBindTexture(_iTextureTarget, intermedTextureID);
	wglMakeCurrent( _hPreviousDC, _hPreviousContext);
	wglBindTexImageARB(_hPBuffer, WGL_FRONT_LEFT_ARB);
	///Swap the Texture ID
	tempID = intermedTextureID;
	intermedTextureID = resultTextureID;
	resultSetTextureID = tempID;
	////Here I find the the data from texture resultTextureID is the rendering result
	////But why in the next pass, it returns to zero?
	////And I think in the begining of each pass, just the data from intermedTextureID should be zero

Am I made myself clear? And I find no reference in the specificatioin about this. So hope gurus come here. Thanks for any suggestion.

[This message has been edited by foollove (edited 02-04-2004).]

I think this problem is valuable for multi-pass algorithm.
Well known that Copy-To-Texture is much slower than Render-To-Texture. So we hope to find out the way to re-use what we have rendered as a texture.

Really need help. Thanks a lot.

In the following it works correctly even the result texture is same to the input texture which used in fragment program. Here two pbuffers are used.

for(i=0; i<nPass; i++)
WhichPBuffer = i%2;
glBindTexture(_iTextureTarget, resultTextureID);
glBegin( GL_QUADS );
glVertex2i( 0, 0 );
glVertex2i( Width, 0 );
glVertex2i( Width, Height );
glVertex2i( 0, Height );

  // save the result texture into result
  glBindTexture(_iTextureTarget, resultTextureID);


But I really don’t know the reason when I swap two texture ids with just ONE pbuffer, it can NOT work.

But I am really confused how to manage the two pbuffers correctly. Can some one provide any suggestions or give an example. Thanks in advance