Jump to content
  • Advertisement
Sign in to follow this  
gekon456

OpenGL OMSetRenderTargets has no effect

This topic is 1007 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

Hi,

 

I trying to implement post process effect in D3D11 (C++) in same way like in OpenGL.

In OpenGL I create frame buffer, bind it before rendering and after that I bind default 0 frame buffer and I render quad with binded previous frame buffer as texture.

 

So in D3D11 I created two render targets using snippet below

D3D11RenderTargetView** buffer;
ID3D11Texture2D *pBufferTexture;

Renderer->SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBufferTexture);
Renderer->Device->CreateRenderTargetView(pBufferTexture, NULL, buffer);

So I have two D3D11RenderTargetView pointers and I bind the first one using DeviceContext method OMSetRenderTargets before rendering stuff.

After rendering I bind the second one and I call SwapChain method Present(0, 0).

 

And I was thinking I will get black (or whatever color I cleared the second RTV) screen, but no. I see whole rendered scene - like it was still using first RTV.

 

I think I missed some concept here, so please can you point me to right direction?

 

Thank you!

Share this post


Link to post
Share on other sites
Advertisement

I don't see a second RenderTargetView. You're creating one that looks at the swap chain, but don't explain what the second one is viewing?

 

Bear in mind that when you create a RenderTargetView of the swap chain (Buffer 0) that this will automatically rotate to view whatever the next buffer in the swap chain will be, so you only need to create one RenderTargetView even if your swap chain has multiple buffers.

 

Have you enabled the Debug Layer to check your aren't getting any warnings or errors?

Share this post


Link to post
Share on other sites

For this you'll need a texture with both a render target view and a shader resource view - can you confirm that you have this?

 

Also, D3D11 is more stringent in it's usage requirements than OpenGL, particularly in that you cannot bind a render target if it is currently bound as a shader resource, and vice-versa.  So you need to either unbind it (by binding NULL to the same slot) or bind a different object before you can use it.

Share this post


Link to post
Share on other sites

@Adam Miles:

 

I creating two RTV, the snippet just show the process which is same for both RTV.

 

And is using two RTV for "post process" the right way? As I said, I trying to follow my implementation from OpenGL, where I have to use two frame buffers (#0 is default one, #1 is mine).

 

I have debug layer enabled and I dont see any errors.

Share this post


Link to post
Share on other sites

I don't see or understand the value in creating two render target views of the same texture. What are you trying to achieve?

 

Try creating just one render target view of the Swap Chain and use that everywhere.

Share this post


Link to post
Share on other sites

Ok, Im maybe little bit confused. sorry about that.

 

My point is to have two "frame buffers", into the first I will draw whole scene which I will use as texture for shader which will be draw into second one, and I like to use the second one as the main "frame buffer" which will be pushed to the screen.

 

Currently I creating two RTV, both of them has texture passed into method CreateRenderTargetView(&texture......); and I swap between them which I thought will do the trick.

 

My first goal is to achieve "black screen" = renderer into one "frame buffer", change it into second one and show it, which have to show black screen (clear color) right?

After that I will use texture for shader and I will draw quad and so on. But I cant get black screen.

 

But if I use just one RTV, how can I change underlying texture of this RTV?

Both textures ID3D11Texture2D I obtain using SwapChain method GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&targetTexture); where targetTexture is first and second texture (targetTexture is method argument). Or do I have to use Device method CreateTexture2D?

Edited by gekon456

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!