Use double instead of float in high level class to avoid

user set values changing when saving/restoring material settings

Convert to float when creating low level, performance critical
objects only.
This commit is contained in:
Nyall Dawson 2024-01-05 07:47:09 +10:00
parent 37e4b8a1af
commit da06bde051
4 changed files with 49 additions and 49 deletions

View File

@ -62,19 +62,19 @@ Returns diffuse color component
%Docstring
Returns specular color component
%End
float shininess() const;
double shininess() const;
%Docstring
Returns shininess of the surface
%End
float opacity() const;
double opacity() const;
%Docstring
Returns the opacity of the surface
.. versionadded:: 3.26
%End
float ambientCoefficient() const;
double ambientCoefficient() const;
%Docstring
Returns the coefficient for the ambient color contribution (ie strength factor of the ambient color).
@ -87,7 +87,7 @@ Returns the coefficient for the ambient color contribution (ie strength factor o
.. versionadded:: 3.36
%End
float diffuseCoefficient() const;
double diffuseCoefficient() const;
%Docstring
Returns the coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
@ -100,7 +100,7 @@ Returns the coefficient for the diffuse color contribution (ie strength factor o
.. versionadded:: 3.36
%End
float specularCoefficient() const;
double specularCoefficient() const;
%Docstring
Returns the coefficient for the specular color contribution (ie strength factor of the specular color).
@ -133,14 +133,14 @@ Sets specular color component
Sets shininess of the surface
%End
void setOpacity( float opacity );
void setOpacity( double opacity );
%Docstring
Sets opacity of the surface
.. versionadded:: 3.26
%End
void setAmbientCoefficient( float coefficient );
void setAmbientCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the ambient color contribution (ie strength factor of the ambient color).
@ -153,7 +153,7 @@ Sets the ``coefficient`` for the ambient color contribution (ie strength factor
.. versionadded:: 3.36
%End
void setDiffuseCoefficient( float coefficient );
void setDiffuseCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the diffuse color contribution (ie strength factor of the diffuse color).
@ -166,7 +166,7 @@ Sets the ``coefficient`` for the diffuse color contribution (ie strength factor
.. versionadded:: 3.36
%End
void setSpecularCoefficient( float coefficient );
void setSpecularCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the specular color contribution (ie strength factor of the specular color).

View File

@ -62,19 +62,19 @@ Returns diffuse color component
%Docstring
Returns specular color component
%End
float shininess() const;
double shininess() const;
%Docstring
Returns shininess of the surface
%End
float opacity() const;
double opacity() const;
%Docstring
Returns the opacity of the surface
.. versionadded:: 3.26
%End
float ambientCoefficient() const;
double ambientCoefficient() const;
%Docstring
Returns the coefficient for the ambient color contribution (ie strength factor of the ambient color).
@ -87,7 +87,7 @@ Returns the coefficient for the ambient color contribution (ie strength factor o
.. versionadded:: 3.36
%End
float diffuseCoefficient() const;
double diffuseCoefficient() const;
%Docstring
Returns the coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
@ -100,7 +100,7 @@ Returns the coefficient for the diffuse color contribution (ie strength factor o
.. versionadded:: 3.36
%End
float specularCoefficient() const;
double specularCoefficient() const;
%Docstring
Returns the coefficient for the specular color contribution (ie strength factor of the specular color).
@ -133,14 +133,14 @@ Sets specular color component
Sets shininess of the surface
%End
void setOpacity( float opacity );
void setOpacity( double opacity );
%Docstring
Sets opacity of the surface
.. versionadded:: 3.26
%End
void setAmbientCoefficient( float coefficient );
void setAmbientCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the ambient color contribution (ie strength factor of the ambient color).
@ -153,7 +153,7 @@ Sets the ``coefficient`` for the ambient color contribution (ie strength factor
.. versionadded:: 3.36
%End
void setDiffuseCoefficient( float coefficient );
void setDiffuseCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the diffuse color contribution (ie strength factor of the diffuse color).
@ -166,7 +166,7 @@ Sets the ``coefficient`` for the diffuse color contribution (ie strength factor
.. versionadded:: 3.36
%End
void setSpecularCoefficient( float coefficient );
void setSpecularCoefficient( double coefficient );
%Docstring
Sets the ``coefficient`` for the specular color contribution (ie strength factor of the specular color).

View File

@ -81,11 +81,11 @@ void QgsPhongMaterialSettings::readXml( const QDomElement &elem, const QgsReadWr
mAmbient = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) );
mDiffuse = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) );
mSpecular = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "specular" ), QStringLiteral( "255,255,255" ) ) );
mShininess = elem.attribute( QStringLiteral( "shininess" ) ).toFloat();
mOpacity = elem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.0" ) ).toFloat();
mAmbientCoefficient = elem.attribute( QStringLiteral( "ka" ), QStringLiteral( "1.0" ) ).toFloat();
mDiffuseCoefficient = elem.attribute( QStringLiteral( "kd" ), QStringLiteral( "1.0" ) ).toFloat();
mSpecularCoefficient = elem.attribute( QStringLiteral( "ks" ), QStringLiteral( "1.0" ) ).toFloat();
mShininess = elem.attribute( QStringLiteral( "shininess" ) ).toDouble();
mOpacity = elem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.0" ) ).toDouble();
mAmbientCoefficient = elem.attribute( QStringLiteral( "ka" ), QStringLiteral( "1.0" ) ).toDouble();
mDiffuseCoefficient = elem.attribute( QStringLiteral( "kd" ), QStringLiteral( "1.0" ) ).toDouble();
mSpecularCoefficient = elem.attribute( QStringLiteral( "ks" ), QStringLiteral( "1.0" ) ).toDouble();
QgsAbstractMaterialSettings::readXml( elem, context );
}
@ -143,11 +143,11 @@ void QgsPhongMaterialSettings::addParametersToEffect( Qt3DRender::QEffect *effec
Qt3DRender::QParameter *ambientParameter = new Qt3DRender::QParameter( QStringLiteral( "ambientColor" ), mAmbient );
Qt3DRender::QParameter *diffuseParameter = new Qt3DRender::QParameter( QStringLiteral( "diffuseColor" ), mDiffuse );
Qt3DRender::QParameter *specularParameter = new Qt3DRender::QParameter( QStringLiteral( "specularColor" ), mSpecular );
Qt3DRender::QParameter *shininessParameter = new Qt3DRender::QParameter( QStringLiteral( "shininess" ), mShininess );
Qt3DRender::QParameter *opacityParameter = new Qt3DRender::QParameter( QStringLiteral( "opacity" ), mOpacity );
Qt3DRender::QParameter *kaParameter = new Qt3DRender::QParameter( QStringLiteral( "ka" ), mAmbientCoefficient );
Qt3DRender::QParameter *kdParameter = new Qt3DRender::QParameter( QStringLiteral( "kd" ), mDiffuseCoefficient );
Qt3DRender::QParameter *ksParameter = new Qt3DRender::QParameter( QStringLiteral( "ks" ), mSpecularCoefficient );
Qt3DRender::QParameter *shininessParameter = new Qt3DRender::QParameter( QStringLiteral( "shininess" ), static_cast< float >( mShininess ) );
Qt3DRender::QParameter *opacityParameter = new Qt3DRender::QParameter( QStringLiteral( "opacity" ), static_cast< float >( mOpacity ) );
Qt3DRender::QParameter *kaParameter = new Qt3DRender::QParameter( QStringLiteral( "ka" ), static_cast< float >( mAmbientCoefficient ) );
Qt3DRender::QParameter *kdParameter = new Qt3DRender::QParameter( QStringLiteral( "kd" ), static_cast< float >( mDiffuseCoefficient ) );
Qt3DRender::QParameter *ksParameter = new Qt3DRender::QParameter( QStringLiteral( "ks" ), static_cast< float >( mSpecularCoefficient ) );
effect->addParameter( ambientParameter );
effect->addParameter( diffuseParameter );
@ -254,14 +254,14 @@ Qt3DRender::QMaterial *QgsPhongMaterialSettings::constantColorMaterial( const Qg
renderPass->setShaderProgram( shaderProgram );
technique->addRenderPass( renderPass );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "shininess" ), mShininess ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "opacity" ), mOpacity ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "shininess" ), static_cast< float >( mShininess ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "opacity" ), static_cast< float >( mOpacity ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ambientColor" ), context.isSelected() ? context.selectionColor().darker() : mAmbient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "diffuseColor" ), context.isSelected() ? context.selectionColor() : mDiffuse ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "specularColor" ), mSpecular ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ka" ), mAmbientCoefficient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "kd" ), mDiffuseCoefficient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ks" ), mSpecularCoefficient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ka" ), static_cast< float >( mAmbientCoefficient ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "kd" ), static_cast< float >( mDiffuseCoefficient ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ks" ), static_cast< float >( mSpecularCoefficient ) ) );
if ( mOpacity < 1.0f )
{
@ -313,8 +313,8 @@ Qt3DRender::QMaterial *QgsPhongMaterialSettings::dataDefinedMaterial() const
renderPass->setShaderProgram( shaderProgram );
technique->addRenderPass( renderPass );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "shininess" ), mShininess ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "opacity" ), mOpacity ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "shininess" ), static_cast< float >( mShininess ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "opacity" ), static_cast< float >( mOpacity ) ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ka" ), mAmbientCoefficient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "kd" ), mDiffuseCoefficient ) );
eff->addParameter( new Qt3DRender::QParameter( QStringLiteral( "ks" ), mSpecularCoefficient ) );

