metaforce/Runtime/Graphics/Shaders/CAABoxShader.cpp

71 lines
3.5 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 <ERglCullMode CullMode, ERglEnum Compare, bool DepthWrite, ERglBlendMode Mode, ERglBlendFactor SrcFac,
ERglBlendFactor DstFac, ERglLogicOp Op, bool AlphaWrite>
2020-09-29 04:58:21 +00:00
struct CAABoxShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, ERglBlendModeAttachment<Mode, SrcFac, DstFac, Op, AlphaWrite>,
ERglCullModeAttachment<CullMode>, ERglDepthCompareAttachment<Compare>, depth_write<DepthWrite>> {
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<ERglCullMode::None, ERglEnum::LEqual, true, ERglBlendMode::Blend,
ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear, true>;
2020-09-29 04:58:21 +00:00
constexpr size_t VertexCount = 34;
CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) {
const std::array<Vert, VertexCount> verts{{
2020-09-29 04:58:21 +00:00
{{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<gx_CullMode, gx_DepthTest, gx_DepthWrite, gx_BlendMode, gx_BlendSrcFac,
gx_BlendDstFac, gx_BlendOp, gx_AlphaWrite>(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
m_dataBind.draw(0, VertexCount);
2017-09-03 05:53:38 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde