SDL_render.h 94 KB

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