View File

@ -63,13 +63,13 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
//! Returns specular color component
QColor specular() const { return mSpecular; }
//! Returns shininess of the surface
float shininess() const { return mShininess; }
double shininess() const { return mShininess; }
/**
* Returns the opacity of the surface
* \since QGIS 3.26
*/
float opacity() const { return mOpacity; }
double opacity() const { return mOpacity; }
/**
* Returns the coefficient for the ambient color contribution (ie strength factor of the ambient color).
@ -80,7 +80,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
float ambientCoefficient() const { return mAmbientCoefficient; }
double ambientCoefficient() const { return mAmbientCoefficient; }
/**
* Returns the coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
@ -91,7 +91,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
float diffuseCoefficient() const { return mDiffuseCoefficient; }
double diffuseCoefficient() const { return mDiffuseCoefficient; }
/**
* Returns the coefficient for the specular color contribution (ie strength factor of the specular color).
@ -102,7 +102,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
float specularCoefficient() const { return mSpecularCoefficient; }
double specularCoefficient() const { return mSpecularCoefficient; }
QMap<QString, QString> toExportParameters() const override;
@ -119,7 +119,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
* Sets opacity of the surface
* \since QGIS 3.26
*/
void setOpacity( float opacity ) { mOpacity = opacity; }
void setOpacity( double opacity ) { mOpacity = opacity; }
/**
* Sets the \a coefficient for the ambient color contribution (ie strength factor of the ambient color).
@ -130,7 +130,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
void setAmbientCoefficient( float coefficient ) { mAmbientCoefficient = coefficient; }
void setAmbientCoefficient( double coefficient ) { mAmbientCoefficient = coefficient; }
/**
* Sets the \a coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
@ -141,7 +141,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
void setDiffuseCoefficient( float coefficient ) { mDiffuseCoefficient = coefficient; }
void setDiffuseCoefficient( double coefficient ) { mDiffuseCoefficient = coefficient; }
/**
* Sets the \a coefficient for the specular color contribution (ie strength factor of the specular color).
@ -152,7 +152,7 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
*
* \since QGIS 3.36
*/
void setSpecularCoefficient( float coefficient ) { mSpecularCoefficient = coefficient; }
void setSpecularCoefficient( double coefficient ) { mSpecularCoefficient = coefficient; }
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
@ -187,13 +187,13 @@ class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
float mShininess = 0.0f;
double mShininess = 0.0;
float mAmbientCoefficient = 1.0f;
float mDiffuseCoefficient = 1.0f;
float mSpecularCoefficient = 1.0f;
double mAmbientCoefficient = 1.0;
double mDiffuseCoefficient = 1.0;
double mSpecularCoefficient = 1.0;
float mOpacity = 1.0f;
double mOpacity = 1.0;
//! Constructs a material from shader files
Qt3DRender::QMaterial *constantColorMaterial( const QgsMaterialContext &context ) const;