Core: Make Color constexpr

This commit is contained in:
SirLynix
2022-12-29 12:13:00 +01:00
parent 3d88746060
commit 9a553e5e9d
38 changed files with 227 additions and 222 deletions

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
const Color Color::Black(0.f, 0.f, 0.f);
const Color Color::Blue(0.f, 0.f, 1.f);
const Color Color::Cyan(0.f, 1.f, 1.f);
const Color Color::Gray(80.f / 255.f, 80.f / 255.f, 80.f / 255.f);
const Color Color::Green(0.f, 1.f, 0.f);
const Color Color::Magenta(1.f, 0.f, 1.f);
const Color Color::Orange(1.f, 165.f / 255.f, 0.f);
const Color Color::Red(1.f, 0.f, 0.f);
const Color Color::Yellow(1.f, 1.f, 0.f);
const Color Color::White(1.f, 1.f, 1.f);
}

View File

@@ -65,7 +65,7 @@ namespace Nz
builder.BeginRenderPass(*passData.framebuffer, *passData.renderPass, passData.renderRect, passData.outputClearValues.data(), passData.outputClearValues.size());
if (!passData.name.empty())
builder.BeginDebugRegion(passData.name, Color::Green);
builder.BeginDebugRegion(passData.name, Color::Green());
FramePassEnvironment env{
*this,

View File

@@ -323,7 +323,7 @@ namespace Nz
// Update UBOs and materials
renderFrame.Execute([&](CommandBufferBuilder& builder)
{
builder.BeginDebugRegion("CPU to GPU transfers", Color::Yellow);
builder.BeginDebugRegion("CPU to GPU transfers", Color::Yellow());
{
builder.PreTransferBarrier();
@@ -446,13 +446,13 @@ namespace Nz
builder.TextureBarrier(PipelineStage::ColorOutput, PipelineStage::FragmentShader, MemoryAccess::ColorWrite, MemoryAccess::ShaderRead, TextureLayout::ColorOutput, TextureLayout::ColorInput, *sourceTexture);
std::array<CommandBufferBuilder::ClearValues, 2> clearValues;
clearValues[0].color = Color::Black;
clearValues[0].color = Color::Black();
clearValues[1].depth = 1.f;
clearValues[1].stencil = 0;
builder.BeginRenderPass(renderTarget.GetFramebuffer(renderFrame.GetFramebufferIndex()), renderTarget.GetRenderPass(), renderRegion, { clearValues[0], clearValues[1] });
{
builder.BeginDebugRegion("Main window rendering", Color::Green);
builder.BeginDebugRegion("Main window rendering", Color::Green());
{
builder.SetScissor(renderRegion);
builder.SetViewport(renderRegion);
@@ -636,7 +636,7 @@ namespace Nz
mergePass.AddInput(viewerData->debugColorAttachment);
mergePass.AddOutput(renderTargetData.finalAttachment);
mergePass.SetClearColor(0, Color::Black);
mergePass.SetClearColor(0, Color::Black());
mergePass.SetCommandCallback([&targetViewers](CommandBufferBuilder& builder, const FramePassEnvironment& env)
{

View File

@@ -182,7 +182,7 @@ namespace Nz
renderFrame.Execute([&](CommandBufferBuilder& builder)
{
builder.BeginDebugRegion("Light UBO Update", Color::Yellow);
builder.BeginDebugRegion("Light UBO Update", Color::Yellow());
{
for (auto& lightUboData : m_lightDataBuffers)
{

View File

@@ -15,7 +15,7 @@ namespace Nz
m_material(std::move(material)),
m_sectionCount(0),
m_spriteCount(0),
m_color(Color::White),
m_color(Color::White()),
m_orientation(orientation),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
m_origin(0.f, 0.f),

View File

@@ -13,7 +13,7 @@ namespace Nz
{
void PredefinedMaterials::AddBasicSettings(MaterialSettings& settings)
{
settings.AddValueProperty<Color>("BaseColor", Color::White);
settings.AddValueProperty<Color>("BaseColor", Color::White());
settings.AddValueProperty<bool>("AlphaTest", false);
settings.AddValueProperty<float>("AlphaTestThreshold", 0.2f);
settings.AddTextureProperty("BaseColorMap", ImageType::E2D);
@@ -43,8 +43,8 @@ namespace Nz
void PredefinedMaterials::AddPhongSettings(MaterialSettings& settings)
{
settings.AddValueProperty<Color>("AmbientColor", Color::Black);
settings.AddValueProperty<Color>("SpecularColor", Color::White);
settings.AddValueProperty<Color>("AmbientColor", Color::Black());
settings.AddValueProperty<Color>("SpecularColor", Color::White());
settings.AddValueProperty<float>("Shininess", 2.f);
settings.AddTextureProperty("EmissiveMap", ImageType::E2D);
settings.AddTextureProperty("HeightMap", ImageType::E2D);

View File

@@ -13,7 +13,7 @@ namespace Nz
{
SlicedSprite::SlicedSprite(std::shared_ptr<MaterialInstance> material) :
m_material(std::move(material)),
m_color(Color::White),
m_color(Color::White()),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
m_origin(0.f, 0.f),
m_size(64.f, 64.f)

View File

@@ -14,12 +14,12 @@ namespace Nz
{
Sprite::Sprite(std::shared_ptr<MaterialInstance> material) :
m_material(std::move(material)),
m_color(Color::White),
m_color(Color::White()),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
m_origin(0.f, 0.f),
m_size(64.f, 64.f)
{
m_cornerColor.fill(Color::White);
m_cornerColor.fill(Color::White());
UpdateVertices();
}

View File

@@ -173,7 +173,7 @@ namespace Nz
{
renderFrame.Execute([&](CommandBufferBuilder& builder)
{
builder.BeginDebugRegion("Debug drawer upload", Color::Yellow);
builder.BeginDebugRegion("Debug drawer upload", Color::Yellow());
{
if (m_viewerDataUpdated)
{

View File

@@ -228,7 +228,7 @@ namespace Nz
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
{
for (UInt32 v = 0; v < header.num_vertices; ++v)
*colorPtr++ = Color::White;
*colorPtr++ = Color::White();
}
vertexMapper.Unmap();

View File

@@ -205,7 +205,7 @@ namespace Nz
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
{
for (std::size_t j = 0; j < md5Mesh.vertices.size(); ++j)
*colorPtr++ = Color::White;
*colorPtr++ = Color::White();
}
vertexMapper.Unmap();
@@ -316,7 +316,7 @@ namespace Nz
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
{
for (std::size_t j = 0; j < md5Mesh.vertices.size(); ++j)
*colorPtr++ = Color::White;
*colorPtr++ = Color::White();
}
vertexMapper.Unmap();

View File

@@ -313,7 +313,7 @@ namespace Nz
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
{
for (UInt32 j = 0; j < vertexCount; ++j)
colorPtr[j] = Color::White;
colorPtr[j] = Color::White();
}
vertexMapper.Unmap();

View File

@@ -10,8 +10,8 @@
namespace Nz
{
RichTextDrawer::RichTextDrawer() :
m_defaultColor(Color::White),
m_defaultOutlineColor(Color::Black),
m_defaultColor(Color::White()),
m_defaultOutlineColor(Color::Black()),
m_defaultStyle(TextStyle_Regular),
m_glyphUpdated(false),
m_defaultCharacterSpacingOffset(0.f),

View File

@@ -612,7 +612,7 @@ namespace Nz
float endX = (i == m_cursorPositionEnd.y) ? GetGlyphPos({ m_cursorPositionEnd.x, i }) : lineInfo.bounds.width;
float spriteSize = std::max(endX - beginX, 1.f);
cursor.sprite->SetColor((m_cursorPositionBegin == m_cursorPositionEnd) ? Color::Black : Color(0.f, 0.f, 0.f, 0.2f));
cursor.sprite->SetColor((m_cursorPositionBegin == m_cursorPositionEnd) ? Color::Black() : Color(0.f, 0.f, 0.f, 0.2f));
cursor.sprite->SetSize(Vector2f(spriteSize, lineInfo.bounds.height));
registry.get<NodeComponent>(cursor.entity).SetPosition(beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);

View File

@@ -13,7 +13,7 @@ namespace Nz
m_hoveredMaterial(std::move(hoveredMaterial)),
m_material(std::move(material)),
m_pressedMaterial(std::move(pressedMaterial)),
m_color(Color::White),
m_color(Color::White()),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
m_cornerSize(cornerSize),
m_cornerTexCoords(cornerTexCoords)