Advice appreciated: RenderTargets and Device Reset.
by Stefan Lundmark · in Torque Game Engine Advanced · 02/10/2009 (3:46 pm) · 2 replies
I'm making some progress using Render Targets but I'm having issues when the device resets.
I'm picking up the callback from the Texture Manager, and reallocate the target textures. However, each time (in this case, when I resize the window) the device is reset, the shader is no longer processing and I get the static gray (which I filled when I cleared the render target, but still - the shader should make it red like before).
If I isolate all this into a class, make an instance of it, delete it and create it again in the new resolution, it's still broken. So it must be something I'm not cleaning up.
I looked at GlowBuffer and the Clipmapper, but no luck so far. PIX isn't telling me anything I understand, etc. If someone (Pat?) can spot an error, this is my rendering function:
Everything works just fine if I never resize the window.
Thanks in advance.
I'm picking up the callback from the Texture Manager, and reallocate the target textures. However, each time (in this case, when I resize the window) the device is reset, the shader is no longer processing and I get the static gray (which I filled when I cleared the render target, but still - the shader should make it red like before).
If I isolate all this into a class, make an instance of it, delete it and create it again in the new resolution, it's still broken. So it must be something I'm not cleaning up.
I looked at GlowBuffer and the Clipmapper, but no luck so far. PIX isn't telling me anything I understand, etc. If someone (Pat?) can spot an error, this is my rendering function:
// Matrix, Viewport and StateBlock GFX->pushWorldMatrix (); RectI vp = GFX->getViewport (); GFX->setVertexBuffer (mVertBuffer); MatrixF oldMat = setupOrthoProjection (); // from GlowBuffer GFX->setStateBlock (mSB); GFX->disableShaders (); // Sanity for(S32 i=0; i<GFX->getNumSamplers(); i++) GFX->setTexture(i, NULL); // Render Target ( GFX->pushActiveRenderTarget(); GFXTextureTargetRef myTarg = GFX->allocRenderToTextureTarget(); myTarg->attachTexture(GFXTextureTarget::Color0, mTex [1] ); GFX->setActiveRenderTarget( myTarg ); // (Removed code to keep size of post down) // It's the regular attach/GFXClearTarget/popTarget/ClearAttachments stuff // Draw GFX->setShaderConstBuffer (mConsts); GFX->setTexture (0, mTex [0]); mShader->mShader->process (); GFX->drawPrimitive (GFXTriangleFan, 0, 2); GFX->setShaderConstBuffer (NULL); GFX->popActiveRenderTarget(); myTarg->clearAttachments (); // Sanity for(S32 i=0; i<GFX->getNumSamplers(); i++) GFX->setTexture(i, NULL); // Restore old proj matrix and cleanup. GFX->disableShaders (); GFX->setViewport (vp); GFX->popWorldMatrix (); GFX->setProjectionMatrix (oldMat);
Everything works just fine if I never resize the window.
Thanks in advance.
#2
02/11/2009 (1:11 am)
Turns out everything works if I put it ingame and call it from a delegated render function instead of in the main loop. It isn't what I wanted to hear, but whatever. Can't get everything :)
Torque Owner Brian Richardson