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

View File

@ -9,12 +9,12 @@ namespace Nz
{ {
inline bool OpenALDevice::IsExtensionSupported(OpenALExtension extension) const inline bool OpenALDevice::IsExtensionSupported(OpenALExtension extension) const
{ {
return m_extensionStatus[UnderlyingCast(extension)]; return m_extensionStatus[extension];
} }
inline ALenum OpenALDevice::TranslateAudioFormat(AudioFormat format) const 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 <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp> #include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Enums.hpp> #include <Nazara/Core/Enums.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array> #include <array>
#include <string_view> #include <string_view>
@ -41,8 +42,8 @@ namespace Nz
void FetchCPUInfo(); void FetchCPUInfo();
void FetchMemoryInfo(); void FetchMemoryInfo();
std::array<bool, ProcessorCapCount> m_cpuCapabilities;
std::array<char, 3 * 4 * 4> m_cpuBrandString; std::array<char, 3 * 4 * 4> m_cpuBrandString;
EnumMap<ProcessorCap, bool> m_cpuCapabilities;
ProcessorVendor m_cpuVendor; ProcessorVendor m_cpuVendor;
unsigned int m_cpuThreadCount; unsigned int m_cpuThreadCount;
UInt64 m_systemTotalMemory; UInt64 m_systemTotalMemory;

View File

@ -29,7 +29,7 @@ namespace Nz
inline bool HardwareInfo::HasCapability(ProcessorCap capability) const 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 Max = ViewerDataUbo
}; };
constexpr std::size_t PredefinedShaderBindingCount = static_cast<std::size_t>(EngineShaderBinding::Max) + 1;
} }
#endif // NAZARA_GRAPHICS_ENUMS_HPP #endif // NAZARA_GRAPHICS_ENUMS_HPP

View File

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

View File

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

View File

@ -26,7 +26,7 @@ namespace Nz
inline UInt32 Material::GetEngineBindingIndex(EngineShaderBinding shaderBinding) const 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 inline const std::shared_ptr<RenderPipelineLayout>& Material::GetRenderPipelineLayout() const

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,6 +12,7 @@
#include <Nazara/Platform/Config.hpp> #include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Enums.hpp> #include <Nazara/Platform/Enums.hpp>
#include <Nazara/Utility/Image.hpp> #include <Nazara/Utility/Image.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array> #include <array>
namespace Nz namespace Nz
@ -53,7 +54,7 @@ namespace Nz
SystemCursor m_systemCursor; SystemCursor m_systemCursor;
std::unique_ptr<CursorImpl> m_impl; 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) 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" // This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <NazaraUtils/EnumMap.hpp>
#include <Nazara/Renderer/Debug.hpp> #include <Nazara/Renderer/Debug.hpp>
namespace Nz namespace Nz
@ -27,22 +28,22 @@ namespace Nz
inline void DebugDrawer::DrawFrustum(const Frustumf& frustum, const Color& color) inline void DebugDrawer::DrawFrustum(const Frustumf& frustum, const Color& color)
{ {
std::array<Vector3f, BoxCornerCount> corners; EnumMap<BoxCorner, Vector3f> corners;
for (std::size_t i = 0; i < BoxCornerCount; ++i) for (auto&& [corner, pos] : corners.iter_kv())
corners[i] = frustum.ComputeCorner(static_cast<BoxCorner>(i)); pos = frustum.ComputeCorner(corner);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearRightBottom)], color); DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearRightBottom], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearLeftTop)], color); DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearLeftTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)], color); DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::FarLeftBottom], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarRightBottom], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarRightBottom], color);
DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::FarLeftTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::NearRightTop], color);
DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::FarRightBottom], color);
} }
inline void DebugDrawer::DrawLine(const Vector3f& start, const Vector3f& end, const Color& 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/Config.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
#include <NazaraUtils/Bitset.hpp> #include <NazaraUtils/Bitset.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <array> #include <array>
#include <functional> #include <functional>
@ -88,9 +89,9 @@ namespace Nz
static bool Initialize(); static bool Initialize();
static void Uninitialize(); static void Uninitialize();
static std::array<std::array<ConvertFunction, PixelFormatCount>, PixelFormatCount> s_convertFunctions; static EnumMap<PixelFormat, EnumMap<PixelFormat, ConvertFunction>> s_convertFunctions;
static std::array<std::array<PixelFormatInfo::FlipFunction, PixelFlippingCount>, PixelFormatCount> s_flipFunctions; static EnumMap<PixelFormat, EnumMap<PixelFlipping, FlipFunction>> s_flipFunctions;
static std::array<PixelFormatDescription, PixelFormatCount> s_pixelFormatInfos; static EnumMap<PixelFormat, PixelFormatDescription> s_pixelFormatInfos;
}; };
} }

View File

@ -197,16 +197,16 @@ namespace Nz
return true; return true;
} }
ConvertFunction func = s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)]; ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func) 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; return false;
} }
if (!func(reinterpret_cast<const UInt8*>(start), reinterpret_cast<const UInt8*>(end), reinterpret_cast<UInt8*>(dst))) 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; return false;
} }
@ -215,7 +215,7 @@ namespace Nz
inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format) inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format)
{ {
return s_pixelFormatInfos[UnderlyingCast(format)].bitsPerPixel; return s_pixelFormatInfos[format].bitsPerPixel;
} }
inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format) inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format)
@ -225,27 +225,27 @@ namespace Nz
inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format) inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format)
{ {
return s_pixelFormatInfos[UnderlyingCast(format)].content; return s_pixelFormatInfos[format].content;
} }
inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format) inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format)
{ {
return s_pixelFormatInfos[UnderlyingCast(format)]; return s_pixelFormatInfos[format];
} }
inline const std::string& PixelFormatInfo::GetName(PixelFormat 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) 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) 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) inline bool PixelFormatInfo::IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat)
@ -253,7 +253,7 @@ namespace Nz
if (srcFormat == dstFormat) if (srcFormat == dstFormat)
return true; return true;
return s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] != nullptr; return s_convertFunctions[srcFormat][dstFormat] != nullptr;
} }
inline bool PixelFormatInfo::IsValid(PixelFormat format) inline bool PixelFormatInfo::IsValid(PixelFormat format)
@ -263,12 +263,12 @@ namespace Nz
inline void PixelFormatInfo::SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func) 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) 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/Core/ObjectLibrary.hpp>
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/SparsePtr.hpp> #include <NazaraUtils/SparsePtr.hpp>
#include <array> #include <array>
#include <vector> #include <vector>
@ -77,7 +78,7 @@ namespace Nz
std::size_t m_stride; std::size_t m_stride;
VertexInputRate m_inputRate; 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) inline const std::shared_ptr<VertexDeclaration>& VertexDeclaration::Get(VertexLayout layout)
{ {
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum"); NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
return s_declarations[layout];
return s_declarations[UnderlyingCast(layout)];
} }
} }

View File

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

View File

