yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sdl2_renderer.h
Go to the documentation of this file.
1#pragma once
2
4#include "util/sdl_deleter.h"
5
6namespace yaze {
7namespace gfx {
8
18class SDL2Renderer : public IRenderer {
19public:
21 ~SDL2Renderer() override;
22
23 // --- Lifecycle and Initialization ---
24 bool Initialize(SDL_Window* window) override;
25 void Shutdown() override;
26
27 // --- Texture Management ---
28 TextureHandle CreateTexture(int width, int height) override;
29 TextureHandle CreateTextureWithFormat(int width, int height, uint32_t format, int access) override;
30 void UpdateTexture(TextureHandle texture, const Bitmap& bitmap) override;
31 void DestroyTexture(TextureHandle texture) override;
32
33 // --- Direct Pixel Access ---
34 bool LockTexture(TextureHandle texture, SDL_Rect* rect, void** pixels, int* pitch) override;
35 void UnlockTexture(TextureHandle texture) override;
36
37 // --- Rendering Primitives ---
38 void Clear() override;
39 void Present() override;
40 void RenderCopy(TextureHandle texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect) override;
41 void SetRenderTarget(TextureHandle texture) override;
42 void SetDrawColor(SDL_Color color) override;
43
48 void* GetBackendRenderer() override { return renderer_.get(); }
49
50private:
51 // The core SDL2 renderer object, managed by a unique_ptr with a custom deleter.
52 std::unique_ptr<SDL_Renderer, util::SDL_Deleter> renderer_;
53};
54
55} // namespace gfx
56} // namespace yaze
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
Defines an abstract interface for all rendering operations.
Definition irenderer.h:35
A concrete implementation of the IRenderer interface using SDL2.
void SetDrawColor(SDL_Color color) override
Sets the draw color.
std::unique_ptr< SDL_Renderer, util::SDL_Deleter > renderer_
bool Initialize(SDL_Window *window) override
Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to ...
void DestroyTexture(TextureHandle texture) override
Destroys an SDL_Texture.
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 ...
void SetRenderTarget(TextureHandle texture) override
Sets the render target.
void * GetBackendRenderer() override
Provides access to the underlying SDL_Renderer*.
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 specialize...
TextureHandle CreateTexture(int width, int height) override
Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures ...
bool LockTexture(TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch) override
void UnlockTexture(TextureHandle texture) override
void Present() override
Presents the rendered frame to the screen.
void Clear() override
Clears the screen with the current draw color.
void Shutdown() override
Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction i...
void RenderCopy(TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) override
Copies a texture to the render target.
void * TextureHandle
An abstract handle representing a texture.
Definition irenderer.h:24
Main namespace for the application.