Make use of the new EnumMap class

This commit is contained in:
SirLynix
2023-05-30 12:32:37 +02:00
parent d914f41404
commit dfe6b2ddcf
46 changed files with 354 additions and 379 deletions

View File

@@ -102,8 +102,6 @@ namespace Nz
Max = ViewerDataUbo
};
constexpr std::size_t PredefinedShaderBindingCount = static_cast<std::size_t>(EngineShaderBinding::Max) + 1;
}
#endif // NAZARA_GRAPHICS_ENUMS_HPP

View File

@@ -78,8 +78,8 @@ namespace Nz
struct DefaultTextures
{
std::array<std::shared_ptr<Texture>, ImageTypeCount> depthTextures;
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
EnumMap<ImageType, std::shared_ptr<Texture>> depthTextures;
EnumMap<ImageType, std::shared_ptr<Texture>> whiteTextures;
};
private:

View File

@@ -90,7 +90,6 @@ namespace Nz
};
private:
std::array<UInt32, PredefinedShaderBindingCount> m_engineShaderBindings;
std::shared_ptr<RenderPipelineLayout> m_renderPipelineLayout;
std::unordered_map<UInt32, nzsl::Ast::ConstantSingleValue> m_optionValues;
std::unordered_map<std::string /*tag*/, std::size_t> m_textureByTag;
@@ -98,6 +97,7 @@ namespace Nz
std::vector<TextureData> m_textures;
std::vector<UniformBlockData> m_uniformBlocks;
mutable std::weak_ptr<MaterialInstance> m_defaultInstance;
EnumMap<EngineShaderBinding, UInt32> m_engineShaderBindings;
MaterialSettings m_settings;
ShaderReflection m_reflection;
};

View File

@@ -26,7 +26,7 @@ namespace Nz
inline UInt32 Material::GetEngineBindingIndex(EngineShaderBinding shaderBinding) const
{
return m_engineShaderBindings[UnderlyingCast(shaderBinding)];
return m_engineShaderBindings[shaderBinding];
}
inline const std::shared_ptr<RenderPipelineLayout>& Material::GetRenderPipelineLayout() const

View File

@@ -50,7 +50,7 @@ namespace Nz
private:
inline void UpdateVertices();
std::array<Color, RectCornerCount> m_cornerColor;
EnumMap<RectCorner, Color> m_cornerColor;
std::array<VertexStruct_XYZ_Color_UV, 4> m_vertices;
std::shared_ptr<MaterialInstance> m_material;
Color m_color;

View File

@@ -14,7 +14,7 @@ namespace Nz
inline const Color& Sprite::GetCornerColor(RectCorner corner) const
{
return m_cornerColor[UnderlyingCast(corner)];
return m_cornerColor[corner];
}
inline const Vector2f& Sprite::GetOrigin() const
@@ -41,7 +41,7 @@ namespace Nz
inline void Sprite::SetCornerColor(RectCorner corner, const Color& color)
{
m_cornerColor[UnderlyingCast(corner)] = color;
m_cornerColor[corner] = color;
UpdateVertices();
}
@@ -90,18 +90,18 @@ namespace Nz
{
VertexStruct_XYZ_Color_UV* vertices = m_vertices.data();
std::array<Vector2f, RectCornerCount> cornerExtent;
cornerExtent[UnderlyingCast(RectCorner::LeftBottom)] = Vector2f(0.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::RightBottom)] = Vector2f(1.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::LeftTop)] = Vector2f(0.f, 1.f);
cornerExtent[UnderlyingCast(RectCorner::RightTop)] = Vector2f(1.f, 1.f);
EnumMap<RectCorner, Vector2f> cornerExtent;
cornerExtent[RectCorner::LeftBottom] = Vector2f(0.f, 0.f);
cornerExtent[RectCorner::RightBottom] = Vector2f(1.f, 0.f);
cornerExtent[RectCorner::LeftTop] = Vector2f(0.f, 1.f);
cornerExtent[RectCorner::RightTop] = Vector2f(1.f, 1.f);
Vector3f originShift = m_origin * m_size;
for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop })
{
vertices->color = m_color * m_cornerColor[UnderlyingCast(corner)];
vertices->position = Vector3f(m_size * cornerExtent[UnderlyingCast(corner)], 0.f) - originShift;
vertices->color = m_color * m_cornerColor[corner];
vertices->position = Vector3f(m_size * cornerExtent[corner], 0.f) - originShift;
vertices->uv = m_textureCoords.GetCorner(corner);
vertices++;