@ -13,7 +13,7 @@ namespace Nz::Vk
{ {
inline UInt32 Device::GetDefaultFamilyIndex(QueueType queueType) const 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 inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const

View File

@ -33,23 +33,23 @@ namespace Nz
// We complete the formats table // We complete the formats table
m_audioFormatValues.fill(0); m_audioFormatValues.fill(0);
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Mono)] = AL_FORMAT_MONO16; m_audioFormatValues[AudioFormat::I16_Mono] = AL_FORMAT_MONO16;
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Stereo)] = AL_FORMAT_STEREO16; m_audioFormatValues[AudioFormat::I16_Stereo] = AL_FORMAT_STEREO16;
// "The presence of an enum value does not guarantee the applicability of an extension to the current context." // "The presence of an enum value does not guarantee the applicability of an extension to the current context."
if (library.alIsExtensionPresent("AL_EXT_MCFORMATS")) if (library.alIsExtensionPresent("AL_EXT_MCFORMATS"))
{ {
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16"); m_audioFormatValues[AudioFormat::I16_Quad] = m_library.alGetEnumValue("AL_FORMAT_QUAD16");
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_5_1)] = m_library.alGetEnumValue("AL_FORMAT_51CHN16"); m_audioFormatValues[AudioFormat::I16_5_1] = m_library.alGetEnumValue("AL_FORMAT_51CHN16");
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_6_1)] = m_library.alGetEnumValue("AL_FORMAT_61CHN16"); m_audioFormatValues[AudioFormat::I16_6_1] = m_library.alGetEnumValue("AL_FORMAT_61CHN16");
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_7_1)] = m_library.alGetEnumValue("AL_FORMAT_71CHN16"); m_audioFormatValues[AudioFormat::I16_7_1] = m_library.alGetEnumValue("AL_FORMAT_71CHN16");
} }
else if (library.alIsExtensionPresent("AL_LOKI_quadriphonic")) else if (library.alIsExtensionPresent("AL_LOKI_quadriphonic"))
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16_LOKI"); m_audioFormatValues[AudioFormat::I16_Quad] = m_library.alGetEnumValue("AL_FORMAT_QUAD16_LOKI");
m_extensionStatus.fill(false); m_extensionStatus.fill(false);
if (library.alIsExtensionPresent("AL_SOFT_source_latency")) if (library.alIsExtensionPresent("AL_SOFT_source_latency"))
m_extensionStatus[UnderlyingCast(OpenALExtension::SourceLatency)] = true; m_extensionStatus[OpenALExtension::SourceLatency] = true;
SetListenerDirection(Vector3f::Forward()); SetListenerDirection(Vector3f::Forward());
} }
@ -226,7 +226,7 @@ namespace Nz
if (format == AudioFormat::Unknown) if (format == AudioFormat::Unknown)
return false; return false;
return m_audioFormatValues[UnderlyingCast(format)] != 0; return m_audioFormatValues[format] != 0;
} }
/*! /*!

View File

@ -4,6 +4,7 @@
#include <Nazara/Core/AbstractLogger.hpp> #include <Nazara/Core/AbstractLogger.hpp>
#include <Nazara/Core/Algorithm.hpp> #include <Nazara/Core/Algorithm.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <sstream> #include <sstream>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
@ -11,14 +12,12 @@ namespace Nz
{ {
namespace NAZARA_ANONYMOUS_NAMESPACE namespace NAZARA_ANONYMOUS_NAMESPACE
{ {
const char* errorType[] = { constexpr EnumMap<ErrorType, std::string_view> s_errorTypes = {
"Assert failed: ", // ErrorType::AssertFailed "Assert failed: ", // ErrorType::AssertFailed
"Internal error: ", // ErrorType::Internal "Internal error: ", // ErrorType::Internal
"Error: ", // ErrorType::Normal "Error: ", // ErrorType::Normal
"Warning: " // ErrorType::Warning "Warning: " // ErrorType::Warning
}; };
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete");
} }
/*! /*!
@ -44,7 +43,7 @@ namespace Nz
NAZARA_USE_ANONYMOUS_NAMESPACE NAZARA_USE_ANONYMOUS_NAMESPACE
std::ostringstream ss; std::ostringstream ss;
ss << errorType[UnderlyingCast(type)] << error; ss << s_errorTypes[type] << error;
if (line != 0 && file && function) if (line != 0 && file && function)
ss << " (" << file << ':' << line << ": " << function << ')'; ss << " (" << file << ':' << line << ": " << function << ')';

View File

@ -4,6 +4,7 @@
#include <Nazara/Core/HardwareInfo.hpp> #include <Nazara/Core/HardwareInfo.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <frozen/string.h> #include <frozen/string.h>
#include <frozen/unordered_map.h> #include <frozen/unordered_map.h>
#include <algorithm> #include <algorithm>
@ -23,34 +24,34 @@ namespace Nz
{ {
namespace NAZARA_ANONYMOUS_NAMESPACE namespace NAZARA_ANONYMOUS_NAMESPACE
{ {
constexpr std::array s_vendorNames = { constexpr EnumMap<ProcessorVendor, std::string_view> s_vendorNames {
std::string_view("ACRN"), // ProcessorVendor::ACRN "ACRN", // ProcessorVendor::ACRN
std::string_view("Advanced Micro Devices"), // ProcessorVendor::AMD "Advanced Micro Devices", // ProcessorVendor::AMD
std::string_view("ao486"), // ProcessorVendor::Ao486 "ao486", // ProcessorVendor::Ao486
std::string_view("Apple Rosetta 2"), // ProcessorVendor::AppleRosetta2 "Apple Rosetta 2", // ProcessorVendor::AppleRosetta2
std::string_view("bhyve"), // ProcessorVendor::Bhyve "bhyve", // ProcessorVendor::Bhyve
std::string_view("Centaur Technology"), // ProcessorVendor::Centaur "Centaur Technology", // ProcessorVendor::Centaur
std::string_view("Cyrix Corporation"), // ProcessorVendor::Cyrix "Cyrix Corporation", // ProcessorVendor::Cyrix
std::string_view("MCST Elbrus"), // ProcessorVendor::Elbrus "MCST Elbrus", // ProcessorVendor::Elbrus
std::string_view("Hygon"), // ProcessorVendor::Hygon "Hygon", // ProcessorVendor::Hygon
std::string_view("Microsoft Hyper-V"), // ProcessorVendor::HyperV "Microsoft Hyper-V", // ProcessorVendor::HyperV
std::string_view("Intel Corporation"), // ProcessorVendor::Intel "Intel Corporation", // ProcessorVendor::Intel
std::string_view("Kernel-based Virtual Machine"), // ProcessorVendor::KVM "Kernel-based Virtual Machine", // ProcessorVendor::KVM
std::string_view("Microsoft x86-to-ARM"), // ProcessorVendor::MicrosoftXTA "Microsoft x86-to-ARM", // ProcessorVendor::MicrosoftXTA
std::string_view("National Semiconductor"), // ProcessorVendor::NSC "National Semiconductor", // ProcessorVendor::NSC
std::string_view("NexGen"), // ProcessorVendor::NexGen "NexGen", // ProcessorVendor::NexGen
std::string_view("Parallels"), // ProcessorVendor::Parallels "Parallels", // ProcessorVendor::Parallels
std::string_view("QEMU"), // ProcessorVendor::QEMU "QEMU", // ProcessorVendor::QEMU
std::string_view("QNX Hypervisor"), // ProcessorVendor::QNX "QNX Hypervisor", // ProcessorVendor::QNX
std::string_view("Rise Technology"), // ProcessorVendor::Rise "Rise Technology", // ProcessorVendor::Rise
std::string_view("Silicon Integrated Systems"), // ProcessorVendor::SiS "Silicon Integrated Systems", // ProcessorVendor::SiS
std::string_view("Transmeta Corporation"), // ProcessorVendor::Transmeta "Transmeta Corporation", // ProcessorVendor::Transmeta
std::string_view("United Microelectronics Corporation"), // ProcessorVendor::UMC "United Microelectronics Corporation", // ProcessorVendor::UMC
std::string_view("VIA Technologies"), // ProcessorVendor::VIA "VIA Technologies", // ProcessorVendor::VIA
std::string_view("VMware"), // ProcessorVendor::VMware "VMware", // ProcessorVendor::VMware
std::string_view("Vortex86"), // ProcessorVendor::Vortex "Vortex86", // ProcessorVendor::Vortex
std::string_view("Xen"), // ProcessorVendor::XenHVM "Xen", // ProcessorVendor::XenHVM
std::string_view("Zhaoxin)") // ProcessorVendor::Zhaoxin "Zhaoxin" // ProcessorVendor::Zhaoxin
}; };
static_assert(s_vendorNames.size() == ProcessorVendorCount, "Processor vendor name array is incomplete"); static_assert(s_vendorNames.size() == ProcessorVendorCount, "Processor vendor name array is incomplete");
@ -111,7 +112,7 @@ namespace Nz
{ {
NAZARA_USE_ANONYMOUS_NAMESPACE NAZARA_USE_ANONYMOUS_NAMESPACE
return s_vendorNames[UnderlyingCast(m_cpuVendor)]; return s_vendorNames[m_cpuVendor];
} }
void HardwareInfo::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]) void HardwareInfo::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4])
@ -160,18 +161,18 @@ namespace Nz
// Retrieval of certain capacities of the processor (ECX and EDX, function 1) // Retrieval of certain capacities of the processor (ECX and EDX, function 1)
HardwareInfoImpl::Cpuid(1, 0, registers.data()); HardwareInfoImpl::Cpuid(1, 0, registers.data());
m_cpuCapabilities[UnderlyingCast(ProcessorCap::AES)] = (ecx & (1U << 25)) != 0; m_cpuCapabilities[ProcessorCap::AES] = (ecx & (1U << 25)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::AVX)] = (ecx & (1U << 28)) != 0; m_cpuCapabilities[ProcessorCap::AVX] = (ecx & (1U << 28)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::FMA3)] = (ecx & (1U << 12)) != 0; m_cpuCapabilities[ProcessorCap::FMA3] = (ecx & (1U << 12)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::MMX)] = (edx & (1U << 23)) != 0; m_cpuCapabilities[ProcessorCap::MMX] = (edx & (1U << 23)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::Popcnt)] = (ecx & (1U << 23)) != 0; m_cpuCapabilities[ProcessorCap::Popcnt] = (ecx & (1U << 23)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::RDRAND)] = (ecx & (1U << 30)) != 0; m_cpuCapabilities[ProcessorCap::RDRAND] = (ecx & (1U << 30)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE)] = (edx & (1U << 25)) != 0; m_cpuCapabilities[ProcessorCap::SSE] = (edx & (1U << 25)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE2)] = (edx & (1U << 26)) != 0; m_cpuCapabilities[ProcessorCap::SSE2] = (edx & (1U << 26)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE3)] = (ecx & (1U << 0)) != 0; m_cpuCapabilities[ProcessorCap::SSE3] = (ecx & (1U << 0)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSSE3)] = (ecx & (1U << 9)) != 0; m_cpuCapabilities[ProcessorCap::SSSE3] = (ecx & (1U << 9)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE41)] = (ecx & (1U << 19)) != 0; m_cpuCapabilities[ProcessorCap::SSE41] = (ecx & (1U << 19)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE42)] = (ecx & (1U << 20)) != 0; m_cpuCapabilities[ProcessorCap::SSE42] = (ecx & (1U << 20)) != 0;
} }
// Retrieval of biggest extended function handled (EAX, function 0x80000000) // Retrieval of biggest extended function handled (EAX, function 0x80000000)
@ -183,10 +184,10 @@ namespace Nz
// Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001) // Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001)
HardwareInfoImpl::Cpuid(0x80000001, 0, registers.data()); HardwareInfoImpl::Cpuid(0x80000001, 0, registers.data());
m_cpuCapabilities[UnderlyingCast(ProcessorCap::x64)] = (edx & (1U << 29)) != 0; // Support of 64bits, doesn't mean executable is 64bits m_cpuCapabilities[ProcessorCap::x64] = (edx & (1U << 29)) != 0; // Support of 64bits, doesn't mean executable is 64bits
m_cpuCapabilities[UnderlyingCast(ProcessorCap::FMA4)] = (ecx & (1U << 16)) != 0; m_cpuCapabilities[ProcessorCap::FMA4] = (ecx & (1U << 16)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE4a)] = (ecx & (1U << 6)) != 0; m_cpuCapabilities[ProcessorCap::SSE4a] = (ecx & (1U << 6)) != 0;
m_cpuCapabilities[UnderlyingCast(ProcessorCap::XOP)] = (ecx & (1U << 11)) != 0; m_cpuCapabilities[ProcessorCap::XOP] = (ecx & (1U << 11)) != 0;
if (maxSupportedExtendedFunction >= 0x80000004) if (maxSupportedExtendedFunction >= 0x80000004)
{ {

View File

@ -4,6 +4,7 @@
#include <Nazara/Core/StdLogger.hpp> #include <Nazara/Core/StdLogger.hpp>
#include <Nazara/Core/Algorithm.hpp> #include <Nazara/Core/Algorithm.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <cstdio> #include <cstdio>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
@ -11,14 +12,12 @@ namespace Nz
{ {
namespace NAZARA_ANONYMOUS_NAMESPACE namespace NAZARA_ANONYMOUS_NAMESPACE
{ {
const char* errorType[] = { constexpr EnumMap<ErrorType, std::string_view> s_errorTypes = {
"Assert failed", // ErrorType::AssertFailed "Assert failed: ", // ErrorType::AssertFailed
"Internal error", // ErrorType::Internal "Internal error: ", // ErrorType::Internal
"Error", // ErrorType::Normal "Error: ", // ErrorType::Normal
"Warning" // ErrorType::Warning "Warning: " // ErrorType::Warning
}; };
static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete");
} }
/*! /*!
@ -83,7 +82,7 @@ namespace Nz
{ {
NAZARA_USE_ANONYMOUS_NAMESPACE NAZARA_USE_ANONYMOUS_NAMESPACE
fprintf(stderr, "%s: ", errorType[UnderlyingCast(type)]); fprintf(stderr, "%s: ", s_errorTypes[type]);
fwrite(error.data(), sizeof(char), error.size(), stdout); fwrite(error.data(), sizeof(char), error.size(), stdout);
if (line != 0 && file && function) if (line != 0 && file && function)

View File

@ -353,15 +353,15 @@ namespace Nz
std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
for (std::size_t i = 0; i < ImageTypeCount; ++i) for (auto&& [imageType, texture] : m_defaultTextures.depthTextures.iter_kv())
{ {
texInfo.type = static_cast<ImageType>(i); if (imageType == ImageType::E3D)
if (texInfo.type == ImageType::E3D)
continue; continue;
texInfo.layerCount = (texInfo.type == ImageType::Cubemap) ? 6 : 1; texInfo.type = imageType;
texInfo.layerCount = (imageType == ImageType::Cubemap) ? 6 : 1;
m_defaultTextures.depthTextures[i] = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); texture = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false);
} }
} }
@ -373,12 +373,12 @@ namespace Nz
std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; std::array<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
for (std::size_t i = 0; i < ImageTypeCount; ++i) for (auto&& [imageType, texture] : m_defaultTextures.whiteTextures.iter_kv())
{ {
texInfo.type = static_cast<ImageType>(i); texInfo.type = imageType;
texInfo.layerCount = (texInfo.type == ImageType::Cubemap) ? 6 : 1; texInfo.layerCount = (imageType == ImageType::Cubemap) ? 6 : 1;
m_defaultTextures.whiteTextures[i] = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); texture = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false);
} }
} }
} }

View File

@ -42,7 +42,7 @@ namespace Nz
}; };
const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1);
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D];
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox)); elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox));
} }

View File

@ -86,25 +86,25 @@ namespace Nz
// TODO: Ensure structs layout is what's expected // TODO: Ensure structs layout is what's expected
if (auto it = block->uniformBlocks.find("InstanceData"); it != block->uniformBlocks.end()) if (auto it = block->uniformBlocks.find("InstanceData"); it != block->uniformBlocks.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::InstanceDataUbo)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::InstanceDataUbo] = it->second.bindingIndex;
if (auto it = block->uniformBlocks.find("LightData"); it != block->uniformBlocks.end()) if (auto it = block->uniformBlocks.find("LightData"); it != block->uniformBlocks.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::LightDataUbo)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::LightDataUbo] = it->second.bindingIndex;
if (auto it = block->uniformBlocks.find("ViewerData"); it != block->uniformBlocks.end()) if (auto it = block->uniformBlocks.find("ViewerData"); it != block->uniformBlocks.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::ViewerDataUbo)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::ViewerDataUbo] = it->second.bindingIndex;
if (auto it = block->samplers.find("ShadowMaps2D"); it != block->samplers.end()) if (auto it = block->samplers.find("ShadowMaps2D"); it != block->samplers.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::Shadowmap2D)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::Shadowmap2D] = it->second.bindingIndex;
if (auto it = block->samplers.find("ShadowMapsCube"); it != block->samplers.end()) if (auto it = block->samplers.find("ShadowMapsCube"); it != block->samplers.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::ShadowmapCube)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::ShadowmapCube] = it->second.bindingIndex;
if (auto it = block->uniformBlocks.find("SkeletalData"); it != block->uniformBlocks.end()) if (auto it = block->uniformBlocks.find("SkeletalData"); it != block->uniformBlocks.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::SkeletalDataUbo)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::SkeletalDataUbo] = it->second.bindingIndex;
if (auto it = block->samplers.find("TextureOverlay"); it != block->samplers.end()) if (auto it = block->samplers.find("TextureOverlay"); it != block->samplers.end())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::OverlayTexture)] = it->second.bindingIndex; m_engineShaderBindings[EngineShaderBinding::OverlayTexture] = it->second.bindingIndex;
} }
for (const auto& handlerPtr : m_settings.GetPropertyHandlers()) for (const auto& handlerPtr : m_settings.GetPropertyHandlers())

View File

@ -145,7 +145,7 @@ namespace Nz
const auto& textureSlot = m_parent->GetTextureData(i); const auto& textureSlot = m_parent->GetTextureData(i);
const auto& textureBinding = m_textureBinding[i]; const auto& textureBinding = m_textureBinding[i];
const std::shared_ptr<Texture>& texture = (textureBinding.texture) ? textureBinding.texture : defaultTextures.whiteTextures[UnderlyingCast(textureSlot.imageType)]; const std::shared_ptr<Texture>& texture = (textureBinding.texture) ? textureBinding.texture : defaultTextures.whiteTextures[textureSlot.imageType];
const std::shared_ptr<TextureSampler>& sampler = (textureBinding.sampler) ? textureBinding.sampler : Graphics::Instance()->GetSamplerCache().Get({}); const std::shared_ptr<TextureSampler>& sampler = (textureBinding.sampler) ? textureBinding.sampler : Graphics::Instance()->GetSamplerCache().Get({});
bindings.push_back({ bindings.push_back({

View File

@ -37,7 +37,7 @@ namespace Nz
}; };
const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1);
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D];
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox)); elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox));
} }

View File

@ -40,7 +40,7 @@ namespace Nz
}; };
const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1);
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D];
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data(), *elementData.scissorBox)); elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data(), *elementData.scissorBox));
} }

View File

@ -54,9 +54,9 @@ namespace Nz
currentShaderBinding = nullptr; currentShaderBinding = nullptr;
}; };
const auto& depthTexture2D = Graphics::Instance()->GetDefaultTextures().depthTextures[UnderlyingCast(ImageType::E2D)]; const auto& depthTexture2D = Graphics::Instance()->GetDefaultTextures().depthTextures[ImageType::E2D];
const auto& depthTextureCube = Graphics::Instance()->GetDefaultTextures().depthTextures[UnderlyingCast(ImageType::Cubemap)]; const auto& depthTextureCube = Graphics::Instance()->GetDefaultTextures().depthTextures[ImageType::Cubemap];
const auto& whiteTexture2D = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& whiteTexture2D = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D];
const auto& defaultSampler = graphics->GetSamplerCache().Get({}); const auto& defaultSampler = graphics->GetSamplerCache().Get({});
TextureSamplerInfo samplerInfo; TextureSamplerInfo samplerInfo;

View File

@ -54,7 +54,7 @@ namespace Nz
vertexDeclaration vertexDeclaration
}; };
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D];
const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<const VertexStruct_XYZ_Color_UV*>(m_vertices.data()); const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<const VertexStruct_XYZ_Color_UV*>(m_vertices.data());
for (std::size_t layerIndex = 0; layerIndex < m_layers.size(); ++layerIndex) for (std::size_t layerIndex = 0; layerIndex < m_layers.size(); ++layerIndex)
@ -116,11 +116,11 @@ namespace Nz
void Tilemap::UpdateVertices() const void Tilemap::UpdateVertices() const
{ {
std::array<Vector2f, RectCornerCount> cornerExtent; EnumMap<RectCorner, Vector2f> cornerExtent;
cornerExtent[UnderlyingCast(RectCorner::LeftBottom)] = Vector2f(0.f, 0.f); cornerExtent[RectCorner::LeftBottom] = Vector2f(0.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::RightBottom)] = Vector2f(1.f, 0.f); cornerExtent[RectCorner::RightBottom] = Vector2f(1.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::LeftTop)] = Vector2f(0.f, 1.f); cornerExtent[RectCorner::LeftTop] = Vector2f(0.f, 1.f);
cornerExtent[UnderlyingCast(RectCorner::RightTop)] = Vector2f(1.f, 1.f); cornerExtent[RectCorner::RightTop] = Vector2f(1.f, 1.f);
std::size_t spriteCount = 0; std::size_t spriteCount = 0;
for (const Layer& layer : m_layers) for (const Layer& layer : m_layers)
@ -150,7 +150,7 @@ namespace Nz
for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop }) for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop })
{ {
vertexPtr->color = tile.color; vertexPtr->color = tile.color;
vertexPtr->position = tileLeftBottom + Vector3f(m_tileSize * cornerExtent[UnderlyingCast(corner)] - originShift, 0.f); vertexPtr->position = tileLeftBottom + Vector3f(m_tileSize * cornerExtent[corner] - originShift, 0.f);
vertexPtr->uv = tile.textureCoords.GetCorner(corner); vertexPtr->uv = tile.textureCoords.GetCorner(corner);
++vertexPtr; ++vertexPtr;

View File

@ -9,6 +9,7 @@
#include <Nazara/Network/Algorithm.hpp> #include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/NetBuffer.hpp> #include <Nazara/Network/NetBuffer.hpp>
#include <Nazara/Network/Posix/IpAddressImpl.hpp> #include <Nazara/Network/Posix/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp> #include <NazaraUtils/StackArray.hpp>
#include <cstring> #include <cstring>
#include <poll.h> #include <poll.h>
@ -1016,31 +1017,29 @@ namespace Nz
int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol) int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol)
{ {
NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum");
static int addressFamily[] = { constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4 AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6 AF_INET6, //< NetProtocol::IPv6
-1 //< NetProtocol::Unknown -1 //< NetProtocol::Unknown
}; };
static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete");
return addressFamily[UnderlyingCast(protocol)]; return addressFamily[protocol];
} }
int SocketImpl::TranslateSocketTypeToSock(SocketType type) int SocketImpl::TranslateSocketTypeToSock(SocketType type)
{ {
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = { constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP SOCK_DGRAM, //< SocketType::UDP
-1 //< SocketType::Unknown -1 //< SocketType::Unknown
}; };
static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete");
return socketType[UnderlyingCast(type)]; return socketType[type];
} }
void SocketImpl::Uninitialize() void SocketImpl::Uninitialize()

View File

@ -8,6 +8,7 @@
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp> #include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Win32/IpAddressImpl.hpp> #include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp> #include <NazaraUtils/StackArray.hpp>
// Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines // Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines
@ -999,30 +1000,28 @@ namespace Nz
{ {
NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum");
static int addressFamily[] = { constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4 AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6 AF_INET6, //< NetProtocol::IPv6
-1 //< NetProtocol::Unknown -1 //< NetProtocol::Unknown
}; };
static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete");
return addressFamily[UnderlyingCast(protocol)]; return addressFamily[protocol];
} }
int SocketImpl::TranslateSocketTypeToSock(SocketType type) int SocketImpl::TranslateSocketTypeToSock(SocketType type)
{ {
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = { constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP SOCK_DGRAM, //< SocketType::UDP
-1 //< SocketType::Unknown -1 //< SocketType::Unknown
}; };
static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete");
return socketType[UnderlyingCast(type)]; return socketType[type];
} }
void SocketImpl::Uninitialize() void SocketImpl::Uninitialize()

View File

@ -134,14 +134,14 @@ namespace Nz::GL
force = true; force = true;
#endif #endif
if (m_state.bufferTargets[UnderlyingCast(target)] != buffer || force) if (m_state.bufferTargets[target] != buffer || force)
{ {
if (!SetCurrentContext(this)) if (!SetCurrentContext(this))
throw std::runtime_error("failed to activate context"); throw std::runtime_error("failed to activate context");
glBindBuffer(ToOpenGL(target), buffer); glBindBuffer(ToOpenGL(target), buffer);
m_state.bufferTargets[UnderlyingCast(target)] = buffer; m_state.bufferTargets[target] = buffer;
} }
} }
@ -248,7 +248,7 @@ namespace Nz::GL
unit.size = size; unit.size = size;
// glBindBufferRange does replace the currently bound buffer // glBindBufferRange does replace the currently bound buffer
m_state.bufferTargets[UnderlyingCast(BufferTarget::Storage)] = buffer; m_state.bufferTargets[BufferTarget::Storage] = buffer;
} }
} }
@ -263,7 +263,7 @@ namespace Nz::GL
throw std::runtime_error("unsupported texture unit #" + std::to_string(textureUnit)); throw std::runtime_error("unsupported texture unit #" + std::to_string(textureUnit));
auto& unit = m_state.textureUnits[textureUnit]; auto& unit = m_state.textureUnits[textureUnit];
if (unit.textureTargets[UnderlyingCast(target)] != texture) if (unit.textureTargets[target] != texture)
{ {
if (!SetCurrentContext(this)) if (!SetCurrentContext(this))
throw std::runtime_error("failed to activate context"); throw std::runtime_error("failed to activate context");
@ -272,7 +272,7 @@ namespace Nz::GL
glBindTexture(ToOpenGL(target), texture); glBindTexture(ToOpenGL(target), texture);
unit.textureTargets[UnderlyingCast(target)] = texture; unit.textureTargets[target] = texture;
} }
} }
@ -294,7 +294,7 @@ namespace Nz::GL
unit.size = size; unit.size = size;
// glBindBufferRange does replace the currently bound buffer // glBindBufferRange does replace the currently bound buffer
m_state.bufferTargets[UnderlyingCast(BufferTarget::Uniform)] = buffer; m_state.bufferTargets[BufferTarget::Uniform] = buffer;
} }
} }
@ -457,87 +457,87 @@ namespace Nz::GL
// Clip control // Clip control
if (m_params.type == ContextType::OpenGL && glVersion >= 450) if (m_params.type == ContextType::OpenGL && glVersion >= 450)
m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::Core; m_extensionStatus[Extension::ClipControl] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_clip_control")) else if (m_supportedExtensions.count("GL_ARB_clip_control"))
m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::ARB; m_extensionStatus[Extension::ClipControl] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_EXT_clip_control")) else if (m_supportedExtensions.count("GL_EXT_clip_control"))
m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::EXT; m_extensionStatus[Extension::ClipControl] = ExtensionStatus::EXT;
// Compute shaders // Compute shaders
if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310))
m_extensionStatus[UnderlyingCast(Extension::ComputeShader)] = ExtensionStatus::Core; m_extensionStatus[Extension::ComputeShader] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_compute_shader")) else if (m_supportedExtensions.count("GL_ARB_compute_shader"))
m_extensionStatus[UnderlyingCast(Extension::ComputeShader)] = ExtensionStatus::ARB; m_extensionStatus[Extension::ComputeShader] = ExtensionStatus::ARB;
// Debug output // Debug output
if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 320)) if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 320))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::Core; m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_KHR_debug")) else if (m_supportedExtensions.count("GL_KHR_debug"))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::KHR; m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::KHR;
else if (m_supportedExtensions.count("GL_ARB_debug_output")) else if (m_supportedExtensions.count("GL_ARB_debug_output"))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::ARB; m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::ARB;
// Depth clamp // Depth clamp
if (m_params.type == ContextType::OpenGL && glVersion >= 320) if (m_params.type == ContextType::OpenGL && glVersion >= 320)
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Core; m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_depth_clamp")) else if (m_supportedExtensions.count("GL_ARB_depth_clamp"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB; m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_EXT_depth_clamp")) else if (m_supportedExtensions.count("GL_EXT_depth_clamp"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::EXT; m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::EXT;
else if (m_supportedExtensions.count("GL_NV_depth_clamp")) else if (m_supportedExtensions.count("GL_NV_depth_clamp"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor; m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor;
// Polygon mode // Polygon mode
if (m_params.type == ContextType::OpenGL) if (m_params.type == ContextType::OpenGL)
m_extensionStatus[UnderlyingCast(Extension::PolygonMode)] = ExtensionStatus::Core; m_extensionStatus[Extension::PolygonMode] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_NV_polygon_mode")) else if (m_supportedExtensions.count("GL_NV_polygon_mode"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor; m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor;
// Shader image load formatted // Shader image load formatted
if (m_supportedExtensions.count("GL_EXT_shader_image_load_formatted")) if (m_supportedExtensions.count("GL_EXT_shader_image_load_formatted"))
m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadFormatted)] = ExtensionStatus::EXT; m_extensionStatus[Extension::ShaderImageLoadFormatted] = ExtensionStatus::EXT;
// Shader image load/store // Shader image load/store
if ((m_params.type == ContextType::OpenGL && glVersion >= 420) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) if ((m_params.type == ContextType::OpenGL && glVersion >= 420) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310))
m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::Core; m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_shader_image_load_store")) else if (m_supportedExtensions.count("GL_ARB_shader_image_load_store"))
m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::ARB; m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_EXT_shader_image_load_store")) else if (m_supportedExtensions.count("GL_EXT_shader_image_load_store"))
m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::EXT; m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::EXT;
// SPIR-V support // SPIR-V support
if (m_params.type == ContextType::OpenGL && glVersion >= 460) if (m_params.type == ContextType::OpenGL && glVersion >= 460)
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::Core; m_extensionStatus[Extension::SpirV] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_gl_spirv")) else if (m_supportedExtensions.count("GL_ARB_gl_spirv"))
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB; m_extensionStatus[Extension::SpirV] = ExtensionStatus::ARB;
// Storage buffers (SSBO) // Storage buffers (SSBO)
if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310))
m_extensionStatus[UnderlyingCast(Extension::StorageBuffers)] = ExtensionStatus::Core; m_extensionStatus[Extension::StorageBuffers] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_shader_storage_buffer_object")) else if (m_supportedExtensions.count("GL_ARB_shader_storage_buffer_object"))
m_extensionStatus[UnderlyingCast(Extension::StorageBuffers)] = ExtensionStatus::ARB; m_extensionStatus[Extension::StorageBuffers] = ExtensionStatus::ARB;
// Texture compression (S3tc) // Texture compression (S3tc)
if (m_supportedExtensions.count("GL_EXT_texture_compression_s3tc")) if (m_supportedExtensions.count("GL_EXT_texture_compression_s3tc"))
m_extensionStatus[UnderlyingCast(Extension::TextureCompressionS3tc)] = ExtensionStatus::EXT; m_extensionStatus[Extension::TextureCompressionS3tc] = ExtensionStatus::EXT;
// Texture anisotropic filter // Texture anisotropic filter
if (m_params.type == ContextType::OpenGL && glVersion >= 460) if (m_params.type == ContextType::OpenGL && glVersion >= 460)
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::Core; m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_texture_filter_anisotropic")) else if (m_supportedExtensions.count("GL_ARB_texture_filter_anisotropic"))
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::ARB; m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_EXT_texture_filter_anisotropic")) else if (m_supportedExtensions.count("GL_EXT_texture_filter_anisotropic"))
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::EXT; m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::EXT;
// Texture view // Texture view
if (m_params.type == ContextType::OpenGL && glVersion >= 430) if (m_params.type == ContextType::OpenGL && glVersion >= 430)
m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::Core; m_extensionStatus[Extension::TextureView] = ExtensionStatus::Core;
else if (m_supportedExtensions.count("GL_ARB_texture_view")) else if (m_supportedExtensions.count("GL_ARB_texture_view"))
m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::ARB; m_extensionStatus[Extension::TextureView] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_OES_texture_view")) else if (m_supportedExtensions.count("GL_OES_texture_view"))
m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::KHR; //< not sure about the OES => KHR mapping m_extensionStatus[Extension::TextureView] = ExtensionStatus::KHR; //< not sure about the OES => KHR mapping
else if (m_supportedExtensions.count("GL_EXT_texture_view")) else if (m_supportedExtensions.count("GL_EXT_texture_view"))
m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::EXT; //< not sure about the OES => KHR mapping m_extensionStatus[Extension::TextureView] = ExtensionStatus::EXT; //< not sure about the OES => KHR mapping
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) #define NAZARA_OPENGLRENDERER_FUNC(name, sig)
#define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig) loader.Load<sig, UnderlyingCast(FunctionIndex:: name)>(name, #name, false); #define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig) loader.Load<sig, UnderlyingCast(FunctionIndex:: name)>(name, #name, false);

View File

@ -73,10 +73,10 @@ namespace Nz
bool Cursor::Initialize() bool Cursor::Initialize()
{ {
for (std::size_t i = 0; i < SystemCursorCount; ++i) for (auto&& [cursor, cursorPtr] : s_systemCursors.iter_kv())
{ {
s_systemCursors[i] = std::make_shared<Cursor>(); cursorPtr = std::make_shared<Cursor>();
s_systemCursors[i]->Create(static_cast<SystemCursor>(i)); cursorPtr->Create(cursor);
} }
return true; return true;
@ -88,5 +88,5 @@ namespace Nz
cursor.reset(); cursor.reset();
} }
std::array<std::shared_ptr<Cursor>, SystemCursorCount> Cursor::s_systemCursors; EnumMap<SystemCursor, std::shared_ptr<Cursor>> Cursor::s_systemCursors;
} }

View File

@ -10,9 +10,9 @@
namespace Nz namespace Nz
{ {
namespace namespace NAZARA_ANONYMOUS_NAMESPACE
{ {
std::array<SDL_SystemCursor, SystemCursorCount> s_systemCursorIds = constexpr EnumMap<SystemCursor, SDL_SystemCursor> s_systemCursorIds =
{ {
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Default SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Default
@ -69,11 +69,13 @@ namespace Nz
CursorImpl::CursorImpl(SystemCursor cursor) CursorImpl::CursorImpl(SystemCursor cursor)
{ {
NAZARA_USE_ANONYMOUS_NAMESPACE
ErrorFlags errFlags(ErrorMode::ThrowException); ErrorFlags errFlags(ErrorMode::ThrowException);
if (cursor != SystemCursor::None) if (cursor != SystemCursor::None)
{ {
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[UnderlyingCast(cursor)]); m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
if (!m_cursor) if (!m_cursor)
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError())); NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
} }

View File

@ -13,6 +13,7 @@
#include <Nazara/Utility/Image.hpp> #include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/Utility.hpp> #include <Nazara/Utility/Utility.hpp>
#include <NazaraUtils/CallOnExit.hpp> #include <NazaraUtils/CallOnExit.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <filesystem> #include <filesystem>
#include <stdexcept> #include <stdexcept>
@ -116,7 +117,7 @@ namespace Nz
#endif #endif
#else #else
constexpr std::array<const char*, RenderAPICount> rendererPaths = { constexpr EnumMap<RenderAPI, const char*> rendererPaths = {
NazaraRendererPrefix "NazaraDirect3DRenderer" NazaraRendererDebugSuffix, // Direct3D NazaraRendererPrefix "NazaraDirect3DRenderer" NazaraRendererDebugSuffix, // Direct3D
NazaraRendererPrefix "NazaraMantleRenderer" NazaraRendererDebugSuffix, // Mantle NazaraRendererPrefix "NazaraMantleRenderer" NazaraRendererDebugSuffix, // Mantle
NazaraRendererPrefix "NazaraMetalRenderer" NazaraRendererDebugSuffix, // Metal NazaraRendererPrefix "NazaraMetalRenderer" NazaraRendererDebugSuffix, // Metal
@ -129,7 +130,7 @@ namespace Nz
auto RegisterImpl = [&](RenderAPI api, auto ComputeScore) auto RegisterImpl = [&](RenderAPI api, auto ComputeScore)
{ {
const char* rendererName = rendererPaths[UnderlyingCast(api)]; const char* rendererName = rendererPaths[api];
assert(rendererName); assert(rendererName);
std::filesystem::path fileName(rendererName); std::filesystem::path fileName(rendererName);

View File

@ -1411,7 +1411,7 @@ namespace Nz
{ {
NazaraAssert(IsValid(format), "invalid pixel format"); NazaraAssert(IsValid(format), "invalid pixel format");
auto& flipFunction = s_flipFunctions[UnderlyingCast(format)][UnderlyingCast(flipping)]; auto& flipFunction = s_flipFunctions[format][flipping];
if (flipFunction) if (flipFunction)
flipFunction(width, height, depth, reinterpret_cast<const UInt8*>(src), reinterpret_cast<UInt8*>(dst)); flipFunction(width, height, depth, reinterpret_cast<const UInt8*>(src), reinterpret_cast<UInt8*>(dst));
else else
@ -1499,13 +1499,12 @@ namespace Nz
PixelFormat PixelFormatInfo::IdentifyFormat(const PixelFormatDescription& info) PixelFormat PixelFormatInfo::IdentifyFormat(const PixelFormatDescription& info)
{ {
for (unsigned int i = 0; i < PixelFormatCount; ++i) for (auto&& [format, formatDesc] : s_pixelFormatInfos.iter_kv())
{ {
PixelFormatDescription& info2 = s_pixelFormatInfos[i]; if (info.bitsPerPixel == formatDesc.bitsPerPixel && info.content == formatDesc.content &&
if (info.bitsPerPixel == info2.bitsPerPixel && info.content == info2.content && info.redMask == formatDesc.redMask && info.greenMask == formatDesc.greenMask && info.blueMask == formatDesc.blueMask && info.alphaMask == formatDesc.alphaMask &&
info.redMask == info2.redMask && info.greenMask == info2.greenMask && info.blueMask == info2.blueMask && info.alphaMask == info2.alphaMask && info.redType == formatDesc.redType && info.greenType == formatDesc.greenType && info.blueType == formatDesc.blueType && info.alphaType == formatDesc.alphaType)
info.redType == info2.redType && info.greenType == info2.greenType && info.blueType == info2.blueType && info.alphaType == info2.alphaType) return format;
return static_cast<PixelFormat>(i);
} }
return PixelFormat::Undefined; return PixelFormat::Undefined;
@ -1517,7 +1516,7 @@ namespace Nz
auto SetupPixelFormat = [](PixelFormat format, PixelFormatDescription&& desc) auto SetupPixelFormat = [](PixelFormat format, PixelFormatDescription&& desc)
{ {
s_pixelFormatInfos[UnderlyingCast(format)] = std::move(desc); s_pixelFormatInfos[format] = std::move(desc);
}; };
Bitset<> b8(0xFF); Bitset<> b8(0xFF);
@ -1586,10 +1585,10 @@ namespace Nz
SetupPixelFormat(PixelFormat::Stencil8, PixelFormatDescription("Stencil8", PixelFormatContent::Stencil, 0xFF, 0, 0, 0, PixelFormatSubType::Unsigned)); SetupPixelFormat(PixelFormat::Stencil8, PixelFormatDescription("Stencil8", PixelFormatContent::Stencil, 0xFF, 0, 0, 0, PixelFormatSubType::Unsigned));
SetupPixelFormat(PixelFormat::Stencil16, PixelFormatDescription("Stencil16", PixelFormatContent::Stencil, 0xFFFF, 0, 0, 0, PixelFormatSubType::Unsigned)); SetupPixelFormat(PixelFormat::Stencil16, PixelFormatDescription("Stencil16", PixelFormatContent::Stencil, 0xFFFF, 0, 0, 0, PixelFormatSubType::Unsigned));
for (unsigned int i = 0; i < PixelFormatCount; ++i) for (auto&& [pixelFormat, pixelFormatInfo] : s_pixelFormatInfos.iter_kv())
{ {
if (!s_pixelFormatInfos[i].Validate()) if (!pixelFormatInfo.Validate())
NazaraWarning("Pixel format 0x" + NumberToString(i, 16) + " (" + GetName(static_cast<Nz::PixelFormat>(i)) + ") failed validation tests"); NazaraWarning("Pixel format 0x" + NumberToString(UnderlyingCast(pixelFormat), 16) + " (" + std::string(GetName(pixelFormat)) + ") failed validation tests");
} }
/***********************************A8************************************/ /***********************************A8************************************/
@ -1824,18 +1823,19 @@ namespace Nz
void PixelFormatInfo::Uninitialize() void PixelFormatInfo::Uninitialize()
{ {
for (std::size_t i = 0; i < PixelFormatCount; ++i) for (auto&& [pixelFormat, formatInfo] : s_pixelFormatInfos.iter_kv())
{ {
s_pixelFormatInfos[i].Clear(); formatInfo.Clear();
for (std::size_t j = 0; j < PixelFormatCount; ++j)
s_convertFunctions[i][j] = nullptr;
for (std::size_t j = 0; j < PixelFlippingCount; ++j) for (auto& convertFuncs : s_convertFunctions)
s_flipFunctions[i][j] = nullptr; convertFuncs.fill(nullptr);
for (auto& flipFuncs : s_flipFunctions)
flipFuncs.fill(nullptr);
} }
} }
std::array<std::array<PixelFormatInfo::ConvertFunction, PixelFormatCount>, PixelFormatCount> PixelFormatInfo::s_convertFunctions; EnumMap<PixelFormat, EnumMap<PixelFormat, PixelFormatInfo::ConvertFunction>> PixelFormatInfo::s_convertFunctions;
std::array<std::array<PixelFormatInfo::FlipFunction, PixelFlippingCount>, PixelFormatCount> PixelFormatInfo::s_flipFunctions; EnumMap<PixelFormat, EnumMap<PixelFlipping, PixelFormatInfo::FlipFunction>> PixelFormatInfo::s_flipFunctions;
std::array<PixelFormatDescription, PixelFormatCount> PixelFormatInfo::s_pixelFormatInfos; EnumMap<PixelFormat, PixelFormatDescription> PixelFormatInfo::s_pixelFormatInfos;
} }

