Convert span with dynamic extent to static extent

In some places we know the size at compile time, so use that knowlage.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2025-08-13 20:55:01 +02:00
parent 2cedb48de2
commit 77e05ca26d
No known key found for this signature in database
6 changed files with 11 additions and 11 deletions

View file

@ -71,7 +71,7 @@ struct CColor
}
// For passing to uniform as vec3/vec4.
std::span<const float> AsFloatArray() const
std::span<const float, 4> AsFloatArray() const
{
// Additional check to prevent a weird compiler has a different
// alignement for an array and a class members.
@ -82,7 +82,7 @@ struct CColor
offsetof(CColor, b) == sizeof(float) * 2u &&
offsetof(CColor, a) == sizeof(float) * 3u,
"CColor should be properly layouted to use AsFloatArray");
return std::span(&r, 4);
return std::span<const float, 4>(&r, 4);
}
// For passing to CRenderer:

View file

@ -528,7 +528,7 @@ void CFont::BlendGlyphBitmapToTextureRGBA(const FT_Bitmap& bitmap, int targetX,
for (uint x{0}; x != bitmap.width; ++x)
{
const std::span<u8> tempDstRow{dstRow + x * m_TextureFormatStride, 4};
const std::span<u8, 4> tempDstRow{dstRow + x * m_TextureFormatStride, 4};
u8 alpha{srcRow[x]};
const float srcAlpha{m_StrokeWidth > 0 ? (*m_GammaCorrectionLUT)[alpha] : alpha/255.0f};

View file

@ -334,7 +334,7 @@ public:
CVector3D RotateTransposed(const CVector3D& vector) const;
// Returns 16 element array of floats, e.g. for mat4 uniforms.
std::span<const float> AsFloatArray() const
std::span<const float, 16> AsFloatArray() const
{
// Additional check to prevent a weird compiler has a different
// alignement for an array and a class members.
@ -344,7 +344,7 @@ public:
offsetof(CMatrix3D, _11) == 0 &&
offsetof(CMatrix3D, _44) == sizeof(float) * 15u,
"CMatrix3D should be properly layouted to use AsFloatArray");
return std::span<const float>(_data, 16);
return std::span<const float, 16>(_data);
}
};

View file

@ -164,7 +164,7 @@ public:
void operator-=(const CSize2D& size);
// Returns 2 element array of floats, e.g. for vec2 uniforms.
std::span<const float> AsFloatArray() const
std::span<const float, 2> AsFloatArray() const
{
// Additional check to prevent a weird compiler having a different
// alignement for an array and a class members.
@ -173,7 +173,7 @@ public:
offsetof(CVector2D, X) == 0 &&
offsetof(CVector2D, Y) == sizeof(float),
"Vector2D should be properly layouted to use AsFloatArray");
return std::span<const float>(&X, 2);
return std::span<const float, 2>(&X, 2);
}
public:

View file

@ -124,7 +124,7 @@ class CVector3D
CVector3D Normalized() const;
// Returns 3 element array of floats, e.g. for vec3 uniforms.
std::span<const float> AsFloatArray() const
std::span<const float, 3> AsFloatArray() const
{
// Additional check to prevent a weird compiler has a different
// alignement for an array and a class members.
@ -134,7 +134,7 @@ class CVector3D
offsetof(CVector3D, Y) == sizeof(float) &&
offsetof(CVector3D, Z) == sizeof(float) * 2u,
"Vector3D should be properly layouted to use AsFloatArray");
return std::span<const float>(&X, 3);
return std::span<const float, 3>(&X, 3);
}
};

View file

@ -126,7 +126,7 @@ public:
}
// Returns 4 element array of floats, e.g. for vec4 uniforms.
std::span<const float> AsFloatArray() const
std::span<const float, 4> AsFloatArray() const
{
// Additional check to prevent a weird compiler has a different
// alignement for an array and a class members.
@ -135,7 +135,7 @@ public:
offsetof(CVector4D, X) == 0 &&
offsetof(CVector4D, W) == sizeof(float) * 3u,
"CVector4D should be properly layouted to use AsFloatArray");
return std::span<const float>(&X, 4);
return std::span<const float, 4>(&X, 4);
}
float X, Y, Z, W;