2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-14 19:25:51 +00:00

CEnergyBarShader: Convert to hsh pipeline

This commit is contained in:
Luke Street 2020-09-29 18:21:20 -04:00
parent 2d786e4318
commit c596834fdf
6 changed files with 54 additions and 54 deletions

View File

@ -11,7 +11,8 @@ using namespace hsh::pipeline;
template <bool zOnly> template <bool zOnly>
struct CAABoxShaderPipeline struct CAABoxShaderPipeline
: pipeline<std::conditional_t<zOnly, NoColorAttachment<>, BlendAttachment<>>, depth_compare<hsh::LEqual>> { : pipeline<topology<hsh::TriangleStrip>, std::conditional_t<zOnly, NoColorAttachment<>, BlendAttachment<>>,
depth_compare<hsh::LEqual>> {
CAABoxShaderPipeline(hsh::vertex_buffer<CAABoxShader::Vert> vbo, hsh::uniform_buffer<CAABoxShader::Uniform> uniBuf) { CAABoxShaderPipeline(hsh::vertex_buffer<CAABoxShader::Vert> vbo, hsh::uniform_buffer<CAABoxShader::Uniform> uniBuf) {
this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f); this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f);
this->color_out[0] = uniBuf->m_color; this->color_out[0] = uniBuf->m_color;

View File

@ -25,7 +25,8 @@ struct CColoredStripShaderColorAttachment<CColoredStripShader::Mode::Subtractive
template <CColoredStripShader::Mode Mode> template <CColoredStripShader::Mode Mode>
// TODO typename == hsh bug? // TODO typename == hsh bug?
struct CColoredStripShaderPipeline : pipeline<typename CColoredStripShaderColorAttachment<Mode>::color_attachment, struct CColoredStripShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, typename CColoredStripShaderColorAttachment<Mode>::color_attachment,
depth_compare<hsh::LEqual>, depth_write<false>> { depth_compare<hsh::LEqual>, depth_write<false>> {
CColoredStripShaderPipeline(hsh::vertex_buffer<CColoredStripShader::Vert> vbo, CColoredStripShaderPipeline(hsh::vertex_buffer<CColoredStripShader::Vert> vbo,
hsh::uniform_buffer<CColoredStripShader::Uniform> uniBuf, hsh::texture2d tex) { hsh::uniform_buffer<CColoredStripShader::Uniform> uniBuf, hsh::texture2d tex) {

View File

@ -11,7 +11,8 @@ using namespace hsh::pipeline;
template <bool Additive, bool RedToAlpha> template <bool Additive, bool RedToAlpha>
struct CDecalShaderTexPipeline struct CDecalShaderTexPipeline
: pipeline<std::conditional_t<Additive, std::conditional_t<RedToAlpha, MultiplyAttachment<>, AdditiveAttachment<>>, : pipeline<topology<hsh::TriangleStrip>,
std::conditional_t<Additive, std::conditional_t<RedToAlpha, MultiplyAttachment<>, AdditiveAttachment<>>,
BlendAttachment<>>, BlendAttachment<>>,
depth_compare<hsh::LEqual>, depth_write<false>> { depth_compare<hsh::LEqual>, depth_write<false>> {
CDecalShaderTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo, hsh::uniform_buffer<SParticleUniforms> uniBuf, CDecalShaderTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo, hsh::uniform_buffer<SParticleUniforms> uniBuf,

View File

@ -1,11 +1,20 @@
#include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp" #include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp"
#include <cstring>
#include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CTexture.hpp"
#include "CEnergyBarShader.cpp.hshhead"
namespace urde { namespace urde {
using namespace hsh::pipeline;
struct CEnergyBarShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, AdditiveAttachment<>, depth_compare<hsh::LEqual>, depth_write<false>> {
CEnergyBarShaderPipeline(hsh::vertex_buffer<CEnergyBarShader::Vertex> vbo,
hsh::uniform_buffer<CEnergyBarShader::Uniform> uniBuf, hsh::texture2d tex) {
this->position = uniBuf->m_matrix * hsh::float4(vbo->pos, 1.f);
this->color_out[0] = uniBuf->m_color * tex.sample<float>(vbo->uv);
}
};
void CEnergyBarShader::updateModelMatrix() { void CEnergyBarShader::updateModelMatrix() {
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); 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<Vertex>& verts0, const zeus::CColor& color1, void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1,
const std::vector<Vertex>& verts1, const zeus::CColor& color2, const std::vector<Vertex>& verts1, const zeus::CColor& color2,
const std::vector<Vertex>& verts2, const CTexture* tex) { const std::vector<Vertex>& verts2, hsh::texture2d tex) {
SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta); SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta);
size_t totalVerts = verts0.size() + verts1.size() + verts2.size(); size_t totalVerts = verts0.size() + verts1.size() + verts2.size();
if (!totalVerts) if (totalVerts == 0) {
return; return;
}
if (totalVerts > m_maxVerts) { if (totalVerts > m_maxVerts) {
m_maxVerts = totalVerts; 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<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs;
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
const std::array<boo::ObjToken<boo::ITexture>, 1> texs{m_tex->GetBooTexture()};
m_vbo = hsh::create_dynamic_vertex_buffer<Vertex>(m_maxVerts);
for (size_t i = 0; i < m_uniBuf.size(); ++i) { for (size_t i = 0; i < m_uniBuf.size(); ++i) {
m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); if (!m_uniBuf[i]) {
bufs[0] = m_uniBuf[i].get(); m_uniBuf[i] = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind[i] = }
ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), m_dataBind[i].hsh_bind(CEnergyBarShaderPipeline(m_vbo.get(), m_uniBuf[i].get(), tex));
nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
} }
return true;
} BooTrace);
} }
size_t vertIter = 0; size_t vertIter = 0;
Vertex* verts = reinterpret_cast<Vertex*>(m_vbo->map(sizeof(Vertex) * totalVerts)); Vertex* verts = m_vbo.map();
if (verts0.size()) { if (!verts0.empty()) {
memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); std::memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size());
vertIter += verts0.size(); vertIter += verts0.size();
} }
if (verts1.size()) { if (!verts1.empty()) {
memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); std::memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size());
vertIter += verts1.size(); vertIter += verts1.size();
} }
if (verts2.size()) { if (!verts2.empty()) {
memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); std::memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size());
} }
m_vbo->unmap(); m_vbo.unmap();
vertIter = 0; vertIter = 0;
if (verts0.size()) { if (!verts0.empty()) {
m_uniform.m_color = color0; m_uniform.m_color = color0;
m_uniBuf[0]->load(&m_uniform, sizeof(Uniform)); m_uniBuf[0].load(m_uniform);
CGraphics::SetShaderDataBinding(m_dataBind[0]); m_dataBind[0].draw_indexed(0, verts0.size());
CGraphics::DrawArray(0, verts0.size());
vertIter += verts0.size(); vertIter += verts0.size();
} }
if (verts1.size()) { if (!verts1.empty()) {
m_uniform.m_color = color1; m_uniform.m_color = color1;
m_uniBuf[1]->load(&m_uniform, sizeof(Uniform)); m_uniBuf[1].load(m_uniform);
CGraphics::SetShaderDataBinding(m_dataBind[1]); m_dataBind[1].draw_indexed(vertIter, verts1.size());
CGraphics::DrawArray(vertIter, verts1.size());
vertIter += verts1.size(); vertIter += verts1.size();
} }
if (verts2.size()) { if (!verts2.empty()) {
m_uniform.m_color = color2; m_uniform.m_color = color2;
m_uniBuf[2]->load(&m_uniform, sizeof(Uniform)); m_uniBuf[2].load(m_uniform);
CGraphics::SetShaderDataBinding(m_dataBind[2]); m_dataBind[2].draw_indexed(vertIter, verts2.size());
CGraphics::DrawArray(vertIter, verts2.size());
} }
} }

