metaforce/Runtime/Graphics/Shaders/CTextSupportShader.cpp

82 lines
3.3 KiB
C++
Raw Permalink Normal View History

#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp"
2020-04-20 01:09:30 +00:00
#include "Runtime/GuiSys/CFontImageDef.hpp"
#include "Runtime/GuiSys/CRasterFont.hpp"
#include <hecl/Pipeline.hpp>
2017-01-29 03:58:16 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-01-29 03:58:16 +00:00
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAlphaPipeline;
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAddPipeline;
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_TextAddOverdrawPipeline;
2017-01-29 03:58:16 +00:00
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAlphaPipeline;
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAddPipeline;
boo::ObjToken<boo::IShaderPipeline> CTextSupportShader::s_ImageAddOverdrawPipeline;
2017-01-29 03:58:16 +00:00
hecl::VertexBufferPool<CTextSupportShader::CharacterInstance> CTextSupportShader::s_CharInsts;
hecl::VertexBufferPool<CTextSupportShader::ImageInstance> CTextSupportShader::s_ImgInsts;
hecl::UniformBufferPool<CTextSupportShader::Uniform> CTextSupportShader::s_Uniforms;
2018-12-08 05:30:43 +00:00
void CTextSupportShader::Initialize() {
s_TextAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderAlpha{});
s_TextAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderAdd{});
s_TextAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderAddOverdraw{});
s_ImageAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAlpha{});
s_ImageAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAdd{});
s_ImageAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAddOverdraw{});
2018-10-07 02:59:17 +00:00
}
2018-12-08 05:30:43 +00:00
void CTextSupportShader::Shutdown() {
s_TextAlphaPipeline.reset();
s_TextAddPipeline.reset();
s_TextAddOverdrawPipeline.reset();
s_ImageAlphaPipeline.reset();
s_ImageAddPipeline.reset();
s_ImageAddOverdrawPipeline.reset();
s_CharInsts.doDestroy();
s_ImgInsts.doDestroy();
s_Uniforms.doDestroy();
2018-10-07 02:59:17 +00:00
}
2018-12-08 05:30:43 +00:00
void CTextSupportShader::CharacterInstance::SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset) {
float layer = glyph.GetLayer();
2017-01-29 03:58:16 +00:00
2018-12-08 05:30:43 +00:00
m_pos[0].assign(offset.x, 0.f, offset.y);
m_uv[0].assign(glyph.GetStartU(), 1.f - glyph.GetStartV(), layer);
2017-01-29 03:58:16 +00:00
2018-12-08 05:30:43 +00:00
m_pos[1].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y);
m_uv[1].assign(glyph.GetEndU(), 1.f - glyph.GetStartV(), layer);
2017-01-29 03:58:16 +00:00
2018-12-08 05:30:43 +00:00
m_pos[2].assign(offset.x, 0.f, offset.y + glyph.GetCellHeight());
m_uv[2].assign(glyph.GetStartU(), 1.f - glyph.GetEndV(), layer);
2017-01-29 03:58:16 +00:00
2018-12-08 05:30:43 +00:00
m_pos[3].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y + glyph.GetCellHeight());
m_uv[3].assign(glyph.GetEndU(), 1.f - glyph.GetEndV(), layer);
2017-01-29 03:58:16 +00:00
}
2018-12-08 05:30:43 +00:00
void CTextSupportShader::ImageInstance::SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset) {
zeus::CVector2f imgSize;
if (imgDef.x4_texs.size()) {
const CTexture& tex = *imgDef.x4_texs[0].GetObj();
imgSize.assign(tex.GetWidth() * imgDef.x14_cropFactor.x(), tex.GetHeight() * imgDef.x14_cropFactor.y());
}
zeus::CVector2f cropPad = imgDef.x14_cropFactor * 0.5f;
m_pos[0].assign(offset.x, 0.f, offset.y);
m_uv[0].assign(0.5f - cropPad.x(), 0.5f + cropPad.y());
m_pos[1].assign(offset.x + imgSize.x(), 0.f, offset.y);
m_uv[1].assign(0.5f + cropPad.x(), 0.5f + cropPad.y());
2017-01-29 03:58:16 +00:00
2018-12-08 05:30:43 +00:00
m_pos[2].assign(offset.x, 0.f, offset.y + imgSize.y());
m_uv[2].assign(0.5f - cropPad.x(), 0.5f - cropPad.y());
m_pos[3].assign(offset.x + imgSize.x(), 0.f, offset.y + imgSize.y());
m_uv[3].assign(0.5f + cropPad.x(), 0.5f - cropPad.y());
2017-01-29 03:58:16 +00:00
}
2018-12-08 05:30:43 +00:00
2021-04-10 08:42:06 +00:00
} // namespace metaforce