MochiEngine
Loading...
Searching...
No Matches
Mochi::Graphics::SDLRenderer Class Reference

This class allows rendering with SDL3 in "the simple way", that is showing textures with SDL_RenderTexture instead of using the GPU module. More...

#include <SDLRenderer.h>

Inheritance diagram for Mochi::Graphics::SDLRenderer:
Mochi::Graphics::IRenderer

Public Member Functions

 SDLRenderer (const char *appName, const char *appVersion, const char *appId, const char *windowName)
 Initializes the renderer and window for the application, setting the necessary metadata for the game to work.
SDL_Renderer * GetRenderer () const
SDL_Window * GetWindow () const
virtual void StartFrameRendering () const override
 Called before rendering anything. Sets a render color and clears the window.
virtual void Render (std::vector< RenderCommand > renderQueue, Camera *camera) const override
 Orders the textures by zindex and renders them on screen depending on the camera position.
virtual void FinishRendering () const override
 Present the screen.
virtual std::unique_ptr< AbstractTextureFactoryCreateTextureFactory (FS::PackCatalog *catalog) const
 Creates (without ownership) a texture factory of the type compatible with the renderer.
virtual std::unique_ptr< AbstractGUICreateGUI (FS::PackCatalog *catalog, Input::IActionManager *actionManager)
 Creates (without ownership) the GUI system compatible with the renderer.
virtual std::unique_ptr< Debug::IGizmosCreateGizmos ()
 Creates (without ownership) a gizmos system compatible with the renderer. This system is only relevant on debug mode.

Detailed Description

This class allows rendering with SDL3 in "the simple way", that is showing textures with SDL_RenderTexture instead of using the GPU module.

Remarks
Do not mistake SDLRenderer (this) and SDL_Renderer (renderer struct used by SDL internally).

Besides that, SDLRenderer is responsible for creating AbstractTextureFactory of the type SDLTextureFactory that generates SDLTexture and AbstractGUI of the type SDLGUI.

Ownership:

  • The SDL_Renderer as a unique pointer
  • The application window as a unique pointer

Guarantees:

  • A clean frame generation if StartFrameRendering, Render and FinishRendering are called in order.
  • That the factories generate textures that can be used by SDLRenderer.
  • That the GUI system uses the SDLRenderer for showing textures.
  • That a single SDL_Renderer and SDL_Window will be created and disposed when destroying the SDLRenderer.

Constructor & Destructor Documentation

◆ SDLRenderer()

Mochi::Graphics::SDLRenderer::SDLRenderer ( const char * appName,
const char * appVersion,
const char * appId,
const char * windowName )

Initializes the renderer and window for the application, setting the necessary metadata for the game to work.

Parameters
appNameName of the application.
appVersionVersion of the application.
appIdUnique string defined as a reverse id used to identify the application.
windowNameThe name that will show on the top of the window.

Member Function Documentation

◆ CreateGizmos()

std::unique_ptr< Debug::IGizmos > Mochi::Graphics::SDLRenderer::CreateGizmos ( )
virtual

Creates (without ownership) a gizmos system compatible with the renderer. This system is only relevant on debug mode.

Returns
A unique pointer to the created gizmos system.

Implements Mochi::Graphics::IRenderer.

◆ CreateGUI()

std::unique_ptr< AbstractGUI > Mochi::Graphics::SDLRenderer::CreateGUI ( FS::PackCatalog * catalog,
Input::IActionManager * actionManager )
virtual

Creates (without ownership) the GUI system compatible with the renderer.

Parameters
catalogThe file catalog used for the GUI system to load files from.
actionManagerThe action manager, used to manage UI interactions.
Returns
A unique pointer to the created gui system.

Implements Mochi::Graphics::IRenderer.

◆ CreateTextureFactory()

std::unique_ptr< AbstractTextureFactory > Mochi::Graphics::SDLRenderer::CreateTextureFactory ( FS::PackCatalog * catalog) const
virtual

Creates (without ownership) a texture factory of the type compatible with the renderer.

Parameters
catalogThe file catalog used for the factory to load files from.
Returns
A unique pointer to the created texture factory.

Implements Mochi::Graphics::IRenderer.

◆ FinishRendering()

void Mochi::Graphics::SDLRenderer::FinishRendering ( ) const
overridevirtual

Present the screen.

Implements Mochi::Graphics::IRenderer.

◆ Render()

void Mochi::Graphics::SDLRenderer::Render ( std::vector< RenderCommand > renderQueue,
Camera * camera ) const
overridevirtual

Orders the textures by zindex and renders them on screen depending on the camera position.

As this renderer knows that every texture coming in the renderQueue is an SDLTexture, it performs

Parameters
renderQueueList of render commands to render.
cameraThe camera on which to project the render.

Implements Mochi::Graphics::IRenderer.

◆ StartFrameRendering()

void Mochi::Graphics::SDLRenderer::StartFrameRendering ( ) const
overridevirtual

Called before rendering anything. Sets a render color and clears the window.

Implements Mochi::Graphics::IRenderer.


The documentation for this class was generated from the following files:
  • Engine/src/Graphics/SDL/SDLRenderer.h
  • Engine/src/Graphics/SDL/SDLRenderer.cpp