code moved to QskTextureRenderer

This commit is contained in:
Uwe Rathmann 2020-11-01 10:43:16 +01:00
parent d64f861e33
commit 271b595609
4 changed files with 80 additions and 58 deletions

View File

@ -7,11 +7,6 @@
#include "QskTextureRenderer.h"
#include <qquickwindow.h>
#include <qsgtexture.h>
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <qsgtexture_platform.h>
#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

View File

@ -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

View File

@ -23,6 +23,12 @@
#include <qscreen.h>
#include <qsurface.h>
#include <qsgtexture.h>
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <qsgtexture_platform.h>
#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 )

View File

@ -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 );
}