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

@@ -33,23 +33,23 @@ namespace Nz
// We complete the formats table
m_audioFormatValues.fill(0);
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Mono)] = AL_FORMAT_MONO16;
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Stereo)] = AL_FORMAT_STEREO16;
m_audioFormatValues[AudioFormat::I16_Mono] = AL_FORMAT_MONO16;
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."
if (library.alIsExtensionPresent("AL_EXT_MCFORMATS"))
{
m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16");
m_audioFormatValues[UnderlyingCast(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[UnderlyingCast(AudioFormat::I16_7_1)] = m_library.alGetEnumValue("AL_FORMAT_71CHN16");
m_audioFormatValues[AudioFormat::I16_Quad] = m_library.alGetEnumValue("AL_FORMAT_QUAD16");
m_audioFormatValues[AudioFormat::I16_5_1] = m_library.alGetEnumValue("AL_FORMAT_51CHN16");
m_audioFormatValues[AudioFormat::I16_6_1] = m_library.alGetEnumValue("AL_FORMAT_61CHN16");
m_audioFormatValues[AudioFormat::I16_7_1] = m_library.alGetEnumValue("AL_FORMAT_71CHN16");
}
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);
if (library.alIsExtensionPresent("AL_SOFT_source_latency"))
m_extensionStatus[UnderlyingCast(OpenALExtension::SourceLatency)] = true;
m_extensionStatus[OpenALExtension::SourceLatency] = true;
SetListenerDirection(Vector3f::Forward());
}
@@ -226,7 +226,7 @@ namespace Nz
if (format == AudioFormat::Unknown)
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/Algorithm.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <sstream>
#include <Nazara/Core/Debug.hpp>
@@ -11,14 +12,12 @@ namespace Nz
{
namespace NAZARA_ANONYMOUS_NAMESPACE
{
const char* errorType[] = {
constexpr EnumMap<ErrorType, std::string_view> s_errorTypes = {
"Assert failed: ", // ErrorType::AssertFailed
"Internal error: ", // ErrorType::Internal
"Error: ", // ErrorType::Normal
"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
std::ostringstream ss;
ss << errorType[UnderlyingCast(type)] << error;
ss << s_errorTypes[type] << error;
if (line != 0 && file && function)
ss << " (" << file << ':' << line << ": " << function << ')';

View File

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

View File

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

View File

@@ -353,15 +353,15 @@ namespace Nz
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 (texInfo.type == ImageType::E3D)
if (imageType == ImageType::E3D)
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 };
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.layerCount = (texInfo.type == ImageType::Cubemap) ? 6 : 1;
texInfo.type = imageType;
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& 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));
}

View File

@@ -86,25 +86,25 @@ namespace Nz
// TODO: Ensure structs layout is what's expected
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())
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())
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())
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())
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())
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())
m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::OverlayTexture)] = it->second.bindingIndex;
m_engineShaderBindings[EngineShaderBinding::OverlayTexture] = it->second.bindingIndex;
}
for (const auto& handlerPtr : m_settings.GetPropertyHandlers())

View File

@@ -145,7 +145,7 @@ namespace Nz
const auto& textureSlot = m_parent->GetTextureData(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({});
bindings.push_back({

View File

@@ -37,7 +37,7 @@ namespace Nz
};
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));
}

View File

@@ -40,7 +40,7 @@ namespace Nz
};
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));
}

View File

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

View File

