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

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