SDL 3.0
SDL_render.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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
22/**
23 * # CategoryRender
24 *
25 * Header file for SDL 2D rendering functions.
26 *
27 * This API supports the following features:
28 *
29 * - single pixel points
30 * - single pixel lines
31 * - filled rectangles
32 * - texture images
33 * - 2D polygons
34 *
35 * The primitives may be drawn in opaque, blended, or additive modes.
36 *
37 * The texture images may be drawn in opaque, blended, or additive modes. They
38 * can have an additional color tint or alpha modulation applied to them, and
39 * may also be stretched with linear interpolation.
40 *
41 * This API is designed to accelerate simple 2D operations. You may want more
42 * functionality such as polygons and particle effects and in that case you
43 * should use SDL's OpenGL/Direct3D support or one of the many good 3D
44 * engines.
45 *
46 * These functions must be called from the main thread. See this bug for
47 * details: https://github.com/libsdl-org/SDL/issues/986
48 */
49
50#ifndef SDL_render_h_
51#define SDL_render_h_
52
53#include <SDL3/SDL_stdinc.h>
54#include <SDL3/SDL_blendmode.h>
55#include <SDL3/SDL_error.h>
56#include <SDL3/SDL_events.h>
57#include <SDL3/SDL_pixels.h>
58#include <SDL3/SDL_properties.h>
59#include <SDL3/SDL_rect.h>
60#include <SDL3/SDL_surface.h>
61#include <SDL3/SDL_video.h>
62
63#include <SDL3/SDL_begin_code.h>
64/* Set up for C function definitions, even when using C++ */
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/**
70 * The name of the software renderer.
71 *
72 * \since This macro is available since SDL 3.0.0.
73 */
74#define SDL_SOFTWARE_RENDERER "software"
75
76/**
77 * Vertex structure.
78 *
79 * \since This struct is available since SDL 3.0.0.
80 */
81typedef struct SDL_Vertex
82{
83 SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
84 SDL_FColor color; /**< Vertex color */
85 SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
87
88/**
89 * The access pattern allowed for a texture.
90 *
91 * \since This enum is available since SDL 3.0.0.
92 */
94{
95 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
96 SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
97 SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
99
100/**
101 * How the logical size is mapped to the output.
102 *
103 * \since This enum is available since SDL 3.0.0.
104 */
106{
107 SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
108 SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
109 SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars */
110 SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
111 SDL_LOGICAL_PRESENTATION_INTEGER_SCALE /**< The rendered content is scaled up by integer multiples to fit the output resolution */
113
114/**
115 * A structure representing rendering state
116 *
117 * \since This struct is available since SDL 3.0.0.
118 */
120
121/**
122 * An efficient driver-specific representation of pixel data
123 *
124 * \since This struct is available since SDL 3.0.0.
125 */
127
128/* Function prototypes */
129
130/**
131 * Get the number of 2D rendering drivers available for the current display.
132 *
133 * A render driver is a set of code that handles rendering and texture
134 * management on a particular display. Normally there is only one, but some
135 * drivers may have several available with different capabilities.
136 *
137 * There may be none if SDL was compiled without render support.
138 *
139 * \returns the number of built in render drivers.
140 *
141 * \since This function is available since SDL 3.0.0.
142 *
143 * \sa SDL_CreateRenderer
144 * \sa SDL_GetRenderDriver
145 */
146extern SDL_DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
147
148/**
149 * Use this function to get the name of a built in 2D rendering driver.
150 *
151 * The list of rendering drivers is given in the order that they are normally
152 * initialized by default; the drivers that seem more reasonable to choose
153 * first (as far as the SDL developers believe) are earlier in the list.
154 *
155 * The names of drivers are all simple, low-ASCII identifiers, like "opengl",
156 * "direct3d12" or "metal". These never have Unicode characters, and are not
157 * meant to be proper names.
158 *
159 * \param index the index of the rendering driver; the value ranges from 0 to
160 * SDL_GetNumRenderDrivers() - 1.
161 * \returns the name of the rendering driver at the requested index, or NULL
162 * if an invalid index was specified.
163 *
164 * \since This function is available since SDL 3.0.0.
165 *
166 * \sa SDL_GetNumRenderDrivers
167 */
168extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index);
169
170/**
171 * Create a window and default renderer.
172 *
173 * \param title the title of the window, in UTF-8 encoding.
174 * \param width the width of the window.
175 * \param height the height of the window.
176 * \param window_flags the flags used to create the window (see
177 * SDL_CreateWindow()).
178 * \param window a pointer filled with the window, or NULL on error.
179 * \param renderer a pointer filled with the renderer, or NULL on error.
180 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
181 * for more information.
182 *
183 * \since This function is available since SDL 3.0.0.
184 *
185 * \sa SDL_CreateRenderer
186 * \sa SDL_CreateWindow
187 */
188extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer);
189
190/**
191 * Create a 2D rendering context for a window.
192 *
193 * If you want a specific renderer, you can specify its name here. A list of
194 * available renderers can be obtained by calling SDL_GetRenderDriver multiple
195 * times, with indices from 0 to SDL_GetNumRenderDrivers()-1. If you don't
196 * need a specific renderer, specify NULL and SDL will attempt to choose the
197 * best option for you, based on what is available on the user's system.
198 *
199 * By default the rendering size matches the window size in pixels, but you
200 * can call SDL_SetRenderLogicalPresentation() to change the content size and
201 * scaling options.
202 *
203 * \param window the window where rendering is displayed.
204 * \param name the name of the rendering driver to initialize, or NULL to
205 * initialize the first one supporting the requested flags.
206 * \returns a valid rendering context or NULL if there was an error; call
207 * SDL_GetError() for more information.
208 *
209 * \since This function is available since SDL 3.0.0.
210 *
211 * \sa SDL_CreateRendererWithProperties
212 * \sa SDL_CreateSoftwareRenderer
213 * \sa SDL_DestroyRenderer
214 * \sa SDL_GetNumRenderDrivers
215 * \sa SDL_GetRenderDriver
216 * \sa SDL_GetRendererName
217 */
218extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name);
219
220/**
221 * Create a 2D rendering context for a window, with the specified properties.
222 *
223 * These are the supported properties:
224 *
225 * - `SDL_PROP_RENDERER_CREATE_NAME_STRING`: the name of the rendering driver
226 * to use, if a specific one is desired
227 * - `SDL_PROP_RENDERER_CREATE_WINDOW_POINTER`: the window where rendering is
228 * displayed, required if this isn't a software renderer using a surface
229 * - `SDL_PROP_RENDERER_CREATE_SURFACE_POINTER`: the surface where rendering
230 * is displayed, if you want a software renderer without a window
231 * - `SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace
232 * value describing the colorspace for output to the display, defaults to
233 * SDL_COLORSPACE_SRGB. The direct3d11, direct3d12, and metal renderers
234 * support SDL_COLORSPACE_SRGB_LINEAR, which is a linear color space and
235 * supports HDR output. If you select SDL_COLORSPACE_SRGB_LINEAR, drawing
236 * still uses the sRGB colorspace, but values can go beyond 1.0 and float
237 * (linear) format textures can be used for HDR content.
238 * - `SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER`: non-zero if you want
239 * present synchronized with the refresh rate. This property can take any
240 * value that is supported by SDL_SetRenderVSync() for the renderer.
241 *
242 * With the vulkan renderer:
243 *
244 * - `SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER`: the VkInstance to use
245 * with the renderer, optional.
246 * - `SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER`: the VkSurfaceKHR to use
247 * with the renderer, optional.
248 * - `SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER`: the
249 * VkPhysicalDevice to use with the renderer, optional.
250 * - `SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER`: the VkDevice to use
251 * with the renderer, optional.
252 * - `SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER`: the
253 * queue family index used for rendering.
254 * - `SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER`: the
255 * queue family index used for presentation.
256 *
257 * \param props the properties to use.
258 * \returns a valid rendering context or NULL if there was an error; call
259 * SDL_GetError() for more information.
260 *
261 * \since This function is available since SDL 3.0.0.
262 *
263 * \sa SDL_CreateProperties
264 * \sa SDL_CreateRenderer
265 * \sa SDL_CreateSoftwareRenderer
266 * \sa SDL_DestroyRenderer
267 * \sa SDL_GetRendererName
268 */
270
271#define SDL_PROP_RENDERER_CREATE_NAME_STRING "SDL.renderer.create.name"
272#define SDL_PROP_RENDERER_CREATE_WINDOW_POINTER "SDL.renderer.create.window"
273#define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "SDL.renderer.create.surface"
274#define SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.create.output_colorspace"
275#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER "SDL.renderer.create.present_vsync"
276#define SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER "SDL.renderer.create.vulkan.instance"
277#define SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER "SDL.renderer.create.vulkan.surface"
278#define SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER "SDL.renderer.create.vulkan.physical_device"
279#define SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER "SDL.renderer.create.vulkan.device"
280#define SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.graphics_queue_family_index"
281#define SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.present_queue_family_index"
282
283/**
284 * Create a 2D software rendering context for a surface.
285 *
286 * Two other API which can be used to create SDL_Renderer:
287 * SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_
288 * create a software renderer, but they are intended to be used with an
289 * SDL_Window as the final destination and not an SDL_Surface.
290 *
291 * \param surface the SDL_Surface structure representing the surface where
292 * rendering is done.
293 * \returns a valid rendering context or NULL if there was an error; call
294 * SDL_GetError() for more information.
295 *
296 * \since This function is available since SDL 3.0.0.
297 *
298 * \sa SDL_DestroyRenderer
299 */
300extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface *surface);
301
302/**
303 * Get the renderer associated with a window.
304 *
305 * \param window the window to query.
306 * \returns the rendering context on success or NULL on failure; call
307 * SDL_GetError() for more information.
308 *
309 * \since This function is available since SDL 3.0.0.
310 */
311extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window *window);
312
313/**
314 * Get the window associated with a renderer.
315 *
316 * \param renderer the renderer to query.
317 * \returns the window on success or NULL on failure; call SDL_GetError() for
318 * more information.
319 *
320 * \since This function is available since SDL 3.0.0.
321 */
322extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetRenderWindow(SDL_Renderer *renderer);
323
324/**
325 * Get the name of a renderer.
326 *
327 * \param renderer the rendering context.
328 * \returns the name of the selected renderer, or NULL on failure; call
329 * SDL_GetError() for more information.
330 *
331 * \since This function is available since SDL 3.0.0.
332 *
333 * \sa SDL_CreateRenderer
334 * \sa SDL_CreateRendererWithProperties
335 */
336extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer);
337
338/**
339 * Get the properties associated with a renderer.
340 *
341 * The following read-only properties are provided by SDL:
342 *
343 * - `SDL_PROP_RENDERER_NAME_STRING`: the name of the rendering driver
344 * - `SDL_PROP_RENDERER_WINDOW_POINTER`: the window where rendering is
345 * displayed, if any
346 * - `SDL_PROP_RENDERER_SURFACE_POINTER`: the surface where rendering is
347 * displayed, if this is a software renderer without a window
348 * - `SDL_PROP_RENDERER_VSYNC_NUMBER`: the current vsync setting
349 * - `SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER`: the maximum texture width
350 * and height
351 * - `SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER`: a (const SDL_PixelFormat *)
352 * array of pixel formats, terminated with SDL_PIXELFORMAT_UNKNOWN,
353 * representing the available texture formats for this renderer.
354 * - `SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace value
355 * describing the colorspace for output to the display, defaults to
356 * SDL_COLORSPACE_SRGB.
357 * - `SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN`: true if the output colorspace is
358 * SDL_COLORSPACE_SRGB_LINEAR and the renderer is showing on a display with
359 * HDR enabled. This property can change dynamically when
360 * SDL_EVENT_DISPLAY_HDR_STATE_CHANGED is sent.
361 * - `SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT`: the value of SDR white in the
362 * SDL_COLORSPACE_SRGB_LINEAR colorspace. When HDR is enabled, this value is
363 * automatically multiplied into the color scale. This property can change
364 * dynamically when SDL_EVENT_DISPLAY_HDR_STATE_CHANGED is sent.
365 * - `SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT`: the additional high dynamic range
366 * that can be displayed, in terms of the SDR white point. When HDR is not
367 * enabled, this will be 1.0. This property can change dynamically when
368 * SDL_EVENT_DISPLAY_HDR_STATE_CHANGED is sent.
369 *
370 * With the direct3d renderer:
371 *
372 * - `SDL_PROP_RENDERER_D3D9_DEVICE_POINTER`: the IDirect3DDevice9 associated
373 * with the renderer
374 *
375 * With the direct3d11 renderer:
376 *
377 * - `SDL_PROP_RENDERER_D3D11_DEVICE_POINTER`: the ID3D11Device associated
378 * with the renderer
379 * - `SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER`: the IDXGISwapChain1
380 * associated with the renderer. This may change when the window is resized.
381 *
382 * With the direct3d12 renderer:
383 *
384 * - `SDL_PROP_RENDERER_D3D12_DEVICE_POINTER`: the ID3D12Device associated
385 * with the renderer
386 * - `SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER`: the IDXGISwapChain4
387 * associated with the renderer.
388 * - `SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER`: the ID3D12CommandQueue
389 * associated with the renderer
390 *
391 * With the vulkan renderer:
392 *
393 * - `SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER`: the VkInstance associated
394 * with the renderer
395 * - `SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER`: the VkSurfaceKHR associated
396 * with the renderer
397 * - `SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER`: the VkPhysicalDevice
398 * associated with the renderer
399 * - `SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER`: the VkDevice associated with
400 * the renderer
401 * - `SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER`: the queue
402 * family index used for rendering
403 * - `SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER`: the queue
404 * family index used for presentation
405 * - `SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER`: the number of
406 * swapchain images, or potential frames in flight, used by the Vulkan
407 * renderer
408 *
409 * \param renderer the rendering context.
410 * \returns a valid property ID on success or 0 on failure; call
411 * SDL_GetError() for more information.
412 *
413 * \since This function is available since SDL 3.0.0.
414 */
415extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Renderer *renderer);
416
417#define SDL_PROP_RENDERER_NAME_STRING "SDL.renderer.name"
418#define SDL_PROP_RENDERER_WINDOW_POINTER "SDL.renderer.window"
419#define SDL_PROP_RENDERER_SURFACE_POINTER "SDL.renderer.surface"
420#define SDL_PROP_RENDERER_VSYNC_NUMBER "SDL.renderer.vsync"
421#define SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER "SDL.renderer.max_texture_size"
422#define SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER "SDL.renderer.texture_formats"
423#define SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.output_colorspace"
424#define SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN "SDL.renderer.HDR_enabled"
425#define SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT "SDL.renderer.SDR_white_point"
426#define SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT "SDL.renderer.HDR_headroom"
427#define SDL_PROP_RENDERER_D3D9_DEVICE_POINTER "SDL.renderer.d3d9.device"
428#define SDL_PROP_RENDERER_D3D11_DEVICE_POINTER "SDL.renderer.d3d11.device"
429#define SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER "SDL.renderer.d3d11.swap_chain"
430#define SDL_PROP_RENDERER_D3D12_DEVICE_POINTER "SDL.renderer.d3d12.device"
431#define SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER "SDL.renderer.d3d12.swap_chain"
432#define SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER "SDL.renderer.d3d12.command_queue"
433#define SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER "SDL.renderer.vulkan.instance"
434#define SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER "SDL.renderer.vulkan.surface"
435#define SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER "SDL.renderer.vulkan.physical_device"
436#define SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER "SDL.renderer.vulkan.device"
437#define SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.vulkan.graphics_queue_family_index"
438#define SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.vulkan.present_queue_family_index"
439#define SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER "SDL.renderer.vulkan.swapchain_image_count"
440
441/**
442 * Get the output size in pixels of a rendering context.
443 *
444 * This returns the true output size in pixels, ignoring any render targets or
445 * logical size and presentation.
446 *
447 * \param renderer the rendering context.
448 * \param w a pointer filled in with the width in pixels.
449 * \param h a pointer filled in with the height in pixels.
450 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
451 * for more information.
452 *
453 * \since This function is available since SDL 3.0.0.
454 *
455 * \sa SDL_GetCurrentRenderOutputSize
456 */
457extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
458
459/**
460 * Get the current output size in pixels of a rendering context.
461 *
462 * If a rendering target is active, this will return the size of the rendering
463 * target in pixels, otherwise if a logical size is set, it will return the
464 * logical size, otherwise it will return the value of
465 * SDL_GetRenderOutputSize().
466 *
467 * \param renderer the rendering context.
468 * \param w a pointer filled in with the current width.
469 * \param h a pointer filled in with the current height.
470 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
471 * for more information.
472 *
473 * \since This function is available since SDL 3.0.0.
474 *
475 * \sa SDL_GetRenderOutputSize
476 */
477extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
478
479/**
480 * Create a texture for a rendering context.
481 *
482 * The contents of a texture when first created are not defined.
483 *
484 * \param renderer the rendering context.
485 * \param format one of the enumerated values in SDL_PixelFormat.
486 * \param access one of the enumerated values in SDL_TextureAccess.
487 * \param w the width of the texture in pixels.
488 * \param h the height of the texture in pixels.
489 * \returns a pointer to the created texture or NULL if no rendering context
490 * was active, the format was unsupported, or the width or height
491 * were out of range; call SDL_GetError() for more information.
492 *
493 * \since This function is available since SDL 3.0.0.
494 *
495 * \sa SDL_CreateTextureFromSurface
496 * \sa SDL_CreateTextureWithProperties
497 * \sa SDL_DestroyTexture
498 * \sa SDL_GetTextureSize
499 * \sa SDL_UpdateTexture
500 */
501extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h);
502
503/**
504 * Create a texture from an existing surface.
505 *
506 * The surface is not modified or freed by this function.
507 *
508 * The SDL_TextureAccess hint for the created texture is
509 * `SDL_TEXTUREACCESS_STATIC`.
510 *
511 * The pixel format of the created texture may be different from the pixel
512 * format of the surface, and can be queried using the
513 * SDL_PROP_TEXTURE_FORMAT_NUMBER property.
514 *
515 * \param renderer the rendering context.
516 * \param surface the SDL_Surface structure containing pixel data used to fill
517 * the texture.
518 * \returns the created texture or NULL on failure; call SDL_GetError() for
519 * more information.
520 *
521 * \since This function is available since SDL 3.0.0.
522 *
523 * \sa SDL_CreateTexture
524 * \sa SDL_CreateTextureWithProperties
525 * \sa SDL_DestroyTexture
526 */
527extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
528
529/**
530 * Create a texture for a rendering context with the specified properties.
531 *
532 * These are the supported properties:
533 *
534 * - `SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER`: an SDL_ColorSpace value
535 * describing the texture colorspace, defaults to SDL_COLORSPACE_SRGB_LINEAR
536 * for floating point textures, SDL_COLORSPACE_HDR10 for 10-bit textures,
537 * SDL_COLORSPACE_SRGB for other RGB textures and SDL_COLORSPACE_JPEG for
538 * YUV textures.
539 * - `SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER`: one of the enumerated values in
540 * SDL_PixelFormat, defaults to the best RGBA format for the renderer
541 * - `SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER`: one of the enumerated values in
542 * SDL_TextureAccess, defaults to SDL_TEXTUREACCESS_STATIC
543 * - `SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER`: the width of the texture in
544 * pixels, required
545 * - `SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER`: the height of the texture in
546 * pixels, required
547 * - `SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating
548 * point textures, this defines the value of 100% diffuse white, with higher
549 * values being displayed in the High Dynamic Range headroom. This defaults
550 * to 100 for HDR10 textures and 1.0 for floating point textures.
551 * - `SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT`: for HDR10 and floating
552 * point textures, this defines the maximum dynamic range used by the
553 * content, in terms of the SDR white point. This would be equivalent to
554 * maxCLL / SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT for HDR10 content.
555 * If this is defined, any values outside the range supported by the display
556 * will be scaled into the available HDR headroom, otherwise they are
557 * clipped.
558 *
559 * With the direct3d11 renderer:
560 *
561 * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER`: the ID3D11Texture2D
562 * associated with the texture, if you want to wrap an existing texture.
563 * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER`: the ID3D11Texture2D
564 * associated with the U plane of a YUV texture, if you want to wrap an
565 * existing texture.
566 * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER`: the ID3D11Texture2D
567 * associated with the V plane of a YUV texture, if you want to wrap an
568 * existing texture.
569 *
570 * With the direct3d12 renderer:
571 *
572 * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER`: the ID3D12Resource
573 * associated with the texture, if you want to wrap an existing texture.
574 * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER`: the ID3D12Resource
575 * associated with the U plane of a YUV texture, if you want to wrap an
576 * existing texture.
577 * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER`: the ID3D12Resource
578 * associated with the V plane of a YUV texture, if you want to wrap an
579 * existing texture.
580 *
581 * With the metal renderer:
582 *
583 * - `SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER`: the CVPixelBufferRef
584 * associated with the texture, if you want to create a texture from an
585 * existing pixel buffer.
586 *
587 * With the opengl renderer:
588 *
589 * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER`: the GLuint texture
590 * associated with the texture, if you want to wrap an existing texture.
591 * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER`: the GLuint texture
592 * associated with the UV plane of an NV12 texture, if you want to wrap an
593 * existing texture.
594 * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER`: the GLuint texture
595 * associated with the U plane of a YUV texture, if you want to wrap an
596 * existing texture.
597 * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER`: the GLuint texture
598 * associated with the V plane of a YUV texture, if you want to wrap an
599 * existing texture.
600 *
601 * With the opengles2 renderer:
602 *
603 * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
604 * associated with the texture, if you want to wrap an existing texture.
605 * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
606 * associated with the texture, if you want to wrap an existing texture.
607 * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER`: the GLuint texture
608 * associated with the UV plane of an NV12 texture, if you want to wrap an
609 * existing texture.
610 * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER`: the GLuint texture
611 * associated with the U plane of a YUV texture, if you want to wrap an
612 * existing texture.
613 * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER`: the GLuint texture
614 * associated with the V plane of a YUV texture, if you want to wrap an
615 * existing texture.
616 *
617 * With the vulkan renderer:
618 *
619 * - `SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER`: the VkImage with layout
620 * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL associated with the texture, if
621 * you want to wrap an existing texture.
622 *
623 * \param renderer the rendering context.
624 * \param props the properties to use.
625 * \returns a pointer to the created texture or NULL if no rendering context
626 * was active, the format was unsupported, or the width or height
627 * were out of range; call SDL_GetError() for more information.
628 *
629 * \since This function is available since SDL 3.0.0.
630 *
631 * \sa SDL_CreateProperties
632 * \sa SDL_CreateTexture
633 * \sa SDL_CreateTextureFromSurface
634 * \sa SDL_DestroyTexture
635 * \sa SDL_GetTextureSize
636 * \sa SDL_UpdateTexture
637 */
638extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
639
640#define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER "SDL.texture.create.colorspace"
641#define SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER "SDL.texture.create.format"
642#define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "SDL.texture.create.access"
643#define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "SDL.texture.create.width"
644#define SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER "SDL.texture.create.height"
645#define SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT "SDL.texture.create.SDR_white_point"
646#define SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT "SDL.texture.create.HDR_headroom"
647#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "SDL.texture.create.d3d11.texture"
648#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER "SDL.texture.create.d3d11.texture_u"
649#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER "SDL.texture.create.d3d11.texture_v"
650#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER "SDL.texture.create.d3d12.texture"
651#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER "SDL.texture.create.d3d12.texture_u"
652#define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER "SDL.texture.create.d3d12.texture_v"
653#define SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER "SDL.texture.create.metal.pixelbuffer"
654#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER "SDL.texture.create.opengl.texture"
655#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.create.opengl.texture_uv"
656#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.create.opengl.texture_u"
657#define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.create.opengl.texture_v"
658#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.create.opengles2.texture"
659#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.create.opengles2.texture_uv"
660#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.create.opengles2.texture_u"
661#define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.create.opengles2.texture_v"
662#define SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER "SDL.texture.create.vulkan.texture"
663
664/**
665 * Get the properties associated with a texture.
666 *
667 * The following read-only properties are provided by SDL:
668 *
669 * - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
670 * the texture colorspace.
671 * - `SDL_PROP_TEXTURE_FORMAT_NUMBER`: one of the enumerated values in
672 * SDL_PixelFormat.
673 * - `SDL_PROP_TEXTURE_ACCESS_NUMBER`: one of the enumerated values in
674 * SDL_TextureAccess.
675 * - `SDL_PROP_TEXTURE_WIDTH_NUMBER`: the width of the texture in pixels.
676 * - `SDL_PROP_TEXTURE_HEIGHT_NUMBER`: the height of the texture in pixels.
677 * - `SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
678 * textures, this defines the value of 100% diffuse white, with higher
679 * values being displayed in the High Dynamic Range headroom. This defaults
680 * to 100 for HDR10 textures and 1.0 for other textures.
681 * - `SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
682 * textures, this defines the maximum dynamic range used by the content, in
683 * terms of the SDR white point. If this is defined, any values outside the
684 * range supported by the display will be scaled into the available HDR
685 * headroom, otherwise they are clipped. This defaults to 1.0 for SDR
686 * textures, 4.0 for HDR10 textures, and no default for floating point
687 * textures.
688 *
689 * With the direct3d11 renderer:
690 *
691 * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER`: the ID3D11Texture2D associated
692 * with the texture
693 * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER`: the ID3D11Texture2D
694 * associated with the U plane of a YUV texture
695 * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER`: the ID3D11Texture2D
696 * associated with the V plane of a YUV texture
697 *
698 * With the direct3d12 renderer:
699 *
700 * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER`: the ID3D12Resource associated
701 * with the texture
702 * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER`: the ID3D12Resource associated
703 * with the U plane of a YUV texture
704 * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER`: the ID3D12Resource associated
705 * with the V plane of a YUV texture
706 *
707 * With the vulkan renderer:
708 *
709 * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_POINTER`: the VkImage associated with
710 * the texture
711 * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_U_POINTER`: the VkImage associated with
712 * the U plane of a YUV texture
713 * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_V_POINTER`: the VkImage associated with
714 * the V plane of a YUV texture
715 * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_UV_POINTER`: the VkImage associated with
716 * the UV plane of a NV12/NV21 texture
717 *
718 * With the opengl renderer:
719 *
720 * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER`: the GLuint texture associated
721 * with the texture
722 * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER`: the GLuint texture
723 * associated with the UV plane of an NV12 texture
724 * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER`: the GLuint texture associated
725 * with the U plane of a YUV texture
726 * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER`: the GLuint texture associated
727 * with the V plane of a YUV texture
728 * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER`: the GLenum for the
729 * texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_RECTANGLE_ARB`, etc)
730 * - `SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT`: the texture coordinate width of
731 * the texture (0.0 - 1.0)
732 * - `SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT`: the texture coordinate height of
733 * the texture (0.0 - 1.0)
734 *
735 * With the opengles2 renderer:
736 *
737 * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
738 * associated with the texture
739 * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER`: the GLuint texture
740 * associated with the UV plane of an NV12 texture
741 * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER`: the GLuint texture
742 * associated with the U plane of a YUV texture
743 * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER`: the GLuint texture
744 * associated with the V plane of a YUV texture
745 * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER`: the GLenum for the
746 * texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_EXTERNAL_OES`, etc)
747 *
748 * With the vulkan renderer:
749 *
750 * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER`: the VkImage associated with the
751 * texture
752 *
753 * \param texture the texture to query.
754 * \returns a valid property ID on success or 0 on failure; call
755 * SDL_GetError() for more information.
756 *
757 * \since This function is available since SDL 3.0.0.
758 */
759extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
760
761#define SDL_PROP_TEXTURE_COLORSPACE_NUMBER "SDL.texture.colorspace"
762#define SDL_PROP_TEXTURE_FORMAT_NUMBER "SDL.texture.format"
763#define SDL_PROP_TEXTURE_ACCESS_NUMBER "SDL.texture.access"
764#define SDL_PROP_TEXTURE_WIDTH_NUMBER "SDL.texture.width"
765#define SDL_PROP_TEXTURE_HEIGHT_NUMBER "SDL.texture.height"
766#define SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT "SDL.texture.SDR_white_point"
767#define SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT "SDL.texture.HDR_headroom"
768#define SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER "SDL.texture.d3d11.texture"
769#define SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER "SDL.texture.d3d11.texture_u"
770#define SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER "SDL.texture.d3d11.texture_v"
771#define SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER "SDL.texture.d3d12.texture"
772#define SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER "SDL.texture.d3d12.texture_u"
773#define SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER "SDL.texture.d3d12.texture_v"
774#define SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER "SDL.texture.opengl.texture"
775#define SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.opengl.texture_uv"
776#define SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.opengl.texture_u"
777#define SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.opengl.texture_v"
778#define SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER "SDL.texture.opengl.target"
779#define SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT "SDL.texture.opengl.tex_w"
780#define SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT "SDL.texture.opengl.tex_h"
781#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.opengles2.texture"
782#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.opengles2.texture_uv"
783#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.opengles2.texture_u"
784#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.opengles2.texture_v"
785#define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER "SDL.texture.opengles2.target"
786#define SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER "SDL.texture.vulkan.texture"
787
788/**
789 * Get the renderer that created an SDL_Texture.
790 *
791 * \param texture the texture to query.
792 * \returns a pointer to the SDL_Renderer that created the texture, or NULL on
793 * failure; call SDL_GetError() for more information.
794 *
795 * \threadsafety It is safe to call this function from any thread.
796 *
797 * \since This function is available since SDL 3.0.0.
798 */
799extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRendererFromTexture(SDL_Texture *texture);
800
801/**
802 * Get the size of a texture, as floating point values.
803 *
804 * \param texture the texture to query.
805 * \param w a pointer filled in with the width of the texture in pixels. This
806 * argument can be NULL if you don't need this information.
807 * \param h a pointer filled in with the height of the texture in pixels. This
808 * argument can be NULL if you don't need this information.
809 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
810 * for more information.
811 *
812 * \since This function is available since SDL 3.0.0.
813 */
814extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);
815
816/**
817 * Set an additional color value multiplied into render copy operations.
818 *
819 * When this texture is rendered, during the copy operation each source color
820 * channel is modulated by the appropriate color value according to the
821 * following formula:
822 *
823 * `srcC = srcC * (color / 255)`
824 *
825 * Color modulation is not always supported by the renderer; it will return
826 * SDL_FALSE if color modulation is not supported.
827 *
828 * \param texture the texture to update.
829 * \param r the red color value multiplied into copy operations.
830 * \param g the green color value multiplied into copy operations.
831 * \param b the blue color value multiplied into copy operations.
832 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
833 * for more information.
834 *
835 * \since This function is available since SDL 3.0.0.
836 *
837 * \sa SDL_GetTextureColorMod
838 * \sa SDL_SetTextureAlphaMod
839 * \sa SDL_SetTextureColorModFloat
840 */
841extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
842
843
844/**
845 * Set an additional color value multiplied into render copy operations.
846 *
847 * When this texture is rendered, during the copy operation each source color
848 * channel is modulated by the appropriate color value according to the
849 * following formula:
850 *
851 * `srcC = srcC * color`
852 *
853 * Color modulation is not always supported by the renderer; it will return
854 * SDL_FALSE if color modulation is not supported.
855 *
856 * \param texture the texture to update.
857 * \param r the red color value multiplied into copy operations.
858 * \param g the green color value multiplied into copy operations.
859 * \param b the blue color value multiplied into copy operations.
860 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
861 * for more information.
862 *
863 * \since This function is available since SDL 3.0.0.
864 *
865 * \sa SDL_GetTextureColorModFloat
866 * \sa SDL_SetTextureAlphaModFloat
867 * \sa SDL_SetTextureColorMod
868 */
869extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b);
870
871
872/**
873 * Get the additional color value multiplied into render copy operations.
874 *
875 * \param texture the texture to query.
876 * \param r a pointer filled in with the current red color value.
877 * \param g a pointer filled in with the current green color value.
878 * \param b a pointer filled in with the current blue color value.
879 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
880 * for more information.
881 *
882 * \since This function is available since SDL 3.0.0.
883 *
884 * \sa SDL_GetTextureAlphaMod
885 * \sa SDL_GetTextureColorModFloat
886 * \sa SDL_SetTextureColorMod
887 */
888extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b);
889
890/**
891 * Get the additional color value multiplied into render copy operations.
892 *
893 * \param texture the texture to query.
894 * \param r a pointer filled in with the current red color value.
895 * \param g a pointer filled in with the current green color value.
896 * \param b a pointer filled in with the current blue color value.
897 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
898 * for more information.
899 *
900 * \since This function is available since SDL 3.0.0.
901 *
902 * \sa SDL_GetTextureAlphaModFloat
903 * \sa SDL_GetTextureColorMod
904 * \sa SDL_SetTextureColorModFloat
905 */
906extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b);
907
908/**
909 * Set an additional alpha value multiplied into render copy operations.
910 *
911 * When this texture is rendered, during the copy operation the source alpha
912 * value is modulated by this alpha value according to the following formula:
913 *
914 * `srcA = srcA * (alpha / 255)`
915 *
916 * Alpha modulation is not always supported by the renderer; it will return
917 * SDL_FALSE if alpha modulation is not supported.
918 *
919 * \param texture the texture to update.
920 * \param alpha the source alpha value multiplied into copy operations.
921 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
922 * for more information.
923 *
924 * \since This function is available since SDL 3.0.0.
925 *
926 * \sa SDL_GetTextureAlphaMod
927 * \sa SDL_SetTextureAlphaModFloat
928 * \sa SDL_SetTextureColorMod
929 */
930extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
931
932/**
933 * Set an additional alpha value multiplied into render copy operations.
934 *
935 * When this texture is rendered, during the copy operation the source alpha
936 * value is modulated by this alpha value according to the following formula:
937 *
938 * `srcA = srcA * alpha`
939 *
940 * Alpha modulation is not always supported by the renderer; it will return
941 * SDL_FALSE if alpha modulation is not supported.
942 *
943 * \param texture the texture to update.
944 * \param alpha the source alpha value multiplied into copy operations.
945 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
946 * for more information.
947 *
948 * \since This function is available since SDL 3.0.0.
949 *
950 * \sa SDL_GetTextureAlphaModFloat
951 * \sa SDL_SetTextureAlphaMod
952 * \sa SDL_SetTextureColorModFloat
953 */
954extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha);
955
956/**
957 * Get the additional alpha value multiplied into render copy operations.
958 *
959 * \param texture the texture to query.
960 * \param alpha a pointer filled in with the current alpha value.
961 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
962 * for more information.
963 *
964 * \since This function is available since SDL 3.0.0.
965 *
966 * \sa SDL_GetTextureAlphaModFloat
967 * \sa SDL_GetTextureColorMod
968 * \sa SDL_SetTextureAlphaMod
969 */
970extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha);
971
972/**
973 * Get the additional alpha value multiplied into render copy operations.
974 *
975 * \param texture the texture to query.
976 * \param alpha a pointer filled in with the current alpha value.
977 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
978 * for more information.
979 *
980 * \since This function is available since SDL 3.0.0.
981 *
982 * \sa SDL_GetTextureAlphaMod
983 * \sa SDL_GetTextureColorModFloat
984 * \sa SDL_SetTextureAlphaModFloat
985 */
986extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha);
987
988/**
989 * Set the blend mode for a texture, used by SDL_RenderTexture().
990 *
991 * If the blend mode is not supported, the closest supported mode is chosen
992 * and this function returns SDL_FALSE.
993 *
994 * \param texture the texture to update.
995 * \param blendMode the SDL_BlendMode to use for texture blending.
996 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
997 * for more information.
998 *
999 * \since This function is available since SDL 3.0.0.
1000 *
1001 * \sa SDL_GetTextureBlendMode
1002 */
1003extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode);
1004
1005/**
1006 * Get the blend mode used for texture copy operations.
1007 *
1008 * \param texture the texture to query.
1009 * \param blendMode a pointer filled in with the current SDL_BlendMode.
1010 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1011 * for more information.
1012 *
1013 * \since This function is available since SDL 3.0.0.
1014 *
1015 * \sa SDL_SetTextureBlendMode
1016 */
1017extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode);
1018
1019/**
1020 * Set the scale mode used for texture scale operations.
1021 *
1022 * The default texture scale mode is SDL_SCALEMODE_LINEAR.
1023 *
1024 * If the scale mode is not supported, the closest supported mode is chosen.
1025 *
1026 * \param texture the texture to update.
1027 * \param scaleMode the SDL_ScaleMode to use for texture scaling.
1028 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1029 * for more information.
1030 *
1031 * \since This function is available since SDL 3.0.0.
1032 *
1033 * \sa SDL_GetTextureScaleMode
1034 */
1035extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode);
1036
1037/**
1038 * Get the scale mode used for texture scale operations.
1039 *
1040 * \param texture the texture to query.
1041 * \param scaleMode a pointer filled in with the current scale mode.
1042 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1043 * for more information.
1044 *
1045 * \since This function is available since SDL 3.0.0.
1046 *
1047 * \sa SDL_SetTextureScaleMode
1048 */
1049extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode);
1050
1051/**
1052 * Update the given texture rectangle with new pixel data.
1053 *
1054 * The pixel data must be in the pixel format of the texture, which can be
1055 * queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
1056 *
1057 * This is a fairly slow function, intended for use with static textures that
1058 * do not change often.
1059 *
1060 * If the texture is intended to be updated often, it is preferred to create
1061 * the texture as streaming and use the locking functions referenced below.
1062 * While this function will work with streaming textures, for optimization
1063 * reasons you may not get the pixels back if you lock the texture afterward.
1064 *
1065 * \param texture the texture to update.
1066 * \param rect an SDL_Rect structure representing the area to update, or NULL
1067 * to update the entire texture.
1068 * \param pixels the raw pixel data in the format of the texture.
1069 * \param pitch the number of bytes in a row of pixel data, including padding
1070 * between lines.
1071 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1072 * for more information.
1073 *
1074 * \since This function is available since SDL 3.0.0.
1075 *
1076 * \sa SDL_LockTexture
1077 * \sa SDL_UnlockTexture
1078 * \sa SDL_UpdateNVTexture
1079 * \sa SDL_UpdateYUVTexture
1080 */
1081extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch);
1082
1083/**
1084 * Update a rectangle within a planar YV12 or IYUV texture with new pixel
1085 * data.
1086 *
1087 * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
1088 * block of Y and U/V planes in the proper order, but this function is
1089 * available if your pixel data is not contiguous.
1090 *
1091 * \param texture the texture to update.
1092 * \param rect a pointer to the rectangle of pixels to update, or NULL to
1093 * update the entire texture.
1094 * \param Yplane the raw pixel data for the Y plane.
1095 * \param Ypitch the number of bytes between rows of pixel data for the Y
1096 * plane.
1097 * \param Uplane the raw pixel data for the U plane.
1098 * \param Upitch the number of bytes between rows of pixel data for the U
1099 * plane.
1100 * \param Vplane the raw pixel data for the V plane.
1101 * \param Vpitch the number of bytes between rows of pixel data for the V
1102 * plane.
1103 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1104 * for more information.
1105 *
1106 * \since This function is available since SDL 3.0.0.
1107 *
1108 * \sa SDL_UpdateNVTexture
1109 * \sa SDL_UpdateTexture
1110 */
1111extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture,
1112 const SDL_Rect *rect,
1113 const Uint8 *Yplane, int Ypitch,
1114 const Uint8 *Uplane, int Upitch,
1115 const Uint8 *Vplane, int Vpitch);
1116
1117/**
1118 * Update a rectangle within a planar NV12 or NV21 texture with new pixels.
1119 *
1120 * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
1121 * block of NV12/21 planes in the proper order, but this function is available
1122 * if your pixel data is not contiguous.
1123 *
1124 * \param texture the texture to update.
1125 * \param rect a pointer to the rectangle of pixels to update, or NULL to
1126 * update the entire texture.
1127 * \param Yplane the raw pixel data for the Y plane.
1128 * \param Ypitch the number of bytes between rows of pixel data for the Y
1129 * plane.
1130 * \param UVplane the raw pixel data for the UV plane.
1131 * \param UVpitch the number of bytes between rows of pixel data for the UV
1132 * plane.
1133 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1134 * for more information.
1135 *
1136 * \since This function is available since SDL 3.0.0.
1137 *
1138 * \sa SDL_UpdateTexture
1139 * \sa SDL_UpdateYUVTexture
1140 */
1141extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture,
1142 const SDL_Rect *rect,
1143 const Uint8 *Yplane, int Ypitch,
1144 const Uint8 *UVplane, int UVpitch);
1145
1146/**
1147 * Lock a portion of the texture for **write-only** pixel access.
1148 *
1149 * As an optimization, the pixels made available for editing don't necessarily
1150 * contain the old texture data. This is a write-only operation, and if you
1151 * need to keep a copy of the texture data you should do that at the
1152 * application level.
1153 *
1154 * You must use SDL_UnlockTexture() to unlock the pixels and apply any
1155 * changes.
1156 *
1157 * \param texture the texture to lock for access, which was created with
1158 * `SDL_TEXTUREACCESS_STREAMING`.
1159 * \param rect an SDL_Rect structure representing the area to lock for access;
1160 * NULL to lock the entire texture.
1161 * \param pixels this is filled in with a pointer to the locked pixels,
1162 * appropriately offset by the locked area.
1163 * \param pitch this is filled in with the pitch of the locked pixels; the
1164 * pitch is the length of one row in bytes.
1165 * \returns SDL_TRUE on success or SDL_FALSE if the texture is not valid or
1166 * was not created with `SDL_TEXTUREACCESS_STREAMING`; call
1167 * SDL_GetError() for more information.
1168 *
1169 * \since This function is available since SDL 3.0.0.
1170 *
1171 * \sa SDL_LockTextureToSurface
1172 * \sa SDL_UnlockTexture
1173 */
1174extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockTexture(SDL_Texture *texture,
1175 const SDL_Rect *rect,
1176 void **pixels, int *pitch);
1177
1178/**
1179 * Lock a portion of the texture for **write-only** pixel access, and expose
1180 * it as a SDL surface.
1181 *
1182 * Besides providing an SDL_Surface instead of raw pixel data, this function
1183 * operates like SDL_LockTexture.
1184 *
1185 * As an optimization, the pixels made available for editing don't necessarily
1186 * contain the old texture data. This is a write-only operation, and if you
1187 * need to keep a copy of the texture data you should do that at the
1188 * application level.
1189 *
1190 * You must use SDL_UnlockTexture() to unlock the pixels and apply any
1191 * changes.
1192 *
1193 * The returned surface is freed internally after calling SDL_UnlockTexture()
1194 * or SDL_DestroyTexture(). The caller should not free it.
1195 *
1196 * \param texture the texture to lock for access, which must be created with
1197 * `SDL_TEXTUREACCESS_STREAMING`.
1198 * \param rect a pointer to the rectangle to lock for access. If the rect is
1199 * NULL, the entire texture will be locked.
1200 * \param surface this is filled in with an SDL surface representing the
1201 * locked area.
1202 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1203 * for more information.
1204 *
1205 * \since This function is available since SDL 3.0.0.
1206 *
1207 * \sa SDL_LockTexture
1208 * \sa SDL_UnlockTexture
1209 */
1210extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface);
1211
1212/**
1213 * Unlock a texture, uploading the changes to video memory, if needed.
1214 *
1215 * **Warning**: Please note that SDL_LockTexture() is intended to be
1216 * write-only; it will not guarantee the previous contents of the texture will
1217 * be provided. You must fully initialize any area of a texture that you lock
1218 * before unlocking it, as the pixels might otherwise be uninitialized memory.
1219 *
1220 * Which is to say: locking and immediately unlocking a texture can result in
1221 * corrupted textures, depending on the renderer in use.
1222 *
1223 * \param texture a texture locked by SDL_LockTexture().
1224 *
1225 * \since This function is available since SDL 3.0.0.
1226 *
1227 * \sa SDL_LockTexture
1228 */
1229extern SDL_DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture *texture);
1230
1231/**
1232 * Set a texture as the current rendering target.
1233 *
1234 * The default render target is the window for which the renderer was created.
1235 * To stop rendering to a texture and render to the window again, call this
1236 * function with a NULL `texture`.
1237 *
1238 * \param renderer the rendering context.
1239 * \param texture the targeted texture, which must be created with the
1240 * `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the
1241 * window instead of a texture.
1242 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1243 * for more information.
1244 *
1245 * \since This function is available since SDL 3.0.0.
1246 *
1247 * \sa SDL_GetRenderTarget
1248 */
1249extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture);
1250
1251/**
1252 * Get the current render target.
1253 *
1254 * The default render target is the window for which the renderer was created,
1255 * and is reported a NULL here.
1256 *
1257 * \param renderer the rendering context.
1258 * \returns the current render target or NULL for the default render target.
1259 *
1260 * \since This function is available since SDL 3.0.0.
1261 *
1262 * \sa SDL_SetRenderTarget
1263 */
1264extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
1265
1266/**
1267 * Set a device independent resolution and presentation mode for rendering.
1268 *
1269 * This function sets the width and height of the logical rendering output. A
1270 * render target is created at the specified size and used for rendering and
1271 * then copied to the output during presentation.
1272 *
1273 * You can disable logical coordinates by setting the mode to
1274 * SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel
1275 * resolution of the output window.
1276 *
1277 * You can convert coordinates in an event into rendering coordinates using
1278 * SDL_ConvertEventToRenderCoordinates().
1279 *
1280 * \param renderer the rendering context.
1281 * \param w the width of the logical resolution.
1282 * \param h the height of the logical resolution.
1283 * \param mode the presentation mode used.
1284 * \param scale_mode the scale mode used.
1285 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1286 * for more information.
1287 *
1288 * \since This function is available since SDL 3.0.0.
1289 *
1290 * \sa SDL_ConvertEventToRenderCoordinates
1291 * \sa SDL_GetRenderLogicalPresentation
1292 * \sa SDL_GetRenderLogicalPresentationRect
1293 */
1294extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
1295
1296/**
1297 * Get device independent resolution and presentation mode for rendering.
1298 *
1299 * This function gets the width and height of the logical rendering output, or
1300 * the output size in pixels if a logical resolution is not enabled.
1301 *
1302 * \param renderer the rendering context.
1303 * \param w an int to be filled with the width.
1304 * \param h an int to be filled with the height.
1305 * \param mode a pointer filled in with the presentation mode.
1306 * \param scale_mode a pointer filled in with the scale mode.
1307 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1308 * for more information.
1309 *
1310 * \since This function is available since SDL 3.0.0.
1311 *
1312 * \sa SDL_SetRenderLogicalPresentation
1313 */
1314extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
1315
1316/**
1317 * Get the final presentation rectangle for rendering.
1318 *
1319 * This function returns the calculated rectangle used for logical
1320 * presentation, based on the presentation mode and output size. If logical
1321 * presentation is disabled, it will fill the rectangle with the output size,
1322 * in pixels.
1323 *
1324 * \param renderer the rendering context.
1325 * \param rect a pointer filled in with the final presentation rectangle, may
1326 * be NULL.
1327 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1328 * for more information.
1329 *
1330 * \since This function is available since SDL 3.0.0.
1331 *
1332 * \sa SDL_SetRenderLogicalPresentation
1333 */
1334extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect);
1335
1336/**
1337 * Get a point in render coordinates when given a point in window coordinates.
1338 *
1339 * \param renderer the rendering context.
1340 * \param window_x the x coordinate in window coordinates.
1341 * \param window_y the y coordinate in window coordinates.
1342 * \param x a pointer filled with the x coordinate in render coordinates.
1343 * \param y a pointer filled with the y coordinate in render coordinates.
1344 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1345 * for more information.
1346 *
1347 * \since This function is available since SDL 3.0.0.
1348 *
1349 * \sa SDL_SetRenderLogicalPresentation
1350 * \sa SDL_SetRenderScale
1351 */
1352extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y);
1353
1354/**
1355 * Get a point in window coordinates when given a point in render coordinates.
1356 *
1357 * \param renderer the rendering context.
1358 * \param x the x coordinate in render coordinates.
1359 * \param y the y coordinate in render coordinates.
1360 * \param window_x a pointer filled with the x coordinate in window
1361 * coordinates.
1362 * \param window_y a pointer filled with the y coordinate in window
1363 * coordinates.
1364 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1365 * for more information.
1366 *
1367 * \since This function is available since SDL 3.0.0.
1368 *
1369 * \sa SDL_SetRenderLogicalPresentation
1370 * \sa SDL_SetRenderScale
1371 */
1372extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y);
1373
1374/**
1375 * Convert the coordinates in an event to render coordinates.
1376 *
1377 * Touch coordinates are converted from normalized coordinates in the window
1378 * to non-normalized rendering coordinates.
1379 *
1380 * Once converted, the coordinates may be outside the rendering area.
1381 *
1382 * \param renderer the rendering context.
1383 * \param event the event to modify.
1384 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1385 * for more information.
1386 *
1387 * \since This function is available since SDL 3.0.0.
1388 *
1389 * \sa SDL_RenderCoordinatesFromWindow
1390 */
1391extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event);
1392
1393/**
1394 * Set the drawing area for rendering on the current target.
1395 *
1396 * \param renderer the rendering context.
1397 * \param rect the SDL_Rect structure representing the drawing area, or NULL
1398 * to set the viewport to the entire target.
1399 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1400 * for more information.
1401 *
1402 * \since This function is available since SDL 3.0.0.
1403 *
1404 * \sa SDL_GetRenderViewport
1405 * \sa SDL_RenderViewportSet
1406 */
1407extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
1408
1409/**
1410 * Get the drawing area for the current target.
1411 *
1412 * \param renderer the rendering context.
1413 * \param rect an SDL_Rect structure filled in with the current drawing area.
1414 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1415 * for more information.
1416 *
1417 * \since This function is available since SDL 3.0.0.
1418 *
1419 * \sa SDL_RenderViewportSet
1420 * \sa SDL_SetRenderViewport
1421 */
1422extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
1423
1424/**
1425 * Return whether an explicit rectangle was set as the viewport.
1426 *
1427 * This is useful if you're saving and restoring the viewport and want to know
1428 * whether you should restore a specific rectangle or NULL. Note that the
1429 * viewport is always reset when changing rendering targets.
1430 *
1431 * \param renderer the rendering context.
1432 * \returns SDL_TRUE if the viewport was set to a specific rectangle, or
1433 * SDL_FALSE if it was set to NULL (the entire target).
1434 *
1435 * \since This function is available since SDL 3.0.0.
1436 *
1437 * \sa SDL_GetRenderViewport
1438 * \sa SDL_SetRenderViewport
1439 */
1440extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *renderer);
1441
1442/**
1443 * Get the safe area for rendering within the current viewport.
1444 *
1445 * Some devices have portions of the screen which are partially obscured or
1446 * not interactive, possibly due to on-screen controls, curved edges, camera
1447 * notches, TV overscan, etc. This function provides the area of the current
1448 * viewport which is safe to have interactible content. You should continue
1449 * rendering into the rest of the render target, but it should not contain
1450 * visually important or interactible content.
1451 *
1452 * \param renderer the rendering context.
1453 * \param rect a pointer filled in with the area that is safe for interactive
1454 * content.
1455 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1456 * for more information.
1457 *
1458 * \since This function is available since SDL 3.0.0.
1459 */
1460extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect);
1461
1462/**
1463 * Set the clip rectangle for rendering on the specified target.
1464 *
1465 * \param renderer the rendering context.
1466 * \param rect an SDL_Rect structure representing the clip area, relative to
1467 * the viewport, or NULL to disable clipping.
1468 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1469 * for more information.
1470 *
1471 * \since This function is available since SDL 3.0.0.
1472 *
1473 * \sa SDL_GetRenderClipRect
1474 * \sa SDL_RenderClipEnabled
1475 */
1476extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
1477
1478/**
1479 * Get the clip rectangle for the current target.
1480 *
1481 * \param renderer the rendering context.
1482 * \param rect an SDL_Rect structure filled in with the current clipping area
1483 * or an empty rectangle if clipping is disabled.
1484 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1485 * for more information.
1486 *
1487 * \since This function is available since SDL 3.0.0.
1488 *
1489 * \sa SDL_RenderClipEnabled
1490 * \sa SDL_SetRenderClipRect
1491 */
1492extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
1493
1494/**
1495 * Get whether clipping is enabled on the given renderer.
1496 *
1497 * \param renderer the rendering context.
1498 * \returns SDL_TRUE if clipping is enabled or SDL_FALSE if not; call
1499 * SDL_GetError() for more information.
1500 *
1501 * \since This function is available since SDL 3.0.0.
1502 *
1503 * \sa SDL_GetRenderClipRect
1504 * \sa SDL_SetRenderClipRect
1505 */
1506extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderClipEnabled(SDL_Renderer *renderer);
1507
1508/**
1509 * Set the drawing scale for rendering on the current target.
1510 *
1511 * The drawing coordinates are scaled by the x/y scaling factors before they
1512 * are used by the renderer. This allows resolution independent drawing with a
1513 * single coordinate system.
1514 *
1515 * If this results in scaling or subpixel drawing by the rendering backend, it
1516 * will be handled using the appropriate quality hints. For best results use
1517 * integer scaling factors.
1518 *
1519 * \param renderer the rendering context.
1520 * \param scaleX the horizontal scaling factor.
1521 * \param scaleY the vertical scaling factor.
1522 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1523 * for more information.
1524 *
1525 * \since This function is available since SDL 3.0.0.
1526 *
1527 * \sa SDL_GetRenderScale
1528 */
1529extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY);
1530
1531/**
1532 * Get the drawing scale for the current target.
1533 *
1534 * \param renderer the rendering context.
1535 * \param scaleX a pointer filled in with the horizontal scaling factor.
1536 * \param scaleY a pointer filled in with the vertical scaling factor.
1537 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1538 * for more information.
1539 *
1540 * \since This function is available since SDL 3.0.0.
1541 *
1542 * \sa SDL_SetRenderScale
1543 */
1544extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
1545
1546/**
1547 * Set the color used for drawing operations.
1548 *
1549 * Set the color for drawing or filling rectangles, lines, and points, and for
1550 * SDL_RenderClear().
1551 *
1552 * \param renderer the rendering context.
1553 * \param r the red value used to draw on the rendering target.
1554 * \param g the green value used to draw on the rendering target.
1555 * \param b the blue value used to draw on the rendering target.
1556 * \param a the alpha value used to draw on the rendering target; usually
1557 * `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to
1558 * specify how the alpha channel is used.
1559 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1560 * for more information.
1561 *
1562 * \since This function is available since SDL 3.0.0.
1563 *
1564 * \sa SDL_GetRenderDrawColor
1565 * \sa SDL_SetRenderDrawColorFloat
1566 */
1567extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1568
1569/**
1570 * Set the color used for drawing operations (Rect, Line and Clear).
1571 *
1572 * Set the color for drawing or filling rectangles, lines, and points, and for
1573 * SDL_RenderClear().
1574 *
1575 * \param renderer the rendering context.
1576 * \param r the red value used to draw on the rendering target.
1577 * \param g the green value used to draw on the rendering target.
1578 * \param b the blue value used to draw on the rendering target.
1579 * \param a the alpha value used to draw on the rendering target. Use
1580 * SDL_SetRenderDrawBlendMode to specify how the alpha channel is
1581 * used.
1582 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1583 * for more information.
1584 *
1585 * \since This function is available since SDL 3.0.0.
1586 *
1587 * \sa SDL_GetRenderDrawColorFloat
1588 * \sa SDL_SetRenderDrawColor
1589 */
1590extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a);
1591
1592/**
1593 * Get the color used for drawing operations (Rect, Line and Clear).
1594 *
1595 * \param renderer the rendering context.
1596 * \param r a pointer filled in with the red value used to draw on the
1597 * rendering target.
1598 * \param g a pointer filled in with the green value used to draw on the
1599 * rendering target.
1600 * \param b a pointer filled in with the blue value used to draw on the
1601 * rendering target.
1602 * \param a a pointer filled in with the alpha value used to draw on the
1603 * rendering target; usually `SDL_ALPHA_OPAQUE` (255).
1604 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1605 * for more information.
1606 *
1607 * \since This function is available since SDL 3.0.0.
1608 *
1609 * \sa SDL_GetRenderDrawColorFloat
1610 * \sa SDL_SetRenderDrawColor
1611 */
1612extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
1613
1614/**
1615 * Get the color used for drawing operations (Rect, Line and Clear).
1616 *
1617 * \param renderer the rendering context.
1618 * \param r a pointer filled in with the red value used to draw on the
1619 * rendering target.
1620 * \param g a pointer filled in with the green value used to draw on the
1621 * rendering target.
1622 * \param b a pointer filled in with the blue value used to draw on the
1623 * rendering target.
1624 * \param a a pointer filled in with the alpha value used to draw on the
1625 * rendering target.
1626 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1627 * for more information.
1628 *
1629 * \since This function is available since SDL 3.0.0.
1630 *
1631 * \sa SDL_SetRenderDrawColorFloat
1632 * \sa SDL_GetRenderDrawColor
1633 */
1634extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a);
1635
1636/**
1637 * Set the color scale used for render operations.
1638 *
1639 * The color scale is an additional scale multiplied into the pixel color
1640 * value while rendering. This can be used to adjust the brightness of colors
1641 * during HDR rendering, or changing HDR video brightness when playing on an
1642 * SDR display.
1643 *
1644 * The color scale does not affect the alpha channel, only the color
1645 * brightness.
1646 *
1647 * \param renderer the rendering context.
1648 * \param scale the color scale value.
1649 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1650 * for more information.
1651 *
1652 * \since This function is available since SDL 3.0.0.
1653 *
1654 * \sa SDL_GetRenderColorScale
1655 */
1656extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale);
1657
1658/**
1659 * Get the color scale used for render operations.
1660 *
1661 * \param renderer the rendering context.
1662 * \param scale a pointer filled in with the current color scale value.
1663 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1664 * for more information.
1665 *
1666 * \since This function is available since SDL 3.0.0.
1667 *
1668 * \sa SDL_SetRenderColorScale
1669 */
1670extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale);
1671
1672/**
1673 * Set the blend mode used for drawing operations (Fill and Line).
1674 *
1675 * If the blend mode is not supported, the closest supported mode is chosen.
1676 *
1677 * \param renderer the rendering context.
1678 * \param blendMode the SDL_BlendMode to use for blending.
1679 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1680 * for more information.
1681 *
1682 * \since This function is available since SDL 3.0.0.
1683 *
1684 * \sa SDL_GetRenderDrawBlendMode
1685 */
1686extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);
1687
1688/**
1689 * Get the blend mode used for drawing operations.
1690 *
1691 * \param renderer the rendering context.
1692 * \param blendMode a pointer filled in with the current SDL_BlendMode.
1693 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1694 * for more information.
1695 *
1696 * \since This function is available since SDL 3.0.0.
1697 *
1698 * \sa SDL_SetRenderDrawBlendMode
1699 */
1700extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode);
1701
1702/**
1703 * Clear the current rendering target with the drawing color.
1704 *
1705 * This function clears the entire rendering target, ignoring the viewport and
1706 * the clip rectangle. Note, that clearing will also set/fill all pixels of
1707 * the rendering target to current renderer draw color, so make sure to invoke
1708 * SDL_SetRenderDrawColor() when needed.
1709 *
1710 * \param renderer the rendering context.
1711 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1712 * for more information.
1713 *
1714 * \since This function is available since SDL 3.0.0.
1715 *
1716 * \sa SDL_SetRenderDrawColor
1717 */
1718extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderClear(SDL_Renderer *renderer);
1719
1720/**
1721 * Draw a point on the current rendering target at subpixel precision.
1722 *
1723 * \param renderer the renderer which should draw a point.
1724 * \param x the x coordinate of the point.
1725 * \param y the y coordinate of the point.
1726 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1727 * for more information.
1728 *
1729 * \since This function is available since SDL 3.0.0.
1730 *
1731 * \sa SDL_RenderPoints
1732 */
1733extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y);
1734
1735/**
1736 * Draw multiple points on the current rendering target at subpixel precision.
1737 *
1738 * \param renderer the renderer which should draw multiple points.
1739 * \param points the points to draw.
1740 * \param count the number of points to draw.
1741 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1742 * for more information.
1743 *
1744 * \since This function is available since SDL 3.0.0.
1745 *
1746 * \sa SDL_RenderPoint
1747 */
1748extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
1749
1750/**
1751 * Draw a line on the current rendering target at subpixel precision.
1752 *
1753 * \param renderer the renderer which should draw a line.
1754 * \param x1 the x coordinate of the start point.
1755 * \param y1 the y coordinate of the start point.
1756 * \param x2 the x coordinate of the end point.
1757 * \param y2 the y coordinate of the end point.
1758 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1759 * for more information.
1760 *
1761 * \since This function is available since SDL 3.0.0.
1762 *
1763 * \sa SDL_RenderLines
1764 */
1765extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2);
1766
1767/**
1768 * Draw a series of connected lines on the current rendering target at
1769 * subpixel precision.
1770 *
1771 * \param renderer the renderer which should draw multiple lines.
1772 * \param points the points along the lines.
1773 * \param count the number of points, drawing count-1 lines.
1774 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1775 * for more information.
1776 *
1777 * \since This function is available since SDL 3.0.0.
1778 *
1779 * \sa SDL_RenderLine
1780 */
1781extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
1782
1783/**
1784 * Draw a rectangle on the current rendering target at subpixel precision.
1785 *
1786 * \param renderer the renderer which should draw a rectangle.
1787 * \param rect a pointer to the destination rectangle, or NULL to outline the
1788 * entire rendering target.
1789 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1790 * for more information.
1791 *
1792 * \since This function is available since SDL 3.0.0.
1793 *
1794 * \sa SDL_RenderRects
1795 */
1796extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect);
1797
1798/**
1799 * Draw some number of rectangles on the current rendering target at subpixel
1800 * precision.
1801 *
1802 * \param renderer the renderer which should draw multiple rectangles.
1803 * \param rects a pointer to an array of destination rectangles.
1804 * \param count the number of rectangles.
1805 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1806 * for more information.
1807 *
1808 * \since This function is available since SDL 3.0.0.
1809 *
1810 * \sa SDL_RenderRect
1811 */
1812extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
1813
1814/**
1815 * Fill a rectangle on the current rendering target with the drawing color at
1816 * subpixel precision.
1817 *
1818 * \param renderer the renderer which should fill a rectangle.
1819 * \param rect a pointer to the destination rectangle, or NULL for the entire
1820 * rendering target.
1821 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1822 * for more information.
1823 *
1824 * \since This function is available since SDL 3.0.0.
1825 *
1826 * \sa SDL_RenderFillRects
1827 */
1828extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect);
1829
1830/**
1831 * Fill some number of rectangles on the current rendering target with the
1832 * drawing color at subpixel precision.
1833 *
1834 * \param renderer the renderer which should fill multiple rectangles.
1835 * \param rects a pointer to an array of destination rectangles.
1836 * \param count the number of rectangles.
1837 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1838 * for more information.
1839 *
1840 * \since This function is available since SDL 3.0.0.
1841 *
1842 * \sa SDL_RenderFillRect
1843 */
1844extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
1845
1846/**
1847 * Copy a portion of the texture to the current rendering target at subpixel
1848 * precision.
1849 *
1850 * \param renderer the renderer which should copy parts of a texture.
1851 * \param texture the source texture.
1852 * \param srcrect a pointer to the source rectangle, or NULL for the entire
1853 * texture.
1854 * \param dstrect a pointer to the destination rectangle, or NULL for the
1855 * entire rendering target.
1856 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1857 * for more information.
1858 *
1859 * \since This function is available since SDL 3.0.0.
1860 *
1861 * \sa SDL_RenderTextureRotated
1862 * \sa SDL_RenderTextureTiled
1863 */
1864extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);
1865
1866/**
1867 * Copy a portion of the source texture to the current rendering target, with
1868 * rotation and flipping, at subpixel precision.
1869 *
1870 * \param renderer the renderer which should copy parts of a texture.
1871 * \param texture the source texture.
1872 * \param srcrect a pointer to the source rectangle, or NULL for the entire
1873 * texture.
1874 * \param dstrect a pointer to the destination rectangle, or NULL for the
1875 * entire rendering target.
1876 * \param angle an angle in degrees that indicates the rotation that will be
1877 * applied to dstrect, rotating it in a clockwise direction.
1878 * \param center a pointer to a point indicating the point around which
1879 * dstrect will be rotated (if NULL, rotation will be done
1880 * around dstrect.w/2, dstrect.h/2).
1881 * \param flip an SDL_FlipMode value stating which flipping actions should be
1882 * performed on the texture.
1883 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1884 * for more information.
1885 *
1886 * \since This function is available since SDL 3.0.0.
1887 *
1888 * \sa SDL_RenderTexture
1889 */
1890extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
1891 const SDL_FRect *srcrect, const SDL_FRect *dstrect,
1892 const double angle, const SDL_FPoint *center,
1893 const SDL_FlipMode flip);
1894
1895/**
1896 * Tile a portion of the texture to the current rendering target at subpixel
1897 * precision.
1898 *
1899 * The pixels in `srcrect` will be repeated as many times as needed to
1900 * completely fill `dstrect`.
1901 *
1902 * \param renderer the renderer which should copy parts of a texture.
1903 * \param texture the source texture.
1904 * \param srcrect a pointer to the source rectangle, or NULL for the entire
1905 * texture.
1906 * \param scale the scale used to transform srcrect into the destination
1907 * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
1908 * 64x64 tiles.
1909 * \param dstrect a pointer to the destination rectangle, or NULL for the
1910 * entire rendering target.
1911 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1912 * for more information.
1913 *
1914 * \since This function is available since SDL 3.0.0.
1915 *
1916 * \sa SDL_RenderTexture
1917 */
1918extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect);
1919
1920/**
1921 * Perform a scaled copy using the 9-grid algorithm to the current rendering
1922 * target at subpixel precision.
1923 *
1924 * The pixels in the texture are split into a 3x3 grid, using the different
1925 * corner sizes for each corner, and the sides and center making up the
1926 * remaining pixels. The corners are then scaled using `scale` and fit into
1927 * the corners of the destination rectangle. The sides and center are then
1928 * stretched into place to cover the remaining destination rectangle.
1929 *
1930 * \param renderer the renderer which should copy parts of a texture.
1931 * \param texture the source texture.
1932 * \param srcrect the SDL_Rect structure representing the rectangle to be used
1933 * for the 9-grid, or NULL to use the entire texture.
1934 * \param left_width the width, in pixels, of the left corners in `srcrect`.
1935 * \param right_width the width, in pixels, of the right corners in `srcrect`.
1936 * \param top_height the height, in pixels, of the top corners in `srcrect`.
1937 * \param bottom_height the height, in pixels, of the bottom corners in
1938 * `srcrect`.
1939 * \param scale the scale used to transform the corner of `srcrect` into the
1940 * corner of `dstrect`, or 0.0f for an unscaled copy.
1941 * \param dstrect a pointer to the destination rectangle, or NULL for the
1942 * entire rendering target.
1943 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1944 * for more information.
1945 *
1946 * \since This function is available since SDL 3.0.0.
1947 *
1948 * \sa SDL_RenderTexture
1949 */
1950extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect);
1951
1952/**
1953 * Render a list of triangles, optionally using a texture and indices into the
1954 * vertex array Color and alpha modulation is done per vertex
1955 * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
1956 *
1957 * \param renderer the rendering context.
1958 * \param texture (optional) The SDL texture to use.
1959 * \param vertices vertices.
1960 * \param num_vertices number of vertices.
1961 * \param indices (optional) An array of integer indices into the 'vertices'
1962 * array, if NULL all vertices will be rendered in sequential
1963 * order.
1964 * \param num_indices number of indices.
1965 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1966 * for more information.
1967 *
1968 * \since This function is available since SDL 3.0.0.
1969 *
1970 * \sa SDL_RenderGeometryRaw
1971 */
1972extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
1973 SDL_Texture *texture,
1974 const SDL_Vertex *vertices, int num_vertices,
1975 const int *indices, int num_indices);
1976
1977/**
1978 * Render a list of triangles, optionally using a texture and indices into the
1979 * vertex arrays Color and alpha modulation is done per vertex
1980 * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
1981 *
1982 * \param renderer the rendering context.
1983 * \param texture (optional) The SDL texture to use.
1984 * \param xy vertex positions.
1985 * \param xy_stride byte size to move from one element to the next element.
1986 * \param color vertex colors (as SDL_FColor).
1987 * \param color_stride byte size to move from one element to the next element.
1988 * \param uv vertex normalized texture coordinates.
1989 * \param uv_stride byte size to move from one element to the next element.
1990 * \param num_vertices number of vertices.
1991 * \param indices (optional) An array of indices into the 'vertices' arrays,
1992 * if NULL all vertices will be rendered in sequential order.
1993 * \param num_indices number of indices.
1994 * \param size_indices index size: 1 (byte), 2 (short), 4 (int).
1995 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
1996 * for more information.
1997 *
1998 * \since This function is available since SDL 3.0.0.
1999 *
2000 * \sa SDL_RenderGeometry
2001 */
2002extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
2003 SDL_Texture *texture,
2004 const float *xy, int xy_stride,
2005 const SDL_FColor *color, int color_stride,
2006 const float *uv, int uv_stride,
2007 int num_vertices,
2008 const void *indices, int num_indices, int size_indices);
2009
2010/**
2011 * Read pixels from the current rendering target.
2012 *
2013 * The returned surface should be freed with SDL_DestroySurface()
2014 *
2015 * **WARNING**: This is a very slow operation, and should not be used
2016 * frequently. If you're using this on the main rendering target, it should be
2017 * called after rendering and before SDL_RenderPresent().
2018 *
2019 * \param renderer the rendering context.
2020 * \param rect an SDL_Rect structure representing the area in pixels relative
2021 * to the to current viewport, or NULL for the entire viewport.
2022 * \returns a new SDL_Surface on success or NULL on failure; call
2023 * SDL_GetError() for more information.
2024 *
2025 * \since This function is available since SDL 3.0.0.
2026 */
2027extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect);
2028
2029/**
2030 * Update the screen with any rendering performed since the previous call.
2031 *
2032 * SDL's rendering functions operate on a backbuffer; that is, calling a
2033 * rendering function such as SDL_RenderLine() does not directly put a line on
2034 * the screen, but rather updates the backbuffer. As such, you compose your
2035 * entire scene and *present* the composed backbuffer to the screen as a
2036 * complete picture.
2037 *
2038 * Therefore, when using SDL's rendering API, one does all drawing intended
2039 * for the frame, and then calls this function once per frame to present the
2040 * final drawing to the user.
2041 *
2042 * The backbuffer should be considered invalidated after each present; do not
2043 * assume that previous contents will exist between frames. You are strongly
2044 * encouraged to call SDL_RenderClear() to initialize the backbuffer before
2045 * starting each new frame's drawing, even if you plan to overwrite every
2046 * pixel.
2047 *
2048 * Please note, that in case of rendering to a texture - there is **no need**
2049 * to call `SDL_RenderPresent` after drawing needed objects to a texture, you
2050 * are only required to change back the rendering target to default via
2051 * `SDL_SetRenderTarget(renderer, NULL)` afterwards, as textures by themselves
2052 * do not have a concept of backbuffers.
2053 *
2054 * \param renderer the rendering context.
2055 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
2056 * for more information.
2057 *
2058 * \threadsafety You may only call this function on the main thread.
2059 *
2060 * \since This function is available since SDL 3.0.0.
2061 *
2062 * \sa SDL_CreateRenderer
2063 * \sa SDL_RenderClear
2064 * \sa SDL_RenderFillRect
2065 * \sa SDL_RenderFillRects
2066 * \sa SDL_RenderLine
2067 * \sa SDL_RenderLines
2068 * \sa SDL_RenderPoint
2069 * \sa SDL_RenderPoints
2070 * \sa SDL_RenderRect
2071 * \sa SDL_RenderRects
2072 * \sa SDL_SetRenderDrawBlendMode
2073 * \sa SDL_SetRenderDrawColor
2074 */
2075extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPresent(SDL_Renderer *renderer);
2076
2077/**
2078 * Destroy the specified texture.
2079 *
2080 * Passing NULL or an otherwise invalid texture will set the SDL error message
2081 * to "Invalid texture".
2082 *
2083 * \param texture the texture to destroy.
2084 *
2085 * \since This function is available since SDL 3.0.0.
2086 *
2087 * \sa SDL_CreateTexture
2088 * \sa SDL_CreateTextureFromSurface
2089 */
2090extern SDL_DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture *texture);
2091
2092/**
2093 * Destroy the rendering context for a window and free all associated
2094 * textures.
2095 *
2096 * This should be called before destroying the associated window.
2097 *
2098 * \param renderer the rendering context.
2099 *
2100 * \since This function is available since SDL 3.0.0.
2101 *
2102 * \sa SDL_CreateRenderer
2103 */
2104extern SDL_DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer *renderer);
2105
2106/**
2107 * Force the rendering context to flush any pending commands and state.
2108 *
2109 * You do not need to (and in fact, shouldn't) call this function unless you
2110 * are planning to call into OpenGL/Direct3D/Metal/whatever directly, in
2111 * addition to using an SDL_Renderer.
2112 *
2113 * This is for a very-specific case: if you are using SDL's render API, and
2114 * you plan to make OpenGL/D3D/whatever calls in addition to SDL render API
2115 * calls. If this applies, you should call this function between calls to
2116 * SDL's render API and the low-level API you're using in cooperation.
2117 *
2118 * In all other cases, you can ignore this function.
2119 *
2120 * This call makes SDL flush any pending rendering work it was queueing up to
2121 * do later in a single batch, and marks any internal cached state as invalid,
2122 * so it'll prepare all its state again later, from scratch.
2123 *
2124 * This means you do not need to save state in your rendering code to protect
2125 * the SDL renderer. However, there lots of arbitrary pieces of Direct3D and
2126 * OpenGL state that can confuse things; you should use your best judgment and
2127 * be prepared to make changes if specific state needs to be protected.
2128 *
2129 * \param renderer the rendering context.
2130 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
2131 * for more information.
2132 *
2133 * \since This function is available since SDL 3.0.0.
2134 */
2135extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlushRenderer(SDL_Renderer *renderer);
2136
2137/**
2138 * Get the CAMetalLayer associated with the given Metal renderer.
2139 *
2140 * This function returns `void *`, so SDL doesn't have to include Metal's
2141 * headers, but it can be safely cast to a `CAMetalLayer *`.
2142 *
2143 * \param renderer the renderer to query.
2144 * \returns a `CAMetalLayer *` on success, or NULL if the renderer isn't a
2145 * Metal renderer.
2146 *
2147 * \since This function is available since SDL 3.0.0.
2148 *
2149 * \sa SDL_GetRenderMetalCommandEncoder
2150 */
2151extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalLayer(SDL_Renderer *renderer);
2152
2153/**
2154 * Get the Metal command encoder for the current frame.
2155 *
2156 * This function returns `void *`, so SDL doesn't have to include Metal's
2157 * headers, but it can be safely cast to an `id<MTLRenderCommandEncoder>`.
2158 *
2159 * This will return NULL if Metal refuses to give SDL a drawable to render to,
2160 * which might happen if the window is hidden/minimized/offscreen. This
2161 * doesn't apply to command encoders for render targets, just the window's
2162 * backbuffer. Check your return values!
2163 *
2164 * \param renderer the renderer to query.
2165 * \returns an `id<MTLRenderCommandEncoder>` on success, or NULL if the
2166 * renderer isn't a Metal renderer or there was an error.
2167 *
2168 * \since This function is available since SDL 3.0.0.
2169 *
2170 * \sa SDL_GetRenderMetalLayer
2171 */
2172extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer);
2173
2174
2175/**
2176 * Add a set of synchronization semaphores for the current frame.
2177 *
2178 * The Vulkan renderer will wait for `wait_semaphore` before submitting
2179 * rendering commands and signal `signal_semaphore` after rendering commands
2180 * are complete for this frame.
2181 *
2182 * This should be called each frame that you want semaphore synchronization.
2183 * The Vulkan renderer may have multiple frames in flight on the GPU, so you
2184 * should have multiple semaphores that are used for synchronization. Querying
2185 * SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER will give you the
2186 * maximum number of semaphores you'll need.
2187 *
2188 * \param renderer the rendering context.
2189 * \param wait_stage_mask the VkPipelineStageFlags for the wait.
2190 * \param wait_semaphore a VkSempahore to wait on before rendering the current
2191 * frame, or 0 if not needed.
2192 * \param signal_semaphore a VkSempahore that SDL will signal when rendering
2193 * for the current frame is complete, or 0 if not
2194 * needed.
2195 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
2196 * for more information.
2197 *
2198 * \threadsafety It is **NOT** safe to call this function from two threads at
2199 * once.
2200 *
2201 * \since This function is available since SDL 3.0.0.
2202 */
2203extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore);
2204
2205/**
2206 * Toggle VSync of the given renderer.
2207 *
2208 * When a renderer is created, vsync defaults to SDL_RENDERER_VSYNC_DISABLED.
2209 *
2210 * The `vsync` parameter can be 1 to synchronize present with every vertical
2211 * refresh, 2 to synchronize present with every second vertical refresh, etc.,
2212 * SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync),
2213 * or SDL_WINDOW_SURFACE_VSYNC_DISABLED to disable. Not every value is
2214 * supported by every driver, so you should check the return value to see
2215 * whether the requested setting is supported.
2216 *
2217 * \param renderer the renderer to toggle.
2218 * \param vsync the vertical refresh sync interval.
2219 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
2220 * for more information.
2221 *
2222 * \since This function is available since SDL 3.0.0.
2223 *
2224 * \sa SDL_GetRenderVSync
2225 */
2226extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync);
2227
2228#define SDL_RENDERER_VSYNC_DISABLED 0
2229#define SDL_RENDERER_VSYNC_ADAPTIVE (-1)
2230
2231/**
2232 * Get VSync of the given renderer.
2233 *
2234 * \param renderer the renderer to toggle.
2235 * \param vsync an int filled with the current vertical refresh sync interval.
2236 * See SDL_SetRenderVSync() for the meaning of the value.
2237 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
2238 * for more information.
2239 *
2240 * \since This function is available since SDL 3.0.0.
2241 *
2242 * \sa SDL_SetRenderVSync
2243 */
2244extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
2245
2246/* Ends C function definitions when using C++ */
2247#ifdef __cplusplus
2248}
2249#endif
2250#include <SDL3/SDL_close_code.h>
2251
2252#endif /* SDL_render_h_ */
Uint32 SDL_BlendMode
SDL_PixelFormat
Definition SDL_pixels.h:265
Uint32 SDL_PropertiesID
SDL_bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch)
SDL_bool SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY)
void SDL_DestroyTexture(SDL_Texture *texture)
SDL_bool SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
SDL_bool SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
SDL_bool SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
SDL_bool SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
SDL_bool SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event)
SDL_bool SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect)
SDL_Texture * SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props)
struct SDL_Texture SDL_Texture
Definition SDL_render.h:126
SDL_bool SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect)
SDL_Window * SDL_GetRenderWindow(SDL_Renderer *renderer)
SDL_bool SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale)
SDL_bool SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect)
SDL_bool SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode)
void SDL_DestroyRenderer(SDL_Renderer *renderer)
void SDL_UnlockTexture(SDL_Texture *texture)
SDL_Surface * SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
SDL_bool SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
int SDL_GetNumRenderDrivers(void)
SDL_bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip)
SDL_bool SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
SDL_bool SDL_RenderViewportSet(SDL_Renderer *renderer)
SDL_Renderer * SDL_CreateRendererWithProperties(SDL_PropertiesID props)
SDL_bool SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
SDL_bool SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y)
SDL_bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
SDL_bool SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b)
SDL_bool SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY)
SDL_Texture * SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h)
SDL_bool SDL_FlushRenderer(SDL_Renderer *renderer)
SDL_bool SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
SDL_bool SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface)
SDL_Texture * SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface)
SDL_Renderer * SDL_GetRendererFromTexture(SDL_Texture *texture)
SDL_Renderer * SDL_CreateRenderer(SDL_Window *window, const char *name)
SDL_bool SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b)
SDL_TextureAccess
Definition SDL_render.h:94
@ SDL_TEXTUREACCESS_STATIC
Definition SDL_render.h:95
@ SDL_TEXTUREACCESS_STREAMING
Definition SDL_render.h:96
@ SDL_TEXTUREACCESS_TARGET
Definition SDL_render.h:97
SDL_bool SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale)
SDL_bool SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync)
SDL_bool SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync)
SDL_bool SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha)
SDL_Renderer * SDL_CreateSoftwareRenderer(SDL_Surface *surface)
SDL_bool SDL_RenderClipEnabled(SDL_Renderer *renderer)
void * SDL_GetRenderMetalLayer(SDL_Renderer *renderer)
SDL_bool SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y)
SDL_bool SDL_RenderClear(SDL_Renderer *renderer)
SDL_RendererLogicalPresentation
Definition SDL_render.h:106
@ SDL_LOGICAL_PRESENTATION_LETTERBOX
Definition SDL_render.h:109
@ SDL_LOGICAL_PRESENTATION_DISABLED
Definition SDL_render.h:107
@ SDL_LOGICAL_PRESENTATION_OVERSCAN
Definition SDL_render.h:110
@ SDL_LOGICAL_PRESENTATION_STRETCH
Definition SDL_render.h:108
@ SDL_LOGICAL_PRESENTATION_INTEGER_SCALE
Definition SDL_render.h:111
SDL_bool SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha)
SDL_bool SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
SDL_bool SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect)
SDL_bool SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode)
SDL_PropertiesID SDL_GetTextureProperties(SDL_Texture *texture)
SDL_Renderer * SDL_GetRenderer(SDL_Window *window)
SDL_bool SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
const char * SDL_GetRenderDriver(int index)
SDL_bool SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h)
void * SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer)
SDL_bool SDL_RenderPresent(SDL_Renderer *renderer)
struct SDL_Renderer SDL_Renderer
Definition SDL_render.h:119
SDL_bool SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
SDL_bool SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a)
SDL_bool SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2)
SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
SDL_bool SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
SDL_Texture * SDL_GetRenderTarget(SDL_Renderer *renderer)
SDL_bool SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a)
SDL_bool SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
SDL_bool SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
SDL_bool SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha)
SDL_bool SDL_RenderPoint(SDL_Renderer *renderer, float x, float y)
SDL_bool SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Vertex *vertices, int num_vertices, const int *indices, int num_indices)
SDL_bool SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect)
SDL_bool SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect)
SDL_bool SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
SDL_bool SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect)
SDL_bool SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
SDL_bool SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
SDL_bool SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_bool SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
SDL_bool SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect)
SDL_bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
SDL_bool SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect)
SDL_bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha)
SDL_bool SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore)
SDL_bool SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
SDL_bool SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode)
const char * SDL_GetRendererName(SDL_Renderer *renderer)
SDL_bool SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer)
uint8_t Uint8
Definition SDL_stdinc.h:317
int64_t Sint64
Definition SDL_stdinc.h:364
uint32_t Uint32
Definition SDL_stdinc.h:353
bool SDL_bool
Definition SDL_stdinc.h:301
SDL_ScaleMode
Definition SDL_surface.h:72
SDL_FlipMode
Definition SDL_surface.h:83
struct SDL_Window SDL_Window
Definition SDL_video.h:144
Uint64 SDL_WindowFlags
Definition SDL_video.h:158
SDL_FPoint tex_coord
Definition SDL_render.h:85
SDL_FPoint position
Definition SDL_render.h:83
SDL_FColor color
Definition SDL_render.h:84