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 | CreateRenderTargetTexture (int width, int height) override |
| Creates a texture intended to be used as a render target. | |
| 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*. | |
Public Member Functions inherited from yaze::gfx::IRenderer | |
| 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 12 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 21 of file sdl2_renderer.cc.
References yaze::platform::CreateRenderer(), renderer_, and yaze::platform::SetRenderVSync().

|
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 45 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 54 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Creates a texture intended to be used as a render target.
| width | The width of the texture in pixels. |
| height | The height of the texture in pixels. |
Implements yaze::gfx::IRenderer.
Definition at line 69 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 85 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 97 of file sdl2_renderer.cc.
References yaze::platform::ConvertSurfaceFormat(), and yaze::gfx::Bitmap::surface().

|
overridevirtual |
Destroys an SDL_Texture.
Implements yaze::gfx::IRenderer.
Definition at line 128 of file sdl2_renderer.cc.
|
overridevirtual |
Implements yaze::gfx::IRenderer.
Definition at line 134 of file sdl2_renderer.cc.
|
overridevirtual |
Implements yaze::gfx::IRenderer.
Definition at line 140 of file sdl2_renderer.cc.
|
overridevirtual |
Clears the screen with the current draw color.
Implements yaze::gfx::IRenderer.
Definition at line 147 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Presents the rendered frame to the screen.
Implements yaze::gfx::IRenderer.
Definition at line 154 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Copies a texture to the render target.
Implements yaze::gfx::IRenderer.
Definition at line 161 of file sdl2_renderer.cc.
References renderer_, and yaze::platform::RenderTexture().

|
overridevirtual |
Sets the render target.
Implements yaze::gfx::IRenderer.
Definition at line 170 of file sdl2_renderer.cc.
References renderer_.
|
overridevirtual |
Sets the draw color.
Implements yaze::gfx::IRenderer.
Definition at line 177 of file sdl2_renderer.cc.
References renderer_.
|
inlineoverridevirtual |
Provides access to the underlying SDL_Renderer*.
Implements yaze::gfx::IRenderer.
Definition at line 52 of file sdl2_renderer.h.
References renderer_.
|
private |
Definition at line 57 of file sdl2_renderer.h.
Referenced by Clear(), CreateRenderTargetTexture(), CreateTexture(), CreateTextureWithFormat(), GetBackendRenderer(), Initialize(), Present(), RenderCopy(), SetDrawColor(), SetRenderTarget(), and Shutdown().