From c596834fdff9e0c351e0ce163d4517f905826244 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 29 Sep 2020 18:21:20 -0400 Subject: [PATCH] CEnergyBarShader: Convert to hsh pipeline --- Runtime/Graphics/Shaders/CAABoxShader.cpp | 3 +- .../Graphics/Shaders/CColoredStripShader.cpp | 5 +- Runtime/Graphics/Shaders/CDecalShaders.cpp | 3 +- Runtime/Graphics/Shaders/CEnergyBarShader.cpp | 79 +++++++++---------- Runtime/Graphics/Shaders/CEnergyBarShader.hpp | 15 ++-- Runtime/GuiSys/CAuiEnergyBarT01.cpp | 3 +- 6 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 17b2e4067..7712a0e82 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -11,7 +11,8 @@ using namespace hsh::pipeline; template struct CAABoxShaderPipeline -: pipeline, BlendAttachment<>>, depth_compare> { +: pipeline, std::conditional_t, BlendAttachment<>>, + depth_compare> { CAABoxShaderPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf) { this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f); this->color_out[0] = uniBuf->m_color; diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index 7e07ef312..d824adb54 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -25,8 +25,9 @@ struct CColoredStripShaderColorAttachment // TODO typename == hsh bug? -struct CColoredStripShaderPipeline : pipeline::color_attachment, - depth_compare, depth_write> { +struct CColoredStripShaderPipeline +: pipeline, typename CColoredStripShaderColorAttachment::color_attachment, + depth_compare, depth_write> { CColoredStripShaderPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf, hsh::texture2d tex) { this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f); diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index 3db79f1c4..e2ec9c79b 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -11,7 +11,8 @@ using namespace hsh::pipeline; template struct CDecalShaderTexPipeline -: pipeline, AdditiveAttachment<>>, +: pipeline, + std::conditional_t, AdditiveAttachment<>>, BlendAttachment<>>, depth_compare, depth_write> { CDecalShaderTexPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf, diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index 7dbf0ef56..a8561ecc0 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -1,11 +1,20 @@ #include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp" -#include - #include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" + +#include "CEnergyBarShader.cpp.hshhead" namespace urde { +using namespace hsh::pipeline; + +struct CEnergyBarShaderPipeline +: pipeline, AdditiveAttachment<>, depth_compare, depth_write> { + CEnergyBarShaderPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf, hsh::texture2d tex) { + this->position = uniBuf->m_matrix * hsh::float4(vbo->pos, 1.f); + this->color_out[0] = uniBuf->m_color * tex.sample(vbo->uv); + } +}; void CEnergyBarShader::updateModelMatrix() { m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); @@ -13,70 +22,58 @@ void CEnergyBarShader::updateModelMatrix() { void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector& verts0, const zeus::CColor& color1, const std::vector& verts1, const zeus::CColor& color2, - const std::vector& verts2, const CTexture* tex) { + const std::vector& verts2, hsh::texture2d tex) { SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta); size_t totalVerts = verts0.size() + verts1.size() + verts2.size(); - if (!totalVerts) + if (totalVerts == 0) { return; + } if (totalVerts > m_maxVerts) { m_maxVerts = totalVerts; - m_tex = tex; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), m_maxVerts); - 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, bufs.size(), bufs.data(), stages.data(), - nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); + m_vbo = hsh::create_dynamic_vertex_buffer(m_maxVerts); + for (size_t i = 0; i < m_uniBuf.size(); ++i) { + if (!m_uniBuf[i]) { + m_uniBuf[i] = hsh::create_dynamic_uniform_buffer(); } - - return true; - } BooTrace); + m_dataBind[i].hsh_bind(CEnergyBarShaderPipeline(m_vbo.get(), m_uniBuf[i].get(), tex)); + } } size_t vertIter = 0; - Vertex* verts = reinterpret_cast(m_vbo->map(sizeof(Vertex) * totalVerts)); - if (verts0.size()) { - memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); + Vertex* verts = m_vbo.map(); + if (!verts0.empty()) { + std::memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); vertIter += verts0.size(); } - if (verts1.size()) { - memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); + if (!verts1.empty()) { + std::memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); vertIter += verts1.size(); } - if (verts2.size()) { - memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); + if (!verts2.empty()) { + std::memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); } - m_vbo->unmap(); + m_vbo.unmap(); vertIter = 0; - if (verts0.size()) { + if (!verts0.empty()) { m_uniform.m_color = color0; - m_uniBuf[0]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[0]); - CGraphics::DrawArray(0, verts0.size()); + m_uniBuf[0].load(m_uniform); + m_dataBind[0].draw_indexed(0, verts0.size()); vertIter += verts0.size(); } - if (verts1.size()) { + if (!verts1.empty()) { m_uniform.m_color = color1; - m_uniBuf[1]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[1]); - CGraphics::DrawArray(vertIter, verts1.size()); + m_uniBuf[1].load(m_uniform); + m_dataBind[1].draw_indexed(vertIter, verts1.size()); vertIter += verts1.size(); } - if (verts2.size()) { + if (!verts2.empty()) { m_uniform.m_color = color2; - m_uniBuf[2]->load(&m_uniform, sizeof(Uniform)); - CGraphics::SetShaderDataBinding(m_dataBind[2]); - CGraphics::DrawArray(vertIter, verts2.size()); + m_uniBuf[2].load(m_uniform); + m_dataBind[2].draw_indexed(vertIter, verts2.size()); } } diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp index 4f0b4a2cd..65924d192 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp @@ -14,27 +14,26 @@ class CTexture; class CEnergyBarShader { public: struct Vertex { - zeus::CVector3f pos; - zeus::CVector2f uv; + hsh::float3 pos; + hsh::float2 uv; + }; + struct Uniform { + hsh::float4x4 m_matrix; + hsh::float4 m_color; }; private: - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; hsh::dynamic_owner> m_vbo; std::array>, 3> m_uniBuf; std::array m_dataBind; Uniform m_uniform; - const CTexture* m_tex = nullptr; size_t m_maxVerts = 0; public: void updateModelMatrix(); void draw(const zeus::CColor& color0, const std::vector& verts0, const zeus::CColor& color1, const std::vector& verts1, const zeus::CColor& color2, const std::vector& verts2, - const CTexture* tex); + hsh::texture2d tex); }; } // namespace urde diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.cpp b/Runtime/GuiSys/CAuiEnergyBarT01.cpp index d30345c86..4676352b0 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.cpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.cpp @@ -118,7 +118,8 @@ void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) { } } - m_energyBarShader.draw(filledColor, m_verts[0], shadowColor, m_verts[1], emptyColor, m_verts[2], xbc_tex.GetObj()); + hsh::texture2d tex = xbc_tex.GetObj()->GetBooTexture(); + m_energyBarShader.draw(filledColor, m_verts[0], shadowColor, m_verts[1], emptyColor, m_verts[2], tex); } void CAuiEnergyBarT01::SetCurrEnergy(float e, ESetMode mode) {