diff --git a/playground/parrots/Overlay.cpp b/playground/parrots/Overlay.cpp index e2e7946c..5dc0ef44 100644 --- a/playground/parrots/Overlay.cpp +++ b/playground/parrots/Overlay.cpp @@ -34,14 +34,15 @@ namespace class FilterNode : public TextureFilterNode { public: - FilterNode( QSGTexture* texture ) + FilterNode( bool useRhi, QSGTexture* texture ) { QString shaders[] = { ":/shaders/blur.vert", ":/shaders/blur.frag" }; -#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) - shaders[0] += ".qsb"; - shaders[1] += ".qsb"; -#endif + if ( useRhi ) + { + shaders[0] += ".qsb"; + shaders[1] += ".qsb"; + } setFlag( QSGNode::OwnsMaterial, true ); setTextureMaterial( new Material( shaders[0], shaders[1] ) ); @@ -150,7 +151,9 @@ namespace QObject::connect( texture, &QskSceneTexture::updateRequested, overlay, &QQuickItem::update ); - textureNode = new FilterNode( texture ); + const bool useRhi = qskRenderingHardwareInterface( window ); + + textureNode = new FilterNode( useRhi, texture ); texture->setTextureNode( textureNode ); } diff --git a/playground/parrots/TextureFilterMaterial.cpp b/playground/parrots/TextureFilterMaterial.cpp index dccc1905..57c240b0 100644 --- a/playground/parrots/TextureFilterMaterial.cpp +++ b/playground/parrots/TextureFilterMaterial.cpp @@ -9,6 +9,12 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + #include + using RhiShader = QSGMaterialRhiShader; +#else + using RhiShader = QSGMaterialShader; +#endif #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) @@ -74,31 +80,26 @@ namespace }; } -QSGMaterialShader* TextureFilterMaterial::createShader() const -{ - Q_ASSERT( !( flags() & QSGMaterial::RhiShaderWanted ) ); - - auto shader = new ShaderGL(); - - shader->setSource( QOpenGLShader::Vertex, m_shaderSourceFiles[ 0 ] ); - shader->setSource( QOpenGLShader::Fragment, m_shaderSourceFiles[ 1 ] ); - - return shader; -} - -#else // Qt6 +#endif namespace { - class Shader : public QSGMaterialShader + class ShaderRhi : public RhiShader { public: - Shader() + ShaderRhi() { setFlag( UpdatesGraphicsPipelineState, true ); } - void setSource( QSGMaterialShader::Stage stage, const QString& filename ) +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + void setSource( QOpenGLShader::ShaderType type, const QString& fileName ) + { + setShaderSourceFile( type, fileName ); + } +#endif + + void setSource( Stage stage, const QString& filename ) { setShaderFileName( stage, filename ); } @@ -139,20 +140,50 @@ namespace auto mat = dynamic_cast< TextureFilterMaterial* >( newMaterial ); if ( auto txt = mat->texture() ) { +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + txt->updateRhiTexture( state.rhi(), state.resourceUpdateBatch() ); +#else txt->commitTextureOperations( state.rhi(), state.resourceUpdateBatch() ); +#endif *texture = txt; } } }; } +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + +QSGMaterialShader* TextureFilterMaterial::createShader() const +{ + if ( flags() & QSGMaterial::RhiShaderWanted ) + { + auto shader = new ShaderRhi(); + + shader->setSource( ShaderRhi::VertexStage, m_shaderFiles[ 0 ] ); + shader->setSource( ShaderRhi::FragmentStage, m_shaderFiles[ 1 ] ); + + return shader; + } + else + { + auto shader = new ShaderGL(); + + shader->setSource( QOpenGLShader::Vertex, m_shaderFiles[ 0 ] ); + shader->setSource( QOpenGLShader::Fragment, m_shaderFiles[ 1 ] ); + + return shader; + } +} + +#else + QSGMaterialShader* TextureFilterMaterial::createShader( QSGRendererInterface::RenderMode ) const { - auto shader = new Shader(); + auto shader = new ShaderRhi(); - shader->setSource( Shader::VertexStage, m_shaderSourceFiles[ 0 ] ); - shader->setSource( Shader::FragmentStage, m_shaderSourceFiles[ 1 ] ); + shader->setSource( ShaderRhi::VertexStage, m_shaderFiles[ 0 ] ); + shader->setSource( ShaderRhi::FragmentStage, m_shaderFiles[ 1 ] ); return shader; } @@ -160,11 +191,14 @@ QSGMaterialShader* TextureFilterMaterial::createShader( #endif TextureFilterMaterial::TextureFilterMaterial( - const QString& vertexShaderSourceFile, - const QString& fragmentShaderSourceFile ) - : m_shaderSourceFiles{ vertexShaderSourceFile, fragmentShaderSourceFile } + const QString& vertexShaderFile, const QString& fragmentShaderFile ) + : m_shaderFiles{ vertexShaderFile, fragmentShaderFile } { setFlag( Blending | RequiresFullMatrix, true ); + +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + setFlag( SupportsRhiShader, true ); +#endif } TextureFilterMaterial::~TextureFilterMaterial() diff --git a/playground/parrots/TextureFilterMaterial.h b/playground/parrots/TextureFilterMaterial.h index cf58950b..93a7c9b9 100644 --- a/playground/parrots/TextureFilterMaterial.h +++ b/playground/parrots/TextureFilterMaterial.h @@ -32,5 +32,5 @@ class TextureFilterMaterial : public QSGMaterial private: QSGTexture* m_texture = nullptr; - const QString m_shaderSourceFiles[ 2 ]; + const QString m_shaderFiles[ 2 ]; }; diff --git a/playground/parrots/shaders/blur.frag.qsb b/playground/parrots/shaders/blur.frag.qsb index 40d031bc..9d04e783 100644 Binary files a/playground/parrots/shaders/blur.frag.qsb and b/playground/parrots/shaders/blur.frag.qsb differ diff --git a/playground/parrots/shaders/blur.vert.qsb b/playground/parrots/shaders/blur.vert.qsb index f530ee4d..018f8b19 100644 Binary files a/playground/parrots/shaders/blur.vert.qsb and b/playground/parrots/shaders/blur.vert.qsb differ diff --git a/playground/parrots/shaders/rgbswap.frag.qsb b/playground/parrots/shaders/rgbswap.frag.qsb index 7ce873e7..fdf07283 100644 Binary files a/playground/parrots/shaders/rgbswap.frag.qsb and b/playground/parrots/shaders/rgbswap.frag.qsb differ diff --git a/src/nodes/QskSceneTexture.cpp b/src/nodes/QskSceneTexture.cpp index 58695720..c8fa4493 100644 --- a/src/nodes/QskSceneTexture.cpp +++ b/src/nodes/QskSceneTexture.cpp @@ -202,32 +202,31 @@ namespace void Renderer::createTarget( const QSize& size ) { -==== BASE ==== - const auto rhi = context()->rhi(); -==== BASE ==== + if ( const auto rhi = context()->rhi() ) + { + auto flags = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource; -==== BASE ==== - auto flags = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource; -==== BASE ==== + m_rhiTexture = rhi->newTexture( QRhiTexture::RGBA8, size, 1, flags ); +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + m_rhiTexture->build(); +#else + m_rhiTexture->create(); +#endif -==== BASE ==== - m_rhiTexture = rhi->newTexture( QRhiTexture::RGBA8, size, 1, flags ); - m_rhiTexture->create(); -==== BASE ==== + QRhiColorAttachment color0( m_rhiTexture ); + auto target = rhi->newTextureRenderTarget( { color0 } ); -==== BASE ==== - QRhiColorAttachment color0( m_rhiTexture ); - auto target = rhi->newTextureRenderTarget( { color0 } ); -==== BASE ==== + target->setRenderPassDescriptor( + target->newCompatibleRenderPassDescriptor() ); -==== BASE ==== - target->setRenderPassDescriptor( - target->newCompatibleRenderPassDescriptor() ); -==== BASE ==== +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + target->build(); +#else + target->create(); +#endif -==== BASE ==== - target->create(); -==== BASE ==== + m_rt.rt = target; + m_rt.rpDesc = target->renderPassDescriptor(); auto defaultContext = qobject_cast< QSGDefaultRenderContext* >( context() ); m_rt.cb = defaultContext->currentFrameCommandBuffer();