View File

@ -16,8 +16,7 @@ namespace Nz
{ {
namespace NAZARA_ANONYMOUS_NAMESPACE namespace NAZARA_ANONYMOUS_NAMESPACE
{ {
std::size_t s_componentStride[ComponentTypeCount] = constexpr EnumMap<ComponentType, std::size_t> s_componentStride = {
{
4 * sizeof(float), // ComponentType::Color 4 * sizeof(float), // ComponentType::Color
1 * sizeof(double), // ComponentType::Double1 1 * sizeof(double), // ComponentType::Double1
2 * sizeof(double), // ComponentType::Double2 2 * sizeof(double), // ComponentType::Double2
@ -33,6 +32,7 @@ namespace Nz
4 * sizeof(UInt32), // ComponentType::Int4 4 * sizeof(UInt32), // ComponentType::Int4
}; };
} }
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) : VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
m_inputRate(inputRate) m_inputRate(inputRate)
{ {
@ -63,7 +63,7 @@ namespace Nz
component.offset = offset; component.offset = offset;
component.type = entry.type; component.type = entry.type;
offset += s_componentStride[UnderlyingCast(component.type)]; offset += s_componentStride[component.type];
} }
m_stride = offset; m_stride = offset;
@ -105,7 +105,7 @@ namespace Nz
}; };
// VertexLayout::XY : VertexStruct_XY // VertexLayout::XY : VertexStruct_XY
s_declarations[UnderlyingCast(VertexLayout::XY)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XY] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float2, ComponentType::Float2,
@ -113,9 +113,9 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY)]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout::XY"); NazaraAssert(s_declarations[VertexLayout::XY]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout::XY");
s_declarations[UnderlyingCast(VertexLayout::XY_Color)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XY_Color] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float2, ComponentType::Float2,
@ -128,10 +128,10 @@ namespace Nz
}, },
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_Color)]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout::XY_Color"); NazaraAssert(s_declarations[VertexLayout::XY_Color]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout::XY_Color");
// VertexLayout::XY_UV : VertexStruct_XY_UV // VertexLayout::XY_UV : VertexStruct_XY_UV
s_declarations[UnderlyingCast(VertexLayout::XY_UV)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XY_UV] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float2, ComponentType::Float2,
@ -144,10 +144,10 @@ namespace Nz
}, },
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_UV)]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout::XY_UV"); NazaraAssert(s_declarations[VertexLayout::XY_UV]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout::XY_UV");
// VertexLayout::XYZ : VertexStruct_XYZ // VertexLayout::XYZ : VertexStruct_XYZ
s_declarations[UnderlyingCast(VertexLayout::XYZ)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -155,10 +155,10 @@ namespace Nz
}, },
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ)]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout::XYZ"); NazaraAssert(s_declarations[VertexLayout::XYZ]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout::XYZ");
// VertexLayout::XYZ_Color : VertexStruct_XYZ_Color // VertexLayout::XYZ_Color : VertexStruct_XYZ_Color
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Color] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -171,10 +171,10 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout::XYZ_Color"); NazaraAssert(s_declarations[VertexLayout::XYZ_Color]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout::XYZ_Color");
// VertexLayout::XYZ_Color_UV : VertexStruct_XYZ_Color_UV // VertexLayout::XYZ_Color_UV : VertexStruct_XYZ_Color_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Color_UV] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -192,10 +192,10 @@ namespace Nz
}, },
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout::XYZ_Color_UV"); NazaraAssert(s_declarations[VertexLayout::XYZ_Color_UV]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout::XYZ_Color_UV");
// VertexLayout::XYZ_Normal : VertexStruct_XYZ_Normal // VertexLayout::XYZ_Normal : VertexStruct_XYZ_Normal
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Normal] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -208,10 +208,10 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout::XYZ_Normal"); NazaraAssert(s_declarations[VertexLayout::XYZ_Normal]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout::XYZ_Normal");
// VertexLayout::XYZ_Normal_UV : VertexStruct_XYZ_Normal_UV // VertexLayout::XYZ_Normal_UV : VertexStruct_XYZ_Normal_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Normal_UV] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -229,10 +229,10 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV"); NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV");
// VertexLayout::XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV_Tangent // VertexLayout::XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV_Tangent
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Normal_UV_Tangent] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -255,10 +255,10 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent"); NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV_Tangent]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent");
// VertexLayout::XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent_Skinning // VertexLayout::XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent_Skinning
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_Normal_UV_Tangent_Skinning] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -291,10 +291,10 @@ namespace Nz
}, },
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent_Skinning"); NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV_Tangent_Skinning]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent_Skinning");
// VertexLayout::XYZ_UV : VertexStruct_XYZ_UV // VertexLayout::XYZ_UV : VertexStruct_XYZ_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::XYZ_UV] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Position, VertexComponent::Position,
ComponentType::Float3, ComponentType::Float3,
@ -307,10 +307,10 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout::XYZ_UV"); NazaraAssert(s_declarations[VertexLayout::XYZ_UV]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout::XYZ_UV");
// VertexLayout::Matrix4 : Matrix4f // VertexLayout::Matrix4 : Matrix4f
s_declarations[UnderlyingCast(VertexLayout::Matrix4)] = NewDeclaration(VertexInputRate::Vertex, { s_declarations[VertexLayout::Matrix4] = NewDeclaration(VertexInputRate::Vertex, {
{ {
VertexComponent::Userdata, VertexComponent::Userdata,
ComponentType::Float4, ComponentType::Float4,
@ -333,7 +333,7 @@ namespace Nz
} }
}); });
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::Matrix4)]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout::Matrix4"); NazaraAssert(s_declarations[VertexLayout::Matrix4]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout::Matrix4");
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@ -349,5 +349,5 @@ namespace Nz
s_declarations.fill(nullptr); s_declarations.fill(nullptr);
} }
std::array<std::shared_ptr<VertexDeclaration>, VertexLayoutCount> VertexDeclaration::s_declarations; EnumMap<VertexLayout, std::shared_ptr<VertexDeclaration>> VertexDeclaration::s_declarations;
} }

