CoriEngine
Loading...
Searching...
No Matches
Cori::Graphics::Renderer2D Class Reference

The main engine renderer. More...

#include <Renderer2D.hpp>

Classes

struct  Statistics

Public Types

enum  TextAlignment : uint8_t { RIGHT , CENTER , LEFT }
 Available text alignment options. More...
enum  DrawSpace : uint8_t { WORLD_SPACE , SCREEN_SPACE , UNSPECIFIED }
 Defines where to draw the object, in what space. More...
enum  ObjectTransparency : uint8_t { OPAQUE , SEMI_TRANSPARENT }

Static Public Member Functions

static void SubmitQuad (const DrawSpace space, const ObjectTransparency transparencyMode, const glm::mat3 &transform, const glm::vec2 halfSize, const glm::vec4 &tintColor, Texture2D *texture, const UVs &uvs, const uint8_t depth, const bool flipX, const bool flipY, const bool flatColored)
 Submits the quad to the render queue.
static void SubmitColoredQuad (const DrawSpace space, const glm::vec2 position, const glm::vec2 halfSize, const glm::vec3 &color)
 Convenience function mainly for debugging, draws a plain colored quad.
static void SubmitAABB (const Utility::AABB &aabb, const float lineThickness, const glm::vec3 &color)
 Draws the AABB, also a debug convenience function, always draws in world space.
static void SubmitText (const DrawSpace space, const TextAlignment alignment, const glm::mat3 &transform, const float fontSize, const std::u32string_view &text, const glm::vec4 &color, Font *font, const uint8_t depth, const float limitX, const float lineSpacing, const float kerning)
 Draws a UTF-32 fixed length encoded string.
static void SubmitText (const DrawSpace space, const TextAlignment alignment, const glm::mat3 &transform, const float fontSize, const std::string_view &text, const glm::vec4 &color, Font *font, const uint8_t depth, const float limitX, const float lineSpacing, const float kerning)
 Draws a UTF-32 fixed length encoded string.
static Statistics GetStatistics ()
 Gives you the rendering stats of the last rendered frame.
static void StartFrame ()
static void EndFrame ()
static void BeginScene (const World::Components::Scene::Camera &camera)
static void EndScene ()

Detailed Description

The main engine renderer.

The render is capable of rendering 2D quads, and text for now. It can render in screen space or in world space, supports both opaque object and transparent objects, and also has a layering system to position opaque and transparent objects currently (need to finish it of with a k-way merge). When rendering text it can be aligned to the left, right or center. Render uses instancing.

Definition at line 24 of file Renderer2D.hpp.

Member Enumeration Documentation

◆ DrawSpace

Defines where to draw the object, in what space.

Basically if WORLD_SPACE is selected it will use the position, rotation, scale applied to orthographic camera, and if SCREEN_SPACE it will ignore the camera position, rotation, scale and use the initial projection matrix.

Note
Never use UNSPECIFIED it is the default value and should not be used by the user.
Enumerator
WORLD_SPACE 
SCREEN_SPACE 
UNSPECIFIED 

Definition at line 83 of file Renderer2D.hpp.

◆ ObjectTransparency

Note
When directly using the renderer you need to correctly specify if the object you are trying to render has semi transparency or no, opaque and transparent object are processed differently.
Enumerator
OPAQUE 
SEMI_TRANSPARENT 

Definition at line 92 of file Renderer2D.hpp.

◆ TextAlignment

Available text alignment options.

Enumerator
RIGHT 
CENTER 
LEFT 

Definition at line 29 of file Renderer2D.hpp.

Member Function Documentation

◆ BeginScene()

void Cori::Graphics::Renderer2D::BeginScene ( const World::Components::Scene::Camera & camera)
static

Definition at line 86 of file Renderer2D.cpp.

◆ EndFrame()

void Cori::Graphics::Renderer2D::EndFrame ( )
static

Definition at line 386 of file Renderer2D.cpp.

◆ EndScene()

void Cori::Graphics::Renderer2D::EndScene ( )
static

Definition at line 116 of file Renderer2D.cpp.

◆ GetStatistics()

Renderer2D::Statistics Cori::Graphics::Renderer2D::GetStatistics ( )
static

Gives you the rendering stats of the last rendered frame.

Returns
Last frame stats.

Definition at line 377 of file Renderer2D.cpp.

◆ StartFrame()

void Cori::Graphics::Renderer2D::StartFrame ( )
static

Definition at line 381 of file Renderer2D.cpp.

◆ SubmitAABB()

void Cori::Graphics::Renderer2D::SubmitAABB ( const Utility::AABB & aabb,
const float lineThickness,
const glm::vec3 & color )
static

Draws the AABB, also a debug convenience function, always draws in world space.

