7#include <QtGui/QOpenGLContext>
8#include <QtQuick/QQuickWindow>
9#include <QtQuick/private/qquickrendertarget_p.h>
16#define GL_RGBA8 0x8058
19#ifndef GL_SRGB8_ALPHA8_EXT
20#define GL_SRGB8_ALPHA8_EXT 0x8C43
23#ifndef GL_DEPTH_COMPONENT16
24#define GL_DEPTH_COMPONENT16 0x81A5
27#ifndef GL_DEPTH_COMPONENT24
28#define GL_DEPTH_COMPONENT24 0x81A6
31#ifndef GL_DEPTH_COMPONENT32F
32#define GL_DEPTH_COMPONENT32F 0x8CAC
35#ifndef GL_DEPTH24_STENCIL8
36#define GL_DEPTH24_STENCIL8 0x88F0
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;
57 for (
const auto &
extension : extensions) {
58 if (!strcmp(XR_KHR_OPENGL_ENABLE_EXTENSION_NAME,
68 return XR_KHR_OPENGL_ENABLE_EXTENSION_NAME;
74 return reinterpret_cast<const XrBaseInStructure*
>(&m_graphicsBinding);
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?");
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 qDebug() <<
"Runtime does not support desired Graphics API and/or version";
106# ifdef XR_USE_PLATFORM_WIN32
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;
138 constexpr int64_t supportedDepthSwapchainFormats[] = {
145 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
146 std::end(supportedDepthSwapchainFormats),
147 swapchainFormats.begin(),
148 swapchainFormats.end());
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,
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;
186 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
193 if (depthSwapchainImage) {
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) {
218 m_depthTexture->
createFrom({ depthImage, 0 });
231 delete m_depthTexture;
232 m_depthTexture =
nullptr;
\inheaderfile QOpenGLContext
const char * extensionName() const override
const XrBaseInStructure * handle() const override
bool finializeGraphics(QRhi *rhi) override
bool isExtensionSupported(const QVector< XrExtensionProperties > &extensions) const override
int64_t colorSwapchainFormat(const QVector< int64_t > &swapchainFormats) const override
void releaseResources() override
bool setupGraphics(const XrInstance &instance, XrSystemId &systemId, const QQuickGraphicsConfiguration &quickConfig) override
QQuickRenderTarget renderTarget(const XrSwapchainSubImage &subImage, const XrSwapchainImageBaseHeader *swapchainImage, quint64 swapchainFormat, int samples, int arraySize, const XrSwapchainImageBaseHeader *depthSwapchainImage, quint64 depthSwapchainFormat) const override
void setupWindow(QQuickWindow *window) override
int64_t depthSwapchainFormat(const QVector< int64_t > &swapchainFormats) const override
QVector< XrSwapchainImageBaseHeader * > allocateSwapchainImages(int count, XrSwapchain swapchain) 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.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\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_SRGB8_ALPHA8_EXT
GLint GLsizei GLsizei GLenum format
#define GL_DEPTH_COMPONENT32F
#define GL_DEPTH24_STENCIL8
#define GL_DEPTH_COMPONENT16
#define GL_DEPTH_COMPONENT24
unsigned long long quint64