SDL_render.h 77 KB

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