diff --git a/src/graphic/QskGraphicTextureFactory.cpp b/src/graphic/QskGraphicTextureFactory.cpp index a93727a2..0a4548a9 100644 --- a/src/graphic/QskGraphicTextureFactory.cpp +++ b/src/graphic/QskGraphicTextureFactory.cpp @@ -7,11 +7,6 @@ #include "QskTextureRenderer.h" #include -#include - -#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) - #include -#endif QskGraphicTextureFactory::QskGraphicTextureFactory() { @@ -28,33 +23,47 @@ QskGraphicTextureFactory::~QskGraphicTextureFactory() { } +void QskGraphicTextureFactory::setGraphic( const QskGraphic& graphic ) +{ + m_graphic = graphic; +} + +QskGraphic QskGraphicTextureFactory::graphic() const +{ + return m_graphic; +} + +void QskGraphicTextureFactory::setColorFilter( + const QskColorFilter& colorFilter ) +{ + m_colorFilter = colorFilter; +} + +const QskColorFilter& QskGraphicTextureFactory::colorFilter() const +{ + return m_colorFilter; +} + +void QskGraphicTextureFactory::setSize( const QSize& size ) +{ + m_size = size; +} + +QSize QskGraphicTextureFactory::size() const +{ + return m_size; +} + + QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) const { - const uint textureId = QskTextureRenderer::createTextureFromGraphic( + using namespace QskTextureRenderer; + + const uint textureId = createTextureFromGraphic( QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter, Qt::IgnoreAspectRatio ); - const auto flags = static_cast< QQuickWindow::CreateTextureOptions >( - QQuickWindow::TextureHasAlphaChannel | QQuickWindow::TextureOwnsGLTexture ); - - QSGTexture* texture; - -#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) - - texture = QNativeInterface::QSGOpenGLTexture::fromNative( - textureId, window, m_size, flags ); - -#elif QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 ) - const int nativeLayout = 0; // VkImageLayout in case of Vulkan - - texture = window->createTextureFromNativeObject( - QQuickWindow::NativeObjectTexture, &textureId, nativeLayout, - m_size, flags ); -#else - texture = window->createTextureFromId( textureId, m_size, flags ); -#endif - - return texture; + return textureFromId( window, textureId, m_size ); } QSize QskGraphicTextureFactory::textureSize() const diff --git a/src/graphic/QskGraphicTextureFactory.h b/src/graphic/QskGraphicTextureFactory.h index 284b01c7..61be41ef 100644 --- a/src/graphic/QskGraphicTextureFactory.h +++ b/src/graphic/QskGraphicTextureFactory.h @@ -40,35 +40,4 @@ class QSK_EXPORT QskGraphicTextureFactory : public QQuickTextureFactory QSize m_size; }; -inline void QskGraphicTextureFactory::setGraphic( const QskGraphic& graphic ) -{ - m_graphic = graphic; -} - -inline QskGraphic QskGraphicTextureFactory::graphic() const -{ - return m_graphic; -} - -inline void QskGraphicTextureFactory::setColorFilter( - const QskColorFilter& colorFilter ) -{ - m_colorFilter = colorFilter; -} - -inline const QskColorFilter& QskGraphicTextureFactory::colorFilter() const -{ - return m_colorFilter; -} - -inline void QskGraphicTextureFactory::setSize( const QSize& size ) -{ - m_size = size; -} - -inline QSize QskGraphicTextureFactory::size() const -{ - return m_size; -} - #endif diff --git a/src/nodes/QskTextureRenderer.cpp b/src/nodes/QskTextureRenderer.cpp index a5572054..9c79b603 100644 --- a/src/nodes/QskTextureRenderer.cpp +++ b/src/nodes/QskTextureRenderer.cpp @@ -23,6 +23,12 @@ #include #include +#include + +#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) + #include +#endif + static uint qskCreateTextureOpenGL( const QSize& size, QskTextureRenderer::PaintHelper* helper ) { @@ -129,6 +135,35 @@ static uint qskCreateTextureRaster( return textureId; } +QSGTexture* QskTextureRenderer::textureFromId( + QQuickWindow* window, uint textureId, const QSize& size ) +{ + const auto flags = static_cast< QQuickWindow::CreateTextureOptions >( + QQuickWindow::TextureHasAlphaChannel | QQuickWindow::TextureOwnsGLTexture ); + + QSGTexture* texture; + +#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) + + texture = QNativeInterface::QSGOpenGLTexture::fromNative( + textureId, window, size, flags ); + +#elif QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 ) + + const int nativeLayout = 0; // VkImageLayout in case of Vulkan + + texture = window->createTextureFromNativeObject( + QQuickWindow::NativeObjectTexture, &textureId, nativeLayout, size, flags ); + +#else + + texture = window->createTextureFromId( textureId, size, flags ); + +#endif + + return texture; +} + QskTextureRenderer::PaintHelper::~PaintHelper() { } @@ -136,6 +171,10 @@ QskTextureRenderer::PaintHelper::~PaintHelper() uint QskTextureRenderer::createTexture( RenderMode renderMode, const QSize& size, PaintHelper* helper ) { +#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) + // Qt6.0.0 is buggy when using FBOs. So let's disable it for the moment TODO ... + renderMode = Raster; +#endif if ( renderMode == AutoDetect ) { if ( qskSetup->controlFlags() & QskSetup::PreferRasterForTextures ) diff --git a/src/nodes/QskTextureRenderer.h b/src/nodes/QskTextureRenderer.h index 876ab739..a15e90de 100644 --- a/src/nodes/QskTextureRenderer.h +++ b/src/nodes/QskTextureRenderer.h @@ -15,6 +15,8 @@ class QskColorFilter; class QPainter; class QSize; class QOpenGLContext; +class QSGTexture; +class QQuickWindow; namespace QskTextureRenderer { @@ -48,6 +50,9 @@ namespace QskTextureRenderer RenderMode, const QSize&, const QskGraphic&, const QskColorFilter&, Qt::AspectRatioMode ); + QSK_EXPORT QSGTexture* textureFromId( + QQuickWindow*, uint textureId, const QSize& ); + QSK_EXPORT qreal devicePixelRatio( const QOpenGLContext* = nullptr ); }