Game Development Community

Downsampling a Render Target Texture

by Lorne McIntosh · in Torque Game Engine Advanced · 12/17/2008 (2:30 pm) · 2 replies

Moved from here:
www.garagegames.com/mg/forums/result.thread.php?qt=81681


Hey everyone,

I'm trying to downsample (resize) a render target texture in TGEA 1.7.1. I have a couple questions:

1) It doesn't seem like stretchRect is exposed in the GFX API. Is this true? If it was available, would this be the fastest approach (performance-wise)?

2) I'm currently trying to do another pass, drawing the texture on a fullscreen quad to another (smaller) render target. However, it seems silly to write a shader for just drawing a texture on a quad, and I believe this is where the fixed-function pipeline should help me. I've tried the following calls, but my new render target remains blank (checking in PIX)... surely I'm missing something:

GFX->setCullMode(GFXCullNone);
GFX->setLightingEnable(false);
GFX->setAlphaBlendEnable(false);
GFX->setZEnable(false);
GFX->setZWriteEnable(false);

GFX->setTexture(0, *mColorTexHandle);
GFX->setTextureStageAddressModeU(0, GFXAddressClamp);
GFX->setTextureStageAddressModeV(0, GFXAddressClamp);
GFX->setTextureStageMinFilter(0, GFXTextureFilterLinear);
GFX->setTextureStageMagFilter(0, GFXTextureFilterLinear);

//use fixed-function pipeline:
GFX->disableShaders();
GFX->setTextureStageColorOp( 0, GFXTOPSelectARG1 );
GFX->setTextureStageColorArg1( 0, GFXTATexture );
GFX->setSrcBlend(GFXBlendOne);
GFX->setDestBlend(GFXBlendZero);

//draw the quad
GFX->setVertexBuffer( mVertBuff );
GFX->drawPrimitive( GFXTriangleFan, 0, 2 );


I welcome any ideas...

Thanks,
Lorne


Tom Spilman replied:
Quote:
First off you should move this discussion to the private forums... we're not supposed to post a bunch of engine code out here.

Writing a shader to do the downsample isn't that crazy of an idea as often you want some specialized filtering.

Still if you do a little digging in the code you'll find a few places that use StretchRect...

GFXD3D9TextureObject::readBackBuffer()
GFXD3D9TextureTarget::deactivate()
GFXPCD3D9Device::copyBBToSfxBuff()

It seems that readBackBuffer() was originally intended to do downsampling, but it was never finished... i would start there.

About the author

Ubiq Visuals is a software and creative content developer for the entertainment industry. Our vision is to provide inspiration and the tools for soon-to-be game designers and creative minds of all ages.


#1
12/17/2008 (10:55 pm)
Haha, well I discovered why the fixed-function pipeline wasn't working. I made a method to fill the vertex buffer with a full-screen quad. However I wasn't calling it! So it was just drawing garbage from memory... duh.

Thanks
#2
12/17/2008 (10:59 pm)
Heh... that will do it.