qskinny/src/graphic/QskGraphicTextureFactory.cpp

60 lines
1.7 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>
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-03-12 08:56:38 +00:00
#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
const int nativeLayout = 0; // VkImageLayout in case of Vulkan
return window->createTextureFromNativeObject(
QQuickWindow::NativeObjectTexture, &textureId, nativeLayout,
m_size, flags );
#else
2017-07-21 16:21:34 +00:00
return window->createTextureFromId( textureId, m_size, flags );
2020-03-12 08:56:38 +00:00
#endif
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 );
}