summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/render/SDL_sysrender.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/render/SDL_sysrender.h
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/render/SDL_sysrender.h')
-rw-r--r--contrib/SDL-3.2.8/src/render/SDL_sysrender.h372
1 files changed, 372 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/render/SDL_sysrender.h b/contrib/SDL-3.2.8/src/render/SDL_sysrender.h
new file mode 100644
index 0000000..9d39dfd
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/render/SDL_sysrender.h
@@ -0,0 +1,372 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifndef SDL_sysrender_h_
24#define SDL_sysrender_h_
25
26#include "../video/SDL_surface_c.h"
27
28#include "SDL_yuv_sw_c.h"
29
30// Set up for C function definitions, even when using C++
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35typedef enum SDL_TextureAddressMode
36{
37 SDL_TEXTURE_ADDRESS_AUTO,
38 SDL_TEXTURE_ADDRESS_CLAMP,
39 SDL_TEXTURE_ADDRESS_WRAP,
40} SDL_TextureAddressMode;
41
42/**
43 * A rectangle, with the origin at the upper left (double precision).
44 */
45typedef struct SDL_DRect
46{
47 double x;
48 double y;
49 double w;
50 double h;
51} SDL_DRect;
52
53// The SDL 2D rendering system
54
55typedef struct SDL_RenderDriver SDL_RenderDriver;
56
57// Rendering view state
58typedef struct SDL_RenderViewState
59{
60 int pixel_w;
61 int pixel_h;
62 SDL_Rect viewport;
63 SDL_Rect pixel_viewport;
64 SDL_Rect clip_rect;
65 SDL_Rect pixel_clip_rect;
66 bool clipping_enabled;
67 SDL_FPoint scale;
68
69 // Support for logical output coordinates
70 SDL_RendererLogicalPresentation logical_presentation_mode;
71 int logical_w, logical_h;
72 SDL_FRect logical_src_rect;
73 SDL_FRect logical_dst_rect;
74 SDL_FPoint logical_scale;
75 SDL_FPoint logical_offset;
76
77 SDL_FPoint current_scale; // this is just `scale * logical_scale`, precalculated, since we use it a lot.
78} SDL_RenderViewState;
79
80// Define the SDL texture structure
81struct SDL_Texture
82{
83 // Public API definition
84 SDL_PixelFormat format; /**< The format of the texture, read-only */
85 int w; /**< The width of the texture, read-only. */
86 int h; /**< The height of the texture, read-only. */
87
88 int refcount; /**< Application reference count, used when freeing texture */
89
90 // Private API definition
91 SDL_Colorspace colorspace; // The colorspace of the texture
92 float SDR_white_point; // The SDR white point for this content
93 float HDR_headroom; // The HDR headroom needed by this content
94 SDL_TextureAccess access; // The texture access mode
95 SDL_BlendMode blendMode; // The texture blend mode
96 SDL_ScaleMode scaleMode; // The texture scale mode
97 SDL_FColor color; // Texture modulation values
98 SDL_RenderViewState view; // Target texture view state
99
100 SDL_Renderer *renderer;
101
102 // Support for formats not supported directly by the renderer
103 SDL_Texture *native;
104 SDL_SW_YUVTexture *yuv;
105 void *pixels;
106 int pitch;
107 SDL_Rect locked_rect;
108 SDL_Surface *locked_surface; // Locked region exposed as a SDL surface
109
110 Uint32 last_command_generation; // last command queue generation this texture was in.
111
112 SDL_PropertiesID props;
113
114 void *internal; // Driver specific texture representation
115
116 SDL_Texture *prev;
117 SDL_Texture *next;
118};
119
120typedef enum
121{
122 SDL_RENDERCMD_NO_OP,
123 SDL_RENDERCMD_SETVIEWPORT,
124 SDL_RENDERCMD_SETCLIPRECT,
125 SDL_RENDERCMD_SETDRAWCOLOR,
126 SDL_RENDERCMD_CLEAR,
127 SDL_RENDERCMD_DRAW_POINTS,
128 SDL_RENDERCMD_DRAW_LINES,
129 SDL_RENDERCMD_FILL_RECTS,
130 SDL_RENDERCMD_COPY,
131 SDL_RENDERCMD_COPY_EX,
132 SDL_RENDERCMD_GEOMETRY
133} SDL_RenderCommandType;
134
135typedef struct SDL_RenderCommand
136{
137 SDL_RenderCommandType command;
138 union
139 {
140 struct
141 {
142 size_t first;
143 SDL_Rect rect;
144 } viewport;
145 struct
146 {
147 bool enabled;
148 SDL_Rect rect;
149 } cliprect;
150 struct
151 {
152 size_t first;
153 size_t count;
154 float color_scale;
155 SDL_FColor color;
156 SDL_BlendMode blend;
157 SDL_Texture *texture;
158 SDL_TextureAddressMode texture_address_mode;
159 } draw;
160 struct
161 {
162 size_t first;
163 float color_scale;
164 SDL_FColor color;
165 } color;
166 } data;
167 struct SDL_RenderCommand *next;
168} SDL_RenderCommand;
169
170typedef struct SDL_VertexSolid
171{
172 SDL_FPoint position;
173 SDL_FColor color;
174} SDL_VertexSolid;
175
176typedef enum
177{
178 SDL_RENDERLINEMETHOD_POINTS,
179 SDL_RENDERLINEMETHOD_LINES,
180 SDL_RENDERLINEMETHOD_GEOMETRY,
181} SDL_RenderLineMethod;
182
183// Define the SDL renderer structure
184struct SDL_Renderer
185{
186 void (*WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event);
187 bool (*GetOutputSize)(SDL_Renderer *renderer, int *w, int *h);
188 bool (*SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode);
189 bool (*CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props);
190 bool (*QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd);
191 bool (*QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd);
192 bool (*QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points,
193 int count);
194 bool (*QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points,
195 int count);
196 bool (*QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects,
197 int count);
198 bool (*QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
199 const SDL_FRect *srcrect, const SDL_FRect *dstrect);
200 bool (*QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
201 const SDL_FRect *srcquad, const SDL_FRect *dstrect,
202 const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y);
203 bool (*QueueGeometry)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
204 const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride,
205 int num_vertices, const void *indices, int num_indices, int size_indices,
206 float scale_x, float scale_y);
207
208 void (*InvalidateCachedState)(SDL_Renderer *renderer);
209 bool (*RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
210 bool (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
211 const SDL_Rect *rect, const void *pixels,
212 int pitch);
213#ifdef SDL_HAVE_YUV
214 bool (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture,
215 const SDL_Rect *rect,
216 const Uint8 *Yplane, int Ypitch,
217 const Uint8 *Uplane, int Upitch,
218 const Uint8 *Vplane, int Vpitch);
219 bool (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture,
220 const SDL_Rect *rect,
221 const Uint8 *Yplane, int Ypitch,
222 const Uint8 *UVplane, int UVpitch);
223#endif
224 bool (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
225 const SDL_Rect *rect, void **pixels, int *pitch);
226 void (*UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
227 void (*SetTextureScaleMode)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode);
228 bool (*SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture);
229 SDL_Surface *(*RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect);
230 bool (*RenderPresent)(SDL_Renderer *renderer);
231 void (*DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
232
233 void (*DestroyRenderer)(SDL_Renderer *renderer);
234
235 bool (*SetVSync)(SDL_Renderer *renderer, int vsync);
236
237 void *(*GetMetalLayer)(SDL_Renderer *renderer);
238 void *(*GetMetalCommandEncoder)(SDL_Renderer *renderer);
239
240 bool (*AddVulkanRenderSemaphores)(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore);
241
242 // The current renderer info
243 const char *name;
244 SDL_PixelFormat *texture_formats;
245 int num_texture_formats;
246 bool software;
247
248 // The window associated with the renderer
249 SDL_Window *window;
250 bool hidden;
251
252 // Whether we should simulate vsync
253 bool wanted_vsync;
254 bool simulate_vsync;
255 Uint64 simulate_vsync_interval_ns;
256 Uint64 last_present;
257
258 SDL_RenderViewState *view;
259 SDL_RenderViewState main_view;
260
261 // The window pixel to point coordinate scale
262 SDL_FPoint dpi_scale;
263
264 // The method of drawing lines
265 SDL_RenderLineMethod line_method;
266
267 // The list of textures
268 SDL_Texture *textures;
269 SDL_Texture *target;
270 SDL_Mutex *target_mutex;
271
272 SDL_Colorspace output_colorspace;
273 float SDR_white_point;
274 float HDR_headroom;
275
276 float desired_color_scale;
277 float color_scale;
278 SDL_FColor color; /**< Color for drawing operations values */
279 SDL_BlendMode blendMode; /**< The drawing blend mode */
280 SDL_TextureAddressMode texture_address_mode;
281
282 SDL_RenderCommand *render_commands;
283 SDL_RenderCommand *render_commands_tail;
284 SDL_RenderCommand *render_commands_pool;
285 Uint32 render_command_generation;
286 SDL_FColor last_queued_color;
287 float last_queued_color_scale;
288 SDL_Rect last_queued_viewport;
289 SDL_Rect last_queued_cliprect;
290 bool last_queued_cliprect_enabled;
291 bool color_queued;
292 bool viewport_queued;
293 bool cliprect_queued;
294
295 void *vertex_data;
296 size_t vertex_data_used;
297 size_t vertex_data_allocation;
298
299 // Shaped window support
300 bool transparent_window;
301 SDL_Surface *shape_surface;
302 SDL_Texture *shape_texture;
303
304 SDL_PropertiesID props;
305
306 SDL_Texture *debug_char_texture_atlas;
307
308 bool destroyed; // already destroyed by SDL_DestroyWindow; just free this struct in SDL_DestroyRenderer.
309
310 void *internal;
311
312 SDL_Renderer *next;
313};
314
315// Define the SDL render driver structure
316struct SDL_RenderDriver
317{
318 bool (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID props);
319
320 const char *name;
321};
322
323// Not all of these are available in a given build. Use #ifdefs, etc.
324extern SDL_RenderDriver D3D_RenderDriver;
325extern SDL_RenderDriver D3D11_RenderDriver;
326extern SDL_RenderDriver D3D12_RenderDriver;
327extern SDL_RenderDriver GL_RenderDriver;
328extern SDL_RenderDriver GLES2_RenderDriver;
329extern SDL_RenderDriver METAL_RenderDriver;
330extern SDL_RenderDriver VULKAN_RenderDriver;
331extern SDL_RenderDriver PS2_RenderDriver;
332extern SDL_RenderDriver PSP_RenderDriver;
333extern SDL_RenderDriver SW_RenderDriver;
334extern SDL_RenderDriver VITA_GXM_RenderDriver;
335extern SDL_RenderDriver GPU_RenderDriver;
336
337// Clean up any renderers at shutdown
338extern void SDL_QuitRender(void);
339
340// Add a supported texture format to a renderer
341extern bool SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format);
342
343// Setup colorspace conversion
344extern void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props);
345
346// Colorspace conversion functions
347extern bool SDL_RenderingLinearSpace(SDL_Renderer *renderer);
348extern void SDL_ConvertToLinear(SDL_FColor *color);
349extern void SDL_ConvertFromLinear(SDL_FColor *color);
350
351// Blend mode functions
352extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
353extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
354extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
355extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
356extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
357extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
358
359/* drivers call this during their Queue*() methods to make space in a array that are used
360 for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until
361 the next call, because it might be in an array that gets realloc()'d. */
362extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, size_t numbytes, size_t alignment, size_t *offset);
363
364// Let the video subsystem destroy a renderer without making its pointer invalid.
365extern void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer);
366
367// Ends C function definitions when using C++
368#ifdef __cplusplus
369}
370#endif
371
372#endif // SDL_sysrender_h_