1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenXRRemotingRenderWindow.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkOpenXRRemotingRenderWindow.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLFramebufferObject.h"
#include "vtkOpenXRManager.h"
#include "vtkOpenXRManagerD3DGraphics.h"
#include "vtkOpenXRManagerRemoteConnection.h"
#include "vtkTextureObject.h"
#include "vtkWin32OpenGLDXRenderWindow.h"
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkOpenXRRemotingRenderWindow);
//------------------------------------------------------------------------------
vtkOpenXRRemotingRenderWindow::vtkOpenXRRemotingRenderWindow()
{
// Flip the texture before presenting to D3D which using a different convention
// for texture orientation.
this->FramebufferFlipY = true;
if (this->HelperWindow) // Clear previous window allocated by vtkVRRenderWindow
{
this->HelperWindow->Delete();
}
// Use an OpenGL-DX render window to allow streaming VTK rendering in a D3D texture.
this->HelperWindow = vtkWin32OpenGLDXRenderWindow::New();
// Use a D3D rendering backend in OpenXR
vtkNew<vtkOpenXRManagerD3DGraphics> D3Dgraphics;
vtkOpenXRManager::GetInstance().SetGraphicsStrategy(D3Dgraphics);
// Use the OpenXR remoting connection strategy
vtkNew<vtkOpenXRManagerRemoteConnection> remoteConnection;
vtkOpenXRManager::GetInstance().SetConnectionStrategy(remoteConnection);
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::SetRemotingIPAddress(const char* host)
{
vtkOpenXRManager::GetInstance().GetConnectionStrategy()->SetIPAddress(host);
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::Initialize()
{
if (this->Initialized)
{
return;
}
this->Superclass::Initialize();
// Set the sample count to the value recommended by the runtime
uint32_t samples = vtkOpenXRManager::GetInstance().GetRecommendedSampleCount();
this->HelperWindow->SetMultiSamples(samples);
vtkOpenGLRenderWindow::CreateFramebuffers(this->Size[0], this->Size[1]);
vtkWin32OpenGLDXRenderWindow* helperWindow =
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow);
// Register this window display framebuffer with the helper window D3D texture.
// We use the display buffer to benefit from FramebufferFlipY.
helperWindow->RegisterSharedTexture(
this->GetDisplayFramebuffer()->GetColorAttachmentAsTextureObject(0)->GetHandle());
// Resize shared texture
this->HelperWindow->SetSize(this->Size[0], this->Size[1]);
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::CopyResultFrame()
{
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow)->Lock();
this->Superclass::CopyResultFrame();
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow)->Unlock();
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::StereoUpdate()
{
// Lock the shared texture for rendering
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow)->Lock();
this->Superclass::StereoUpdate();
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::StereoMidpoint()
{
this->RenderModels();
// Blit to DisplayFamebuffer with FramebufferFlipY enabled
this->Frame();
// RenderOneEye
this->Superclass::StereoMidpoint();
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::StereoRenderComplete()
{
this->RenderModels();
// Blit to DisplayFamebuffer with FramebufferFlipY enabled
this->Frame();
// RenderOneEye
this->Superclass::StereoRenderComplete();
// Unlock the shared texture
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow)->Unlock();
}
//------------------------------------------------------------------------------
void vtkOpenXRRemotingRenderWindow::RenderOneEye(uint32_t eye)
{
ID3D11Texture2D* colorTexture = nullptr;
ID3D11Texture2D* depthTexture = nullptr;
if (!vtkOpenXRManager::GetInstance().PrepareRendering(eye, &colorTexture, &depthTexture))
{
return;
}
// D3D11 Rendering
vtkWin32OpenGLDXRenderWindow* helperWindow =
vtkWin32OpenGLDXRenderWindow::SafeDownCast(this->HelperWindow);
helperWindow->Unlock();
helperWindow->BlitToTexture(colorTexture);
helperWindow->Lock();
// Release this swapchain image
vtkOpenXRManager::GetInstance().ReleaseSwapchainImage(eye);
}
VTK_ABI_NAMESPACE_END
|