SDL_render.h 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_render.h
  20. *
  21. * Header file for SDL 2D rendering functions.
  22. *
  23. * This API supports the following features:
  24. * * single pixel points
  25. * * single pixel lines
  26. * * filled rectangles
  27. * * texture images
  28. *
  29. * The primitives may be drawn in opaque, blended, or additive modes.
  30. *
  31. * The texture images may be drawn in opaque, blended, or additive modes.
  32. * They can have an additional color tint or alpha modulation applied to
  33. * them, and may also be stretched with linear interpolation.
  34. *
  35. * This API is designed to accelerate simple 2D operations. You may
  36. * want more functionality such as polygons and particle effects and
  37. * in that case you should use SDL's OpenGL/Direct3D support or one
  38. * of the many good 3D engines.
  39. *
  40. * These functions must be called from the main thread.
  41. * See this bug for details: https://github.com/libsdl-org/SDL/issues/986
  42. */
  43. #ifndef SDL_render_h_
  44. #define SDL_render_h_
  45. #include <SDL3/SDL_stdinc.h>
  46. #include <SDL3/SDL_events.h>
  47. #include <SDL3/SDL_properties.h>
  48. #include <SDL3/SDL_rect.h>
  49. #include <SDL3/SDL_video.h>
  50. #include <SDL3/SDL_begin_code.h>
  51. /* Set up for C function definitions, even when using C++ */
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**
  56. * Flags used when creating a rendering context
  57. */
  58. typedef enum
  59. {
  60. SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
  61. SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
  62. acceleration */
  63. SDL_RENDERER_PRESENTVSYNC = 0x00000004 /**< Present is synchronized
  64. with the refresh rate */
  65. } SDL_RendererFlags;
  66. /**
  67. * Information on the capabilities of a render driver or context.
  68. */
  69. typedef struct SDL_RendererInfo
  70. {
  71. const char *name; /**< The name of the renderer */
  72. Uint32 flags; /**< Supported ::SDL_RendererFlags */
  73. Uint32 num_texture_formats; /**< The number of available texture formats */
  74. Uint32 texture_formats[16]; /**< The available texture formats */
  75. int max_texture_width; /**< The maximum texture width */
  76. int max_texture_height; /**< The maximum texture height */
  77. } SDL_RendererInfo;
  78. /**
  79. * Vertex structure
  80. */
  81. typedef struct SDL_Vertex
  82. {
  83. SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
  84. SDL_Color color; /**< Vertex color */
  85. SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
  86. } SDL_Vertex;
  87. /**
  88. * The access pattern allowed for a texture.
  89. */
  90. typedef enum
  91. {
  92. SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
  93. SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
  94. SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
  95. } SDL_TextureAccess;
  96. /**
  97. * Flip constants for SDL_RenderTextureRotated
  98. */
  99. typedef enum
  100. {
  101. SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
  102. SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
  103. SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
  104. } SDL_RendererFlip;
  105. /**
  106. * How the logical size is mapped to the output
  107. */
  108. typedef enum
  109. {
  110. SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
  111. SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
  112. SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars */
  113. SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
  114. SDL_LOGICAL_PRESENTATION_INTEGER_SCALE /**< The rendered content is scaled up by integer multiples to fit the output resolution */
  115. } SDL_RendererLogicalPresentation;
  116. /**
  117. * A structure representing rendering state
  118. */
  119. struct SDL_Renderer;
  120. typedef struct SDL_Renderer SDL_Renderer;
  121. /**
  122. * An efficient driver-specific representation of pixel data
  123. */
  124. struct SDL_Texture;
  125. typedef struct SDL_Texture SDL_Texture;
  126. /* Function prototypes */
  127. /**
  128. * Get the number of 2D rendering drivers available for the current display.
  129. *
  130. * A render driver is a set of code that handles rendering and texture
  131. * management on a particular display. Normally there is only one, but some
  132. * drivers may have several available with different capabilities.
  133. *
  134. * There may be none if SDL was compiled without render support.
  135. *
  136. * \returns a number >= 0 on success or a negative error code on failure; call
  137. * SDL_GetError() for more information.
  138. *
  139. * \since This function is available since SDL 3.0.0.
  140. *
  141. * \sa SDL_CreateRenderer
  142. * \sa SDL_GetRenderDriver
  143. */
  144. extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
  145. /**
  146. * Use this function to get the name of a built in 2D rendering driver.
  147. *
  148. * The list of rendering drivers is given in the order that they are normally
  149. * initialized by default; the drivers that seem more reasonable to choose
  150. * first (as far as the SDL developers believe) are earlier in the list.
  151. *
  152. * The names of drivers are all simple, low-ASCII identifiers, like "opengl",
  153. * "direct3d12" or "metal". These never have Unicode characters, and are not
  154. * meant to be proper names.
  155. *
  156. * The returned value points to a static, read-only string; do not modify or
  157. * free it!
  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. */
  168. extern DECLSPEC const char *SDLCALL SDL_GetRenderDriver(int index);
  169. /**
  170. * Create a window and default renderer.
  171. *
  172. * \param width the width of the window
  173. * \param height the height of the window
  174. * \param window_flags the flags used to create the window (see
  175. * SDL_CreateWindow())
  176. * \param window a pointer filled with the window, or NULL on error
  177. * \param renderer a pointer filled with the renderer, or NULL on error
  178. * \returns 0 on success or a negative error code on failure; call
  179. * SDL_GetError() for more information.
  180. *
  181. * \since This function is available since SDL 3.0.0.
  182. *
  183. * \sa SDL_CreateRenderer
  184. * \sa SDL_CreateWindow
  185. */
  186. extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer);
  187. /**
  188. * Create a 2D rendering context for a window.
  189. *
  190. * If you want a specific renderer, you can specify its name here. A list of
  191. * available renderers can be obtained by calling SDL_GetRenderDriver multiple
  192. * times, with indices from 0 to SDL_GetNumRenderDrivers()-1. If you don't
  193. * need a specific renderer, specify NULL and SDL will attempt to choose the
  194. * best option for you, based on what is available on the user's system.
  195. *
  196. * By default the rendering size matches the window size in pixels, but you
  197. * can call SDL_SetRenderLogicalPresentation() to change the content size and
  198. * scaling options.
  199. *
  200. * \param window the window where rendering is displayed
  201. * \param name the name of the rendering driver to initialize, or NULL to
  202. * initialize the first one supporting the requested flags
  203. * \param flags 0, or one or more SDL_RendererFlags OR'd together
  204. * \returns a valid rendering context or NULL if there was an error; call
  205. * SDL_GetError() for more information.
  206. *
  207. * \since This function is available since SDL 3.0.0.
  208. *
  209. * \sa SDL_CreateRendererWithProperties
  210. * \sa SDL_CreateSoftwareRenderer
  211. * \sa SDL_DestroyRenderer
  212. * \sa SDL_GetNumRenderDrivers
  213. * \sa SDL_GetRenderDriver
  214. * \sa SDL_GetRendererInfo
  215. */
  216. extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name, Uint32 flags);
  217. /**
  218. * Create a 2D rendering context for a window, with the specified properties.
  219. *
  220. * These are the supported properties:
  221. */
  222. #define SDL_PROPERTY_RENDERER_CREATE_WINDOW_POINTER "window" /* the window where rendering is displayed */
  223. #define SDL_PROPERTY_RENDERER_CREATE_SURFACE_POINTER "surface" /* the surface where rendering is displayed, if you want a software renderer without a window */
  224. #define SDL_PROPERTY_RENDERER_CREATE_NAME_STRING "name" /* the name of the rendering driver to use, if a specific one is desired */
  225. #define SDL_PROPERTY_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN "present_vsync" /* true if you want present synchronized with the refresh rate */
  226. /*
  227. * \param props the properties to use
  228. * \returns a valid rendering context or NULL if there was an error; call
  229. * SDL_GetError() for more information.
  230. *
  231. * \since This function is available since SDL 3.0.0.
  232. *
  233. * \sa SDL_CreateRenderer
  234. * \sa SDL_CreateSoftwareRenderer
  235. * \sa SDL_DestroyRenderer
  236. * \sa SDL_GetRendererInfo
  237. */
  238. /**
  239. * Create a 2D rendering context for a window, with the specified properties.
  240. *
  241. * These are the supported properties:
  242. *
  243. * - "window" (pointer) - the window where rendering is displayed
  244. * - "surface" (pointer) - the surface where rendering is displayed, if you
  245. * want a software renderer without a window
  246. * - "name" (string) - the name of the rendering driver to use, if a specific
  247. * one is desired
  248. * - "present_vsync" (boolean) - true if you want present synchronized with
  249. * the refresh rate
  250. *
  251. * \param props the properties to use
  252. * \returns a valid rendering context or NULL if there was an error; call
  253. * SDL_GetError() for more information.
  254. *
  255. * \since This function is available since SDL 3.0.0.
  256. *
  257. * \sa SDL_CreateRenderer
  258. * \sa SDL_CreateSoftwareRenderer
  259. * \sa SDL_DestroyRenderer
  260. * \sa SDL_GetRendererInfo
  261. */
  262. extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_PropertiesID props);
  263. /**
  264. * Create a 2D software rendering context for a surface.
  265. *
  266. * Two other API which can be used to create SDL_Renderer:
  267. * SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_
  268. * create a software renderer, but they are intended to be used with an
  269. * SDL_Window as the final destination and not an SDL_Surface.
  270. *
  271. * \param surface the SDL_Surface structure representing the surface where
  272. * rendering is done
  273. * \returns a valid rendering context or NULL if there was an error; call
  274. * SDL_GetError() for more information.
  275. *
  276. * \since This function is available since SDL 3.0.0.
  277. *
  278. * \sa SDL_CreateRenderer
  279. * \sa SDL_CreateWindowRenderer
  280. * \sa SDL_DestroyRenderer
  281. */
  282. extern DECLSPEC SDL_Renderer *SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface *surface);
  283. /**
  284. * Get the renderer associated with a window.
  285. *
  286. * \param window the window to query
  287. * \returns the rendering context on success or NULL on failure; call
  288. * SDL_GetError() for more information.
  289. *
  290. * \since This function is available since SDL 3.0.0.
  291. *
  292. * \sa SDL_CreateRenderer
  293. */
  294. extern DECLSPEC SDL_Renderer *SDLCALL SDL_GetRenderer(SDL_Window *window);
  295. /**
  296. * Get the window associated with a renderer.
  297. *
  298. * \param renderer the renderer to query
  299. * \returns the window on success or NULL on failure; call SDL_GetError() for
  300. * more information.
  301. *
  302. * \since This function is available since SDL 3.0.0.
  303. */
  304. extern DECLSPEC SDL_Window *SDLCALL SDL_GetRenderWindow(SDL_Renderer *renderer);
  305. /**
  306. * Get information about a rendering context.
  307. *
  308. * \param renderer the rendering context
  309. * \param info an SDL_RendererInfo structure filled with information about the
  310. * current renderer
  311. * \returns 0 on success or a negative error code on failure; call
  312. * SDL_GetError() for more information.
  313. *
  314. * \since This function is available since SDL 3.0.0.
  315. *
  316. * \sa SDL_CreateRenderer
  317. */
  318. extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info);
  319. /**
  320. * Get the properties associated with a renderer.
  321. *
  322. * The following read-only properties are provided by SDL:
  323. */
  324. #define SDL_PROPERTY_RENDERER_D3D9_DEVICE_POINTER "SDL.renderer.d3d9.device" /* the IDirect3DDevice9 associated with the renderer */
  325. #define SDL_PROPERTY_RENDERER_D3D11_DEVICE_POINTER "SDL.renderer.d3d11.device" /* the ID3D11Device associated with the renderer */
  326. #define SDL_PROPERTY_RENDERER_D3D12_DEVICE_POINTER "SDL.renderer.d3d12.device" /* the ID3D12Device associated with the renderer */
  327. #define SDL_PROPERTY_RENDERER_D3D12_COMMAND_QUEUE_POINTER "SDL.renderer.d3d12.command_queue" /* the ID3D12CommandQueue associated with the renderer */
  328. /*
  329. * \param renderer the rendering context
  330. * \returns a valid property ID on success or 0 on failure; call
  331. * SDL_GetError() for more information.
  332. *
  333. * \since This function is available since SDL 3.0.0.
  334. *
  335. * \sa SDL_GetProperty
  336. * \sa SDL_SetProperty
  337. */
  338. /**
  339. * Get the properties associated with a renderer.
  340. *
  341. * The following read-only properties are provided by SDL:
  342. *
  343. * ```
  344. * "SDL.renderer.d3d9.device" (pointer) - the IDirect3DDevice9 associated with the renderer
  345. * "SDL.renderer.d3d11.device" (pointer) - the ID3D11Device associated with the renderer
  346. * "SDL.renderer.d3d12.device" (pointer) - the ID3D12Device associated with the renderer
  347. * "SDL.renderer.d3d12.command_queue" (pointer) - the ID3D12CommandQueue associated with the renderer
  348. * ```
  349. *
  350. * \param renderer the rendering context
  351. * \returns a valid property ID on success or 0 on failure; call
  352. * SDL_GetError() for more information.
  353. *
  354. * \since This function is available since SDL 3.0.0.
  355. *
  356. * \sa SDL_GetProperty
  357. * \sa SDL_SetProperty
  358. */
  359. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Renderer *renderer);
  360. /**
  361. * Get the output size in pixels of a rendering context.
  362. *
  363. * This returns the true output size in pixels, ignoring any render targets or
  364. * logical size and presentation.
  365. *
  366. * \param renderer the rendering context
  367. * \param w a pointer filled in with the width in pixels
  368. * \param h a pointer filled in with the height in pixels
  369. * \returns 0 on success or a negative error code on failure; call
  370. * SDL_GetError() for more information.
  371. *
  372. * \since This function is available since SDL 3.0.0.
  373. *
  374. * \sa SDL_GetRenderer
  375. */
  376. extern DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  377. /**
  378. * Get the current output size in pixels of a rendering context.
  379. *
  380. * If a rendering target is active, this will return the size of the rendering
  381. * target in pixels, otherwise if a logical size is set, it will return the
  382. * logical size, otherwise it will return the value of
  383. * SDL_GetRenderOutputSize().
  384. *
  385. * \param renderer the rendering context
  386. * \param w a pointer filled in with the current width
  387. * \param h a pointer filled in with the current height
  388. * \returns 0 on success or a negative error code on failure; call
  389. * SDL_GetError() for more information.
  390. *
  391. * \since This function is available since SDL 3.0.0.
  392. *
  393. * \sa SDL_GetRenderOutputSize
  394. * \sa SDL_GetRenderer
  395. */
  396. extern DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  397. /**
  398. * Create a texture for a rendering context.
  399. *
  400. * You can set the texture scaling method by setting
  401. * `SDL_HINT_RENDER_SCALE_QUALITY` before creating the texture.
  402. *
  403. * \param renderer the rendering context
  404. * \param format one of the enumerated values in SDL_PixelFormatEnum
  405. * \param access one of the enumerated values in SDL_TextureAccess
  406. * \param w the width of the texture in pixels
  407. * \param h the height of the texture in pixels
  408. * \returns a pointer to the created texture or NULL if no rendering context
  409. * was active, the format was unsupported, or the width or height
  410. * were out of range; call SDL_GetError() for more information.
  411. *
  412. * \since This function is available since SDL 3.0.0.
  413. *
  414. * \sa SDL_CreateTextureFromSurface
  415. * \sa SDL_CreateTextureWithProperties
  416. * \sa SDL_DestroyTexture
  417. * \sa SDL_QueryTexture
  418. * \sa SDL_UpdateTexture
  419. */
  420. extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h);
  421. /**
  422. * Create a texture from an existing surface.
  423. *
  424. * The surface is not modified or freed by this function.
  425. *
  426. * The SDL_TextureAccess hint for the created texture is
  427. * `SDL_TEXTUREACCESS_STATIC`.
  428. *
  429. * The pixel format of the created texture may be different from the pixel
  430. * format of the surface. Use SDL_QueryTexture() to query the pixel format of
  431. * the texture.
  432. *
  433. * \param renderer the rendering context
  434. * \param surface the SDL_Surface structure containing pixel data used to fill
  435. * the texture
  436. * \returns the created texture or NULL on failure; call SDL_GetError() for
  437. * more information.
  438. *
  439. * \since This function is available since SDL 3.0.0.
  440. *
  441. * \sa SDL_CreateTexture
  442. * \sa SDL_CreateTextureWithProperties
  443. * \sa SDL_DestroyTexture
  444. * \sa SDL_QueryTexture
  445. */
  446. extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
  447. /**
  448. * Create a texture for a rendering context with the specified properties.
  449. *
  450. * These are the supported properties:
  451. */
  452. #define SDL_PROPERTY_TEXTURE_CREATE_FORMAT_NUMBER "format" /* one of the enumerated values in SDL_PixelFormatEnum, defaults to the best RGBA format for the renderer */
  453. #define SDL_PROPERTY_TEXTURE_CREATE_ACCESS_NUMBER "access" /* one of the enumerated values in SDL_TextureAccess, defaults to SDL_TEXTUREACCESS_STATIC */
  454. #define SDL_PROPERTY_TEXTURE_CREATE_WIDTH_NUMBER "width" /* the width of the texture in pixels, required */
  455. #define SDL_PROPERTY_TEXTURE_CREATE_HEIGHT_NUMBER "height" /* the height of the texture in pixels, required */
  456. /*
  457. * With the direct3d11 renderer:
  458. */
  459. #define SDL_PROPERTY_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "d3d11.texture" /* the ID3D11Texture2D associated with the texture, if you want to wrap an existing texture. */
  460. #define SDL_PROPERTY_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER "d3d11.texture_u" /* the ID3D11Texture2D associated with the U plane of a YUV texture, if you want to wrap an existing texture. */
  461. #define SDL_PROPERTY_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER "d3d11.texture_v" /* the ID3D11Texture2D associated with the V plane of a YUV texture, if you want to wrap an existing texture. */
  462. /*
  463. * With the direct3d12 renderer:
  464. */
  465. #define SDL_PROPERTY_TEXTURE_CREATE_D3D12_TEXTURE_POINTER "d3d12.texture" /* the ID3D12Resource associated with the texture, if you want to wrap an existing texture. */
  466. #define SDL_PROPERTY_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER "d3d12.texture_u" /* the ID3D12Resource associated with the U plane of a YUV texture, if you want to wrap an existing texture. */
  467. #define SDL_PROPERTY_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER "d3d12.texture_v" /* the ID3D12Resource associated with the V plane of a YUV texture, if you want to wrap an existing texture. */
  468. /*
  469. * With the opengl renderer:
  470. */
  471. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER "opengl.texture" /* the GLuint texture associated with the texture, if you want to wrap an existing texture. */
  472. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER "opengl.texture_uv" /* the GLuint texture associated with the UV plane of an NV12 texture, if you want to wrap an existing texture. */
  473. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER "opengl.texture_u" /* the GLuint texture associated with the U plane of a YUV texture, if you want to wrap an existing texture. */
  474. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER "opengl.texture_v" /* the GLuint texture associated with the V plane of a YUV texture, if you want to wrap an existing texture. */
  475. /*
  476. * With the opengles2 renderer:
  477. */
  478. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "opengles2.texture" /* the GLuint texture associated with the texture, if you want to wrap an existing texture. */
  479. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "opengles2.texture" /* the GLuint texture associated with the texture, if you want to wrap an existing texture. */
  480. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER "opengles2.texture_uv" /* the GLuint texture associated with the UV plane of an NV12 texture, if you want to wrap an existing texture. */
  481. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER "opengles2.texture_u" /* the GLuint texture associated with the U plane of a YUV texture, if you want to wrap an existing texture. */
  482. #define SDL_PROPERTY_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER "opengles2.texture_v" /* the GLuint texture associated with the V plane of a YUV texture, if you want to wrap an existing texture. */
  483. /*
  484. * \param renderer the rendering context
  485. * \param props the properties to use
  486. * \returns a pointer to the created texture or NULL if no rendering context
  487. * was active, the format was unsupported, or the width or height
  488. * were out of range; call SDL_GetError() for more information.
  489. *
  490. * \since This function is available since SDL 3.0.0.
  491. *
  492. * \sa SDL_CreateTextureFromSurface
  493. * \sa SDL_CreateTexture
  494. * \sa SDL_DestroyTexture
  495. * \sa SDL_QueryTexture
  496. * \sa SDL_UpdateTexture
  497. */
  498. /**
  499. * Create a texture for a rendering context with the specified properties.
  500. *
  501. * These are the supported properties:
  502. *
  503. * - "format" (number) - one of the enumerated values in SDL_PixelFormatEnum,
  504. * defaults to the best RGBA format for the renderer
  505. * - "access" (number) - one of the enumerated values in SDL_TextureAccess,
  506. * defaults to SDL_TEXTUREACCESS_STATIC
  507. * - "width" (number) - the width of the texture in pixels, required
  508. * - "height" (number) - the height of the texture in pixels, required
  509. *
  510. * With the direct3d11 renderer:
  511. *
  512. * - "d3d11.texture" (pointer) - the ID3D11Texture2D associated with the
  513. * texture, if you want to wrap an existing texture.
  514. * - "d3d11.texture_u" (pointer) - the ID3D11Texture2D associated with the U
  515. * plane of a YUV texture, if you want to wrap an existing texture.
  516. * - "d3d11.texture_v" (pointer) - the ID3D11Texture2D associated with the V
  517. * plane of a YUV texture, if you want to wrap an existing texture.
  518. *
  519. * With the direct3d12 renderer:
  520. *
  521. * - "d3d12.texture" (pointer) - the ID3D12Resource associated with the
  522. * texture, if you want to wrap an existing texture.
  523. * - "d3d12.texture_u" (pointer) - the ID3D12Resource associated with the U
  524. * plane of a YUV texture, if you want to wrap an existing texture.
  525. * - "d3d12.texture_v" (pointer) - the ID3D12Resource associated with the V
  526. * plane of a YUV texture, if you want to wrap an existing texture.
  527. *
  528. * With the opengl renderer:
  529. *
  530. * - "opengl.texture" (number) - the GLuint texture associated with the
  531. * texture, if you want to wrap an existing texture.
  532. * - "opengl.texture_uv" (number) - the GLuint texture associated with the UV
  533. * plane of an NV12 texture, if you want to wrap an existing texture.
  534. * - "opengl.texture_u" (number) - the GLuint texture associated with the U
  535. * plane of a YUV texture, if you want to wrap an existing texture.
  536. * - "opengl.texture_v" (number) - the GLuint texture associated with the V
  537. * plane of a YUV texture, if you want to wrap an existing texture.
  538. *
  539. * With the opengles2 renderer:
  540. *
  541. * - "opengles2.texture" (number) - the GLuint texture associated with the
  542. * texture, if you want to wrap an existing texture.
  543. * - "opengles2.texture_uv" (number) - the GLuint texture associated with the
  544. * UV plane of an NV12 texture, if you want to wrap an existing texture.
  545. * - "opengles2.texture_u" (number) - the GLuint texture associated with the U
  546. * plane of a YUV texture, if you want to wrap an existing texture.
  547. * - "opengles2.texture_v" (number) - the GLuint texture associated with the V
  548. * plane of a YUV texture, if you want to wrap an existing texture.
  549. *
  550. * \param renderer the rendering context
  551. * \param props the properties to use
  552. * \returns a pointer to the created texture or NULL if no rendering context
  553. * was active, the format was unsupported, or the width or height
  554. * were out of range; call SDL_GetError() for more information.
  555. *
  556. * \since This function is available since SDL 3.0.0.
  557. *
  558. * \sa SDL_CreateTextureFromSurface
  559. * \sa SDL_CreateTexture
  560. * \sa SDL_DestroyTexture
  561. * \sa SDL_QueryTexture
  562. * \sa SDL_UpdateTexture
  563. */
  564. extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
  565. /**
  566. * Get the properties associated with a texture.
  567. *
  568. * The following read-only properties are provided by SDL:
  569. */
  570. /*
  571. * With the direct3d11 renderer:
  572. */
  573. #define SDL_PROPERTY_TEXTURE_D3D11_TEXTURE_POINTER "SDL.texture.d3d11.texture" /* the ID3D11Texture2D associated with the texture */
  574. #define SDL_PROPERTY_TEXTURE_D3D11_TEXTURE_U_POINTER "SDL.texture.d3d11.texture_u" /* the ID3D11Texture2D associated with the U plane of a YUV texture */
  575. #define SDL_PROPERTY_TEXTURE_D3D11_TEXTURE_V_POINTER "SDL.texture.d3d11.texture_v" /* the ID3D11Texture2D associated with the V plane of a YUV texture */
  576. /*
  577. * With the direct3d12 renderer:
  578. */
  579. #define SDL_PROPERTY_TEXTURE_D3D12_TEXTURE_POINTER "SDL.texture.d3d12.texture" /* the ID3D12Resource associated with the texture */
  580. #define SDL_PROPERTY_TEXTURE_D3D12_TEXTURE_U_POINTER "SDL.texture.d3d12.texture_u" /* the ID3D12Resource associated with the U plane of a YUV texture */
  581. #define SDL_PROPERTY_TEXTURE_D3D12_TEXTURE_V_POINTER "SDL.texture.d3d12.texture_v" /* the ID3D12Resource associated with the V plane of a YUV texture */
  582. /*
  583. * With the opengl renderer:
  584. */
  585. #define SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_NUMBER "SDL.texture.opengl.texture" /* the GLuint texture associated with the texture */
  586. #define SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.opengl.texture_uv" /* the GLuint texture associated with the UV plane of an NV12 texture */
  587. #define SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.opengl.texture_u" /* the GLuint texture associated with the U plane of a YUV texture */
  588. #define SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.opengl.texture_v" /* the GLuint texture associated with the V plane of a YUV texture */
  589. #define SDL_PROPERTY_TEXTURE_OPENGL_TEX_W_FLOAT "SDL.texture.opengl.tex_w" /* the texture coordinate width of the texture (0.0 - 1.0) */
  590. #define SDL_PROPERTY_TEXTURE_OPENGL_TEX_H_FLOAT "SDL.texture.opengl.tex_h" /* the texture coordinate height of the texture (0.0 - 1.0) */
  591. /*
  592. * With the opengles2 renderer:
  593. */
  594. #define SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.opengles2.texture" /* the GLuint texture associated with the texture */
  595. #define SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.opengles2.texture_uv" /* the GLuint texture associated with the UV plane of an NV12 texture */
  596. #define SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.opengles2.texture_u" /* the GLuint texture associated with the U plane of a YUV texture */
  597. #define SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.opengles2.texture_v" /* the GLuint texture associated with the V plane of a YUV texture */
  598. /*
  599. * associated with the V plane of a YUV texture
  600. * \param texture the texture to query
  601. * \returns a valid property ID on success or 0 on failure; call
  602. * SDL_GetError() for more information.
  603. *
  604. * \since This function is available since SDL 3.0.0.
  605. *
  606. * \sa SDL_GetProperty
  607. * \sa SDL_SetProperty
  608. */
  609. /**
  610. * Get the properties associated with a texture.
  611. *
  612. * The following read-only properties are provided by SDL:
  613. *
  614. * With the direct3d11 renderer:
  615. *
  616. * - "SDL.texture.d3d11.texture" (pointer) - the ID3D11Texture2D associated
  617. * with the texture
  618. * - "SDL.texture.d3d11.texture_u" (pointer) - the ID3D11Texture2D associated
  619. * with the U plane of a YUV texture
  620. * - "SDL.texture.d3d11.texture_v" (pointer) - the ID3D11Texture2D associated
  621. * with the V plane of a YUV texture
  622. *
  623. * With the direct3d12 renderer:
  624. *
  625. * - "SDL.texture.d3d12.texture" (pointer) - the ID3D12Resource associated
  626. * with the texture
  627. * - "SDL.texture.d3d12.texture_u" (pointer) - the ID3D12Resource associated
  628. * with the U plane of a YUV texture
  629. * - "SDL.texture.d3d12.texture_v" (pointer) - the ID3D12Resource associated
  630. * with the V plane of a YUV texture
  631. *
  632. * With the opengl renderer:
  633. *
  634. * - "SDL.texture.opengl.texture" (number) - the GLuint texture associated
  635. * with the texture
  636. * - "SDL.texture.opengl.texture_uv" (number) - the GLuint texture associated
  637. * with the UV plane of an NV12 texture
  638. * - "SDL.texture.opengl.texture_u" (number) - the GLuint texture associated
  639. * with the U plane of a YUV texture
  640. * - "SDL.texture.opengl.texture_v" (number) - the GLuint texture associated
  641. * with the V plane of a YUV texture
  642. * - "SDL.texture.opengl.tex_w" (float) - the texture coordinate width of the
  643. * texture (0.0 - 1.0)
  644. * - "SDL.texture.opengl.tex_h" (float) - the texture coordinate height of the
  645. * texture (0.0 - 1.0)
  646. *
  647. * With the opengles2 renderer:
  648. *
  649. * - "SDL.texture.opengles2.texture" (number) - the GLuint texture associated
  650. * with the texture
  651. * - "SDL.texture.opengles2.texture_uv" (number) - the GLuint texture
  652. * associated with the UV plane of an NV12 texture
  653. * - "SDL.texture.opengles2.texture_u" (number) - the GLuint texture
  654. * associated with the U plane of a YUV texture
  655. * - "SDL.texture.opengles2.texture_v" (number) - the GLuint texture
  656. * associated with the V plane of a YUV texture
  657. *
  658. * \param texture the texture to query
  659. * \returns a valid property ID on success or 0 on failure; call
  660. * SDL_GetError() for more information.
  661. *
  662. * \since This function is available since SDL 3.0.0.
  663. *
  664. * \sa SDL_GetProperty
  665. * \sa SDL_SetProperty
  666. */
  667. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
  668. /**
  669. * Get the renderer that created an SDL_Texture.
  670. *
  671. * \param texture the texture to query
  672. * \returns a pointer to the SDL_Renderer that created the texture, or NULL on
  673. * failure; call SDL_GetError() for more information.
  674. *
  675. * \threadsafety It is safe to call this function from any thread.
  676. *
  677. * \since This function is available since SDL 3.0.0.
  678. *
  679. * \sa SDL_CreateTexture
  680. * \sa SDL_CreateTextureFromSurface
  681. * \sa SDL_CreateTextureWithProperties
  682. */
  683. extern DECLSPEC SDL_Renderer *SDLCALL SDL_GetTextureRenderer(SDL_Texture *texture);
  684. /**
  685. * Query the attributes of a texture.
  686. *
  687. * \param texture the texture to query
  688. * \param format a pointer filled in with the raw format of the texture; the
  689. * actual format may differ, but pixel transfers will use this
  690. * format (one of the SDL_PixelFormatEnum values). This argument
  691. * can be NULL if you don't need this information.
  692. * \param access a pointer filled in with the actual access to the texture
  693. * (one of the SDL_TextureAccess values). This argument can be
  694. * NULL if you don't need this information.
  695. * \param w a pointer filled in with the width of the texture in pixels. This
  696. * argument can be NULL if you don't need this information.
  697. * \param h a pointer filled in with the height of the texture in pixels. This
  698. * argument can be NULL if you don't need this information.
  699. * \returns 0 on success or a negative error code on failure; call
  700. * SDL_GetError() for more information.
  701. *
  702. * \since This function is available since SDL 3.0.0.
  703. *
  704. * \sa SDL_CreateTexture
  705. */
  706. extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h);
  707. /**
  708. * Set an additional color value multiplied into render copy operations.
  709. *
  710. * When this texture is rendered, during the copy operation each source color
  711. * channel is modulated by the appropriate color value according to the
  712. * following formula:
  713. *
  714. * `srcC = srcC * (color / 255)`
  715. *
  716. * Color modulation is not always supported by the renderer; it will return -1
  717. * if color modulation is not supported.
  718. *
  719. * \param texture the texture to update
  720. * \param r the red color value multiplied into copy operations
  721. * \param g the green color value multiplied into copy operations
  722. * \param b the blue color value multiplied into copy operations
  723. * \returns 0 on success or a negative error code on failure; call
  724. * SDL_GetError() for more information.
  725. *
  726. * \since This function is available since SDL 3.0.0.
  727. *
  728. * \sa SDL_GetTextureColorMod
  729. * \sa SDL_SetTextureAlphaMod
  730. */
  731. extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
  732. /**
  733. * Get the additional color value multiplied into render copy operations.
  734. *
  735. * \param texture the texture to query
  736. * \param r a pointer filled in with the current red color value
  737. * \param g a pointer filled in with the current green color value
  738. * \param b a pointer filled in with the current blue color value
  739. * \returns 0 on success or a negative error code on failure; call
  740. * SDL_GetError() for more information.
  741. *
  742. * \since This function is available since SDL 3.0.0.
  743. *
  744. * \sa SDL_GetTextureAlphaMod
  745. * \sa SDL_SetTextureColorMod
  746. */
  747. extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b);
  748. /**
  749. * Set an additional alpha value multiplied into render copy operations.
  750. *
  751. * When this texture is rendered, during the copy operation the source alpha
  752. * value is modulated by this alpha value according to the following formula:
  753. *
  754. * `srcA = srcA * (alpha / 255)`
  755. *
  756. * Alpha modulation is not always supported by the renderer; it will return -1
  757. * if alpha modulation is not supported.
  758. *
  759. * \param texture the texture to update
  760. * \param alpha the source alpha value multiplied into copy operations
  761. * \returns 0 on success or a negative error code on failure; call
  762. * SDL_GetError() for more information.
  763. *
  764. * \since This function is available since SDL 3.0.0.
  765. *
  766. * \sa SDL_GetTextureAlphaMod
  767. * \sa SDL_SetTextureColorMod
  768. */
  769. extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
  770. /**
  771. * Get the additional alpha value multiplied into render copy operations.
  772. *
  773. * \param texture the texture to query
  774. * \param alpha a pointer filled in with the current alpha value
  775. * \returns 0 on success or a negative error code on failure; call
  776. * SDL_GetError() for more information.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. *
  780. * \sa SDL_GetTextureColorMod
  781. * \sa SDL_SetTextureAlphaMod
  782. */
  783. extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha);
  784. /**
  785. * Set the blend mode for a texture, used by SDL_RenderTexture().
  786. *
  787. * If the blend mode is not supported, the closest supported mode is chosen
  788. * and this function returns -1.
  789. *
  790. * \param texture the texture to update
  791. * \param blendMode the SDL_BlendMode to use for texture blending
  792. * \returns 0 on success or a negative error code on failure; call
  793. * SDL_GetError() for more information.
  794. *
  795. * \since This function is available since SDL 3.0.0.
  796. *
  797. * \sa SDL_GetTextureBlendMode
  798. * \sa SDL_RenderTexture
  799. */
  800. extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode);
  801. /**
  802. * Get the blend mode used for texture copy operations.
  803. *
  804. * \param texture the texture to query
  805. * \param blendMode a pointer filled in with the current SDL_BlendMode
  806. * \returns 0 on success or a negative error code on failure; call
  807. * SDL_GetError() for more information.
  808. *
  809. * \since This function is available since SDL 3.0.0.
  810. *
  811. * \sa SDL_SetTextureBlendMode
  812. */
  813. extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode);
  814. /**
  815. * Set the scale mode used for texture scale operations.
  816. *
  817. * If the scale mode is not supported, the closest supported mode is chosen.
  818. *
  819. * \param texture The texture to update.
  820. * \param scaleMode the SDL_ScaleMode to use for texture scaling.
  821. * \returns 0 on success or a negative error code on failure; call
  822. * SDL_GetError() for more information.
  823. *
  824. * \since This function is available since SDL 3.0.0.
  825. *
  826. * \sa SDL_GetTextureScaleMode
  827. */
  828. extern DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode);
  829. /**
  830. * Get the scale mode used for texture scale operations.
  831. *
  832. * \param texture the texture to query.
  833. * \param scaleMode a pointer filled in with the current scale mode.
  834. * \returns 0 on success or a negative error code on failure; call
  835. * SDL_GetError() for more information.
  836. *
  837. * \since This function is available since SDL 3.0.0.
  838. *
  839. * \sa SDL_SetTextureScaleMode
  840. */
  841. extern DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode);
  842. /**
  843. * Update the given texture rectangle with new pixel data.
  844. *
  845. * The pixel data must be in the pixel format of the texture. Use
  846. * SDL_QueryTexture() to query the pixel format of the texture.
  847. *
  848. * This is a fairly slow function, intended for use with static textures that
  849. * do not change often.
  850. *
  851. * If the texture is intended to be updated often, it is preferred to create
  852. * the texture as streaming and use the locking functions referenced below.
  853. * While this function will work with streaming textures, for optimization
  854. * reasons you may not get the pixels back if you lock the texture afterward.
  855. *
  856. * \param texture the texture to update
  857. * \param rect an SDL_Rect structure representing the area to update, or NULL
  858. * to update the entire texture
  859. * \param pixels the raw pixel data in the format of the texture
  860. * \param pitch the number of bytes in a row of pixel data, including padding
  861. * between lines
  862. * \returns 0 on success or a negative error code on failure; call
  863. * SDL_GetError() for more information.
  864. *
  865. * \since This function is available since SDL 3.0.0.
  866. *
  867. * \sa SDL_CreateTexture
  868. * \sa SDL_LockTexture
  869. * \sa SDL_UnlockTexture
  870. */
  871. extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch);
  872. /**
  873. * Update a rectangle within a planar YV12 or IYUV texture with new pixel
  874. * data.
  875. *
  876. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  877. * block of Y and U/V planes in the proper order, but this function is
  878. * available if your pixel data is not contiguous.
  879. *
  880. * \param texture the texture to update
  881. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  882. * update the entire texture
  883. * \param Yplane the raw pixel data for the Y plane
  884. * \param Ypitch the number of bytes between rows of pixel data for the Y
  885. * plane
  886. * \param Uplane the raw pixel data for the U plane
  887. * \param Upitch the number of bytes between rows of pixel data for the U
  888. * plane
  889. * \param Vplane the raw pixel data for the V plane
  890. * \param Vpitch the number of bytes between rows of pixel data for the V
  891. * plane
  892. * \returns 0 on success or a negative error code on failure; call
  893. * SDL_GetError() for more information.
  894. *
  895. * \since This function is available since SDL 3.0.0.
  896. *
  897. * \sa SDL_UpdateTexture
  898. */
  899. extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture,
  900. const SDL_Rect *rect,
  901. const Uint8 *Yplane, int Ypitch,
  902. const Uint8 *Uplane, int Upitch,
  903. const Uint8 *Vplane, int Vpitch);
  904. /**
  905. * Update a rectangle within a planar NV12 or NV21 texture with new pixels.
  906. *
  907. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  908. * block of NV12/21 planes in the proper order, but this function is available
  909. * if your pixel data is not contiguous.
  910. *
  911. * \param texture the texture to update
  912. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  913. * update the entire texture.
  914. * \param Yplane the raw pixel data for the Y plane.
  915. * \param Ypitch the number of bytes between rows of pixel data for the Y
  916. * plane.
  917. * \param UVplane the raw pixel data for the UV plane.
  918. * \param UVpitch the number of bytes between rows of pixel data for the UV
  919. * plane.
  920. * \returns 0 on success or a negative error code on failure; call
  921. * SDL_GetError() for more information.
  922. *
  923. * \since This function is available since SDL 3.0.0.
  924. */
  925. extern DECLSPEC int SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture,
  926. const SDL_Rect *rect,
  927. const Uint8 *Yplane, int Ypitch,
  928. const Uint8 *UVplane, int UVpitch);
  929. /**
  930. * Lock a portion of the texture for **write-only** pixel access.
  931. *
  932. * As an optimization, the pixels made available for editing don't necessarily
  933. * contain the old texture data. This is a write-only operation, and if you
  934. * need to keep a copy of the texture data you should do that at the
  935. * application level.
  936. *
  937. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  938. * changes.
  939. *
  940. * \param texture the texture to lock for access, which was created with
  941. * `SDL_TEXTUREACCESS_STREAMING`
  942. * \param rect an SDL_Rect structure representing the area to lock for access;
  943. * NULL to lock the entire texture
  944. * \param pixels this is filled in with a pointer to the locked pixels,
  945. * appropriately offset by the locked area
  946. * \param pitch this is filled in with the pitch of the locked pixels; the
  947. * pitch is the length of one row in bytes
  948. * \returns 0 on success or a negative error code if the texture is not valid
  949. * or was not created with `SDL_TEXTUREACCESS_STREAMING`; call
  950. * SDL_GetError() for more information.
  951. *
  952. * \since This function is available since SDL 3.0.0.
  953. *
  954. * \sa SDL_UnlockTexture
  955. */
  956. extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture *texture,
  957. const SDL_Rect *rect,
  958. void **pixels, int *pitch);
  959. /**
  960. * Lock a portion of the texture for **write-only** pixel access, and expose
  961. * it as a SDL surface.
  962. *
  963. * Besides providing an SDL_Surface instead of raw pixel data, this function
  964. * operates like SDL_LockTexture.
  965. *
  966. * As an optimization, the pixels made available for editing don't necessarily
  967. * contain the old texture data. This is a write-only operation, and if you
  968. * need to keep a copy of the texture data you should do that at the
  969. * application level.
  970. *
  971. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  972. * changes.
  973. *
  974. * The returned surface is freed internally after calling SDL_UnlockTexture()
  975. * or SDL_DestroyTexture(). The caller should not free it.
  976. *
  977. * \param texture the texture to lock for access, which must be created with
  978. * `SDL_TEXTUREACCESS_STREAMING`
  979. * \param rect a pointer to the rectangle to lock for access. If the rect is
  980. * NULL, the entire texture will be locked
  981. * \param surface this is filled in with an SDL surface representing the
  982. * locked area
  983. * \returns 0 on success or a negative error code on failure; call
  984. * SDL_GetError() for more information.
  985. *
  986. * \since This function is available since SDL 3.0.0.
  987. *
  988. * \sa SDL_LockTexture
  989. * \sa SDL_UnlockTexture
  990. */
  991. extern DECLSPEC int SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture,
  992. const SDL_Rect *rect,
  993. SDL_Surface **surface);
  994. /**
  995. * Unlock a texture, uploading the changes to video memory, if needed.
  996. *
  997. * **Warning**: Please note that SDL_LockTexture() is intended to be
  998. * write-only; it will not guarantee the previous contents of the texture will
  999. * be provided. You must fully initialize any area of a texture that you lock
  1000. * before unlocking it, as the pixels might otherwise be uninitialized memory.
  1001. *
  1002. * Which is to say: locking and immediately unlocking a texture can result in
  1003. * corrupted textures, depending on the renderer in use.
  1004. *
  1005. * \param texture a texture locked by SDL_LockTexture()
  1006. *
  1007. * \since This function is available since SDL 3.0.0.
  1008. *
  1009. * \sa SDL_LockTexture
  1010. */
  1011. extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture *texture);
  1012. /**
  1013. * Set a texture as the current rendering target.
  1014. *
  1015. * The default render target is the window for which the renderer was created.
  1016. * To stop rendering to a texture and render to the window again, call this
  1017. * function with a NULL `texture`.
  1018. *
  1019. * \param renderer the rendering context
  1020. * \param texture the targeted texture, which must be created with the
  1021. * `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the
  1022. * window instead of a texture.
  1023. * \returns 0 on success or a negative error code on failure; call
  1024. * SDL_GetError() for more information.
  1025. *
  1026. * \since This function is available since SDL 3.0.0.
  1027. *
  1028. * \sa SDL_GetRenderTarget
  1029. */
  1030. extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture);
  1031. /**
  1032. * Get the current render target.
  1033. *
  1034. * The default render target is the window for which the renderer was created,
  1035. * and is reported a NULL here.
  1036. *
  1037. * \param renderer the rendering context
  1038. * \returns the current render target or NULL for the default render target.
  1039. *
  1040. * \since This function is available since SDL 3.0.0.
  1041. *
  1042. * \sa SDL_SetRenderTarget
  1043. */
  1044. extern DECLSPEC SDL_Texture *SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
  1045. /**
  1046. * Set a device independent resolution and presentation mode for rendering.
  1047. *
  1048. * This function sets the width and height of the logical rendering output. A
  1049. * render target is created at the specified size and used for rendering and
  1050. * then copied to the output during presentation.
  1051. *
  1052. * You can disable logical coordinates by setting the mode to
  1053. * SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel
  1054. * resolution of the output window.
  1055. *
  1056. * You can convert coordinates in an event into rendering coordinates using
  1057. * SDL_ConvertEventToRenderCoordinates().
  1058. *
  1059. * \param renderer the rendering context
  1060. * \param w the width of the logical resolution
  1061. * \param h the height of the logical resolution
  1062. * \param mode the presentation mode used
  1063. * \param scale_mode the scale mode used
  1064. * \returns 0 on success or a negative error code on failure; call
  1065. * SDL_GetError() for more information.
  1066. *
  1067. * \since This function is available since SDL 3.0.0.
  1068. *
  1069. * \sa SDL_ConvertEventToRenderCoordinates
  1070. * \sa SDL_GetRenderLogicalPresentation
  1071. */
  1072. extern DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
  1073. /**
  1074. * Get device independent resolution and presentation mode for rendering.
  1075. *
  1076. * This function gets the width and height of the logical rendering output, or
  1077. * the output size in pixels if a logical resolution is not enabled.
  1078. *
  1079. * \param renderer the rendering context
  1080. * \param w an int to be filled with the width
  1081. * \param h an int to be filled with the height
  1082. * \param mode a pointer filled in with the presentation mode
  1083. * \param scale_mode a pointer filled in with the scale mode
  1084. * \returns 0 on success or a negative error code on failure; call
  1085. * SDL_GetError() for more information.
  1086. *
  1087. * \since This function is available since SDL 3.0.0.
  1088. *
  1089. * \sa SDL_SetRenderLogicalPresentation
  1090. */
  1091. extern DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
  1092. /**
  1093. * Get a point in render coordinates when given a point in window coordinates.
  1094. *
  1095. * \param renderer the rendering context
  1096. * \param window_x the x coordinate in window coordinates
  1097. * \param window_y the y coordinate in window coordinates
  1098. * \param x a pointer filled with the x coordinate in render coordinates
  1099. * \param y a pointer filled with the y coordinate in render coordinates
  1100. * \returns 0 on success or a negative error code on failure; call
  1101. * SDL_GetError() for more information.
  1102. *
  1103. * \since This function is available since SDL 3.0.0.
  1104. *
  1105. * \sa SDL_SetRenderLogicalPresentation
  1106. * \sa SDL_SetRenderScale
  1107. */
  1108. extern DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y);
  1109. /**
  1110. * Get a point in window coordinates when given a point in render coordinates.
  1111. *
  1112. * \param renderer the rendering context
  1113. * \param x the x coordinate in render coordinates
  1114. * \param y the y coordinate in render coordinates
  1115. * \param window_x a pointer filled with the x coordinate in window
  1116. * coordinates
  1117. * \param window_y a pointer filled with the y coordinate in window
  1118. * coordinates
  1119. * \returns 0 on success or a negative error code on failure; call
  1120. * SDL_GetError() for more information.
  1121. *
  1122. * \since This function is available since SDL 3.0.0.
  1123. *
  1124. * \sa SDL_SetRenderLogicalPresentation
  1125. * \sa SDL_SetRenderScale
  1126. */
  1127. extern DECLSPEC int SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y);
  1128. /**
  1129. * Convert the coordinates in an event to render coordinates.
  1130. *
  1131. * Touch coordinates are converted from normalized coordinates in the window
  1132. * to non-normalized rendering coordinates.
  1133. *
  1134. * Once converted, the coordinates may be outside the rendering area.
  1135. *
  1136. * \param renderer the rendering context
  1137. * \param event the event to modify
  1138. * \returns 0 on success or a negative error code on failure; call
  1139. * SDL_GetError() for more information.
  1140. *
  1141. * \since This function is available since SDL 3.0.0.
  1142. *
  1143. * \sa SDL_GetRenderCoordinatesFromWindowCoordinates
  1144. */
  1145. extern DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event);
  1146. /**
  1147. * Set the drawing area for rendering on the current target.
  1148. *
  1149. * \param renderer the rendering context
  1150. * \param rect the SDL_Rect structure representing the drawing area, or NULL
  1151. * to set the viewport to the entire target
  1152. * \returns 0 on success or a negative error code on failure; call
  1153. * SDL_GetError() for more information.
  1154. *
  1155. * \since This function is available since SDL 3.0.0.
  1156. *
  1157. * \sa SDL_GetRenderViewport
  1158. */
  1159. extern DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
  1160. /**
  1161. * Get the drawing area for the current target.
  1162. *
  1163. * \param renderer the rendering context
  1164. * \param rect an SDL_Rect structure filled in with the current drawing area
  1165. * \returns 0 on success or a negative error code on failure; call
  1166. * SDL_GetError() for more information.
  1167. *
  1168. * \since This function is available since SDL 3.0.0.
  1169. *
  1170. * \sa SDL_SetRenderViewport
  1171. */
  1172. extern DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
  1173. /**
  1174. * Set the clip rectangle for rendering on the specified target.
  1175. *
  1176. * \param renderer the rendering context
  1177. * \param rect an SDL_Rect structure representing the clip area, relative to
  1178. * the viewport, or NULL to disable clipping
  1179. * \returns 0 on success or a negative error code on failure; call
  1180. * SDL_GetError() for more information.
  1181. *
  1182. * \since This function is available since SDL 3.0.0.
  1183. *
  1184. * \sa SDL_GetRenderClipRect
  1185. * \sa SDL_RenderClipEnabled
  1186. */
  1187. extern DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
  1188. /**
  1189. * Get the clip rectangle for the current target.
  1190. *
  1191. * \param renderer the rendering context
  1192. * \param rect an SDL_Rect structure filled in with the current clipping area
  1193. * or an empty rectangle if clipping is disabled
  1194. * \returns 0 on success or a negative error code on failure; call
  1195. * SDL_GetError() for more information.
  1196. *
  1197. * \since This function is available since SDL 3.0.0.
  1198. *
  1199. * \sa SDL_RenderClipEnabled
  1200. * \sa SDL_SetRenderClipRect
  1201. */
  1202. extern DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
  1203. /**
  1204. * Get whether clipping is enabled on the given renderer.
  1205. *
  1206. * \param renderer the rendering context
  1207. * \returns SDL_TRUE if clipping is enabled or SDL_FALSE if not; call
  1208. * SDL_GetError() for more information.
  1209. *
  1210. * \since This function is available since SDL 3.0.0.
  1211. *
  1212. * \sa SDL_GetRenderClipRect
  1213. * \sa SDL_SetRenderClipRect
  1214. */
  1215. extern DECLSPEC SDL_bool SDLCALL SDL_RenderClipEnabled(SDL_Renderer *renderer);
  1216. /**
  1217. * Set the drawing scale for rendering on the current target.
  1218. *
  1219. * The drawing coordinates are scaled by the x/y scaling factors before they
  1220. * are used by the renderer. This allows resolution independent drawing with a
  1221. * single coordinate system.
  1222. *
  1223. * If this results in scaling or subpixel drawing by the rendering backend, it
  1224. * will be handled using the appropriate quality hints. For best results use
  1225. * integer scaling factors.
  1226. *
  1227. * \param renderer the rendering context
  1228. * \param scaleX the horizontal scaling factor
  1229. * \param scaleY the vertical scaling factor
  1230. * \returns 0 on success or a negative error code on failure; call
  1231. * SDL_GetError() for more information.
  1232. *
  1233. * \since This function is available since SDL 3.0.0.
  1234. *
  1235. * \sa SDL_GetRenderScale
  1236. */
  1237. extern DECLSPEC int SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY);
  1238. /**
  1239. * Get the drawing scale for the current target.
  1240. *
  1241. * \param renderer the rendering context
  1242. * \param scaleX a pointer filled in with the horizontal scaling factor
  1243. * \param scaleY a pointer filled in with the vertical scaling factor
  1244. * \returns 0 on success or a negative error code on failure; call
  1245. * SDL_GetError() for more information.
  1246. *
  1247. * \since This function is available since SDL 3.0.0.
  1248. *
  1249. * \sa SDL_SetRenderScale
  1250. */
  1251. extern DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
  1252. /**
  1253. * Set the color used for drawing operations (Rect, Line and Clear).
  1254. *
  1255. * Set the color for drawing or filling rectangles, lines, and points, and for
  1256. * SDL_RenderClear().
  1257. *
  1258. * \param renderer the rendering context
  1259. * \param r the red value used to draw on the rendering target
  1260. * \param g the green value used to draw on the rendering target
  1261. * \param b the blue value used to draw on the rendering target
  1262. * \param a the alpha value used to draw on the rendering target; usually
  1263. * `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to
  1264. * specify how the alpha channel is used
  1265. * \returns 0 on success or a negative error code on failure; call
  1266. * SDL_GetError() for more information.
  1267. *
  1268. * \since This function is available since SDL 3.0.0.
  1269. *
  1270. * \sa SDL_GetRenderDrawColor
  1271. * \sa SDL_RenderClear
  1272. * \sa SDL_RenderLine
  1273. * \sa SDL_RenderLines
  1274. * \sa SDL_RenderPoint
  1275. * \sa SDL_RenderPoints
  1276. * \sa SDL_RenderRect
  1277. * \sa SDL_RenderRects
  1278. * \sa SDL_RenderFillRect
  1279. * \sa SDL_RenderFillRects
  1280. */
  1281. extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1282. /**
  1283. * Get the color used for drawing operations (Rect, Line and Clear).
  1284. *
  1285. * \param renderer the rendering context
  1286. * \param r a pointer filled in with the red value used to draw on the
  1287. * rendering target
  1288. * \param g a pointer filled in with the green value used to draw on the
  1289. * rendering target
  1290. * \param b a pointer filled in with the blue value used to draw on the
  1291. * rendering target
  1292. * \param a a pointer filled in with the alpha value used to draw on the
  1293. * rendering target; usually `SDL_ALPHA_OPAQUE` (255)
  1294. * \returns 0 on success or a negative error code on failure; call
  1295. * SDL_GetError() for more information.
  1296. *
  1297. * \since This function is available since SDL 3.0.0.
  1298. *
  1299. * \sa SDL_SetRenderDrawColor
  1300. */
  1301. extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1302. /**
  1303. * Set the blend mode used for drawing operations (Fill and Line).
  1304. *
  1305. * If the blend mode is not supported, the closest supported mode is chosen.
  1306. *
  1307. * \param renderer the rendering context
  1308. * \param blendMode the SDL_BlendMode to use for blending
  1309. * \returns 0 on success or a negative error code on failure; call
  1310. * SDL_GetError() for more information.
  1311. *
  1312. * \since This function is available since SDL 3.0.0.
  1313. *
  1314. * \sa SDL_GetRenderDrawBlendMode
  1315. * \sa SDL_RenderLine
  1316. * \sa SDL_RenderLines
  1317. * \sa SDL_RenderPoint
  1318. * \sa SDL_RenderPoints
  1319. * \sa SDL_RenderRect
  1320. * \sa SDL_RenderRects
  1321. * \sa SDL_RenderFillRect
  1322. * \sa SDL_RenderFillRects
  1323. */
  1324. extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);
  1325. /**
  1326. * Get the blend mode used for drawing operations.
  1327. *
  1328. * \param renderer the rendering context
  1329. * \param blendMode a pointer filled in with the current SDL_BlendMode
  1330. * \returns 0 on success or a negative error code on failure; call
  1331. * SDL_GetError() for more information.
  1332. *
  1333. * \since This function is available since SDL 3.0.0.
  1334. *
  1335. * \sa SDL_SetRenderDrawBlendMode
  1336. */
  1337. extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode);
  1338. /**
  1339. * Clear the current rendering target with the drawing color.
  1340. *
  1341. * This function clears the entire rendering target, ignoring the viewport and
  1342. * the clip rectangle.
  1343. *
  1344. * \param renderer the rendering context
  1345. * \returns 0 on success or a negative error code on failure; call
  1346. * SDL_GetError() for more information.
  1347. *
  1348. * \since This function is available since SDL 3.0.0.
  1349. *
  1350. * \sa SDL_SetRenderDrawColor
  1351. */
  1352. extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer *renderer);
  1353. /**
  1354. * Draw a point on the current rendering target at subpixel precision.
  1355. *
  1356. * \param renderer The renderer which should draw a point.
  1357. * \param x The x coordinate of the point.
  1358. * \param y The y coordinate of the point.
  1359. * \returns 0 on success, or -1 on error
  1360. *
  1361. * \since This function is available since SDL 3.0.0.
  1362. */
  1363. extern DECLSPEC int SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y);
  1364. /**
  1365. * Draw multiple points on the current rendering target at subpixel precision.
  1366. *
  1367. * \param renderer The renderer which should draw multiple points.
  1368. * \param points The points to draw
  1369. * \param count The number of points to draw
  1370. * \returns 0 on success or a negative error code on failure; call
  1371. * SDL_GetError() for more information.
  1372. *
  1373. * \since This function is available since SDL 3.0.0.
  1374. */
  1375. extern DECLSPEC int SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  1376. /**
  1377. * Draw a line on the current rendering target at subpixel precision.
  1378. *
  1379. * \param renderer The renderer which should draw a line.
  1380. * \param x1 The x coordinate of the start point.
  1381. * \param y1 The y coordinate of the start point.
  1382. * \param x2 The x coordinate of the end point.
  1383. * \param y2 The y coordinate of the end point.
  1384. * \returns 0 on success, or -1 on error
  1385. *
  1386. * \since This function is available since SDL 3.0.0.
  1387. */
  1388. extern DECLSPEC int SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2);
  1389. /**
  1390. * Draw a series of connected lines on the current rendering target at
  1391. * subpixel precision.
  1392. *
  1393. * \param renderer The renderer which should draw multiple lines.
  1394. * \param points The points along the lines
  1395. * \param count The number of points, drawing count-1 lines
  1396. * \returns 0 on success or a negative error code on failure; call
  1397. * SDL_GetError() for more information.
  1398. *
  1399. * \since This function is available since SDL 3.0.0.
  1400. */
  1401. extern DECLSPEC int SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  1402. /**
  1403. * Draw a rectangle on the current rendering target at subpixel precision.
  1404. *
  1405. * \param renderer The renderer which should draw a rectangle.
  1406. * \param rect A pointer to the destination rectangle, or NULL to outline the
  1407. * entire rendering target.
  1408. * \returns 0 on success, or -1 on error
  1409. *
  1410. * \since This function is available since SDL 3.0.0.
  1411. */
  1412. extern DECLSPEC int SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  1413. /**
  1414. * Draw some number of rectangles on the current rendering target at subpixel
  1415. * precision.
  1416. *
  1417. * \param renderer The renderer which should draw multiple rectangles.
  1418. * \param rects A pointer to an array of destination rectangles.
  1419. * \param count The number of rectangles.
  1420. * \returns 0 on success or a negative error code on failure; call
  1421. * SDL_GetError() for more information.
  1422. *
  1423. * \since This function is available since SDL 3.0.0.
  1424. */
  1425. extern DECLSPEC int SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  1426. /**
  1427. * Fill a rectangle on the current rendering target with the drawing color at
  1428. * subpixel precision.
  1429. *
  1430. * \param renderer The renderer which should fill a rectangle.
  1431. * \param rect A pointer to the destination rectangle, or NULL for the entire
  1432. * rendering target.
  1433. * \returns 0 on success, or -1 on error
  1434. *
  1435. * \since This function is available since SDL 3.0.0.
  1436. */
  1437. extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  1438. /**
  1439. * Fill some number of rectangles on the current rendering target with the
  1440. * drawing color at subpixel precision.
  1441. *
  1442. * \param renderer The renderer which should fill multiple rectangles.
  1443. * \param rects A pointer to an array of destination rectangles.
  1444. * \param count The number of rectangles.
  1445. * \returns 0 on success or a negative error code on failure; call
  1446. * SDL_GetError() for more information.
  1447. *
  1448. * \since This function is available since SDL 3.0.0.
  1449. */
  1450. extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  1451. /**
  1452. * Copy a portion of the texture to the current rendering target at subpixel
  1453. * precision.
  1454. *
  1455. * \param renderer The renderer which should copy parts of a texture.
  1456. * \param texture The source texture.
  1457. * \param srcrect A pointer to the source rectangle, or NULL for the entire
  1458. * texture.
  1459. * \param dstrect A pointer to the destination rectangle, or NULL for the
  1460. * entire rendering target.
  1461. * \returns 0 on success, or -1 on error
  1462. *
  1463. * \since This function is available since SDL 3.0.0.
  1464. */
  1465. extern DECLSPEC int SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);
  1466. /**
  1467. * Copy a portion of the source texture to the current rendering target, with
  1468. * rotation and flipping, at subpixel precision.
  1469. *
  1470. * \param renderer The renderer which should copy parts of a texture.
  1471. * \param texture The source texture.
  1472. * \param srcrect A pointer to the source rectangle, or NULL for the entire
  1473. * texture.
  1474. * \param dstrect A pointer to the destination rectangle, or NULL for the
  1475. * entire rendering target.
  1476. * \param angle An angle in degrees that indicates the rotation that will be
  1477. * applied to dstrect, rotating it in a clockwise direction
  1478. * \param center A pointer to a point indicating the point around which
  1479. * dstrect will be rotated (if NULL, rotation will be done
  1480. * around dstrect.w/2, dstrect.h/2).
  1481. * \param flip An SDL_RendererFlip value stating which flipping actions should
  1482. * be performed on the texture
  1483. * \returns 0 on success or a negative error code on failure; call
  1484. * SDL_GetError() for more information.
  1485. *
  1486. * \since This function is available since SDL 3.0.0.
  1487. */
  1488. extern DECLSPEC int SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
  1489. const SDL_FRect *srcrect, const SDL_FRect *dstrect,
  1490. const double angle, const SDL_FPoint *center,
  1491. const SDL_RendererFlip flip);
  1492. /**
  1493. * Render a list of triangles, optionally using a texture and indices into the
  1494. * vertex array Color and alpha modulation is done per vertex
  1495. * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
  1496. *
  1497. * \param renderer The rendering context.
  1498. * \param texture (optional) The SDL texture to use.
  1499. * \param vertices Vertices.
  1500. * \param num_vertices Number of vertices.
  1501. * \param indices (optional) An array of integer indices into the 'vertices'
  1502. * array, if NULL all vertices will be rendered in sequential
  1503. * order.
  1504. * \param num_indices Number of indices.
  1505. * \returns 0 on success, or -1 if the operation is not supported
  1506. *
  1507. * \since This function is available since SDL 3.0.0.
  1508. *
  1509. * \sa SDL_RenderGeometryRaw
  1510. * \sa SDL_Vertex
  1511. */
  1512. extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
  1513. SDL_Texture *texture,
  1514. const SDL_Vertex *vertices, int num_vertices,
  1515. const int *indices, int num_indices);
  1516. /**
  1517. * Render a list of triangles, optionally using a texture and indices into the
  1518. * vertex arrays Color and alpha modulation is done per vertex
  1519. * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
  1520. *
  1521. * \param renderer The rendering context.
  1522. * \param texture (optional) The SDL texture to use.
  1523. * \param xy Vertex positions
  1524. * \param xy_stride Byte size to move from one element to the next element
  1525. * \param color Vertex colors (as SDL_Color)
  1526. * \param color_stride Byte size to move from one element to the next element
  1527. * \param uv Vertex normalized texture coordinates
  1528. * \param uv_stride Byte size to move from one element to the next element
  1529. * \param num_vertices Number of vertices.
  1530. * \param indices (optional) An array of indices into the 'vertices' arrays,
  1531. * if NULL all vertices will be rendered in sequential order.
  1532. * \param num_indices Number of indices.
  1533. * \param size_indices Index size: 1 (byte), 2 (short), 4 (int)
  1534. * \returns 0 on success or a negative error code on failure; call
  1535. * SDL_GetError() for more information.
  1536. *
  1537. * \since This function is available since SDL 3.0.0.
  1538. *
  1539. * \sa SDL_RenderGeometry
  1540. * \sa SDL_Vertex
  1541. */
  1542. extern DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
  1543. SDL_Texture *texture,
  1544. const float *xy, int xy_stride,
  1545. const SDL_Color *color, int color_stride,
  1546. const float *uv, int uv_stride,
  1547. int num_vertices,
  1548. const void *indices, int num_indices, int size_indices);
  1549. /**
  1550. * Read pixels from the current rendering target to an array of pixels.
  1551. *
  1552. * **WARNING**: This is a very slow operation, and should not be used
  1553. * frequently. If you're using this on the main rendering target, it should be
  1554. * called after rendering and before SDL_RenderPresent().
  1555. *
  1556. * `pitch` specifies the number of bytes between rows in the destination
  1557. * `pixels` data. This allows you to write to a subrectangle or have padded
  1558. * rows in the destination. Generally, `pitch` should equal the number of
  1559. * pixels per row in the `pixels` data times the number of bytes per pixel,
  1560. * but it might contain additional padding (for example, 24bit RGB Windows
  1561. * Bitmap data pads all rows to multiples of 4 bytes).
  1562. *
  1563. * \param renderer the rendering context
  1564. * \param rect an SDL_Rect structure representing the area in pixels relative
  1565. * to the to current viewport, or NULL for the entire viewport
  1566. * \param format an SDL_PixelFormatEnum value of the desired format of the
  1567. * pixel data, or 0 to use the format of the rendering target
  1568. * \param pixels a pointer to the pixel data to copy into
  1569. * \param pitch the pitch of the `pixels` parameter
  1570. * \returns 0 on success or a negative error code on failure; call
  1571. * SDL_GetError() for more information.
  1572. *
  1573. * \since This function is available since SDL 3.0.0.
  1574. */
  1575. extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer *renderer,
  1576. const SDL_Rect *rect,
  1577. Uint32 format,
  1578. void *pixels, int pitch);
  1579. /**
  1580. * Update the screen with any rendering performed since the previous call.
  1581. *
  1582. * SDL's rendering functions operate on a backbuffer; that is, calling a
  1583. * rendering function such as SDL_RenderLine() does not directly put a line on
  1584. * the screen, but rather updates the backbuffer. As such, you compose your
  1585. * entire scene and *present* the composed backbuffer to the screen as a
  1586. * complete picture.
  1587. *
  1588. * Therefore, when using SDL's rendering API, one does all drawing intended
  1589. * for the frame, and then calls this function once per frame to present the
  1590. * final drawing to the user.
  1591. *
  1592. * The backbuffer should be considered invalidated after each present; do not
  1593. * assume that previous contents will exist between frames. You are strongly
  1594. * encouraged to call SDL_RenderClear() to initialize the backbuffer before
  1595. * starting each new frame's drawing, even if you plan to overwrite every
  1596. * pixel.
  1597. *
  1598. * \param renderer the rendering context
  1599. * \returns 0 on success or a negative error code on failure; call
  1600. * SDL_GetError() for more information.
  1601. *
  1602. * \threadsafety You may only call this function on the main thread.
  1603. *
  1604. * \since This function is available since SDL 3.0.0.
  1605. *
  1606. * \sa SDL_RenderClear
  1607. * \sa SDL_RenderLine
  1608. * \sa SDL_RenderLines
  1609. * \sa SDL_RenderPoint
  1610. * \sa SDL_RenderPoints
  1611. * \sa SDL_RenderRect
  1612. * \sa SDL_RenderRects
  1613. * \sa SDL_RenderFillRect
  1614. * \sa SDL_RenderFillRects
  1615. * \sa SDL_SetRenderDrawBlendMode
  1616. * \sa SDL_SetRenderDrawColor
  1617. */
  1618. extern DECLSPEC int SDLCALL SDL_RenderPresent(SDL_Renderer *renderer);
  1619. /**
  1620. * Destroy the specified texture.
  1621. *
  1622. * Passing NULL or an otherwise invalid texture will set the SDL error message
  1623. * to "Invalid texture".
  1624. *
  1625. * \param texture the texture to destroy
  1626. *
  1627. * \since This function is available since SDL 3.0.0.
  1628. *
  1629. * \sa SDL_CreateTexture
  1630. * \sa SDL_CreateTextureFromSurface
  1631. */
  1632. extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture *texture);
  1633. /**
  1634. * Destroy the rendering context for a window and free associated textures.
  1635. *
  1636. * If `renderer` is NULL, this function will return immediately after setting
  1637. * the SDL error message to "Invalid renderer". See SDL_GetError().
  1638. *
  1639. * \param renderer the rendering context
  1640. *
  1641. * \since This function is available since SDL 3.0.0.
  1642. *
  1643. * \sa SDL_CreateRenderer
  1644. */
  1645. extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer *renderer);
  1646. /**
  1647. * Force the rendering context to flush any pending commands and state.
  1648. *
  1649. * You do not need to (and in fact, shouldn't) call this function unless you
  1650. * are planning to call into OpenGL/Direct3D/Metal/whatever directly, in
  1651. * addition to using an SDL_Renderer.
  1652. *
  1653. * This is for a very-specific case: if you are using SDL's render API, and
  1654. * you plan to make OpenGL/D3D/whatever calls in addition to SDL render API
  1655. * calls. If this applies, you should call this function between calls to
  1656. * SDL's render API and the low-level API you're using in cooperation.
  1657. *
  1658. * In all other cases, you can ignore this function.
  1659. *
  1660. * This call makes SDL flush any pending rendering work it was queueing up to
  1661. * do later in a single batch, and marks any internal cached state as invalid,
  1662. * so it'll prepare all its state again later, from scratch.
  1663. *
  1664. * This means you do not need to save state in your rendering code to protect
  1665. * the SDL renderer. However, there lots of arbitrary pieces of Direct3D and
  1666. * OpenGL state that can confuse things; you should use your best judgement
  1667. * and be prepared to make changes if specific state needs to be protected.
  1668. *
  1669. * \param renderer the rendering context
  1670. * \returns 0 on success or a negative error code on failure; call
  1671. * SDL_GetError() for more information.
  1672. *
  1673. * \since This function is available since SDL 3.0.0.
  1674. */
  1675. extern DECLSPEC int SDLCALL SDL_FlushRenderer(SDL_Renderer *renderer);
  1676. /**
  1677. * Get the CAMetalLayer associated with the given Metal renderer.
  1678. *
  1679. * This function returns `void *`, so SDL doesn't have to include Metal's
  1680. * headers, but it can be safely cast to a `CAMetalLayer *`.
  1681. *
  1682. * \param renderer The renderer to query
  1683. * \returns a `CAMetalLayer *` on success, or NULL if the renderer isn't a
  1684. * Metal renderer
  1685. *
  1686. * \since This function is available since SDL 3.0.0.
  1687. *
  1688. * \sa SDL_GetRenderMetalCommandEncoder
  1689. */
  1690. extern DECLSPEC void *SDLCALL SDL_GetRenderMetalLayer(SDL_Renderer *renderer);
  1691. /**
  1692. * Get the Metal command encoder for the current frame
  1693. *
  1694. * This function returns `void *`, so SDL doesn't have to include Metal's
  1695. * headers, but it can be safely cast to an `id<MTLRenderCommandEncoder>`.
  1696. *
  1697. * Note that as of SDL 2.0.18, this will return NULL if Metal refuses to give
  1698. * SDL a drawable to render to, which might happen if the window is
  1699. * hidden/minimized/offscreen. This doesn't apply to command encoders for
  1700. * render targets, just the window's backbuffer. Check your return values!
  1701. *
  1702. * \param renderer The renderer to query
  1703. * \returns an `id<MTLRenderCommandEncoder>` on success, or NULL if the
  1704. * renderer isn't a Metal renderer or there was an error.
  1705. *
  1706. * \since This function is available since SDL 3.0.0.
  1707. *
  1708. * \sa SDL_GetRenderMetalLayer
  1709. */
  1710. extern DECLSPEC void *SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer);
  1711. /**
  1712. * Toggle VSync of the given renderer.
  1713. *
  1714. * \param renderer The renderer to toggle
  1715. * \param vsync 1 for on, 0 for off. All other values are reserved
  1716. * \returns 0 on success or a negative error code on failure; call
  1717. * SDL_GetError() for more information.
  1718. *
  1719. * \since This function is available since SDL 3.0.0.
  1720. */
  1721. extern DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync);
  1722. /**
  1723. * Get VSync of the given renderer.
  1724. *
  1725. * \param renderer The renderer to toggle
  1726. * \param vsync an int filled with 1 for on, 0 for off. All other values are
  1727. * reserved
  1728. * \returns 0 on success or a negative error code on failure; call
  1729. * SDL_GetError() for more information.
  1730. *
  1731. * \since This function is available since SDL 3.0.0.
  1732. */
  1733. extern DECLSPEC int SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
  1734. /* Ends C function definitions when using C++ */
  1735. #ifdef __cplusplus
  1736. }
  1737. #endif
  1738. #include <SDL3/SDL_close_code.h>
  1739. #endif /* SDL_render_h_ */