metaforce/Runtime/Graphics/Shaders/CEnergyBarShader.cpp

81 lines
2.6 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "CEnergyBarShader.cpp.hshhead"
2018-12-08 05:30:43 +00:00
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);
}
};
2017-04-02 03:03:37 +00:00
2018-12-08 05:30:43 +00:00
void CEnergyBarShader::updateModelMatrix() {
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
2017-04-02 03:03:37 +00:00
}
2018-12-08 05:30:43 +00:00
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>& verts2, hsh::texture2d tex) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta);
2018-12-08 05:30:43 +00:00
size_t totalVerts = verts0.size() + verts1.size() + verts2.size();
if (totalVerts == 0) {
2018-12-08 05:30:43 +00:00
return;
}
2017-04-02 03:03:37 +00:00
2018-12-08 05:30:43 +00:00
if (totalVerts > m_maxVerts) {
m_maxVerts = totalVerts;
m_vbo = hsh::create_dynamic_vertex_buffer<Vertex>(m_maxVerts);
for (size_t i = 0; i < m_uniBuf.size(); ++i) {
if (!m_uniBuf[i]) {
m_uniBuf[i] = hsh::create_dynamic_uniform_buffer<Uniform>();
2018-12-08 05:30:43 +00:00
}
m_dataBind[i].hsh_bind(CEnergyBarShaderPipeline(m_vbo.get(), m_uniBuf[i].get(), tex));
}
2018-12-08 05:30:43 +00:00
}
2017-04-02 03:03:37 +00:00
2018-12-08 05:30:43 +00:00
size_t vertIter = 0;
Vertex* verts = m_vbo.map();
if (!verts0.empty()) {
std::memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size());
2018-12-08 05:30:43 +00:00
vertIter += verts0.size();
}
if (!verts1.empty()) {
std::memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size());
2018-12-08 05:30:43 +00:00
vertIter += verts1.size();
}
if (!verts2.empty()) {
std::memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size());
2018-12-08 05:30:43 +00:00
}
m_vbo.unmap();
2017-04-02 03:03:37 +00:00
2018-12-08 05:30:43 +00:00
vertIter = 0;
if (!verts0.empty()) {
2018-12-08 05:30:43 +00:00
m_uniform.m_color = color0;
m_uniBuf[0].load(m_uniform);
m_dataBind[0].draw_indexed(0, verts0.size());
2018-12-08 05:30:43 +00:00
vertIter += verts0.size();
}
if (!verts1.empty()) {
2018-12-08 05:30:43 +00:00
m_uniform.m_color = color1;
m_uniBuf[1].load(m_uniform);
m_dataBind[1].draw_indexed(vertIter, verts1.size());
2018-12-08 05:30:43 +00:00
vertIter += verts1.size();
}
if (!verts2.empty()) {
2018-12-08 05:30:43 +00:00
m_uniform.m_color = color2;
m_uniBuf[2].load(m_uniform);
m_dataBind[2].draw_indexed(vertIter, verts2.size());
2018-12-08 05:30:43 +00:00
}
2017-04-02 03:03:37 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde