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

@@ -15,6 +15,7 @@
#include <Nazara/Audio/Enums.hpp>
#include <Nazara/Audio/OpenAL.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/MovablePtr.hpp>
#include <array>
#include <string>
@@ -30,8 +31,6 @@ namespace Nz
Max = SourceLatency
};
constexpr std::size_t OpenALExtensionCount = static_cast<std::size_t>(OpenALExtension::Max) + 1;
class NAZARA_AUDIO_API OpenALDevice : public AudioDevice
{
friend OpenALLibrary;
@@ -72,8 +71,8 @@ namespace Nz
OpenALDevice& operator=(OpenALDevice&&) = delete;
private:
std::array<ALenum, AudioFormatCount> m_audioFormatValues;
std::array<bool, OpenALExtensionCount> m_extensionStatus;
EnumMap<AudioFormat, ALenum> m_audioFormatValues;
EnumMap<OpenALExtension, ALenum> m_extensionStatus;
std::string m_renderer;
std::string m_vendor;
OpenALLibrary& m_library;

View File

@@ -9,12 +9,12 @@ namespace Nz
{
inline bool OpenALDevice::IsExtensionSupported(OpenALExtension extension) const
{
return m_extensionStatus[UnderlyingCast(extension)];
return m_extensionStatus[extension];
}
inline ALenum OpenALDevice::TranslateAudioFormat(AudioFormat format) const
{
return m_audioFormatValues[UnderlyingCast(format)];
return m_audioFormatValues[format];
}
}

View File

@@ -10,6 +10,7 @@
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Enums.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array>
#include <string_view>
@@ -41,8 +42,8 @@ namespace Nz
void FetchCPUInfo();
void FetchMemoryInfo();
std::array<bool, ProcessorCapCount> m_cpuCapabilities;
std::array<char, 3 * 4 * 4> m_cpuBrandString;
EnumMap<ProcessorCap, bool> m_cpuCapabilities;
ProcessorVendor m_cpuVendor;
unsigned int m_cpuThreadCount;
UInt64 m_systemTotalMemory;

View File

@@ -29,7 +29,7 @@ namespace Nz
inline bool HardwareInfo::HasCapability(ProcessorCap capability) const
{
return m_cpuCapabilities[UnderlyingCast(capability)];
return m_cpuCapabilities[capability];
}
}

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++;

View File

@@ -15,6 +15,7 @@
#include <Nazara/Math/Plane.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array>
#include <string>
@@ -27,7 +28,7 @@ namespace Nz
{
public:
Frustum() = default;
explicit Frustum(const std::array<Plane<T>, FrustumPlaneCount>& planes);
explicit Frustum(const EnumMap<FrustumPlane, Plane<T>>& planes);
template<typename U> explicit Frustum(const Frustum<U>& frustum);
Frustum(const Frustum& frustum) = default;
~Frustum() = default;
@@ -63,7 +64,7 @@ namespace Nz
friend bool Unserialize(SerializationContext& context, Frustum<U>* frustum, TypeTag<Frustum<U>>);
private:
std::array<Plane<T>, FrustumPlaneCount> m_planes;
EnumMap<FrustumPlane, Plane<T>> m_planes;
};
using Frustumd = Frustum<double>;

View File

