7#include <QtGui/QOpenGLContext>
8#include <QtQuick/private/qquickrendertarget_p.h>
13#ifndef GL_DEPTH_COMPONENT32F
14#define GL_DEPTH_COMPONENT32F 0x8CAC
19#ifdef XR_USE_PLATFORM_ANDROID
20 m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR;
22 m_graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_ES_KHR;
28 for (
const auto &
extension : extensions) {
29 if (!strcmp(XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME,
39 return XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME;
45 return reinterpret_cast<const XrBaseInStructure*
>(&m_graphicsBinding);
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?");
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 qDebug() <<
"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[] = {
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,
142 const XrSwapchainImageBaseHeader *depthSwapchainImage,
143 quint64 depthSwapchainFormat)
const
145 const uint32_t colorTexture =
reinterpret_cast<const XrSwapchainImageOpenGLESKHR*
>(swapchainImage)->
image;
147 switch (swapchainFormat) {
155 QQuickRenderTarget::Flags
flags;
159 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
166 if (depthSwapchainImage) {
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) {
191 m_depthTexture->
createFrom({ depthImage, 0 });
199 delete m_depthTexture;
200 m_depthTexture =
nullptr;
QQuickRenderTarget renderTarget(const XrSwapchainSubImage &subImage, const XrSwapchainImageBaseHeader *swapchainImage, quint64 swapchainFormat, int samples, int arraySize, const XrSwapchainImageBaseHeader *depthSwapchainImage, quint64 depthSwapchainFormat) const override
const XrBaseInStructure * handle() const override
const char * extensionName() const override
void releaseResources() override
int64_t depthSwapchainFormat(const QVector< int64_t > &swapchainFormats) const override
QVector< XrSwapchainImageBaseHeader * > allocateSwapchainImages(int count, XrSwapchain swapchain) override
bool isExtensionSupported(const QVector< XrExtensionProperties > &extensions) const override
QOpenXRGraphicsOpenGLES()
bool finializeGraphics(QRhi *rhi) override
bool setupGraphics(const XrInstance &instance, XrSystemId &systemId, const QQuickGraphicsConfiguration &quickConfig) override
int64_t colorSwapchainFormat(const QVector< int64_t > &swapchainFormats) const override
QQuickGraphicsConfiguration controls lower level graphics settings for the QQuickWindow.
The QQuickRenderTarget class provides an opaque container for native graphics resources specifying a ...
void setDepthTexture(QRhiTexture *texture)
Requests using the given texture as the depth or depth-stencil buffer.
\variable QRhiGles2InitParams::format
Format
Specifies the texture format.
virtual bool createFrom(NativeTexture src)
Similar to create(), except that no new native textures are created.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
QRhiTexture * newTextureArray(QRhiTexture::Format format, int arraySize, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
const QRhiNativeHandles * nativeHandles()
bool checkXrResult(XrResult result, XrInstance instance)
Combined button and popup list for selecting options.
GLenum GLenum GLsizei count
#define GL_DEPTH_COMPONENT16_OES
#define GL_SRGB8_ALPHA8_EXT
#define GL_DEPTH24_STENCIL8_OES
#define GL_DEPTH_COMPONENT24_OES
GLint GLsizei GLsizei GLenum format
#define GL_DEPTH_COMPONENT32F
unsigned long long quint64