Parameters
aabbAABB to draw.
lineThicknessThickness of the AABB border.
colorBorder color.

Definition at line 289 of file Renderer2D.cpp.

Here is the call graph for this function:

◆ SubmitColoredQuad()

void Cori::Graphics::Renderer2D::SubmitColoredQuad ( const DrawSpace space,
const glm::vec2 position,
const glm::vec2 halfSize,
const glm::vec3 & color )
static

Convenience function mainly for debugging, draws a plain colored quad.

Parameters
spaceDrawSpace to draw the quad.
positionPosition defined is the center of the quad.
halfSizeHalf size of the quad.
colorQuad color.
Note
Draws on the depth 255.

Definition at line 284 of file Renderer2D.cpp.

Here is the call graph for this function:

◆ SubmitQuad()

void Cori::Graphics::Renderer2D::SubmitQuad ( const DrawSpace space,
const ObjectTransparency transparencyMode,
const glm::mat3 & transform,
const glm::vec2 halfSize,
const glm::vec4 & tintColor,
Texture2D * texture,
const UVs & uvs,
const uint8_t depth,
const bool flipX,
const bool flipY,
const bool flatColored )
static

Submits the quad to the render queue.

Parameters
spaceDrawSpace to draw the quad.
transparencyModeTransparency mode, defines how to handle the quad. (hint: you can query a Texture2D if it has semi transparency or no)
transformRendering transform. Position defined is the center of the quad.
halfSizeHalf size of the quad.
tintColorTint color of the quad, or a color if flatColored=true.
textureTexture to sample from.
uvsUVs to sample with.
depthQuad Depth, for layering, the higher the "closer".
flipXFlip quad on X axis.
flipYFlip quad on Y axis.
flatColoredIgnore the texture and use a plain white texture.
Warning
You need to make sure that texture pointer stays valid until the end of the frame, or this will induce a dangling pointer. Be aware!

Definition at line 157 of file Renderer2D.cpp.

◆ SubmitText() [1/2]

void Cori::Graphics::Renderer2D::SubmitText ( const DrawSpace space,
const TextAlignment alignment,
const glm::mat3 & transform,
const float fontSize,
const std::string_view & text,
const glm::vec4 & color,
Font * font,
const uint8_t depth,
const float limitX,
const float lineSpacing,
const float kerning )
static

Draws a UTF-32 fixed length encoded string.

Parameters
spaceDrawSpace to draw text in.
alignmentText alignment with which to draw the text.
transformRendering transform.
fontSizeSize of the font to render.
textView to the UTF-8 variable length encoded string to render.
colorColor of the text to render.
fontFont to use when rendering the text.
depthDepth at which to render the text.
limitXLength limit of the one line.
lineSpacingAdditional line spacing.
kerningAdditional kerning.

Transform for TextAlignment::LEFT is a lower left border of the char in the first line.
For TextAlignment::CENTER it's the lower bound on y of the first line, and on x the center between the left border of the char in the first line and the right border of the char in the first line.
For TextAlignment::RIGHT it's the left lower border of the last char in the line.

Note
All text is considered semi transparent when rendering.
Warning
You need to make sure that font pointer stays valid until the end of the frame, or this will induce a dangling pointer. Be aware!

Definition at line 352 of file Renderer2D.cpp.

Here is the call graph for this function:

◆ SubmitText() [2/2]

void Cori::Graphics::Renderer2D::SubmitText ( const DrawSpace space,
const TextAlignment alignment,
const glm::mat3 & transform,
const float fontSize,
const std::u32string_view & text,
const glm::vec4 & color,
Font * font,
const uint8_t depth,
const float limitX,
const float lineSpacing,
const float kerning )
static

Draws a UTF-32 fixed length encoded string.

Parameters
spaceDrawSpace to draw text in.
alignmentText alignment with which to draw the text.
transformRendering transform.
fontSizeSize of the font to render.
textView to the UTF-32 fixed length encoded string to render.
colorColor of the text to render.
fontFont to use when rendering the text.
depthDepth at which to render the text.
limitXLength limit of the one line.
lineSpacingAdditional line spacing.
kerningAdditional kerning.

Transform for TextAlignment::LEFT is a lower left border of the char in the first line.
For TextAlignment::CENTER it's the lower bound on y of the first line, and on x the center between the left border of the char in the first line and the right border of the char in the first line.
For TextAlignment::RIGHT it's the left lower border of the last char in the line.

Note
All text is considered semi transparent when rendering.
Warning
You need to make sure that font pointer stays valid until the end of the frame, or this will induce a dangling pointer. Be aware!

Definition at line 328 of file Renderer2D.cpp.

Here is the call graph for this function:

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