@@ -8,6 +8,7 @@
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <cstring>
#include <sstream>
#include <Nazara/Core/Debug.hpp>
@@ -30,7 +31,7 @@ namespace Nz
* \param planes Frustum of type U to convert to type T
*/
template<typename T>
Frustum<T>::Frustum(const std::array<Plane<T>, FrustumPlaneCount>& planes) :
Frustum<T>::Frustum(const EnumMap<FrustumPlane, Plane<T>>& planes) :
m_planes(planes)
{
}
@@ -44,8 +45,8 @@ namespace Nz
template<typename U>
Frustum<T>::Frustum(const Frustum<U>& frustum)
{
for (std::size_t i = 0; i < FrustumPlaneCount; ++i)
m_planes[i].Set(frustum.m_planes[i]);
for (auto&& [planeEnum, plane] : m_planes)
plane = Frustum(frustum.GetPlane(planeEnum));
}
/*!
@@ -129,9 +130,9 @@ namespace Nz
bool Frustum<T>::Contains(const Box<T>& box) const
{
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
for (unsigned int i = 0; i < FrustumPlaneCount; i++)
for (const auto& plane : m_planes)
{
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
if (plane.Distance(box.GetPositiveVertex(plane.normal)) < T(0.0))
return false;
}
@@ -161,9 +162,9 @@ namespace Nz
template<typename T>
bool Frustum<T>::Contains(const Sphere<T>& sphere) const
{
for (unsigned int i = 0; i < FrustumPlaneCount; i++)
for (const auto& plane : m_planes)
{
if (m_planes[i].Distance(sphere.GetPosition()) < -sphere.radius)
if (plane.Distance(sphere.GetPosition()) < -sphere.radius)
return false;
}
@@ -180,9 +181,9 @@ namespace Nz
template<typename T>
bool Frustum<T>::Contains(const Vector3<T>& point) const
{
for (unsigned int i = 0; i < FrustumPlaneCount; ++i)
for (const auto& plane : m_planes)
{
if (m_planes[i].Distance(point) < T(0.0))
if (plane.Distance(point) < T(0.0))
return false;
}
@@ -200,12 +201,12 @@ namespace Nz
template<typename T>
bool Frustum<T>::Contains(const Vector3<T>* points, std::size_t pointCount) const
{
for (std::size_t i = 0; i < FrustumPlaneCount; ++i)
for (const auto& plane : m_planes)
{
std::size_t j;
for (j = 0; j < pointCount; j++ )
{
if (m_planes[i].Distance(points[j]) > T(0.0))
if (plane.Distance(points[j]) > T(0.0))
break;
}
@@ -228,8 +229,8 @@ namespace Nz
template<typename T>
const Plane<T>& Frustum<T>::GetPlane(FrustumPlane plane) const
{
NazaraAssert(UnderlyingCast(plane) < FrustumPlaneCount, "invalid plane");
return m_planes[UnderlyingCast(plane)];
NazaraAssert(plane <= FrustumPlane::Max, "invalid plane");
return m_planes[plane];
}
/*!
@@ -292,11 +293,11 @@ namespace Nz
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
IntersectionSide side = IntersectionSide::Inside;
for (std::size_t i = 0; i < FrustumPlaneCount; i++)
for (const auto& plane : m_planes)
{
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
if (plane.Distance(box.GetPositiveVertex(plane.normal)) < T(0.0))
return IntersectionSide::Outside;
else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < T(0.0))
else if (plane.Distance(box.GetNegativeVertex(plane.normal)) < T(0.0))
side = IntersectionSide::Intersecting;
}
@@ -329,9 +330,9 @@ namespace Nz
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-points-and-spheres/
IntersectionSide side = IntersectionSide::Inside;
for (std::size_t i = 0; i < FrustumPlaneCount; i++)
for (const auto& plane : m_planes)
{
T distance = m_planes[i].Distance(sphere.GetPosition());
T distance = plane.Distance(sphere.GetPosition());
if (distance < -sphere.radius)
return IntersectionSide::Outside;
else if (distance < sphere.radius)
@@ -354,12 +355,12 @@ namespace Nz
{
std::size_t c = 0;
for (std::size_t i = 0; i < FrustumPlaneCount; ++i)
for (const auto& plane : m_planes)
{
std::size_t j;
for (j = 0; j < pointCount; j++ )
{
if (m_planes[i].Distance(points[j]) > T(0.0))
if (plane.Distance(points[j]) > T(0.0))
break;
}
@@ -418,25 +419,26 @@ namespace Nz
Vector3<T> fc = eye + f * zFar;
// Computing the frustum
std::array<Vector3<T>, BoxCornerCount> corners;
corners[UnderlyingCast(BoxCorner::FarLeftBottom)] = fc - u * farH - s * farW;
corners[UnderlyingCast(BoxCorner::FarLeftTop)] = fc + u * farH - s * farW;
corners[UnderlyingCast(BoxCorner::FarRightTop)] = fc + u * farH + s * farW;
corners[UnderlyingCast(BoxCorner::FarRightBottom)] = fc - u * farH + s * farW;
EnumMap<BoxCorner, Vector3<T>> corners;
corners[BoxCorner::FarLeftBottom] = fc - u * farH - s * farW;
corners[BoxCorner::FarLeftTop] = fc + u * farH - s * farW;
corners[BoxCorner::FarRightTop] = fc + u * farH + s * farW;
corners[BoxCorner::FarRightBottom] = fc - u * farH + s * farW;
corners[UnderlyingCast(BoxCorner::NearLeftBottom)] = nc - u * nearH - s * nearW;
corners[UnderlyingCast(BoxCorner::NearLeftTop)] = nc + u * nearH - s * nearW;
corners[UnderlyingCast(BoxCorner::NearRightTop)] = nc + u * nearH + s * nearW;
corners[UnderlyingCast(BoxCorner::NearRightBottom)] = nc - u * nearH + s * nearW;
corners[BoxCorner::NearLeftBottom] = nc - u * nearH - s * nearW;
corners[BoxCorner::NearLeftTop] = nc + u * nearH - s * nearW;
corners[BoxCorner::NearRightTop] = nc + u * nearH + s * nearW;
corners[BoxCorner::NearRightBottom] = nc - u * nearH + s * nearW;
// Construction of frustum's planes
std::array<Plane<T>, FrustumPlaneCount> planes;
planes[UnderlyingCast(FrustumPlane::Bottom)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)]);
planes[UnderlyingCast(FrustumPlane::Far)] = Plane(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)]);
planes[UnderlyingCast(FrustumPlane::Left)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)]);
planes[UnderlyingCast(FrustumPlane::Near)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::NearRightBottom)]);
planes[UnderlyingCast(FrustumPlane::Right)] = Plane(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::FarRightBottom)]);
planes[UnderlyingCast(FrustumPlane::Top)] = Plane(corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)]);
EnumMap<FrustumPlane, Plane<T>> planes;
planes[FrustumPlane::Bottom] = Plane(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearRightBottom], corners[BoxCorner::FarRightBottom]);
planes[FrustumPlane::Far] = Plane(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarLeftTop], corners[BoxCorner::FarLeftBottom]);
planes[FrustumPlane::Left] = Plane(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearLeftBottom], corners[BoxCorner::FarLeftBottom]);
planes[FrustumPlane::Near] = Plane(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearRightTop], corners[BoxCorner::NearRightBottom]);
planes[FrustumPlane::Right] = Plane(corners[BoxCorner::NearRightBottom], corners[BoxCorner::NearRightTop], corners[BoxCorner::FarRightBottom]);
planes[FrustumPlane::Top] = Plane(corners[BoxCorner::NearRightTop], corners[BoxCorner::NearLeftTop], corners[BoxCorner::FarLeftTop]);
return Frustum(planes);
}
@@ -454,7 +456,7 @@ namespace Nz
T plane[4];
T invLength;
std::array<Plane<T>, FrustumPlaneCount> planes;
EnumMap<FrustumPlane, Plane<T>> planes;
// Extract the numbers for the RIGHT plane
plane[0] = viewProjMatrix[3] - viewProjMatrix[0];
@@ -469,7 +471,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Right)] = Plane<T>(plane);
planes[FrustumPlane::Right] = Plane<T>(plane);
// Extract the numbers for the LEFT plane
plane[0] = viewProjMatrix[3] + viewProjMatrix[0];
@@ -484,7 +486,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Left)] = Plane<T>(plane);
planes[FrustumPlane::Left] = Plane<T>(plane);
// Extract the BOTTOM plane
plane[0] = viewProjMatrix[3] + viewProjMatrix[1];
@@ -499,7 +501,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Bottom)] = Plane<T>(plane);
planes[FrustumPlane::Bottom] = Plane<T>(plane);
// Extract the TOP plane
plane[0] = viewProjMatrix[3] - viewProjMatrix[1];
@@ -514,7 +516,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Top)] = Plane<T>(plane);
planes[FrustumPlane::Top] = Plane<T>(plane);
// Extract the FAR plane
plane[0] = viewProjMatrix[3] - viewProjMatrix[2];
@@ -529,7 +531,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Far)] = Plane<T>(plane);
planes[FrustumPlane::Far] = Plane<T>(plane);
// Extract the NEAR plane
plane[0] = viewProjMatrix[3] + viewProjMatrix[2];
@@ -544,7 +546,7 @@ namespace Nz
plane[2] *= invLength;
plane[3] *= -invLength;
planes[UnderlyingCast(FrustumPlane::Near)] = Plane<T>(plane);
planes[FrustumPlane::Near] = Plane<T>(plane);
return Frustum(planes);
}
@@ -559,9 +561,9 @@ namespace Nz
template<typename T>
bool Serialize(SerializationContext& context, const Frustum<T>& frustum, TypeTag<Frustum<T>>)
{
for (unsigned int i = 0; i < FrustumPlaneCount; ++i)
for (const auto& plane : frustum.m_planes)
{
if (!Serialize(context, frustum.m_planes[i]))
if (!Serialize(context, plane))
return false;
}
@@ -578,9 +580,9 @@ namespace Nz
template<typename T>
bool Unserialize(SerializationContext& context, Frustum<T>* frustum, TypeTag<Frustum<T>>)
{
for (unsigned int i = 0; i < FrustumPlaneCount; ++i)
for (auto& plane : frustum->m_planes)
{
if (!Unserialize(context, &frustum->m_planes[i]))
if (!Unserialize(context, &plane))
return false;
}

View File

@@ -11,6 +11,7 @@
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <string>
namespace Nz
@@ -53,7 +54,7 @@ namespace Nz
Box<T> localBox;
private:
Vector3<T> m_corners[BoxCornerCount];
EnumMap<BoxCorner, Vector3<T>> m_corners;
};
using OrientedBoxd = OrientedBox<double>;

View File

@@ -43,8 +43,8 @@ namespace Nz
OrientedBox<T>::OrientedBox(const OrientedBox<U>& orientedBox) :
localBox(orientedBox.localBox)
{
for (unsigned int i = 0; i < BoxCornerCount; ++i)
m_corners[i] = Vector3<T>(orientedBox(i));
for (auto&& [cornerEnum, corner] : m_corners.iter_kv())
corner = Vector3<T>(orientedBox.GetCorner(cornerEnum));
}
/*!
@@ -59,23 +59,14 @@ namespace Nz
template<typename T>
const Vector3<T>& OrientedBox<T>::GetCorner(BoxCorner corner) const
{
#ifdef NAZARA_DEBUG
if (UnderlyingCast(corner) > BoxCornerCount)
{
NazaraError("Corner not handled (0x" + NumberToString(UnderlyingCast(corner), 16) + ')');
static Vector3<T> dummy;
return dummy;
}
#endif
return m_corners[UnderlyingCast(corner)];
NazaraAssert(corner <= BoxCorner::Max, "invalid corner");
return m_corners[corner];
}
template<typename T>
const Vector3<T>* OrientedBox<T>::GetCorners() const
{
return &m_corners[0];
return &m_corners.front();
}
/*!
@@ -112,8 +103,8 @@ namespace Nz
template<typename T>
void OrientedBox<T>::Update(const Matrix4<T>& transformMatrix)
{
for (unsigned int i = 0; i < BoxCornerCount; ++i)
m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast<BoxCorner>(i)));
for (auto&& [corner, pos] : m_corners.iter_kv())
pos = transformMatrix.Transform(localBox.GetCorner(corner));
}
/*!
@@ -125,8 +116,8 @@ namespace Nz
template<typename T>
void OrientedBox<T>::Update(const Vector3<T>& translation)
{
for (unsigned int i = 0; i < BoxCornerCount; ++i)
m_corners[i] = localBox.GetCorner(static_cast<BoxCorner>(i)) + translation;
for (auto&& [corner, pos] : m_corners.iter_kv())
pos = localBox.GetCorner(corner) + translation;
}
/*!
@@ -140,18 +131,8 @@ namespace Nz
template<typename T>
Vector3<T>& OrientedBox<T>::operator()(unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= BoxCornerCount)
{
std::ostringstream ss;
ss << "Index out of range: (" << i << " >= " << BoxCornerCount << ")";
NazaraError(ss.str());
throw std::out_of_range(ss.str());
}
#endif
return m_corners[i];
NazaraAssert(i < m_corners.size(), "corner out of range");
return m_corners[static_cast<BoxCorner>(i)];
}
/*!
@@ -165,18 +146,8 @@ namespace Nz
template<typename T>
const Vector3<T>& OrientedBox<T>::operator()(unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= BoxCornerCount)
{
std::ostringstream ss;
ss << "Index out of range: (" << i << " >= " << BoxCornerCount << ")";
NazaraError(ss.str());
throw std::out_of_range(ss.str());
}
#endif
return m_corners[i];
NazaraAssert(i < m_corners.size(), "corner out of range");
return m_corners[static_cast<BoxCorner>(i)];
}
/*!
@@ -282,16 +253,16 @@ namespace Nz
* \param orientedBox The orientedBox to output
*/
template<typename T>
std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox<T>& orientedBox)
std::ostream& operator<<(std::ostream& out, const OrientedBox<T>& orientedBox)
{
return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftBottom) << ",\n"
<< " FLT: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftTop) << ",\n"
<< " FRB: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightBottom) << ",\n"
<< " FRT: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightTop) << ",\n"
<< " NLB: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftBottom) << ",\n"
<< " NLT: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftTop) << ",\n"
<< " NRB: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightBottom) << ",\n"
<< " NRT: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightTop) << ")\n";
return out << "OrientedBox(FLB: " << orientedBox.GetCorner(BoxCorner::FarLeftBottom) << ",\n"
<< " FLT: " << orientedBox.GetCorner(BoxCorner::FarLeftTop) << ",\n"
<< " FRB: " << orientedBox.GetCorner(BoxCorner::FarRightBottom) << ",\n"
<< " FRT: " << orientedBox.GetCorner(BoxCorner::FarRightTop) << ",\n"
<< " NLB: " << orientedBox.GetCorner(BoxCorner::NearLeftBottom) << ",\n"
<< " NLT: " << orientedBox.GetCorner(BoxCorner::NearLeftTop) << ",\n"
<< " NRB: " << orientedBox.GetCorner(BoxCorner::NearRightBottom) << ",\n"
<< " NRT: " << orientedBox.GetCorner(BoxCorner::NearRightTop) << ")\n";
}
}