View File

@ -14,27 +14,26 @@ class CTexture;
class CEnergyBarShader { class CEnergyBarShader {
public: public:
struct Vertex { struct Vertex {
zeus::CVector3f pos; hsh::float3 pos;
zeus::CVector2f uv; hsh::float2 uv;
};
struct Uniform {
hsh::float4x4 m_matrix;
hsh::float4 m_color;
}; };
private: private:
struct Uniform {
zeus::CMatrix4f m_matrix;
zeus::CColor m_color;
};
hsh::dynamic_owner<hsh::vertex_buffer<Vertex>> m_vbo; hsh::dynamic_owner<hsh::vertex_buffer<Vertex>> m_vbo;
std::array<hsh::dynamic_owner<hsh::uniform_buffer<Uniform>>, 3> m_uniBuf; std::array<hsh::dynamic_owner<hsh::uniform_buffer<Uniform>>, 3> m_uniBuf;
std::array<hsh::binding, 3> m_dataBind; std::array<hsh::binding, 3> m_dataBind;
Uniform m_uniform; Uniform m_uniform;
const CTexture* m_tex = nullptr;
size_t m_maxVerts = 0; size_t m_maxVerts = 0;
public: public:
void updateModelMatrix(); void updateModelMatrix();
void draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1, void draw(const zeus::CColor& color0, const std::vector<Vertex>& verts0, const zeus::CColor& color1,
const std::vector<Vertex>& verts1, const zeus::CColor& color2, const std::vector<Vertex>& verts2, const std::vector<Vertex>& verts1, const zeus::CColor& color2, const std::vector<Vertex>& verts2,
const CTexture* tex); hsh::texture2d tex);
}; };
} // namespace urde } // namespace urde

View File

@ -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) { void CAuiEnergyBarT01::SetCurrEnergy(float e, ESetMode mode) {