metaforce/Runtime/Graphics/Shaders/CAABoxShader.cpp

68 lines
3.0 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/Shaders/CAABoxShader.hpp"
#include <array>
2020-09-29 04:58:21 +00:00
#include <zeus/CAABox.hpp>
#include "Runtime/Graphics/CGraphics.hpp"
2020-09-29 04:58:21 +00:00
#include "CAABoxShader.cpp.hshhead"
2017-09-03 05:53:38 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
2020-09-29 04:58:21 +00:00
using namespace hsh::pipeline;
template <bool zOnly>
struct CAABoxShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, std::conditional_t<zOnly, NoColorAttachment<>, BlendAttachment<>>,
depth_compare<hsh::LEqual>> {
2020-09-29 04:58:21 +00:00
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->color_out[0] = uniBuf->m_color;
}
};
template struct CAABoxShaderPipeline<true>;
template struct CAABoxShaderPipeline<false>;
CAABoxShader::CAABoxShader(const zeus::CAABox& aabb, bool zOnly) {
const std::array<Vert, 34> verts{{
{{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()}},
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
{{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.min.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}},
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
{{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()}},
}};
2017-09-03 05:53:38 +00:00
2020-09-29 04:58:21 +00:00
m_vbo = hsh::create_vertex_buffer(verts);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_bind(CAABoxShaderPipeline<zOnly>(m_vbo.get(), m_uniBuf.get()));
2017-09-03 05:53:38 +00:00
}
2018-12-08 05:30:43 +00:00
void CAABoxShader::draw(const zeus::CColor& color) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta);
2018-12-08 05:30:43 +00:00
m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = color;
2020-09-29 04:58:21 +00:00
m_uniBuf.load(m_uniform);
2017-09-03 05:53:38 +00:00
2020-09-29 04:58:21 +00:00
m_dataBind.draw(0, 34);
2017-09-03 05:53:38 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde