39QOpenXRGraphicsOpenGL::QOpenXRGraphicsOpenGL()
41#ifdef XR_USE_PLATFORM_WIN32
42 m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
43#elif defined(XR_USE_PLATFORM_XLIB)
44 m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
45#elif defined(XR_USE_PLATFORM_XCB)
46 m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR;
47#elif defined(XR_USE_PLATFORM_WAYLAND)
48 m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR;
51 m_graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR;
81 PFN_xrGetOpenGLGraphicsRequirementsKHR pfnGetOpenGLGraphicsRequirementsKHR =
nullptr;
83 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetOpenGLGraphicsRequirementsKHR)),
85 if (!pfnGetOpenGLGraphicsRequirementsKHR) {
86 qWarning(
"Could not resolve xrGetOpenGLGraphicsRequirementsKHR; perhaps the OpenXR implementation does not support OpenGL?");
89 OpenXRHelpers::checkXrResult(pfnGetOpenGLGraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
96 const QRhiGles2NativeHandles *openglRhi =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
98 auto context = openglRhi->context;
100 const XrVersion desiredApiVersion = XR_MAKE_VERSION(context->format().majorVersion(), context->format().minorVersion(), 0);
101 if (m_graphicsRequirements.minApiVersionSupported > desiredApiVersion) {
102 qWarning(
"Qt Quick 3D XR (OpenGL): Runtime does not support desired graphics API and/or version");
106# ifdef XR_USE_PLATFORM_WIN32
107 auto nativeContext = context->nativeInterface<QNativeInterface::QWGLContext>();
109 m_graphicsBinding.hGLRC = nativeContext->nativeContext();
110 m_graphicsBinding.hDC = GetDC(
reinterpret_cast<HWND>(m_window->winId()));
123 constexpr int64_t supportedColorSwapchainFormats[] = {
128 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
129 std::end(supportedColorSwapchainFormats),
130 swapchainFormats.begin(),
131 swapchainFormats.end());
132 return *swapchainFormatIt;
153 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
154 QVector<XrSwapchainImageOpenGLKHR> swapchainImageBuffer(count);
155 for (XrSwapchainImageOpenGLKHR& image : swapchainImageBuffer) {
156 image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR;
157 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
159 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
160 return swapchainImages;
165 const XrSwapchainImageBaseHeader *swapchainImage,
166 quint64 swapchainFormat,
169 const XrSwapchainImageBaseHeader *depthSwapchainImage,
170 quint64 depthSwapchainFormat)
const
172 const uint32_t colorTexture =
reinterpret_cast<
const XrSwapchainImageOpenGLKHR*>(swapchainImage)->image;
174 switch (swapchainFormat) {
182 QQuickRenderTarget::Flags flags;
184 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
186 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
187 QQuickRenderTarget rt = QQuickRenderTarget::fromOpenGLTexture(colorTexture,
193 if (depthSwapchainImage) {
194 QRhiTexture::Format format = QRhiTexture::D24S8;
195 switch (depthSwapchainFormat) {
197 format = QRhiTexture::D32F;
200 format = QRhiTexture::D24;
203 format = QRhiTexture::D16;
206 GLuint depthImage =
reinterpret_cast<
const XrSwapchainImageOpenGLKHR*>(depthSwapchainImage)->image;
207 if (m_depthTexture && (m_depthTexture->format() != format || m_depthTexture->pixelSize() != pixelSize || m_depthTexture->arraySize() != arraySize)) {
208 delete m_depthTexture;
209 m_depthTexture =
nullptr;
211 if (!m_depthTexture) {
214 m_depthTexture = m_rhi->newTextureArray(format, arraySize, pixelSize, 1, QRhiTexture::RenderTarget);
216 m_depthTexture = m_rhi->newTexture(format, pixelSize, 1, QRhiTexture::RenderTarget);
218 m_depthTexture->createFrom({ depthImage, 0 });
219 rt.setDepthTexture(m_depthTexture);
QQuickRenderTarget renderTarget(const XrSwapchainSubImage &subImage, const XrSwapchainImageBaseHeader *swapchainImage, quint64 swapchainFormat, int samples, int arraySize, const XrSwapchainImageBaseHeader *depthSwapchainImage, quint64 depthSwapchainFormat) const override