SDL_render.h 109 KB

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