View File

@@ -16,6 +16,7 @@
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array>
#include <string>
#include <unordered_set>
@@ -256,10 +257,10 @@ namespace Nz::GL
struct TextureUnit
{
GLuint sampler = 0;
std::array<GLuint, UnderlyingCast(TextureTarget::Max) + 1> textureTargets = { 0 };
EnumMap<TextureTarget, GLuint> textureTargets = { 0 };
};
std::array<GLuint, UnderlyingCast(BufferTarget::Max) + 1> bufferTargets = { 0 };
EnumMap<BufferTarget, GLuint> bufferTargets = { 0 };
std::vector<BufferBinding> storageUnits;
std::vector<BufferBinding> uboUnits;
std::vector<ImageUnits> imageUnits;
@@ -274,7 +275,7 @@ namespace Nz::GL
RenderStates renderStates;
};
std::array<ExtensionStatus, UnderlyingCast(Extension::Max) + 1> m_extensionStatus;
EnumMap<Extension, ExtensionStatus> m_extensionStatus;
std::array<GLFunction, UnderlyingCast(FunctionIndex::Count)> m_originalFunctionPointer;
mutable std::unique_ptr<BlitFramebuffers> m_blitFramebuffers;
std::unordered_set<std::string> m_supportedExtensions;

View File

