spritefont takes a vector instead of a null-terminated charset

This commit is contained in:
Noel Berry
2021-03-20 23:24:18 -07:00
parent d388931dd3
commit 9b42bba16e
6 changed files with 75 additions and 50 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include <blah/core/common.h>
#include <type_traits>
#include <initializer_list>
#include <new>
namespace Blah
@ -19,6 +20,7 @@ namespace Blah
Vector(int capacity);
Vector(const Vector& src);
Vector(Vector&& src) noexcept;
Vector(std::initializer_list<T> list);
~Vector();
Vector& operator=(const Vector& src);
@ -95,6 +97,17 @@ namespace Blah
src.m_count = 0;
}
template<class T>
inline Vector<T>::Vector(std::initializer_list<T> list)
{
m_buffer = nullptr;
m_count = m_capacity = 0;
reserve(list.size());
for (auto& it : list)
push_back(std::move(it));
}
template<class T>
inline Vector<T>::~Vector()
{

View File

@ -214,23 +214,23 @@ namespace Blah
scissor(0, 0, -1, -1) {}
};
static ShaderRef m_default_shader;
MaterialRef m_default_material;
MeshRef m_mesh;
Mat3x2 m_matrix;
ColorMode m_color_mode;
u8 m_tex_mult;
u8 m_tex_wash;
DrawBatch m_batch;
Vector<Vertex> m_vertices;
Vector<u32> m_indices;
Vector<Mat3x2> m_matrix_stack;
Vector<Rect> m_scissor_stack;
Vector<BlendMode> m_blend_stack;
Vector<MaterialRef> m_material_stack;
Vector<ColorMode> m_color_mode_stack;
Vector<int> m_layer_stack;
Vector<DrawBatch> m_batches;
static ShaderRef m_default_shader;
MaterialRef m_default_material;
MeshRef m_mesh;
Mat3x2 m_matrix;
ColorMode m_color_mode;
u8 m_tex_mult;
u8 m_tex_wash;
DrawBatch m_batch;
Vector<Vertex> m_vertices;
Vector<u32> m_indices;
Vector<Mat3x2> m_matrix_stack;
Vector<Rect> m_scissor_stack;
Vector<BlendMode> m_blend_stack;
Vector<MaterialRef> m_material_stack;
Vector<ColorMode> m_color_mode_stack;
Vector<int> m_layer_stack;
Vector<DrawBatch> m_batches;
void render_single_batch(RenderPass& pass, const DrawBatch& b, const Mat4x4& matrix);
};

View File

@ -10,6 +10,21 @@ namespace Blah
{
class Font;
struct CharacterRange;
using CharacterSet = Vector<CharacterRange>;
struct CharacterRange
{
u32 from;
u32 to;
CharacterRange();
CharacterRange(u32 single);
CharacterRange(u32 from, u32 to);
static const CharacterSet ASCII;
};
class SpriteFont
{
public:
@ -28,7 +43,6 @@ namespace Blah
Vector<TextureRef> m_atlas;
public:
static const u32* ASCII;
String name;
float size;
@ -36,14 +50,11 @@ namespace Blah
float descent;
float line_gap;
// Note:
// charset is a list of range pairs, until a 0 terminator (ex. 32,128,0)
SpriteFont();
SpriteFont(const char* file, float size);
SpriteFont(const char* file, float size, const u32* charset);
SpriteFont(const char* file, float size, const CharacterSet& charset);
SpriteFont(const Font& font, float size);
SpriteFont(const Font& font, float size, const u32* charset);
SpriteFont(const Font& font, float size, const CharacterSet& charset);
SpriteFont(const SpriteFont&) = delete;
SpriteFont(SpriteFont&& src) noexcept;
~SpriteFont();
@ -62,8 +73,8 @@ namespace Blah
float width_of_line(const String& text, int start = 0) const;
float height_of(const String& text) const;
void build(const char* file, float size, const u32* charset);
void build(const Font& font, float size, const u32* charset);
void build(const char* file, float size, const CharacterSet& charset);
void build(const Font& font, float size, const CharacterSet& charset);
float get_kerning(u32 codepoint0, u32 codepoint1) const;
void set_kerning(u32 codepoint0, u32 codepoint1, float kerning);

View File

@ -4,16 +4,8 @@
#include <blah/math/color.h>
#include <memory>
// 4 color attachments + 1 depth/stencil
#define BLAH_ATTACHMENTS 5
namespace Blah
{
typedef StackVector<TextureRef, BLAH_ATTACHMENTS> Attachments;
class FrameBuffer;
typedef std::shared_ptr<FrameBuffer> FrameBufferRef;
enum class ClearMask
{
None = 0,
@ -23,6 +15,12 @@ namespace Blah
All = (int)Color | (int)Depth | (int)Stencil
};
// Up to 4 color attachments + 1 depth/stencil
using Attachments = StackVector<TextureRef, 5>;
class FrameBuffer;
using FrameBufferRef = std::shared_ptr<FrameBuffer>;
class FrameBuffer
{
protected: