yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
irenderer.h
Go to the documentation of this file.
1#pragma once
2
4
5// Undef C math macros that can be defined by /usr/local/include/math.h (e.g.
6// Homebrew on macOS). They conflict with libc++ __math/traits.h when <memory>
7// or other C++ headers use these identifiers. Must run after sdl_compat (SDL
8// can pull in C math) and before any C++ stdlib includes.
9#ifdef isfinite
10#undef isfinite
11#endif
12#ifdef isinf
13#undef isinf
14#endif
15#ifdef isnan
16#undef isnan
17#endif
18#ifdef isnormal
19#undef isnormal
20#endif
21#ifdef signbit
22#undef signbit
23#endif
24
25#include <memory>
26#include <vector>
27
28// Forward declarations prevent circular dependencies and speed up compilation.
29// Instead of including the full header, we just tell the compiler that these
30// types exist.
31namespace yaze {
32namespace gfx {
33class Bitmap;
34}
35} // namespace yaze
36
37namespace yaze {
38namespace gfx {
39
47using TextureHandle = void*;
48
60class IRenderer {
61 public:
62 virtual ~IRenderer() = default;
63
64 // --- Initialization and Lifecycle ---
65
71 virtual bool Initialize(SDL_Window* window) = 0;
72
76 virtual void Shutdown() = 0;
77
78 // --- Texture Management ---
79
87 virtual TextureHandle CreateTexture(int width, int height) = 0;
88
99 virtual TextureHandle CreateTextureWithFormat(int width, int height,
100 uint32_t format,
101 int access) = 0;
102
108 virtual void UpdateTexture(TextureHandle texture, const Bitmap& bitmap) = 0;
109
114 virtual void DestroyTexture(TextureHandle texture) = 0;
115
116 // --- Direct Pixel Access ---
117 virtual bool LockTexture(TextureHandle texture, SDL_Rect* rect, void** pixels,
118 int* pitch) = 0;
119 virtual void UnlockTexture(TextureHandle texture) = 0;
120
121 // --- Rendering Primitives ---
122
126 virtual void Clear() = 0;
127
132 virtual void Present() = 0;
133
142 virtual void RenderCopy(TextureHandle texture, const SDL_Rect* srcrect,
143 const SDL_Rect* dstrect) = 0;
144
150 virtual void SetRenderTarget(TextureHandle texture) = 0;
151
156 virtual void SetDrawColor(SDL_Color color) = 0;
157
158 // --- Backend-specific Access ---
159
171 virtual void* GetBackendRenderer() = 0;
172};
173
174} // namespace gfx
175} // namespace yaze
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
virtual void UnlockTexture(TextureHandle texture)=0
virtual TextureHandle CreateTexture(int width, int height)=0
Creates a new, empty texture.
virtual bool Initialize(SDL_Window *window)=0
Initializes the renderer with a given window.
virtual void * GetBackendRenderer()=0
Provides an escape hatch to get the underlying, concrete renderer object.
virtual void UpdateTexture(TextureHandle texture, const Bitmap &bitmap)=0
Updates a texture with the pixel data from a Bitmap.
virtual bool LockTexture(TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch)=0
virtual ~IRenderer()=default
virtual void RenderCopy(TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)=0
Copies a portion of a texture to the current render target.
virtual void SetDrawColor(SDL_Color color)=0
Sets the color used for drawing operations (e.g., Clear).
virtual void Shutdown()=0
Shuts down the renderer and releases all associated resources.
virtual void Present()=0
Presents the back buffer to the screen, making the rendered content visible.
virtual void Clear()=0
Clears the entire render target with the current draw color.
virtual void DestroyTexture(TextureHandle texture)=0
Destroys a texture and frees its associated resources.
virtual TextureHandle CreateTextureWithFormat(int width, int height, uint32_t format, int access)=0
Creates a new texture with a specific pixel format.
virtual void SetRenderTarget(TextureHandle texture)=0
Sets the render target for subsequent drawing operations.
void * TextureHandle
An abstract handle representing a texture.
Definition irenderer.h:47
SDL2/SDL3 compatibility layer.