@@ -54,7 +54,7 @@ namespace Nz
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());
for (std::size_t layerIndex = 0; layerIndex < m_layers.size(); ++layerIndex)
@@ -116,11 +116,11 @@ namespace Nz
void Tilemap::UpdateVertices() const
{
std::array<Vector2f, RectCornerCount> cornerExtent;
cornerExtent[UnderlyingCast(RectCorner::LeftBottom)] = Vector2f(0.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::RightBottom)] = Vector2f(1.f, 0.f);
cornerExtent[UnderlyingCast(RectCorner::LeftTop)] = Vector2f(0.f, 1.f);
cornerExtent[UnderlyingCast(RectCorner::RightTop)] = Vector2f(1.f, 1.f);
EnumMap<RectCorner, Vector2f> cornerExtent;
cornerExtent[RectCorner::LeftBottom] = Vector2f(0.f, 0.f);
cornerExtent[RectCorner::RightBottom] = Vector2f(1.f, 0.f);
cornerExtent[RectCorner::LeftTop] = Vector2f(0.f, 1.f);
cornerExtent[RectCorner::RightTop] = Vector2f(1.f, 1.f);
std::size_t spriteCount = 0;
for (const Layer& layer : m_layers)
@@ -150,7 +150,7 @@ namespace Nz
for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop })
{
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;

View File

@@ -9,6 +9,7 @@
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/NetBuffer.hpp>
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp>
#include <cstring>
#include <poll.h>
@@ -1016,31 +1017,29 @@ namespace Nz
int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol)
{
NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum");
static int addressFamily[] = {
constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6
-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)
{
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = {
constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP
-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()

View File

@@ -8,6 +8,7 @@
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <NazaraUtils/EnumMap.hpp>
#include <NazaraUtils/StackArray.hpp>
// 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");
static int addressFamily[] = {
constexpr EnumMap<NetProtocol, int> addressFamily {
AF_UNSPEC, //< NetProtocol::Any
AF_INET, //< NetProtocol::IPv4
AF_INET6, //< NetProtocol::IPv6
-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)
{
NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum");
static int socketType[] = {
constexpr EnumMap<SocketType, int> socketType {
SOCK_RAW, //< SocketType::Raw
SOCK_STREAM, //< SocketType::TCP
SOCK_DGRAM, //< SocketType::UDP
-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()

View File

@@ -134,14 +134,14 @@ namespace Nz::GL
force = true;
#endif
if (m_state.bufferTargets[UnderlyingCast(target)] != buffer || force)
if (m_state.bufferTargets[target] != buffer || force)
{
if (!SetCurrentContext(this))
throw std::runtime_error("failed to activate context");
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;
// 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));
auto& unit = m_state.textureUnits[textureUnit];
if (unit.textureTargets[UnderlyingCast(target)] != texture)
if (unit.textureTargets[target] != texture)
{
if (!SetCurrentContext(this))
throw std::runtime_error("failed to activate context");
@@ -272,7 +272,7 @@ namespace Nz::GL
glBindTexture(ToOpenGL(target), texture);
unit.textureTargets[UnderlyingCast(target)] = texture;
unit.textureTargets[target] = texture;
}
}
@@ -294,7 +294,7 @@ namespace Nz::GL
unit.size = size;
// 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
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"))
m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::ClipControl] = ExtensionStatus::ARB;
else if (m_supportedExtensions.count("GL_EXT_clip_control"))
m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::EXT;
m_extensionStatus[Extension::ClipControl] = ExtensionStatus::EXT;
// Compute shaders
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"))
m_extensionStatus[UnderlyingCast(Extension::ComputeShader)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::ComputeShader] = ExtensionStatus::ARB;
// Debug output
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"))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::KHR;
m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::KHR;
else if (m_supportedExtensions.count("GL_ARB_debug_output"))
m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::ARB;
// Depth clamp
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"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::ARB;
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"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor;
m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor;
// Polygon mode
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"))
m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor;
m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor;
// 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
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"))
m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::ARB;
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
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"))
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::SpirV] = ExtensionStatus::ARB;
// Storage buffers (SSBO)
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"))
m_extensionStatus[UnderlyingCast(Extension::StorageBuffers)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::StorageBuffers] = ExtensionStatus::ARB;
// 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
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"))
m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::ARB;
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
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"))
m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::ARB;
m_extensionStatus[Extension::TextureView] = ExtensionStatus::ARB;
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"))
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_EXT_FUNC(name, sig) loader.Load<sig, UnderlyingCast(FunctionIndex:: name)>(name, #name, false);

View File

@@ -73,10 +73,10 @@ namespace Nz
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>();
s_systemCursors[i]->Create(static_cast<SystemCursor>(i));
cursorPtr = std::make_shared<Cursor>();
cursorPtr->Create(cursor);
}
return true;
@@ -88,5 +88,5 @@ namespace Nz
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
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_ARROW, // SystemCursor::Default
@@ -69,11 +69,13 @@ namespace Nz
CursorImpl::CursorImpl(SystemCursor cursor)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
ErrorFlags errFlags(ErrorMode::ThrowException);
if (cursor != SystemCursor::None)
{
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[UnderlyingCast(cursor)]);
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
if (!m_cursor)
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
}

View File

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

View File

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

View File

@@ -16,8 +16,7 @@ namespace Nz
{
namespace NAZARA_ANONYMOUS_NAMESPACE
{
std::size_t s_componentStride[ComponentTypeCount] =
{
constexpr EnumMap<ComponentType, std::size_t> s_componentStride = {
4 * sizeof(float), // ComponentType::Color
1 * sizeof(double), // ComponentType::Double1
2 * sizeof(double), // ComponentType::Double2
@@ -33,6 +32,7 @@ namespace Nz
4 * sizeof(UInt32), // ComponentType::Int4
};
}
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
m_inputRate(inputRate)
{
@@ -63,7 +63,7 @@ namespace Nz
component.offset = offset;
component.type = entry.type;
offset += s_componentStride[UnderlyingCast(component.type)];
offset += s_componentStride[component.type];
}
m_stride = offset;
@@ -105,7 +105,7 @@ namespace Nz
};
// VertexLayout::XY : VertexStruct_XY
s_declarations[UnderlyingCast(VertexLayout::XY)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XY] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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,
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
s_declarations[UnderlyingCast(VertexLayout::XY_UV)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XY_UV] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_Color] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_Color_UV] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_Normal] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_Normal_UV] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_Normal_UV_Tangent] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
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,
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
s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::XYZ_UV] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Position,
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
s_declarations[UnderlyingCast(VertexLayout::Matrix4)] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[VertexLayout::Matrix4] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent::Userdata,
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)
{
@@ -349,5 +349,5 @@ namespace Nz
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;
};
@@ -49,7 +49,7 @@ namespace Nz
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)
@@ -155,24 +155,23 @@ namespace Nz
return 0U;
};
std::size_t queueIndex = static_cast<std::size_t>(queueType);
for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos)
{
if ((familyInfo.flags & QueueTypeToFlags(queueType)) == 0)
continue;
m_defaultQueues[queueIndex] = familyInfo.familyIndex;
m_defaultQueues[queueType] = familyInfo.familyIndex;
// Break only if queue has not been selected before
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)
break;
}
Vk::CommandPool& commandPool = m_internalData->commandPools[queueIndex];
if (!commandPool.Create(*this, m_defaultQueues[queueIndex], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT))
Vk::CommandPool& commandPool = m_internalData->commandPools[queueType];
if (!commandPool.Create(*this, m_defaultQueues[queueType], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT))
{
NazaraError("Failed to create command pool: " + TranslateVulkanError(commandPool.GetLastErrorCode()));
return false;