Skip to content

Commit

Permalink
Minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Sep 9, 2024
1 parent 07ef3b6 commit 02fc032
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 10 additions & 13 deletions src/gl/glproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ void BSShaderLightingProperty::clear()
sfMaterialPath.clear();
}

bool BSShaderLightingProperty::getSFTexture( int & texunit, int & texUniform, FloatVector4 * replUniform, const std::string_view * texturePath, std::uint32_t textureReplacement, int textureReplacementMode, const CE2Material::UVStream * uvStream )
int BSShaderLightingProperty::getSFTexture( int & texunit, FloatVector4 & replUniform, const std::string_view & texturePath, std::uint32_t textureReplacement, int textureReplacementMode, const CE2Material::UVStream * uvStream )
{
FloatVector4 c( textureReplacement );
c *= 1.0f / 255.0f;
Expand All @@ -940,9 +940,9 @@ bool BSShaderLightingProperty::getSFTexture( int & texunit, int & texUniform, Fl
c = c + c - 1.0f; // SNORM
}
do {
size_t n;
if ( !( texturePath && ( n = texturePath->length() ) > 0 && n <= 1024 ) )
break;
size_t n = texturePath.length();
if ( ( n - 1 ) & ~( size_t(1023) ) )
break; // empty path or not enough space in tmpBuf
if ( !( texunit >= 3 && texunit < TexCache::num_texture_units && activateTextureUnit(texunit, true) ) )
break;

Expand All @@ -960,24 +960,21 @@ bool BSShaderLightingProperty::getSFTexture( int & texunit, int & texUniform, Fl

// convert std::string_view to a temporary array of QChar
std::uint16_t tmpBuf[1024];
convertStringToUInt16( tmpBuf, texturePath->data(), n );
convertStringToUInt16( tmpBuf, texturePath.data(), n );

if ( !bind( QStringView( tmpBuf, qsizetype( n ) ), false, clampMode ) )
break;

texUniform = texunit - 2;
texunit++;
return true;
return texunit - 3;

} while ( false );

if ( textureReplacementMode > 0 && replUniform ) {
texUniform = -1;
*replUniform = c;
return true;
if ( textureReplacementMode > 0 ) {
replUniform = c;
return -1;
}
texUniform = 0;
return false;
return 0;
}

void BSShaderLightingProperty::setMaterial( Material * newMaterial )
Expand Down
3 changes: 2 additions & 1 deletion src/gl/glproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,8 @@ class BSShaderLightingProperty : public Property
return sf_material_valid;
}
// textureReplacementMode <= 0: disabled, > 0: enabled, 1: linear, 2: sRGB, 3: normal map (-1.0 to 1.0)
bool getSFTexture( int & texunit, int & texUniform, FloatVector4 * replUniform, const std::string_view * texturePath, std::uint32_t textureReplacement, int textureReplacementMode, const CE2Material::UVStream * uvStream );
// returns the texture uniform value (0: no texture, -1: use replacement, >= 1: sampler array index)
int getSFTexture( int & texunit, FloatVector4 & replUniform, const std::string_view & texturePath, std::uint32_t textureReplacement, int textureReplacementMode, const CE2Material::UVStream * uvStream );

protected:
ShaderFlags::SF1 flags1 = ShaderFlags::SLSF1_ZBuffer_Test;
Expand Down

0 comments on commit 02fc032

Please sign in to comment.