Charlie
Charlie

Reputation: 653

Is it possible to draw using opengl on a directx dc/buffer?

This is probably a stupid question, but I cant find good examples on how to approach this, or if its even possible. Im just done with a project where I used gdi to biblt stuff onto a DIB-buffer then swap that onto the screen hdc, basically making my own swapchain and drawing with opengl.

So then I thought, can I do the same thing using directx11? But I cant seem to find where the DIB/buffer I need to change even is.

Am I even thinking about this correctly? Any ideas on how to handle this?

Upvotes: 2

Views: 1136

Answers (2)

Ani
Ani

Reputation: 10896

Yes, you can. Nvidia exposes vendor-specific extensions called NV_DX_interop and NV_DX_Interop2. With these extensions, you can directly access a DirectX surface (when it resides on the GPU) and render to it from an OpenGL context. There should be minimal (driver-only) overhead for this operation and the CPU will almost never be involved.

Note that while this is a vendor-specific extension, Intel GPUs support it as well.

However, don't do this simply for the fun of it or if you control all the source code for your application. This kind of interop scenario is meant for cases where you have two legacy/complicated codebases and interop is a cheaper/better option than porting all the logic to the other API.

Upvotes: 2

Blindy
Blindy

Reputation: 67380

Yeah you can do it, both OpenGL and D3D support both writeable textures and locking them to get to the pixel data.

Simply render your scene in OpenGL to a texture, lock it, read the pixel data and pass it directly to the D3D locked texture pixel data, unlock it then do whatever you want with the texture.

Performance would be dreadful of course, you're stalling the GPU multiple times in a single "operation" and forcing it to synchronize with the CPU (who's passing the data) and the bus (for memory access). Plus there would be absolutely no benefit at all. But if you really want to try it, you can do it.

Upvotes: 0

Related Questions