Qt5/RHI supported
This commit is contained in:
parent
e1069d9292
commit
6ad68a6da8
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
#include <qsgmaterialshader.h>
|
||||
#include <qsgtexture.h>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
#include <qsgmaterialrhishader.h>
|
||||
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()
|
||||
|
|
|
@ -32,5 +32,5 @@ class TextureFilterMaterial : public QSGMaterial
|
|||
|
||||
private:
|
||||
QSGTexture* m_texture = nullptr;
|
||||
const QString m_shaderSourceFiles[ 2 ];
|
||||
const QString m_shaderFiles[ 2 ];
|
||||
};
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue