diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 2d87c62dd..e157ee43c 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -414,7 +414,7 @@ void CBooModel::ActivateLights(const std::vector& lights) { m_lightingDa void CBooModel::DisableAllLights() { m_lightingData.ambient = zeus::skBlack; - for (size_t curLight = 0; curLight < URDE_MAX_LIGHTS; ++curLight) { + for (size_t curLight = 0; curLight < m_lightingData.lights.size(); ++curLight) { CModelShaders::Light& lightOut = m_lightingData.lights[curLight]; lightOut.color = zeus::skClear; lightOut.linAtt[0] = 1.f; diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index c21e25d81..a697cece9 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CAABoxShader.hpp" +#include + #include "Runtime/Graphics/CGraphics.hpp" #include @@ -24,16 +26,17 @@ CAABoxShader::CAABoxShader(bool zOnly) { CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, - stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + m_dataBind = + ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), + bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } void CAABoxShader::setAABB(const zeus::CAABox& aabb) { - zeus::CVector3f vboData[] = { + const std::array vboData{{ {aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()}, @@ -57,9 +60,9 @@ void CAABoxShader::setAABB(const zeus::CAABox& aabb) { {aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.max.x(), aabb.max.y(), aabb.min.z()}, - }; + }}; - m_vbo->load(vboData, sizeof(zeus::CVector3f) * 34); + m_vbo->load(vboData.data(), sizeof(vboData)); } void CAABoxShader::draw(const zeus::CColor& color) { diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index a49712d49..0e51076ec 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp" +#include + #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CGraphics.hpp" @@ -40,18 +42,22 @@ CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) { struct Vert { zeus::CVector2f m_pos; - } verts[4] = { + }; + + const std::array verts{{ {{0.0, 0.0}}, {{0.0, 1.0}}, {{1.0, 0.0}}, {{1.0, 1.0}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 16, 4); + }}; + + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 16, verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, - nullptr, 0, nullptr, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index 5ace88d1e..653c3bda3 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CColoredStripShader.hpp" +#include + #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" @@ -45,15 +47,18 @@ void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx boo::ObjToken tex) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[1]; - if (tex) + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + std::array, 1> texs; + if (tex) { texs[0] = tex; - else + } else { texs[0] = g_Renderer->GetWhiteTexture(); - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, - nullptr, 1, texs, nullptr, nullptr); + } + + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); } CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, boo::ObjToken tex) { diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index e5815b2fa..d460976a7 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CDecalShaders.hpp" +#include + #include "Runtime/Particle/CDecal.hpp" #include @@ -46,26 +48,31 @@ void CDecalShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& c regPipeline = m_noTexZTestNoZWrite; } - const SQuadDescr* desc = decal.m_desc; + const SQuadDescr* const desc = decal.m_desc; + const CUVElement* const texr = desc->x14_TEX.get(); + size_t texCount = 0; + std::array, 1> textures; - CUVElement* texr = desc->x14_TEX.get(); - int texCount = 0; - boo::ObjToken textures[1]; - - if (texr) { + if (texr != nullptr) { textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); texCount = 1; } - if (decal.m_instBuf) { - boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; + if (!decal.m_instBuf) { + return; + } - if (regPipeline) - decal.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, 1, - uniforms, nullptr, texCount, textures, nullptr, nullptr); - if (redToAlphaPipeline) - decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, - 1, uniforms, nullptr, texCount, textures, nullptr, nullptr); + std::array, 1> uniforms{decal.m_uniformBuf.get()}; + + if (regPipeline) { + decal.m_normalDataBind = + ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), + nullptr, texCount, textures.data(), nullptr, nullptr); + } + if (redToAlphaPipeline) { + decal.m_redToAlphaDataBind = + ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), + uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); } } diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index 0892c93e4..03e825184 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CElementGenShaders.hpp" +#include + #include "Runtime/Particle/CElementGen.hpp" #include @@ -226,10 +228,10 @@ void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Conte } } - CUVElement* texr = desc->x54_x40_TEXR.get(); - CUVElement* tind = desc->x58_x44_TIND.get(); + const CUVElement* const texr = desc->x54_x40_TEXR.get(); + const CUVElement* const tind = desc->x58_x44_TIND.get(); int texCount = 0; - boo::ObjToken textures[3]; + std::array, 3> textures; if (texr) { textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); @@ -244,43 +246,56 @@ void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Conte } if (gen.m_instBuf) { - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; + const std::array, 1> uniforms{gen.m_uniformBuf.get()}; - if (regPipeline) - for (int i = 0; i < 2; ++i) - gen.m_normalDataBind[i] = ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, 1, - uniforms, nullptr, texCount, textures, nullptr, nullptr); - if (regPipelineSub) - for (int i = 0; i < 2; ++i) - gen.m_normalSubDataBind[i] = ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), - nullptr, 1, uniforms, nullptr, texCount, textures, - nullptr, nullptr); - if (redToAlphaPipeline) - for (int i = 0; i < 2; ++i) - gen.m_redToAlphaDataBind[i] = ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), - nullptr, 1, uniforms, nullptr, texCount, textures, - nullptr, nullptr); - if (redToAlphaPipelineSub) - for (int i = 0; i < 2; ++i) - gen.m_redToAlphaSubDataBind[i] = - ctx.newShaderDataBinding((*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); + if (regPipeline != nullptr) { + for (size_t i = 0; i < std::size(gen.m_normalDataBind); ++i) { + gen.m_normalDataBind[i] = + ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), + uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); + } + } + if (regPipelineSub != nullptr) { + for (size_t i = 0; i < std::size(gen.m_normalSubDataBind); ++i) { + gen.m_normalSubDataBind[i] = + ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), + uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); + } + } + if (redToAlphaPipeline != nullptr) { + for (size_t i = 0; i < std::size(gen.m_redToAlphaDataBind); ++i) { + gen.m_redToAlphaDataBind[i] = + ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), + uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); + } + } + if (redToAlphaPipelineSub != nullptr) { + for (size_t i = 0; i < std::size(gen.m_redToAlphaSubDataBind); ++i) { + gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding( + (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), + nullptr, texCount, textures.data(), nullptr, nullptr); + } + } } if (gen.m_instBufPmus) { - boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; + const std::array, 1> uniforms{gen.m_uniformBufPmus.get()}; texCount = std::min(texCount, 1); - if (regPipelinePmus) - for (int i = 0; i < 2; ++i) - gen.m_normalDataBindPmus[i] = ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), - nullptr, 1, uniforms, nullptr, texCount, textures, - nullptr, nullptr); - if (redToAlphaPipelinePmus) - for (int i = 0; i < 2; ++i) - gen.m_redToAlphaDataBindPmus[i] = - ctx.newShaderDataBinding((*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); + if (regPipelinePmus != nullptr) { + for (size_t i = 0; i < std::size(gen.m_normalDataBindPmus); ++i) { + gen.m_normalDataBindPmus[i] = + ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), + uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); + } + } + if (redToAlphaPipelinePmus != nullptr) { + for (size_t i = 0; i < std::size(gen.m_redToAlphaDataBindPmus); ++i) { + gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding( + (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(), + nullptr, texCount, textures.data(), nullptr, nullptr); + } + } } } diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index 8e73df229..75688ec42 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp" +#include + #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" @@ -31,15 +33,19 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector bufs[1]; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {m_tex->GetBooTexture()}; - for (int i = 0; i < 3; ++i) { + + std::array, 1> bufs; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 1> texs{m_tex->GetBooTexture()}; + + for (size_t i = 0; i < m_uniBuf.size(); ++i) { m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); bufs[0] = m_uniBuf[i].get(); - m_dataBind[i] = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, - nullptr, 1, texs, nullptr, nullptr); + m_dataBind[i] = + ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), + nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); } + return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp index e5711e7ba..f7bb378f9 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -25,8 +26,8 @@ private: zeus::CColor m_color; }; boo::ObjToken m_vbo; - boo::ObjToken m_uniBuf[3]; - boo::ObjToken m_dataBind[3]; + std::array, 3> m_uniBuf; + std::array, 3> m_dataBind; Uniform m_uniform; const CTexture* m_tex = nullptr; size_t m_maxVerts = 0; diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp index dae90bb1d..ee3497cce 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp @@ -20,21 +20,38 @@ void CEnvFxShaders::Shutdown() { void CEnvFxShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CEnvFxManager& fxMgr, CEnvFxManagerGrid& grid) { - auto uBufInfo = grid.m_uniformBuf.getBufferInfo(); - auto iBufInfo = grid.m_instBuf.getBufferInfo(); - boo::ObjToken uniforms[] = {uBufInfo.first.get(), fxMgr.m_fogUniformBuf.get()}; - size_t ubufOffsets[] = {size_t(uBufInfo.second), 0}; - size_t ubufSizes[] = {sizeof(CEnvFxShaders::Uniform), sizeof(CGraphics::g_Fog)}; - boo::PipelineStage uniformStages[] = {boo::PipelineStage::Vertex, boo::PipelineStage::Fragment}; - boo::ObjToken textures[] = {fxMgr.xb74_txtrSnowFlake->GetBooTexture(), - fxMgr.x40_txtrEnvGradient->GetBooTexture()}; - grid.m_snowBinding = - ctx.newShaderDataBinding(m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, 2, uniforms, uniformStages, - ubufOffsets, ubufSizes, 2, textures, nullptr, nullptr, 0, iBufInfo.second); + const auto uBufInfo = grid.m_uniformBuf.getBufferInfo(); + const auto iBufInfo = grid.m_instBuf.getBufferInfo(); + + const std::array, 2> uniforms{{ + uBufInfo.first.get(), + fxMgr.m_fogUniformBuf.get(), + }}; + const std::array ubufOffsets{ + size_t(uBufInfo.second), + 0, + }; + constexpr std::array ubufSizes{ + sizeof(CEnvFxShaders::Uniform), + sizeof(CGraphics::g_Fog), + }; + constexpr std::array uniformStages{ + boo::PipelineStage::Vertex, + boo::PipelineStage::Fragment, + }; + std::array, 2> textures{ + fxMgr.xb74_txtrSnowFlake->GetBooTexture(), + fxMgr.x40_txtrEnvGradient->GetBooTexture(), + }; + + grid.m_snowBinding = ctx.newShaderDataBinding( + m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(), + ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture(); grid.m_underwaterBinding = - ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, 2, uniforms, uniformStages, - ubufOffsets, ubufSizes, 2, textures, nullptr, nullptr, 0, iBufInfo.second); + ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), + uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(), + textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp index aec2d832c..37947fa55 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -14,9 +16,9 @@ class CEnvFxManagerGrid; class CEnvFxShaders { public: struct Instance { - zeus::CVector3f positions[4]; + std::array positions; zeus::CColor color; - zeus::CVector2f uvs[4]; + std::array uvs; }; struct Uniform { zeus::CMatrix4f mv; diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index 34b57dddf..9ca4e35f4 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -124,38 +124,64 @@ void CFluidPlaneShader::Cache::Clear() { void CFluidPlaneShader::PrepareBinding(u32 maxVertCount) { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), maxVertCount); - if (m_pipelines.m_tessellation) + if (m_pipelines.m_tessellation) { m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount); + } m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken ubufs[] = {m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get()}; - boo::PipelineStage ubufStages[] = {boo::PipelineStage::Vertex, boo::PipelineStage::Vertex, - boo::PipelineStage::Fragment}; - size_t ubufOffs[] = {0, 0, 1280}; - size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)}; + const std::array, 3> ubufs{{ + m_uniBuf.get(), + m_uniBuf.get(), + m_uniBuf.get(), + }}; + constexpr std::array ubufStages{ + boo::PipelineStage::Vertex, + boo::PipelineStage::Vertex, + boo::PipelineStage::Fragment, + }; + constexpr std::array ubufOffs{ + 0, + 0, + 1280, + }; + constexpr std::array ubufSizes{ + 1280, + 1280, + sizeof(CModelShaders::LightingUniform), + }; + size_t texCount = 0; - boo::ObjToken texs[8]; - if (m_patternTex1) + std::array, 8> texs; + if (m_patternTex1) { texs[texCount++] = m_patternTex1->GetBooTexture(); - if (m_patternTex2) + } + if (m_patternTex2) { texs[texCount++] = m_patternTex2->GetBooTexture(); - if (m_colorTex) + } + if (m_colorTex) { texs[texCount++] = m_colorTex->GetBooTexture(); - if (m_bumpMap) + } + if (m_bumpMap) { texs[texCount++] = m_bumpMap->GetBooTexture(); - if (m_envMap) + } + if (m_envMap) { texs[texCount++] = m_envMap->GetBooTexture(); - if (m_envBumpMap) + } + if (m_envBumpMap) { texs[texCount++] = m_envBumpMap->GetBooTexture(); - if (m_lightmap) + } + if (m_lightmap) { texs[texCount++] = m_lightmap->GetBooTexture(); - auto regular = ctx.newShaderDataBinding(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, 3, ubufs, ubufStages, - ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr); + } + auto regular = ctx.newShaderDataBinding(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, ubufs.size(), + ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), + texCount, texs.data(), nullptr, nullptr); boo::ObjToken tessellation; if (m_pipelines.m_tessellation) { texs[texCount++] = m_rippleMap.get(); - tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, 3, ubufs, - ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr); + tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, ubufs.size(), + ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), + texCount, texs.data(), nullptr, nullptr); } m_dataBind = {regular, tessellation}; return true; @@ -201,11 +227,11 @@ void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info) { uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); uni.m_mvNorm = info.normMtx; uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); - for (int i = 0; i < 6; ++i) - uni.m_texMtxs[i] = info.texMtxs[i]; + uni.m_texMtxs = info.texMtxs; uni.m_lighting.ActivateLights(info.lights); - for (int i = 0; i < 3; ++i) + for (size_t i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { uni.m_lighting.colorRegs[i] = info.kColors[i]; + } uni.m_lighting.mulColor = info.kColors[3]; uni.m_lighting.fog = CGraphics::g_Fog; uni.m_pad2.x() = info.indScale; @@ -219,11 +245,11 @@ void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info, const zeus::CVe uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); uni.m_mvNorm = info.normMtx; uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); - for (int i = 0; i < 6; ++i) - uni.m_texMtxs[i] = info.texMtxs[i]; - int i = 0; + uni.m_texMtxs = info.texMtxs; + + size_t i = 0; for (const CRipple& ripple : rippleManager.GetRipples()) { - assert(i < 20 && "Too many ripples"); + assert(i < uni.m_ripple.size() && "Too many ripples"); Ripple& rOut = uni.m_ripple[i++]; if (ripple.GetTime() >= ripple.GetTimeFalloff()) { rOut.center.zeroOut(); @@ -243,8 +269,9 @@ void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info, const zeus::CVe uni.m_colorMul = colorMul; uni.m_pad[0].x() = rippleNormResolution; uni.m_lighting.ActivateLights(info.lights); - for (i = 0; i < 3; ++i) + for (i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { uni.m_lighting.colorRegs[i] = info.kColors[i]; + } uni.m_lighting.mulColor = info.kColors[3]; uni.m_lighting.fog = CGraphics::g_Fog; uni.m_pad2.x() = info.indScale; diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index 1c0195910..6109af8cd 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "Runtime/CToken.hpp" @@ -39,15 +40,15 @@ public: struct PatchVertex { zeus::CVector4f m_pos; - float m_outerLevels[4] = {}; - float m_innerLevels[4] = {}; + std::array m_outerLevels{}; + std::array m_innerLevels{}; }; struct RenderSetupInfo { - zeus::CMatrix4f texMtxs[6]; + std::array texMtxs; zeus::CMatrix4f normMtx; float indScale = 1.f; - zeus::CColor kColors[4]; + std::array kColors; std::vector lights; }; @@ -67,8 +68,8 @@ private: }; class Cache { - ShaderPair m_cache[1024] = {}; - ShaderPair m_doorCache[8] = {}; + std::array m_cache{}; + std::array m_doorCache{}; ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; } ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; } static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info); @@ -90,10 +91,10 @@ private: zeus::CMatrix4f m_mv; zeus::CMatrix4f m_mvNorm; zeus::CMatrix4f m_proj; - zeus::CMatrix4f m_texMtxs[6]; - Ripple m_ripple[20]; + std::array m_texMtxs; + std::array m_ripple; zeus::CVector4f m_colorMul; - zeus::CVector4f m_pad[3]; // rippleNormResolution, Pad out to 1280 bytes + std::array m_pad; // rippleNormResolution, Pad out to 1280 bytes CModelShaders::LightingUniform m_lighting; zeus::CVector3f m_pad2; // Pad out to 768 bytes, also holds ind scale }; diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp index e54abbed0..d9073bc5a 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp @@ -6,7 +6,7 @@ namespace urde { -static boo::ObjToken s_Pipelines[4]; +static std::array, 4> s_Pipelines; void CFogVolumePlaneShader::Initialize() { s_Pipelines[0] = hecl::conv->convert(Shader_CFogVolumePlaneShader0{}); @@ -26,9 +26,10 @@ void CFogVolumePlaneShader::CommitResources(size_t capacity) { m_vertCapacity = capacity; CGraphics::CommitResources([this, capacity](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector4f), capacity); - for (int i = 0; i < 4; ++i) + for (size_t i = 0; i < m_dataBinds.size(); ++i) { m_dataBinds[i] = ctx.newShaderDataBinding(s_Pipelines[i], m_vbo.get(), nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + } return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp index 8d3b136a1..b015390ce 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -16,7 +17,7 @@ namespace urde { class CFogVolumePlaneShader { boo::ObjToken m_vbo; - boo::ObjToken m_dataBinds[4]; + std::array, 4> m_dataBinds; std::vector m_verts; size_t m_vertCapacity = 0; diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index 96e897bb6..414783b43 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -91,8 +91,8 @@ void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Con } } - int texCount = 0; - boo::ObjToken textures[1]; + size_t texCount = 0; + std::array, 1> textures; std::pair, hecl::VertexBufferPool::IndexTp> vbufInfo; @@ -106,15 +106,16 @@ void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Con vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); } - boo::ObjToken uniforms[] = {ubufInfo.first.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Fragment}; - size_t ubufOffs[] = {size_t(ubufInfo.second)}; - size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; + const std::array, 1> uniforms{ubufInfo.first.get()}; + constexpr std::array stages{boo::PipelineStage::Fragment}; + const std::array ubufOffs{size_t(ubufInfo.second)}; + const std::array ubufSizes{sizeof(CLineRenderer::SDrawUniform)}; - for (int i = 0; i < 2; ++i) - renderer.m_shaderBind[i] = - ctx.newShaderDataBinding((*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, 1, uniforms, stages, ubufOffs, - ubufSizes, texCount, textures, nullptr, nullptr, vbufInfo.second); + for (size_t i = 0; i < std::size(renderer.m_shaderBind); ++i) { + renderer.m_shaderBind[i] = ctx.newShaderDataBinding( + (*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(), + ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second); + } } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index c0f0034df..e35fdd4cb 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" +#include + #include "Runtime/Graphics/CGraphics.hpp" #include @@ -17,10 +19,10 @@ CMapSurfaceShader::CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx, const boo::ObjToken& ibo) : m_vbo(vbo), m_ibo(ibo) { m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), 1, bufs, stages, nullptr, - nullptr, 0, nullptr, nullptr, nullptr); + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); } void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index 928e90e23..6d06d77b1 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -23,8 +23,9 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector& l case ELightType::Spot: case ELightType::Custom: case ELightType::Directional: { - if (curLight >= URDE_MAX_LIGHTS) + if (curLight >= lights.size()) { continue; + } CModelShaders::Light& lightOut = lights[curLight++]; lightOut.pos = CGraphics::g_CameraMatrix * light.GetPosition(); lightOut.dir = CGraphics::g_CameraMatrix.basis * light.GetDirection(); @@ -44,7 +45,7 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector& l } } - for (; curLight < URDE_MAX_LIGHTS; ++curLight) { + for (; curLight < lights.size(); ++curLight) { CModelShaders::Light& lightOut = lights[curLight]; lightOut.pos = zeus::skZero3f; lightOut.dir = zeus::skDown; @@ -60,93 +61,94 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector& l using TexCoordSource = hecl::Backend::TexCoordSource; -static const hecl::Backend::TextureInfo ThermalTextures[] = {{TexCoordSource::Normal, 7, true}}; +constexpr std::array ThermalTextures{{ + {TexCoordSource::Normal, 7, true}, +}}; -static const hecl::Backend::TextureInfo BallFadeTextures[] = { +constexpr std::array BallFadeTextures{{ {TexCoordSource::Position, 0, false}, // ID tex {TexCoordSource::Position, 0, false}, // Sphere ramp - {TexCoordSource::Position, 1, false} // TXTR_BallFade -}; + {TexCoordSource::Position, 1, false}, // TXTR_BallFade +}}; -static const hecl::Backend::TextureInfo WorldShadowTextures[] = { - {TexCoordSource::Position, 7, false} // Shadow tex -}; +constexpr std::array WorldShadowTextures{{ + {TexCoordSource::Position, 7, false}, // Shadow tex +}}; -static const hecl::Backend::TextureInfo DisintegrateTextures[] = { +constexpr std::array DisintegrateTextures{{ {TexCoordSource::Position, 0, false}, // Ashy tex - {TexCoordSource::Position, 1, false} // Ashy tex -}; + {TexCoordSource::Position, 1, false}, // Ashy tex +}}; -static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = { +static std::array g_ExtensionSlots{{ /* Default solid shading */ {}, /* Normal lit shading */ {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, /* Thermal Visor shading */ - {1, ThermalTextures, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, + {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true}, /* Forced alpha shading */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, /* Forced additive shading */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, false, false, true}, /* Solid color */ - {0, nullptr, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::Zero, - hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Backface, false, false, false}, + {0, nullptr, hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, false, false, false}, /* Solid color additive */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Backface, true, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, true, false, true}, /* Alpha-only Solid color frontface cull, LEqual */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Frontface, false, true, false}, + {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Frontface, false, true, false}, /* Alpha-only Solid color frontface cull, Always, No Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::None, hecl::Backend::CullMode::Frontface, true, true, false}, + {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, + hecl::Backend::CullMode::Frontface, true, true, false}, /* Alpha-only Solid color backface cull, LEqual */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Backface, false, true, false}, + {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, false, true, false}, /* Alpha-only Solid color backface cull, Greater, No Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::Backface, true, true, false}, + {0, nullptr, hecl::Backend::BlendFactor::Zero, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, + hecl::Backend::CullMode::Backface, true, true, false}, /* MorphBall shadow shading */ - {3, BallFadeTextures, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, + {3, BallFadeTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Equal, hecl::Backend::CullMode::Backface, false, false, true, false, true}, /* World shadow shading (modified lighting) */ - {1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, + {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, /* Forced alpha shading without culling */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, false, false, true}, /* Forced additive shading without culling */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, false, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, false, false, true}, /* Forced alpha shading without Z-write */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, true, false, true}, /* Forced additive shading without Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, true, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Original, true, false, true}, /* Forced alpha shading without culling or Z-write */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, true, false, true}, /* Forced additive shading without culling or Z-write */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::None, true, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, true, false, true}, /* Depth GEqual no Z-write */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::GEqual, hecl::Backend::CullMode::Backface, true, false, true}, /* Disintegration */ - {2, DisintegrateTextures, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, + {2, DisintegrateTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true}, /* Forced additive shading without culling or Z-write and greater depth test */ - {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, - hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}, + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, + hecl::Backend::CullMode::None, true, false, true}, /* Thermal cold shading */ {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, - false, false, true, false, false, false, true}, + hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true}, /* Normal lit shading with alpha */ {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}, @@ -154,10 +156,11 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = { {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, /* Normal lit shading with cube reflection and world shadow */ - {1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, - hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}}; + {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, + hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, +}}; -static const char* ShaderMacros[] = { +constexpr std::array ShaderMacros{ "URDE_LIGHTING", "URDE_LIGHTING", "URDE_THERMAL_HOT", @@ -187,9 +190,9 @@ static const char* ShaderMacros[] = { }; void CModelShaders::Initialize() { - const char** macro = ShaderMacros; - for (auto& ext : g_ExtensionSlots) - ext.shaderMacro = *macro++; + for (size_t i = 0; i < g_ExtensionSlots.size(); i++) { + g_ExtensionSlots[i].shaderMacro = ShaderMacros[i]; + } } void CModelShaders::Shutdown() { g_ShaderPipelines.clear(); } diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index 9afbd25e0..c17e6f381 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -59,14 +59,14 @@ public: zeus::CVector3f pos; zeus::CVector3f dir; zeus::CColor color = zeus::skClear; - float linAtt[4] = {1.f, 0.f, 0.f}; - float angAtt[4] = {1.f, 0.f, 0.f}; + std::array linAtt{1.f, 0.f, 0.f}; + std::array angAtt{1.f, 0.f, 0.f}; }; struct LightingUniform { - Light lights[URDE_MAX_LIGHTS]; + std::array lights; zeus::CColor ambient; - zeus::CColor colorRegs[3]; + std::array colorRegs; zeus::CColor mulColor; zeus::CColor addColor; CGraphics::CFogState fog; diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp index e391e5510..02e56af04 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp" +#include + #include "Runtime/Particle/CParticleSwoosh.hpp" #include "Runtime/Particle/CSwooshDescription.hpp" @@ -88,13 +90,17 @@ void CParticleSwooshShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::C } } - CUVElement* texr = desc->x3c_TEXR.get(); - boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; + const CUVElement* const texr = desc->x3c_TEXR.get(); + const std::array, 1> textures{ + texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr, + }; - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - for (int i = 0; i < 2; ++i) - gen.m_dataBind[i] = ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, 1, uniforms, - nullptr, texr ? 1 : 0, textures, nullptr, nullptr); + const std::array, 1> uniforms{gen.m_uniformBuf.get()}; + for (size_t i = 0; i < std::size(gen.m_dataBind); ++i) { + gen.m_dataBind[i] = + ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(), + uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr); + } } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index c26392dfb..4474a15d9 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp" +#include + #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" @@ -42,38 +44,46 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { struct BlurVert { zeus::CVector3f pos; zeus::CVector2f uv; - } blurVerts[4] = {{{-1.f, 1.f, 0.f}, {0.f, 1.f}}, - {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {1.f, 1.f}}, - {{1.f, -1.f, 0.f}, {1.f, 0.f}}}; - m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts, sizeof(BlurVert), 4); + }; + const std::array blurVerts{{ + {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, + {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, + {{1.f, 1.f, 0.f}, {1.f, 1.f}}, + {{1.f, -1.f, 0.f}, {1.f, 0.f}}, + }}; + m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts.data(), sizeof(BlurVert), blurVerts.size()); struct Vert { zeus::CVector3f pos; zeus::CVector2f screenUv; zeus::CVector2f indUv; zeus::CVector2f maskUv; - } verts[4] = {{{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}}, - {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}}, - {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}}}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); + }; + const std::array verts{{ + {{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}}, + {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}}, + {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}}, + {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}}, + }}; + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); - boo::ObjToken bufs[] = {m_uniBufBlurX.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[4]; - int texBindIdxs[4]; + std::array, 1> bufs{m_uniBufBlurX.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + std::array, 4> texs; + std::array texBindIdxs; texs[0] = CGraphics::g_SpareTexture.get(); texBindIdxs[0] = 1; - m_dataBindBlurX = ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, 1, bufs, stages, - nullptr, nullptr, 1, texs, texBindIdxs, nullptr); + m_dataBindBlurX = + ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); bufs[0] = m_uniBufBlurY.get(); texs[0] = CGraphics::g_SpareTexture.get(); texBindIdxs[0] = 2; - m_dataBindBlurY = ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, 1, bufs, stages, - nullptr, nullptr, 1, texs, texBindIdxs, nullptr); + m_dataBindBlurY = + ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), nullptr); bufs[0] = m_uniBuf.get(); size_t texCount; @@ -97,8 +107,9 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { texCount = 3; } - m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, - bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); + m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, + bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, texCount, + texs.data(), texBindIdxs.data(), nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index d95c98cd9..c891d30cd 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -26,11 +26,14 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {m_tex->GetBooTexture()}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, 1, bufs, stages, nullptr, - nullptr, 1, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 1> texs{m_tex->GetBooTexture()}; + + m_dataBind = + ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(), + nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp index 0fe7f6893..4965ae15a 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -14,8 +15,8 @@ class CTexture; class CRadarPaintShader { public: struct Instance { - zeus::CVector3f pos[4]; - zeus::CVector2f uv[4]; + std::array pos; + std::array uv; zeus::CColor color; }; diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp index 5f2375f39..c1b44e3b4 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp" +#include + #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" @@ -45,20 +47,22 @@ CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) : struct Vert { zeus::CVector2f m_pos; zeus::CVector2f m_uv; - } verts[4] = { + }; + const std::array verts{{ {{-1.f, -1.f}, {0.f, 0.f}}, {{-1.f, 1.f}, {0.f, 448.f}}, {{1.f, -1.f}, {640.f, 0.f}}, {{1.f, 1.f}, {640.f, 448.f}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); + }}; + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex()}; - m_dataBind = - ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(), nullptr, - nullptr, 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 1> texs{g_Renderer->GetRandomStaticEntropyTex()}; + m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(), + nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, + texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp index 5a3330c17..f83590224 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CScanLinesFilter.hpp" +#include + #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CBooRenderer.hpp" @@ -43,10 +45,11 @@ CScanLinesFilter::CScanLinesFilter(EFilterType type, bool even) : m_even(even) { m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); boo::ObjToken vbo = m_even ? g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, 1, bufs, stages, nullptr, - nullptr, 0, nullptr, nullptr, nullptr); + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp index 2d2705968..f0fb34463 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp @@ -16,12 +16,12 @@ void CSpaceWarpFilter::Initialize() { s_Pipeline = hecl::conv->convert(Shader_CS void CSpaceWarpFilter::Shutdown() { s_Pipeline.reset(); } void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx) { - u8 data[WARP_RAMP_RES + 1][WARP_RAMP_RES + 1][4] = {}; - float halfRes = WARP_RAMP_RES / 2.f; + std::array, WARP_RAMP_RES + 1>, WARP_RAMP_RES + 1> data{}; + const float halfRes = WARP_RAMP_RES / 2.f; for (int y = 0; y < WARP_RAMP_RES + 1; ++y) { for (int x = 0; x < WARP_RAMP_RES + 1; ++x) { zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes); - float mag = vec.magnitude(); + const float mag = vec.magnitude(); if (mag < 1.f && vec.canBeNormalized()) { vec.normalize(); vec *= zeus::CVector2f(std::sqrt(mag)); @@ -33,29 +33,36 @@ void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& c } m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, boo::TextureFormat::RGBA8, - boo::TextureClampMode::Repeat, data[0], (WARP_RAMP_RES + 1) * (WARP_RAMP_RES + 1) * 4) + boo::TextureClampMode::Repeat, data.data(), (WARP_RAMP_RES + 1) * (WARP_RAMP_RES + 1) * 4) .get(); } CSpaceWarpFilter::CSpaceWarpFilter() { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { GenerateWarpRampTex(ctx); + struct Vert { zeus::CVector2f m_pos; zeus::CVector2f m_uv; - } verts[4] = { - {{-1.f, -1.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 1.f}}, - {{1.f, -1.f}, {1.f, 0.f}}, - {{1.f, 1.f}, {1.f, 1.f}}, }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); + const std::array verts{{ + {{-1.f, -1.f}, {0.f, 0.f}}, + {{-1.f, 1.f}, {0.f, 1.f}}, + {{1.f, -1.f}, {1.f, 0.f}}, + {{1.f, 1.f}, {1.f, 1.f}}, + }}; + + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), m_warpTex.get()}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, - 2, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 2> texs{ + CGraphics::g_SpareTexture.get(), + m_warpTex.get(), + }; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index ffab42db1..3ad35830d 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Runtime/GCNTypes.hpp" #include @@ -15,7 +17,7 @@ class CSpaceWarpFilter { zeus::CMatrix4f m_indXf; zeus::CVector3f m_strength; }; - u8 m_shiftTexture[4][8][4] = {}; + std::array, 8>, 4> m_shiftTexture{}; boo::ObjToken m_warpTex; boo::ObjToken m_vbo; boo::ObjToken m_uniBuf; diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.hpp b/Runtime/Graphics/Shaders/CTextSupportShader.hpp index 9d76821a0..83e7eaf1e 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.hpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Runtime/GuiSys/CGuiWidget.hpp" #include @@ -33,8 +35,8 @@ class CTextSupportShader { }; struct CharacterInstance { - zeus::CVector3f m_pos[4]; - zeus::CVector3f m_uv[4]; + std::array m_pos; + std::array m_uv; zeus::CColor m_fontColor; zeus::CColor m_outlineColor; zeus::CColor m_mulColor; @@ -42,8 +44,8 @@ class CTextSupportShader { }; struct ImageInstance { - zeus::CVector3f m_pos[4]; - zeus::CVector2f m_uv[4]; + std::array m_pos; + std::array m_uv; zeus::CColor m_color; void SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset); }; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index 7f4944e73..a9a1be609 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" +#include + #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CTexture.hpp" @@ -187,11 +189,13 @@ CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {m_booTex.get()}; - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, 1, bufs, stages, - nullptr, nullptr, 1, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + const std::array stages{boo::PipelineStage::Vertex}; + const std::array, 1> texs{m_booTex.get()}; + m_dataBind = + ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } @@ -205,13 +209,13 @@ CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken verts{{ {{0.f, 0.f, z}, {0.f, 0.f}}, {{0.f, 1.f, z}, {0.f, uvScale}}, {{1.f, 0.f, z}, {uvScale, 0.f}}, {{1.f, 1.f, z}, {uvScale, uvScale}}, - }; - m_vbo->load(verts, sizeof(verts)); + }}; + m_vbo->load(verts.data(), sizeof(verts)); if (!m_flipRect) { m_uniform.m_matrix[0][0] = rect.size.x() * 2.f; @@ -234,18 +238,18 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z void CTexturedQuadFilter::drawCropped(const zeus::CColor& color, float uvScale) { SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawCropped", zeus::skMagenta); - float xFac = CGraphics::g_CroppedViewport.xc_width / float(g_Viewport.x8_width); - float yFac = CGraphics::g_CroppedViewport.x10_height / float(g_Viewport.xc_height); - float xBias = CGraphics::g_CroppedViewport.x4_left / float(g_Viewport.x8_width); - float yBias = CGraphics::g_CroppedViewport.x8_top / float(g_Viewport.xc_height); + const float xFac = CGraphics::g_CroppedViewport.xc_width / float(g_Viewport.x8_width); + const float yFac = CGraphics::g_CroppedViewport.x10_height / float(g_Viewport.xc_height); + const float xBias = CGraphics::g_CroppedViewport.x4_left / float(g_Viewport.x8_width); + const float yBias = CGraphics::g_CroppedViewport.x8_top / float(g_Viewport.xc_height); - Vert verts[4] = { + const std::array verts{{ {{-1.f, -1.f, 0.f}, {xBias * uvScale, yBias * uvScale}}, {{-1.f, 1.f, 0.f}, {xBias * uvScale, (yBias + yFac) * uvScale}}, {{1.f, -1.f, 0.f}, {(xBias + xFac) * uvScale, yBias * uvScale}}, {{1.f, 1.f, 0.f}, {(xBias + xFac) * uvScale, (yBias + yFac) * uvScale}}, - }; - m_vbo->load(verts, sizeof(verts)); + }}; + m_vbo->load(verts.data(), sizeof(verts)); m_uniform.m_color = color; m_uniBuf->load(&m_uniform, sizeof(m_uniform)); @@ -279,30 +283,42 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col CGraphics::SetShaderDataBinding(m_dataBind); if (shape == EFilterShape::FullscreenQuarters) { - Vert QuadVerts[] = { - {{-1.f, -1.f, 0.f}, {t, t}}, // ll - {{-1.f, 0.f, 0.f}, {t, 0.f}}, {{0.f, -1.f, 0.f}, {0.f, t}}, {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - {{-1.f, 1.f, 0.f}, {t, t}}, // ul - {{-1.f, 0.f, 0.f}, {t, 0.f}}, {{0.f, 1.f, 0.f}, {0.f, t}}, {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - {{1.f, -1.f, 0.f}, {t, t}}, // lr - {{1.f, 0.f, 0.f}, {t, 0.f}}, {{0.f, -1.f, 0.f}, {0.f, t}}, {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - {{1.f, 1.f, 0.f}, {t, t}}, // ur - {{1.f, 0.f, 0.f}, {t, 0.f}}, {{0.f, 1.f, 0.f}, {0.f, t}}, {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - }; - m_vbo->load(QuadVerts, sizeof(Vert) * 16); + const std::array QuadVerts{{ + // ll + {{-1.f, -1.f, 0.f}, {t, t}}, + {{-1.f, 0.f, 0.f}, {t, 0.f}}, + {{0.f, -1.f, 0.f}, {0.f, t}}, + {{0.f, 0.f, 0.f}, {0.f, 0.f}}, + // ul + {{-1.f, 1.f, 0.f}, {t, t}}, + {{-1.f, 0.f, 0.f}, {t, 0.f}}, + {{0.f, 1.f, 0.f}, {0.f, t}}, + {{0.f, 0.f, 0.f}, {0.f, 0.f}}, + // lr + {{1.f, -1.f, 0.f}, {t, t}}, + {{1.f, 0.f, 0.f}, {t, 0.f}}, + {{0.f, -1.f, 0.f}, {0.f, t}}, + {{0.f, 0.f, 0.f}, {0.f, 0.f}}, + // ur + {{1.f, 1.f, 0.f}, {t, t}}, + {{1.f, 0.f, 0.f}, {t, 0.f}}, + {{0.f, 1.f, 0.f}, {0.f, t}}, + {{0.f, 0.f, 0.f}, {0.f, 0.f}}, + }}; + m_vbo->load(QuadVerts.data(), sizeof(QuadVerts)); CGraphics::DrawArray(0, 4); CGraphics::DrawArray(4, 4); CGraphics::DrawArray(8, 4); CGraphics::DrawArray(12, 4); } else { - Vert FullscreenVerts[] = { + const std::array FullscreenVerts{{ {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, {{-1.f, 1.f, 0.f}, {0.f, t}}, {{1.f, -1.f, 0.f}, {t, 0.f}}, {{1.f, 1.f, 0.f}, {t, t}}, - }; - m_vbo->load(FullscreenVerts, sizeof(Vert) * 4); - CGraphics::DrawArray(0, 4); + }}; + m_vbo->load(FullscreenVerts.data(), sizeof(FullscreenVerts)); + CGraphics::DrawArray(0, FullscreenVerts.size()); } } @@ -313,11 +329,13 @@ CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const boo:: CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {m_booTex.get()}; - m_dataBind = ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, 1, bufs, stages, - nullptr, nullptr, 1, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 1> texs{m_booTex.get()}; + m_dataBind = + ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp index 3ebd601c8..cc7fc5b6d 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -21,20 +21,24 @@ CThermalColdFilter::CThermalColdFilter() { zeus::CVector2f m_pos; zeus::CVector2f m_uv; zeus::CVector2f m_uvNoise; - } verts[4] = { + }; + const std::array verts{{ {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 48, 4); + }}; + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), - g_Renderer->GetRandomStaticEntropyTex()}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, - 2, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 2> texs{ + CGraphics::g_SpareTexture.get(), + g_Renderer->GetRandomStaticEntropyTex(), + }; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index 54cf48407..5f5754037 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -10,7 +12,7 @@ namespace urde { class CThermalColdFilter { struct Uniform { zeus::CMatrix4f m_indMtx; - zeus::CColor m_colorRegs[3]; + std::array m_colorRegs; float m_randOff = 0.f; }; boo::ObjToken m_vbo; diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp index b0e5ca8ce..e5f7e45b1 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp @@ -20,19 +20,24 @@ CThermalHotFilter::CThermalHotFilter() { struct Vert { zeus::CVector2f m_pos; zeus::CVector2f m_uv; - } verts[4] = { + }; + const std::array verts{{ {{-1.0, -1.0}, {0.0, 0.0}}, {{-1.0, 1.0}, {0.0, 1.0}}, {{1.0, -1.0}, {1.0, 0.0}}, {{1.0, 1.0}, {1.0, 1.0}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); + }}; + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette()}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, - 2, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 2> texs{ + CGraphics::g_SpareTexture.get(), + g_Renderer->GetThermoPalette(), + }; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp index 24ee5f869..e824d2b90 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -8,7 +10,7 @@ namespace urde { class CThermalHotFilter { struct Uniform { - zeus::CColor m_colorRegs[3]; + std::array m_colorRegs; }; boo::ObjToken m_vbo; boo::ObjToken m_uniBuf; diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index b3e6dc1cc..c161e7496 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -1,5 +1,7 @@ #include "Runtime/Graphics/Shaders/CWorldShadowShader.hpp" +#include + #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/Graphics/CGraphics.hpp" @@ -25,12 +27,14 @@ CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, - 0, nullptr, nullptr, nullptr); - m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, - nullptr, 0, nullptr, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); + m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); + m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0); return true; } BooTrace); @@ -41,9 +45,13 @@ void CWorldShadowShader::bindRenderTarget() { CGraphics::g_BooMainCommandQueue-> void CWorldShadowShader::drawBase(float extent) { SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta); - zeus::CVector3f verts[] = { - {-extent, 0.f, extent}, {extent, 0.f, extent}, {-extent, 0.f, -extent}, {extent, 0.f, -extent}}; - m_vbo->load(verts, sizeof(zeus::CVector3f) * 4); + const std::array verts{{ + {-extent, 0.f, extent}, + {extent, 0.f, extent}, + {-extent, 0.f, -extent}, + {extent, 0.f, -extent}, + }}; + m_vbo->load(verts.data(), sizeof(verts)); m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = zeus::skWhite; diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp index 63678c3c3..413301e70 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp @@ -20,19 +20,24 @@ CXRayBlurFilter::CXRayBlurFilter(TLockedToken& tex) : m_paletteTex(tex struct Vert { zeus::CVector2f m_pos; zeus::CVector2f m_uv; - } verts[4] = { + }; + const std::array verts{{ {{-1.f, -1.f}, {0.f, 0.f}}, {{-1.f, 1.f}, {0.f, 1.f}}, {{1.f, -1.f}, {1.f, 0.f}}, {{1.f, 1.f}, {1.f, 1.f}}, - }; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); + }}; + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - boo::ObjToken bufs[] = {m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), m_booTex}; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, - 2, texs, nullptr, nullptr); + + const std::array, 1> bufs{m_uniBuf.get()}; + constexpr std::array stages{boo::PipelineStage::Vertex}; + const std::array, 2> texs{ + CGraphics::g_SpareTexture.get(), + m_booTex, + }; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), + stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); return true; } BooTrace); } @@ -42,13 +47,13 @@ void CXRayBlurFilter::draw(float amount) { CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - float blurL = amount * g_tweakGui->GetXrayBlurScaleLinear() * 0.25f; - float blurQ = amount * g_tweakGui->GetXrayBlurScaleQuadratic() * 0.25f; + const float blurL = amount * g_tweakGui->GetXrayBlurScaleLinear() * 0.25f; + const float blurQ = amount * g_tweakGui->GetXrayBlurScaleQuadratic() * 0.25f; - for (int i = 0; i < 8; ++i) { - float iflt = i / 2.f; - float uvScale = (1.f - (blurL * iflt + blurQ * iflt * iflt)); - float uvOffset = uvScale * -0.5f + 0.5f; + for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) { + const float iflt = float(i) / 2.f; + const float uvScale = (1.f - (blurL * iflt + blurQ * iflt * iflt)); + const float uvOffset = uvScale * -0.5f + 0.5f; m_uniform.m_uv[i][0][0] = uvScale; m_uniform.m_uv[i][1][1] = uvScale; m_uniform.m_uv[i][3][0] = uvOffset; diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index ff0d8695c..35b08d986 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Runtime/CToken.hpp" #include @@ -10,7 +12,7 @@ class CTexture; class CXRayBlurFilter { struct Uniform { - zeus::CMatrix4f m_uv[8]; + std::array m_uv; }; TLockedToken m_paletteTex; boo::ObjToken m_booTex; diff --git a/Runtime/World/CFluidPlaneGPU.cpp b/Runtime/World/CFluidPlaneGPU.cpp index 1bab07312..858df7af3 100644 --- a/Runtime/World/CFluidPlaneGPU.cpp +++ b/Runtime/World/CFluidPlaneGPU.cpp @@ -52,19 +52,19 @@ void CFluidPlaneGPU::RenderStripWithRipples(float curY, const CFluidPlaneRender: break; } - std::fill(std::begin(pv.m_outerLevels), std::end(pv.m_outerLevels), subdivF); - std::fill(std::begin(pv.m_innerLevels), std::end(pv.m_innerLevels), subdivF); + pv.m_outerLevels.fill(subdivF); + pv.m_innerLevels.fill(subdivF); } else { - bool r19 = (flags[yTile + 1][xTile] & 0x2) != 0; // North - bool r16 = (flags[yTile][xTile - 1] & 0x8) != 0; // West - bool r18 = (flags[yTile][xTile + 1] & 0x4) != 0; // East - bool r17 = (flags[yTile - 1][xTile] & 0x1) != 0; // South + const bool r19 = (flags[yTile + 1][xTile] & 0x2) != 0; // North + const bool r16 = (flags[yTile][xTile - 1] & 0x8) != 0; // West + const bool r18 = (flags[yTile][xTile + 1] & 0x4) != 0; // East + const bool r17 = (flags[yTile - 1][xTile] & 0x1) != 0; // South pv.m_outerLevels[0] = r16 ? subdivF : 1.f; pv.m_outerLevels[1] = r17 ? subdivF : 1.f; pv.m_outerLevels[2] = r18 ? subdivF : 1.f; pv.m_outerLevels[3] = r19 ? subdivF : 1.f; - std::fill(std::begin(pv.m_innerLevels), std::end(pv.m_innerLevels), subdivF); + pv.m_innerLevels.fill(subdivF); } float curTileY = yMin;