SDL_render.h 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryRender
  20. *
  21. * Header file for SDL 2D rendering functions.
  22. *
  23. * This API supports the following features:
  24. *
  25. * - single pixel points
  26. * - single pixel lines
  27. * - filled rectangles
  28. * - texture images
  29. * - 2D polygons
  30. *
  31. * The primitives may be drawn in opaque, blended, or additive modes.
  32. *
  33. * The texture images may be drawn in opaque, blended, or additive modes. They
  34. * can have an additional color tint or alpha modulation applied to them, and
  35. * may also be stretched with linear interpolation.
  36. *
  37. * This API is designed to accelerate simple 2D operations. You may want more
  38. * functionality such as 3D polygons and particle effects, and in that case
  39. * you should use SDL's OpenGL/Direct3D support, the SDL3 GPU API, or one of
  40. * the many good 3D engines.
  41. *
  42. * These functions must be called from the main thread. See this bug for
  43. * details: https://github.com/libsdl-org/SDL/issues/986
  44. */
  45. #ifndef SDL_render_h_
  46. #define SDL_render_h_
  47. #include <SDL3/SDL_stdinc.h>
  48. #include <SDL3/SDL_blendmode.h>
  49. #include <SDL3/SDL_error.h>
  50. #include <SDL3/SDL_events.h>
  51. #include <SDL3/SDL_pixels.h>
  52. #include <SDL3/SDL_properties.h>
  53. #include <SDL3/SDL_rect.h>
  54. #include <SDL3/SDL_surface.h>
  55. #include <SDL3/SDL_video.h>
  56. #include <SDL3/SDL_gpu.h>
  57. #include <SDL3/SDL_begin_code.h>
  58. /* Set up for C function definitions, even when using C++ */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /**
  63. * The name of the software renderer.
  64. *
  65. * \since This macro is available since SDL 3.2.0.
  66. */
  67. #define SDL_SOFTWARE_RENDERER "software"
  68. /**
  69. * The name of the GPU renderer.
  70. *
  71. * \since This macro is available since SDL 3.4.0.
  72. */
  73. #define SDL_GPU_RENDERER "gpu"
  74. /**
  75. * Vertex structure.
  76. *
  77. * \since This struct is available since SDL 3.2.0.
  78. */
  79. typedef struct SDL_Vertex
  80. {
  81. SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
  82. SDL_FColor color; /**< Vertex color */
  83. SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
  84. } SDL_Vertex;
  85. /**
  86. * The access pattern allowed for a texture.
  87. *
  88. * \since This enum is available since SDL 3.2.0.
  89. */
  90. typedef enum SDL_TextureAccess
  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. * The addressing mode for a texture when used in SDL_RenderGeometry().
  98. *
  99. * This affects how texture coordinates are interpreted outside of [0, 1]
  100. *
  101. * Texture wrapping is always supported for power of two texture sizes, and is
  102. * supported for other texture sizes if
  103. * SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN is set to true.
  104. *
  105. * \since This enum is available since SDL 3.4.0.
  106. */
  107. typedef enum SDL_TextureAddressMode
  108. {
  109. SDL_TEXTURE_ADDRESS_INVALID = -1,
  110. SDL_TEXTURE_ADDRESS_AUTO, /**< Wrapping is enabled if texture coordinates are outside [0, 1], this is the default */
  111. SDL_TEXTURE_ADDRESS_CLAMP, /**< Texture coordinates are clamped to the [0, 1] range */
  112. SDL_TEXTURE_ADDRESS_WRAP /**< The texture is repeated (tiled) */
  113. } SDL_TextureAddressMode;
  114. /**
  115. * How the logical size is mapped to the output.
  116. *
  117. * \since This enum is available since SDL 3.2.0.
  118. */
  119. typedef enum SDL_RendererLogicalPresentation
  120. {
  121. SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
  122. SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
  123. SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with the clear color */
  124. SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
  125. SDL_LOGICAL_PRESENTATION_INTEGER_SCALE /**< The rendered content is scaled up by integer multiples to fit the output resolution */
  126. } SDL_RendererLogicalPresentation;
  127. /**
  128. * A structure representing rendering state
  129. *
  130. * \since This struct is available since SDL 3.2.0.
  131. */
  132. typedef struct SDL_Renderer SDL_Renderer;
  133. #ifndef SDL_INTERNAL
  134. /**
  135. * An efficient driver-specific representation of pixel data
  136. *
  137. * \since This struct is available since SDL 3.2.0.
  138. *
  139. * \sa SDL_CreateTexture
  140. * \sa SDL_CreateTextureFromSurface
  141. * \sa SDL_CreateTextureWithProperties
  142. * \sa SDL_DestroyTexture
  143. */
  144. struct SDL_Texture
  145. {
  146. SDL_PixelFormat format; /**< The format of the texture, read-only */
  147. int w; /**< The width of the texture, read-only. */
  148. int h; /**< The height of the texture, read-only. */
  149. int refcount; /**< Application reference count, used when freeing texture */
  150. };
  151. #endif /* !SDL_INTERNAL */
  152. typedef struct SDL_Texture SDL_Texture;
  153. /* Function prototypes */
  154. /**
  155. * Get the number of 2D rendering drivers available for the current display.
  156. *
  157. * A render driver is a set of code that handles rendering and texture
  158. * management on a particular display. Normally there is only one, but some
  159. * drivers may have several available with different capabilities.
  160. *
  161. * There may be none if SDL was compiled without render support.
  162. *
  163. * \returns the number of built in render drivers.
  164. *
  165. * \threadsafety It is safe to call this function from any thread.
  166. *
  167. * \since This function is available since SDL 3.2.0.
  168. *
  169. * \sa SDL_CreateRenderer
  170. * \sa SDL_GetRenderDriver
  171. */
  172. extern SDL_DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
  173. /**
  174. * Use this function to get the name of a built in 2D rendering driver.
  175. *
  176. * The list of rendering drivers is given in the order that they are normally
  177. * initialized by default; the drivers that seem more reasonable to choose
  178. * first (as far as the SDL developers believe) are earlier in the list.
  179. *
  180. * The names of drivers are all simple, low-ASCII identifiers, like "opengl",
  181. * "direct3d12" or "metal". These never have Unicode characters, and are not
  182. * meant to be proper names.
  183. *
  184. * \param index the index of the rendering driver; the value ranges from 0 to
  185. * SDL_GetNumRenderDrivers() - 1.
  186. * \returns the name of the rendering driver at the requested index, or NULL
  187. * if an invalid index was specified.
  188. *
  189. * \threadsafety It is safe to call this function from any thread.
  190. *
  191. * \since This function is available since SDL 3.2.0.
  192. *
  193. * \sa SDL_GetNumRenderDrivers
  194. */
  195. extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index);
  196. /**
  197. * Create a window and default renderer.
  198. *
  199. * \param title the title of the window, in UTF-8 encoding.
  200. * \param width the width of the window.
  201. * \param height the height of the window.
  202. * \param window_flags the flags used to create the window (see
  203. * SDL_CreateWindow()).
  204. * \param window a pointer filled with the window, or NULL on error.
  205. * \param renderer a pointer filled with the renderer, or NULL on error.
  206. * \returns true on success or false on failure; call SDL_GetError() for more
  207. * information.
  208. *
  209. * \threadsafety This function should only be called on the main thread.
  210. *
  211. * \since This function is available since SDL 3.2.0.
  212. *
  213. * \sa SDL_CreateRenderer
  214. * \sa SDL_CreateWindow
  215. */
  216. extern SDL_DECLSPEC bool SDLCALL SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer);
  217. /**
  218. * Create a 2D rendering context for a window.
  219. *
  220. * If you want a specific renderer, you can specify its name here. A list of
  221. * available renderers can be obtained by calling SDL_GetRenderDriver()
  222. * multiple times, with indices from 0 to SDL_GetNumRenderDrivers()-1. If you
  223. * don't need a specific renderer, specify NULL and SDL will attempt to choose
  224. * the best option for you, based on what is available on the user's system.
  225. *
  226. * If `name` is a comma-separated list, SDL will try each name, in the order
  227. * listed, until one succeeds or all of them fail.
  228. *
  229. * By default the rendering size matches the window size in pixels, but you
  230. * can call SDL_SetRenderLogicalPresentation() to change the content size and
  231. * scaling options.
  232. *
  233. * \param window the window where rendering is displayed.
  234. * \param name the name of the rendering driver to initialize, or NULL to let
  235. * SDL choose one.
  236. * \returns a valid rendering context or NULL if there was an error; call
  237. * SDL_GetError() for more information.
  238. *
  239. * \threadsafety This function should only be called on the main thread.
  240. *
  241. * \since This function is available since SDL 3.2.0.
  242. *
  243. * \sa SDL_CreateRendererWithProperties
  244. * \sa SDL_CreateSoftwareRenderer
  245. * \sa SDL_DestroyRenderer
  246. * \sa SDL_GetNumRenderDrivers
  247. * \sa SDL_GetRenderDriver
  248. * \sa SDL_GetRendererName
  249. */
  250. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name);
  251. /**
  252. * Create a 2D rendering context for a window, with the specified properties.
  253. *
  254. * These are the supported properties:
  255. *
  256. * - `SDL_PROP_RENDERER_CREATE_NAME_STRING`: the name of the rendering driver
  257. * to use, if a specific one is desired
  258. * - `SDL_PROP_RENDERER_CREATE_WINDOW_POINTER`: the window where rendering is
  259. * displayed, required if this isn't a software renderer using a surface
  260. * - `SDL_PROP_RENDERER_CREATE_SURFACE_POINTER`: the surface where rendering
  261. * is displayed, if you want a software renderer without a window
  262. * - `SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER`: an SDL_Colorspace
  263. * value describing the colorspace for output to the display, defaults to
  264. * SDL_COLORSPACE_SRGB. The direct3d11, direct3d12, and metal renderers
  265. * support SDL_COLORSPACE_SRGB_LINEAR, which is a linear color space and
  266. * supports HDR output. If you select SDL_COLORSPACE_SRGB_LINEAR, drawing
  267. * still uses the sRGB colorspace, but values can go beyond 1.0 and float
  268. * (linear) format textures can be used for HDR content.
  269. * - `SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER`: non-zero if you want
  270. * present synchronized with the refresh rate. This property can take any
  271. * value that is supported by SDL_SetRenderVSync() for the renderer.
  272. *
  273. * With the SDL GPU renderer (since SDL 3.4.0):
  274. *
  275. * - `SDL_PROP_RENDERER_CREATE_GPU_DEVICE_POINTER`: the device to use with the
  276. * renderer, optional.
  277. * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN`: the app is able to
  278. * provide SPIR-V shaders to SDL_GPURenderState, optional.
  279. * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN`: the app is able to
  280. * provide DXIL shaders to SDL_GPURenderState, optional.
  281. * - `SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN`: the app is able to
  282. * provide MSL shaders to SDL_GPURenderState, optional.
  283. *
  284. * With the metal renderer:
  285. *
  286. * - `SDL_PROP_RENDERER_CREATE_METAL_DEVICE_POINTER`: the MTLDevice to use
  287. * with the renderer, optional.
  288. * - `SDL_PROP_RENDERER_CREATE_METAL_COMMAND_QUEUE_POINTER`: the
  289. * MTLCommandQueue to use with the renderer, optional. If you set this
  290. * property it will implicitly set (and override)
  291. * `SDL_PROP_RENDERER_CREATE_METAL_DEVICE_POINTER`.
  292. *
  293. * With the vulkan renderer:
  294. *
  295. * - `SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER`: the VkInstance to use
  296. * with the renderer, optional.
  297. * - `SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER`: the VkSurfaceKHR to use
  298. * with the renderer, optional.
  299. * - `SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER`: the
  300. * VkPhysicalDevice to use with the renderer, optional.
  301. * - `SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER`: the VkDevice to use
  302. * with the renderer, optional.
  303. * - `SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER`: the
  304. * queue family index used for rendering.
  305. * - `SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER`: the
  306. * queue family index used for presentation.
  307. *
  308. * \param props the properties to use.
  309. * \returns a valid rendering context or NULL if there was an error; call
  310. * SDL_GetError() for more information.
  311. *
  312. * \threadsafety This function should only be called on the main thread.
  313. *
  314. * \since This function is available since SDL 3.2.0.
  315. *
  316. * \sa SDL_CreateProperties
  317. * \sa SDL_CreateRenderer
  318. * \sa SDL_CreateSoftwareRenderer
  319. * \sa SDL_DestroyRenderer
  320. * \sa SDL_GetRendererName
  321. */
  322. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_PropertiesID props);
  323. #define SDL_PROP_RENDERER_CREATE_NAME_STRING "SDL.renderer.create.name"
  324. #define SDL_PROP_RENDERER_CREATE_WINDOW_POINTER "SDL.renderer.create.window"
  325. #define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "SDL.renderer.create.surface"
  326. #define SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.create.output_colorspace"
  327. #define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER "SDL.renderer.create.present_vsync"
  328. #define SDL_PROP_RENDERER_CREATE_GPU_DEVICE_POINTER "SDL.renderer.create.gpu.device"
  329. #define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_SPIRV_BOOLEAN "SDL.renderer.create.gpu.shaders_spirv"
  330. #define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_DXIL_BOOLEAN "SDL.renderer.create.gpu.shaders_dxil"
  331. #define SDL_PROP_RENDERER_CREATE_GPU_SHADERS_MSL_BOOLEAN "SDL.renderer.create.gpu.shaders_msl"
  332. #define SDL_PROP_RENDERER_CREATE_METAL_DEVICE_POINTER "SDL.renderer.create.metal.device"
  333. #define SDL_PROP_RENDERER_CREATE_METAL_COMMAND_QUEUE_POINTER "SDL.renderer.create.metal.command_queue"
  334. #define SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER "SDL.renderer.create.vulkan.instance"
  335. #define SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER "SDL.renderer.create.vulkan.surface"
  336. #define SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER "SDL.renderer.create.vulkan.physical_device"
  337. #define SDL_PROP_RENDERER_CREATE_VULKAN_DEVICE_POINTER "SDL.renderer.create.vulkan.device"
  338. #define SDL_PROP_RENDERER_CREATE_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.graphics_queue_family_index"
  339. #define SDL_PROP_RENDERER_CREATE_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.create.vulkan.present_queue_family_index"
  340. /**
  341. * Create a 2D GPU rendering context.
  342. *
  343. * The GPU device to use is passed in as a parameter. If this is NULL, then a
  344. * device will be created normally and can be retrieved using
  345. * SDL_GetGPURendererDevice().
  346. *
  347. * The window to use is passed in as a parameter. If this is NULL, then this
  348. * will become an offscreen renderer. In that case, you should call
  349. * SDL_SetRenderTarget() to setup rendering to a texture, and then call
  350. * SDL_RenderPresent() normally to complete drawing a frame.
  351. *
  352. * \param device the GPU device to use with the renderer, or NULL to create a
  353. * device.
  354. * \param window the window where rendering is displayed, or NULL to create an
  355. * offscreen renderer.
  356. * \returns a valid rendering context or NULL if there was an error; call
  357. * SDL_GetError() for more information.
  358. *
  359. * \threadsafety If this function is called with a valid GPU device, it should
  360. * be called on the thread that created the device. If this
  361. * function is called with a valid window, it should be called
  362. * on the thread that created the window.
  363. *
  364. * \since This function is available since SDL 3.4.0.
  365. *
  366. * \sa SDL_CreateRendererWithProperties
  367. * \sa SDL_GetGPURendererDevice
  368. * \sa SDL_CreateGPUShader
  369. * \sa SDL_CreateGPURenderState
  370. * \sa SDL_SetGPURenderState
  371. */
  372. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateGPURenderer(SDL_GPUDevice *device, SDL_Window *window);
  373. /**
  374. * Return the GPU device used by a renderer.
  375. *
  376. * \param renderer the rendering context.
  377. * \returns the GPU device used by the renderer, or NULL if the renderer is
  378. * not a GPU renderer; call SDL_GetError() for more information.
  379. *
  380. * \threadsafety It is safe to call this function from any thread.
  381. *
  382. * \since This function is available since SDL 3.4.0.
  383. */
  384. extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_GetGPURendererDevice(SDL_Renderer *renderer);
  385. /**
  386. * Create a 2D software rendering context for a surface.
  387. *
  388. * Two other APIs which can be used to create SDL_Renderer:
  389. * SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_
  390. * create a software renderer, but they are intended to be used with an
  391. * SDL_Window as the final destination and not an SDL_Surface.
  392. *
  393. * \param surface the SDL_Surface structure representing the surface where
  394. * rendering is done.
  395. * \returns a valid rendering context or NULL if there was an error; call
  396. * SDL_GetError() for more information.
  397. *
  398. * \threadsafety It is safe to call this function from any thread.
  399. *
  400. * \since This function is available since SDL 3.2.0.
  401. *
  402. * \sa SDL_DestroyRenderer
  403. */
  404. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface *surface);
  405. /**
  406. * Get the renderer associated with a window.
  407. *
  408. * \param window the window to query.
  409. * \returns the rendering context on success or NULL on failure; call
  410. * SDL_GetError() for more information.
  411. *
  412. * \threadsafety It is safe to call this function from any thread.
  413. *
  414. * \since This function is available since SDL 3.2.0.
  415. */
  416. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window *window);
  417. /**
  418. * Get the window associated with a renderer.
  419. *
  420. * \param renderer the renderer to query.
  421. * \returns the window on success or NULL on failure; call SDL_GetError() for
  422. * more information.
  423. *
  424. * \threadsafety It is safe to call this function from any thread.
  425. *
  426. * \since This function is available since SDL 3.2.0.
  427. */
  428. extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetRenderWindow(SDL_Renderer *renderer);
  429. /**
  430. * Get the name of a renderer.
  431. *
  432. * \param renderer the rendering context.
  433. * \returns the name of the selected renderer, or NULL on failure; call
  434. * SDL_GetError() for more information.
  435. *
  436. * \threadsafety It is safe to call this function from any thread.
  437. *
  438. * \since This function is available since SDL 3.2.0.
  439. *
  440. * \sa SDL_CreateRenderer
  441. * \sa SDL_CreateRendererWithProperties
  442. */
  443. extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer);
  444. /**
  445. * Get the properties associated with a renderer.
  446. *
  447. * The following read-only properties are provided by SDL:
  448. *
  449. * - `SDL_PROP_RENDERER_NAME_STRING`: the name of the rendering driver
  450. * - `SDL_PROP_RENDERER_WINDOW_POINTER`: the window where rendering is
  451. * displayed, if any
  452. * - `SDL_PROP_RENDERER_SURFACE_POINTER`: the surface where rendering is
  453. * displayed, if this is a software renderer without a window
  454. * - `SDL_PROP_RENDERER_VSYNC_NUMBER`: the current vsync setting
  455. * - `SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER`: the maximum texture width
  456. * and height
  457. * - `SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER`: a (const SDL_PixelFormat *)
  458. * array of pixel formats, terminated with SDL_PIXELFORMAT_UNKNOWN,
  459. * representing the available texture formats for this renderer.
  460. * - `SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN`: true if the renderer
  461. * supports SDL_TEXTURE_ADDRESS_WRAP on non-power-of-two textures.
  462. * - `SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER`: an SDL_Colorspace value
  463. * describing the colorspace for output to the display, defaults to
  464. * SDL_COLORSPACE_SRGB.
  465. * - `SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN`: true if the output colorspace is
  466. * SDL_COLORSPACE_SRGB_LINEAR and the renderer is showing on a display with
  467. * HDR enabled. This property can change dynamically when
  468. * SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  469. * - `SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT`: the value of SDR white in the
  470. * SDL_COLORSPACE_SRGB_LINEAR colorspace. When HDR is enabled, this value is
  471. * automatically multiplied into the color scale. This property can change
  472. * dynamically when SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  473. * - `SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT`: the additional high dynamic range
  474. * that can be displayed, in terms of the SDR white point. When HDR is not
  475. * enabled, this will be 1.0. This property can change dynamically when
  476. * SDL_EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  477. *
  478. * With the direct3d renderer:
  479. *
  480. * - `SDL_PROP_RENDERER_D3D9_DEVICE_POINTER`: the IDirect3DDevice9 associated
  481. * with the renderer
  482. *
  483. * With the direct3d11 renderer:
  484. *
  485. * - `SDL_PROP_RENDERER_D3D11_DEVICE_POINTER`: the ID3D11Device associated
  486. * with the renderer
  487. * - `SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER`: the IDXGISwapChain1
  488. * associated with the renderer. This may change when the window is resized.
  489. *
  490. * With the direct3d12 renderer:
  491. *
  492. * - `SDL_PROP_RENDERER_D3D12_DEVICE_POINTER`: the ID3D12Device associated
  493. * with the renderer
  494. * - `SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER`: the IDXGISwapChain4
  495. * associated with the renderer.
  496. * - `SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER`: the ID3D12CommandQueue
  497. * associated with the renderer
  498. *
  499. * With the metal renderer:
  500. *
  501. * - `SDL_PROP_RENDERER_METAL_DEVICE_POINTER`: the MTLDevice associated with
  502. * the renderer
  503. * - `SDL_PROP_RENDERER_METAL_COMMAND_QUEUE_POINTER`: the MTLCommandQueue
  504. * associated with the renderer. Work submitted on this queue will be
  505. * ordered relative to other rendering. SDL_FlushRenderer() can be used to
  506. * guarantee the current rendering has been submitted.
  507. *
  508. * With the vulkan renderer:
  509. *
  510. * - `SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER`: the VkInstance associated
  511. * with the renderer
  512. * - `SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER`: the VkSurfaceKHR associated
  513. * with the renderer
  514. * - `SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER`: the VkPhysicalDevice
  515. * associated with the renderer
  516. * - `SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER`: the VkDevice associated with
  517. * the renderer
  518. * - `SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER`: the queue
  519. * family index used for rendering
  520. * - `SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER`: the queue
  521. * family index used for presentation
  522. * - `SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER`: the number of
  523. * swapchain images, or potential frames in flight, used by the Vulkan
  524. * renderer
  525. *
  526. * With the gpu renderer:
  527. *
  528. * - `SDL_PROP_RENDERER_GPU_DEVICE_POINTER`: the SDL_GPUDevice associated with
  529. * the renderer
  530. *
  531. * \param renderer the rendering context.
  532. * \returns a valid property ID on success or 0 on failure; call
  533. * SDL_GetError() for more information.
  534. *
  535. * \threadsafety It is safe to call this function from any thread.
  536. *
  537. * \since This function is available since SDL 3.2.0.
  538. */
  539. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Renderer *renderer);
  540. #define SDL_PROP_RENDERER_NAME_STRING "SDL.renderer.name"
  541. #define SDL_PROP_RENDERER_WINDOW_POINTER "SDL.renderer.window"
  542. #define SDL_PROP_RENDERER_SURFACE_POINTER "SDL.renderer.surface"
  543. #define SDL_PROP_RENDERER_VSYNC_NUMBER "SDL.renderer.vsync"
  544. #define SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER "SDL.renderer.max_texture_size"
  545. #define SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER "SDL.renderer.texture_formats"
  546. #define SDL_PROP_RENDERER_TEXTURE_WRAPPING_BOOLEAN "SDL.renderer.texture_wrapping"
  547. #define SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.output_colorspace"
  548. #define SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN "SDL.renderer.HDR_enabled"
  549. #define SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT "SDL.renderer.SDR_white_point"
  550. #define SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT "SDL.renderer.HDR_headroom"
  551. #define SDL_PROP_RENDERER_D3D9_DEVICE_POINTER "SDL.renderer.d3d9.device"
  552. #define SDL_PROP_RENDERER_D3D11_DEVICE_POINTER "SDL.renderer.d3d11.device"
  553. #define SDL_PROP_RENDERER_D3D11_SWAPCHAIN_POINTER "SDL.renderer.d3d11.swap_chain"
  554. #define SDL_PROP_RENDERER_D3D12_DEVICE_POINTER "SDL.renderer.d3d12.device"
  555. #define SDL_PROP_RENDERER_D3D12_SWAPCHAIN_POINTER "SDL.renderer.d3d12.swap_chain"
  556. #define SDL_PROP_RENDERER_D3D12_COMMAND_QUEUE_POINTER "SDL.renderer.d3d12.command_queue"
  557. #define SDL_PROP_RENDERER_METAL_DEVICE_POINTER "SDL.renderer.metal.device"
  558. #define SDL_PROP_RENDERER_METAL_COMMAND_QUEUE_POINTER "SDL.renderer.metal.command_queue"
  559. #define SDL_PROP_RENDERER_VULKAN_INSTANCE_POINTER "SDL.renderer.vulkan.instance"
  560. #define SDL_PROP_RENDERER_VULKAN_SURFACE_NUMBER "SDL.renderer.vulkan.surface"
  561. #define SDL_PROP_RENDERER_VULKAN_PHYSICAL_DEVICE_POINTER "SDL.renderer.vulkan.physical_device"
  562. #define SDL_PROP_RENDERER_VULKAN_DEVICE_POINTER "SDL.renderer.vulkan.device"
  563. #define SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.vulkan.graphics_queue_family_index"
  564. #define SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.vulkan.present_queue_family_index"
  565. #define SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER "SDL.renderer.vulkan.swapchain_image_count"
  566. #define SDL_PROP_RENDERER_GPU_DEVICE_POINTER "SDL.renderer.gpu.device"
  567. /**
  568. * Get the output size in pixels of a rendering context.
  569. *
  570. * This returns the true output size in pixels, ignoring any render targets or
  571. * logical size and presentation.
  572. *
  573. * For the output size of the current rendering target, with logical size
  574. * adjustments, use SDL_GetCurrentRenderOutputSize() instead.
  575. *
  576. * \param renderer the rendering context.
  577. * \param w a pointer filled in with the width in pixels.
  578. * \param h a pointer filled in with the height in pixels.
  579. * \returns true on success or false on failure; call SDL_GetError() for more
  580. * information.
  581. *
  582. * \threadsafety This function should only be called on the main thread.
  583. *
  584. * \since This function is available since SDL 3.2.0.
  585. *
  586. * \sa SDL_GetCurrentRenderOutputSize
  587. */
  588. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  589. /**
  590. * Get the current output size in pixels of a rendering context.
  591. *
  592. * If a rendering target is active, this will return the size of the rendering
  593. * target in pixels, otherwise return the value of SDL_GetRenderOutputSize().
  594. *
  595. * Rendering target or not, the output will be adjusted by the current logical
  596. * presentation state, dictated by SDL_SetRenderLogicalPresentation().
  597. *
  598. * \param renderer the rendering context.
  599. * \param w a pointer filled in with the current width.
  600. * \param h a pointer filled in with the current height.
  601. * \returns true on success or false on failure; call SDL_GetError() for more
  602. * information.
  603. *
  604. * \threadsafety This function should only be called on the main thread.
  605. *
  606. * \since This function is available since SDL 3.2.0.
  607. *
  608. * \sa SDL_GetRenderOutputSize
  609. */
  610. extern SDL_DECLSPEC bool SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  611. /**
  612. * Create a texture for a rendering context.
  613. *
  614. * The contents of a texture when first created are not defined.
  615. *
  616. * \param renderer the rendering context.
  617. * \param format one of the enumerated values in SDL_PixelFormat.
  618. * \param access one of the enumerated values in SDL_TextureAccess.
  619. * \param w the width of the texture in pixels.
  620. * \param h the height of the texture in pixels.
  621. * \returns the created texture or NULL on failure; call SDL_GetError() for
  622. * more information.
  623. *
  624. * \threadsafety This function should only be called on the main thread.
  625. *
  626. * \since This function is available since SDL 3.2.0.
  627. *
  628. * \sa SDL_CreateTextureFromSurface
  629. * \sa SDL_CreateTextureWithProperties
  630. * \sa SDL_DestroyTexture
  631. * \sa SDL_GetTextureSize
  632. * \sa SDL_UpdateTexture
  633. */
  634. extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h);
  635. /**
  636. * Create a texture from an existing surface.
  637. *
  638. * The surface is not modified or freed by this function.
  639. *
  640. * The SDL_TextureAccess hint for the created texture is
  641. * `SDL_TEXTUREACCESS_STATIC`.
  642. *
  643. * The pixel format of the created texture may be different from the pixel
  644. * format of the surface, and can be queried using the
  645. * SDL_PROP_TEXTURE_FORMAT_NUMBER property.
  646. *
  647. * \param renderer the rendering context.
  648. * \param surface the SDL_Surface structure containing pixel data used to fill
  649. * the texture.
  650. * \returns the created texture or NULL on failure; call SDL_GetError() for
  651. * more information.
  652. *
  653. * \threadsafety This function should only be called on the main thread.
  654. *
  655. * \since This function is available since SDL 3.2.0.
  656. *
  657. * \sa SDL_CreateTexture
  658. * \sa SDL_CreateTextureWithProperties
  659. * \sa SDL_DestroyTexture
  660. */
  661. extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
  662. /**
  663. * Create a texture for a rendering context with the specified properties.
  664. *
  665. * These are the supported properties:
  666. *
  667. * - `SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER`: an SDL_Colorspace value
  668. * describing the texture colorspace, defaults to SDL_COLORSPACE_SRGB_LINEAR
  669. * for floating point textures, SDL_COLORSPACE_HDR10 for 10-bit textures,
  670. * SDL_COLORSPACE_SRGB for other RGB textures and SDL_COLORSPACE_JPEG for
  671. * YUV textures.
  672. * - `SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER`: one of the enumerated values in
  673. * SDL_PixelFormat, defaults to the best RGBA format for the renderer
  674. * - `SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER`: one of the enumerated values in
  675. * SDL_TextureAccess, defaults to SDL_TEXTUREACCESS_STATIC
  676. * - `SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER`: the width of the texture in
  677. * pixels, required
  678. * - `SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER`: the height of the texture in
  679. * pixels, required
  680. * - `SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER`: an SDL_Palette to use with
  681. * palettized texture formats. This can be set later with
  682. * SDL_SetTexturePalette()
  683. * - `SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating
  684. * point textures, this defines the value of 100% diffuse white, with higher
  685. * values being displayed in the High Dynamic Range headroom. This defaults
  686. * to 100 for HDR10 textures and 1.0 for floating point textures.
  687. * - `SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT`: for HDR10 and floating
  688. * point textures, this defines the maximum dynamic range used by the
  689. * content, in terms of the SDR white point. This would be equivalent to
  690. * maxCLL / SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT for HDR10 content.
  691. * If this is defined, any values outside the range supported by the display
  692. * will be scaled into the available HDR headroom, otherwise they are
  693. * clipped.
  694. *
  695. * With the direct3d11 renderer:
  696. *
  697. * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER`: the ID3D11Texture2D
  698. * associated with the texture, if you want to wrap an existing texture.
  699. * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER`: the ID3D11Texture2D
  700. * associated with the U plane of a YUV texture, if you want to wrap an
  701. * existing texture.
  702. * - `SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER`: the ID3D11Texture2D
  703. * associated with the V plane of a YUV texture, if you want to wrap an
  704. * existing texture.
  705. *
  706. * With the direct3d12 renderer:
  707. *
  708. * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER`: the ID3D12Resource
  709. * associated with the texture, if you want to wrap an existing texture.
  710. * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER`: the ID3D12Resource
  711. * associated with the U plane of a YUV texture, if you want to wrap an
  712. * existing texture.
  713. * - `SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER`: the ID3D12Resource
  714. * associated with the V plane of a YUV texture, if you want to wrap an
  715. * existing texture.
  716. *
  717. * With the metal renderer:
  718. *
  719. * - `SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER`: the CVPixelBufferRef
  720. * associated with the texture, if you want to create a texture from an
  721. * existing pixel buffer.
  722. * - `SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_POINTER`: the MTLTexture
  723. * associated with the texture, if you want to wrap an existing texture.
  724. * - `SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_UV_POINTER`: the MTLTexture
  725. * associated with the UV plane of an NV12 texture, if you want to wrap an
  726. * existing texture.
  727. * - `SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_U_POINTER`: the MTLTexture
  728. * associated with the U plane of a YUV texture, if you want to wrap an
  729. * existing texture.
  730. * - `SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_V_POINTER`: the MTLTexture
  731. * associated with the V plane of a YUV texture, if you want to wrap an
  732. * existing texture.
  733. * - `SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_USAGE_NUMBER`: any additional
  734. * MTLTextureUsage that this texture should have, defaults to 0.
  735. *
  736. * With the opengl renderer:
  737. *
  738. * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER`: the GLuint texture
  739. * associated with the texture, if you want to wrap an existing texture.
  740. * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER`: the GLuint texture
  741. * associated with the UV plane of an NV12 texture, if you want to wrap an
  742. * existing texture.
  743. * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER`: the GLuint texture
  744. * associated with the U plane of a YUV texture, if you want to wrap an
  745. * existing texture.
  746. * - `SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER`: the GLuint texture
  747. * associated with the V plane of a YUV texture, if you want to wrap an
  748. * existing texture.
  749. *
  750. * With the opengles2 renderer:
  751. *
  752. * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
  753. * associated with the texture, if you want to wrap an existing texture.
  754. * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER`: the GLuint texture
  755. * associated with the UV plane of an NV12 texture, if you want to wrap an
  756. * existing texture.
  757. * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER`: the GLuint texture
  758. * associated with the U plane of a YUV texture, if you want to wrap an
  759. * existing texture.
  760. * - `SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER`: the GLuint texture
  761. * associated with the V plane of a YUV texture, if you want to wrap an
  762. * existing texture.
  763. *
  764. * With the vulkan renderer:
  765. *
  766. * - `SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER`: the VkImage associated
  767. * with the texture, if you want to wrap an existing texture.
  768. * - `SDL_PROP_TEXTURE_CREATE_VULKAN_LAYOUT_NUMBER`: the VkImageLayout for the
  769. * VkImage, defaults to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.
  770. *
  771. * With the GPU renderer:
  772. *
  773. * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER`: the SDL_GPUTexture
  774. * associated with the texture, if you want to wrap an existing texture.
  775. * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_UV_NUMBER`: the SDL_GPUTexture
  776. * associated with the UV plane of an NV12 texture, if you want to wrap an
  777. * existing texture.
  778. * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_U_NUMBER`: the SDL_GPUTexture
  779. * associated with the U plane of a YUV texture, if you want to wrap an
  780. * existing texture.
  781. * - `SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_V_NUMBER`: the SDL_GPUTexture
  782. * associated with the V plane of a YUV texture, if you want to wrap an
  783. * existing texture.
  784. *
  785. * \param renderer the rendering context.
  786. * \param props the properties to use.
  787. * \returns the created texture or NULL on failure; call SDL_GetError() for
  788. * more information.
  789. *
  790. * \threadsafety This function should only be called on the main thread.
  791. *
  792. * \since This function is available since SDL 3.2.0.
  793. *
  794. * \sa SDL_CreateProperties
  795. * \sa SDL_CreateTexture
  796. * \sa SDL_CreateTextureFromSurface
  797. * \sa SDL_DestroyTexture
  798. * \sa SDL_GetTextureSize
  799. * \sa SDL_UpdateTexture
  800. */
  801. extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props);
  802. #define SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER "SDL.texture.create.colorspace"
  803. #define SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER "SDL.texture.create.format"
  804. #define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "SDL.texture.create.access"
  805. #define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "SDL.texture.create.width"
  806. #define SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER "SDL.texture.create.height"
  807. #define SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER "SDL.texture.create.palette"
  808. #define SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT "SDL.texture.create.SDR_white_point"
  809. #define SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT "SDL.texture.create.HDR_headroom"
  810. #define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "SDL.texture.create.d3d11.texture"
  811. #define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER "SDL.texture.create.d3d11.texture_u"
  812. #define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER "SDL.texture.create.d3d11.texture_v"
  813. #define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER "SDL.texture.create.d3d12.texture"
  814. #define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER "SDL.texture.create.d3d12.texture_u"
  815. #define SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER "SDL.texture.create.d3d12.texture_v"
  816. #define SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER "SDL.texture.create.metal.pixelbuffer"
  817. #define SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_POINTER "SDL.texture.create.metal.texture"
  818. #define SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_UV_POINTER "SDL.texture.create.metal.texture_uv"
  819. #define SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_U_POINTER "SDL.texture.create.metal.texture_u"
  820. #define SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_V_POINTER "SDL.texture.create.metal.texture_v"
  821. #define SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_USAGE_NUMBER "SDL.texture.create.metal.texture_usage"
  822. #define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_NUMBER "SDL.texture.create.opengl.texture"
  823. #define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.create.opengl.texture_uv"
  824. #define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.create.opengl.texture_u"
  825. #define SDL_PROP_TEXTURE_CREATE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.create.opengl.texture_v"
  826. #define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.create.opengles2.texture"
  827. #define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.create.opengles2.texture_uv"
  828. #define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.create.opengles2.texture_u"
  829. #define SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.create.opengles2.texture_v"
  830. #define SDL_PROP_TEXTURE_CREATE_VULKAN_TEXTURE_NUMBER "SDL.texture.create.vulkan.texture"
  831. #define SDL_PROP_TEXTURE_CREATE_VULKAN_LAYOUT_NUMBER "SDL.texture.create.vulkan.layout"
  832. #define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER "SDL.texture.create.gpu.texture"
  833. #define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_UV_POINTER "SDL.texture.create.gpu.texture_uv"
  834. #define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_U_POINTER "SDL.texture.create.gpu.texture_u"
  835. #define SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_V_POINTER "SDL.texture.create.gpu.texture_v"
  836. /**
  837. * Get the properties associated with a texture.
  838. *
  839. * The following read-only properties are provided by SDL:
  840. *
  841. * - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_Colorspace value describing
  842. * the texture colorspace.
  843. * - `SDL_PROP_TEXTURE_FORMAT_NUMBER`: one of the enumerated values in
  844. * SDL_PixelFormat.
  845. * - `SDL_PROP_TEXTURE_ACCESS_NUMBER`: one of the enumerated values in
  846. * SDL_TextureAccess.
  847. * - `SDL_PROP_TEXTURE_WIDTH_NUMBER`: the width of the texture in pixels.
  848. * - `SDL_PROP_TEXTURE_HEIGHT_NUMBER`: the height of the texture in pixels.
  849. * - `SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  850. * textures, this defines the value of 100% diffuse white, with higher
  851. * values being displayed in the High Dynamic Range headroom. This defaults
  852. * to 100 for HDR10 textures and 1.0 for other textures.
  853. * - `SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT`: for HDR10 and floating point
  854. * textures, this defines the maximum dynamic range used by the content, in
  855. * terms of the SDR white point. If this is defined, any values outside the
  856. * range supported by the display will be scaled into the available HDR
  857. * headroom, otherwise they are clipped. This defaults to 1.0 for SDR
  858. * textures, 4.0 for HDR10 textures, and no default for floating point
  859. * textures.
  860. *
  861. * With the direct3d11 renderer:
  862. *
  863. * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER`: the ID3D11Texture2D associated
  864. * with the texture
  865. * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER`: the ID3D11Texture2D
  866. * associated with the U plane of a YUV texture
  867. * - `SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER`: the ID3D11Texture2D
  868. * associated with the V plane of a YUV texture
  869. *
  870. * With the direct3d12 renderer:
  871. *
  872. * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER`: the ID3D12Resource associated
  873. * with the texture
  874. * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER`: the ID3D12Resource associated
  875. * with the U plane of a YUV texture
  876. * - `SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER`: the ID3D12Resource associated
  877. * with the V plane of a YUV texture
  878. *
  879. * With the metal renderer:
  880. *
  881. * - `SDL_PROP_TEXTURE_METAL_TEXTURE_POINTER`: the MTLTexture associated with
  882. * the texture
  883. * - `SDL_PROP_TEXTURE_METAL_TEXTURE_UV_POINTER`: the MTLTexture associated
  884. * with the UV plane of an NV12 texture
  885. * - `SDL_PROP_TEXTURE_METAL_TEXTURE_U_POINTER`: the MTLTexture associated
  886. * with the U plane of a YUV texture style texture
  887. * - `SDL_PROP_TEXTURE_METAL_TEXTURE_V_POINTER`: the MTLTexture associated
  888. * with the V plane of a YUV texture
  889. *
  890. * With the vulkan renderer:
  891. *
  892. * - `SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER`: the VkImage associated with the
  893. * texture
  894. *
  895. * With the opengl renderer:
  896. *
  897. * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER`: the GLuint texture associated
  898. * with the texture
  899. * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER`: the GLuint texture
  900. * associated with the UV plane of an NV12 texture
  901. * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER`: the GLuint texture associated
  902. * with the U plane of a YUV texture
  903. * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER`: the GLuint texture associated
  904. * with the V plane of a YUV texture
  905. * - `SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER`: the GLenum for the
  906. * texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_RECTANGLE_ARB`, etc)
  907. * - `SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT`: the texture coordinate width of
  908. * the texture (0.0 - 1.0)
  909. * - `SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT`: the texture coordinate height of
  910. * the texture (0.0 - 1.0)
  911. *
  912. * With the opengles2 renderer:
  913. *
  914. * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER`: the GLuint texture
  915. * associated with the texture
  916. * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER`: the GLuint texture
  917. * associated with the UV plane of an NV12 texture
  918. * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER`: the GLuint texture
  919. * associated with the U plane of a YUV texture
  920. * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER`: the GLuint texture
  921. * associated with the V plane of a YUV texture
  922. * - `SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER`: the GLenum for the
  923. * texture target (`GL_TEXTURE_2D`, `GL_TEXTURE_EXTERNAL_OES`, etc)
  924. *
  925. * With the gpu renderer:
  926. *
  927. * - `SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER`: the SDL_GPUTexture associated
  928. * with the texture
  929. * - `SDL_PROP_TEXTURE_GPU_TEXTURE_UV_POINTER`: the SDL_GPUTexture associated
  930. * with the UV plane of an NV12 texture
  931. * - `SDL_PROP_TEXTURE_GPU_TEXTURE_U_POINTER`: the SDL_GPUTexture associated
  932. * with the U plane of a YUV texture
  933. * - `SDL_PROP_TEXTURE_GPU_TEXTURE_V_POINTER`: the SDL_GPUTexture associated
  934. * with the V plane of a YUV texture
  935. *
  936. * \param texture the texture to query.
  937. * \returns a valid property ID on success or 0 on failure; call
  938. * SDL_GetError() for more information.
  939. *
  940. * \threadsafety It is safe to call this function from any thread.
  941. *
  942. * \since This function is available since SDL 3.2.0.
  943. */
  944. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
  945. #define SDL_PROP_TEXTURE_COLORSPACE_NUMBER "SDL.texture.colorspace"
  946. #define SDL_PROP_TEXTURE_FORMAT_NUMBER "SDL.texture.format"
  947. #define SDL_PROP_TEXTURE_ACCESS_NUMBER "SDL.texture.access"
  948. #define SDL_PROP_TEXTURE_WIDTH_NUMBER "SDL.texture.width"
  949. #define SDL_PROP_TEXTURE_HEIGHT_NUMBER "SDL.texture.height"
  950. #define SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT "SDL.texture.SDR_white_point"
  951. #define SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT "SDL.texture.HDR_headroom"
  952. #define SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER "SDL.texture.d3d11.texture"
  953. #define SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER "SDL.texture.d3d11.texture_u"
  954. #define SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER "SDL.texture.d3d11.texture_v"
  955. #define SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER "SDL.texture.d3d12.texture"
  956. #define SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER "SDL.texture.d3d12.texture_u"
  957. #define SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER "SDL.texture.d3d12.texture_v"
  958. #define SDL_PROP_TEXTURE_METAL_TEXTURE_POINTER "SDL.texture.metal.texture"
  959. #define SDL_PROP_TEXTURE_METAL_TEXTURE_UV_POINTER "SDL.texture.metal.texture_uv"
  960. #define SDL_PROP_TEXTURE_METAL_TEXTURE_U_POINTER "SDL.texture.metal.texture_u"
  961. #define SDL_PROP_TEXTURE_METAL_TEXTURE_V_POINTER "SDL.texture.metal.texture_v"
  962. #define SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER "SDL.texture.opengl.texture"
  963. #define SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER "SDL.texture.opengl.texture_uv"
  964. #define SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER "SDL.texture.opengl.texture_u"
  965. #define SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER "SDL.texture.opengl.texture_v"
  966. #define SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER "SDL.texture.opengl.target"
  967. #define SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT "SDL.texture.opengl.tex_w"
  968. #define SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT "SDL.texture.opengl.tex_h"
  969. #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER "SDL.texture.opengles2.texture"
  970. #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER "SDL.texture.opengles2.texture_uv"
  971. #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER "SDL.texture.opengles2.texture_u"
  972. #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER "SDL.texture.opengles2.texture_v"
  973. #define SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER "SDL.texture.opengles2.target"
  974. #define SDL_PROP_TEXTURE_VULKAN_TEXTURE_NUMBER "SDL.texture.vulkan.texture"
  975. #define SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER "SDL.texture.gpu.texture"
  976. #define SDL_PROP_TEXTURE_GPU_TEXTURE_UV_POINTER "SDL.texture.gpu.texture_uv"
  977. #define SDL_PROP_TEXTURE_GPU_TEXTURE_U_POINTER "SDL.texture.gpu.texture_u"
  978. #define SDL_PROP_TEXTURE_GPU_TEXTURE_V_POINTER "SDL.texture.gpu.texture_v"
  979. /**
  980. * Get the renderer that created an SDL_Texture.
  981. *
  982. * \param texture the texture to query.
  983. * \returns a pointer to the SDL_Renderer that created the texture, or NULL on
  984. * failure; call SDL_GetError() for more information.
  985. *
  986. * \threadsafety It is safe to call this function from any thread.
  987. *
  988. * \since This function is available since SDL 3.2.0.
  989. */
  990. extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRendererFromTexture(SDL_Texture *texture);
  991. /**
  992. * Get the size of a texture, as floating point values.
  993. *
  994. * \param texture the texture to query.
  995. * \param w a pointer filled in with the width of the texture in pixels. This
  996. * argument can be NULL if you don't need this information.
  997. * \param h a pointer filled in with the height of the texture in pixels. This
  998. * argument can be NULL if you don't need this information.
  999. * \returns true on success or false on failure; call SDL_GetError() for more
  1000. * information.
  1001. *
  1002. * \threadsafety This function should only be called on the main thread.
  1003. *
  1004. * \since This function is available since SDL 3.2.0.
  1005. */
  1006. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);
  1007. /**
  1008. * Set the palette used by a texture.
  1009. *
  1010. * Setting the palette keeps an internal reference to the palette, which can
  1011. * be safely destroyed afterwards.
  1012. *
  1013. * A single palette can be shared with many textures.
  1014. *
  1015. * \param texture the texture to update.
  1016. * \param palette the SDL_Palette structure to use.
  1017. * \returns true on success or false on failure; call SDL_GetError() for more
  1018. * information.
  1019. *
  1020. * \threadsafety This function should only be called on the main thread.
  1021. *
  1022. * \since This function is available since SDL 3.4.0.
  1023. *
  1024. * \sa SDL_CreatePalette
  1025. * \sa SDL_GetTexturePalette
  1026. */
  1027. extern SDL_DECLSPEC bool SDLCALL SDL_SetTexturePalette(SDL_Texture *texture, SDL_Palette *palette);
  1028. /**
  1029. * Get the palette used by a texture.
  1030. *
  1031. * \param texture the texture to query.
  1032. * \returns a pointer to the palette used by the texture, or NULL if there is
  1033. * no palette used.
  1034. *
  1035. * \threadsafety This function should only be called on the main thread.
  1036. *
  1037. * \since This function is available since SDL 3.4.0.
  1038. *
  1039. * \sa SDL_SetTexturePalette
  1040. */
  1041. extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetTexturePalette(SDL_Texture *texture);
  1042. /**
  1043. * Set an additional color value multiplied into render copy operations.
  1044. *
  1045. * When this texture is rendered, during the copy operation each source color
  1046. * channel is modulated by the appropriate color value according to the
  1047. * following formula:
  1048. *
  1049. * `srcC = srcC * (color / 255)`
  1050. *
  1051. * Color modulation is not always supported by the renderer; it will return
  1052. * false if color modulation is not supported.
  1053. *
  1054. * \param texture the texture to update.
  1055. * \param r the red color value multiplied into copy operations.
  1056. * \param g the green color value multiplied into copy operations.
  1057. * \param b the blue color value multiplied into copy operations.
  1058. * \returns true on success or false on failure; call SDL_GetError() for more
  1059. * information.
  1060. *
  1061. * \threadsafety This function should only be called on the main thread.
  1062. *
  1063. * \since This function is available since SDL 3.2.0.
  1064. *
  1065. * \sa SDL_GetTextureColorMod
  1066. * \sa SDL_SetTextureAlphaMod
  1067. * \sa SDL_SetTextureColorModFloat
  1068. */
  1069. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
  1070. /**
  1071. * Set an additional color value multiplied into render copy operations.
  1072. *
  1073. * When this texture is rendered, during the copy operation each source color
  1074. * channel is modulated by the appropriate color value according to the
  1075. * following formula:
  1076. *
  1077. * `srcC = srcC * color`
  1078. *
  1079. * Color modulation is not always supported by the renderer; it will return
  1080. * false if color modulation is not supported.
  1081. *
  1082. * \param texture the texture to update.
  1083. * \param r the red color value multiplied into copy operations.
  1084. * \param g the green color value multiplied into copy operations.
  1085. * \param b the blue color value multiplied into copy operations.
  1086. * \returns true on success or false on failure; call SDL_GetError() for more
  1087. * information.
  1088. *
  1089. * \threadsafety This function should only be called on the main thread.
  1090. *
  1091. * \since This function is available since SDL 3.2.0.
  1092. *
  1093. * \sa SDL_GetTextureColorModFloat
  1094. * \sa SDL_SetTextureAlphaModFloat
  1095. * \sa SDL_SetTextureColorMod
  1096. */
  1097. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b);
  1098. /**
  1099. * Get the additional color value multiplied into render copy operations.
  1100. *
  1101. * \param texture the texture to query.
  1102. * \param r a pointer filled in with the current red color value.
  1103. * \param g a pointer filled in with the current green color value.
  1104. * \param b a pointer filled in with the current blue color value.
  1105. * \returns true on success or false on failure; call SDL_GetError() for more
  1106. * information.
  1107. *
  1108. * \threadsafety This function should only be called on the main thread.
  1109. *
  1110. * \since This function is available since SDL 3.2.0.
  1111. *
  1112. * \sa SDL_GetTextureAlphaMod
  1113. * \sa SDL_GetTextureColorModFloat
  1114. * \sa SDL_SetTextureColorMod
  1115. */
  1116. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b);
  1117. /**
  1118. * Get the additional color value multiplied into render copy operations.
  1119. *
  1120. * \param texture the texture to query.
  1121. * \param r a pointer filled in with the current red color value.
  1122. * \param g a pointer filled in with the current green color value.
  1123. * \param b a pointer filled in with the current blue color value.
  1124. * \returns true on success or false on failure; call SDL_GetError() for more
  1125. * information.
  1126. *
  1127. * \threadsafety This function should only be called on the main thread.
  1128. *
  1129. * \since This function is available since SDL 3.2.0.
  1130. *
  1131. * \sa SDL_GetTextureAlphaModFloat
  1132. * \sa SDL_GetTextureColorMod
  1133. * \sa SDL_SetTextureColorModFloat
  1134. */
  1135. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b);
  1136. /**
  1137. * Set an additional alpha value multiplied into render copy operations.
  1138. *
  1139. * When this texture is rendered, during the copy operation the source alpha
  1140. * value is modulated by this alpha value according to the following formula:
  1141. *
  1142. * `srcA = srcA * (alpha / 255)`
  1143. *
  1144. * Alpha modulation is not always supported by the renderer; it will return
  1145. * false if alpha modulation is not supported.
  1146. *
  1147. * \param texture the texture to update.
  1148. * \param alpha the source alpha value multiplied into copy operations.
  1149. * \returns true on success or false on failure; call SDL_GetError() for more
  1150. * information.
  1151. *
  1152. * \threadsafety This function should only be called on the main thread.
  1153. *
  1154. * \since This function is available since SDL 3.2.0.
  1155. *
  1156. * \sa SDL_GetTextureAlphaMod
  1157. * \sa SDL_SetTextureAlphaModFloat
  1158. * \sa SDL_SetTextureColorMod
  1159. */
  1160. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
  1161. /**
  1162. * Set an additional alpha value multiplied into render copy operations.
  1163. *
  1164. * When this texture is rendered, during the copy operation the source alpha
  1165. * value is modulated by this alpha value according to the following formula:
  1166. *
  1167. * `srcA = srcA * alpha`
  1168. *
  1169. * Alpha modulation is not always supported by the renderer; it will return
  1170. * false if alpha modulation is not supported.
  1171. *
  1172. * \param texture the texture to update.
  1173. * \param alpha the source alpha value multiplied into copy operations.
  1174. * \returns true on success or false on failure; call SDL_GetError() for more
  1175. * information.
  1176. *
  1177. * \threadsafety This function should only be called on the main thread.
  1178. *
  1179. * \since This function is available since SDL 3.2.0.
  1180. *
  1181. * \sa SDL_GetTextureAlphaModFloat
  1182. * \sa SDL_SetTextureAlphaMod
  1183. * \sa SDL_SetTextureColorModFloat
  1184. */
  1185. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha);
  1186. /**
  1187. * Get the additional alpha value multiplied into render copy operations.
  1188. *
  1189. * \param texture the texture to query.
  1190. * \param alpha a pointer filled in with the current alpha value.
  1191. * \returns true on success or false on failure; call SDL_GetError() for more
  1192. * information.
  1193. *
  1194. * \threadsafety This function should only be called on the main thread.
  1195. *
  1196. * \since This function is available since SDL 3.2.0.
  1197. *
  1198. * \sa SDL_GetTextureAlphaModFloat
  1199. * \sa SDL_GetTextureColorMod
  1200. * \sa SDL_SetTextureAlphaMod
  1201. */
  1202. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha);
  1203. /**
  1204. * Get the additional alpha value multiplied into render copy operations.
  1205. *
  1206. * \param texture the texture to query.
  1207. * \param alpha a pointer filled in with the current alpha value.
  1208. * \returns true on success or false on failure; call SDL_GetError() for more
  1209. * information.
  1210. *
  1211. * \threadsafety This function should only be called on the main thread.
  1212. *
  1213. * \since This function is available since SDL 3.2.0.
  1214. *
  1215. * \sa SDL_GetTextureAlphaMod
  1216. * \sa SDL_GetTextureColorModFloat
  1217. * \sa SDL_SetTextureAlphaModFloat
  1218. */
  1219. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha);
  1220. /**
  1221. * Set the blend mode for a texture.
  1222. *
  1223. * This blend mode is used for any drawing that involves this texture.
  1224. *
  1225. * If the blend mode is not supported, the closest supported mode is chosen
  1226. * and this function returns false.
  1227. *
  1228. * \param texture the texture to update.
  1229. * \param blendMode the SDL_BlendMode to use for texture blending.
  1230. * \returns true on success or false on failure; call SDL_GetError() for more
  1231. * information.
  1232. *
  1233. * \threadsafety This function should only be called on the main thread.
  1234. *
  1235. * \since This function is available since SDL 3.2.0.
  1236. *
  1237. * \sa SDL_GetTextureBlendMode
  1238. * \sa SDL_SetRenderDrawBlendMode
  1239. */
  1240. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode);
  1241. /**
  1242. * Get the blend mode used for texture copy operations.
  1243. *
  1244. * \param texture the texture to query.
  1245. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  1246. * \returns true on success or false on failure; call SDL_GetError() for more
  1247. * information.
  1248. *
  1249. * \threadsafety This function should only be called on the main thread.
  1250. *
  1251. * \since This function is available since SDL 3.2.0.
  1252. *
  1253. * \sa SDL_SetTextureBlendMode
  1254. */
  1255. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode);
  1256. /**
  1257. * Set the scale mode used for texture scale operations.
  1258. *
  1259. * The default texture scale mode is SDL_SCALEMODE_LINEAR.
  1260. *
  1261. * If the scale mode is not supported, the closest supported mode is chosen.
  1262. *
  1263. * \param texture the texture to update.
  1264. * \param scaleMode the SDL_ScaleMode to use for texture scaling.
  1265. * \returns true on success or false on failure; call SDL_GetError() for more
  1266. * information.
  1267. *
  1268. * \threadsafety This function should only be called on the main thread.
  1269. *
  1270. * \since This function is available since SDL 3.2.0.
  1271. *
  1272. * \sa SDL_GetTextureScaleMode
  1273. */
  1274. extern SDL_DECLSPEC bool SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode);
  1275. /**
  1276. * Get the scale mode used for texture scale operations.
  1277. *
  1278. * \param texture the texture to query.
  1279. * \param scaleMode a pointer filled in with the current scale mode.
  1280. * \returns true on success or false on failure; call SDL_GetError() for more
  1281. * information.
  1282. *
  1283. * \threadsafety This function should only be called on the main thread.
  1284. *
  1285. * \since This function is available since SDL 3.2.0.
  1286. *
  1287. * \sa SDL_SetTextureScaleMode
  1288. */
  1289. extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode);
  1290. /**
  1291. * Update the given texture rectangle with new pixel data.
  1292. *
  1293. * The pixel data must be in the pixel format of the texture, which can be
  1294. * queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
  1295. *
  1296. * This is a fairly slow function, intended for use with static textures that
  1297. * do not change often.
  1298. *
  1299. * If the texture is intended to be updated often, it is preferred to create
  1300. * the texture as streaming and use the locking functions referenced below.
  1301. * While this function will work with streaming textures, for optimization
  1302. * reasons you may not get the pixels back if you lock the texture afterward.
  1303. *
  1304. * \param texture the texture to update.
  1305. * \param rect an SDL_Rect structure representing the area to update, or NULL
  1306. * to update the entire texture.
  1307. * \param pixels the raw pixel data in the format of the texture.
  1308. * \param pitch the number of bytes in a row of pixel data, including padding
  1309. * between lines.
  1310. * \returns true on success or false on failure; call SDL_GetError() for more
  1311. * information.
  1312. *
  1313. * \threadsafety This function should only be called on the main thread.
  1314. *
  1315. * \since This function is available since SDL 3.2.0.
  1316. *
  1317. * \sa SDL_LockTexture
  1318. * \sa SDL_UnlockTexture
  1319. * \sa SDL_UpdateNVTexture
  1320. * \sa SDL_UpdateYUVTexture
  1321. */
  1322. extern SDL_DECLSPEC bool SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch);
  1323. /**
  1324. * Update a rectangle within a planar YV12 or IYUV texture with new pixel
  1325. * data.
  1326. *
  1327. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  1328. * block of Y and U/V planes in the proper order, but this function is
  1329. * available if your pixel data is not contiguous.
  1330. *
  1331. * \param texture the texture to update.
  1332. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  1333. * update the entire texture.
  1334. * \param Yplane the raw pixel data for the Y plane.
  1335. * \param Ypitch the number of bytes between rows of pixel data for the Y
  1336. * plane.
  1337. * \param Uplane the raw pixel data for the U plane.
  1338. * \param Upitch the number of bytes between rows of pixel data for the U
  1339. * plane.
  1340. * \param Vplane the raw pixel data for the V plane.
  1341. * \param Vpitch the number of bytes between rows of pixel data for the V
  1342. * plane.
  1343. * \returns true on success or false on failure; call SDL_GetError() for more
  1344. * information.
  1345. *
  1346. * \threadsafety This function should only be called on the main thread.
  1347. *
  1348. * \since This function is available since SDL 3.2.0.
  1349. *
  1350. * \sa SDL_UpdateNVTexture
  1351. * \sa SDL_UpdateTexture
  1352. */
  1353. extern SDL_DECLSPEC bool SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture,
  1354. const SDL_Rect *rect,
  1355. const Uint8 *Yplane, int Ypitch,
  1356. const Uint8 *Uplane, int Upitch,
  1357. const Uint8 *Vplane, int Vpitch);
  1358. /**
  1359. * Update a rectangle within a planar NV12 or NV21 texture with new pixels.
  1360. *
  1361. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  1362. * block of NV12/21 planes in the proper order, but this function is available
  1363. * if your pixel data is not contiguous.
  1364. *
  1365. * \param texture the texture to update.
  1366. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  1367. * update the entire texture.
  1368. * \param Yplane the raw pixel data for the Y plane.
  1369. * \param Ypitch the number of bytes between rows of pixel data for the Y
  1370. * plane.
  1371. * \param UVplane the raw pixel data for the UV plane.
  1372. * \param UVpitch the number of bytes between rows of pixel data for the UV
  1373. * plane.
  1374. * \returns true on success or false on failure; call SDL_GetError() for more
  1375. * information.
  1376. *
  1377. * \threadsafety This function should only be called on the main thread.
  1378. *
  1379. * \since This function is available since SDL 3.2.0.
  1380. *
  1381. * \sa SDL_UpdateTexture
  1382. * \sa SDL_UpdateYUVTexture
  1383. */
  1384. extern SDL_DECLSPEC bool SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture,
  1385. const SDL_Rect *rect,
  1386. const Uint8 *Yplane, int Ypitch,
  1387. const Uint8 *UVplane, int UVpitch);
  1388. /**
  1389. * Lock a portion of the texture for **write-only** pixel access.
  1390. *
  1391. * As an optimization, the pixels made available for editing don't necessarily
  1392. * contain the old texture data. This is a write-only operation, and if you
  1393. * need to keep a copy of the texture data you should do that at the
  1394. * application level.
  1395. *
  1396. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  1397. * changes.
  1398. *
  1399. * \param texture the texture to lock for access, which was created with
  1400. * `SDL_TEXTUREACCESS_STREAMING`.
  1401. * \param rect an SDL_Rect structure representing the area to lock for access;
  1402. * NULL to lock the entire texture.
  1403. * \param pixels this is filled in with a pointer to the locked pixels,
  1404. * appropriately offset by the locked area.
  1405. * \param pitch this is filled in with the pitch of the locked pixels; the
  1406. * pitch is the length of one row in bytes.
  1407. * \returns true on success or false if the texture is not valid or was not
  1408. * created with `SDL_TEXTUREACCESS_STREAMING`; call SDL_GetError()
  1409. * for more information.
  1410. *
  1411. * \threadsafety This function should only be called on the main thread.
  1412. *
  1413. * \since This function is available since SDL 3.2.0.
  1414. *
  1415. * \sa SDL_LockTextureToSurface
  1416. * \sa SDL_UnlockTexture
  1417. */
  1418. extern SDL_DECLSPEC bool SDLCALL SDL_LockTexture(SDL_Texture *texture,
  1419. const SDL_Rect *rect,
  1420. void **pixels, int *pitch);
  1421. /**
  1422. * Lock a portion of the texture for **write-only** pixel access, and expose
  1423. * it as a SDL surface.
  1424. *
  1425. * Besides providing an SDL_Surface instead of raw pixel data, this function
  1426. * operates like SDL_LockTexture.
  1427. *
  1428. * As an optimization, the pixels made available for editing don't necessarily
  1429. * contain the old texture data. This is a write-only operation, and if you
  1430. * need to keep a copy of the texture data you should do that at the
  1431. * application level.
  1432. *
  1433. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  1434. * changes.
  1435. *
  1436. * The returned surface is freed internally after calling SDL_UnlockTexture()
  1437. * or SDL_DestroyTexture(). The caller should not free it.
  1438. *
  1439. * \param texture the texture to lock for access, which must be created with
  1440. * `SDL_TEXTUREACCESS_STREAMING`.
  1441. * \param rect a pointer to the rectangle to lock for access. If the rect is
  1442. * NULL, the entire texture will be locked.
  1443. * \param surface a pointer to an SDL surface of size **rect**. Don't assume
  1444. * any specific pixel content.
  1445. * \returns true on success or false on failure; call SDL_GetError() for more
  1446. * information.
  1447. *
  1448. * \threadsafety This function should only be called on the main thread.
  1449. *
  1450. * \since This function is available since SDL 3.2.0.
  1451. *
  1452. * \sa SDL_LockTexture
  1453. * \sa SDL_UnlockTexture
  1454. */
  1455. extern SDL_DECLSPEC bool SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface);
  1456. /**
  1457. * Unlock a texture, uploading the changes to video memory, if needed.
  1458. *
  1459. * **Warning**: Please note that SDL_LockTexture() is intended to be
  1460. * write-only; it will not guarantee the previous contents of the texture will
  1461. * be provided. You must fully initialize any area of a texture that you lock
  1462. * before unlocking it, as the pixels might otherwise be uninitialized memory.
  1463. *
  1464. * Which is to say: locking and immediately unlocking a texture can result in
  1465. * corrupted textures, depending on the renderer in use.
  1466. *
  1467. * \param texture a texture locked by SDL_LockTexture().
  1468. *
  1469. * \threadsafety This function should only be called on the main thread.
  1470. *
  1471. * \since This function is available since SDL 3.2.0.
  1472. *
  1473. * \sa SDL_LockTexture
  1474. */
  1475. extern SDL_DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture *texture);
  1476. /**
  1477. * Set a texture as the current rendering target.
  1478. *
  1479. * The default render target is the window for which the renderer was created.
  1480. * To stop rendering to a texture and render to the window again, call this
  1481. * function with a NULL `texture`.
  1482. *
  1483. * Viewport, cliprect, scale, and logical presentation are unique to each
  1484. * render target. Get and set functions for these states apply to the current
  1485. * render target set by this function, and those states persist on each target
  1486. * when the current render target changes.
  1487. *
  1488. * \param renderer the rendering context.
  1489. * \param texture the targeted texture, which must be created with the
  1490. * `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the
  1491. * window instead of a texture.
  1492. * \returns true on success or false on failure; call SDL_GetError() for more
  1493. * information.
  1494. *
  1495. * \threadsafety This function should only be called on the main thread.
  1496. *
  1497. * \since This function is available since SDL 3.2.0.
  1498. *
  1499. * \sa SDL_GetRenderTarget
  1500. */
  1501. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture);
  1502. /**
  1503. * Get the current render target.
  1504. *
  1505. * The default render target is the window for which the renderer was created,
  1506. * and is reported a NULL here.
  1507. *
  1508. * \param renderer the rendering context.
  1509. * \returns the current render target or NULL for the default render target.
  1510. *
  1511. * \threadsafety This function should only be called on the main thread.
  1512. *
  1513. * \since This function is available since SDL 3.2.0.
  1514. *
  1515. * \sa SDL_SetRenderTarget
  1516. */
  1517. extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
  1518. /**
  1519. * Set a device-independent resolution and presentation mode for rendering.
  1520. *
  1521. * This function sets the width and height of the logical rendering output.
  1522. * The renderer will act as if the current render target is always the
  1523. * requested dimensions, scaling to the actual resolution as necessary.
  1524. *
  1525. * This can be useful for games that expect a fixed size, but would like to
  1526. * scale the output to whatever is available, regardless of how a user resizes
  1527. * a window, or if the display is high DPI.
  1528. *
  1529. * Logical presentation can be used with both render target textures and the
  1530. * renderer's window; the state is unique to each render target, and this
  1531. * function sets the state for the current render target. It might be useful
  1532. * to draw to a texture that matches the window dimensions with logical
  1533. * presentation enabled, and then draw that texture across the entire window
  1534. * with logical presentation disabled. Be careful not to render both with
  1535. * logical presentation enabled, however, as this could produce
  1536. * double-letterboxing, etc.
  1537. *
  1538. * You can disable logical coordinates by setting the mode to
  1539. * SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel
  1540. * resolution of the render target; it is safe to toggle logical presentation
  1541. * during the rendering of a frame: perhaps most of the rendering is done to
  1542. * specific dimensions but to make fonts look sharp, the app turns off logical
  1543. * presentation while drawing text, for example.
  1544. *
  1545. * You can convert coordinates in an event into rendering coordinates using
  1546. * SDL_ConvertEventToRenderCoordinates().
  1547. *
  1548. * \param renderer the rendering context.
  1549. * \param w the width of the logical resolution.
  1550. * \param h the height of the logical resolution.
  1551. * \param mode the presentation mode used.
  1552. * \returns true on success or false on failure; call SDL_GetError() for more
  1553. * information.
  1554. *
  1555. * \threadsafety This function should only be called on the main thread.
  1556. *
  1557. * \since This function is available since SDL 3.2.0.
  1558. *
  1559. * \sa SDL_ConvertEventToRenderCoordinates
  1560. * \sa SDL_GetRenderLogicalPresentation
  1561. * \sa SDL_GetRenderLogicalPresentationRect
  1562. */
  1563. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode);
  1564. /**
  1565. * Get device independent resolution and presentation mode for rendering.
  1566. *
  1567. * This function gets the width and height of the logical rendering output, or
  1568. * 0 if a logical resolution is not enabled.
  1569. *
  1570. * Each render target has its own logical presentation state. This function
  1571. * gets the state for the current render target.
  1572. *
  1573. * \param renderer the rendering context.
  1574. * \param w an int filled with the logical presentation width.
  1575. * \param h an int filled with the logical presentation height.
  1576. * \param mode a variable filled with the logical presentation mode being
  1577. * used.
  1578. * \returns true on success or false on failure; call SDL_GetError() for more
  1579. * information.
  1580. *
  1581. * \threadsafety This function should only be called on the main thread.
  1582. *
  1583. * \since This function is available since SDL 3.2.0.
  1584. *
  1585. * \sa SDL_SetRenderLogicalPresentation
  1586. */
  1587. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode);
  1588. /**
  1589. * Get the final presentation rectangle for rendering.
  1590. *
  1591. * This function returns the calculated rectangle used for logical
  1592. * presentation, based on the presentation mode and output size. If logical
  1593. * presentation is disabled, it will fill the rectangle with the output size,
  1594. * in pixels.
  1595. *
  1596. * Each render target has its own logical presentation state. This function
  1597. * gets the rectangle for the current render target.
  1598. *
  1599. * \param renderer the rendering context.
  1600. * \param rect a pointer filled in with the final presentation rectangle, may
  1601. * be NULL.
  1602. * \returns true on success or false on failure; call SDL_GetError() for more
  1603. * information.
  1604. *
  1605. * \threadsafety This function should only be called on the main thread.
  1606. *
  1607. * \since This function is available since SDL 3.2.0.
  1608. *
  1609. * \sa SDL_SetRenderLogicalPresentation
  1610. */
  1611. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect);
  1612. /**
  1613. * Get a point in render coordinates when given a point in window coordinates.
  1614. *
  1615. * This takes into account several states:
  1616. *
  1617. * - The window dimensions.
  1618. * - The logical presentation settings (SDL_SetRenderLogicalPresentation)
  1619. * - The scale (SDL_SetRenderScale)
  1620. * - The viewport (SDL_SetRenderViewport)
  1621. *
  1622. * \param renderer the rendering context.
  1623. * \param window_x the x coordinate in window coordinates.
  1624. * \param window_y the y coordinate in window coordinates.
  1625. * \param x a pointer filled with the x coordinate in render coordinates.
  1626. * \param y a pointer filled with the y coordinate in render coordinates.
  1627. * \returns true on success or false on failure; call SDL_GetError() for more
  1628. * information.
  1629. *
  1630. * \threadsafety This function should only be called on the main thread.
  1631. *
  1632. * \since This function is available since SDL 3.2.0.
  1633. *
  1634. * \sa SDL_SetRenderLogicalPresentation
  1635. * \sa SDL_SetRenderScale
  1636. */
  1637. extern SDL_DECLSPEC bool SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y);
  1638. /**
  1639. * Get a point in window coordinates when given a point in render coordinates.
  1640. *
  1641. * This takes into account several states:
  1642. *
  1643. * - The window dimensions.
  1644. * - The logical presentation settings (SDL_SetRenderLogicalPresentation)
  1645. * - The scale (SDL_SetRenderScale)
  1646. * - The viewport (SDL_SetRenderViewport)
  1647. *
  1648. * \param renderer the rendering context.
  1649. * \param x the x coordinate in render coordinates.
  1650. * \param y the y coordinate in render coordinates.
  1651. * \param window_x a pointer filled with the x coordinate in window
  1652. * coordinates.
  1653. * \param window_y a pointer filled with the y coordinate in window
  1654. * coordinates.
  1655. * \returns true on success or false on failure; call SDL_GetError() for more
  1656. * information.
  1657. *
  1658. * \threadsafety This function should only be called on the main thread.
  1659. *
  1660. * \since This function is available since SDL 3.2.0.
  1661. *
  1662. * \sa SDL_SetRenderLogicalPresentation
  1663. * \sa SDL_SetRenderScale
  1664. * \sa SDL_SetRenderViewport
  1665. */
  1666. extern SDL_DECLSPEC bool SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y);
  1667. /**
  1668. * Convert the coordinates in an event to render coordinates.
  1669. *
  1670. * This takes into account several states:
  1671. *
  1672. * - The window dimensions.
  1673. * - The logical presentation settings (SDL_SetRenderLogicalPresentation)
  1674. * - The scale (SDL_SetRenderScale)
  1675. * - The viewport (SDL_SetRenderViewport)
  1676. *
  1677. * Various event types are converted with this function: mouse, touch, pen,
  1678. * etc.
  1679. *
  1680. * Touch coordinates are converted from normalized coordinates in the window
  1681. * to non-normalized rendering coordinates.
  1682. *
  1683. * Relative mouse coordinates (xrel and yrel event fields) are _also_
  1684. * converted. Applications that do not want these fields converted should use
  1685. * SDL_RenderCoordinatesFromWindow() on the specific event fields instead of
  1686. * converting the entire event structure.
  1687. *
  1688. * Once converted, coordinates may be outside the rendering area.
  1689. *
  1690. * \param renderer the rendering context.
  1691. * \param event the event to modify.
  1692. * \returns true if the event is converted or doesn't need conversion, or
  1693. * false on failure; call SDL_GetError() for more information.
  1694. *
  1695. * \threadsafety This function should only be called on the main thread.
  1696. *
  1697. * \since This function is available since SDL 3.2.0.
  1698. *
  1699. * \sa SDL_RenderCoordinatesFromWindow
  1700. */
  1701. extern SDL_DECLSPEC bool SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event);
  1702. /**
  1703. * Set the drawing area for rendering on the current target.
  1704. *
  1705. * Drawing will clip to this area (separately from any clipping done with
  1706. * SDL_SetRenderClipRect), and the top left of the area will become coordinate
  1707. * (0, 0) for future drawing commands.
  1708. *
  1709. * The area's width and height must be >= 0.
  1710. *
  1711. * Each render target has its own viewport. This function sets the viewport
  1712. * for the current render target.
  1713. *
  1714. * \param renderer the rendering context.
  1715. * \param rect the SDL_Rect structure representing the drawing area, or NULL
  1716. * to set the viewport to the entire target.
  1717. * \returns true on success or false on failure; call SDL_GetError() for more
  1718. * information.
  1719. *
  1720. * \threadsafety This function should only be called on the main thread.
  1721. *
  1722. * \since This function is available since SDL 3.2.0.
  1723. *
  1724. * \sa SDL_GetRenderViewport
  1725. * \sa SDL_RenderViewportSet
  1726. */
  1727. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
  1728. /**
  1729. * Get the drawing area for the current target.
  1730. *
  1731. * Each render target has its own viewport. This function gets the viewport
  1732. * for the current render target.
  1733. *
  1734. * \param renderer the rendering context.
  1735. * \param rect an SDL_Rect structure filled in with the current drawing area.
  1736. * \returns true on success or false on failure; call SDL_GetError() for more
  1737. * information.
  1738. *
  1739. * \threadsafety This function should only be called on the main thread.
  1740. *
  1741. * \since This function is available since SDL 3.2.0.
  1742. *
  1743. * \sa SDL_RenderViewportSet
  1744. * \sa SDL_SetRenderViewport
  1745. */
  1746. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
  1747. /**
  1748. * Return whether an explicit rectangle was set as the viewport.
  1749. *
  1750. * This is useful if you're saving and restoring the viewport and want to know
  1751. * whether you should restore a specific rectangle or NULL.
  1752. *
  1753. * Each render target has its own viewport. This function checks the viewport
  1754. * for the current render target.
  1755. *
  1756. * \param renderer the rendering context.
  1757. * \returns true if the viewport was set to a specific rectangle, or false if
  1758. * it was set to NULL (the entire target).
  1759. *
  1760. * \threadsafety This function should only be called on the main thread.
  1761. *
  1762. * \since This function is available since SDL 3.2.0.
  1763. *
  1764. * \sa SDL_GetRenderViewport
  1765. * \sa SDL_SetRenderViewport
  1766. */
  1767. extern SDL_DECLSPEC bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *renderer);
  1768. /**
  1769. * Get the safe area for rendering within the current viewport.
  1770. *
  1771. * Some devices have portions of the screen which are partially obscured or
  1772. * not interactive, possibly due to on-screen controls, curved edges, camera
  1773. * notches, TV overscan, etc. This function provides the area of the current
  1774. * viewport which is safe to have interactible content. You should continue
  1775. * rendering into the rest of the render target, but it should not contain
  1776. * visually important or interactible content.
  1777. *
  1778. * \param renderer the rendering context.
  1779. * \param rect a pointer filled in with the area that is safe for interactive
  1780. * content.
  1781. * \returns true on success or false on failure; call SDL_GetError() for more
  1782. * information.
  1783. *
  1784. * \threadsafety This function should only be called on the main thread.
  1785. *
  1786. * \since This function is available since SDL 3.2.0.
  1787. */
  1788. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect);
  1789. /**
  1790. * Set the clip rectangle for rendering on the specified target.
  1791. *
  1792. * Each render target has its own clip rectangle. This function sets the
  1793. * cliprect for the current render target.
  1794. *
  1795. * \param renderer the rendering context.
  1796. * \param rect an SDL_Rect structure representing the clip area, relative to
  1797. * the viewport, or NULL to disable clipping.
  1798. * \returns true on success or false on failure; call SDL_GetError() for more
  1799. * information.
  1800. *
  1801. * \threadsafety This function should only be called on the main thread.
  1802. *
  1803. * \since This function is available since SDL 3.2.0.
  1804. *
  1805. * \sa SDL_GetRenderClipRect
  1806. * \sa SDL_RenderClipEnabled
  1807. */
  1808. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
  1809. /**
  1810. * Get the clip rectangle for the current target.
  1811. *
  1812. * Each render target has its own clip rectangle. This function gets the
  1813. * cliprect for the current render target.
  1814. *
  1815. * \param renderer the rendering context.
  1816. * \param rect an SDL_Rect structure filled in with the current clipping area
  1817. * or an empty rectangle if clipping is disabled.
  1818. * \returns true on success or false on failure; call SDL_GetError() for more
  1819. * information.
  1820. *
  1821. * \threadsafety This function should only be called on the main thread.
  1822. *
  1823. * \since This function is available since SDL 3.2.0.
  1824. *
  1825. * \sa SDL_RenderClipEnabled
  1826. * \sa SDL_SetRenderClipRect
  1827. */
  1828. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
  1829. /**
  1830. * Get whether clipping is enabled on the given render target.
  1831. *
  1832. * Each render target has its own clip rectangle. This function checks the
  1833. * cliprect for the current render target.
  1834. *
  1835. * \param renderer the rendering context.
  1836. * \returns true if clipping is enabled or false if not; call SDL_GetError()
  1837. * for more information.
  1838. *
  1839. * \threadsafety This function should only be called on the main thread.
  1840. *
  1841. * \since This function is available since SDL 3.2.0.
  1842. *
  1843. * \sa SDL_GetRenderClipRect
  1844. * \sa SDL_SetRenderClipRect
  1845. */
  1846. extern SDL_DECLSPEC bool SDLCALL SDL_RenderClipEnabled(SDL_Renderer *renderer);
  1847. /**
  1848. * Set the drawing scale for rendering on the current target.
  1849. *
  1850. * The drawing coordinates are scaled by the x/y scaling factors before they
  1851. * are used by the renderer. This allows resolution independent drawing with a
  1852. * single coordinate system.
  1853. *
  1854. * If this results in scaling or subpixel drawing by the rendering backend, it
  1855. * will be handled using the appropriate quality hints. For best results use
  1856. * integer scaling factors.
  1857. *
  1858. * Each render target has its own scale. This function sets the scale for the
  1859. * current render target.
  1860. *
  1861. * \param renderer the rendering context.
  1862. * \param scaleX the horizontal scaling factor.
  1863. * \param scaleY the vertical scaling factor.
  1864. * \returns true on success or false on failure; call SDL_GetError() for more
  1865. * information.
  1866. *
  1867. * \threadsafety This function should only be called on the main thread.
  1868. *
  1869. * \since This function is available since SDL 3.2.0.
  1870. *
  1871. * \sa SDL_GetRenderScale
  1872. */
  1873. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY);
  1874. /**
  1875. * Get the drawing scale for the current target.
  1876. *
  1877. * Each render target has its own scale. This function gets the scale for the
  1878. * current render target.
  1879. *
  1880. * \param renderer the rendering context.
  1881. * \param scaleX a pointer filled in with the horizontal scaling factor.
  1882. * \param scaleY a pointer filled in with the vertical scaling factor.
  1883. * \returns true on success or false on failure; call SDL_GetError() for more
  1884. * information.
  1885. *
  1886. * \threadsafety This function should only be called on the main thread.
  1887. *
  1888. * \since This function is available since SDL 3.2.0.
  1889. *
  1890. * \sa SDL_SetRenderScale
  1891. */
  1892. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
  1893. /**
  1894. * Set the color used for drawing operations.
  1895. *
  1896. * Set the color for drawing or filling rectangles, lines, and points, and for
  1897. * SDL_RenderClear().
  1898. *
  1899. * \param renderer the rendering context.
  1900. * \param r the red value used to draw on the rendering target.
  1901. * \param g the green value used to draw on the rendering target.
  1902. * \param b the blue value used to draw on the rendering target.
  1903. * \param a the alpha value used to draw on the rendering target; usually
  1904. * `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to
  1905. * specify how the alpha channel is used.
  1906. * \returns true on success or false on failure; call SDL_GetError() for more
  1907. * information.
  1908. *
  1909. * \threadsafety This function should only be called on the main thread.
  1910. *
  1911. * \since This function is available since SDL 3.2.0.
  1912. *
  1913. * \sa SDL_GetRenderDrawColor
  1914. * \sa SDL_SetRenderDrawColorFloat
  1915. */
  1916. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  1917. /**
  1918. * Set the color used for drawing operations (Rect, Line and Clear).
  1919. *
  1920. * Set the color for drawing or filling rectangles, lines, and points, and for
  1921. * SDL_RenderClear().
  1922. *
  1923. * \param renderer the rendering context.
  1924. * \param r the red value used to draw on the rendering target.
  1925. * \param g the green value used to draw on the rendering target.
  1926. * \param b the blue value used to draw on the rendering target.
  1927. * \param a the alpha value used to draw on the rendering target. Use
  1928. * SDL_SetRenderDrawBlendMode to specify how the alpha channel is
  1929. * used.
  1930. * \returns true on success or false on failure; call SDL_GetError() for more
  1931. * information.
  1932. *
  1933. * \threadsafety This function should only be called on the main thread.
  1934. *
  1935. * \since This function is available since SDL 3.2.0.
  1936. *
  1937. * \sa SDL_GetRenderDrawColorFloat
  1938. * \sa SDL_SetRenderDrawColor
  1939. */
  1940. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a);
  1941. /**
  1942. * Get the color used for drawing operations (Rect, Line and Clear).
  1943. *
  1944. * \param renderer the rendering context.
  1945. * \param r a pointer filled in with the red value used to draw on the
  1946. * rendering target.
  1947. * \param g a pointer filled in with the green value used to draw on the
  1948. * rendering target.
  1949. * \param b a pointer filled in with the blue value used to draw on the
  1950. * rendering target.
  1951. * \param a a pointer filled in with the alpha value used to draw on the
  1952. * rendering target; usually `SDL_ALPHA_OPAQUE` (255).
  1953. * \returns true on success or false on failure; call SDL_GetError() for more
  1954. * information.
  1955. *
  1956. * \threadsafety This function should only be called on the main thread.
  1957. *
  1958. * \since This function is available since SDL 3.2.0.
  1959. *
  1960. * \sa SDL_GetRenderDrawColorFloat
  1961. * \sa SDL_SetRenderDrawColor
  1962. */
  1963. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1964. /**
  1965. * Get the color used for drawing operations (Rect, Line and Clear).
  1966. *
  1967. * \param renderer the rendering context.
  1968. * \param r a pointer filled in with the red value used to draw on the
  1969. * rendering target.
  1970. * \param g a pointer filled in with the green value used to draw on the
  1971. * rendering target.
  1972. * \param b a pointer filled in with the blue value used to draw on the
  1973. * rendering target.
  1974. * \param a a pointer filled in with the alpha value used to draw on the
  1975. * rendering target.
  1976. * \returns true on success or false on failure; call SDL_GetError() for more
  1977. * information.
  1978. *
  1979. * \threadsafety This function should only be called on the main thread.
  1980. *
  1981. * \since This function is available since SDL 3.2.0.
  1982. *
  1983. * \sa SDL_SetRenderDrawColorFloat
  1984. * \sa SDL_GetRenderDrawColor
  1985. */
  1986. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a);
  1987. /**
  1988. * Set the color scale used for render operations.
  1989. *
  1990. * The color scale is an additional scale multiplied into the pixel color
  1991. * value while rendering. This can be used to adjust the brightness of colors
  1992. * during HDR rendering, or changing HDR video brightness when playing on an
  1993. * SDR display.
  1994. *
  1995. * The color scale does not affect the alpha channel, only the color
  1996. * brightness.
  1997. *
  1998. * \param renderer the rendering context.
  1999. * \param scale the color scale value.
  2000. * \returns true on success or false on failure; call SDL_GetError() for more
  2001. * information.
  2002. *
  2003. * \threadsafety This function should only be called on the main thread.
  2004. *
  2005. * \since This function is available since SDL 3.2.0.
  2006. *
  2007. * \sa SDL_GetRenderColorScale
  2008. */
  2009. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale);
  2010. /**
  2011. * Get the color scale used for render operations.
  2012. *
  2013. * \param renderer the rendering context.
  2014. * \param scale a pointer filled in with the current color scale value.
  2015. * \returns true on success or false on failure; call SDL_GetError() for more
  2016. * information.
  2017. *
  2018. * \threadsafety This function should only be called on the main thread.
  2019. *
  2020. * \since This function is available since SDL 3.2.0.
  2021. *
  2022. * \sa SDL_SetRenderColorScale
  2023. */
  2024. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale);
  2025. /**
  2026. * Set the blend mode used for drawing operations.
  2027. *
  2028. * This blend mode is used for any drawing that doesn't involve textures.
  2029. *
  2030. * If the blend mode is not supported, the closest supported mode is chosen.
  2031. *
  2032. * \param renderer the rendering context.
  2033. * \param blendMode the SDL_BlendMode to use for blending.
  2034. * \returns true on success or false on failure; call SDL_GetError() for more
  2035. * information.
  2036. *
  2037. * \threadsafety This function should only be called on the main thread.
  2038. *
  2039. * \since This function is available since SDL 3.2.0.
  2040. *
  2041. * \sa SDL_GetRenderDrawBlendMode
  2042. * \sa SDL_SetTextureBlendMode
  2043. */
  2044. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);
  2045. /**
  2046. * Get the blend mode used for drawing operations.
  2047. *
  2048. * \param renderer the rendering context.
  2049. * \param blendMode a pointer filled in with the current SDL_BlendMode.
  2050. * \returns true on success or false on failure; call SDL_GetError() for more
  2051. * information.
  2052. *
  2053. * \threadsafety This function should only be called on the main thread.
  2054. *
  2055. * \since This function is available since SDL 3.2.0.
  2056. *
  2057. * \sa SDL_SetRenderDrawBlendMode
  2058. */
  2059. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode);
  2060. /**
  2061. * Clear the current rendering target with the drawing color.
  2062. *
  2063. * This function clears the entire rendering target, ignoring the viewport and
  2064. * the clip rectangle. Note, that clearing will also set/fill all pixels of
  2065. * the rendering target to current renderer draw color, so make sure to invoke
  2066. * SDL_SetRenderDrawColor() when needed.
  2067. *
  2068. * \param renderer the rendering context.
  2069. * \returns true on success or false on failure; call SDL_GetError() for more
  2070. * information.
  2071. *
  2072. * \threadsafety This function should only be called on the main thread.
  2073. *
  2074. * \since This function is available since SDL 3.2.0.
  2075. *
  2076. * \sa SDL_SetRenderDrawColor
  2077. */
  2078. extern SDL_DECLSPEC bool SDLCALL SDL_RenderClear(SDL_Renderer *renderer);
  2079. /**
  2080. * Draw a point on the current rendering target at subpixel precision.
  2081. *
  2082. * \param renderer the renderer which should draw a point.
  2083. * \param x the x coordinate of the point.
  2084. * \param y the y coordinate of the point.
  2085. * \returns true on success or false on failure; call SDL_GetError() for more
  2086. * information.
  2087. *
  2088. * \threadsafety This function should only be called on the main thread.
  2089. *
  2090. * \since This function is available since SDL 3.2.0.
  2091. *
  2092. * \sa SDL_RenderPoints
  2093. */
  2094. extern SDL_DECLSPEC bool SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y);
  2095. /**
  2096. * Draw multiple points on the current rendering target at subpixel precision.
  2097. *
  2098. * \param renderer the renderer which should draw multiple points.
  2099. * \param points the points to draw.
  2100. * \param count the number of points to draw.
  2101. * \returns true on success or false on failure; call SDL_GetError() for more
  2102. * information.
  2103. *
  2104. * \threadsafety This function should only be called on the main thread.
  2105. *
  2106. * \since This function is available since SDL 3.2.0.
  2107. *
  2108. * \sa SDL_RenderPoint
  2109. */
  2110. extern SDL_DECLSPEC bool SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  2111. /**
  2112. * Draw a line on the current rendering target at subpixel precision.
  2113. *
  2114. * \param renderer the renderer which should draw a line.
  2115. * \param x1 the x coordinate of the start point.
  2116. * \param y1 the y coordinate of the start point.
  2117. * \param x2 the x coordinate of the end point.
  2118. * \param y2 the y coordinate of the end point.
  2119. * \returns true on success or false on failure; call SDL_GetError() for more
  2120. * information.
  2121. *
  2122. * \threadsafety This function should only be called on the main thread.
  2123. *
  2124. * \since This function is available since SDL 3.2.0.
  2125. *
  2126. * \sa SDL_RenderLines
  2127. */
  2128. extern SDL_DECLSPEC bool SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2);
  2129. /**
  2130. * Draw a series of connected lines on the current rendering target at
  2131. * subpixel precision.
  2132. *
  2133. * \param renderer the renderer which should draw multiple lines.
  2134. * \param points the points along the lines.
  2135. * \param count the number of points, drawing count-1 lines.
  2136. * \returns true on success or false on failure; call SDL_GetError() for more
  2137. * information.
  2138. *
  2139. * \threadsafety This function should only be called on the main thread.
  2140. *
  2141. * \since This function is available since SDL 3.2.0.
  2142. *
  2143. * \sa SDL_RenderLine
  2144. */
  2145. extern SDL_DECLSPEC bool SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  2146. /**
  2147. * Draw a rectangle on the current rendering target at subpixel precision.
  2148. *
  2149. * \param renderer the renderer which should draw a rectangle.
  2150. * \param rect a pointer to the destination rectangle, or NULL to outline the
  2151. * entire rendering target.
  2152. * \returns true on success or false on failure; call SDL_GetError() for more
  2153. * information.
  2154. *
  2155. * \threadsafety This function should only be called on the main thread.
  2156. *
  2157. * \since This function is available since SDL 3.2.0.
  2158. *
  2159. * \sa SDL_RenderRects
  2160. */
  2161. extern SDL_DECLSPEC bool SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  2162. /**
  2163. * Draw some number of rectangles on the current rendering target at subpixel
  2164. * precision.
  2165. *
  2166. * \param renderer the renderer which should draw multiple rectangles.
  2167. * \param rects a pointer to an array of destination rectangles.
  2168. * \param count the number of rectangles.
  2169. * \returns true on success or false on failure; call SDL_GetError() for more
  2170. * information.
  2171. *
  2172. * \threadsafety This function should only be called on the main thread.
  2173. *
  2174. * \since This function is available since SDL 3.2.0.
  2175. *
  2176. * \sa SDL_RenderRect
  2177. */
  2178. extern SDL_DECLSPEC bool SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  2179. /**
  2180. * Fill a rectangle on the current rendering target with the drawing color at
  2181. * subpixel precision.
  2182. *
  2183. * \param renderer the renderer which should fill a rectangle.
  2184. * \param rect a pointer to the destination rectangle, or NULL for the entire
  2185. * rendering target.
  2186. * \returns true on success or false on failure; call SDL_GetError() for more
  2187. * information.
  2188. *
  2189. * \threadsafety This function should only be called on the main thread.
  2190. *
  2191. * \since This function is available since SDL 3.2.0.
  2192. *
  2193. * \sa SDL_RenderFillRects
  2194. */
  2195. extern SDL_DECLSPEC bool SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  2196. /**
  2197. * Fill some number of rectangles on the current rendering target with the
  2198. * drawing color at subpixel precision.
  2199. *
  2200. * \param renderer the renderer which should fill multiple rectangles.
  2201. * \param rects a pointer to an array of destination rectangles.
  2202. * \param count the number of rectangles.
  2203. * \returns true on success or false on failure; call SDL_GetError() for more
  2204. * information.
  2205. *
  2206. * \threadsafety This function should only be called on the main thread.
  2207. *
  2208. * \since This function is available since SDL 3.2.0.
  2209. *
  2210. * \sa SDL_RenderFillRect
  2211. */
  2212. extern SDL_DECLSPEC bool SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  2213. /**
  2214. * Copy a portion of the texture to the current rendering target at subpixel
  2215. * precision.
  2216. *
  2217. * \param renderer the renderer which should copy parts of a texture.
  2218. * \param texture the source texture.
  2219. * \param srcrect a pointer to the source rectangle, or NULL for the entire
  2220. * texture.
  2221. * \param dstrect a pointer to the destination rectangle, or NULL for the
  2222. * entire rendering target.
  2223. * \returns true on success or false on failure; call SDL_GetError() for more
  2224. * information.
  2225. *
  2226. * \threadsafety This function should only be called on the main thread.
  2227. *
  2228. * \since This function is available since SDL 3.2.0.
  2229. *
  2230. * \sa SDL_RenderTextureRotated
  2231. * \sa SDL_RenderTextureTiled
  2232. */
  2233. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);
  2234. /**
  2235. * Copy a portion of the source texture to the current rendering target, with
  2236. * rotation and flipping, at subpixel precision.
  2237. *
  2238. * \param renderer the renderer which should copy parts of a texture.
  2239. * \param texture the source texture.
  2240. * \param srcrect a pointer to the source rectangle, or NULL for the entire
  2241. * texture.
  2242. * \param dstrect a pointer to the destination rectangle, or NULL for the
  2243. * entire rendering target.
  2244. * \param angle an angle in degrees that indicates the rotation that will be
  2245. * applied to dstrect, rotating it in a clockwise direction.
  2246. * \param center a pointer to a point indicating the point around which
  2247. * dstrect will be rotated (if NULL, rotation will be done
  2248. * around dstrect.w/2, dstrect.h/2).
  2249. * \param flip an SDL_FlipMode value stating which flipping actions should be
  2250. * performed on the texture.
  2251. * \returns true on success or false on failure; call SDL_GetError() for more
  2252. * information.
  2253. *
  2254. * \threadsafety This function should only be called on the main thread.
  2255. *
  2256. * \since This function is available since SDL 3.2.0.
  2257. *
  2258. * \sa SDL_RenderTexture
  2259. */
  2260. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
  2261. const SDL_FRect *srcrect, const SDL_FRect *dstrect,
  2262. double angle, const SDL_FPoint *center,
  2263. SDL_FlipMode flip);
  2264. /**
  2265. * Copy a portion of the source texture to the current rendering target, with
  2266. * affine transform, at subpixel precision.
  2267. *
  2268. * \param renderer the renderer which should copy parts of a texture.
  2269. * \param texture the source texture.
  2270. * \param srcrect a pointer to the source rectangle, or NULL for the entire
  2271. * texture.
  2272. * \param origin a pointer to a point indicating where the top-left corner of
  2273. * srcrect should be mapped to, or NULL for the rendering
  2274. * target's origin.
  2275. * \param right a pointer to a point indicating where the top-right corner of
  2276. * srcrect should be mapped to, or NULL for the rendering
  2277. * target's top-right corner.
  2278. * \param down a pointer to a point indicating where the bottom-left corner of
  2279. * srcrect should be mapped to, or NULL for the rendering target's
  2280. * bottom-left corner.
  2281. * \returns true on success or false on failure; call SDL_GetError() for more
  2282. * information.
  2283. *
  2284. * \threadsafety You may only call this function from the main thread.
  2285. *
  2286. * \since This function is available since SDL 3.2.0.
  2287. *
  2288. * \sa SDL_RenderTexture
  2289. */
  2290. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTextureAffine(SDL_Renderer *renderer, SDL_Texture *texture,
  2291. const SDL_FRect *srcrect, const SDL_FPoint *origin,
  2292. const SDL_FPoint *right, const SDL_FPoint *down);
  2293. /**
  2294. * Tile a portion of the texture to the current rendering target at subpixel
  2295. * precision.
  2296. *
  2297. * The pixels in `srcrect` will be repeated as many times as needed to
  2298. * completely fill `dstrect`.
  2299. *
  2300. * \param renderer the renderer which should copy parts of a texture.
  2301. * \param texture the source texture.
  2302. * \param srcrect a pointer to the source rectangle, or NULL for the entire
  2303. * texture.
  2304. * \param scale the scale used to transform srcrect into the destination
  2305. * rectangle, e.g. a 32x32 texture with a scale of 2 would fill
  2306. * 64x64 tiles.
  2307. * \param dstrect a pointer to the destination rectangle, or NULL for the
  2308. * entire rendering target.
  2309. * \returns true on success or false on failure; call SDL_GetError() for more
  2310. * information.
  2311. *
  2312. * \threadsafety This function should only be called on the main thread.
  2313. *
  2314. * \since This function is available since SDL 3.2.0.
  2315. *
  2316. * \sa SDL_RenderTexture
  2317. */
  2318. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect);
  2319. /**
  2320. * Perform a scaled copy using the 9-grid algorithm to the current rendering
  2321. * target at subpixel precision.
  2322. *
  2323. * The pixels in the texture are split into a 3x3 grid, using the different
  2324. * corner sizes for each corner, and the sides and center making up the
  2325. * remaining pixels. The corners are then scaled using `scale` and fit into
  2326. * the corners of the destination rectangle. The sides and center are then
  2327. * stretched into place to cover the remaining destination rectangle.
  2328. *
  2329. * \param renderer the renderer which should copy parts of a texture.
  2330. * \param texture the source texture.
  2331. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  2332. * for the 9-grid, or NULL to use the entire texture.
  2333. * \param left_width the width, in pixels, of the left corners in `srcrect`.
  2334. * \param right_width the width, in pixels, of the right corners in `srcrect`.
  2335. * \param top_height the height, in pixels, of the top corners in `srcrect`.
  2336. * \param bottom_height the height, in pixels, of the bottom corners in
  2337. * `srcrect`.
  2338. * \param scale the scale used to transform the corner of `srcrect` into the
  2339. * corner of `dstrect`, or 0.0f for an unscaled copy.
  2340. * \param dstrect a pointer to the destination rectangle, or NULL for the
  2341. * entire rendering target.
  2342. * \returns true on success or false on failure; call SDL_GetError() for more
  2343. * information.
  2344. *
  2345. * \threadsafety This function should only be called on the main thread.
  2346. *
  2347. * \since This function is available since SDL 3.2.0.
  2348. *
  2349. * \sa SDL_RenderTexture
  2350. * \sa SDL_RenderTexture9GridTiled
  2351. */
  2352. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect);
  2353. /**
  2354. * Perform a scaled copy using the 9-grid algorithm to the current rendering
  2355. * target at subpixel precision.
  2356. *
  2357. * The pixels in the texture are split into a 3x3 grid, using the different
  2358. * corner sizes for each corner, and the sides and center making up the
  2359. * remaining pixels. The corners are then scaled using `scale` and fit into
  2360. * the corners of the destination rectangle. The sides and center are then
  2361. * tiled into place to cover the remaining destination rectangle.
  2362. *
  2363. * \param renderer the renderer which should copy parts of a texture.
  2364. * \param texture the source texture.
  2365. * \param srcrect the SDL_Rect structure representing the rectangle to be used
  2366. * for the 9-grid, or NULL to use the entire texture.
  2367. * \param left_width the width, in pixels, of the left corners in `srcrect`.
  2368. * \param right_width the width, in pixels, of the right corners in `srcrect`.
  2369. * \param top_height the height, in pixels, of the top corners in `srcrect`.
  2370. * \param bottom_height the height, in pixels, of the bottom corners in
  2371. * `srcrect`.
  2372. * \param scale the scale used to transform the corner of `srcrect` into the
  2373. * corner of `dstrect`, or 0.0f for an unscaled copy.
  2374. * \param dstrect a pointer to the destination rectangle, or NULL for the
  2375. * entire rendering target.
  2376. * \param tileScale the scale used to transform the borders and center of
  2377. * `srcrect` into the borders and middle of `dstrect`, or
  2378. * 1.0f for an unscaled copy.
  2379. * \returns true on success or false on failure; call SDL_GetError() for more
  2380. * information.
  2381. *
  2382. * \threadsafety This function should only be called on the main thread.
  2383. *
  2384. * \since This function is available since SDL 3.4.0.
  2385. *
  2386. * \sa SDL_RenderTexture
  2387. * \sa SDL_RenderTexture9Grid
  2388. */
  2389. extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9GridTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect, float tileScale);
  2390. /**
  2391. * Render a list of triangles, optionally using a texture and indices into the
  2392. * vertex array.
  2393. *
  2394. * Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and
  2395. * SDL_SetTextureAlphaMod are ignored).
  2396. *
  2397. * \param renderer the rendering context.
  2398. * \param texture (optional) The SDL texture to use.
  2399. * \param vertices vertices.
  2400. * \param num_vertices number of vertices.
  2401. * \param indices (optional) An array of integer indices into the 'vertices'
  2402. * array, if NULL all vertices will be rendered in sequential
  2403. * order.
  2404. * \param num_indices number of indices.
  2405. * \returns true on success or false on failure; call SDL_GetError() for more
  2406. * information.
  2407. *
  2408. * \threadsafety This function should only be called on the main thread.
  2409. *
  2410. * \since This function is available since SDL 3.2.0.
  2411. *
  2412. * \sa SDL_RenderGeometryRaw
  2413. * \sa SDL_SetRenderTextureAddressMode
  2414. */
  2415. extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
  2416. SDL_Texture *texture,
  2417. const SDL_Vertex *vertices, int num_vertices,
  2418. const int *indices, int num_indices);
  2419. /**
  2420. * Render a list of triangles, optionally using a texture and indices into the
  2421. * vertex arrays.
  2422. *
  2423. * Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and
  2424. * SDL_SetTextureAlphaMod are ignored).
  2425. *
  2426. * \param renderer the rendering context.
  2427. * \param texture (optional) The SDL texture to use.
  2428. * \param xy vertex positions.
  2429. * \param xy_stride byte size to move from one element to the next element.
  2430. * \param color vertex colors (as SDL_FColor).
  2431. * \param color_stride byte size to move from one element to the next element.
  2432. * \param uv vertex normalized texture coordinates.
  2433. * \param uv_stride byte size to move from one element to the next element.
  2434. * \param num_vertices number of vertices.
  2435. * \param indices (optional) An array of indices into the 'vertices' arrays,
  2436. * if NULL all vertices will be rendered in sequential order.
  2437. * \param num_indices number of indices.
  2438. * \param size_indices index size: 1 (byte), 2 (short), 4 (int).
  2439. * \returns true on success or false on failure; call SDL_GetError() for more
  2440. * information.
  2441. *
  2442. * \threadsafety This function should only be called on the main thread.
  2443. *
  2444. * \since This function is available since SDL 3.2.0.
  2445. *
  2446. * \sa SDL_RenderGeometry
  2447. * \sa SDL_SetRenderTextureAddressMode
  2448. */
  2449. extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
  2450. SDL_Texture *texture,
  2451. const float *xy, int xy_stride,
  2452. const SDL_FColor *color, int color_stride,
  2453. const float *uv, int uv_stride,
  2454. int num_vertices,
  2455. const void *indices, int num_indices, int size_indices);
  2456. /**
  2457. * Set the texture addressing mode used in SDL_RenderGeometry().
  2458. *
  2459. * \param renderer the rendering context.
  2460. * \param u_mode the SDL_TextureAddressMode to use for horizontal texture
  2461. * coordinates in SDL_RenderGeometry().
  2462. * \param v_mode the SDL_TextureAddressMode to use for vertical texture
  2463. * coordinates in SDL_RenderGeometry().
  2464. * \returns true on success or false on failure; call SDL_GetError() for more
  2465. * information.
  2466. *
  2467. * \threadsafety This function should only be called on the main thread.
  2468. *
  2469. * \since This function is available since SDL 3.4.0.
  2470. *
  2471. * \sa SDL_RenderGeometry
  2472. * \sa SDL_RenderGeometryRaw
  2473. * \sa SDL_GetRenderTextureAddressMode
  2474. */
  2475. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderTextureAddressMode(SDL_Renderer *renderer, SDL_TextureAddressMode u_mode, SDL_TextureAddressMode v_mode);
  2476. /**
  2477. * Get the texture addressing mode used in SDL_RenderGeometry().
  2478. *
  2479. * \param renderer the rendering context.
  2480. * \param u_mode a pointer filled in with the SDL_TextureAddressMode to use
  2481. * for horizontal texture coordinates in SDL_RenderGeometry(),
  2482. * may be NULL.
  2483. * \param v_mode a pointer filled in with the SDL_TextureAddressMode to use
  2484. * for vertical texture coordinates in SDL_RenderGeometry(), may
  2485. * be NULL.
  2486. * \returns true on success or false on failure; call SDL_GetError() for more
  2487. * information.
  2488. *
  2489. * \threadsafety This function should only be called on the main thread.
  2490. *
  2491. * \since This function is available since SDL 3.4.0.
  2492. *
  2493. * \sa SDL_SetRenderTextureAddressMode
  2494. */
  2495. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderTextureAddressMode(SDL_Renderer *renderer, SDL_TextureAddressMode *u_mode, SDL_TextureAddressMode *v_mode);
  2496. /**
  2497. * Read pixels from the current rendering target.
  2498. *
  2499. * The returned surface contains pixels inside the desired area clipped to the
  2500. * current viewport, and should be freed with SDL_DestroySurface().
  2501. *
  2502. * Note that this returns the actual pixels on the screen, so if you are using
  2503. * logical presentation you should use SDL_GetRenderLogicalPresentationRect()
  2504. * to get the area containing your content.
  2505. *
  2506. * **WARNING**: This is a very slow operation, and should not be used
  2507. * frequently. If you're using this on the main rendering target, it should be
  2508. * called after rendering and before SDL_RenderPresent().
  2509. *
  2510. * \param renderer the rendering context.
  2511. * \param rect an SDL_Rect structure representing the area to read, which will
  2512. * be clipped to the current viewport, or NULL for the entire
  2513. * viewport.
  2514. * \returns a new SDL_Surface on success or NULL on failure; call
  2515. * SDL_GetError() for more information.
  2516. *
  2517. * \threadsafety This function should only be called on the main thread.
  2518. *
  2519. * \since This function is available since SDL 3.2.0.
  2520. */
  2521. extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect);
  2522. /**
  2523. * Update the screen with any rendering performed since the previous call.
  2524. *
  2525. * SDL's rendering functions operate on a backbuffer; that is, calling a
  2526. * rendering function such as SDL_RenderLine() does not directly put a line on
  2527. * the screen, but rather updates the backbuffer. As such, you compose your
  2528. * entire scene and *present* the composed backbuffer to the screen as a
  2529. * complete picture.
  2530. *
  2531. * Therefore, when using SDL's rendering API, one does all drawing intended
  2532. * for the frame, and then calls this function once per frame to present the
  2533. * final drawing to the user.
  2534. *
  2535. * The backbuffer should be considered invalidated after each present; do not
  2536. * assume that previous contents will exist between frames. You are strongly
  2537. * encouraged to call SDL_RenderClear() to initialize the backbuffer before
  2538. * starting each new frame's drawing, even if you plan to overwrite every
  2539. * pixel.
  2540. *
  2541. * Please note, that in case of rendering to a texture - there is **no need**
  2542. * to call `SDL_RenderPresent` after drawing needed objects to a texture, and
  2543. * should not be done; you are only required to change back the rendering
  2544. * target to default via `SDL_SetRenderTarget(renderer, NULL)` afterwards, as
  2545. * textures by themselves do not have a concept of backbuffers. Calling
  2546. * SDL_RenderPresent while rendering to a texture will fail.
  2547. *
  2548. * \param renderer the rendering context.
  2549. * \returns true on success or false on failure; call SDL_GetError() for more
  2550. * information.
  2551. *
  2552. * \threadsafety This function should only be called on the main thread.
  2553. *
  2554. * \since This function is available since SDL 3.2.0.
  2555. *
  2556. * \sa SDL_CreateRenderer
  2557. * \sa SDL_RenderClear
  2558. * \sa SDL_RenderFillRect
  2559. * \sa SDL_RenderFillRects
  2560. * \sa SDL_RenderLine
  2561. * \sa SDL_RenderLines
  2562. * \sa SDL_RenderPoint
  2563. * \sa SDL_RenderPoints
  2564. * \sa SDL_RenderRect
  2565. * \sa SDL_RenderRects
  2566. * \sa SDL_SetRenderDrawBlendMode
  2567. * \sa SDL_SetRenderDrawColor
  2568. */
  2569. extern SDL_DECLSPEC bool SDLCALL SDL_RenderPresent(SDL_Renderer *renderer);
  2570. /**
  2571. * Destroy the specified texture.
  2572. *
  2573. * Passing NULL or an otherwise invalid texture will set the SDL error message
  2574. * to "Invalid texture".
  2575. *
  2576. * \param texture the texture to destroy.
  2577. *
  2578. * \threadsafety This function should only be called on the main thread.
  2579. *
  2580. * \since This function is available since SDL 3.2.0.
  2581. *
  2582. * \sa SDL_CreateTexture
  2583. * \sa SDL_CreateTextureFromSurface
  2584. */
  2585. extern SDL_DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture *texture);
  2586. /**
  2587. * Destroy the rendering context for a window and free all associated
  2588. * textures.
  2589. *
  2590. * This should be called before destroying the associated window.
  2591. *
  2592. * \param renderer the rendering context.
  2593. *
  2594. * \threadsafety This function should only be called on the main thread.
  2595. *
  2596. * \since This function is available since SDL 3.2.0.
  2597. *
  2598. * \sa SDL_CreateRenderer
  2599. */
  2600. extern SDL_DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer *renderer);
  2601. /**
  2602. * Force the rendering context to flush any pending commands and state.
  2603. *
  2604. * You do not need to (and in fact, shouldn't) call this function unless you
  2605. * are planning to call into OpenGL/Direct3D/Metal/whatever directly, in
  2606. * addition to using an SDL_Renderer.
  2607. *
  2608. * This is for a very-specific case: if you are using SDL's render API, and
  2609. * you plan to make OpenGL/D3D/whatever calls in addition to SDL render API
  2610. * calls. If this applies, you should call this function between calls to
  2611. * SDL's render API and the low-level API you're using in cooperation.
  2612. *
  2613. * In all other cases, you can ignore this function.
  2614. *
  2615. * This call makes SDL flush any pending rendering work it was queueing up to
  2616. * do later in a single batch, and marks any internal cached state as invalid,
  2617. * so it'll prepare all its state again later, from scratch.
  2618. *
  2619. * This means you do not need to save state in your rendering code to protect
  2620. * the SDL renderer. However, there lots of arbitrary pieces of Direct3D and
  2621. * OpenGL state that can confuse things; you should use your best judgment and
  2622. * be prepared to make changes if specific state needs to be protected.
  2623. *
  2624. * \param renderer the rendering context.
  2625. * \returns true on success or false on failure; call SDL_GetError() for more
  2626. * information.
  2627. *
  2628. * \threadsafety This function should only be called on the main thread.
  2629. *
  2630. * \since This function is available since SDL 3.2.0.
  2631. */
  2632. extern SDL_DECLSPEC bool SDLCALL SDL_FlushRenderer(SDL_Renderer *renderer);
  2633. /**
  2634. * Get the CAMetalLayer associated with the given Metal renderer.
  2635. *
  2636. * This function returns `void *`, so SDL doesn't have to include Metal's
  2637. * headers, but it can be safely cast to a `CAMetalLayer *`.
  2638. *
  2639. * \param renderer the renderer to query.
  2640. * \returns a `CAMetalLayer *` on success, or NULL if the renderer isn't a
  2641. * Metal renderer.
  2642. *
  2643. * \threadsafety This function should only be called on the main thread.
  2644. *
  2645. * \since This function is available since SDL 3.2.0.
  2646. *
  2647. * \sa SDL_GetRenderMetalCommandEncoder
  2648. */
  2649. extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalLayer(SDL_Renderer *renderer);
  2650. /**
  2651. * Get the Metal command encoder for the current frame.
  2652. *
  2653. * This function returns `void *`, so SDL doesn't have to include Metal's
  2654. * headers, but it can be safely cast to an `id<MTLRenderCommandEncoder>`.
  2655. *
  2656. * This will return NULL if Metal refuses to give SDL a drawable to render to,
  2657. * which might happen if the window is hidden/minimized/offscreen. This
  2658. * doesn't apply to command encoders for render targets, just the window's
  2659. * backbuffer. Check your return values!
  2660. *
  2661. * \param renderer the renderer to query.
  2662. * \returns an `id<MTLRenderCommandEncoder>` on success, or NULL if the
  2663. * renderer isn't a Metal renderer or there was an error.
  2664. *
  2665. * \threadsafety This function should only be called on the main thread.
  2666. *
  2667. * \since This function is available since SDL 3.2.0.
  2668. *
  2669. * \sa SDL_GetRenderMetalLayer
  2670. */
  2671. extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer);
  2672. /**
  2673. * Add a set of synchronization semaphores for the current frame.
  2674. *
  2675. * The Vulkan renderer will wait for `wait_semaphore` before submitting
  2676. * rendering commands and signal `signal_semaphore` after rendering commands
  2677. * are complete for this frame.
  2678. *
  2679. * This should be called each frame that you want semaphore synchronization.
  2680. * The Vulkan renderer may have multiple frames in flight on the GPU, so you
  2681. * should have multiple semaphores that are used for synchronization. Querying
  2682. * SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER will give you the
  2683. * maximum number of semaphores you'll need.
  2684. *
  2685. * \param renderer the rendering context.
  2686. * \param wait_stage_mask the VkPipelineStageFlags for the wait.
  2687. * \param wait_semaphore a VkSempahore to wait on before rendering the current
  2688. * frame, or 0 if not needed.
  2689. * \param signal_semaphore a VkSempahore that SDL will signal when rendering
  2690. * for the current frame is complete, or 0 if not
  2691. * needed.
  2692. * \returns true on success or false on failure; call SDL_GetError() for more
  2693. * information.
  2694. *
  2695. * \threadsafety It is **NOT** safe to call this function from two threads at
  2696. * once.
  2697. *
  2698. * \since This function is available since SDL 3.2.0.
  2699. */
  2700. extern SDL_DECLSPEC bool SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore);
  2701. /**
  2702. * Toggle VSync of the given renderer.
  2703. *
  2704. * When a renderer is created, vsync defaults to SDL_RENDERER_VSYNC_DISABLED.
  2705. *
  2706. * The `vsync` parameter can be 1 to synchronize present with every vertical
  2707. * refresh, 2 to synchronize present with every second vertical refresh, etc.,
  2708. * SDL_RENDERER_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync), or
  2709. * SDL_RENDERER_VSYNC_DISABLED to disable. Not every value is supported by
  2710. * every driver, so you should check the return value to see whether the
  2711. * requested setting is supported.
  2712. *
  2713. * \param renderer the renderer to toggle.
  2714. * \param vsync the vertical refresh sync interval.
  2715. * \returns true on success or false on failure; call SDL_GetError() for more
  2716. * information.
  2717. *
  2718. * \threadsafety This function should only be called on the main thread.
  2719. *
  2720. * \since This function is available since SDL 3.2.0.
  2721. *
  2722. * \sa SDL_GetRenderVSync
  2723. */
  2724. extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync);
  2725. #define SDL_RENDERER_VSYNC_DISABLED 0
  2726. #define SDL_RENDERER_VSYNC_ADAPTIVE (-1)
  2727. /**
  2728. * Get VSync of the given renderer.
  2729. *
  2730. * \param renderer the renderer to toggle.
  2731. * \param vsync an int filled with the current vertical refresh sync interval.
  2732. * See SDL_SetRenderVSync() for the meaning of the value.
  2733. * \returns true on success or false on failure; call SDL_GetError() for more
  2734. * information.
  2735. *
  2736. * \threadsafety This function should only be called on the main thread.
  2737. *
  2738. * \since This function is available since SDL 3.2.0.
  2739. *
  2740. * \sa SDL_SetRenderVSync
  2741. */
  2742. extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
  2743. /**
  2744. * The size, in pixels, of a single SDL_RenderDebugText() character.
  2745. *
  2746. * The font is monospaced and square, so this applies to all characters.
  2747. *
  2748. * \since This macro is available since SDL 3.2.0.
  2749. *
  2750. * \sa SDL_RenderDebugText
  2751. */
  2752. #define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE 8
  2753. /**
  2754. * Draw debug text to an SDL_Renderer.
  2755. *
  2756. * This function will render a string of text to an SDL_Renderer. Note that
  2757. * this is a convenience function for debugging, with severe limitations, and
  2758. * not intended to be used for production apps and games.
  2759. *
  2760. * Among these limitations:
  2761. *
  2762. * - It accepts UTF-8 strings, but will only renders ASCII characters.
  2763. * - It has a single, tiny size (8x8 pixels). You can use logical presentation
  2764. * or SDL_SetRenderScale() to adjust it.
  2765. * - It uses a simple, hardcoded bitmap font. It does not allow different font
  2766. * selections and it does not support truetype, for proper scaling.
  2767. * - It does no word-wrapping and does not treat newline characters as a line
  2768. * break. If the text goes out of the window, it's gone.
  2769. *
  2770. * For serious text rendering, there are several good options, such as
  2771. * SDL_ttf, stb_truetype, or other external libraries.
  2772. *
  2773. * On first use, this will create an internal texture for rendering glyphs.
  2774. * This texture will live until the renderer is destroyed.
  2775. *
  2776. * The text is drawn in the color specified by SDL_SetRenderDrawColor().
  2777. *
  2778. * \param renderer the renderer which should draw a line of text.
  2779. * \param x the x coordinate where the top-left corner of the text will draw.
  2780. * \param y the y coordinate where the top-left corner of the text will draw.
  2781. * \param str the string to render.
  2782. * \returns true on success or false on failure; call SDL_GetError() for more
  2783. * information.
  2784. *
  2785. * \threadsafety This function should only be called on the main thread.
  2786. *
  2787. * \since This function is available since SDL 3.2.0.
  2788. *
  2789. * \sa SDL_RenderDebugTextFormat
  2790. * \sa SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE
  2791. */
  2792. extern SDL_DECLSPEC bool SDLCALL SDL_RenderDebugText(SDL_Renderer *renderer, float x, float y, const char *str);
  2793. /**
  2794. * Draw debug text to an SDL_Renderer.
  2795. *
  2796. * This function will render a printf()-style format string to a renderer.
  2797. * Note that this is a convenience function for debugging, with severe
  2798. * limitations, and is not intended to be used for production apps and games.
  2799. *
  2800. * For the full list of limitations and other useful information, see
  2801. * SDL_RenderDebugText.
  2802. *
  2803. * \param renderer the renderer which should draw the text.
  2804. * \param x the x coordinate where the top-left corner of the text will draw.
  2805. * \param y the y coordinate where the top-left corner of the text will draw.
  2806. * \param fmt the format string to draw.
  2807. * \param ... additional parameters matching % tokens in the `fmt` string, if
  2808. * any.
  2809. * \returns true on success or false on failure; call SDL_GetError() for more
  2810. * information.
  2811. *
  2812. * \threadsafety This function should only be called on the main thread.
  2813. *
  2814. * \since This function is available since SDL 3.2.0.
  2815. *
  2816. * \sa SDL_RenderDebugText
  2817. * \sa SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE
  2818. */
  2819. extern SDL_DECLSPEC bool SDLCALL SDL_RenderDebugTextFormat(SDL_Renderer *renderer, float x, float y, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(4);
  2820. /**
  2821. * Set default scale mode for new textures for given renderer.
  2822. *
  2823. * When a renderer is created, scale_mode defaults to SDL_SCALEMODE_LINEAR.
  2824. *
  2825. * \param renderer the renderer to update.
  2826. * \param scale_mode the scale mode to change to for new textures.
  2827. * \returns true on success or false on failure; call SDL_GetError() for more
  2828. * information.
  2829. *
  2830. * \threadsafety This function should only be called on the main thread.
  2831. *
  2832. * \since This function is available since SDL 3.4.0.
  2833. *
  2834. * \sa SDL_GetDefaultTextureScaleMode
  2835. */
  2836. extern SDL_DECLSPEC bool SDLCALL SDL_SetDefaultTextureScaleMode(SDL_Renderer *renderer, SDL_ScaleMode scale_mode);
  2837. /**
  2838. * Get default texture scale mode of the given renderer.
  2839. *
  2840. * \param renderer the renderer to get data from.
  2841. * \param scale_mode a SDL_ScaleMode filled with current default scale mode.
  2842. * See SDL_SetDefaultTextureScaleMode() for the meaning of
  2843. * the value.
  2844. * \returns true on success or false on failure; call SDL_GetError() for more
  2845. * information.
  2846. *
  2847. * \threadsafety This function should only be called on the main thread.
  2848. *
  2849. * \since This function is available since SDL 3.4.0.
  2850. *
  2851. * \sa SDL_SetDefaultTextureScaleMode
  2852. */
  2853. extern SDL_DECLSPEC bool SDLCALL SDL_GetDefaultTextureScaleMode(SDL_Renderer *renderer, SDL_ScaleMode *scale_mode);
  2854. /**
  2855. * A structure specifying the parameters of a GPU render state.
  2856. *
  2857. * \since This struct is available since SDL 3.4.0.
  2858. *
  2859. * \sa SDL_CreateGPURenderState
  2860. */
  2861. typedef struct SDL_GPURenderStateCreateInfo
  2862. {
  2863. SDL_GPUShader *fragment_shader; /**< The fragment shader to use when this render state is active */
  2864. Sint32 num_sampler_bindings; /**< The number of additional fragment samplers to bind when this render state is active */
  2865. const SDL_GPUTextureSamplerBinding *sampler_bindings; /**< Additional fragment samplers to bind when this render state is active */
  2866. Sint32 num_storage_textures; /**< The number of storage textures to bind when this render state is active */
  2867. SDL_GPUTexture *const *storage_textures; /**< Storage textures to bind when this render state is active */
  2868. Sint32 num_storage_buffers; /**< The number of storage buffers to bind when this render state is active */
  2869. SDL_GPUBuffer *const *storage_buffers; /**< Storage buffers to bind when this render state is active */
  2870. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  2871. } SDL_GPURenderStateCreateInfo;
  2872. /**
  2873. * A custom GPU render state.
  2874. *
  2875. * \since This struct is available since SDL 3.4.0.
  2876. *
  2877. * \sa SDL_CreateGPURenderState
  2878. * \sa SDL_SetGPURenderStateFragmentUniforms
  2879. * \sa SDL_SetGPURenderState
  2880. * \sa SDL_DestroyGPURenderState
  2881. */
  2882. typedef struct SDL_GPURenderState SDL_GPURenderState;
  2883. /**
  2884. * Create custom GPU render state.
  2885. *
  2886. * \param renderer the renderer to use.
  2887. * \param createinfo a struct describing the GPU render state to create.
  2888. * \returns a custom GPU render state or NULL on failure; call SDL_GetError()
  2889. * for more information.
  2890. *
  2891. * \threadsafety This function should be called on the thread that created the
  2892. * renderer.
  2893. *
  2894. * \since This function is available since SDL 3.4.0.
  2895. *
  2896. * \sa SDL_SetGPURenderStateFragmentUniforms
  2897. * \sa SDL_SetGPURenderState
  2898. * \sa SDL_DestroyGPURenderState
  2899. */
  2900. extern SDL_DECLSPEC SDL_GPURenderState * SDLCALL SDL_CreateGPURenderState(SDL_Renderer *renderer, const SDL_GPURenderStateCreateInfo *createinfo);
  2901. /**
  2902. * Set sampler bindings variables in a custom GPU render state.
  2903. *
  2904. * The data is copied and will be binded using SDL_BindGPUFragmentSamplers()
  2905. * during draw call execution.
  2906. *
  2907. * \param state the state to modify.
  2908. * \param num_sampler_bindings The number of additional fragment samplers to
  2909. * bind.
  2910. * \param sampler_bindings Additional fragment samplers to bind.
  2911. * \returns true on success or false on failure; call SDL_GetError() for more
  2912. * information.
  2913. *
  2914. * \threadsafety This function should be called on the thread that created the
  2915. * renderer.
  2916. *
  2917. * \since This function is available since SDL 3.6.0.
  2918. */
  2919. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderStateSamplerBindings(SDL_GPURenderState *state, int num_sampler_bindings, const SDL_GPUTextureSamplerBinding *sampler_bindings);
  2920. /**
  2921. * Set storage textures variables in a custom GPU render state.
  2922. *
  2923. * The data is copied and will be binded using
  2924. * SDL_BindGPUFragmentStorageTextures() during draw call execution.
  2925. *
  2926. * \param state the state to modify.
  2927. * \param num_storage_textures The number of storage textures to bind.
  2928. * \param storage_textures Storage textures to bind.
  2929. * \returns true on success or false on failure; call SDL_GetError() for more
  2930. * information.
  2931. *
  2932. * \threadsafety This function should be called on the thread that created the
  2933. * renderer.
  2934. *
  2935. * \since This function is available since SDL 3.6.0.
  2936. */
  2937. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderStateStorageTextures(SDL_GPURenderState *state, int num_storage_textures, SDL_GPUTexture *const *storage_textures);
  2938. /**
  2939. * Set storage buffers variables in a custom GPU render state.
  2940. *
  2941. * The data is copied and will be binded using
  2942. * SDL_BindGPUFragmentStorageBuffers() during draw call execution.
  2943. *
  2944. * \param state the state to modify.
  2945. * \param num_storage_buffers The number of storage buffers to bind.
  2946. * \param storage_buffers Storage buffers to bind.
  2947. * \returns true on success or false on failure; call SDL_GetError() for more
  2948. * information.
  2949. *
  2950. * \threadsafety This function should be called on the thread that created the
  2951. * renderer.
  2952. *
  2953. * \since This function is available since SDL 3.6.0.
  2954. */
  2955. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderStateStorageBuffers(SDL_GPURenderState *state, int num_storage_buffers, SDL_GPUBuffer *const *storage_buffers);
  2956. /**
  2957. * Set fragment shader uniform variables in a custom GPU render state.
  2958. *
  2959. * The data is copied and will be pushed using
  2960. * SDL_PushGPUFragmentUniformData() during draw call execution.
  2961. *
  2962. * \param state the state to modify.
  2963. * \param slot_index the fragment uniform slot to push data to.
  2964. * \param data client data to write.
  2965. * \param length the length of the data to write.
  2966. * \returns true on success or false on failure; call SDL_GetError() for more
  2967. * information.
  2968. *
  2969. * \threadsafety This function should be called on the thread that created the
  2970. * renderer.
  2971. *
  2972. * \since This function is available since SDL 3.4.0.
  2973. */
  2974. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderStateFragmentUniforms(SDL_GPURenderState *state, Uint32 slot_index, const void *data, Uint32 length);
  2975. /**
  2976. * Set custom GPU render state.
  2977. *
  2978. * This function sets custom GPU render state for subsequent draw calls. This
  2979. * allows using custom shaders with the GPU renderer.
  2980. *
  2981. * \param renderer the renderer to use.
  2982. * \param state the state to to use, or NULL to clear custom GPU render state.
  2983. * \returns true on success or false on failure; call SDL_GetError() for more
  2984. * information.
  2985. *
  2986. * \threadsafety This function should be called on the thread that created the
  2987. * renderer.
  2988. *
  2989. * \since This function is available since SDL 3.4.0.
  2990. */
  2991. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPURenderState(SDL_Renderer *renderer, SDL_GPURenderState *state);
  2992. /**
  2993. * Destroy custom GPU render state.
  2994. *
  2995. * \param state the state to destroy.
  2996. *
  2997. * \threadsafety This function should be called on the thread that created the
  2998. * renderer.
  2999. *
  3000. * \since This function is available since SDL 3.4.0.
  3001. *
  3002. * \sa SDL_CreateGPURenderState
  3003. */
  3004. extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPURenderState(SDL_GPURenderState *state);
  3005. #ifdef SDL_PLATFORM_GDK
  3006. /**
  3007. * Call this to suspend Render operations on Xbox after receiving the
  3008. * SDL_EVENT_DID_ENTER_BACKGROUND event.
  3009. *
  3010. * Do NOT call any SDL_Render functions after calling this function! This must
  3011. * also be called before calling SDL_GDKSuspendComplete.
  3012. *
  3013. * This function MUST be called on the application's render thread.
  3014. *
  3015. * \param renderer the renderer which should suspend operation.
  3016. *
  3017. * \since This function is available since SDL 3.6.0.
  3018. *
  3019. * \sa SDL_AddEventWatch
  3020. */
  3021. extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendRenderer(SDL_Renderer *renderer);
  3022. /**
  3023. * Call this to resume Render operations on Xbox after receiving the
  3024. * SDL_EVENT_WILL_ENTER_FOREGROUND event.
  3025. *
  3026. * When resuming, this function MUST be called before calling any other
  3027. * SDL_Render functions.
  3028. *
  3029. * This function MUST be called on the application's render thread.
  3030. *
  3031. * \param renderer the renderer which should resume operation.
  3032. *
  3033. * \since This function is available since SDL 3.6.0.
  3034. *
  3035. * \sa SDL_AddEventWatch
  3036. */
  3037. extern SDL_DECLSPEC void SDLCALL SDL_GDKResumeRenderer(SDL_Renderer *renderer);
  3038. #endif /* SDL_PLATFORM_GDK */
  3039. /* Ends C function definitions when using C++ */
  3040. #ifdef __cplusplus
  3041. }
  3042. #endif
  3043. #include <SDL3/SDL_close_code.h>
  3044. #endif /* SDL_render_h_ */