Atlas - SDL_sysrender.h

Home / ext / SDL / src / render Lines: 1 | Size: 15353 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 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 35/** 36 * A rectangle, with the origin at the upper left (double precision). 37 */ 38typedef struct SDL_DRect 39{ 40 double x; 41 double y; 42 double w; 43 double h; 44} SDL_DRect; 45 46// The SDL 2D rendering system 47 48typedef struct SDL_RenderDriver SDL_RenderDriver; 49 50// Rendering view state 51typedef struct SDL_RenderViewState 52{ 53 int pixel_w; 54 int pixel_h; 55 SDL_Rect viewport; 56 SDL_Rect pixel_viewport; 57 SDL_Rect clip_rect; 58 SDL_Rect pixel_clip_rect; 59 bool clipping_enabled; 60 SDL_FPoint scale; 61 62 // Support for logical output coordinates 63 SDL_RendererLogicalPresentation logical_presentation_mode; 64 int logical_w, logical_h; 65 SDL_FRect logical_src_rect; 66 SDL_FRect logical_dst_rect; 67 SDL_FPoint logical_scale; 68 SDL_FPoint logical_offset; 69 70 SDL_FPoint current_scale; // this is just `scale * logical_scale`, precalculated, since we use it a lot. 71} SDL_RenderViewState; 72 73// Define the SDL texture palette structure 74typedef struct SDL_TexturePalette 75{ 76 int refcount; 77 Uint32 version; 78 Uint32 last_command_generation; // last command queue generation this palette was in. 79 void *internal; // Driver specific palette representation 80} SDL_TexturePalette; 81 82// Define the SDL texture structure 83struct SDL_Texture 84{ 85 // Public API definition 86 SDL_PixelFormat format; /**< The format of the texture, read-only */ 87 int w; /**< The width of the texture, read-only. */ 88 int h; /**< The height of the texture, read-only. */ 89 90 int refcount; /**< Application reference count, used when freeing texture */ 91 92 // Private API definition 93 SDL_Renderer *renderer; 94 SDL_Colorspace colorspace; // The colorspace of the texture 95 float SDR_white_point; // The SDR white point for this content 96 float HDR_headroom; // The HDR headroom needed by this content 97 SDL_TextureAccess access; // The texture access mode 98 SDL_BlendMode blendMode; // The texture blend mode 99 SDL_ScaleMode scaleMode; // The texture scale mode 100 SDL_FColor color; // Texture modulation values 101 SDL_RenderViewState view; // Target texture view state 102 SDL_Palette *public_palette; 103 SDL_TexturePalette *palette; 104 Uint32 palette_version; 105 SDL_Surface *palette_surface; 106 107 // Support for formats not supported directly by the renderer 108 SDL_Texture *native; 109 SDL_SW_YUVTexture *yuv; 110 void *pixels; 111 int pitch; 112 SDL_Rect locked_rect; 113 SDL_Surface *locked_surface; // Locked region exposed as a SDL surface 114 115 Uint32 last_command_generation; // last command queue generation this texture was in. 116 117 SDL_PropertiesID props; 118 119 void *internal; // Driver specific texture representation 120 121 SDL_Texture *prev; 122 SDL_Texture *next; 123}; 124 125// Define the GPU render state structure 126typedef struct SDL_GPURenderStateUniformBuffer 127{ 128 Uint32 slot_index; 129 void *data; 130 Uint32 length; 131} SDL_GPURenderStateUniformBuffer; 132 133// Define the GPU render state structure 134struct SDL_GPURenderState 135{ 136 SDL_Renderer *renderer; 137 138 Uint32 last_command_generation; // last command queue generation this state was in. 139 140 SDL_GPUShader *fragment_shader; 141 142 int num_sampler_bindings; 143 SDL_GPUTextureSamplerBinding *sampler_bindings; 144 145 int num_storage_textures; 146 SDL_GPUTexture **storage_textures; 147 148 int num_storage_buffers; 149 SDL_GPUBuffer **storage_buffers; 150 151 int num_uniform_buffers; 152 SDL_GPURenderStateUniformBuffer *uniform_buffers; 153}; 154 155typedef enum 156{ 157 SDL_RENDERCMD_NO_OP, 158 SDL_RENDERCMD_SETVIEWPORT, 159 SDL_RENDERCMD_SETCLIPRECT, 160 SDL_RENDERCMD_SETDRAWCOLOR, 161 SDL_RENDERCMD_CLEAR, 162 SDL_RENDERCMD_DRAW_POINTS, 163 SDL_RENDERCMD_DRAW_LINES, 164 SDL_RENDERCMD_FILL_RECTS, 165 SDL_RENDERCMD_COPY, 166 SDL_RENDERCMD_COPY_EX, 167 SDL_RENDERCMD_GEOMETRY 168} SDL_RenderCommandType; 169 170typedef struct SDL_RenderCommand 171{ 172 SDL_RenderCommandType command; 173 union 174 { 175 struct 176 { 177 size_t first; 178 SDL_Rect rect; 179 } viewport; 180 struct 181 { 182 bool enabled; 183 SDL_Rect rect; 184 } cliprect; 185 struct 186 { 187 size_t first; 188 size_t count; 189 float color_scale; 190 SDL_FColor color; 191 SDL_BlendMode blend; 192 SDL_Texture *texture; 193 SDL_ScaleMode texture_scale_mode; 194 SDL_TextureAddressMode texture_address_mode_u; 195 SDL_TextureAddressMode texture_address_mode_v; 196 SDL_GPURenderState *gpu_render_state; 197 } draw; 198 struct 199 { 200 size_t first; 201 float color_scale; 202 SDL_FColor color; 203 } color; 204 } data; 205 struct SDL_RenderCommand *next; 206} SDL_RenderCommand; 207 208typedef struct SDL_VertexSolid 209{ 210 SDL_FPoint position; 211 SDL_FColor color; 212} SDL_VertexSolid; 213 214typedef enum 215{ 216 SDL_RENDERLINEMETHOD_POINTS, 217 SDL_RENDERLINEMETHOD_LINES, 218 SDL_RENDERLINEMETHOD_GEOMETRY, 219} SDL_RenderLineMethod; 220 221// Define the SDL renderer structure 222struct SDL_Renderer 223{ 224 void (*WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event); 225 bool (*GetOutputSize)(SDL_Renderer *renderer, int *w, int *h); 226 bool (*SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode); 227 bool (*CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props); 228 bool (*QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); 229 bool (*QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); 230 bool (*QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, 231 int count); 232 bool (*QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, 233 int count); 234 bool (*QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, 235 int count); 236 bool (*QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, 237 const SDL_FRect *srcrect, const SDL_FRect *dstrect); 238 bool (*QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, 239 const SDL_FRect *srcquad, const SDL_FRect *dstrect, 240 const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y); 241 bool (*QueueGeometry)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, 242 const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, 243 int num_vertices, const void *indices, int num_indices, int size_indices, 244 float scale_x, float scale_y); 245 246 void (*InvalidateCachedState)(SDL_Renderer *renderer); 247 bool (*RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize); 248 bool (*CreatePalette)(SDL_Renderer *renderer, SDL_TexturePalette *palette); 249 bool (*UpdatePalette)(SDL_Renderer *renderer, SDL_TexturePalette *palette, int ncolors, SDL_Color *colors); 250 void (*DestroyPalette)(SDL_Renderer *renderer, SDL_TexturePalette *palette); 251 bool (*ChangeTexturePalette)(SDL_Renderer *renderer, SDL_Texture *texture); 252 bool (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, 253 const SDL_Rect *rect, const void *pixels, 254 int pitch); 255#ifdef SDL_HAVE_YUV 256 bool (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture, 257 const SDL_Rect *rect, 258 const Uint8 *Yplane, int Ypitch, 259 const Uint8 *Uplane, int Upitch, 260 const Uint8 *Vplane, int Vpitch); 261 bool (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture, 262 const SDL_Rect *rect, 263 const Uint8 *Yplane, int Ypitch, 264 const Uint8 *UVplane, int UVpitch); 265#endif 266 bool (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, 267 const SDL_Rect *rect, void **pixels, int *pitch); 268 void (*UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture); 269 bool (*SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture); 270 SDL_Surface *(*RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect); 271 bool (*RenderPresent)(SDL_Renderer *renderer); 272 void (*DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture); 273 274 void (*DestroyRenderer)(SDL_Renderer *renderer); 275 276 bool (*SetVSync)(SDL_Renderer *renderer, int vsync); 277 278 void *(*GetMetalLayer)(SDL_Renderer *renderer); 279 void *(*GetMetalCommandEncoder)(SDL_Renderer *renderer); 280 281 bool (*AddVulkanRenderSemaphores)(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore); 282 283#ifdef SDL_PLATFORM_GDK 284 void (*GDKSuspendRenderer)(SDL_Renderer *renderer); 285 void (*GDKResumeRenderer)(SDL_Renderer *renderer); 286#endif 287 288 // The current renderer info 289 const char *name; 290 SDL_PixelFormat *texture_formats; 291 int num_texture_formats; 292 bool software; 293 bool npot_texture_wrap_unsupported; 294 295 // The window associated with the renderer 296 SDL_Window *window; 297 bool hidden; 298 299 // Whether we should simulate vsync 300 bool wanted_vsync; 301 bool simulate_vsync; 302 Uint64 simulate_vsync_interval_ns; 303 Uint64 last_present; 304 305 SDL_RenderViewState *view; 306 SDL_RenderViewState main_view; 307 308 // The window pixel to point coordinate scale 309 SDL_FPoint dpi_scale; 310 311 // The method of drawing lines 312 SDL_RenderLineMethod line_method; 313 314 // Default scale mode for textures created with this renderer 315 SDL_ScaleMode scale_mode; 316 317 // The list of textures 318 SDL_Texture *textures; 319 SDL_Texture *target; 320 SDL_Mutex *target_mutex; 321 322 // The list of palettes 323 SDL_HashTable *palettes; 324 325 SDL_Colorspace output_colorspace; 326 float SDR_white_point; 327 float HDR_headroom; 328 329 float desired_color_scale; 330 float color_scale; 331 SDL_FColor color; /**< Color for drawing operations values */ 332 SDL_BlendMode blendMode; /**< The drawing blend mode */ 333 SDL_TextureAddressMode texture_address_mode_u; 334 SDL_TextureAddressMode texture_address_mode_v; 335 SDL_GPURenderState *gpu_render_state; 336 337 SDL_RenderCommand *render_commands; 338 SDL_RenderCommand *render_commands_tail; 339 SDL_RenderCommand *render_commands_pool; 340 Uint32 render_command_generation; 341 SDL_FColor last_queued_color; 342 float last_queued_color_scale; 343 SDL_Rect last_queued_viewport; 344 SDL_Rect last_queued_cliprect; 345 bool last_queued_cliprect_enabled; 346 bool color_queued; 347 bool viewport_queued; 348 bool cliprect_queued; 349 350 void *vertex_data; 351 size_t vertex_data_used; 352 size_t vertex_data_allocation; 353 354 // Shaped window support 355 bool transparent_window; 356 SDL_Surface *shape_surface; 357 SDL_Texture *shape_texture; 358 359 SDL_PropertiesID props; 360 361 SDL_Texture *debug_char_texture_atlas; 362 363 bool destroyed; // already destroyed by SDL_DestroyWindow; just free this struct in SDL_DestroyRenderer. 364 365 void *internal; 366 367 SDL_Renderer *next; 368}; 369 370// Define the SDL render driver structure 371struct SDL_RenderDriver 372{ 373 bool (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID props); 374 375 const char *name; 376}; 377 378// Not all of these are available in a given build. Use #ifdefs, etc. 379extern SDL_RenderDriver D3D_RenderDriver; 380extern SDL_RenderDriver D3D11_RenderDriver; 381extern SDL_RenderDriver D3D12_RenderDriver; 382extern SDL_RenderDriver GL_RenderDriver; 383extern SDL_RenderDriver GLES2_RenderDriver; 384extern SDL_RenderDriver METAL_RenderDriver; 385extern SDL_RenderDriver NGAGE_RenderDriver; 386extern SDL_RenderDriver VULKAN_RenderDriver; 387extern SDL_RenderDriver PS2_RenderDriver; 388extern SDL_RenderDriver PSP_RenderDriver; 389extern SDL_RenderDriver SW_RenderDriver; 390extern SDL_RenderDriver VITA_GXM_RenderDriver; 391extern SDL_RenderDriver GPU_RenderDriver; 392 393// Clean up any renderers at shutdown 394extern void SDL_QuitRender(void); 395 396#define RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v) \ 397 (((scale_mode == SDL_SCALEMODE_NEAREST) << 0) | \ 398 ((address_u == SDL_TEXTURE_ADDRESS_WRAP) << 1) | \ 399 ((address_v == SDL_TEXTURE_ADDRESS_WRAP) << 2)) 400#define RENDER_SAMPLER_COUNT (((1 << 0) | (1 << 1) | (1 << 2)) + 1) 401 402// Add a supported texture format to a renderer 403extern bool SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format); 404 405// Setup colorspace conversion 406extern void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props); 407 408// Colorspace conversion functions 409extern bool SDL_RenderingLinearSpace(SDL_Renderer *renderer); 410extern void SDL_ConvertToLinear(SDL_FColor *color); 411extern void SDL_ConvertFromLinear(SDL_FColor *color); 412 413// Blend mode functions 414extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode); 415extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode); 416extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode); 417extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode); 418extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode); 419extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode); 420 421/* drivers call this during their Queue*() methods to make space in a array that are used 422 for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until 423 the next call, because it might be in an array that gets realloc()'d. */ 424extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, size_t numbytes, size_t alignment, size_t *offset); 425 426// Let the video subsystem destroy a renderer without making its pointer invalid. 427extern void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer); 428 429// Ends C function definitions when using C++ 430#ifdef __cplusplus 431} 432#endif 433 434#endif // SDL_sysrender_h_ 435
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.