You.i Engine
CYIGeometryBatch Class Reference

Detailed Description

Allows drawing of simple 2D geometry in batch.

For example, rendering 2 rectangles one after another might not flush it to the GPU right away, but instead batch them. They will be flushed on state change like blending or texture bound. This reduces the number of draw calls.

#include <utility/YiGeometryBatch.h>

Classes

struct  TextSettings
 
struct  TextSize
 

Public Types

enum  YI_TEXT_STYLE {
  YI_TEXT_STYLE_NORMAL,
  YI_TEXT_STYLE_SHADOW,
  YI_TEXT_STYLE_OUTLINE,
  YI_TEXT_STYLE_BOLD
}
 
enum  YI_TEXT_SIZE {
  YI_VERY_SMALL,
  YI_SMALL,
  YI_REGULAR,
  YI_LARGE,
  YI_VERY_LARGE
}
 
enum  charACTER_SET {
  YI_UTF8,
  YI_CODE_PAGE_437
}
 
enum  YI_LINE_STYLE {
  YI_LINE_SOLID = 0,
  YI_LINE_DOT = 1,
  YI_LINE_DASH = 2,
  YI_LINE_DASH_DOT = 3,
  YI_LINE_LONG_DASH = 4,
  YI_LINE_LONG_DASH_DOT = 5,
  YI_LINE_SPARSE_DOT = 6,
  YI_LINE_SPARSE_DASH = 7
}
 
enum  YI_LINE_HEAD_STYLE {
  YI_LINE_HEAD_PLAIN = 0,
  YI_LINE_HEAD_SIMPLE_ARROW = 1,
  YI_LINE_HEAD_BARBED_ARROW = 2,
  YI_LINE_HEAD_TRIANGLE_ARROW = 3,
  YI_LINE_HEAD_HOLLOW_DIAMOND = 4,
  YI_LINE_HEAD_SOLID_DIAMOND = 5
}
 
enum  YI_WRAP_MODE {
  YI_WRAP_NONE,
  YI_WRAP_ON_CHARACTER,
  YI_WRAP_ON_SPACE
}
 

Public Member Functions

 ~CYIGeometryBatch ()
 
void Begin ()
 
void End ()
 
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))
 
void DrawRect (const glm::vec4 &rect, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f))
 
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))
 
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)
 
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))
 
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))
 
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))
 
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))
 
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)
 
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)
 
TextSize DrawText (const CYIString &text, const TextSettings &settings)
 
TextSize GetTextSize (const CYIString &text, const TextSettings &settings) const
 
void PushClipping (const glm::vec4 &rect)
 
void PopClipping ()
 

Static Public Member Functions

static CYIGeometryBatchGetInstance ()
 
static std::pair< glm::ivec2, float > GetTextSizeForCurrentSurface (YI_TEXT_SIZE eTextSize=YI_REGULAR)
 

Member Enumeration Documentation

Enumerator
YI_UTF8 
YI_CODE_PAGE_437 
Enumerator
YI_LINE_HEAD_PLAIN 

No line head.

YI_LINE_HEAD_SIMPLE_ARROW 

A simple arrow made of line segments.

YI_LINE_HEAD_BARBED_ARROW 

A filled 'arrow head'-shaped arrow.

YI_LINE_HEAD_TRIANGLE_ARROW 

A filled triangular arrow.

YI_LINE_HEAD_HOLLOW_DIAMOND 

A hollow flattended 'UML' diamond.

YI_LINE_HEAD_SOLID_DIAMOND 

A filled flattened 'UML' diamond.

The style of line to draw when drawing lines and outlines.

Enumerator
YI_LINE_SOLID 
-------------
YI_LINE_DOT 
--  --  --  --  --  
YI_LINE_DASH 
-------  -------  -------  
YI_LINE_DASH_DOT 
-------  --  -------  --  
YI_LINE_LONG_DASH 
----------  ----------  
YI_LINE_LONG_DASH_DOT 
----------  --  ----------  --  
YI_LINE_SPARSE_DOT 
--      --      --      
YI_LINE_SPARSE_DASH 
-------      -------      
Enumerator
YI_VERY_SMALL 

33% of the size of YI_REGULAR

YI_SMALL 

50% of the size of YI_REGULAR

YI_REGULAR 

A text size where each character is 9 pixels wide and 16 pixels tall.

YI_LARGE 

200% of the size of YI_REGULAR

YI_VERY_LARGE 

300% of the size of YI_REGULAR

Enumerator
YI_TEXT_STYLE_NORMAL 
YI_TEXT_STYLE_SHADOW 
YI_TEXT_STYLE_OUTLINE 
YI_TEXT_STYLE_BOLD 
Enumerator
YI_WRAP_NONE 

No text wrapping (except for explicit newline characters)

YI_WRAP_ON_CHARACTER 

Text wraps on the first character that exceeds the wrapping width.

YI_WRAP_ON_SPACE 

Text wraps on the last space prior toto the wrapping width.

Constructor & Destructor Documentation

CYIGeometryBatch::~CYIGeometryBatch ( )

Member Function Documentation

void CYIGeometryBatch::Begin ( )

Begin a new batch.

void CYIGeometryBatch::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 
)

Draws a line segment.

void CYIGeometryBatch::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 
)

Draw an outlined rectangle. This internaly will call DrawRect 4 times.

void CYIGeometryBatch::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) 
)

Draws a quad with points point1, point2, point3 and point4. Vertices are read counterclockwise starting with the top-left corner.

void CYIGeometryBatch::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) 
)

Draws a quad with points point1, point2, point3 and point4. Vertices are read counterclockwise starting with the top-left corner.

void CYIGeometryBatch::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) 
)

Draw a rectangle.

void CYIGeometryBatch::DrawRect ( const glm::vec4 &  rect,
const CYIColor color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f) 
)

Draw a rectangle.

void CYIGeometryBatch::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) 
)

Same as DrawRect, but using a CYIOffscreenRenderTarget as texture source.

TextSize CYIGeometryBatch::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 
)

Draw text using the default internal console font. Returns an object containing size information about the rendered text.

If eCharacterSet is YI_CODE_PAGE_437, the provided string is rendered by reading each byte and rendering them using Code Page 437 (rather than interpreting the data in the text string as if encoded using UTF-8).

Note
Unicode characters not present in Code Page 437 are rendered as an inverted question mark.
TextSize CYIGeometryBatch::DrawText ( const CYIString text,
const TextSettings settings 
)

Draw text using the default internal console font. Rendering settings can be provided in the settings parameter. Returns an object containing size information about the rendered text.

void CYIGeometryBatch::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) 
)

Draws a triangle with points point1, point2 and point3.

void CYIGeometryBatch::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) 
)

Draws a triangle with points point1, point2 and point3.

void CYIGeometryBatch::End ( )

End a batch. This will flush and render what's left to the screen.

static CYIGeometryBatch* CYIGeometryBatch::GetInstance ( )
static
TextSize CYIGeometryBatch::GetTextSize ( const CYIString text,
const TextSettings settings 
) const

Calculates and returns the size data for the text text if it was rendered using the settings settings.

static std::pair<glm::ivec2, float> CYIGeometryBatch::GetTextSizeForCurrentSurface ( YI_TEXT_SIZE  eTextSize = YI_REGULAR)
static

Calculates and returns a geometry batch text size for the current surface. A 'regular' size, the text size will be calculated so that XYZ lines of text can fit on the screen (when in landscape mode). Note that the text size will not be allowed to go below a scale of 0.75f, as text at that scale becomes difficult to read.

The return value is a pair object containing the size (in pixels) of a single character of text, and the text scale (to be used in the DrawText functions).

void CYIGeometryBatch::PopClipping ( )

Pop the top-most clipping volume from the clipping stack.

void CYIGeometryBatch::PushClipping ( const glm::vec4 &  rect)

Push a world-space clipping volume onto the clipping stack.


The documentation for this class was generated from the following file: