Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::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 Init ()
 Initializes the 2D renderer.
static void Shutdown ()
 Shuts down the 2D renderer.
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 EndScene ()
 Ends the current scene.
static void Flush ()
 Flushes the current batch of rendering commands.
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::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::vec3 &position, const glm::vec2 &size, const glm::vec4 &color)
 Draws a colored quad at the specified position and size.
static void DrawQuadWithTexture (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 DrawQuadWithTexture (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 DrawQuadWithTexture (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 DrawQuadWithTexture (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 DrawQuadWithTexture (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 DrawQuadWithTexture (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 DrawQuadRotated (const glm::mat4 &transform, const glm::vec4 &color)
 Draws a rotated colored quad with the given transform and color.
static void DrawQuadRotated (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 DrawQuadRotated (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 DrawQuadRotatedWithTexture (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 DrawQuadRotatedWithTexture (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 DrawQuadRotatedWithTexture (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 DrawQuadRotatedWithTexture (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 DrawQuadRotatedWithTexture (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 DrawQuadRotatedWithTexture (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 Ref< Texture2DGetWhiteTexture ()
 Returns a reference to the default white texture that allows for coloring.
static void ResetStats ()
 Resets the rendering statistics.
static Statistics GetStats ()
 Retrieves the current rendering statistics.

Static Private Member Functions

static void FlushAndReset ()
static void StartBatch ()

Detailed Description

A 2D renderer for drawing quads and sprites.

Member Function Documentation

◆ BeginScene() [1/3]

void Vesper::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.
124 {
126
127 glm::mat4 viewProj = camera.GetProjection() * glm::inverse(transform);
128
129 s_Data.TextureShader->Bind();
130 s_Data.TextureShader->SetMat4("u_ViewProjection", viewProj);
131
134
136 }
#define VZ_PROFILE_FUNCTION()
Definition Instrumentor.h:240
static Renderer2DData s_Data
Definition Renderer2D.cpp:52
Ref< Shader > TextureShader
Definition Renderer2D.cpp:30
QuadVertex * QuadVertexBufferPtr
Definition Renderer2D.cpp:35
QuadVertex * QuadVertexBufferBase
Definition Renderer2D.cpp:34
uint32_t QuadIndexCount
Definition Renderer2D.cpp:33
uint32_t TextureSlotIndex
Definition Renderer2D.cpp:38

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

◆ BeginScene() [2/3]

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

Begins a new scene with the given editor camera.

Parameters
cameraThe editor camera to use for the scene.
139 {
141
142 glm::mat4 viewProj = camera.GetViewProjection();
143 s_Data.TextureShader->Bind();
144 s_Data.TextureShader->SetMat4("u_ViewProjection", viewProj);
145 StartBatch();
146 }
static void StartBatch()
Definition Renderer2D.cpp:515

References Vesper::s_Data, and StartBatch().

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

◆ BeginScene() [3/3]

void Vesper::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
149 {
151 s_Data.TextureShader->Bind();
152 s_Data.TextureShader->SetMat4("u_ViewProjection", camera.GetViewProjectionMatrix());
153
156
158 }

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

◆ DrawQuad() [1/3]

void Vesper::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.
181 {
183 constexpr size_t quadVertexCount = 4;
184 constexpr glm::vec2 texCoords[quadVertexCount] = {
185 { 0.0f, 0.0f },
186 { 1.0f, 0.0f },
187 { 1.0f, 1.0f },
188 { 0.0f, 1.0f }
189 };
192 const float texIndex = 0.0f; // White Texture
193 const float tilingFactor = 1.0f;
194 for (size_t i = 0; i < quadVertexCount; i++)
195 {
198 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
202 }
205
206 }
static void FlushAndReset()
Definition Renderer2D.cpp:507
glm::vec4 Color
Definition Renderer2D.cpp:15
glm::vec2 TexCoord
Definition Renderer2D.cpp:16
glm::vec3 Position
Definition Renderer2D.cpp:14
float TilingFactor
Definition Renderer2D.cpp:18
float TexIndex
Definition Renderer2D.cpp:17
uint32_t QuadCount
The number of quads being drawn.
Definition Renderer2D.h:209
static const uint32_t MaxIndices
Definition Renderer2D.cpp:25
Renderer2D::Statistics Stats
Definition Renderer2D.cpp:41
glm::vec4 QuadVertexPositions[4]
Definition Renderer2D.cpp:40

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

◆ DrawQuad() [2/3]

void Vesper::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.
208 {
209 DrawQuad({ position.x, position.y, 0.0f }, size, color);
210 }
static void DrawQuad(const glm::mat4 &transform, const glm::vec4 &color)
Draws a colored quad with the given transform and color.
Definition Renderer2D.cpp:180

◆ DrawQuad() [3/3]

void Vesper::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.
212 {
213 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
214 DrawQuad(transform, color);
215
216 }

◆ DrawQuadRotated() [1/3]

void Vesper::Renderer2D::DrawQuadRotated ( 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.
331 {
333 constexpr size_t quadVertexCount = 4;
334 constexpr glm::vec2 texCoords[quadVertexCount] = {
335 { 0.0f, 0.0f },
336 { 1.0f, 0.0f },
337 { 1.0f, 1.0f },
338 { 0.0f, 1.0f }
339 };
342 const float texIndex = 0.0f; // White Texture
343 const float tilingFactor = 1.0f;
344 for (size_t i = 0; i < quadVertexCount; i++)
345 {
348 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
352 }
355 }

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

◆ DrawQuadRotated() [2/3]

void Vesper::Renderer2D::DrawQuadRotated ( 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.
357 {
358 DrawQuadRotated({ position.x, position.y, 0.0f }, size, rotationRads, color);
359 }
static void DrawQuadRotated(const glm::mat4 &transform, const glm::vec4 &color)
Draws a rotated colored quad with the given transform and color.
Definition Renderer2D.cpp:330

◆ DrawQuadRotated() [3/3]

void Vesper::Renderer2D::DrawQuadRotated ( 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.
361 {
362 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
363 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
364 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
365 DrawQuadRotated(transform, color);
366 }

◆ DrawQuadRotatedWithTexture() [1/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
423 {
425 constexpr size_t quadVertexCount = 4;
426 const glm::vec2* texCoords = subtexture->GetTexCoords();
427 const Ref<Texture2D> texture = subtexture->GetTexture();
430 float textureIndex = 0.0f;
431 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
432 {
433 if (*s_Data.TextureSlots[i].get() == *texture.get())
434 {
435 textureIndex = (float)i;
436 break;
437 }
438 }
439 if (textureIndex == 0.0f)
440 {
443 textureIndex = (float)s_Data.TextureSlotIndex;
446 }
447 for (size_t i = 0; i < quadVertexCount; i++)
448 {
450 s_Data.QuadVertexBufferPtr->Color = tintColor;
451 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
452 s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
455 }
458
459 }
std::shared_ptr< T > Ref
A smart pointer type representing shared ownership of an object.
Definition Defines_Macros.h:63
static const uint32_t MaxTextureSlots
Definition Renderer2D.cpp:26
std::array< Ref< Texture2D >, MaxTextureSlots > TextureSlots
Definition Renderer2D.cpp:37

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

◆ DrawQuadRotatedWithTexture() [2/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
369 {
371 constexpr size_t quadVertexCount = 4;
372 constexpr glm::vec2 texCoords[quadVertexCount] = {
373 { 0.0f, 0.0f },
374 { 1.0f, 0.0f },
375 { 1.0f, 1.0f },
376 { 0.0f, 1.0f }
377 };
380 float textureIndex = 0.0f;
381 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
382 {
383 if (*s_Data.TextureSlots[i].get() == *texture.get())
384 {
385 textureIndex = (float)i;
386 break;
387 }
388 }
389 if (textureIndex == 0.0f)
390 {
393 textureIndex = (float)s_Data.TextureSlotIndex;
396 }
397 for (size_t i = 0; i < quadVertexCount; i++)
398 {
400 s_Data.QuadVertexBufferPtr->Color = tintColor;
401 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
402 s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
405 }
408 }

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

◆ DrawQuadRotatedWithTexture() [3/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
461 {
462 DrawQuadRotatedWithTexture({ position.x, position.y, 0.0f }, size, subtexture, rotationRads, tilingFactor, tintColor);
463 }
static void DrawQuadRotatedWithTexture(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.
Definition Renderer2D.cpp:368

◆ DrawQuadRotatedWithTexture() [4/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
410 {
411 DrawQuadRotatedWithTexture({ position.x, position.y, 0.0f }, size, texture, rotationRads, tilingFactor, tintColor);
412 }

◆ DrawQuadRotatedWithTexture() [5/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
465 {
467
468 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
469 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
470 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
471
472 DrawQuadRotatedWithTexture(transform, subtexture, tilingFactor, tintColor);
473 }

◆ DrawQuadRotatedWithTexture() [6/6]

void Vesper::Renderer2D::DrawQuadRotatedWithTexture ( 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.
414 {
415 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position)
416 * glm::rotate(glm::mat4(1.0f), rotationRads, { 0.0f, 0.0f, 1.0f })
417 * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
418
419 DrawQuadRotatedWithTexture(transform, texture, tilingFactor, tintColor);
420 }

◆ DrawQuadWithTexture() [1/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
275 {
277
278 constexpr size_t quadVertexCount = 4;
279 const glm::vec2* texCoords = subtexture->GetTexCoords();
280 const Ref<Texture2D> texture = subtexture->GetTexture();
281
284
285 float textureIndex = 0.0f;
286 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
287 {
288 if (*s_Data.TextureSlots[i].get() == *texture.get())
289 {
290 textureIndex = (float)i;
291 break;
292 }
293 }
294
295 if (textureIndex == 0.0f)
296 {
299
300 textureIndex = (float)s_Data.TextureSlotIndex;
303 }
304
305 for (size_t i = 0; i < quadVertexCount; i++)
306 {
308 s_Data.QuadVertexBufferPtr->Color = tintColor;
309 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
310 s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
313 }
314
317 }

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

◆ DrawQuadWithTexture() [2/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
219 {
221 constexpr size_t quadVertexCount = 4;
222 constexpr glm::vec4 color = { 1.0f, 1.0f, 1.0f, 1.0f };
223 constexpr glm::vec2 texCoords[quadVertexCount] = {
224 { 0.0f, 0.0f },
225 { 1.0f, 0.0f },
226 { 1.0f, 1.0f },
227 { 0.0f, 1.0f }
228 };
231 float textureIndex = 0.0f;
232 for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
233 {
234 if (*s_Data.TextureSlots[i].get() == *texture.get())
235 {
236 textureIndex = (float)i;
237 break;
238 }
239 }
240 if (textureIndex == 0.0f)
241 {
244 textureIndex = (float)s_Data.TextureSlotIndex;
247 }
248 for (size_t i = 0; i < quadVertexCount; i++)
249 {
251 s_Data.QuadVertexBufferPtr->Color = tintColor;
252 s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
253 s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
256 }
257
260
261 }

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

◆ DrawQuadWithTexture() [3/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
319 {
320 DrawQuadWithTexture({ position.x, position.y, 0.0f }, size, subtexture, tilingFactor, tintColor);
321 }
static void DrawQuadWithTexture(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.
Definition Renderer2D.cpp:218

◆ DrawQuadWithTexture() [4/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
263 {
264 DrawQuadWithTexture({ position.x, position.y, 0.0f }, size, texture, tilingFactor, tintColor);
265 }

◆ DrawQuadWithTexture() [5/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
323 {
325
326 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
327 DrawQuadWithTexture(transform, subtexture, tilingFactor, tintColor);
328 }

◆ DrawQuadWithTexture() [6/6]

void Vesper::Renderer2D::DrawQuadWithTexture ( 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.
267 {
269
270 glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
271 DrawQuadWithTexture(transform, texture, tilingFactor, tintColor);
272 }

◆ EndScene()

void Vesper::Renderer2D::EndScene ( )
static

Ends the current scene.

161 {
163 uint32_t dataSize = (uint32_t)((uint8_t*)s_Data.QuadVertexBufferPtr - (uint8_t*)s_Data.QuadVertexBufferBase);
164
166 Flush();
167 }
static void Flush()
Flushes the current batch of rendering commands.
Definition Renderer2D.cpp:169
Ref< VertexBuffer > QuadVertexBuffer
Definition Renderer2D.cpp:29

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

Referenced by FlushAndReset(), Vesper::EditorLayer::OnUpdate(), Vesper::Scene::OnUpdateEditor(), and Vesper::Scene::OnUpdateRuntime().

◆ Flush()

void Vesper::Renderer2D::Flush ( )
static

Flushes the current batch of rendering commands.

170 {
172 // Bind textures
173 for (uint32_t i = 0; i < s_Data.TextureSlotIndex; i++)
174 s_Data.TextureSlots[i]->Bind(i);
175
178 }
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:38
uint32_t DrawCalls
The number of draw calls being made.
Definition Renderer2D.h:207
Ref< VertexArray > QuadVertexArray
Definition Renderer2D.cpp:28

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

Referenced by EndScene().

◆ FlushAndReset()

◆ GetStats()

Renderer2D::Statistics Vesper::Renderer2D::GetStats ( )
static

Retrieves the current rendering statistics.

503 {
504 return s_Data.Stats;
505 }

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

Referenced by Vesper::EditorLayer::OnImGuiRender().

◆ GetWhiteTexture()

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

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

493 {
494 return s_Data.WhiteTexture;
495 }
Ref< Texture2D > WhiteTexture
Definition Renderer2D.cpp:31

References Vesper::s_Data.

◆ Init()

void Vesper::Renderer2D::Init ( )
static

Initializes the 2D renderer.

56 {
58
60
61
63
64 s_Data.QuadVertexBuffer->SetLayout({
65 { ShaderDataType::Float3, "a_Position" },
66 { ShaderDataType::Float4, "a_Color" },
67 { ShaderDataType::Float2, "a_TexCoord" },
68 { ShaderDataType::Float, "a_TexIndex" },
69 { ShaderDataType::Float, "a_TilingFactor"}
70 });
72
74
75 uint32_t* quadIndices = new uint32_t[s_Data.MaxIndices];
76 uint32_t offset = 0;
77
78 for (uint32_t i = 0; i < s_Data.MaxIndices; i += 6) {
79 quadIndices[i + 0] = offset + 0;
80 quadIndices[i + 1] = offset + 1;
81 quadIndices[i + 2] = offset + 2;
82 quadIndices[i + 3] = offset + 2;
83 quadIndices[i + 4] = offset + 3;
84 quadIndices[i + 5] = offset + 0;
85
86 offset += 4;
87 }
88
89 Ref<IndexBuffer> quadIB;
90 quadIB = (IndexBuffer::Create(quadIndices, s_Data.MaxIndices));
91 s_Data.QuadVertexArray->SetIndexBuffer(quadIB);
92 delete[] quadIndices;
93
95 uint32_t whiteTextureData = 0xffffffff;
96 s_Data.WhiteTexture->SetData(&whiteTextureData, sizeof(uint32_t));
97
98 int32_t samplers[s_Data.MaxTextureSlots];
99 for (uint32_t i = 0; i < s_Data.MaxTextureSlots; i++)
100 samplers[i] = i;
101
102
103 s_Data.TextureShader = Shader::Create("../../Vesper-Editor/assets/shaders/Texture.glsl");
104 s_Data.TextureShader->Bind();
105 s_Data.TextureShader->SetIntArray("u_Textures", samplers, s_Data.MaxTextureSlots);
106
108
109 s_Data.QuadVertexPositions[0] = { -0.5f, -0.5f, 0.0f, 1.0f };
110 s_Data.QuadVertexPositions[1] = { 0.5f, -0.5f, 0.0f, 1.0f };
111 s_Data.QuadVertexPositions[2] = { 0.5f, 0.5f, 0.0f, 1.0f };
112 s_Data.QuadVertexPositions[3] = { -0.5f, 0.5f, 0.0f, 1.0f };
113
114 }
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)
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
@ Float
Definition Buffer.h:8
@ Float4
Definition Buffer.h:8
@ Float2
Definition Buffer.h:8
@ Float3
Definition Buffer.h:8
static const uint32_t MaxVertices
Definition Renderer2D.cpp:24

References Vesper::Float, Vesper::Float2, Vesper::Float3, Vesper::Float4, Vesper::Renderer2DData::MaxIndices, Vesper::Renderer2DData::MaxTextureSlots, Vesper::Renderer2DData::MaxVertices, Vesper::Renderer2DData::QuadVertexBufferBase, and Vesper::s_Data.

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

◆ ResetStats()

void Vesper::Renderer2D::ResetStats ( )
static

Resets the rendering statistics.

498 {
499 memset(&s_Data.Stats, 0, sizeof(Statistics));
500 }
2D Renderer Statistics
Definition Renderer2D.h:205

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

Referenced by Vesper::EditorLayer::OnUpdate().

◆ Shutdown()

void Vesper::Renderer2D::Shutdown ( )
static

Shuts down the 2D renderer.

117 {
119
121 }

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

◆ StartBatch()

void Vesper::Renderer2D::StartBatch ( )
staticprivate
516 {
517
520
521 //s_Data.CircleIndexCount = 0;
522 //s_Data.CircleVertexBufferPtr = s_Data.CircleVertexBufferBase;
523
524 //s_Data.LineVertexCount = 0;
525 //s_Data.LineVertexBufferPtr = s_Data.LineVertexBufferBase;
526
527 //s_Data.TextIndexCount = 0;
528 //s_Data.TextVertexBufferPtr = s_Data.TextVertexBufferBase;
529
531
532 }

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

Referenced by BeginScene().


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