Atlas - SDL_sysrender.h

Home / ext / SDL / src / render Lines: 1 | Size: 15210 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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 // The current renderer info 284 const char *name; 285 SDL_PixelFormat *texture_formats; 286 int num_texture_formats; 287 bool software; 288 bool npot_texture_wrap_unsupported; 289 290 // The window associated with the renderer 291 SDL_Window *window; 292 bool hidden; 293 294 // Whether we should simulate vsync 295 bool wanted_vsync; 296 bool simulate_vsync; 297 Uint64 simulate_vsync_interval_ns; 298 Uint64 last_present; 299 300 SDL_RenderViewState *view; 301 SDL_RenderViewState main_view; 302 303 // The window pixel to point coordinate scale 304 SDL_FPoint dpi_scale; 305 306 // The method of drawing lines 307 SDL_RenderLineMethod line_method; 308 309 // Default scale mode for textures created with this renderer 310 SDL_ScaleMode scale_mode; 311 312 // The list of textures 313 SDL_Texture *textures; 314 SDL_Texture *target; 315 SDL_Mutex *target_mutex; 316 317 // The list of palettes 318 SDL_HashTable *palettes; 319 320 SDL_Colorspace output_colorspace; 321 float SDR_white_point; 322 float HDR_headroom; 323 324 float desired_color_scale; 325 float color_scale; 326 SDL_FColor color; /**< Color for drawing operations values */ 327 SDL_BlendMode blendMode; /**< The drawing blend mode */ 328 SDL_TextureAddressMode texture_address_mode_u; 329 SDL_TextureAddressMode texture_address_mode_v; 330 SDL_GPURenderState *gpu_render_state; 331 332 SDL_RenderCommand *render_commands; 333 SDL_RenderCommand *render_commands_tail; 334 SDL_RenderCommand *render_commands_pool; 335 Uint32 render_command_generation; 336 SDL_FColor last_queued_color; 337 float last_queued_color_scale; 338 SDL_Rect last_queued_viewport; 339 SDL_Rect last_queued_cliprect; 340 bool last_queued_cliprect_enabled; 341 bool color_queued; 342 bool viewport_queued; 343 bool cliprect_queued; 344 345 void *vertex_data; 346 size_t vertex_data_used; 347 size_t vertex_data_allocation; 348 349 // Shaped window support 350 bool transparent_window; 351 SDL_Surface *shape_surface; 352 SDL_Texture *shape_texture; 353 354 SDL_PropertiesID props; 355 356 SDL_Texture *debug_char_texture_atlas; 357 358 bool destroyed; // already destroyed by SDL_DestroyWindow; just free this struct in SDL_DestroyRenderer. 359 360 void *internal; 361 362 SDL_Renderer *next; 363}; 364 365// Define the SDL render driver structure 366struct SDL_RenderDriver 367{ 368 bool (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID props); 369 370 const char *name; 371}; 372 373// Not all of these are available in a given build. Use #ifdefs, etc. 374extern SDL_RenderDriver D3D_RenderDriver; 375extern SDL_RenderDriver D3D11_RenderDriver; 376extern SDL_RenderDriver D3D12_RenderDriver; 377extern SDL_RenderDriver GL_RenderDriver; 378extern SDL_RenderDriver GLES2_RenderDriver; 379extern SDL_RenderDriver METAL_RenderDriver; 380extern SDL_RenderDriver NGAGE_RenderDriver; 381extern SDL_RenderDriver VULKAN_RenderDriver; 382extern SDL_RenderDriver PS2_RenderDriver; 383extern SDL_RenderDriver PSP_RenderDriver; 384extern SDL_RenderDriver SW_RenderDriver; 385extern SDL_RenderDriver VITA_GXM_RenderDriver; 386extern SDL_RenderDriver GPU_RenderDriver; 387 388// Clean up any renderers at shutdown 389extern void SDL_QuitRender(void); 390 391#define RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v) \ 392 (((scale_mode == SDL_SCALEMODE_NEAREST) << 0) | \ 393 ((address_u == SDL_TEXTURE_ADDRESS_WRAP) << 1) | \ 394 ((address_v == SDL_TEXTURE_ADDRESS_WRAP) << 2)) 395#define RENDER_SAMPLER_COUNT (((1 << 0) | (1 << 1) | (1 << 2)) + 1) 396 397// Add a supported texture format to a renderer 398extern bool SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format); 399 400// Setup colorspace conversion 401extern void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props); 402 403// Colorspace conversion functions 404extern bool SDL_RenderingLinearSpace(SDL_Renderer *renderer); 405extern void SDL_ConvertToLinear(SDL_FColor *color); 406extern void SDL_ConvertFromLinear(SDL_FColor *color); 407 408// Blend mode functions 409extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode); 410extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode); 411extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode); 412extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode); 413extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode); 414extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode); 415 416/* drivers call this during their Queue*() methods to make space in a array that are used 417 for a vertex buffer during RunCommandQueue(). Pointers returned here are only valid until 418 the next call, because it might be in an array that gets realloc()'d. */ 419extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, size_t numbytes, size_t alignment, size_t *offset); 420 421// Let the video subsystem destroy a renderer without making its pointer invalid. 422extern void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer); 423 424// Ends C function definitions when using C++ 425#ifdef __cplusplus 426} 427#endif 428 429#endif // SDL_sysrender_h_ 430
[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.