@@ -37,7 +37,7 @@ namespace Nz::GL
inline ExtensionStatus Context::GetExtensionStatus(Extension extension) const
{
return m_extensionStatus[UnderlyingCast(extension)];
return m_extensionStatus[extension];
}
inline float Context::GetFloat(GLenum name) const

View File

@@ -12,6 +12,7 @@
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Utility/Image.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array>
namespace Nz
@@ -53,7 +54,7 @@ namespace Nz
SystemCursor m_systemCursor;
std::unique_ptr<CursorImpl> m_impl;
static std::array<std::shared_ptr<Cursor>, SystemCursorCount> s_systemCursors;
static EnumMap<SystemCursor, std::shared_ptr<Cursor>> s_systemCursors;
};
}

View File

@@ -20,7 +20,7 @@ namespace Nz
inline std::shared_ptr<Cursor>& Cursor::Get(SystemCursor cursor)
{
return s_systemCursors[UnderlyingCast(cursor)];
return s_systemCursors[cursor];
}
}

View File

@@ -2,6 +2,7 @@
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <NazaraUtils/EnumMap.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
@@ -27,22 +28,22 @@ namespace Nz
inline void DebugDrawer::DrawFrustum(const Frustumf& frustum, const Color& color)
{
std::array<Vector3f, BoxCornerCount> corners;
for (std::size_t i = 0; i < BoxCornerCount; ++i)
corners[i] = frustum.ComputeCorner(static_cast<BoxCorner>(i));
EnumMap<BoxCorner, Vector3f> corners;
for (auto&& [corner, pos] : corners.iter_kv())
pos = frustum.ComputeCorner(corner);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearRightBottom)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearLeftTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color);
DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearRightBottom], color);
DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearLeftTop], color);
DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::FarLeftBottom], color);
DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarRightBottom], color);
DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarRightBottom], color);
DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::FarRightBottom], color);
}
inline void DebugDrawer::DrawLine(const Vector3f& start, const Vector3f& end, const Color& color)

