qskinny/src/graphic/QskGraphicTextureFactory.cpp

74 lines
2.0 KiB
C++
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskGraphicTextureFactory.h"
#include "QskTextureRenderer.h"
2017-07-21 16:21:34 +00:00
2018-07-19 12:10:48 +00:00
#include <qquickwindow.h>
2020-11-01 07:48:50 +00:00
#include <qsgtexture.h>
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <qsgtexture_platform.h>
#endif
2017-07-21 16:21:34 +00:00
QskGraphicTextureFactory::QskGraphicTextureFactory()
{
}
QskGraphicTextureFactory::QskGraphicTextureFactory(
2018-08-03 06:15:28 +00:00
const QskGraphic& graphic, const QSize& size )
: m_graphic( graphic )
, m_size( size )
2017-07-21 16:21:34 +00:00
{
}
QskGraphicTextureFactory::~QskGraphicTextureFactory()
{
}
QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) const
{
const uint textureId = QskTextureRenderer::createTextureFromGraphic(
QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter,
Qt::IgnoreAspectRatio );
2017-07-21 16:21:34 +00:00
const auto flags = static_cast< QQuickWindow::CreateTextureOptions >(
QQuickWindow::TextureHasAlphaChannel | QQuickWindow::TextureOwnsGLTexture );
2020-11-01 07:48:50 +00:00
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 )
2020-03-12 08:56:38 +00:00
const int nativeLayout = 0; // VkImageLayout in case of Vulkan
2020-11-01 07:48:50 +00:00
texture = window->createTextureFromNativeObject(
2020-03-12 08:56:38 +00:00
QQuickWindow::NativeObjectTexture, &textureId, nativeLayout,
m_size, flags );
#else
2020-11-01 07:48:50 +00:00
texture = window->createTextureFromId( textureId, m_size, flags );
2020-03-12 08:56:38 +00:00
#endif
2020-11-01 07:48:50 +00:00
return texture;
2017-07-21 16:21:34 +00:00
}
QSize QskGraphicTextureFactory::textureSize() const
{
return m_size;
}
int QskGraphicTextureFactory::textureByteCount() const
{
return m_size.width() * m_size.height() * 4;
}
QImage QskGraphicTextureFactory::image() const
{
return m_graphic.toImage( m_size, Qt::KeepAspectRatio );
}