Sign in to follow this  

unable to write into render target

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Folks, I am looking for sample code where one creates a a render-target, writes to it using HLSL shader and reads it back in C++. I would like to see how to read the values pixel by pixel, and not use teh whole texture. e.g. I have seen HDRCubeMap sample that comes with DX and they use the whole surface as a texture on one of the faces of cube-maps. I want to read the values in stored in texture. Here's how I am reading back from the render target.
IDirect3DSurface9 *dt = 0; 
	V( DXUTGetD3DDevice()->CreateOffscreenPlainSurface( REN_TARGET_SIZE, REN_TARGET_SIZE, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &dt, 0 ) ); 
	V( DXUTGetD3DDevice()->GetRenderTargetData( g_pSurf, dt ) ); 
	D3DLOCKED_RECT outRect;


	if (FAILED (dt->LockRect(&outRect,0,D3DLOCK_READONLY )))
		DXUTOutputDebugString( L"Failed to lock the render target dt\n");

	int iResult = ((int*)(outRect.pBits))[0] ;
	DXUTOutputDebugString( L"Output from shader = 0x%x \n",iResult);

	if (FAILED (dt->UnlockRect()))
		DXUTOutputDebugString( L"Failed to unlock the render target dt\n");

	SAFE_RELEASE(dt);
I do not see the output of shader. I see the Clear value that I am using before BeginScene. Any pointers? -Rahul EDIT: Using 'source' tags makes posts more readable... [Edited by - jollyjeffers on March 1, 2006 1:26:53 PM]

Share this post


Link to post
Share on other sites
A few thoughts...

You're only examining the first pixel in the texture - is that intentional? Are you sure it writes something to that particular location (have you checked other coordinates)?

Have you tried rendering the texture to the screen to see if you get anything that way?

Have you tried stepping through a call-stream capture with PIX and examined the state of the resources as it sees them?

Have you tried using the debug runtime - are you getting any warnings?

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by rpsathe
I tried that. Still no luck.
-Rahul

Please be more descriptive. If you've tried the things Jack mentioned, what were the results? Saying "it didn't work" doesn't help us much.

The first thing you need to do is verify that your render target has valid data in it. One way you can do this is to render the texture to the screen. Another way is to save the texture out to a .bmp file using D3DXSaveTextureToFile.

Once you've made sure the render target contains reasonable data, then you can worry about copying it to an offscreen surface so you can lock it.

Does the debug spew output any errors or interesting warnings? If you're doing something wrong, the debug spew will often tell you what the problem is.

PIX is also a good tool to figure out what's going on with your rendering.

neneboricua

Share this post


Link to post
Share on other sites
Sorry guys was out of town for a couple of days.

So I tried rendering to the render target (without switching to a new render target). I still see only the Clear values being written to my default render target. I don't see my HLSL's Pixel shader's output values in my renderTarget.

I'll try BMP thing next.

Thanks
-Rahul

Share this post


Link to post
Share on other sites
Alright folks,
Figured out what the problem was. In HLSL Pixel shader I was returning a color value as float4 (a,b,c,d). Instead, I should've initialized the structure Color.r = a, Color.g = b etc.

Thanks for your help anyways. Learnt a few debugging tricks.
-Rahul

Share this post


Link to post
Share on other sites

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this