Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::Renderer2D Class Reference

A 2D renderer for drawing quads and sprites. More...

#include <Renderer2D.h>

Classes

struct  Statistics
 2D Renderer Statistics More...
 

Static Public Member Functions

static void BeginScene (const Camera &camera, const glm::mat4 &transform)
 Begins a new scene with the given camera and transform.
 
static void BeginScene (const EditorCamera &camera)
 Begins a new scene with the given editor camera.
 
static void BeginScene (const OrthographicCamera &camera)
 Begins a new scene with the given orthographic camera.
 
static void DrawQuad (const glm::mat4 &transform, const glm::vec4 &color)
 Draws a colored quad with the given transform and color.
 
static void DrawQuad (const glm::mat4 &transform, const Ref< SubTexture2D > &subtexture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad with the given transform, subtexture, tiling factor, and tint color.
 
static void DrawQuad (const glm::mat4 &transform, const Ref< Texture2D > &texture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad with the given transform, texture, tiling factor, and tint color.
 
static void DrawQuad (const glm::vec2 &position, const glm::vec2 &size, const glm::vec4 &color)
 Draws a colored quad at the specified position and size.
 
static void DrawQuad (const glm::vec2 &position, const glm::vec2 &size, const Ref< SubTexture2D > &subtexture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad at the specified position and size.
 
static void DrawQuad (const glm::vec2 &position, const glm::vec2 &size, const Ref< Texture2D > &texture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad at the specified position and size.
 
static void DrawQuad (const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &color)
 Draws a colored quad at the specified position and size.
 
static void DrawQuad (const glm::vec3 &position, const glm::vec2 &size, const Ref< SubTexture2D > &subtexture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad at the specified position and size.
 
static void DrawQuad (const glm::vec3 &position, const glm::vec2 &size, const Ref< Texture2D > &texture, float tilingFactor, const glm::vec4 tintColor)
 Draws a textured quad at the specified position and size.
 
static void DrawRotatedQuad (const glm::mat4 &transform, const glm::vec4 &color)
 Draws a rotated colored quad with the given transform and color.
 
static void DrawRotatedQuad (const glm::mat4 &transform, const Ref< SubTexture2D > &subtexture, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad with the given transform, subtexture, tiling factor, and tint color.
 
static void DrawRotatedQuad (const glm::mat4 &transform, const Ref< Texture2D > &texture, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad with the given transform, texture, tiling factor, and tint color.
 
static void DrawRotatedQuad (const glm::vec2 &position, const glm::vec2 &size, const Ref< SubTexture2D > &subtexture, float rotationRads, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad at the specified position, size, and rotation.
 
static void DrawRotatedQuad (const glm::vec2 &position, const glm::vec2 &size, const Ref< Texture2D > &texture, float rotationRads, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad at the specified position, size, and rotation.
 
static void DrawRotatedQuad (const glm::vec2 &position, const glm::vec2 &size, float rotationRads, const glm::vec4 &color)
 Draws a rotated colored quad at the specified position, size, and rotation.
 
static void DrawRotatedQuad (const glm::vec3 &position, const glm::vec2 &size, const Ref< SubTexture2D > &subtexture, float rotationRads, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad at the specified position, size, and rotation.
 
static void DrawRotatedQuad (const glm::vec3 &position, const glm::vec2 &size, const Ref< Texture2D > &texture, float rotationRads, float tilingFactor, const glm::vec4 tintColor)
 Draws a rotated textured quad at the specified position, size, and rotation.
 
static void DrawRotatedQuad (const glm::vec3 &position, const glm::vec2 &size, float rotationRads, const glm::vec4 &color)
 Draws a rotated colored quad at the specified position, size, and rotation.
 
static void EndScene ()
 Ends the current scene.
 
static void Flush ()
 Flushes the current batch of rendering commands.
 
static Statistics GetStats ()
 Retrieves the current rendering statistics.
 
static Ref< Texture2D > GetWhiteTexture ()
 Returns a reference to the default white texture that allows for coloring.
 
static void Init ()
 Initializes the 2D renderer.
 
static void ResetStats ()
 Resets the rendering statistics.
 
static void Shutdown ()
 Shuts down the 2D renderer.
 

Static Private Member Functions

static void FlushAndReset ()
 
static void StartBatch ()
 

Detailed Description

A 2D renderer for drawing quads and sprites.

Todo:
Change draw func names to be overloaded DrawQuad and remove the "WithTexture" suffix, as the presence of a texture parameter should be sufficient to determine the type of quad being drawn. The current naming convention is a holdover from when the renderer had separate functions for textured and non-textured quads.

Member Function Documentation

◆ BeginScene() [1/3]

void Muto::Renderer2D::BeginScene ( const Camera &  camera,
const glm::mat4 &  transform 
)
static

Begins a new scene with the given camera and transform.

Parameters
cameraThe camera to use for the scene.
transformThe transform matrix for the camera.
Note
Currently the intended use of this function is for rendering from a scene with an attached camera component, but it can be used for any camera and transform. The other BeginScene overloads are intended for editor use and the latter will likely be removed once we have a proper scene system in place.
138 {
140
141 glm::mat4 viewProj = camera.GetProjection() * glm::inverse(transform);
142 s_Data.TextureShader->Bind();
143 s_Data.TextureShader->SetMat4("u_ViewProjection", viewProj);
144 StartBatch();
145 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
static void StartBatch()
Definition Renderer2D.cpp:532
static Renderer2DData s_Data
Definition Renderer2D.cpp:62
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51
Ref< Shader > TextureShader
Definition Renderer2D.cpp:40

References Muto::s_Data, and StartBatch().

◆ BeginScene() [2/3]

void Muto::Renderer2D::BeginScene ( const EditorCamera &  camera)
static

Begins a new scene with the given editor camera.

Parameters
cameraThe editor camera to use for the scene.
148 {
150
151 glm::mat4 viewProj = camera.GetViewProjection();
152 s_Data.TextureShader->Bind();
153 s_Data.TextureShader->SetMat4("u_ViewProjection", viewProj);
154 StartBatch();
155 }

References Muto::s_Data, and StartBatch().

Referenced by Muto::Scene::OnUpdateEditor().

◆ BeginScene() [3/3]

void Muto::Renderer2D::BeginScene ( const OrthographicCamera &  camera)
static

Begins a new scene with the given orthographic camera.

Parameters
cameraThe orthographic camera to use for the scene.
Todo:
Remove once we have a proper scene system
158 {
160 s_Data.TextureShader->Bind();
161 s_Data.TextureShader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
162 StartBatch();
163 }

References Muto::s_Data, and StartBatch().

◆ DrawQuad() [1/9]

void Muto::Renderer2D::DrawQuad ( const glm::mat4 &  transform,
const glm::vec4 &  color 
)
static

Draws a colored quad with the given transform and color.

Parameters
transformThe transform matrix for the quad.
colorThe color of the quad.
216 {
218 constexpr size_t quadVertexCount = 4;
219 constexpr glm::vec2 texCoords[quadVertexCount] = {
220 { 0.0f, 0.0f },
221 { 1.0f, 0.0f },
222 { 1.0f, 1.0f },
223 { 0.0f, 1.0f }
224 };
227 const float texIndex = 0.0f; // White Texture
228 const float tilingFactor = 1.0f;
229 for (size_t i = 0; i < quadVertexCount; i++)
230 {
237 }
240
241 }
static void FlushAndReset()
Definition Renderer2D.cpp:526
float TexIndex
Definition Renderer2D.cpp:24
glm::vec4 Color
Definition Renderer2D.cpp:22
float TilingFactor
Definition Renderer2D.cpp:25
glm::vec2 TexCoord
Definition Renderer2D.cpp:23
glm::vec3 Position
Definition Renderer2D.cpp:21
static const uint32_t MaxIndices
Definition Renderer2D.cpp:35
glm::vec4 QuadVertexPositions[4]
Definition Renderer2D.cpp:50
QuadVertex * QuadVertexBufferPtr
Definition Renderer2D.cpp:45
Renderer2D::Statistics Stats
Definition Renderer2D.cpp:51
uint32_t QuadIndexCount
Definition Renderer2D.cpp:43
uint32_t QuadCount
The number of quads being drawn.
Definition Renderer2D.h:214

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawQuad() [2/9]

void Muto::Renderer2D::DrawQuad ( const glm::mat4 &  transform,
const Ref< SubTexture2D > &  subtexture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad with the given transform, subtexture, tiling factor, and tint color.

Parameters
transformThe transform matrix for the quad.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
310 {
312
313 constexpr size_t quadVertexCount = 4;
314 const glm::vec2* texCoords = subtexture->GetTexCoords();
315 const Ref<Texture2D> texture = subtexture->GetTexture();
316
319
320 float textureIndex = 0.0f;
321 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
322 {
323 if (*s_Data.TextureSlots[i].get() == *texture.get())
324 {
326 break;
327 }
328 }
329
330 if (textureIndex == 0.0f)
331 {
334
338 }
339
340 for (size_t i = 0; i < quadVertexCount; i++)
341 {
348 }
349
352 }
uint32_t TextureSlotIndex
Definition Renderer2D.cpp:48
static const uint32_t MaxTextureSlots
Definition Renderer2D.cpp:36
std::array< Ref< Texture2D >, MaxTextureSlots > TextureSlots
Definition Renderer2D.cpp:47

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2DData::MaxTextureSlots, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, Muto::Renderer2DData::TextureSlotIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawQuad() [3/9]

void Muto::Renderer2D::DrawQuad ( const glm::mat4 &  transform,
const Ref< Texture2D > &  texture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad with the given transform, texture, tiling factor, and tint color.

Parameters
transformThe transform matrix for the quad.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
254 {
256 constexpr size_t quadVertexCount = 4;
257 constexpr glm::vec4 color = { 1.0f, 1.0f, 1.0f, 1.0f };
258 constexpr glm::vec2 texCoords[quadVertexCount] = {
259 { 0.0f, 0.0f },
260 { 1.0f, 0.0f },
261 { 1.0f, 1.0f },
262 { 0.0f, 1.0f }
263 };
266 float textureIndex = 0.0f;
267 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
268 {
269 if (*s_Data.TextureSlots[i].get() == *texture.get())
270 {
272 break;
273 }
274 }
275 if (textureIndex == 0.0f)
276 {
282 }
283 for (size_t i = 0; i < quadVertexCount; i++)
284 {
291 }
292
295
296 }

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2DData::MaxTextureSlots, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, Muto::Renderer2DData::TextureSlotIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawQuad() [4/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
const glm::vec4 &  color 
)
static

Draws a colored quad at the specified position and size.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
colorThe color of the quad.
243 {
244 DrawQuad({ position.x, position.y, 0.0f }, size, color);
245 }
static void DrawQuad(const glm::mat4 &transform, const glm::vec4 &color)
Draws a colored quad with the given transform and color.
Definition Renderer2D.cpp:215

◆ DrawQuad() [5/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
const Ref< SubTexture2D > &  subtexture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad at the specified position and size.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
354 {
356 }

◆ DrawQuad() [6/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
const Ref< Texture2D > &  texture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad at the specified position and size.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
298 {
300 }

◆ DrawQuad() [7/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
const glm::vec4 &  color 
)
static

Draws a colored quad at the specified position and size.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
colorThe color of the quad.
247 {
248 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
250
251 }

◆ DrawQuad() [8/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
const Ref< SubTexture2D > &  subtexture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad at the specified position and size.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
358 {
360
361 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
363 }

◆ DrawQuad() [9/9]

void Muto::Renderer2D::DrawQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
const Ref< Texture2D > &  texture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a textured quad at the specified position and size.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
302 {
304
305 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
307 }

◆ DrawRotatedQuad() [1/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::mat4 &  transform,
const glm::vec4 &  color 
)
static

Draws a rotated colored quad with the given transform and color.

Parameters
transformThe transform matrix for the quad.
colorThe color of the quad.
366 {
368 constexpr size_t quadVertexCount = 4;
369 constexpr glm::vec2 texCoords[quadVertexCount] = {
370 { 0.0f, 0.0f },
371 { 1.0f, 0.0f },
372 { 1.0f, 1.0f },
373 { 0.0f, 1.0f }
374 };
377 const float texIndex = 0.0f; // White Texture
378 const float tilingFactor = 1.0f;
379 for (size_t i = 0; i < quadVertexCount; i++)
380 {
387 }
390 }

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawRotatedQuad() [2/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::mat4 &  transform,
const Ref< SubTexture2D > &  subtexture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad with the given transform, subtexture, tiling factor, and tint color.

Parameters
transformThe transform matrix for the quad.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
458 {
460 constexpr size_t quadVertexCount = 4;
461 const glm::vec2* texCoords = subtexture->GetTexCoords();
462 const Ref<Texture2D> texture = subtexture->GetTexture();
465 float textureIndex = 0.0f;
466 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
467 {
468 if (*s_Data.TextureSlots[i].get() == *texture.get())
469 {
471 break;
472 }
473 }
474 if (textureIndex == 0.0f)
475 {
481 }
482 for (size_t i = 0; i < quadVertexCount; i++)
483 {
490 }
493
494 }

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2DData::MaxTextureSlots, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, Muto::Renderer2DData::TextureSlotIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawRotatedQuad() [3/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::mat4 &  transform,
const Ref< Texture2D > &  texture,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad with the given transform, texture, tiling factor, and tint color.

Parameters
transformThe transform matrix for the quad.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
404 {
406 constexpr size_t quadVertexCount = 4;
407 constexpr glm::vec2 texCoords[quadVertexCount] = {
408 { 0.0f, 0.0f },
409 { 1.0f, 0.0f },
410 { 1.0f, 1.0f },
411 { 0.0f, 1.0f }
412 };
415 float textureIndex = 0.0f;
416 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
417 {
418 if (*s_Data.TextureSlots[i].get() == *texture.get())
419 {
421 break;
422 }
423 }
424 if (textureIndex == 0.0f)
425 {
431 }
432 for (size_t i = 0; i < quadVertexCount; i++)
433 {
440 }
443 }

References FlushAndReset(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2DData::MaxTextureSlots, Muto::Renderer2D::Statistics::QuadCount, Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, Muto::Renderer2DData::Stats, Muto::QuadVertex::TexIndex, Muto::Renderer2DData::TextureSlotIndex, and Muto::QuadVertex::TilingFactor.

◆ DrawRotatedQuad() [4/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
const Ref< SubTexture2D > &  subtexture,
float  rotationRads,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
496 {
498 }
static void DrawRotatedQuad(const glm::mat4 &transform, const glm::vec4 &color)
Draws a rotated colored quad with the given transform and color.
Definition Renderer2D.cpp:365

◆ DrawRotatedQuad() [5/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
const Ref< Texture2D > &  texture,
float  rotationRads,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.

◆ DrawRotatedQuad() [6/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec2 &  position,
const glm::vec2 &  size,
float  rotationRads,
const glm::vec4 &  color 
)
static

Draws a rotated colored quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 2D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
colorThe color of the quad.
392 {
394 }

◆ DrawRotatedQuad() [7/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
const Ref< SubTexture2D > &  subtexture,
float  rotationRads,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
subtextureThe subtexture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
500 {
502
503 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
504 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
505 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
506
508 }

◆ DrawRotatedQuad() [8/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
const Ref< Texture2D > &  texture,
float  rotationRads,
float  tilingFactor,
const glm::vec4  tintColor 
)
static

Draws a rotated textured quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
textureThe texture to apply to the quad.
tilingFactorThe tiling factor for the texture.
tintColorThe tint color to apply to the texture.
449 {
450 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
451 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
452 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
453
455 }

◆ DrawRotatedQuad() [9/9]

void Muto::Renderer2D::DrawRotatedQuad ( const glm::vec3 &  position,
const glm::vec2 &  size,
float  rotationRads,
const glm::vec4 &  color 
)
static

Draws a rotated colored quad at the specified position, size, and rotation.

Parameters
positionThe position of the quad in 3D space.
sizeThe size of the quad.
rotationRadsThe rotation of the quad in radians.
colorThe color of the quad.
396 {
397 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
398 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
399 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
401 }

◆ EndScene()

void Muto::Renderer2D::EndScene ( )
static

Ends the current scene.

166 {
168
169 if (s_Data.QuadIndexCount == 0)
170 return; // Nothing to draw
171
173
174 {
175#ifdef MU_ENABLE_ASSERTS
177 uint32_t expectedBytes = expectedVertices * sizeof(QuadVertex);
178 MU_CORE_ASSERT(dataSize == expectedBytes, "Renderer2D: vertex buffer size does not match index count (possible ghosting source). dataSize = {0}, expected = {1}", dataSize, expectedBytes);
179#endif
180 }
181
183 Flush();
184 }
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
static void Flush()
Flushes the current batch of rendering commands.
Definition Renderer2D.cpp:188
QuadVertex * QuadVertexBufferBase
Definition Renderer2D.cpp:44
Ref< VertexBuffer > QuadVertexBuffer
Definition Renderer2D.cpp:39

References Flush(), Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferBase, Muto::Renderer2DData::QuadVertexBufferPtr, and Muto::s_Data.

Referenced by FlushAndReset(), Sandbox2D::OnUpdate(), Muto::Scene::OnUpdateEditor(), and Muto::Scene::OnUpdateRuntime().

◆ Flush()

void Muto::Renderer2D::Flush ( )
static

Flushes the current batch of rendering commands.

Resets the batch for a new set of draw calls.

Todo:
Remove the OpenGL-specific code from here
Todo:
Remove the OpenGL-specific code from here
189 {
191
192 // DIsable depth testing
196
197 if (depthEnabled)
200
201 // Bind textures
202 for (uint32_t i = 0; i < s_Data.TextureSlotIndex; i++)
203 s_Data.TextureSlots[i]->Bind(i);
204
207
208 // Restore depth state
210 if (depthEnabled)
212 }
static void DrawIndexed(const Ref< VertexArray > &vertexArray, uint32_t indexCount=0)
Draws indexed geometry using the specified vertex array and index count.
Definition RenderCommand.h:41
Ref< VertexArray > QuadVertexArray
Definition Renderer2D.cpp:38
uint32_t DrawCalls
The number of draw calls being made.
Definition Renderer2D.h:212

References Muto::Renderer2D::Statistics::DrawCalls, Muto::Renderer2DData::QuadIndexCount, Muto::s_Data, Muto::Renderer2DData::Stats, and Muto::Renderer2DData::TextureSlotIndex.

Referenced by EndScene().

◆ FlushAndReset()

void Muto::Renderer2D::FlushAndReset ( )
staticprivate
527 {
528 EndScene();
529 StartBatch();
530 }
static void EndScene()
Ends the current scene.
Definition Renderer2D.cpp:165

References EndScene(), and StartBatch().

Referenced by DrawQuad(), DrawQuad(), DrawQuad(), DrawRotatedQuad(), DrawRotatedQuad(), and DrawRotatedQuad().

◆ GetStats()

Renderer2D::Statistics Muto::Renderer2D::GetStats ( )
static

Retrieves the current rendering statistics.

522 {
523 return s_Data.Stats;
524 }

References Muto::s_Data, and Muto::Renderer2DData::Stats.

Referenced by Muto::EditorLayer::OnImGuiRender(), and Sandbox2D::OnImGuiRender().

◆ GetWhiteTexture()

Ref< Texture2D > Muto::Renderer2D::GetWhiteTexture ( )
static

Returns a reference to the default white texture that allows for coloring.

512 {
513 return s_Data.WhiteTexture;
514 }
Ref< Texture2D > WhiteTexture
Definition Renderer2D.cpp:41

References Muto::s_Data.

◆ Init()

void Muto::Renderer2D::Init ( )
static

Initializes the 2D renderer.

66 {
68
70
71
73
74 s_Data.QuadVertexBuffer->SetLayout({
75 { ShaderDataType::SDT_Float3, "a_Position" },
76 { ShaderDataType::SDT_Float4, "a_Color" },
77 { ShaderDataType::SDT_Float2, "a_TexCoord" },
78 { ShaderDataType::SDT_Float, "a_TexIndex" },
79 { ShaderDataType::SDT_Float, "a_TilingFactor"},
80 });
82
84
86 uint32_t offset = 0;
87
88 for (uint32_t i = 0; i < s_Data.MaxIndices; i += 6) {
89 quadIndices[i + 0] = offset + 0;
90 quadIndices[i + 1] = offset + 1;
91 quadIndices[i + 2] = offset + 2;
92 quadIndices[i + 3] = offset + 2;
93 quadIndices[i + 4] = offset + 3;
94 quadIndices[i + 5] = offset + 0;
95
96 offset += 4;
97 }
98
101 s_Data.QuadVertexArray->SetIndexBuffer(quadIB);
102 delete[] quadIndices;
103
105 uint32_t whiteTextureData = 0xffffffff;
106 s_Data.WhiteTexture->SetData(&whiteTextureData, sizeof(uint32_t));
107
109 for (uint32_t i = 0; i < s_Data.MaxTextureSlots; i++)
110 samplers[i] = i;
111
112
114 MU_CORE_INFO("Attempting to load shader from: {0}", shaderPath);
115
117 s_Data.TextureShader->Bind();
118 s_Data.TextureShader->SetIntArray("u_Textures", samplers, s_Data.MaxTextureSlots);
119
121
122
123 s_Data.QuadVertexPositions[0] = { -0.5f, -0.5f, 0.0f, 1.0f };
124 s_Data.QuadVertexPositions[1] = { 0.5f, -0.5f, 0.0f, 1.0f };
125 s_Data.QuadVertexPositions[2] = { 0.5f, 0.5f, 0.0f, 1.0f };
126 s_Data.QuadVertexPositions[3] = { -0.5f, 0.5f, 0.0f, 1.0f };
127
128 }
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
std::string ResolvePath(const std::string &Path, PathResolveMode Mode=PathResolveMode::AssetsDirectory) const
Resolves the full path to a resource based on a relative path and the application's settings.
Definition Application.cpp:166
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
static Ref< IndexBuffer > Create(uint32_t *indices, uint32_t count)
Definition Buffer.cpp:33
static Ref< Shader > Create(const std::string &name, const std::string &vertexSrc, const std::string &fragmentSrc)
Creates a new shader from vertex and fragment shader source code.
Definition Shader.cpp:20
static Ref< Texture2D > Create(uint32_t width, uint32_t height)
Definition Texture.cpp:10
static Ref< VertexArray > Create()
Definition VertexArray.cpp:7
static Ref< VertexBuffer > Create(uint32_t size)
Definition Buffer.cpp:11
static std::string JoinPaths(const std::string &base, const std::string &relative)
Joins two path segments with proper separator handling.
Definition ResourceManager.h:22
static const uint32_t MaxVertices
Definition Renderer2D.cpp:34

References Muto::AssetsDirectory, Muto::Application::Get(), Muto::JoinPaths(), Muto::Renderer2DData::MaxIndices, Muto::Renderer2DData::MaxTextureSlots, Muto::Renderer2DData::MaxVertices, Muto::Renderer2DData::QuadVertexBufferBase, Muto::Application::ResolvePath(), Muto::s_Data, Muto::SDT_Float, Muto::SDT_Float2, Muto::SDT_Float3, and Muto::SDT_Float4.

Referenced by Muto::Renderer::Init().

◆ ResetStats()

void Muto::Renderer2D::ResetStats ( )
static

Resets the rendering statistics.

517 {
518 memset(&s_Data.Stats, 0, sizeof(Statistics));
519 }

References Muto::s_Data, and Muto::Renderer2DData::Stats.

Referenced by Sandbox2D::OnUpdate(), and Muto::EditorLayer::OnUpdate().

◆ Shutdown()

void Muto::Renderer2D::Shutdown ( )
static

Shuts down the 2D renderer.

131 {
133
135 }

References Muto::Renderer2DData::QuadVertexBufferBase, and Muto::s_Data.

◆ StartBatch()

void Muto::Renderer2D::StartBatch ( )
staticprivate
533 {
534
537
538 //s_Data.CircleIndexCount = 0;
539 //s_Data.CircleVertexBufferPtr = s_Data.CircleVertexBufferBase;
540
541 //s_Data.LineVertexCount = 0;
542 //s_Data.LineVertexBufferPtr = s_Data.LineVertexBufferBase;
543
544 //s_Data.TextIndexCount = 0;
545 //s_Data.TextVertexBufferPtr = s_Data.TextVertexBufferBase;
546
548
549 }

References Muto::Renderer2DData::QuadIndexCount, Muto::Renderer2DData::QuadVertexBufferBase, Muto::Renderer2DData::QuadVertexBufferPtr, Muto::s_Data, and Muto::Renderer2DData::TextureSlotIndex.

Referenced by BeginScene(), BeginScene(), BeginScene(), and FlushAndReset().


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