SDL_render.h 77 KB

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