View File

@ -28,7 +28,7 @@ namespace Nz
{ {
} }
std::array<Vk::CommandPool, QueueCount> commandPools; EnumMap<QueueType, Vk::CommandPool> commandPools;
VulkanDescriptorSetLayoutCache setLayoutCache; VulkanDescriptorSetLayoutCache setLayoutCache;
}; };
@ -49,7 +49,7 @@ namespace Nz
AutoCommandBuffer Device::AllocateCommandBuffer(QueueType queueType) AutoCommandBuffer Device::AllocateCommandBuffer(QueueType queueType)
{ {
return m_internalData->commandPools[UnderlyingCast(queueType)].AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY); return m_internalData->commandPools[queueType].AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
} }
bool Device::Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) bool Device::Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
@ -155,24 +155,23 @@ namespace Nz
return 0U; return 0U;
}; };
std::size_t queueIndex = static_cast<std::size_t>(queueType);
for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos) for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos)
{ {
if ((familyInfo.flags & QueueTypeToFlags(queueType)) == 0) if ((familyInfo.flags & QueueTypeToFlags(queueType)) == 0)
continue; continue;
m_defaultQueues[queueIndex] = familyInfo.familyIndex; m_defaultQueues[queueType] = familyInfo.familyIndex;
// Break only if queue has not been selected before // Break only if queue has not been selected before
auto queueBegin = m_defaultQueues.begin(); auto queueBegin = m_defaultQueues.begin();
auto queueEnd = queueBegin + queueIndex; auto queueEnd = queueBegin + static_cast<std::size_t>(queueType);
if (std::find(queueBegin, queueEnd, familyInfo.familyIndex) == queueEnd) if (std::find(queueBegin, queueEnd, familyInfo.familyIndex) == queueEnd)
break; break;
} }
Vk::CommandPool& commandPool = m_internalData->commandPools[queueIndex]; Vk::CommandPool& commandPool = m_internalData->commandPools[queueType];
if (!commandPool.Create(*this, m_defaultQueues[queueIndex], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT)) if (!commandPool.Create(*this, m_defaultQueues[queueType], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT))
{ {
NazaraError("Failed to create command pool: " + TranslateVulkanError(commandPool.GetLastErrorCode())); NazaraError("Failed to create command pool: " + TranslateVulkanError(commandPool.GetLastErrorCode()));
return false; return false;