52 PFN_xrGetOpenGLESGraphicsRequirementsKHR pfnGetOpenGLESGraphicsRequirementsKHR =
nullptr;
54 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetOpenGLESGraphicsRequirementsKHR)),
57 if (!pfnGetOpenGLESGraphicsRequirementsKHR) {
58 qWarning(
"Could not resolve xrGetOpenGLESGraphicsRequirementsKHR; perhaps the OpenXR implementation does not support OpenGL ES?");
61 OpenXRHelpers::checkXrResult(pfnGetOpenGLESGraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
68 const QRhiGles2NativeHandles *openglRhi =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
70 auto context = openglRhi->context;
71 const XrVersion desiredApiVersion = XR_MAKE_VERSION(context->format().majorVersion(), context->format().minorVersion(), 0);
72 if (m_graphicsRequirements.minApiVersionSupported > desiredApiVersion) {
73 qWarning(
"Qt Quick 3D XR (Open GL ES): Runtime does not support desired graphics API and/or version");
77#ifdef XR_USE_PLATFORM_ANDROID
78 auto nativeContext = context->nativeInterface<QNativeInterface::QEGLContext>();
80 m_graphicsBinding.display = nativeContext->display();
81 m_graphicsBinding.config = nativeContext->config();
82 m_graphicsBinding.context = nativeContext->nativeContext();
95 constexpr int64_t supportedColorSwapchainFormats[] = {
100 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
101 std::end(supportedColorSwapchainFormats),
102 swapchainFormats.begin(),
103 swapchainFormats.end());
104 return *swapchainFormatIt;
110 constexpr int64_t supportedDepthSwapchainFormats[] = {
111 GL_DEPTH24_STENCIL8_OES,
113 GL_DEPTH_COMPONENT24_OES,
114 GL_DEPTH_COMPONENT16_OES
117 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
118 std::end(supportedDepthSwapchainFormats),
119 swapchainFormats.begin(),
120 swapchainFormats.end());
126 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
127 QVector<XrSwapchainImageOpenGLESKHR> swapchainImageBuffer(count);
128 for (XrSwapchainImageOpenGLESKHR& image : swapchainImageBuffer) {
129 image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
130 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
132 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
133 return swapchainImages;
138 const XrSwapchainImageBaseHeader *swapchainImage,
139 quint64 swapchainFormat,
142 const XrSwapchainImageBaseHeader *depthSwapchainImage,
143 quint64 depthSwapchainFormat)
const
145 const uint32_t colorTexture =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(swapchainImage)->image;
147 switch (swapchainFormat) {
148 case GL_SRGB8_ALPHA8_EXT:
149 swapchainFormat = GL_RGBA8_OES;
155 QQuickRenderTarget::Flags flags;
157 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
159 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
160 QQuickRenderTarget rt = QQuickRenderTarget::fromOpenGLTexture(colorTexture,
166 if (depthSwapchainImage) {
167 QRhiTexture::Format format = QRhiTexture::D24S8;
168 switch (depthSwapchainFormat) {
170 format = QRhiTexture::D32F;
172 case GL_DEPTH_COMPONENT24_OES:
173 format = QRhiTexture::D24;
175 case GL_DEPTH_COMPONENT16_OES:
176 format = QRhiTexture::D16;
179 GLuint depthImage =
reinterpret_cast<
const XrSwapchainImageOpenGLESKHR*>(depthSwapchainImage)->image;
180 if (m_depthTexture && (m_depthTexture->format() != format || m_depthTexture->pixelSize() != pixelSize || m_depthTexture->arraySize() != arraySize)) {
181 delete m_depthTexture;
182 m_depthTexture =
nullptr;
184 if (!m_depthTexture) {
187 m_depthTexture = m_rhi->newTextureArray(format, arraySize, pixelSize, 1, QRhiTexture::RenderTarget);
189 m_depthTexture = m_rhi->newTexture(format, pixelSize, 1, QRhiTexture::RenderTarget);
191 m_depthTexture->createFrom({ depthImage, 0 });
192 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