From df0cb0edac85db1fe12442d332bafc1d508bc3ae Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 13 Nov 2019 16:35:11 +0100 Subject: Fix Metal usage on iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also enable the two Metal-specific scenegraph examples on iOS. Change-Id: I0e1e6d527544ea4a5bfb0d08ca2d32c762d3c699 Reviewed-by: Andy Nichols Reviewed-by: Tor Arne Vestbø --- .../quick/scenegraph/metaltextureimport/metaltextureimport.pro | 5 +++-- examples/quick/scenegraph/metalunderqml/metalsquircle.mm | 5 ++++- examples/quick/scenegraph/metalunderqml/metalunderqml.pro | 5 +++-- examples/quick/scenegraph/scenegraph.pro | 2 +- src/quick/scenegraph/qsgrhisupport.cpp | 8 ++++---- src/quick/scenegraph/qsgrhisupport_p.h | 2 +- src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp | 4 ++-- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro index 5b11606946..bbdfd358d3 100644 --- a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro +++ b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro @@ -1,4 +1,4 @@ -!macos: error("This example requires macOS") +!macos:!ios: error("This example requires macOS or iOS") QT += qml quick @@ -6,7 +6,8 @@ HEADERS += metaltextureimport.h SOURCES += metaltextureimport.mm main.cpp RESOURCES += metaltextureimport.qrc -LIBS += -framework Metal -framework AppKit +LIBS += -framework Metal +macos: LIBS += -framework AppKit target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metaltextureimport INSTALLS += target diff --git a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm index 5ca6daa01a..4844df0c70 100644 --- a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm +++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm @@ -349,10 +349,13 @@ void SquircleRenderer::init(int framesInFlight) rpDesc.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne; rpDesc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne; +#ifdef Q_OS_MACOS if (m_device.depth24Stencil8PixelFormatSupported) { rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8; rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8; - } else { + } else +#endif + { rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8; rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8; } diff --git a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro index 9fd131fe1b..2f4c3f63da 100644 --- a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro +++ b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro @@ -1,4 +1,4 @@ -!macos: error("This example requires macOS") +!macos:!ios: error("This example requires macOS or iOS") QT += qml quick @@ -6,7 +6,8 @@ HEADERS += metalsquircle.h SOURCES += metalsquircle.mm main.cpp RESOURCES += metalunderqml.qrc -LIBS += -framework Metal -framework AppKit +LIBS += -framework Metal +macos: LIBS += -framework AppKit target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metalunderqml INSTALLS += target diff --git a/examples/quick/scenegraph/scenegraph.pro b/examples/quick/scenegraph/scenegraph.pro index 5fea3b974a..cc75cbc0d3 100644 --- a/examples/quick/scenegraph/scenegraph.pro +++ b/examples/quick/scenegraph/scenegraph.pro @@ -16,7 +16,7 @@ SUBDIRS += \ rendernode \ threadedanimation -macos { +macos|ios { SUBDIRS += \ metalunderqml \ metaltextureimport diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 34325a35f3..38c2ef9612 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -159,7 +159,7 @@ void QSGRhiSupport::applySettings() } else { #if defined(Q_OS_WIN) m_rhiBackend = QRhi::D3D11; -#elif defined(Q_OS_DARWIN) +#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) m_rhiBackend = QRhi::Metal; #else m_rhiBackend = QRhi::OpenGLES2; @@ -350,7 +350,7 @@ static const void *qsgrhi_d3d11_rifResource(QSGRendererInterface::Resource res, } #endif -#ifdef Q_OS_DARWIN +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) static const void *qsgrhi_mtl_rifResource(QSGRendererInterface::Resource res, const QRhiNativeHandles *nat, const QRhiNativeHandles *cbNat) { @@ -408,7 +408,7 @@ const void *QSGRhiSupport::rifResource(QSGRendererInterface::Resource res, const case QRhi::D3D11: return qsgrhi_d3d11_rifResource(res, nat); #endif -#ifdef Q_OS_DARWIN +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) case QRhi::Metal: { QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer(); @@ -507,7 +507,7 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf rhi = QRhi::create(backend, &rhiParams, flags); } #endif -#ifdef Q_OS_DARWIN +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) if (backend == QRhi::Metal) { QRhiMetalInitParams rhiParams; rhi = QRhi::create(backend, &rhiParams, flags); diff --git a/src/quick/scenegraph/qsgrhisupport_p.h b/src/quick/scenegraph/qsgrhisupport_p.h index d008ecd0af..11693051d4 100644 --- a/src/quick/scenegraph/qsgrhisupport_p.h +++ b/src/quick/scenegraph/qsgrhisupport_p.h @@ -70,7 +70,7 @@ #include #endif -#ifdef Q_OS_DARWIN +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) #include #endif diff --git a/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp b/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp index 7a7c19f587..85a88326ca 100644 --- a/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp +++ b/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp @@ -48,7 +48,7 @@ void QSGRhiNativeTextureImporter::buildWrapper(QRhi *rhi, QRhiTexture *t, #if !QT_CONFIG(vulkan) Q_UNUSED(nativeLayout); #endif -#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) && !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) && !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) && !defined(Q_OS_IOS) Q_UNUSED(nativeObjectPtr); #endif @@ -83,7 +83,7 @@ void QSGRhiNativeTextureImporter::buildWrapper(QRhi *rhi, QRhiTexture *t, break; case QRhi::Metal: { -#ifdef Q_OS_DARWIN +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) QRhiMetalTextureNativeHandles h; h.texture = *reinterpret_cast(nativeObjectPtr); t->buildFrom(&h); -- cgit v1.2.3