45 PFN_xrGetOpenGLESGraphicsRequirementsKHR pfnGetOpenGLESGraphicsRequirementsKHR =
nullptr;
47 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetOpenGLESGraphicsRequirementsKHR)),
50 if (!pfnGetOpenGLESGraphicsRequirementsKHR) {
51 qWarning(
"Could not resolve xrGetOpenGLESGraphicsRequirementsKHR; perhaps the OpenXR implementation does not support OpenGL ES?");
54 OpenXRHelpers::checkXrResult(pfnGetOpenGLESGraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
61 const QRhiGles2NativeHandles *openglRhi =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
63 auto context = openglRhi->context;
64 const XrVersion desiredApiVersion = XR_MAKE_VERSION(context->format().majorVersion(), context->format().minorVersion(), 0);
65 if (m_graphicsRequirements.minApiVersionSupported > desiredApiVersion) {
66 qWarning(
"Qt Quick 3D XR (Open GL ES): Runtime does not support desired graphics API and/or version");
70#ifdef XR_USE_PLATFORM_ANDROID
71 auto nativeContext = context->nativeInterface<QNativeInterface::QEGLContext>();
73 m_graphicsBinding.display = nativeContext->display();
74 m_graphicsBinding.config = nativeContext->config();
75 m_graphicsBinding.context = nativeContext->nativeContext();
88 constexpr int64_t supportedColorSwapchainFormats[] = {
93 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
94 std::end(supportedColorSwapchainFormats),
95 swapchainFormats.begin(),
96 swapchainFormats.end());
97 return *swapchainFormatIt;
103 constexpr int64_t supportedDepthSwapchainFormats[] = {
104 GL_DEPTH24_STENCIL8_OES,
106 GL_DEPTH_COMPONENT24_OES,
107 GL_DEPTH_COMPONENT16_OES
110 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
111 std::end(supportedDepthSwapchainFormats),
112 swapchainFormats.begin(),
113 swapchainFormats.end());
119 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
120 QVector<XrSwapchainImageOpenGLESKHR> swapchainImageBuffer(count);
121 for (XrSwapchainImageOpenGLESKHR& image : swapchainImageBuffer) {
122 image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
123 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
125 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
126 return swapchainImages;
131 const XrSwapchainImageBaseHeader *swapchainImage,
132 quint64 swapchainFormat,
135 const XrSwapchainImageBaseHeader *depthSwapchainImage,
136 quint64 depthSwapchainFormat)
const
138 const uint32_t colorTexture =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(swapchainImage)->image;
140 switch (swapchainFormat) {
141 case GL_SRGB8_ALPHA8_EXT:
142 swapchainFormat = GL_RGBA8_OES;
148 QQuickRenderTarget::Flags flags;
150 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
152 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
153 QQuickRenderTarget rt = QQuickRenderTarget::fromOpenGLTexture(colorTexture,
159 if (depthSwapchainImage) {
160 QRhiTexture::Format format = QRhiTexture::D24S8;
161 switch (depthSwapchainFormat) {
163 format = QRhiTexture::D32F;
165 case GL_DEPTH_COMPONENT24_OES:
166 format = QRhiTexture::D24;
168 case GL_DEPTH_COMPONENT16_OES:
169 format = QRhiTexture::D16;
172 GLuint depthImage =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(depthSwapchainImage)->image;
173 if (m_depthTexture && (m_depthTexture->format() != format || m_depthTexture->pixelSize() != pixelSize || m_depthTexture->arraySize() != arraySize)) {
174 delete m_depthTexture;
175 m_depthTexture =
nullptr;
177 if (!m_depthTexture) {
180 m_depthTexture = m_rhi->newTextureArray(format, arraySize, pixelSize, 1, QRhiTexture::RenderTarget);
182 m_depthTexture = m_rhi->newTexture(format, pixelSize, 1, QRhiTexture::RenderTarget);
184 m_depthTexture->createFrom({ depthImage, 0 });
185 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