Advertisement

Render to a texture

Started by January 10, 2016 07:45 PM
1 comment, last by myvraccount 8 years, 11 months ago

Using SharpDX/SlimDX in C# (or VB.NET if you prefer), how can I render onto a texture? I'm pretty sure where I render has to do with RenderTargetView, and if I get the RenderTargetView.Resource, I can convert it to a Texture2D.

That's great, but I have an uneasy feeling, because I still notice that my SwapChainDescription.OutputHandle may not be null, and it supposedly must point to some kind of window or other control on which I can draw. But why would I need that if I'm only rendering onto a texture, not a form?

Am I going about this the right way?

I believe the swapchain is only used when you commit the backbuffer's contents to your display device using the Present() method. If you are just rendering to a texture, then you just don't present, after drawing you can then retrieve the contents of your texture and do whatever you want with it.

I am pretty sure if you are only doing offscreen rendering (for instance some command line conversion tool) then you don't even need a swapchain at all.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

Oh, that makes more sense, thanks.

Although now when I retrieve the Texture2D, it seems to be valid, but then I tried to do something with it that I normally do (I don't remember the details off hand - I may have tried to set it as a resource or something), and it just threw an exception that said there was an incorrect parameter or something.

Under the same circumstances with other textures I haven't had that problem, which leads me to believe that although it gave me back a texture, something may somehow be wrong with it.

This topic is closed to new replies.

Advertisement