View File

@@ -12,6 +12,7 @@
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <NazaraUtils/Bitset.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array>
#include <functional>
@@ -88,9 +89,9 @@ namespace Nz
static bool Initialize();
static void Uninitialize();
static std::array<std::array<ConvertFunction, PixelFormatCount>, PixelFormatCount> s_convertFunctions;
static std::array<std::array<PixelFormatInfo::FlipFunction, PixelFlippingCount>, PixelFormatCount> s_flipFunctions;
static std::array<PixelFormatDescription, PixelFormatCount> s_pixelFormatInfos;
static EnumMap<PixelFormat, EnumMap<PixelFormat, ConvertFunction>> s_convertFunctions;
static EnumMap<PixelFormat, EnumMap<PixelFlipping, FlipFunction>> s_flipFunctions;
static EnumMap<PixelFormat, PixelFormatDescription> s_pixelFormatInfos;
};
}

View File

@@ -197,16 +197,16 @@ namespace Nz
return true;
}
ConvertFunction func = s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)];
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported");
NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " is not supported");
return false;
}
if (!func(reinterpret_cast<const UInt8*>(start), reinterpret_cast<const UInt8*>(end), reinterpret_cast<UInt8*>(dst)))
{
NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " failed");
NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " failed");
return false;
}
@@ -215,7 +215,7 @@ namespace Nz
inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)].bitsPerPixel;
return s_pixelFormatInfos[format].bitsPerPixel;
}
inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format)
@@ -225,27 +225,27 @@ namespace Nz
inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)].content;
return s_pixelFormatInfos[format].content;
}
inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)];
return s_pixelFormatInfos[format];
}
inline const std::string& PixelFormatInfo::GetName(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)].name;
return s_pixelFormatInfos[format].name;
}
inline bool PixelFormatInfo::HasAlpha(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)].alphaMask.TestAny();
return s_pixelFormatInfos[format].alphaMask.TestAny();
}
inline bool PixelFormatInfo::IsCompressed(PixelFormat format)
{
return s_pixelFormatInfos[UnderlyingCast(format)].IsCompressed();
return s_pixelFormatInfos[format].IsCompressed();
}
inline bool PixelFormatInfo::IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat)
@@ -253,7 +253,7 @@ namespace Nz
if (srcFormat == dstFormat)
return true;
return s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] != nullptr;
return s_convertFunctions[srcFormat][dstFormat] != nullptr;
}
inline bool PixelFormatInfo::IsValid(PixelFormat format)
@@ -263,12 +263,12 @@ namespace Nz
inline void PixelFormatInfo::SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func)
{
s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] = func;
s_convertFunctions[srcFormat][dstFormat] = func;
}
inline void PixelFormatInfo::SetFlipFunction(PixelFlipping flipping, PixelFormat format, FlipFunction func)
{
s_flipFunctions[UnderlyingCast(flipping)][UnderlyingCast(format)] = func;
s_flipFunctions[format][flipping] = func;
}
}

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/SparsePtr.hpp>
#include <array>
#include <vector>
@@ -77,7 +78,7 @@ namespace Nz
std::size_t m_stride;
VertexInputRate m_inputRate;
static std::array<std::shared_ptr<VertexDeclaration>, VertexLayoutCount> s_declarations;
static EnumMap<VertexLayout, std::shared_ptr<VertexDeclaration>> s_declarations;
};
}

