47 PFN_xrGetOpenGLESGraphicsRequirementsKHR pfnGetOpenGLESGraphicsRequirementsKHR =
nullptr;
48 OpenXRHelpers::checkXrResult(xrGetInstanceProcAddr(instance,
"xrGetOpenGLESGraphicsRequirementsKHR",
49 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetOpenGLESGraphicsRequirementsKHR)),
52 if (!pfnGetOpenGLESGraphicsRequirementsKHR) {
53 qWarning(
"Could not resolve xrGetOpenGLESGraphicsRequirementsKHR; perhaps the OpenXR implementation does not support OpenGL ES?");
56 OpenXRHelpers::checkXrResult(pfnGetOpenGLESGraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
63 const QRhiGles2NativeHandles *openglRhi =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
65 auto context = openglRhi->context;
66 const XrVersion desiredApiVersion = XR_MAKE_VERSION(context->format().majorVersion(), context->format().minorVersion(), 0);
67 if (m_graphicsRequirements.minApiVersionSupported > desiredApiVersion) {
68 qWarning(
"Qt Quick 3D XR (Open GL ES): Runtime does not support desired graphics API and/or version");
72#ifdef XR_USE_PLATFORM_ANDROID
73 auto nativeContext = context->nativeInterface<QNativeInterface::QEGLContext>();
75 m_graphicsBinding.display = nativeContext->display();
76 m_graphicsBinding.config = nativeContext->config();
77 m_graphicsBinding.context = nativeContext->nativeContext();
90 constexpr int64_t supportedColorSwapchainFormats[] = {
95 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
96 std::end(supportedColorSwapchainFormats),
97 swapchainFormats.begin(),
98 swapchainFormats.end());
99 return *swapchainFormatIt;
105 constexpr int64_t supportedDepthSwapchainFormats[] = {
106 GL_DEPTH24_STENCIL8_OES,
108 GL_DEPTH_COMPONENT24_OES,
109 GL_DEPTH_COMPONENT16_OES
112 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
113 std::end(supportedDepthSwapchainFormats),
114 swapchainFormats.begin(),
115 swapchainFormats.end());
121 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
122 QVector<XrSwapchainImageOpenGLESKHR> swapchainImageBuffer(count);
123 for (XrSwapchainImageOpenGLESKHR& image : swapchainImageBuffer) {
124 image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
125 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
127 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
128 return swapchainImages;
133 const XrSwapchainImageBaseHeader *swapchainImage,
134 quint64 swapchainFormat,
137 const XrSwapchainImageBaseHeader *depthSwapchainImage,
138 quint64 depthSwapchainFormat)
const
140 const uint32_t colorTexture =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(swapchainImage)->image;
142 switch (swapchainFormat) {
143 case GL_SRGB8_ALPHA8_EXT:
144 swapchainFormat = GL_RGBA8_OES;
150 QQuickRenderTarget::Flags flags;
152 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
154 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
155 QQuickRenderTarget rt = QQuickRenderTarget::fromOpenGLTexture(colorTexture,
161 if (depthSwapchainImage) {
162 QRhiTexture::Format format = QRhiTexture::D24S8;
163 switch (depthSwapchainFormat) {
165 format = QRhiTexture::D32F;
167 case GL_DEPTH_COMPONENT24_OES:
168 format = QRhiTexture::D24;
170 case GL_DEPTH_COMPONENT16_OES:
171 format = QRhiTexture::D16;
174 GLuint depthImage =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(depthSwapchainImage)->image;
175 if (m_depthTexture && (m_depthTexture->format() != format || m_depthTexture->pixelSize() != pixelSize || m_depthTexture->arraySize() != arraySize)) {
176 delete m_depthTexture;
177 m_depthTexture =
nullptr;
179 if (!m_depthTexture) {
182 m_depthTexture = m_rhi->newTextureArray(format, arraySize, pixelSize, 1, QRhiTexture::RenderTarget);
184 m_depthTexture = m_rhi->newTexture(format, pixelSize, 1, QRhiTexture::RenderTarget);
186 m_depthTexture->createFrom({ depthImage, 0 });
187 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