palette -> colorRamp

This commit is contained in:
Uwe Rathmann 2022-11-13 11:05:53 +01:00
parent 0fb4b25bba
commit a658a2a4e4
15 changed files with 33 additions and 33 deletions

View File

@ -37,10 +37,10 @@ QSK_QT_PRIVATE_END
namespace namespace
{ {
class GradientTexture : public QSGPlainTexture class ColorRamp : public QSGPlainTexture
{ {
public: public:
GradientTexture( const QskGradientStops& stops, QGradient::Spread spread ) ColorRamp( const QskGradientStops& stops, QGradient::Spread spread )
{ {
/* /*
Qt creates tables of 1024 colors, while Chrome, Firefox, and Android Qt creates tables of 1024 colors, while Chrome, Firefox, and Android
@ -75,10 +75,10 @@ namespace
} }
}; };
class TextureHashKey class ColorRampHashKey
{ {
public: public:
inline bool operator==( const TextureHashKey& other ) const inline bool operator==( const ColorRampHashKey& other ) const
{ {
return rhi == other.rhi && spread == other.spread && stops == other.stops; return rhi == other.rhi && spread == other.spread && stops == other.stops;
} }
@ -88,7 +88,7 @@ namespace
const QGradient::Spread spread; const QGradient::Spread spread;
}; };
inline size_t qHash( const TextureHashKey& key, size_t seed = 0 ) inline size_t qHash( const ColorRampHashKey& key, size_t seed = 0 )
{ {
size_t valus = seed + key.spread; size_t valus = seed + key.spread;
@ -98,15 +98,15 @@ namespace
return valus; return valus;
} }
class TextureCache class ColorRampCache
{ {
public: public:
static TextureCache* instance() static ColorRampCache* instance()
{ {
static TextureCache* s_instance = nullptr; static ColorRampCache* s_instance = nullptr;
if ( s_instance == nullptr ) if ( s_instance == nullptr )
{ {
s_instance = new TextureCache(); s_instance = new ColorRampCache();
/* /*
For RHI we have QRhi::addCleanupCallback, but with For RHI we have QRhi::addCleanupCallback, but with
@ -119,20 +119,20 @@ namespace
return s_instance; return s_instance;
} }
~TextureCache() ~ColorRampCache()
{ {
qDeleteAll( m_hashTable ); qDeleteAll( m_hashTable );
} }
GradientTexture* texture( const void* rhi, ColorRamp* colorRamp( const void* rhi,
const QskGradientStops& stops, QGradient::Spread spread ) const QskGradientStops& stops, QGradient::Spread spread )
{ {
const TextureHashKey key { rhi, stops, spread }; const ColorRampHashKey key { rhi, stops, spread };
auto texture = m_hashTable[key]; auto texture = m_hashTable[key];
if ( texture == nullptr ) if ( texture == nullptr )
{ {
texture = new GradientTexture( stops, spread ); texture = new ColorRamp( stops, spread );
m_hashTable[ key ] = texture; m_hashTable[ key ] = texture;
if ( rhi != nullptr ) if ( rhi != nullptr )
@ -141,7 +141,7 @@ namespace
if ( !m_rhiTable.contains( myrhi ) ) if ( !m_rhiTable.contains( myrhi ) )
{ {
myrhi->addCleanupCallback( TextureCache::cleanupRhi ); myrhi->addCleanupCallback( ColorRampCache::cleanupRhi );
m_rhiTable += myrhi; m_rhiTable += myrhi;
} }
} }
@ -177,7 +177,7 @@ namespace
cache->m_rhiTable.removeAll( rhi ); cache->m_rhiTable.removeAll( rhi );
} }
QHash< TextureHashKey, GradientTexture* > m_hashTable; QHash< ColorRampHashKey, ColorRamp* > m_hashTable;
QVector< const QRhi* > m_rhiTable; QVector< const QRhi* > m_rhiTable;
}; };
} }
@ -253,9 +253,9 @@ namespace
updateUniformValues( material ); updateUniformValues( material );
auto texture = TextureCache::instance()->texture( auto colorRamp = ColorRampCache::instance()->colorRamp(
nullptr, material->stops(), material->spread() ); nullptr, material->stops(), material->spread() );
texture->bind(); colorRamp->bind();
} }
char const* const* attributeNames() const override final char const* const* attributeNames() const override final
@ -292,16 +292,16 @@ namespace
auto material = static_cast< const GradientMaterial* >( newMaterial ); auto material = static_cast< const GradientMaterial* >( newMaterial );
auto texture = TextureCache::instance()->texture( auto colorRamp = ColorRampCache::instance()->colorRamp(
state.rhi(), material->stops(), material->spread() ); state.rhi(), material->stops(), material->spread() );
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
texture->updateRhiTexture( state.rhi(), state.resourceUpdateBatch() ); colorRamp->updateRhiTexture( state.rhi(), state.resourceUpdateBatch() );
#else #else
texture->commitTextureOperations( state.rhi(), state.resourceUpdateBatch() ); colorRamp->commitTextureOperations( state.rhi(), state.resourceUpdateBatch() );
#endif #endif
textures[0] = texture; textures[0] = colorRamp;
} }
}; };
#endif #endif

Binary file not shown.

Binary file not shown.

View File

@ -12,11 +12,11 @@ layout( std140, binding = 0 ) uniform buf
float opacity; float opacity;
} ubuf; } ubuf;
layout( binding = 1 ) uniform sampler2D palette; layout( binding = 1 ) uniform sampler2D colorRamp;
vec4 colorAt( highp float value ) vec4 colorAt( highp float value )
{ {
return texture( palette, vec2( value, 0.0 ) ); return texture( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()

View File

@ -1,4 +1,4 @@
uniform sampler2D palette; uniform sampler2D colorRamp;
uniform lowp float opacity; uniform lowp float opacity;
uniform highp float start; uniform highp float start;
@ -8,7 +8,7 @@ varying highp vec2 coord;
lowp vec4 colorAt( highp float value ) lowp vec4 colorAt( highp float value )
{ {
return texture2D( palette, vec2( value, 0.0 ) ); return texture2D( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()

View File

@ -10,11 +10,11 @@ layout( std140, binding = 0 ) uniform buf
float opacity; float opacity;
} ubuf; } ubuf;
layout( binding = 1 ) uniform sampler2D palette; layout( binding = 1 ) uniform sampler2D colorRamp;
vec4 colorAt( float value ) vec4 colorAt( float value )
{ {
return texture( palette, vec2( value, 0.0 ) ); return texture( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()

View File

@ -1,11 +1,11 @@
uniform sampler2D palette; uniform sampler2D colorRamp;
uniform highp float opacity; uniform highp float opacity;
varying highp float colorIndex; varying highp float colorIndex;
lowp vec4 colorAt( float value ) lowp vec4 colorAt( float value )
{ {
return texture2D( palette, vec2( value, 0.0 ) ); return texture2D( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()

View File

@ -11,11 +11,11 @@ layout( std140, binding = 0 ) uniform buf
float opacity; float opacity;
} ubuf; } ubuf;
layout( binding = 1 ) uniform sampler2D palette; layout( binding = 1 ) uniform sampler2D colorRamp;
vec4 colorAt( float value ) vec4 colorAt( float value )
{ {
return texture( palette, vec2( value, 0.0 ) ); return texture( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()

View File

@ -1,4 +1,4 @@
uniform sampler2D palette; uniform sampler2D colorRamp;
uniform lowp float opacity; uniform lowp float opacity;
uniform highp vec2 radius; uniform highp vec2 radius;
@ -7,7 +7,7 @@ varying highp vec2 coord;
lowp vec4 colorAt( highp float value ) lowp vec4 colorAt( highp float value )
{ {
return texture2D( palette, vec2( value, 0.0 ) ); return texture2D( colorRamp, vec2( value, 0.0 ) );
} }
void main() void main()