You.i Engine
YiGeometryBatch.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_GEOMETRY_BATCH_H_
3 #define _YI_GEOMETRY_BATCH_H_
4 
5 #include "utility/YiColor.h"
6 
7 #include <glm/vec2.hpp>
8 
9 #include <memory>
10 
13 class CYIAssetTexture;
15 class CYIMaterial;
16 class CYIMesh;
18 
31 {
32 public:
33  static CYIGeometryBatch *GetInstance();
35 
37  {
42  };
43 
45  {
51  };
52 
54  {
57  };
58 
63  {
72  };
73 
75  {
82  };
83 
85  {
89  };
90 
91  struct TextSettings
92  {
93  TextSettings();
94 
95  glm::vec2 position;
97  float fScale;
102  };
103 
104  struct TextSize
105  {
106  glm::vec2 characterSize;
107  glm::vec2 boxSize;
109  };
110 
114  void Begin();
115 
119  void End();
120 
124  void DrawRect(const std::shared_ptr<CYIAssetTextureBase> &pTexture, const glm::vec4 &rect, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs = glm::vec4(0, 0, 1, 1));
125 
129  void DrawRect(const glm::vec4 &rect, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f));
130 
134  void DrawRectWithRenderTarget(const std::shared_ptr<CYIOffscreenRenderTarget> &pRenderTarget, const glm::vec4 &rect, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs = glm::vec4(0, 0, 1, 1));
135 
139  void DrawOutline(const glm::vec4 &rect, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fSize = 1.f, YI_LINE_STYLE eStyle = YI_LINE_SOLID);
140 
144  void DrawQuad(const std::shared_ptr<CYIAssetTextureBase> &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs = glm::vec4(0, 0, 1, 1));
145 
149  void DrawQuad(const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f));
150 
154  void DrawTriangle(const std::shared_ptr<CYIAssetTextureBase> &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs = glm::vec4(0, 0, 1, 1));
155 
159  void DrawTriangle(const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f));
160 
164  void DrawLine(const glm::vec2 &start, const glm::vec2 &end, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fThickness = 1.f, YI_LINE_STYLE eLineStyle = YI_LINE_SOLID, YI_LINE_HEAD_STYLE eStartHeadStyle = YI_LINE_HEAD_PLAIN, YI_LINE_HEAD_STYLE eEndHeadStyle = YI_LINE_HEAD_PLAIN, float fHeadSize = 10.0f);
165 
173  TextSize DrawText(const CYIString &text, const glm::vec2 &pos, const CYIColor &color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fScale = 1.f, YI_TEXT_STYLE eStyle = YI_TEXT_STYLE_NORMAL, charACTER_SET eCharacterSet = YI_UTF8);
174 
178  TextSize DrawText(const CYIString &text, const TextSettings &settings);
179 
183  TextSize GetTextSize(const CYIString &text, const TextSettings &settings) const;
184 
190  static std::pair<glm::ivec2, float> GetTextSizeForCurrentSurface(YI_TEXT_SIZE eTextSize = YI_REGULAR);
191 
195  void PushClipping(const glm::vec4 &rect);
196 
200  void PopClipping();
201 
202 private:
203  struct VertexP2T2C4
204  {
205  glm::vec2 position;
206  glm::vec2 texCoords;
207  glm::vec4 color;
208  };
209 
211 
212  void Flush();
213  void CreateBuffers();
214 
215  void DrawRect(const std::shared_ptr<CYIAssetTextureBase> &pTexture, const glm::vec4 &rect, const CYIColor &color, const glm::vec4 &UVs, bool bTransposeTexture);
216  void DrawQuad(const std::shared_ptr<CYIAssetTextureBase> &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color, const glm::vec4 &UVs, bool bTransposeTexture);
217  TextSize DrawText(const CYIString &text, const TextSettings &settings, bool bDraw);
218 
219  std::shared_ptr<CYIAssetTexture> CreateAndAddLineStyleTexture(const CYIString &pattern, const CYIString &nameFragment) const;
220 
221  VertexP2T2C4 *m_pVertices;
222  float m_fInvWidth;
223  float m_fInvHeight;
224  std::shared_ptr<CYIAssetTextureBase> m_pCurrentTexture;
225  std::shared_ptr<CYIAssetShaderProgram> m_pShader;
226  std::shared_ptr<CYIAssetBufferObjectData> m_pIndexBuffer;
227  std::shared_ptr<CYIAssetBufferObjectData> *m_pVertexBuffer;
228 
229  std::shared_ptr<CYIMesh> m_pMesh;
230  std::shared_ptr<CYIMaterial> m_pMaterial;
231 
232  int32_t m_nCurrentBufferIndex;
233  uint32_t m_uClippingStackHeight;
234 
235  static CYIGeometryBatch *s_pInstance;
236 
237  bool m_bIsDrawing;
238  bool m_bRenderingEnabled;
239  uint32_t m_uSpriteCount;
240  std::shared_ptr<CYIAssetTextureBase> m_pASCIITexture;
241  std::vector<std::shared_ptr<CYIAssetTextureBase>> m_lineStyleTextures;
242 
244 };
245 
250 #endif // _YI_GEOMETRY_BATCH_H_
Definition: YiGeometryBatch.h:71
Text wraps on the first character that exceeds the wrapping width.
Definition: YiGeometryBatch.h:87
Definition: YiGeometryBatch.h:38
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
void DrawQuad(const std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs=glm::vec4(0, 0, 1, 1))
No text wrapping (except for explicit newline characters)
Definition: YiGeometryBatch.h:86
static std::pair< glm::ivec2, float > GetTextSizeForCurrentSurface(YI_TEXT_SIZE eTextSize=YI_REGULAR)
A text size where each character is 9 pixels wide and 16 pixels tall.
Definition: YiGeometryBatch.h:48
Class representing an instance of geometry information.
Definition: YiMesh.h:33
YI_WRAP_MODE
Definition: YiGeometryBatch.h:84
33% of the size of YI_REGULAR
Definition: YiGeometryBatch.h:46
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
glm::vec2 boxSize
The tight fit of the size of the text, taking line breaks into consideration.
Definition: YiGeometryBatch.h:107
CYIColor color
The text color. Defaults to white.
Definition: YiGeometryBatch.h:96
Definition: YiGeometryBatch.h:64
static CYIGeometryBatch * GetInstance()
A texture asset representing an image which will be loaded into the GPU.
Definition: YiAssetTexture.h:23
glm::vec2 lastCharacterBottomRight
The position of the bottom right corner of the last rendered character. Affected by the draw position...
Definition: YiGeometryBatch.h:108
Allows drawing of simple 2D geometry in batch.
Definition: YiGeometryBatch.h:30
charACTER_SET
Definition: YiGeometryBatch.h:53
A filled &#39;arrow head&#39;-shaped arrow.
Definition: YiGeometryBatch.h:78
Definition: YiGeometryBatch.h:70
Definition: YiGeometryBatch.h:91
CYIMaterial is a place holder for all the drawing parameters required by the renderer to draw a mesh/...
Definition: YiMaterial.h:27
TextSize GetTextSize(const CYIString &text, const TextSettings &settings) const
Definition: YiGeometryBatch.h:39
A hollow flattended &#39;UML&#39; diamond.
Definition: YiGeometryBatch.h:80
YI_TEXT_SIZE
Definition: YiGeometryBatch.h:44
A simple arrow made of line segments.
Definition: YiGeometryBatch.h:77
Definition: YiGeometryBatch.h:68
YI_LINE_HEAD_STYLE
Definition: YiGeometryBatch.h:74
Definition: YiGeometryBatch.h:41
Definition: YiGeometryBatch.h:104
200% of the size of YI_REGULAR
Definition: YiGeometryBatch.h:49
Definition: YiGeometryBatch.h:40
glm::vec2 characterSize
The size of single character.
Definition: YiGeometryBatch.h:106
Text wraps on the last space prior toto the wrapping width.
Definition: YiGeometryBatch.h:88
void DrawRectWithRenderTarget(const std::shared_ptr< CYIOffscreenRenderTarget > &pRenderTarget, const glm::vec4 &rect, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs=glm::vec4(0, 0, 1, 1))
50% of the size of YI_REGULAR
Definition: YiGeometryBatch.h:47
Definition: YiTextEngine.h:74
void PushClipping(const glm::vec4 &rect)
A filled flattened &#39;UML&#39; diamond.
Definition: YiGeometryBatch.h:81
A filled triangular arrow.
Definition: YiGeometryBatch.h:79
Definition: YiGeometryBatch.h:69
YI_LINE_STYLE
Definition: YiGeometryBatch.h:62
Defines an offscreen target for the rendering results to be sent to.
Definition: YiOffscreenRenderTarget.h:26
300% of the size of YI_REGULAR
Definition: YiGeometryBatch.h:50
void DrawRect(const std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::vec4 &rect, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs=glm::vec4(0, 0, 1, 1))
YI_TEXT_STYLE eStyle
The text style. Defaults to YI_TEXT_STYLE_NORMAL.
Definition: YiGeometryBatch.h:98
Definition: YiGeometryBatch.h:66
Definition: YiGeometryBatch.h:67
Definition: YiGeometryBatch.h:56
void DrawTriangle(const std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), const glm::vec4 &UVs=glm::vec4(0, 0, 1, 1))
This asset represents the base class for POT (Power Of Two) and NPOT (Non-Power Of Two) textures...
Definition: YiAssetTextureBase.h:24
charACTER_SET eCharacterSet
The character set. If YI_UTF8, the text is intepreted as UTF-8 code points. If YI_CODE_PAGE_437, the text is interpreted as bytes repesenting Code Page 437 values. Defaults to YI_UTF8.
Definition: YiGeometryBatch.h:99
Shader program asset. Contains a vector of CYIAssetShaderObject types.
Definition: YiAssetShaderProgram.h:22
float fWrappingWidth
The text wrapping width. Used only when eWrapMode is not YI_WRAP_NONE. Defaults to 0...
Definition: YiGeometryBatch.h:101
As asset container which wraps shared index or vertex buffer object data.
Definition: YiAssetBufferObjectData.h:17
void DrawLine(const glm::vec2 &start, const glm::vec2 &end, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fThickness=1.f, YI_LINE_STYLE eLineStyle=YI_LINE_SOLID, YI_LINE_HEAD_STYLE eStartHeadStyle=YI_LINE_HEAD_PLAIN, YI_LINE_HEAD_STYLE eEndHeadStyle=YI_LINE_HEAD_PLAIN, float fHeadSize=10.0f)
A class used to represent a color value.
Definition: YiColor.h:31
float fScale
The text scale. Defaults to 1.0.
Definition: YiGeometryBatch.h:97
void DrawOutline(const glm::vec4 &rect, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fSize=1.f, YI_LINE_STYLE eStyle=YI_LINE_SOLID)
TextSize DrawText(const CYIString &text, const glm::vec2 &pos, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float fScale=1.f, YI_TEXT_STYLE eStyle=YI_TEXT_STYLE_NORMAL, charACTER_SET eCharacterSet=YI_UTF8)
YI_WRAP_MODE eWrapMode
The text wrapping mode. Defaults to YI_WRAP_NONE.
Definition: YiGeometryBatch.h:100
Definition: YiGeometryBatch.h:55
glm::vec2 position
The top-left position at which text should be rendered. Defaults to (0.0, 0.0)
Definition: YiGeometryBatch.h:95
Definition: YiGeometryBatch.h:65
No line head.
Definition: YiGeometryBatch.h:76