19#include "moc_qgscolorramptexture.cpp"
25QgsColorRampTextureGenerator::QgsColorRampTextureGenerator(
const QgsColorRampShader &colorRampShader,
double verticalScale )
26 : mColorRampShader( colorRampShader )
27 , mVerticalScale( verticalScale )
31Qt3DRender::QTextureImageDataPtr QgsColorRampTextureGenerator::operator()()
33 Qt3DRender::QTextureImageDataPtr dataPtr = Qt3DRender::QTextureImageDataPtr::create();
34 dataPtr->setFormat( QOpenGLTexture::RGBA32F );
35 dataPtr->setTarget( QOpenGLTexture::Target1D );
36 dataPtr->setPixelFormat( QOpenGLTexture::RGBA );
37 dataPtr->setPixelType( QOpenGLTexture::Float32 );
40 const QList<QgsColorRampShader::ColorRampItem> colorItemList = mColorRampShader.colorRampItemList();
41 const int size = colorItemList.count() ;
43 dataPtr->setWidth( size );
44 dataPtr->setHeight( 1 );
45 dataPtr->setDepth( 1 );
46 dataPtr->setFaces( 1 );
47 dataPtr->setLayers( 1 );
48 dataPtr->setMipLevels( 1 );
50 for (
int i = 0; i < colorItemList.count(); ++i )
52 float mag = float( colorItemList.at( i ).value * mVerticalScale );
54 const QColor color = colorItemList.at( i ).color;
55 if ( color.alphaF() == 0.0f )
57 float rf = float( color.redF() );
58 float gf = float( color.greenF() );
59 float bf = float( color.blueF() );
61 data.append(
reinterpret_cast<const char *
>( &mag ),
sizeof(
float ) );
62 data.append(
reinterpret_cast<const char *
>( &rf ),
sizeof(
float ) );
63 data.append(
reinterpret_cast<const char *
>( &gf ),
sizeof(
float ) );
64 data.append(
reinterpret_cast<const char *
>( &bf ),
sizeof(
float ) );
67 dataPtr->setData( data,
sizeof(
float ) );
72bool QgsColorRampTextureGenerator::operator==(
const Qt3DRender::QTextureImageDataGenerator &other )
const
74 const QgsColorRampTextureGenerator *otherFunctor = functor_cast<QgsColorRampTextureGenerator>( &other );
78 return mColorRampShader == otherFunctor->mColorRampShader;
83QgsColorRampTexture::QgsColorRampTexture(
const QgsColorRampShader &colorRampShader,
double verticalScale, Qt3DCore::QNode *parent )
85 mColorRampShader( colorRampShader ),
86 mVerticalScale( verticalScale )
91Qt3DRender::QTextureImageDataGeneratorPtr QgsColorRampTexture::dataGenerator()
const
93 return Qt3DRender::QTextureImageDataGeneratorPtr(
new QgsColorRampTextureGenerator( mColorRampShader, mVerticalScale ) );
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.