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 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 CYIGeometryBatch * | GetInstance () |
static std::pair< glm::ivec2, float > | GetTextSizeForCurrentSurface (TextSize textSize=TextSize::Regular) |
|
strong |
|
strong |
|
strong |
|
strong |
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 |
|
strong |
|
strong |
CYIGeometryBatch::~CYIGeometryBatch | ( | ) |
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 | thickness = 1.f , |
||
LineStyle | lineStyle = LineStyle::Solid , |
||
LineHeadStyle | startHeadStyle = LineHeadStyle::Plain , |
||
LineHeadStyle | endHeadStyle = LineHeadStyle::Plain , |
||
float | headSize = 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 | size = 1.f , |
||
LineStyle | style = LineStyle::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 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.
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::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.
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::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.
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.
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).
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.
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 |
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.
|
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.