SDL_render.h 132 KB

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