FontMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Font.hpp"
4 
5 #include "../Rendering/FlatShader.hpp"
6 #include "../Elements/ElementRenderer.hpp"
7 
8 namespace iv
9 {
10 
13 class FontMesh
14 {
15 public:
16  struct LineState
17  {
19  float preadvance;
20 
22  float ascender;
23  float descender;
24 
25  LineState() : basepoint( 0, 0 ), preadvance( 0 ), baseline_fixed( false ), ascender( 0 ), descender( 0 ){}
26  bool operator==( LineState const & b ) { return this->basepoint==b.basepoint && this->baseline_fixed==b.baseline_fixed && this->ascender==b.ascender && this->descender==b.descender; }
27  };
28 
29  struct Location
30  {
32  float line_spacing;
33 
35 
36  unsigned skip_characters;
37 
38  Location() : size( 0, 0 ), line_spacing( 0 ), line_state(), skip_characters( 0 ){}
39  bool operator==( Location const & b ) { return this->size==b.size && this->line_spacing==b.line_spacing && this->line_state==b.line_state && this->skip_characters==b.skip_characters; }
40  };
41 
42  struct Geometry
43  {
44  unsigned characters;
45  bool fits;
46  float max_width;
47 
49 
50  Geometry() : characters( 0 ), fits( true ), max_width( 0 ), line_state(){}
51  };
52 
53 public:
55 
56  FontMesh( Instance * inst );
57  Instance * instance() const;
58 
59  void font_path( ResourcePath const & path );
60 
61  GLuint program_id();
62  GLuint texture_id();
63 
64  Geometry ComputeGeometry( std::string const & text, float font_size, Location const & location );
65  void GenerateMesh( std::string const & text, float font_size, Location const & location );
66  void Render( CameraState const & camera, float4x4 const & model_transform, float4 color, float4 preblend, bool translucent, std::optional< float > depth_override, ShaderScissor const & scissor );
67 
68 private:
69  Instance * inst;
70  FlatShader_Resource shader;
71  Font_Resource font;
72 
73  Texture const * variant_texture;
74  float2 variant_texcoordDensity;
75  GlMesh mesh;
76 };
77 
78 }