Skip to main content
GameDev.net gamedev.net
🔒 Locked

use rendertarget as texture? [solved]

Started by DarkZoulz Jun 21, 2007 at 6:34 AM 3 replies 8k views
Original Post
DarkZoulz
DarkZoulz

Direct3D9: (WARN) :Can not render to a render target that is also used as a texture. A render target was detected as bound, but couldn't detect if texture was actually used in rendering.


I get this from rendering to a texture that is set as rendertarget. And then attempting to use the rendertarget texture as a texture on a mesh. The thing is, the result appears as I want it. The rendertarget texture is applied to the mesh. [Edited by - DarkZoulz on June 21, 2007 8:33:31 AM]
supagu
supagu
dx10 or 9, how do you set up and bind your RT
DarkZoulz
DarkZoulz
I'm using DirectX9, and this is the code that setup the rendertarget texture.

	D3DXCreateTexture(m_device, 512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_modDecals);	m_modDecals->GetSurfaceLevel(0, &m_decalSurface);	m_device->GetRenderTarget(0, &m_backbuffer);


This is the code that renders to the texture.

	m_device->SetRenderTarget(0, m_decalSurface);	m_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);	m_device->BeginScene();	m_sprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);	// Draw decal sprites.	m_sprite->End();	m_device->EndScene();	m_device->SetRenderTarget(0, m_backbuffer);


After this, I pass the texture (m_modDecals) to my effect and run it through my vertex/pixel shader.
Adam_42
Adam_42
The warning is telling you that you have the render target set to draw from when you begin rendering to it. Having the same texture as both source and destination isn't valid so you get that warning. On the first frame the render to texture will work, it'll only cause that warning on the second and subsequent frames.

To fix it all you need to do is put something like the code below before you begin rendering to the target.

// Make sure the render target isn't still set as a source texturefor (int i=0; i< 16; i++) m_device->SetTexure(i, NULL);
DarkZoulz
DarkZoulz
Quote:
Original post by Adam_42
The warning is telling you that you have the render target set to draw from when you begin rendering to it. Having the same texture as both source and destination isn't valid so you get that warning. On the first frame the render to texture will work, it'll only cause that warning on the second and subsequent frames.

To fix it all you need to do is put something like the code below before you begin rendering to the target.

// Make sure the render target isn't still set as a source texturefor (int i=0; i< 16; i++) m_device->SetTexure(i, NULL);


I see. Thank you very much! :) Thanks for taking your time everyone!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.