A concrete implementation of the IRenderer interface using SDL2. More...
#include <sdl2_renderer.h>
Public Member Functions | |
SDL2Renderer () | |
~SDL2Renderer () override | |
bool | Initialize (SDL_Window *window) override |
Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to the given window. | |
void | Shutdown () override |
Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction is handled automatically. | |
TextureHandle | CreateTexture (int width, int height) override |
Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures that are updated frequently. | |
TextureHandle | CreateTextureWithFormat (int width, int height, uint32_t format, int access) override |
Creates an SDL_Texture with a specific pixel format and access pattern. This is useful for specialized textures like emulator PPU output. | |
void | UpdateTexture (TextureHandle texture, const Bitmap &bitmap) override |
Updates an SDL_Texture with data from a Bitmap. This involves converting the bitmap's surface to the correct format and updating the texture. | |
void | DestroyTexture (TextureHandle texture) override |
Destroys an SDL_Texture. | |
bool | LockTexture (TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch) override |
void | UnlockTexture (TextureHandle texture) override |
void | Clear () override |
Clears the screen with the current draw color. | |
void | Present () override |
Presents the rendered frame to the screen. | |
void | RenderCopy (TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) override |
Copies a texture to the render target. | |
void | SetRenderTarget (TextureHandle texture) override |
Sets the render target. | |
void | SetDrawColor (SDL_Color color) override |
Sets the draw color. | |
void * | GetBackendRenderer () override |
Provides access to the underlying SDL_Renderer*. | |
![]() | |
virtual | ~IRenderer ()=default |
Private Attributes | |
std::unique_ptr< SDL_Renderer, util::SDL_Deleter > | renderer_ |
A concrete implementation of the IRenderer interface using SDL2.
This class encapsulates all rendering logic that is specific to the SDL2_render API. It translates the abstract calls from the IRenderer interface into concrete SDL2 commands. This is the first step in abstracting the renderer, allowing the rest of the application to be independent of SDL2.
Definition at line 18 of file sdl2_renderer.h.
|
default |
|
override |
Definition at line 10 of file sdl2_renderer.cc.
References Shutdown().
|
overridevirtual |
Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to the given window.
Implements yaze::gfx::IRenderer.
Definition at line 18 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction is handled automatically.
Implements yaze::gfx::IRenderer.
Definition at line 38 of file sdl2_renderer.cc.
References renderer_.
Referenced by ~SDL2Renderer().
|
overridevirtual |
Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures that are updated frequently.
Implements yaze::gfx::IRenderer.
Definition at line 46 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Creates an SDL_Texture with a specific pixel format and access pattern. This is useful for specialized textures like emulator PPU output.
Implements yaze::gfx::IRenderer.
Definition at line 57 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Updates an SDL_Texture with data from a Bitmap. This involves converting the bitmap's surface to the correct format and updating the texture.
Implements yaze::gfx::IRenderer.
Definition at line 67 of file sdl2_renderer.cc.
References yaze::gfx::Bitmap::surface().
|
overridevirtual |
Destroys an SDL_Texture.
Implements yaze::gfx::IRenderer.
Definition at line 95 of file sdl2_renderer.cc.
|
overridevirtual |
Implements yaze::gfx::IRenderer.
Definition at line 101 of file sdl2_renderer.cc.
|
overridevirtual |
Implements yaze::gfx::IRenderer.
Definition at line 105 of file sdl2_renderer.cc.
|
overridevirtual |
Clears the screen with the current draw color.
Implements yaze::gfx::IRenderer.
Definition at line 112 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Presents the rendered frame to the screen.
Implements yaze::gfx::IRenderer.
Definition at line 119 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Copies a texture to the render target.
Implements yaze::gfx::IRenderer.
Definition at line 126 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Sets the render target.
Implements yaze::gfx::IRenderer.
Definition at line 133 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Sets the draw color.
Implements yaze::gfx::IRenderer.
Definition at line 140 of file sdl2_renderer.cc.
References renderer_.
|
inlineoverridevirtual |
Provides access to the underlying SDL_Renderer*.
Implements yaze::gfx::IRenderer.
Definition at line 48 of file sdl2_renderer.h.
References renderer_.
|
private |
Definition at line 52 of file sdl2_renderer.h.
Referenced by Clear(), CreateTexture(), CreateTextureWithFormat(), GetBackendRenderer(), Initialize(), Present(), RenderCopy(), SetDrawColor(), SetRenderTarget(), and Shutdown().