metaforce/Runtime/GuiSys/CTextRenderBuffer.hpp

146 lines
4.2 KiB
C++
Raw Normal View History

2016-03-19 00:07:31 +00:00
#ifndef __URDE_CTEXTRENDERBUFFER_HPP__
#define __URDE_CTEXTRENDERBUFFER_HPP__
#include "zeus/CColor.hpp"
#include "zeus/CVector2i.hpp"
2016-03-22 08:15:00 +00:00
#include "zeus/CVector2f.hpp"
#include "zeus/CMatrix4f.hpp"
2016-03-19 00:07:31 +00:00
#include "CToken.hpp"
2016-03-22 08:15:00 +00:00
#include "CFontImageDef.hpp"
2016-03-19 00:07:31 +00:00
#include "RetroTypes.hpp"
2017-01-29 03:58:16 +00:00
#include "CGuiWidget.hpp"
#include "Graphics/Shaders/CTextSupportShader.hpp"
2016-03-22 08:15:00 +00:00
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
2016-03-19 00:07:31 +00:00
namespace urde
{
class CGraphicsPalette;
class CRasterFont;
2016-03-22 08:15:00 +00:00
class CGlyph;
2016-12-30 06:37:01 +00:00
class CTextExecuteBuffer;
2016-03-19 00:07:31 +00:00
2016-03-21 22:01:19 +00:00
using CTextColor = zeus::CColor;
2016-03-19 00:07:31 +00:00
class CTextRenderBuffer
{
2016-03-21 22:01:19 +00:00
friend class CGuiTextSupport;
2017-01-29 03:58:16 +00:00
friend class CTextSupportShader;
2016-03-19 00:07:31 +00:00
public:
2016-03-22 08:15:00 +00:00
enum class Command
{
CharacterRender,
ImageRender,
FontChange,
PaletteChange
};
2016-12-31 00:51:51 +00:00
#if 0
2016-03-19 00:07:31 +00:00
struct Primitive
{
2016-03-21 22:01:19 +00:00
CTextColor x0_color1;
2016-03-22 08:15:00 +00:00
Command x4_command;
u16 x8_xPos;
u16 xa_zPos;
wchar_t xc_glyph;
u8 xe_imageIndex;
2016-03-19 00:07:31 +00:00
};
2016-12-31 00:51:51 +00:00
#endif
2016-03-19 00:07:31 +00:00
enum class EMode
{
2016-03-22 08:15:00 +00:00
AllocTally,
BufferFill
2016-03-19 00:07:31 +00:00
};
2016-03-22 08:15:00 +00:00
2016-03-19 00:07:31 +00:00
private:
EMode x0_mode;
2016-03-22 08:15:00 +00:00
#if 0
2016-03-19 00:07:31 +00:00
std::vector<TToken<CRasterFont>> x4_fonts;
std::vector<CFontImageDef> x14_images;
std::vector<int> x24_primOffsets;
2016-03-22 08:15:00 +00:00
std::vector<char> x34_bytecode;
2016-03-19 00:07:31 +00:00
u32 x44_blobSize = 0;
2016-03-22 08:15:00 +00:00
u32 x48_curBytecodeOffset = 0;
2016-12-31 00:51:51 +00:00
u8 x4c_activeFont;
2016-03-19 00:07:31 +00:00
u32 x50_paletteCount = 0;
2016-03-22 08:15:00 +00:00
std::array<std::unique_ptr<CGraphicsPalette>, 64> x54_palettes;
2016-03-19 00:07:31 +00:00
u32 x254_nextPalette = 0;
2016-03-22 08:15:00 +00:00
#else
/* Boo-specific text-rendering functionality */
2017-01-29 03:58:16 +00:00
hecl::UniformBufferPool<CTextSupportShader::Uniform>::Token m_uniBuf;
hecl::UniformBufferPool<CTextSupportShader::Uniform>::Token m_uniBuf2;
2016-03-22 08:15:00 +00:00
struct BooFontCharacters
{
2017-01-29 03:58:16 +00:00
TLockedToken<CRasterFont> m_font;
hecl::VertexBufferPool<CTextSupportShader::CharacterInstance>::Token m_instBuf;
boo::ObjToken<boo::IShaderDataBinding> m_dataBinding;
boo::ObjToken<boo::IShaderDataBinding> m_dataBinding2;
2017-01-29 03:58:16 +00:00
std::vector<CTextSupportShader::CharacterInstance> m_charData;
2016-03-22 08:15:00 +00:00
u32 m_charCount = 0;
bool m_dirty = true;
2016-03-22 18:35:52 +00:00
BooFontCharacters(const CToken& token)
2017-01-29 03:58:16 +00:00
: m_font(token) {}
2016-03-22 08:15:00 +00:00
};
std::vector<BooFontCharacters> m_fontCharacters;
struct BooImage
{
CFontImageDef m_imageDef;
2017-01-29 03:58:16 +00:00
hecl::VertexBufferPool<CTextSupportShader::ImageInstance>::Token m_instBuf;
std::vector<boo::ObjToken<boo::IShaderDataBinding>> m_dataBinding;
std::vector<boo::ObjToken<boo::IShaderDataBinding>> m_dataBinding2;
2017-01-29 03:58:16 +00:00
CTextSupportShader::ImageInstance m_imageData;
2016-03-22 08:15:00 +00:00
bool m_dirty = true;
2016-12-31 00:51:51 +00:00
BooImage(const CFontImageDef& imgDef, const zeus::CVector2i& offset);
2016-03-22 08:15:00 +00:00
};
std::vector<BooImage> m_images;
struct BooPrimitiveMark
{
Command m_cmd;
u32 m_bindIdx;
u32 m_instIdx;
void SetOpacity(CTextRenderBuffer& rb, float opacity);
};
std::vector<BooPrimitiveMark> m_primitiveMarks;
u32 m_imagesCount = 0;
u32 m_activeFontCh = -1;
zeus::CColor m_main;
2017-02-13 21:29:00 +00:00
zeus::CColor m_outline = zeus::CColor::skBlack;
2016-03-22 08:15:00 +00:00
2017-01-29 03:58:16 +00:00
CGuiWidget::EGuiModelDrawFlags m_drawFlags;
2016-03-22 08:15:00 +00:00
bool m_committed = false;
void CommitResources();
#endif
2016-03-19 00:07:31 +00:00
public:
2017-01-29 03:58:16 +00:00
CTextRenderBuffer(EMode mode, CGuiWidget::EGuiModelDrawFlags df);
2016-03-22 08:15:00 +00:00
#if 0
2016-03-19 00:07:31 +00:00
void SetPrimitive(const Primitive&, int);
Primitive GetPrimitive(int) const;
void GetOutStream();
void VerifyBuffer();
int GetMatchingPaletteIndex(const CGraphicsPalette& palette);
CGraphicsPalette* GetNextAvailablePalette();
2016-03-22 08:15:00 +00:00
void AddPaletteChange(const CGraphicsPalette& palette);
#else
void SetPrimitiveOpacity(int idx, float opacity);
2016-12-31 00:51:51 +00:00
u32 GetPrimitiveCount() const { return m_primitiveMarks.size(); }
2016-03-22 08:15:00 +00:00
#endif
void SetMode(EMode mode);
void Render(const zeus::CColor& col, float) const;
void AddImage(const zeus::CVector2i& offset, const CFontImageDef& image);
2017-01-29 03:58:16 +00:00
void AddCharacter(const zeus::CVector2i& offset, char16_t ch, const zeus::CColor& color);
2016-03-22 08:15:00 +00:00
void AddPaletteChange(const zeus::CColor& main, const zeus::CColor& outline);
void AddFontChange(const TToken<CRasterFont>& font);
2016-03-19 00:07:31 +00:00
2016-12-31 00:51:51 +00:00
bool HasSpaceAvailable(const zeus::CVector2i& origin, const zeus::CVector2i& extent) const;
std::pair<zeus::CVector2i, zeus::CVector2i> AccumulateTextBounds() const;
2016-12-30 06:37:01 +00:00
};
2016-03-19 00:07:31 +00:00
}
#endif // __URDE_CTEXTRENDERBUFFER_HPP__