Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Renderer2D.h
Go to the documentation of this file.
1#pragma once
2/// @file Renderer2D.h
3/// @author Damon S. Green II
4/// @brief Defines the Renderer2D class, which is responsible for rendering 2D quads and sprites. This class provides a simple API for drawing 2D graphics in a scene.
5
6#include "Renderer/OrthographicCamera.h"
7
8#include "Renderer/Texture.h"
9#include "Renderer/SubTexture2D.h"
10
11#include "Renderer/Camera.h"
12#include "Renderer/EditorCamera.h"
13#include "Scene/Components.h"
14
15namespace Muto {
16
17 /// @class Renderer2D
18 /// @brief A 2D renderer for drawing quads and sprites.
19 /// @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.
21 {
22 public:
23 /// @brief Initializes the 2D renderer.
24 static void Init();
25 /// @brief Shuts down the 2D renderer.
26 static void Shutdown();
27
28 /// @brief Begins a new scene with the given camera and transform.
29 ///
30 /// @param camera The camera to use for the scene.
31 /// @param transform The transform matrix for the camera.
32 /// @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.
33 static void BeginScene(const Camera& camera, const glm::mat4& transform);
34
35 /// @brief Begins a new scene with the given editor camera.
36 ///
37 /// @param camera The editor camera to use for the scene.
38 static void BeginScene(const EditorCamera& camera);
39
40 /// @brief Begins a new scene with the given orthographic camera.
41 ///
42 /// @param camera The orthographic camera to use for the scene.
43 /// @todo Remove once we have a proper scene system
44 static void BeginScene(const OrthographicCamera& camera);
45
46 /// @brief Ends the current scene.
47 static void EndScene();
48
49 /// @brief Flushes the current batch of rendering commands.
50 static void Flush();
51
52 /// @brief Draws a colored quad with the given transform and color.
53 ///
54 /// @param transform The transform matrix for the quad.
55 /// @param color The color of the quad.
56 static void DrawQuad(const glm::mat4& transform, const glm::vec4& color);
57
58 /// @brief Draws a colored quad at the specified position and size.
59 ///
60 /// @param position The position of the quad in 2D space.
61 /// @param size The size of the quad.
62 /// @param color The color of the quad.
63 static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color);
64
65 /// @brief Draws a colored quad at the specified position and size.
66 ///
67 /// @param position The position of the quad in 3D space.
68 /// @param size The size of the quad.
69 /// @param color The color of the quad.
70 static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color);
71
72 /// @brief Draws a textured quad with the given transform, texture, tiling factor, and tint color.
73 ///
74 /// @param transform The transform matrix for the quad.
75 /// @param texture The texture to apply to the quad.
76 /// @param tilingFactor The tiling factor for the texture.
77 /// @param tintColor The tint color to apply to the texture.
78 static void DrawQuad(const glm::mat4& transform, const Ref<Texture2D>& texture, float tilingFactor, const glm::vec4 tintColor);
79
80 /// @brief Draws a textured quad at the specified position and size.
81 ///
82 /// @param position The position of the quad in 2D space.
83 /// @param size The size of the quad.
84 /// @param texture The texture to apply to the quad.
85 /// @param tilingFactor The tiling factor for the texture.
86 /// @param tintColor The tint color to apply to the texture.
87 static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture, float tilingFactor, const glm::vec4 tintColor);
88
89 /// @brief Draws a textured quad at the specified position and size.
90 ///
91 /// @param position The position of the quad in 3D space.
92 /// @param size The size of the quad.
93 /// @param texture The texture to apply to the quad.
94 /// @param tilingFactor The tiling factor for the texture.
95 /// @param tintColor The tint color to apply to the texture.
96 static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture, float tilingFactor, const glm::vec4 tintColor);
97
98 /// @brief Draws a textured quad with the given transform, subtexture, tiling factor, and tint color.
99 ///
100 /// @param transform The transform matrix for the quad.
101 /// @param subtexture The subtexture to apply to the quad.
102 /// @param tilingFactor The tiling factor for the texture.
103 /// @param tintColor The tint color to apply to the texture.
104 static void DrawQuad(const glm::mat4& transform, const Ref<SubTexture2D>& subtexture, float tilingFactor, const glm::vec4 tintColor);
105
106 /// @brief Draws a textured quad at the specified position and size.
107 ///
108 /// @param position The position of the quad in 2D space.
109 /// @param size The size of the quad.
110 /// @param subtexture The subtexture to apply to the quad.
111 /// @param tilingFactor The tiling factor for the texture.
112 /// @param tintColor The tint color to apply to the texture.
113 static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<SubTexture2D>& subtexture, float tilingFactor, const glm::vec4 tintColor);
114
115 /// @brief Draws a textured quad at the specified position and size.
116 ///
117 /// @param position The position of the quad in 3D space.
118 /// @param size The size of the quad.
119 /// @param subtexture The subtexture to apply to the quad.
120 /// @param tilingFactor The tiling factor for the texture.
121 /// @param tintColor The tint color to apply to the texture.
122 static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<SubTexture2D>& subtexture, float tilingFactor, const glm::vec4 tintColor);
123
124 /// @brief Draws a rotated colored quad with the given transform and color.
125 ///
126 /// @param transform The transform matrix for the quad.
127 /// @param color The color of the quad.
128 static void DrawRotatedQuad(const glm::mat4& transform, const glm::vec4& color);
129
130 /// @brief Draws a rotated colored quad at the specified position, size, and rotation.
131 ///
132 /// @param position The position of the quad in 2D space.
133 /// @param size The size of the quad.
134 /// @param rotationRads The rotation of the quad in radians.
135 /// @param color The color of the quad.
136 static void DrawRotatedQuad(const glm::vec2& position, const glm::vec2& size, float rotationRads, const glm::vec4& color);
137
138 /// @brief Draws a rotated colored quad at the specified position, size, and rotation.
139 ///
140 /// @param position The position of the quad in 3D space.
141 /// @param size The size of the quad.
142 /// @param rotationRads The rotation of the quad in radians.
143 /// @param color The color of the quad.
144 static void DrawRotatedQuad(const glm::vec3& position, const glm::vec2& size, float rotationRads, const glm::vec4& color);
145
146 /// @brief Draws a rotated textured quad with the given transform, texture, tiling factor, and tint color.
147 ///
148 /// @param transform The transform matrix for the quad.
149 /// @param texture The texture to apply to the quad.
150 /// @param tilingFactor The tiling factor for the texture.
151 /// @param tintColor The tint color to apply to the texture.
152 static void DrawRotatedQuad(const glm::mat4& transform, const Ref<Texture2D>& texture, float tilingFactor, const glm::vec4 tintColor);
153
154 /// @brief Draws a rotated textured quad at the specified position, size, and rotation.
155 ///
156 /// @param position The position of the quad in 2D space.
157 /// @param size The size of the quad.
158 /// @param rotationRads The rotation of the quad in radians.
159 /// @param texture The texture to apply to the quad.
160 /// @param tilingFactor The tiling factor for the texture.
161 /// @param tintColor The tint color to apply to the texture.
162 static void DrawRotatedQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture, float rotationRads, float tilingFactor, const glm::vec4 tintColor);
163
164 /// @brief Draws a rotated textured quad at the specified position, size, and rotation.
165 ///
166 /// @param position The position of the quad in 3D space.
167 /// @param size The size of the quad.
168 /// @param rotationRads The rotation of the quad in radians.
169 /// @param texture The texture to apply to the quad.
170 /// @param tilingFactor The tiling factor for the texture.
171 /// @param tintColor The tint color to apply to the texture.
172 static void DrawRotatedQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture, float rotationRads, float tilingFactor, const glm::vec4 tintColor);
173
174 /// @brief Draws a rotated textured quad with the given transform, subtexture, tiling factor, and tint color.
175 ///
176 /// @param transform The transform matrix for the quad.
177 /// @param subtexture The subtexture to apply to the quad.
178 /// @param tilingFactor The tiling factor for the texture.
179 /// @param tintColor The tint color to apply to the texture.
180 static void DrawRotatedQuad(const glm::mat4& transform, const Ref<SubTexture2D>& subtexture, float tilingFactor, const glm::vec4 tintColor);
181
182 /// @brief Draws a rotated textured quad at the specified position, size, and rotation.
183 ///
184 /// @param position The position of the quad in 2D space.
185 /// @param size The size of the quad.
186 /// @param rotationRads The rotation of the quad in radians.
187 /// @param subtexture The subtexture to apply to the quad.
188 /// @param tilingFactor The tiling factor for the texture.
189 /// @param tintColor The tint color to apply to the texture.
190 static void DrawRotatedQuad(const glm::vec2& position, const glm::vec2& size, const Ref<SubTexture2D>& subtexture, float rotationRads, float tilingFactor, const glm::vec4 tintColor);
191
192 /// @brief Draws a rotated textured quad at the specified position, size, and rotation.
193 ///
194 /// @param position The position of the quad in 3D space.
195 /// @param size The size of the quad.
196 /// @param rotationRads The rotation of the quad in radians.
197 /// @param subtexture The subtexture to apply to the quad.
198 /// @param tilingFactor The tiling factor for the texture.
199 /// @param tintColor The tint color to apply to the texture.
200 static void DrawRotatedQuad(const glm::vec3& position, const glm::vec2& size, const Ref<SubTexture2D>& subtexture, float rotationRads, float tilingFactor, const glm::vec4 tintColor);
201
202
203 //static void DrawSprite(const glm::mat4& transform, const SpriteRendererComponent& src, int entityID);
204 //static void DrawSprite(const glm::mat4& transform, const SubTextureComponent& stc, int entityID);
205
206 /// @brief Returns a reference to the default white texture that allows for coloring.
207 static Ref<Texture2D> GetWhiteTexture();
208
209 /// @brief 2D Renderer Statistics
210 struct Statistics {
211 /// @brief The number of draw calls being made
212 uint32_t DrawCalls = 0;
213 /// @brief The number of quads being drawn
214 uint32_t QuadCount = 0;
215 /// @brief Calculates the total number of vertices drawn
216 uint32_t GetTotalVertexCount() { return QuadCount * 4; }
217 /// @brief Calculates the total number of indices drawn
218 uint32_t GetTotalIndexCount() { return QuadCount * 6; }
219 };
220
221 /// @brief Resets the rendering statistics.
222 static void ResetStats();
223 /// @brief Retrieves the current rendering statistics.
224 static Statistics GetStats();
225
226 private:
227 static void FlushAndReset();
228 static void StartBatch();
229 };
230
231}
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define MU_BIND_EVENT_FN(fn)
Binds a member function as an event handler.
Definition Defines_Macros.h:17
static const uint32_t s_MapHeight
Definition EditorLayer.cpp:14
static const char * s_MapTiles
Definition EditorLayer.cpp:15
static const uint32_t s_MapWidth
Definition EditorLayer.cpp:13
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
The core application class that manages the main loop, window, layers, and event handling.
Definition Application.h:70
void Close()
Closes the application.
Definition Application.cpp:103
ImGuiLayer * GetImGuiLayer()
Retrieves the ImGui layer.
Definition Application.h:104
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
The base Camera class that all Camera's derive from Only contains a pojection matrix and a getter.
Definition Camera.h:15
glm::mat4 m_Projection
Definition Camera.h:25
const glm::mat4 & GetProjection() const
Definition Camera.h:23
Camera()=default
~Camera()=default
Camera(const glm::mat4 &projection)
Definition Camera.h:18
Definition EditorCamera.h:20
Definition EditorLayer.h:13
bool useEntityScene
Definition EditorLayer.h:90
OrthographicCameraController m_CameraController
Definition EditorLayer.h:52
bool m_PrimaryCamera
Definition EditorLayer.h:46
virtual void OnAttach() override
Called when the layer is attached to the application.
Definition EditorLayer.cpp:46
bool scene3
Definition EditorLayer.h:89
glm::vec2 m_ViewportBounds[2]
Definition EditorLayer.h:45
Ref< Scene > m_ActiveScene
Definition EditorLayer.h:34
Ref< Scene > m_EditorScene
Definition EditorLayer.h:35
ParticleProps m_ParticleProps
Definition EditorLayer.h:86
glm::vec4 m_TextureTintColor2
Definition EditorLayer.h:94
Ref< SubTexture2D > m_SubTextureSmoke
Definition EditorLayer.h:70
void OpenScene()
Definition EditorLayer.cpp:539
glm::vec4 m_SpecialQuadColor
Definition EditorLayer.h:97
bool scene2
Definition EditorLayer.h:89
EditorCamera m_EditorCamera
Definition EditorLayer.h:78
bool scene1
Definition EditorLayer.h:89
int m_GizmoType
Definition EditorLayer.h:49
Ref< Shader > m_FlatColorShader
Definition EditorLayer.h:59
bool OnKeyPressed(KeyPressedEvent &e)
Definition EditorLayer.cpp:480
Entity m_CameraEntity
Definition EditorLayer.h:47
EditorLayer()
Definition EditorLayer.cpp:38
void NewScene()
Definition EditorLayer.cpp:532
Ref< Framebuffer > m_Framebuffer
Definition EditorLayer.h:76
Entity m_FireEntity
Definition EditorLayer.h:55
float m_textureScale
Definition EditorLayer.h:80
void SaveSceneAs()
Definition EditorLayer.cpp:555
Ref< Texture2D > m_SpriteSheetFire
Definition EditorLayer.h:62
Ref< SubTexture2D > m_SubTextureFire
Definition EditorLayer.h:69
bool scene4
Definition EditorLayer.h:89
std::unordered_map< char, Ref< SubTexture2D > > s_TextureMap
Definition EditorLayer.h:100
virtual void OnDetach() override
Called when the layer is detached from the application.
Definition EditorLayer.cpp:230
SceneHierarchyPanel m_SceneHierarchyPanel
Definition EditorLayer.h:32
float m_squareRotation
Definition EditorLayer.h:81
bool m_UseSpecialQuadColor
Definition EditorLayer.h:98
glm::vec4 m_ClearColor
Definition EditorLayer.h:96
float lastFrameTime
Definition EditorLayer.h:54
virtual void OnEvent(Event &e) override
Called when an event is dispatched to the layer.
Definition EditorLayer.cpp:468
virtual ~EditorLayer()=default
glm::vec4 m_SquareColor
Definition EditorLayer.h:92
virtual void OnUpdate(Timestep ts) override
Called every frame to update the layer with the given timestep.
Definition EditorLayer.cpp:235
ParticleSystem m_ParticleSystem
Definition EditorLayer.h:85
glm::vec4 m_TextureTintColor1
Definition EditorLayer.h:93
void ResetScene()
Definition EditorLayer.cpp:566
glm::vec2 m_ViewportSize
Definition EditorLayer.h:44
float m_TranslationSnap
Definition EditorLayer.h:50
SceneState m_SceneState
Definition EditorLayer.h:41
float m_ScaleSnap
Definition EditorLayer.h:50
Ref< Texture2D > m_SpriteSheetTown
Definition EditorLayer.h:64
Ref< Texture2D > m_CheckerboardTexture
Definition EditorLayer.h:60
bool m_ViewportFocused
Definition EditorLayer.h:43
Ref< Texture2D > m_SpriteSheetRocks
Definition EditorLayer.h:66
Ref< VertexArray > m_SquareVA
Definition EditorLayer.h:58
float m_RotationSnap
Definition EditorLayer.h:50
int m_ParticleEmitCount
Definition EditorLayer.h:83
glm::vec4 m_BackgroundColor
Definition EditorLayer.h:95
Ref< Texture2D > m_SpriteSheetSmoke
Definition EditorLayer.h:63
virtual void OnImGuiRender() override
Called when the layer should render its ImGui components.
Definition EditorLayer.cpp:281
SceneState
Definition EditorLayer.h:38
Entity m_SmokeEntity
Definition EditorLayer.h:55
bool m_ViewportHovered
Definition EditorLayer.h:43
float m_specialQuadRotation
Definition EditorLayer.h:82
Ref< SubTexture2D > m_SubTextureTown
Definition EditorLayer.h:71
Ref< Texture2D > m_SpriteSheetCursedLands
Definition EditorLayer.h:67
Ref< Texture2D > m_SpriteSheetCrystals
Definition EditorLayer.h:65
Represents an entity in a scene.
Definition Entity.h:17
T & AddOrReplaceComponent(Args &&... args)
Adds or replaces a component of type T to the entity with the provided arguments.
Definition Entity.h:63
T & GetOrAddComponent(Args &&... args)
Retrieves a reference to the component of type T attached to the entity if it exists....
Definition Entity.h:86
Entity(entt::entity handle, Scene *scene)
Constructs an Entity with the given handle and scene.
Definition Entity.cpp:6
Entity(const Entity &other)=default
Copy constructor for Entity.
T & GetComponent()
Retrieves a reference to the component of type T attached to the entity if it exists....
Definition Entity.h:73
Scene * m_Scene
Pointer to the scene that contains the entity.
Definition Entity.h:131
const std::string & GetName()
Retrieves a const reference to the name of the entity.
Definition Entity.h:115
bool HasComponent() const
Checks if the entity has a component of type T.
Definition Entity.h:36
Entity()=default
void RemoveComponent()
Removes the component of type T from the entity if it exists. Otherwise, asserts.
Definition Entity.h:98
const UUID & GetID()
Retrieves a const reference to the UUID of the entity.
Definition Entity.h:107
T & AddComponent(Args &&... args)
Adds a component of type T to the entity with the provided arguments Otherwise, asserts if the entity...
Definition Entity.h:48
operator bool() const
Definition Entity.h:121
Stack-based templated event dispatcher.
Definition Event.h:66
EventDispatcher(Event &event)
Construct an EventDispatcher for a specific event.
Definition Event.h:76
Abstract base class for all events.
Definition Event.h:35
Cross-platform file dialog utilities.
Definition PlatformUtils.h:13
static std::string SaveFile(const char *filter)
Opens a file dialog to select a location to save a file.
Definition LinuxPlatformUtils.cpp:165
static std::string OpenFile(const char *filter)
Opens a file dialog to select a file to open.
Definition LinuxPlatformUtils.cpp:160
WIP.
Definition PlatformUtils.h:31
static std::string m_RootEditorDirectory
Definition PlatformUtils.h:41
static std::string m_RootEngineDirectory
Definition PlatformUtils.h:40
static std::string m_ProjectsDirectory
Definition PlatformUtils.h:44
static std::string m_AssetsDirectory
Definition PlatformUtils.h:43
static bool IsInitialized()
Definition PlatformUtils.h:37
static void Initialize()
Definition FileSystem.cpp:16
static bool m_Initialized
Definition PlatformUtils.h:39
static std::string GetAbsolutePath(const std::string &relativePath)
Definition FileSystem.cpp:38
static std::string GetCurrentWorkingDirectory()
Definition FileSystem.cpp:33
static std::string m_ResourcesDirectory
Definition PlatformUtils.h:42
static std::string m_CurrentProjectDirectory
Definition PlatformUtils.h:45
static std::string GetTravelingUpPath(const std::string &path)
Definition FileSystem.cpp:43
virtual void SetBlockEvents(bool block)
Definition ImGuiLayer.h:29
Base input class for querying input states.
Definition Input.h:15
static bool IsKeyPressed(int keycode)
Checks if the specified key is currently pressed.
Definition WindowsInput.cpp:9
int GetKeyCode() const
Get the key code associated with the event.
Definition KeyEvent.h:20
Event for registering key press.
Definition KeyEvent.h:37
int GetRepeatCount() const
Get the repeat count of the key press event.
Definition KeyEvent.h:48
Represents a reusable application layer that receives lifecycle callbacks (attach,...
Definition Layer.h:17
Definition OrthographicCameraController.h:30
Definition OrthographicCamera.h:15
A simple particle system for stress testing the renderer. This is a temporary starter particle system...
Definition ParticleSystem.h:45
int m_EmitRate
Definition ParticleSystem.h:64
ParticleSystem(uint32_t maxParticles)
Definition ParticleSystem.cpp:18
void ResetParticle(Particle &particle, const ParticleProps &particleProps)
Definition ParticleSystem.cpp:120
void OnRender()
Definition ParticleSystem.cpp:76
bool m_Loop
Definition ParticleSystem.h:65
bool m_IsEmitting
Definition ParticleSystem.h:63
uint32_t m_PoolIndex
Definition ParticleSystem.h:58
void OnUpdate(Timestep ts)
Definition ParticleSystem.cpp:24
ParticleProps m_Props
Definition ParticleSystem.h:61
float m_TimeSinceLastEmit
Definition ParticleSystem.h:62
ParticleSystem()
Definition ParticleSystem.cpp:11
void SetParticleProps(const ParticleProps &particleProps)
Definition ParticleSystem.h:53
std::vector< Particle > m_ParticlePool
Definition ParticleSystem.h:57
void Emit(const ParticleProps &particleProps)
Definition ParticleSystem.cpp:96
void ResetSystem()
Definition ParticleSystem.h:54
int m_activeParticleCount
Definition ParticleSystem.h:59
A static class that provides an interface for issuing rendering commands.
Definition RenderCommand.h:13
static void Clear()
Clears the rendering buffers.
Definition RenderCommand.h:35
A 2D renderer for drawing quads and sprites.
Definition Renderer2D.h:21
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.
Definition Renderer2D.cpp:391
static void StartBatch()
Definition Renderer2D.cpp:532
static void FlushAndReset()
Definition Renderer2D.cpp:526
static void BeginScene(const OrthographicCamera &camera)
Begins a new scene with the given orthographic camera.
Definition Renderer2D.cpp:157
static void Init()
Initializes the 2D renderer.
Definition Renderer2D.cpp:65
static void EndScene()
Ends the current scene.
Definition Renderer2D.cpp:165
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.
Definition Renderer2D.cpp:444
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.
Definition Renderer2D.cpp:242
static void ResetStats()
Resets the rendering statistics.
Definition Renderer2D.cpp:516
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.
Definition Renderer2D.cpp:297
static void Shutdown()
Shuts down the 2D renderer.
Definition Renderer2D.cpp:130
static Ref< Texture2D > GetWhiteTexture()
Returns a reference to the default white texture that allows for coloring.
Definition Renderer2D.cpp:511
static void BeginScene(const Camera &camera, const glm::mat4 &transform)
Begins a new scene with the given camera and transform.
Definition Renderer2D.cpp:137
static void BeginScene(const EditorCamera &camera)
Begins a new scene with the given editor camera.
Definition Renderer2D.cpp:147
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.
Definition Renderer2D.cpp:253
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.
Definition Renderer2D.cpp:403
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
static void Flush()
Flushes the current batch of rendering commands.
Definition Renderer2D.cpp:188
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
static Statistics GetStats()
Retrieves the current rendering statistics.
Definition Renderer2D.cpp:521
Definition SceneCamera.h:12
virtual ~SceneCamera()=default
void RecalculateProjection()
Definition SceneCamera.cpp:37
float m_AspectRatio
Definition SceneCamera.h:51
float m_OrthographicFar
Definition SceneCamera.h:49
ProjectionType m_ProjectionType
Definition SceneCamera.h:43
void SetPerspectiveNearClip(float nearClip)
Definition SceneCamera.h:27
ProjectionType GetProjectionType() const
Definition SceneCamera.h:38
void SetPerspectiveVerticalFOV(float verticalFov)
Definition SceneCamera.h:25
float m_OrthographicSize
Definition SceneCamera.h:48
float GetPerspectiveNearClip() const
Definition SceneCamera.h:26
SceneCamera()
Definition SceneCamera.cpp:9
void SetOrthographicSize(float size)
Definition SceneCamera.h:32
float GetOrthographicNearClip() const
Definition SceneCamera.h:33
float GetPerspectiveVerticalFOV() const
Definition SceneCamera.h:24
float m_PerspectiveNear
Definition SceneCamera.h:46
void SetPerspectiveFarClip(float farClip)
Definition SceneCamera.h:29
float GetOrthographicFarClip() const
Definition SceneCamera.h:35
float m_PerspectiveFar
Definition SceneCamera.h:46
void SetOrthographicNearClip(float nearClip)
Definition SceneCamera.h:34
float GetPerspectiveFarClip() const
Definition SceneCamera.h:28
float m_OrthographicNear
Definition SceneCamera.h:49
float GetOrthographicSize() const
Definition SceneCamera.h:31
void SetViewportSize(uint32_t width, uint32_t height)
Definition SceneCamera.cpp:31
ProjectionType
Definition SceneCamera.h:14
void SetPerspective(float verticalFOV, float nearClip, float farClip)
Definition SceneCamera.cpp:14
void SetProjectionType(ProjectionType type)
Definition SceneCamera.h:39
float m_PerspectiveFOV
Definition SceneCamera.h:45
void SetOrthographicFarClip(float farClip)
Definition SceneCamera.h:36
void SetOrthographic(float size, float nearClip, float farClip)
Definition SceneCamera.cpp:23
Definition SceneHierarchyPanel.h:12
Handles serialization and deserialization of scenes.
Definition SceneSerializer.h:16
void Serialize(const std::string &filepath)
Definition SceneSerializer.cpp:179
bool Deserialize(const std::string &filepath)
Definition SceneSerializer.cpp:206
Represents a scene in the application and manages entities and their components.
Definition Scene.h:21
entt::registry m_Registry
Definition Scene.h:41
void OnUpdateRuntime(Timestep ts)
Definition Scene.cpp:58
void OnUpdateEditor(Timestep ts, EditorCamera &camera)
Definition Scene.cpp:188
const std::string & GetName() const
Definition Scene.h:50
void OnComponentAdded(Entity entity, T &component)
Definition Scene.cpp:313
void SetName(const std::string &name)
Definition Scene.h:49
Scene()
Definition Scene.cpp:14
void DestroyEntity(Entity entity)
Definition Scene.cpp:52
uint32_t m_ViewportHeight
Definition Scene.h:42
Entity GetPrimaryCameraEntity()
Definition Scene.cpp:295
void OnViewportResize(uint32_t width, uint32_t height)
Definition Scene.cpp:280
~Scene()
Definition Scene.cpp:26
Entity CreateEntity(const std::string &name=std::string())
Definition Scene.cpp:30
Scene(const std::string &name)
Definition Scene.cpp:21
Entity CreateEntity(const std::string &name, const std::string &uuid)
Definition Scene.cpp:41
std::string m_Name
Definition Scene.h:40
uint32_t m_ViewportWidth
Definition Scene.h:42
Base class for scriptable entities within a scene.
Definition ScriptableEntity.h:14
virtual void OnDestroy()
Called when the entity is destroyed.
Definition ScriptableEntity.h:40
virtual void OnCreate()
Sets the entity associated with this scriptable entity.
Definition ScriptableEntity.h:34
virtual void OnUpdate(Timestep ts)
Called every frame to update the entity.
Definition ScriptableEntity.h:46
Entity m_Entity
Definition ScriptableEntity.h:48
T & GetComponent()
Retrieves a reference to a component of type T attached to the entity.
Definition ScriptableEntity.h:24
virtual ~ScriptableEntity()
Definition ScriptableEntity.h:16
Represents a sub-region of a 2D texture, useful for sprite sheets.
Definition SubTexture2D.h:16
glm::vec2 m_TexCoords[4]
The texture coordinates of the sub-texture.
Definition SubTexture2D.h:41
glm::vec2 * GetTexCoords()
Returns the texture coordinates of the sub-texture.
Definition SubTexture2D.h:28
Ref< Texture2D > m_Texture
The underlying texture of the sub-texture.
Definition SubTexture2D.h:39
SubTexture2D(const Ref< Texture2D > &texture, const glm::vec2 &min, const glm::vec2 &max)
Constructs a SubTexture2D from the given texture and texture coordinates.
Definition SubTexture2D.cpp:8
const Ref< Texture2D > GetTexture()
Returns the underlying texture of the sub-texture.
Definition SubTexture2D.h:26
static Ref< SubTexture2D > CreateFromCoords(const Ref< Texture2D > &texture, const glm::vec2 &coords, const glm::vec2 &cellSize, const glm::vec2 &spriteSize={1, 1})
Creates a SubTexture2D from a grid of cells within the given texture.
Definition SubTexture2D.cpp:17
An abstraction for a 2D texture.
Definition Texture.h:41
static Ref< Texture2D > Create(const std::string &path)
Definition Texture.cpp:21
static Ref< Texture2D > Create(uint32_t width, uint32_t height)
Definition Texture.cpp:10
A library for managing and storing textures.
Definition Texture.h:53
void Add(const Ref< Texture2D > &texture)
Adds a texture to the library using its own name.
Definition Texture.cpp:39
bool Exists(const std::string &name) const
Checks if a texture with the specified name exists in the library.
Definition Texture.cpp:69
Ref< Texture2D > Load(const std::string &filepath)
Loads a texture from the specified filepath and adds it to the library.
Definition Texture.cpp:46
void Add(const std::string &name, const Ref< Texture2D > &texture)
Adds a texture to the library with the specified name.
Definition Texture.cpp:32
Ref< Texture2D > Get(const std::string &name) const
Retrieves a texture from the library by name.
Definition Texture.cpp:62
Ref< Texture2D > Load(const std::string &name, const std::string &filepath)
Loads a texture from the specified filepath and adds it to the library with the given name.
Definition Texture.cpp:54
std::unordered_map< std::string, Ref< Texture2D > > m_Textures
Definition Texture.h:68
An abstraction for a texture.
Definition Texture.h:14
virtual ~Texture()=default
virtual void Bind(uint32_t slot=0) const =0
Binds the texture to the specified slot for use.
virtual std::string GetName() const =0
virtual uint32_t GetRendererID() const =0
Returns the renderer ID of the texture.
virtual uint32_t GetHeight() const =0
Returns the height of the texture.
virtual uint32_t GetWidth() const =0
Returns the width of the texture.
virtual void SetData(void *data, uint32_t size)=0
Sets the data of the texture.
virtual bool operator==(const Texture2D &other) const =0
Represents a time step in seconds.
Definition Timestep.h:11
static glm::vec4 Brown()
Returns a vec4 representing the color brown.
Definition Color.h:44
static glm::vec4 StripAlpha(const glm::vec4 &color)
Strips the alpha component from the given color, setting it to 1.0 (fully opaque).
Definition Color.h:49
static glm::vec4 Cyan()
Returns a vec4 representing the color cyan.
Definition Color.h:38
static glm::vec4 Indigo()
Returns a vec4 representing the color indigo.
Definition Color.h:33
static glm::vec4 Orange()
Returns a vec4 representing the color orange.
Definition Color.h:25
static glm::vec4 Black()
Returns a vec4 representing the color black.
Definition Color.h:18
static glm::vec4 SetAlpha(const glm::vec4 &color, float alpha=0.0f)
Sets the alpha component of the given color to the specified value.
Definition Color.h:51
static glm::vec4 Yellow()
Returns a vec4 representing the color yellow.
Definition Color.h:27
static glm::vec4 Purple()
Returns a vec4 representing the color purple.
Definition Color.h:35
static glm::vec4 Gray()
Returns a vec4 representing the color gray.
Definition Color.h:20
static glm::vec4 Pink()
Returns a vec4 representing the color pink.
Definition Color.h:42
static glm::vec4 White()
Returns a vec4 representing the color white.
Definition Color.h:16
static glm::vec4 Green()
Returns a vec4 representing the color green.
Definition Color.h:29
static glm::vec4 Blue()
Returns a vec4 representing the color blue.
Definition Color.h:31
static glm::vec4 Transparent()
Returns a vec4 representing a fully transparent color.
Definition Color.h:46
static glm::vec4 Red()
Returns a vec4 representing the color red.
Definition Color.h:23
static glm::vec4 Magenta()
Returns a vec4 representing the color magenta.
Definition Color.h:40
@ RightControl
Definition KeyCodes.h:147
@ NumLock
Definition KeyCodes.h:93
@ KP_9
Definition KeyCodes.h:132
@ Enter
Definition KeyCodes.h:78
@ KP_1
Definition KeyCodes.h:124
@ RightAlt
Definition KeyCodes.h:148
@ A
Definition KeyCodes.h:41
@ F16
Definition KeyCodes.h:111
@ D9
Definition KeyCodes.h:36
@ F23
Definition KeyCodes.h:118
@ F2
Definition KeyCodes.h:97
@ KP_SUBTRACT
Definition KeyCodes.h:136
@ F4
Definition KeyCodes.h:99
@ J
Definition KeyCodes.h:50
@ Equal
Definition KeyCodes.h:39
@ Home
Definition KeyCodes.h:89
@ E
Definition KeyCodes.h:45
@ World1
Definition KeyCodes.h:73
@ C
Definition KeyCodes.h:43
@ P
Definition KeyCodes.h:56
@ PrintScreen
Definition KeyCodes.h:94
@ F12
Definition KeyCodes.h:107
@ GraveAccent
Definition KeyCodes.h:71
@ LeftControl
Definition KeyCodes.h:143
@ LeftSuper
Definition KeyCodes.h:145
@ S
Definition KeyCodes.h:59
@ Backslash
Definition KeyCodes.h:69
@ F25
Definition KeyCodes.h:120
@ RightBracket
Definition KeyCodes.h:70
@ F11
Definition KeyCodes.h:106
@ R
Definition KeyCodes.h:58
@ K
Definition KeyCodes.h:51
@ F
Definition KeyCodes.h:46
@ Z
Definition KeyCodes.h:66
@ KP_DECIMAL
Definition KeyCodes.h:133
@ Period
Definition KeyCodes.h:24
@ F3
Definition KeyCodes.h:98
@ End
Definition KeyCodes.h:90
@ F14
Definition KeyCodes.h:109
@ Up
Definition KeyCodes.h:86
@ PageDown
Definition KeyCodes.h:88
@ PageUp
Definition KeyCodes.h:87
@ W
Definition KeyCodes.h:63
@ KP_4
Definition KeyCodes.h:127
@ LeftBracket
Definition KeyCodes.h:68
@ D0
Definition KeyCodes.h:27
@ F20
Definition KeyCodes.h:115
@ Menu
Definition KeyCodes.h:150
@ Left
Definition KeyCodes.h:84
@ N
Definition KeyCodes.h:54
@ Space
Definition KeyCodes.h:20
@ Minus
Definition KeyCodes.h:23
@ D8
Definition KeyCodes.h:35
@ Tab
Definition KeyCodes.h:79
@ KP_MULTIPLY
Definition KeyCodes.h:135
@ F22
Definition KeyCodes.h:117
@ KP_DIVIDE
Definition KeyCodes.h:134
@ D3
Definition KeyCodes.h:30
@ KP_5
Definition KeyCodes.h:128
@ KP_EQUAL
Definition KeyCodes.h:139
@ F7
Definition KeyCodes.h:102
@ KP_7
Definition KeyCodes.h:130
@ F21
Definition KeyCodes.h:116
@ CapsLock
Definition KeyCodes.h:91
@ F19
Definition KeyCodes.h:114
@ Y
Definition KeyCodes.h:65
@ F18
Definition KeyCodes.h:113
@ KP_6
Definition KeyCodes.h:129
@ Apostrophe
Definition KeyCodes.h:21
@ Delete
Definition KeyCodes.h:82
@ KP_0
Definition KeyCodes.h:123
@ Q
Definition KeyCodes.h:57
@ F5
Definition KeyCodes.h:100
@ O
Definition KeyCodes.h:55
@ F6
Definition KeyCodes.h:101
@ Pause
Definition KeyCodes.h:95
@ KP_ENTER
Definition KeyCodes.h:138
@ X
Definition KeyCodes.h:64
@ LeftShift
Definition KeyCodes.h:142
@ KP_ADD
Definition KeyCodes.h:137
@ RightShift
Definition KeyCodes.h:146
@ B
Definition KeyCodes.h:42
@ D1
Definition KeyCodes.h:28
@ D4
Definition KeyCodes.h:31
@ LeftAlt
Definition KeyCodes.h:144
@ I
Definition KeyCodes.h:49
@ F17
Definition KeyCodes.h:112
@ F24
Definition KeyCodes.h:119
@ Insert
Definition KeyCodes.h:81
@ D
Definition KeyCodes.h:44
@ D6
Definition KeyCodes.h:33
@ F8
Definition KeyCodes.h:103
@ F15
Definition KeyCodes.h:110
@ RightSuper
Definition KeyCodes.h:149
@ Right
Definition KeyCodes.h:83
@ ScrollLock
Definition KeyCodes.h:92
@ KP_3
Definition KeyCodes.h:126
@ Semicolon
Definition KeyCodes.h:38
@ Escape
Definition KeyCodes.h:77
@ KP_2
Definition KeyCodes.h:125
@ KP_8
Definition KeyCodes.h:131
@ F1
Definition KeyCodes.h:96
@ Slash
Definition KeyCodes.h:25
@ G
Definition KeyCodes.h:47
@ F10
Definition KeyCodes.h:105
@ L
Definition KeyCodes.h:52
@ M
Definition KeyCodes.h:53
@ D7
Definition KeyCodes.h:34
@ V
Definition KeyCodes.h:62
@ T
Definition KeyCodes.h:60
@ F13
Definition KeyCodes.h:108
@ H
Definition KeyCodes.h:48
@ U
Definition KeyCodes.h:61
@ D5
Definition KeyCodes.h:32
@ Down
Definition KeyCodes.h:85
@ World2
Definition KeyCodes.h:74
@ D2
Definition KeyCodes.h:29
@ F9
Definition KeyCodes.h:104
@ Comma
Definition KeyCodes.h:22
@ Backspace
Definition KeyCodes.h:80
MouseButtonCodes
Enumeration of mouse button codes.
Definition MouseButtonCodes.h:17
@ MBC_Button4
Definition MouseButtonCodes.h:23
@ MBC_Button2
Definition MouseButtonCodes.h:21
@ MBC_Button6
Definition MouseButtonCodes.h:25
@ MBC_Button1
Definition MouseButtonCodes.h:20
@ MBC_ButtonRight
Definition MouseButtonCodes.h:30
@ MBC_ButtonLast
Definition MouseButtonCodes.h:28
@ MBC_ButtonMiddle
Definition MouseButtonCodes.h:31
@ MBC_Button3
Definition MouseButtonCodes.h:22
@ MBC_Button5
Definition MouseButtonCodes.h:24
@ MBC_Button7
Definition MouseButtonCodes.h:26
@ MBC_Button0
Definition MouseButtonCodes.h:19
@ MBC_ButtonLeft
Definition MouseButtonCodes.h:29
Definition Random.h:17
glm::vec3 RangeF3(float min, float max)
Definition Random.h:129
glm::vec3 Float3()
Definition Random.h:124
glm::vec2 RangeF2(float min1, float max1, float min2, float max2)
Definition Random.h:113
float RangeF1(float min, float max)
Definition Random.h:87
glm::vec3 RangeF3(const glm::vec2 &range1, const glm::vec2 &range2, const glm::vec2 &range3)
Definition Random.h:139
std::string String(size_t length)
Definition Random.h:46
glm::vec2 Float2()
Definition Random.h:103
std::mt19937 & GetRNG()
Definition Random.h:19
uint32_t UInt1(uint32_t max)
Definition Random.h:28
bool Bool1(float trueChance)
Definition Random.h:34
glm::vec2 RangeF2(float min, float max)
Definition Random.h:108
std::string HexString(size_t length)
Definition Random.h:60
void Seed(uint32_t seed)
Definition Random.h:24
glm::vec3 RangeF3(float min1, float max1, float min2, float max2, float min3, float max3)
Definition Random.h:134
float Float1()
Definition Random.h:79
unsigned char Char()
Definition Random.h:40
float RangeF1_Inclusive(float min, float max)
Definition Random.h:95
glm::vec4 Float4()
Definition Random.h:144
std::string UUID()
Definition Random.h:73
glm::vec2 RangeF2(const glm::vec2 &minRange, const glm::vec2 &maxRange)
Definition Random.h:118
glm::vec4 RangeF4(float min, float max)
Definition Random.h:149
The main namespace for the Muto engine.
Definition Application.cpp:15
float LifeRemaining
Definition ParticleSystem.h:36
float SizeVariation
Definition ParticleSystem.h:21
float SizeBegin
Definition ParticleSystem.h:19
uint32_t Height
Definition Framebuffer.h:15
glm::vec4 ColorBegin
Definition ParticleSystem.h:32
glm::vec3 Position
Definition ParticleSystem.h:13
float Lifetime
Definition ParticleSystem.h:35
float SizeEnd
Definition ParticleSystem.h:33
float RotationVariation
Definition ParticleSystem.h:23
float Lifetime
Definition ParticleSystem.h:24
glm::vec3 Velocity
Definition ParticleSystem.h:31
uint32_t Width
Definition Framebuffer.h:15
float Rotation
Definition ParticleSystem.h:34
glm::vec4 ColorEnd
Definition ParticleSystem.h:18
glm::vec3 VelocityVariation
Definition ParticleSystem.h:16
bool Active
Definition ParticleSystem.h:37
glm::vec4 ColorBegin
Definition ParticleSystem.h:17
glm::vec4 ColorEnd
Definition ParticleSystem.h:32
glm::vec3 PositionVariation
Definition ParticleSystem.h:14
float SizeBegin
Definition ParticleSystem.h:33
float LifetimeVariation
Definition ParticleSystem.h:25
float Rotation
Definition ParticleSystem.h:22
glm::vec3 Velocity
Definition ParticleSystem.h:15
glm::vec3 Position
Definition ParticleSystem.h:30
float SizeEnd
Definition ParticleSystem.h:20
Specification for creating a Framebuffer.
Definition Framebuffer.h:14
Definition ParticleSystem.h:29
Definition ParticleSystem.h:12
Component that holds camera data.
Definition Components.h:225
CameraComponent(const CameraComponent &)=default
bool Primary
Whether this camera is the primary camera.
Definition Components.h:232
bool FixedAspectRatio
Whether the aspect ratio is fixed.
Definition Components.h:235
SceneCamera Camera
The scene camera.
Definition Components.h:227
Component that holds the name of an entity.
Definition Components.h:52
NameComponent(const NameComponent &)=default
NameComponent()=default
std::string Name
The name of the owning entity.
Definition Components.h:54
operator const std::string &() const
Definition Components.h:62
std::string & GetName()
Definition Components.h:63
operator std::string &()
Definition Components.h:61
NameComponent(const std::string &name)
Definition Components.h:58
Component that holds scripting data for an entity.
Definition Components.h:248
void(* DestroyScript)(NativeScriptComponent *)
Function pointer to destroy the script.
Definition Components.h:255
ScriptableEntity * Instance
Pointer to the instance of the scriptable entity.
Definition Components.h:250
void Bind()
Binds a script type to this component.
Definition Components.h:261
Definition Components.h:270
ParticleSystemComponent(const int maxParticles)
Definition Components.h:275
ParticleSystemComponent(const ParticleSystemComponent &)=default
ParticleSystem System
Definition Components.h:271
2D Renderer Statistics
Definition Renderer2D.h:210
uint32_t GetTotalIndexCount()
Calculates the total number of indices drawn.
Definition Renderer2D.h:218
uint32_t GetTotalVertexCount()
Calculates the total number of vertices drawn.
Definition Renderer2D.h:216
uint32_t QuadCount
The number of quads being drawn.
Definition Renderer2D.h:214
uint32_t DrawCalls
The number of draw calls being made.
Definition Renderer2D.h:212
Component that holds sprite rendering data.
Definition Components.h:96
SpriteRendererComponent(const SpriteRendererComponent &)=default
SpriteRendererComponent(const glm::vec4 &color)
Constructor that initializes the color.
Definition Components.h:107
Ref< Texture2D > Texture
Texture of the sprite.
Definition Components.h:100
bool Billboard
whether the sprite should always face the camera
Definition Components.h:123
glm::vec4 Color
Color of the sprite.
Definition Components.h:98
float TilingFactor
Tiling factor for the texture.
Definition Components.h:102
Component that holds sub-texture data for sprites.
Definition Components.h:128
SubTextureComponent(const Ref< Texture2D > &texture)
Constructor that initializes the sub-texture from a full texture.
Definition Components.h:140
void SetTexture(const Ref< Texture2D > &texture)
Copy constructor.
Definition Components.h:148
Ref< SubTexture2D > SubTexture
The sub-texture reference.
Definition Components.h:130
glm::vec2 TilingFactor
Tiling factor for the sub-texture.
Definition Components.h:132
void SetTilingFactor(const glm::vec2 &tiling)
Sets the tiling factor for the sub-texture.
Definition Components.h:153
void SetOffset(const glm::vec2 &offset)
Sets the offset for the sub-texture.
Definition Components.h:158
glm::vec2 Offset
Offset for the sub-texture.
Definition Components.h:134
Animates through a series of sub textures.
Definition Components.h:171
int CurrentFrame
The current frame index.
Definition Components.h:175
TextureAnimationComponent(const std::vector< Ref< SubTexture2D > > &subTextures, float frameTime)
Constructor that initializes the sub-textures and frame time.
Definition Components.h:190
bool IsLooping
Definition Components.h:181
TextureAnimationComponent(const TextureAnimationComponent &)=default
float FrameTime
Time per frame in seconds.
Definition Components.h:177
float TimeAccumulator
Accumulated time for frame switching.
Definition Components.h:179
std::vector< Ref< SubTexture2D > > SubTextures
The list of sub-textures for the animation.
Definition Components.h:173
Component that holds the transform of an entity.
Definition Components.h:68
glm::vec3 Translation
Translation (position) vector.
Definition Components.h:70
glm::vec3 Scale
Scale vector.
Definition Components.h:74
glm::mat4 GetTransform() const
Calculates and returns the transformation matrix.
Definition Components.h:84
TransformComponent(const glm::vec3 &translation)
Constructor that initializes the translation with a 3D vector.
Definition Components.h:79
glm::vec3 Rotation
Rotation vector (in radians).
Definition Components.h:72
TransformComponent(const TransformComponent &)=default
Component that holds a UUID.
Definition Components.h:36
UUID ID
The UUID of the owning entity.
Definition Components.h:38
UUIDComponent(const std::string &id)
Definition Components.h:44
UUIDComponent(const UUIDComponent &)=default
UUIDComponent()
Definition Components.h:40
Universally Unique Identifier.
Definition Components.h:23
UUID()
Definition Components.h:27
UUID(const std::string &id)
Definition Components.h:28
operator std::string &()
Definition Components.h:31
operator const std::string &() const
Definition Components.h:32
std::string ID
The string representation of the UUID.
Definition Components.h:25