View File

@@ -74,8 +74,7 @@ namespace Nz
inline const std::shared_ptr<VertexDeclaration>& VertexDeclaration::Get(VertexLayout layout)
{
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
return s_declarations[UnderlyingCast(layout)];
return s_declarations[layout];
}
}

View File

@@ -13,6 +13,7 @@
#include <Nazara/VulkanRenderer/Config.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
#include <Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <vulkan/vulkan_core.h>
#include <array>
#include <memory>
@@ -105,16 +106,14 @@ namespace Nz
struct InternalData;
static constexpr std::size_t QueueCount = static_cast<std::size_t>(QueueType::Max) + 1;
std::unique_ptr<InternalData> m_internalData;
std::array<UInt32, QueueCount> m_defaultQueues;
std::unordered_set<std::string> m_loadedExtensions;
std::unordered_set<std::string> m_loadedLayers;
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
std::vector<const QueueList*> m_queuesByFamily;
Instance& m_instance;
const Vk::PhysicalDevice* m_physicalDevice;
EnumMap<QueueType, UInt32> m_defaultQueues;
VkAllocationCallbacks m_allocator;
VkDevice m_device;
VkResult m_lastErrorCode;

View File

@@ -13,7 +13,7 @@ namespace Nz::Vk
{
inline UInt32 Device::GetDefaultFamilyIndex(QueueType queueType) const
{
return m_defaultQueues[UnderlyingCast(queueType)];
return m_defaultQueues[queueType];
}
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const