Created
May 2, 2022 02:57
-
-
Save fredemmott/ad6a6c40a49cd090706e648cbaaf659d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/injectables/OculusD3D11Kneeboard.cpp b/src/injectables/OculusD3D11Kneeboard.cpp | |
| index 91102f0..a95a1eb 100644 | |
| --- a/src/injectables/OculusD3D11Kneeboard.cpp | |
| +++ b/src/injectables/OculusD3D11Kneeboard.cpp | |
| @@ -19,6 +19,7 @@ | |
| */ | |
| #include "OculusD3D11Kneeboard.h" | |
| +#include <DIrectXTK/SpriteBatch.h> | |
| #include <OVR_CAPI_D3D.h> | |
| #include <OpenKneeboard/config.h> | |
| #include <OpenKneeboard/dprint.h> | |
| @@ -129,20 +130,28 @@ bool OculusD3D11Kneeboard::Render( | |
| ovr->ovr_GetTextureSwapChainBufferDX( | |
| session, swapChain, index, IID_PPV_ARGS(&texture)); | |
| + winrt::com_ptr<ID3D11RenderTargetView> rtv; | |
| + mD3D->CreateRenderTargetView(texture.get(), nullptr, rtv.put()); | |
| + auto rtvp = rtv.get(); | |
| + | |
| winrt::com_ptr<ID3D11DeviceContext> context; | |
| mD3D->GetImmediateContext(context.put()); | |
| - D3D11_BOX sourceBox { | |
| - .left = 0, | |
| - .top = 0, | |
| - .front = 0, | |
| - .right = config.imageWidth, | |
| - .bottom = config.imageHeight, | |
| - .back = 1, | |
| + context->ClearRenderTargetView(rtvp, DirectX::Colors::Transparent); | |
| + context->OMSetRenderTargets(1, &rtvp, nullptr); | |
| + DirectX::SpriteBatch spriteBatch(context.get()); | |
| + const RECT usedRect { | |
| + 0, | |
| + 0, | |
| + config.imageWidth, | |
| + config.imageHeight, | |
| }; | |
| - | |
| - context->CopySubresourceRegion( | |
| - texture.get(), 0, 0, 0, 0, sharedTexture.GetTexture(), 0, &sourceBox); | |
| - context->Flush(); | |
| + spriteBatch.Begin(); | |
| + spriteBatch.Draw( | |
| + sharedTexture.GetShaderResourceView(), | |
| + usedRect, | |
| + &usedRect, | |
| + DirectX::Colors::White * 0.5f); | |
| + spriteBatch.End(); | |
| auto error = ovr->ovr_CommitTextureSwapChain(session, swapChain); | |
| if (error) { | |
| diff --git a/src/lib/SHM.cpp b/src/lib/SHM.cpp | |
| index 54cfc26..2e40415 100644 | |
| --- a/src/lib/SHM.cpp | |
| +++ b/src/lib/SHM.cpp | |
| @@ -198,6 +198,16 @@ IDXGISurface* SharedTexture::GetSurface() const { | |
| return mTexture.as<IDXGISurface>().get(); | |
| } | |
| +ID3D11ShaderResourceView* SharedTexture::GetShaderResourceView() const { | |
| + winrt::com_ptr<ID3D11Device> device; | |
| + mTexture->GetDevice(device.put()); | |
| + device->CreateShaderResourceView( | |
| + mTexture.get(), | |
| + nullptr, | |
| + const_cast<SharedTexture*>(this)->mShaderResourceView.put()); | |
| + return mShaderResourceView.get(); | |
| +} | |
| + | |
| Snapshot::Snapshot() { | |
| } | |
| diff --git a/src/lib/include/OpenKneeboard/SHM.h b/src/lib/include/OpenKneeboard/SHM.h | |
| index da5f47e..d1ae7e9 100644 | |
| --- a/src/lib/include/OpenKneeboard/SHM.h | |
| +++ b/src/lib/include/OpenKneeboard/SHM.h | |
| @@ -86,6 +86,7 @@ class SharedTexture final { | |
| operator bool() const; | |
| ID3D11Texture2D* GetTexture() const; | |
| IDXGISurface* GetSurface() const; | |
| + ID3D11ShaderResourceView* GetShaderResourceView() const; | |
| SharedTexture(const SharedTexture&) = delete; | |
| SharedTexture(SharedTexture&&) = delete; | |
| @@ -93,6 +94,7 @@ class SharedTexture final { | |
| private: | |
| UINT mKey = 0; | |
| winrt::com_ptr<ID3D11Texture2D> mTexture; | |
| + winrt::com_ptr<ID3D11ShaderResourceView> mShaderResourceView; | |
| }; | |
| class Snapshot final { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment