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  TextMeasurements
 
struct  TextSettings
 

Public Types

enum  TextStyle {
  TextStyle::Normal,
  TextStyle::Shadow,
  TextStyle::Outline,
  TextStyle::Bold
}
 
enum  TextSize {
  TextSize::VerySmall,
  TextSize::Small,
  TextSize::Regular,
  TextSize::Large,
  TextSize::VeryLarge
}
 
enum  CharacterSet {
  CharacterSet::UTF8,
  CharacterSet::CodePage437
}
 
enum  LineStyle {
  LineStyle::Solid = 0,
  LineStyle::Dot,
  LineStyle::Dash,
  LineStyle::DashDot,
  LineStyle::LongDash,
  LineStyle::LongDashDot,
  LineStyle::SparseDot,
  LineStyle::SparseDash
}
 
enum  LineHeadStyle {
  LineHeadStyle::Plain,
  LineHeadStyle::SimpleArrow,
  LineHeadStyle::BarbedArrow,
  LineHeadStyle::TriangleArrow,
  LineHeadStyle::HollowDiamond,
  LineHeadStyle::SolidDiamond
}
 
enum  WrapMode {
  WrapMode::None,
  WrapMode::OnCharacter,
  WrapMode::OnSpace
}
 

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 DrawRect (const glm::vec4 &rect, const CYIColor &color1, const CYIColor &color2, const CYIColor &color3, const CYIColor &color4)
 
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 size=1.f, LineStyle style=LineStyle::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 std::shared_ptr< CYIAssetTextureBase > &pTexture, const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color1, const CYIColor &color2, const CYIColor &color3, const CYIColor &color4, 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 DrawQuad (const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, const glm::vec2 &point4, const CYIColor &color1, const CYIColor &color2, const CYIColor &color3, const CYIColor &color4)
 
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 thickness=1.f, LineStyle lineStyle=LineStyle::Solid, LineHeadStyle startHeadStyle=LineHeadStyle::Plain, LineHeadStyle endHeadStyle=LineHeadStyle::Plain, float headSize=10.0f)
 
TextMeasurements DrawText (const CYIString &text, const glm::vec2 &pos, const CYIColor &color=CYIColor(1.0f, 1.0f, 1.0f, 1.0f), float scale=1.f, TextStyle style=TextStyle::Normal, CharacterSet characterSet=CharacterSet::UTF8)
 
TextMeasurements DrawText (const CYIString &text, const TextSettings &settings)
 
TextMeasurements 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 (TextSize textSize=TextSize::Regular)
 

Member Enumeration Documentation

◆ CharacterSet

Enumerator
UTF8 
CodePage437 

◆ LineHeadStyle

Enumerator
Plain 

No line head.

SimpleArrow 

A simple arrow made of line segments.

BarbedArrow 

A filled 'arrow head'-shaped arrow.

TriangleArrow 

A filled triangular arrow.

HollowDiamond 

A hollow flattended 'UML' diamond.

SolidDiamond 

A filled flattened 'UML' diamond.

◆ LineStyle

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

Enumerator
Solid 
-------------
Dot 
--  --  --  --  --  
Dash 
-------  -------  -------  
DashDot 
-------  --  -------  --  
LongDash 
----------  ----------  
LongDashDot 
----------  --  ----------  --  
SparseDot 
--      --      --      
SparseDash 
-------      -------      

◆ TextSize

Enumerator
VerySmall 

33% of the size of TextSize::Regular

Small 

50% of the size of TextSize::Regular

Regular 

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

Large 

200% of the size of TextSize::Regular

VeryLarge 

300% of the size of TextSize::Regular

◆ TextStyle

Enumerator
Normal 
Shadow 
Outline 
Bold 

◆ WrapMode

Enumerator
None 

No text wrapping (except for explicit newline characters)

OnCharacter 

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

OnSpace 

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

Constructor & Destructor Documentation

◆ ~CYIGeometryBatch()

CYIGeometryBatch::~CYIGeometryBatch ( )

Member Function Documentation

◆ Begin()

void CYIGeometryBatch::Begin ( )

Begin a new batch.

◆ DrawLine()

void CYIGeometryBatch::DrawLine ( const glm::vec2 &  start,
const glm::vec2 &  end,
const CYIColor color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f),
float  thickness = 1.f,
LineStyle  lineStyle = LineStyle::Solid,
LineHeadStyle  startHeadStyle = LineHeadStyle::Plain,
LineHeadStyle  endHeadStyle = LineHeadStyle::Plain,
float  headSize = 10.0f 
)

Draws a line segment.

◆ DrawOutline()

void CYIGeometryBatch::DrawOutline ( const glm::vec4 &  rect,
const CYIColor color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f),
float  size = 1.f,
LineStyle  style = LineStyle::Solid 
)

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

◆ DrawQuad() [1/4]

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.

◆ DrawQuad() [2/4]

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 color1,
const CYIColor color2,
const CYIColor color3,
const CYIColor color4,
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. A separate color can be specified for each vertex.

◆ DrawQuad() [3/4]

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.

◆ DrawQuad() [4/4]

void CYIGeometryBatch::DrawQuad ( const glm::vec2 &  point1,
const glm::vec2 &  point2,
const glm::vec2 &  point3,
const glm::vec2 &  point4,
const CYIColor color1,
const CYIColor color2,
const CYIColor color3,
const CYIColor color4 
)

Draws a quad with points point1, point2, point3 and point4. Vertices are read counterclockwise starting with the top-left corner. A separate color can be specified for each vertex.

◆ DrawRect() [1/3]

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.

◆ DrawRect() [2/3]

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

Draw a rectangle.

◆ DrawRect() [3/3]

void CYIGeometryBatch::DrawRect ( const glm::vec4 &  rect,
const CYIColor color1,
const CYIColor color2,
const CYIColor color3,
const CYIColor color4 
)

Draw a rectangle. Each corner can have a different color, going counterclockwise from the top-left corner.

◆ DrawRectWithRenderTarget()

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.

◆ DrawText() [1/2]

TextMeasurements CYIGeometryBatch::DrawText ( const CYIString text,
const glm::vec2 &  pos,
const CYIColor color = CYIColor(1.0f, 1.0f, 1.0f, 1.0f),
float  scale = 1.f,
TextStyle  style = TextStyle::Normal,
CharacterSet  characterSet = CharacterSet::UTF8 
)

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

If characterSet is CharacterSet::CodePage437, 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.

◆ DrawText() [2/2]

TextMeasurements 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.

◆ DrawTriangle() [1/2]

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.

◆ DrawTriangle() [2/2]

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.

◆ End()

void CYIGeometryBatch::End ( )

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

◆ GetInstance()

static CYIGeometryBatch* CYIGeometryBatch::GetInstance ( )
static

◆ GetTextSize()

TextMeasurements 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.

◆ GetTextSizeForCurrentSurface()

static std::pair<glm::ivec2, float> CYIGeometryBatch::GetTextSizeForCurrentSurface ( TextSize  textSize = TextSize::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).

◆ PopClipping()

void CYIGeometryBatch::PopClipping ( )

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

◆ PushClipping()

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: