veldrid icon indicating copy to clipboard operation
veldrid copied to clipboard

Need to get to underlying ID3D11Texture2D pointer from a Veldrid texture... how?

Open mherbold opened this issue 3 years ago • 1 comments

I am trying to write a SteamVR (OpenVR) overlay app. OpenVR requires a handle to the D3D11 texture to use to render the overlay. I have a Veldrid texture that I set as render target (drawn on by ImGui) and the texture has the sampled flag on it as well. All that works. Now I need to pass the underlying D3D11 texture to OpenVR so it can display it on my HMD as an overlay... how do I get to that pointer?

Note I am using GraphicsBackend.Direct3D11 when calling VeldridStartup.CreateWindowAndGraphicsDevice.

In Unity I would just call texture.GetNativeTexturePtr(). What's the equivalent with Veldrid?

mherbold avatar Mar 29 '23 02:03 mherbold

Never mind - I figured this one out. The answer is -

BackendInfoD3D11 _backendInfo;

_graphicsDevice.GetD3D11Info( out var _backendInfo );

var texture_t = new Texture_t();

texture_t.handle = _backendInfo.GetTexturePointer( _texture ); texture_t.eType = ETextureType.DirectX; texture_t.eColorSpace = EColorSpace.Gamma;

OpenVR.Overlay.SetOverlayTexture( _overlayHandle, ref texture_t );

mherbold avatar Mar 29 '23 15:03 mherbold