reference-libobs-graphics-graphics.rst 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. Core Graphics API
  2. =================
  3. .. code:: cpp
  4. #include <graphics/graphics.h>
  5. Graphics Enumerations
  6. ---------------------
  7. .. type:: enum gs_draw_mode
  8. Draw mode. Can be one of the following values:
  9. - GS_POINTS - Draws points
  10. - GS_LINES - Draws individual lines
  11. - GS_LINESTRIP - Draws a line strip
  12. - GS_TRIS - Draws individual triangles
  13. - GS_TRISTRIP - Draws a triangle strip
  14. .. type:: enum gs_color_format
  15. Color format. Can be one of the following values:
  16. - GS_UNKNOWN - Unknown format
  17. - GS_A8 - 8 bit alpha channel only
  18. - GS_R8 - 8 bit red channel only
  19. - GS_RGBA - RGBA, 8 bits per channel
  20. - GS_BGRX - BGRX, 8 bits per channel
  21. - GS_BGRA - BGRA, 8 bits per channel
  22. - GS_R10G10B10A2 - RGBA, 10 bits per channel except alpha, which is 2
  23. bits
  24. - GS_RGBA16 - RGBA, 16 bits per channel
  25. - GS_R16 - 16 bit red channel only
  26. - GS_RGBA16F - RGBA, 16 bit floating point per channel
  27. - GS_RGBA32F - RGBA, 32 bit floating point per channel
  28. - GS_RG16F - 16 bit floating point red and green channels only
  29. - GS_RG32F - 32 bit floating point red and green channels only
  30. - GS_R16F - 16 bit floating point red channel only
  31. - GS_R32F - 32 bit floating point red channel only
  32. - GS_DXT1 - Compressed DXT1
  33. - GS_DXT3 - Compressed DXT3
  34. - GS_DXT5 - Compressed DXT5
  35. - GS_RGBA_UNORM - RGBA, 8 bits per channel, no SRGB aliasing
  36. - GS_BGRX_UNORM - BGRX, 8 bits per channel, no SRGB aliasing
  37. - GS_BGRA_UNORM - BGRA, 8 bits per channel, no SRGB aliasing
  38. .. type:: enum gs_zstencil_format
  39. Z-Stencil buffer format. Can be one of the following values:
  40. - GS_ZS_NONE - No Z-stencil buffer
  41. - GS_Z16 - 16 bit Z buffer
  42. - GS_Z24_S8 - 24 bit Z buffer, 8 bit stencil
  43. - GS_Z32F - 32 bit floating point Z buffer
  44. - GS_Z32F_S8X24 - 32 bit floating point Z buffer, 8 bit stencil
  45. .. type:: enum gs_index_type
  46. Index buffer type. Can be one of the following values:
  47. - GS_UNSIGNED_SHORT - 16 bit index
  48. - GS_UNSIGNED_LONG - 32 bit index
  49. .. type:: enum gs_cull_mode
  50. Cull mode. Can be one of the following values:
  51. - GS_BACK - Cull back faces
  52. - GS_FRONT - Cull front faces
  53. - GS_NEITHER - Cull neither
  54. .. type:: enum gs_blend_type
  55. Blend type. Can be one of the following values:
  56. - GS_BLEND_ZERO
  57. - GS_BLEND_ONE
  58. - GS_BLEND_SRCCOLOR
  59. - GS_BLEND_INVSRCCOLOR
  60. - GS_BLEND_SRCALPHA
  61. - GS_BLEND_INVSRCALPHA
  62. - GS_BLEND_DSTCOLOR
  63. - GS_BLEND_INVDSTCOLOR
  64. - GS_BLEND_DSTALPHA
  65. - GS_BLEND_INVDSTALPHA
  66. - GS_BLEND_SRCALPHASAT
  67. .. type:: enum gs_depth_test
  68. Depth test type. Can be one of the following values:
  69. - GS_NEVER
  70. - GS_LESS
  71. - GS_LEQUAL
  72. - GS_EQUAL
  73. - GS_GEQUAL
  74. - GS_GREATER
  75. - GS_NOTEQUAL
  76. - GS_ALWAYS
  77. .. type:: enum gs_stencil_side
  78. Stencil side. Can be one of the following values:
  79. - GS_STENCIL_FRONT=1
  80. - GS_STENCIL_BACK
  81. - GS_STENCIL_BOTH
  82. .. type:: enum gs_stencil_op_type
  83. Stencil operation type. Can be one of the following values:
  84. - GS_KEEP
  85. - GS_ZERO
  86. - GS_REPLACE
  87. - GS_INCR
  88. - GS_DECR
  89. - GS_INVERT
  90. .. type:: enum gs_cube_sides
  91. Cubemap side. Can be one of the following values:
  92. - GS_POSITIVE_X
  93. - GS_NEGATIVE_X
  94. - GS_POSITIVE_Y
  95. - GS_NEGATIVE_Y
  96. - GS_POSITIVE_Z
  97. - GS_NEGATIVE_Z
  98. .. type:: enum gs_sample_filter
  99. Sample filter type. Can be one of the following values:
  100. - GS_FILTER_POINT
  101. - GS_FILTER_LINEAR
  102. - GS_FILTER_ANISOTROPIC
  103. - GS_FILTER_MIN_MAG_POINT_MIP_LINEAR
  104. - GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT
  105. - GS_FILTER_MIN_POINT_MAG_MIP_LINEAR
  106. - GS_FILTER_MIN_LINEAR_MAG_MIP_POINT
  107. - GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR
  108. - GS_FILTER_MIN_MAG_LINEAR_MIP_POINT
  109. .. type:: enum gs_address_mode
  110. Address mode. Can be one of the following values:
  111. - GS_ADDRESS_CLAMP
  112. - GS_ADDRESS_WRAP
  113. - GS_ADDRESS_MIRROR
  114. - GS_ADDRESS_BORDER
  115. - GS_ADDRESS_MIRRORONCE
  116. .. type:: enum gs_texture_type
  117. Texture type. Can be one of the following values:
  118. - GS_TEXTURE_2D
  119. - GS_TEXTURE_3D
  120. - GS_TEXTURE_CUBE
  121. Graphics Structures
  122. -------------------
  123. .. type:: struct gs_monitor_info
  124. .. member:: int gs_monitor_info.rotation_degrees
  125. .. member:: long gs_monitor_info.x
  126. .. member:: long gs_monitor_info.y
  127. .. member:: long gs_monitor_info.cx
  128. .. member:: long gs_monitor_info.cy
  129. ---------------------
  130. .. type:: struct gs_tvertarray
  131. .. member:: size_t gs_tvertarray.width
  132. .. member:: void *gs_tvertarray.array
  133. ---------------------
  134. .. type:: struct gs_vb_data
  135. .. member:: size_t gs_vb_data.num
  136. .. member:: struct vec3 *gs_vb_data.points
  137. .. member:: struct vec3 *gs_vb_data.normals
  138. .. member:: struct vec3 *gs_vb_data.tangents
  139. .. member:: uint32_t *gs_vb_data.colors
  140. .. member:: size_t gs_vb_data.num_tex
  141. .. member:: struct gs_tvertarray *gs_vb_data.tvarray
  142. ---------------------
  143. .. type:: struct gs_sampler_info
  144. .. member:: enum gs_sample_filter gs_sampler_info.filter
  145. .. member:: enum gs_address_mode gs_sampler_info.address_u
  146. .. member:: enum gs_address_mode gs_sampler_info.address_v
  147. .. member:: enum gs_address_mode gs_sampler_info.address_w
  148. .. member:: int gs_sampler_info.max_anisotropy
  149. .. member:: uint32_t gs_sampler_info.border_color
  150. ---------------------
  151. .. type:: struct gs_display_mode
  152. .. member:: uint32_t gs_display_mode.width
  153. .. member:: uint32_t gs_display_mode.height
  154. .. member:: uint32_t gs_display_mode.bits
  155. .. member:: uint32_t gs_display_mode.freq
  156. ---------------------
  157. .. type:: struct gs_rect
  158. .. member:: int gs_rect.x
  159. .. member:: int gs_rect.y
  160. .. member:: int gs_rect.cx
  161. .. member:: int gs_rect.cy
  162. ---------------------
  163. .. type:: struct gs_window
  164. A window structure. This structure is used with a native widget.
  165. .. member:: void *gs_window.hwnd
  166. (Windows only) an HWND widget.
  167. .. member:: id gs_window.view
  168. (Mac only) A view ID.
  169. .. member:: uint32_t gs_window.id
  170. void* gs_window.display
  171. (Linux only) Window ID and display
  172. ---------------------
  173. .. type:: struct gs_init_data
  174. Swap chain initialization data.
  175. .. member:: struct gs_window gs_init_data.window
  176. .. member:: uint32_t gs_init_data.cx
  177. .. member:: uint32_t gs_init_data.cy
  178. .. member:: uint32_t gs_init_data.num_backbuffers
  179. .. member:: enum gs_color_format gs_init_data.format
  180. .. member:: enum gs_zstencil_format gs_init_data.zsformat
  181. .. member:: uint32_t gs_init_data.adapter
  182. ---------------------
  183. Initialization Functions
  184. ------------------------
  185. .. function:: void gs_enum_adapters(bool (*callback)(void *param, const char *name, uint32_t id), void *param)
  186. Enumerates adapters (this really only applies on windows).
  187. :param callback: Enumeration callback
  188. :param param: Private data passed to the callback
  189. ---------------------
  190. .. function:: int gs_create(graphics_t **graphics, const char *module, uint32_t adapter)
  191. Creates a graphics context
  192. :param graphics: Pointer to receive the graphics context
  193. :param module: Module name
  194. :param adapter: Adapter index
  195. :return: Can return one of the following values:
  196. - GS_SUCCESS
  197. - GS_ERROR_FAIL
  198. - GS_ERROR_MODULE_NOT_FOUND
  199. - GS_ERROR_NOT_SUPPORTED
  200. ---------------------
  201. .. function:: void gs_destroy(graphics_t *graphics)
  202. Destroys a graphics context
  203. :param graphics: Graphics context
  204. ---------------------
  205. .. function:: void gs_enter_context(graphics_t *graphics)
  206. Enters and locks the graphics context
  207. :param graphics: Graphics context
  208. ---------------------
  209. .. function:: void gs_leave_context(void)
  210. Leaves and unlocks the graphics context
  211. :param graphics: Graphics context
  212. ---------------------
  213. .. function:: graphics_t *gs_get_context(void)
  214. :return: The currently locked graphics context for this thread
  215. ---------------------
  216. Matrix Stack Functions
  217. ----------------------
  218. .. function:: void gs_matrix_push(void)
  219. Pushes the matrix stack and duplicates the current matrix.
  220. ---------------------
  221. .. function:: void gs_matrix_pop(void)
  222. Pops the current matrix from the matrix stack.
  223. ---------------------
  224. .. function:: void gs_matrix_identity(void)
  225. Sets the current matrix to an identity matrix.
  226. ---------------------
  227. .. function:: void gs_matrix_transpose(void)
  228. Transposes the current matrix.
  229. ---------------------
  230. .. function:: void gs_matrix_set(const struct matrix4 *matrix)
  231. Sets the current matrix.
  232. :param matrix: The matrix to set
  233. ---------------------
  234. .. function:: void gs_matrix_get(struct matrix4 *dst)
  235. Gets the current matrix
  236. :param dst: Destination matrix
  237. ---------------------
  238. .. function:: void gs_matrix_mul(const struct matrix4 *matrix)
  239. Multiplies the current matrix
  240. :param matrix: Matrix to multiply the current stack matrix with
  241. ---------------------
  242. .. function:: void gs_matrix_rotquat(const struct quat *rot)
  243. Multiplies the current matrix with a quaternion
  244. :param rot: Quaternion to multiple the current matrix stack with
  245. ---------------------
  246. .. function:: void gs_matrix_rotaa(const struct axisang *rot)
  247. void gs_matrix_rotaa4f(float x, float y, float z, float angle)
  248. Multiplies the current matrix with an axis angle
  249. :param rot: Axis angle to multiple the current matrix stack with
  250. ---------------------
  251. .. function:: void gs_matrix_translate(const struct vec3 *pos)
  252. void gs_matrix_translate3f(float x, float y, float z)
  253. Translates the current matrix
  254. :param pos: Vector to translate the current matrix stack with
  255. ---------------------
  256. .. function:: void gs_matrix_scale(const struct vec3 *scale)
  257. void gs_matrix_scale3f(float x, float y, float z)
  258. Scales the current matrix
  259. :param scale: Scale value to scale the current matrix stack with
  260. ---------------------
  261. Draw Functions
  262. --------------
  263. .. function:: gs_effect_t *gs_get_effect(void)
  264. :return: The currently active effect, or *NULL* if none active
  265. ---------------------
  266. .. function:: void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, uint32_t height)
  267. Draws a 2D sprite. Sets the "image" parameter of the current effect
  268. to the texture and renders a quad.
  269. If width or height is 0, the width or height of the texture will be
  270. used. The flip value specifies whether the texture should be flipped
  271. on the U or V axis with GS_FLIP_U and GS_FLIP_V.
  272. :param tex: Texture to draw
  273. :param flip: Can be 0 or a bitwise-OR combination of one of the
  274. following values:
  275. - GS_FLIP_U - Flips the texture horizontally
  276. - GS_FLIP_V - Flips the texture vertically
  277. :param width: Width
  278. :param height: Height
  279. ---------------------
  280. .. function:: void gs_draw_sprite_subregion(gs_texture_t *tex, uint32_t flip, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
  281. Draws a subregion of a 2D sprite. Sets the "image" parameter of the
  282. current effect to the texture and renders a quad.
  283. :param tex: Texture to draw
  284. :param flip: Can be 0 or a bitwise-OR combination of one of the
  285. following values:
  286. - GS_FLIP_U - Flips the texture horizontally
  287. - GS_FLIP_V - Flips the texture vertically
  288. :param x: X value within subregion
  289. :param y: Y value within subregion
  290. :param cx: CX value of subregion
  291. :param cy: CY value of subregion
  292. ---------------------
  293. .. function:: void gs_reset_viewport(void)
  294. Sets the viewport to current swap chain size
  295. ---------------------
  296. .. function:: void gs_set_2d_mode(void)
  297. Sets the projection matrix to a default screen-sized orthographic
  298. mode
  299. ---------------------
  300. .. function:: void gs_set_3d_mode(double fovy, double znear, double zfar)
  301. Sets the projection matrix to a default screen-sized perspective
  302. mode
  303. :param fovy: Field of view (in degrees)
  304. :param znear: Near plane
  305. :param zfar: Far plane
  306. ---------------------
  307. .. function:: void gs_viewport_push(void)
  308. Pushes/stores the current viewport
  309. ---------------------
  310. .. function:: void gs_viewport_pop(void)
  311. Pops/recalls the last pushed viewport
  312. ---------------------
  313. .. function:: void gs_perspective(float fovy, float aspect, float znear, float zfar)
  314. Sets the projection matrix to a perspective mode
  315. :param fovy: Field of view (in degrees)
  316. :param aspect: Aspect ratio
  317. :param znear: Near plane
  318. :param zfar: Far plane
  319. ---------------------
  320. .. function:: void gs_blend_state_push(void)
  321. Pushes/stores the current blend state
  322. ---------------------
  323. .. function:: void gs_blend_state_pop(void)
  324. Pops/restores the last blend state
  325. ---------------------
  326. .. function:: void gs_reset_blend_state(void)
  327. Sets the blend state to the default value: source alpha and invert
  328. source alpha.
  329. ---------------------
  330. Swap Chains
  331. -----------
  332. .. function:: gs_swapchain_t *gs_swapchain_create(const struct gs_init_data *data)
  333. Creates a swap chain (display view on a native widget)
  334. :param data: Swap chain initialization data
  335. :return: New swap chain object, or *NULL* if failed
  336. ---------------------
  337. .. function:: void gs_swapchain_destroy(gs_swapchain_t *swapchain)
  338. Destroys a swap chain
  339. ---------------------
  340. .. function:: void gs_resize(uint32_t cx, uint32_t cy)
  341. Resizes the currently active swap chain
  342. :param cx: New width
  343. :param cy: New height
  344. ---------------------
  345. .. function:: void gs_get_size(uint32_t *cx, uint32_t *cy)
  346. Gets the size of the currently active swap chain
  347. :param cx: Pointer to receive width
  348. :param cy: Pointer to receive height
  349. ---------------------
  350. .. function:: uint32_t gs_get_width(void)
  351. Gets the width of the currently active swap chain
  352. ---------------------
  353. .. function:: uint32_t gs_get_height(void)
  354. Gets the height of the currently active swap chain
  355. ---------------------
  356. Resource Loading
  357. ----------------
  358. .. function:: void gs_load_vertexbuffer(gs_vertbuffer_t *vertbuffer)
  359. Loads a vertex buffer
  360. :param vertbuffer: Vertex buffer to load, or NULL to unload
  361. ---------------------
  362. .. function:: void gs_load_indexbuffer(gs_indexbuffer_t *indexbuffer)
  363. Loads a index buffer
  364. :param indexbuffer: Index buffer to load, or NULL to unload
  365. ---------------------
  366. .. function:: void gs_load_texture(gs_texture_t *tex, int unit)
  367. Loads a texture (this is usually not called manually)
  368. :param tex: Texture to load, or NULL to unload
  369. :param unit: Texture unit to load texture for
  370. ---------------------
  371. .. function:: void gs_load_samplerstate(gs_samplerstate_t *samplerstate, int unit)
  372. Loads a sampler state (this is usually not called manually)
  373. :param samplerstate: Sampler state to load, or NULL to unload
  374. :param unit: Texture unit to load sampler state for
  375. ---------------------
  376. .. function:: void gs_load_swapchain(gs_swapchain_t *swapchain)
  377. Loads a swapchain
  378. :param swapchain: Swap chain to load, or NULL to unload
  379. ---------------------
  380. Draw Functions
  381. --------------
  382. .. function:: gs_texture_t *gs_get_render_target(void)
  383. :return: The currently active render target
  384. ---------------------
  385. .. function:: gs_zstencil_t *gs_get_zstencil_target(void)
  386. :return: The currently active Z-stencil target
  387. ---------------------
  388. .. function:: void gs_set_render_target(gs_texture_t *tex, gs_zstencil_t *zstencil)
  389. Sets the active render target
  390. :param tex: Texture to set as the active render target
  391. :param zstencil: Z-stencil to use as the active render target
  392. ---------------------
  393. .. function:: void gs_set_cube_render_target(gs_texture_t *cubetex, int side, gs_zstencil_t *zstencil)
  394. Sets a cubemap side as the active render target
  395. :param cubetex: Cubemap
  396. :param side: Cubemap side
  397. :param zstencil: Z-stencil buffer, or *NULL* if none
  398. ---------------------
  399. .. function:: void gs_copy_texture(gs_texture_t *dst, gs_texture_t *src)
  400. Copies a texture
  401. :param dst: Destination texture
  402. :param src: Source texture
  403. ---------------------
  404. .. function:: void gs_stage_texture(gs_stagesurf_t *dst, gs_texture_t *src)
  405. Copies a texture to a staging surface and copies it to RAM. Ideally
  406. best to give this a frame to process to prevent stalling.
  407. :param dst: Staging surface
  408. :param src: Texture to stage
  409. ---------------------
  410. .. function:: void gs_begin_scene(void)
  411. void gs_end_scene(void)
  412. Begins/ends a scene (this is automatically called by libobs, there's
  413. no need to call this manually).
  414. ---------------------
  415. .. function:: void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts)
  416. Draws a primitive or set of primitives.
  417. :param draw_mode: The primitive draw mode to use
  418. :param start_vert: Starting vertex index
  419. :param num_verts: Number of vertices
  420. ---------------------
  421. .. function:: void gs_clear(uint32_t clear_flags, const struct vec4 *color, float depth, uint8_t stencil)
  422. Clears color/depth/stencil buffers.
  423. :param clear_flags: Flags to clear with. Can be one of the following
  424. values:
  425. - GS_CLEAR_COLOR - Clears color buffer
  426. - GS_CLEAR_DEPTH - Clears depth buffer
  427. - GS_CLEAR_STENCIL - Clears stencil buffer
  428. :param color: Color value to clear the color buffer with
  429. :param depth: Depth value to clear the depth buffer with
  430. :param stencil: Stencil value to clear the stencil buffer with
  431. ---------------------
  432. .. function:: void gs_present(void)
  433. Displays what was rendered on to the current render target
  434. ---------------------
  435. .. function:: void gs_flush(void)
  436. Flushes GPU calls
  437. ---------------------
  438. .. function:: void gs_set_cull_mode(enum gs_cull_mode mode)
  439. Sets the current cull mode.
  440. :param mode: Cull mode
  441. ---------------------
  442. .. function:: enum gs_cull_mode gs_get_cull_mode(void)
  443. :return: The current cull mode
  444. ---------------------
  445. .. function:: void gs_enable_blending(bool enable)
  446. Enables/disables blending
  447. :param enable: *true* to enable, *false* to disable
  448. ---------------------
  449. .. function:: void gs_enable_depth_test(bool enable)
  450. Enables/disables depth testing
  451. :param enable: *true* to enable, *false* to disable
  452. ---------------------
  453. .. function:: void gs_enable_stencil_test(bool enable)
  454. Enables/disables stencil testing
  455. :param enable: *true* to enable, *false* to disable
  456. ---------------------
  457. .. function:: void gs_enable_stencil_write(bool enable)
  458. Enables/disables stencil writing
  459. :param enable: *true* to enable, *false* to disable
  460. ---------------------
  461. .. function:: void gs_enable_color(bool red, bool green, bool blue, bool alpha)
  462. Enables/disables specific color channels
  463. :param red: *true* to enable red channel, *false* to disable
  464. :param green: *true* to enable green channel, *false* to disable
  465. :param blue: *true* to enable blue channel, *false* to disable
  466. :param alpha: *true* to enable alpha channel, *false* to disable
  467. ---------------------
  468. .. function:: void gs_blend_function(enum gs_blend_type src, enum gs_blend_type dest)
  469. Sets the blend function
  470. :param src: Blend type for the source
  471. :param dest: Blend type for the destination
  472. ---------------------
  473. .. function:: void gs_blend_function_separate(enum gs_blend_type src_c, enum gs_blend_type dest_c, enum gs_blend_type src_a, enum gs_blend_type dest_a)
  474. Sets the blend function for RGB and alpha separately
  475. :param src_c: Blend type for the source RGB
  476. :param dest_c: Blend type for the destination RGB
  477. :param src_a: Blend type for the source alpha
  478. :param dest_a: Blend type for the destination alpha
  479. ---------------------
  480. .. function:: void gs_depth_function(enum gs_depth_test test)
  481. Sets the depth function
  482. :param test: Sets the depth test type
  483. ---------------------
  484. .. function:: void gs_stencil_function(enum gs_stencil_side side, enum gs_depth_test test)
  485. Sets the stencil function
  486. :param side: Stencil side
  487. :param test: Depth test
  488. ---------------------
  489. .. function:: void gs_stencil_op(enum gs_stencil_side side, enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail, enum gs_stencil_op_type zpass)
  490. Sets the stencil operation
  491. :param side: Stencil side
  492. :param fail: Operation to perform on stencil test failure
  493. :param zfail: Operation to perform on depth test failure
  494. :param zpass: Operation to perform on depth test success
  495. ---------------------
  496. .. function:: void gs_set_viewport(int x, int y, int width, int height)
  497. Sets the current viewport
  498. :param x: X position relative to upper left
  499. :param y: Y position relative to upper left
  500. :param width: Width of the viewport
  501. :param height: Height of the viewport
  502. ---------------------
  503. .. function:: void gs_get_viewport(struct gs_rect *rect)
  504. Gets the current viewport
  505. :param rect: Pointer to receive viewport rectangle
  506. ---------------------
  507. .. function:: void gs_set_scissor_rect(const struct gs_rect *rect)
  508. Sets or clears the current scissor rectangle
  509. :rect: Scissor rectangle, or *NULL* to clear
  510. ---------------------
  511. .. function:: void gs_ortho(float left, float right, float top, float bottom, float znear, float zfar)
  512. Sets the projection matrix to an orthographic matrix
  513. ---------------------
  514. .. function:: void gs_frustum(float left, float right, float top, float bottom, float znear, float zfar)
  515. Sets the projection matrix to a frustum matrix
  516. ---------------------
  517. .. function:: void gs_projection_push(void)
  518. Pushes/stores the current projection matrix
  519. ---------------------
  520. .. function:: void gs_projection_pop(void)
  521. Pops/restores the last projection matrix pushed
  522. ---------------------
  523. Texture Functions
  524. -----------------
  525. .. function:: gs_texture_t *gs_texture_create(uint32_t width, uint32_t height, enum gs_color_format color_format, uint32_t levels, const uint8_t **data, uint32_t flags)
  526. Creates a texture.
  527. :param width: Width
  528. :param height: Height
  529. :param color_format: Color format
  530. :param levels: Number of total texture levels. Set to 1 if no
  531. mip-mapping
  532. :param data: Pointer to array of texture data pointers
  533. :param flags: Can be 0 or a bitwise-OR combination of one or
  534. more of the following value:
  535. - GS_BUILD_MIPMAPS - Automatically builds
  536. mipmaps (Note: not fully tested)
  537. - GS_DYNAMIC - Dynamic
  538. - GS_RENDER_TARGET - Render target
  539. :return: A new texture object
  540. ---------------------
  541. .. function:: gs_texture_t *gs_texture_create_from_file(const char *file)
  542. Creates a texture from a file. Note that this isn't recommended for
  543. animated gifs -- instead use the :ref:`image_file_helper`.
  544. :param file: Image file to open
  545. ---------------------
  546. .. function:: void gs_texture_destroy(gs_texture_t *tex)
  547. Destroys a texture
  548. :param tex: Texture object
  549. ---------------------
  550. .. function:: uint32_t gs_texture_get_width(const gs_texture_t *tex)
  551. Gets the texture's width
  552. :param tex: Texture object
  553. :return: The texture's width
  554. ---------------------
  555. .. function:: uint32_t gs_texture_get_height(const gs_texture_t *tex)
  556. Gets the texture's height
  557. :param tex: Texture object
  558. :return: The texture's height
  559. ---------------------
  560. .. function:: enum gs_color_format gs_texture_get_color_format(const gs_texture_t *tex)
  561. Gets the texture's color format
  562. :param tex: Texture object
  563. :return: The texture's color format
  564. ---------------------
  565. .. function:: bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize)
  566. Maps a texture.
  567. :param tex: Texture object
  568. :param ptr: Pointer to receive the pointer to the texture data
  569. to write to
  570. :param linesize: Pointer to receive the line size (pitch) of the
  571. texture
  572. ---------------------
  573. .. function:: void gs_texture_unmap(gs_texture_t *tex)
  574. Unmaps a texture.
  575. :param tex: Texture object
  576. ---------------------
  577. .. function:: void gs_texture_set_image(gs_texture_t *tex, const uint8_t *data, uint32_t linesize, bool invert)
  578. Sets the image of a dynamic texture
  579. :param tex: Texture object
  580. :param data: Data to set as the image
  581. :param linesize: Line size (pitch) of the data
  582. :param invert: *true* to invert vertically, *false* otherwise
  583. ---------------------
  584. .. function:: gs_texture_t *gs_texture_create_from_iosurface(void *iosurf)
  585. **Mac only:** Creates a texture from an IOSurface.
  586. :param iosurf: IOSurface object
  587. ---------------------
  588. .. function:: bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
  589. **Mac only:** Rebinds a texture to another IOSurface
  590. :param texture: Texture object
  591. :param iosuf: IOSurface object
  592. ---------------------
  593. .. function:: gs_texture_t *gs_texture_create_gdi(uint32_t width, uint32_t height)
  594. **Windows only:** Creates a GDI-interop texture
  595. :param width: Width
  596. :param height: Height
  597. ---------------------
  598. .. function:: void *gs_texture_get_dc(gs_texture_t *gdi_tex)
  599. **Windows only:** Gets the HDC of a GDI-interop texture. Call
  600. :c:func:`gs_texture_release_dc()` to release the HDC.
  601. :param gdi_tex: GDI-interop texture object
  602. :return: HDC object
  603. ---------------------
  604. .. function:: void gs_texture_release_dc(gs_texture_t *gdi_tex)
  605. **Windows only:** Releases the HDC of the GDI-interop texture.
  606. :param gdi_tex: GDI-interop texture object
  607. ---------------------
  608. .. function:: gs_texture_t *gs_texture_open_shared(uint32_t handle)
  609. **Windows only:** Creates a texture from a shared texture handle.
  610. :param handle: Shared texture handle
  611. :return: A texture object
  612. ---------------------
  613. .. function:: bool gs_gdi_texture_available(void)
  614. **Windows only:** Returns whether GDI-interop textures are available.
  615. :return: *true* if available, *false* otherwise
  616. ---------------------
  617. .. function:: bool gs_shared_texture_available(void)
  618. **Windows only:** Returns whether shared textures are available.
  619. :return: *true* if available, *false* otherwise
  620. ---------------------
  621. Cube Texture Functions
  622. ----------------------
  623. .. function:: gs_texture_t *gs_cubetexture_create(uint32_t size, enum gs_color_format color_format, uint32_t levels, const uint8_t **data, uint32_t flags)
  624. Creates a cubemap texture.
  625. :param size: Width/height/depth value
  626. :param color_format: Color format
  627. :param levels: Number of texture levels
  628. :param data: Pointer to array of texture data pointers
  629. :param flags: Can be 0 or a bitwise-OR combination of one or
  630. more of the following value:
  631. - GS_BUILD_MIPMAPS - Automatically builds
  632. mipmaps (Note: not fully tested)
  633. - GS_DYNAMIC - Dynamic
  634. - GS_RENDER_TARGET - Render target
  635. :return: A new cube texture object
  636. ---------------------
  637. .. function:: void gs_cubetexture_destroy(gs_texture_t *cubetex)
  638. Destroys a cube texture.
  639. :param cubetex: Cube texture object
  640. ---------------------
  641. .. function:: uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex)
  642. Get the width/height/depth value of a cube texture.
  643. :param cubetex: Cube texture object
  644. :return: The width/height/depth value of the cube texture
  645. ---------------------
  646. .. function:: enum gs_color_format gs_cubetexture_get_color_format(const gs_texture_t *cubetex)
  647. Gets the color format of a cube texture.
  648. :param cubetex: Cube texture object
  649. :return: The color format of the cube texture
  650. ---------------------
  651. .. function:: void gs_cubetexture_set_image(gs_texture_t *cubetex, uint32_t side, const void *data, uint32_t linesize, bool invert)
  652. Sets an image of a cube texture side.
  653. :param cubetex: Cube texture object
  654. :param side: Side
  655. :param data: Texture data to set
  656. :param linesize: Line size (pitch) of the texture data
  657. :param invert: *true* to invert texture data, *false* otherwise
  658. ---------------------
  659. Staging Surface Functions
  660. -------------------------
  661. Staging surfaces are used to efficiently copy textures from VRAM to RAM.
  662. .. function:: gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height, enum gs_color_format color_format)
  663. Creates a staging surface.
  664. :param width: Width
  665. :param height: Height
  666. :param color_format: Color format
  667. :return: The staging surface object
  668. ---------------------
  669. .. function:: void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf)
  670. Destroys a staging surface.
  671. :param stagesurf: Staging surface object
  672. ---------------------
  673. .. function:: uint32_t gs_stagesurface_get_width(const gs_stagesurf_t *stagesurf)
  674. uint32_t gs_stagesurface_get_height(const gs_stagesurf_t *stagesurf)
  675. Gets the width/height of a staging surface object.
  676. :param stagesurf: Staging surface object
  677. :return: Width/height of the staging surface
  678. ---------------------
  679. .. function:: enum gs_color_format gs_stagesurface_get_color_format(const gs_stagesurf_t *stagesurf)
  680. Gets the color format of a staging surface object.
  681. :param stagesurf: Staging surface object
  682. :return: Color format of the staging surface
  683. ---------------------
  684. .. function:: bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data, uint32_t *linesize)
  685. Maps the staging surface texture (for reading). Call
  686. :c:func:`gs_stagesurface_unmap()` to unmap when complete.
  687. :param stagesurf: Staging surface object
  688. :param data: Pointer to receive texture data pointer
  689. :param linesize: Pointer to receive line size (pitch) of the texture
  690. data
  691. :return: *true* if map successful, *false* otherwise
  692. ---------------------
  693. .. function:: void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf)
  694. Unmaps a staging surface.
  695. :param stagesurf: Staging surface object
  696. ---------------------
  697. Z-Stencil Functions
  698. -------------------
  699. .. function:: gs_zstencil_t *gs_zstencil_create(uint32_t width, uint32_t height, enum gs_zstencil_format format)
  700. Creates a Z-stencil surface object.
  701. :param width: Width
  702. :param height: Height
  703. :param format: Format
  704. :return: New Z-stencil surface object, or *NULL* if failed
  705. ---------------------
  706. .. function:: void gs_zstencil_destroy(gs_zstencil_t *zstencil)
  707. Destroys a Z-stencil buffer.
  708. :param zstencil: Z-stencil surface object
  709. ---------------------
  710. Sampler State Functions
  711. -----------------------
  712. .. function:: gs_samplerstate_t *gs_samplerstate_create(const struct gs_sampler_info *info)
  713. Creates a sampler state object.
  714. :param info: Sampler state information
  715. :return: New sampler state object
  716. ---------------------
  717. .. function:: void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
  718. Destroys a sampler state object.
  719. :param samplerstate: Sampler state object
  720. ---------------------
  721. Vertex Buffer Functions
  722. -----------------------
  723. .. function:: gs_vertbuffer_t *gs_vertexbuffer_create(struct gs_vb_data *data, uint32_t flags)
  724. Creates a vertex buffer.
  725. :param data: Vertex buffer data to create vertex buffer with. The
  726. structure should be created with gs_vbdata_create(),
  727. and then buffers in this structure should be allocated
  728. with :c:func:`bmalloc()`, :c:func:`bzalloc()`, or
  729. :c:func:`brealloc()`. The ownership of the gs_vb_data
  730. pointer is then passed to the function, and they should
  731. not be destroyed by the caller once passed
  732. :param flags: Creation flags. Can be 0 or a bitwise-OR combination
  733. of any of the following values:
  734. - GS_DYNAMIC - Can be dynamically updated in real time.
  735. - GS_DUP_BUFFER - Do not pass buffer ownership of the
  736. structure or the buffer pointers within the
  737. structure.
  738. :return: A new vertex buffer object, or *NULL* if failed
  739. ---------------------
  740. .. function:: void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer)
  741. Destroys a vertex buffer object.
  742. :param vertbuffer: Vertex buffer object
  743. ---------------------
  744. .. function:: void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer)
  745. Flushes a vertex buffer to its interval vertex data object. To
  746. modify its internal vertex data, call
  747. :c:func:`gs_vertexbuffer_get_data()`.
  748. Can only be used with dynamic vertex buffer objects.
  749. :param vertbuffer: Vertex buffer object
  750. ---------------------
  751. .. function:: void gs_vertexbuffer_flush_direct(gs_vertbuffer_t *vertbuffer, const struct gs_vb_data *data)
  752. Directly flushes a vertex buffer to the specified vertex buffer data.
  753. .
  754. Can only be used with dynamic vertex buffer objects.
  755. :param vertbuffer: Vertex buffer object
  756. :param data: Vertex buffer data to flush. Components that
  757. don't need to be flushed can be left *NULL*
  758. ---------------------
  759. .. function:: struct gs_vb_data *gs_vertexbuffer_get_data(const gs_vertbuffer_t *vertbuffer)
  760. Gets the vertex buffer data associated with a vertex buffer object.
  761. This data can be changed and vertex buffer can be updated with
  762. :c:func:`gs_vertexbuffer_flush()`.
  763. Can only be used with dynamic vertex buffer objects.
  764. :param vertbuffer: Vertex buffer object
  765. :return: Vertex buffer data structure
  766. ---------------------
  767. Index Buffer Functions
  768. ----------------------
  769. .. function:: gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type, void *indices, size_t num, uint32_t flags)
  770. Creates an index buffer.
  771. :param type: Index buffer type
  772. :param indices: Index buffer data. This buffer must be allocated
  773. with :c:func:`bmalloc()`, :c:func:`bzalloc()`, or
  774. :c:func:`bralloc()`, and ownership of this buffer is
  775. passed to the index buffer object.
  776. :param num: Number of indices in the buffer
  777. :param flags: Creation flags. Can be 0 or a bitwise-OR combination
  778. of any of the following values:
  779. - GS_DYNAMIC - Can be dynamically updated in real time.
  780. - GS_DUP_BUFFER - Do not pass buffer ownership
  781. :return: A new index buffer object, or *NULL* if failed
  782. ---------------------
  783. .. function:: void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer)
  784. Destroys an index buffer object.
  785. :param indexbuffer: Index buffer object
  786. ---------------------
  787. .. function:: void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer)
  788. Flushes a index buffer to its interval index data object. To modify
  789. its internal index data, call :c:func:`gs_indexbuffer_get_data()`.
  790. Can only be used with dynamic index buffer objects.
  791. :param indexbuffer: Index buffer object
  792. ---------------------
  793. .. function:: void gs_indexbuffer_flush_direct(gs_indexbuffer_t *indexbuffer, const void *data)
  794. Flushes a index buffer to the specified index buffer data.
  795. Can only be used with dynamic index buffer objects.
  796. :param indexbuffer: Index buffer object
  797. :param data: Index buffer data to flush
  798. ---------------------
  799. .. function:: void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer)
  800. Gets the index buffer data associated with a index buffer object.
  801. This data can be changed and index buffer can be updated with
  802. :c:func:`gs_indexbuffer_flush()`.
  803. Can only be used with dynamic index buffer objects.
  804. :param vertbuffer: Index buffer object
  805. :return: Index buffer data pointer
  806. ---------------------
  807. .. function:: size_t gs_indexbuffer_get_num_indices(const gs_indexbuffer_t *indexbuffer)
  808. Gets the number of indices associated with this index buffer.
  809. :param indexbuffer: Index buffer object
  810. :return: Number of indices the vertex buffer object has
  811. ---------------------
  812. .. function:: enum gs_index_type gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer)
  813. Gets the type of index buffer.
  814. :param indexbuffer: Index buffer object
  815. :return: Index buffer type
  816. ---------------------
  817. Display Duplicator (Windows Only)
  818. ---------------------------------
  819. .. function:: gs_duplicator_t *gs_duplicator_create(int monitor_idx)
  820. ---------------------
  821. .. function:: void gs_duplicator_destroy(gs_duplicator_t *duplicator)
  822. ---------------------
  823. .. function:: bool gs_duplicator_update_frame(gs_duplicator_t *duplicator)
  824. ---------------------
  825. .. function:: gs_texture_t *gs_duplicator_get_texture(gs_duplicator_t *duplicator)
  826. ---------------------
  827. .. function:: bool gs_get_duplicator_monitor_info(int monitor_idx, struct gs_monitor_info *monitor_info)
  828. ---------------------
  829. Render Helper Functions
  830. -----------------------
  831. .. function:: void gs_render_start(bool b_new)
  832. ---------------------
  833. .. function:: void gs_render_stop(enum gs_draw_mode mode)
  834. ---------------------
  835. .. function:: gs_vertbuffer_t *gs_render_save(void)
  836. ---------------------
  837. .. function:: void gs_vertex2f(float x, float y)
  838. ---------------------
  839. .. function:: void gs_vertex3f(float x, float y, float z)
  840. ---------------------
  841. .. function:: void gs_normal3f(float x, float y, float z)
  842. ---------------------
  843. .. function:: void gs_color(uint32_t color)
  844. ---------------------
  845. .. function:: void gs_texcoord(float x, float y, int unit)
  846. ---------------------
  847. .. function:: void gs_vertex2v(const struct vec2 *v)
  848. ---------------------
  849. .. function:: void gs_vertex3v(const struct vec3 *v)
  850. ---------------------
  851. .. function:: void gs_normal3v(const struct vec3 *v)
  852. ---------------------
  853. .. function:: void gs_color4v(const struct vec4 *v)
  854. ---------------------
  855. .. function:: void gs_texcoord2v(const struct vec2 *v, int unit)
  856. ---------------------
  857. Graphics Types
  858. --------------
  859. .. type:: typedef struct gs_duplicator gs_duplicator_t
  860. .. type:: typedef struct gs_texture gs_texture_t
  861. .. type:: typedef struct gs_stage_surface gs_stagesurf_t
  862. .. type:: typedef struct gs_zstencil_buffer gs_zstencil_t
  863. .. type:: typedef struct gs_vertex_buffer gs_vertbuffer_t
  864. .. type:: typedef struct gs_index_buffer gs_indexbuffer_t
  865. .. type:: typedef struct gs_sampler_state gs_samplerstate_t
  866. .. type:: typedef struct gs_swap_chain gs_swapchain_t
  867. .. type:: typedef struct gs_texture_render gs_texrender_t
  868. .. type:: typedef struct gs_shader gs_shader_t
  869. .. type:: typedef struct gs_shader_param gs_sparam_t
  870. .. type:: typedef struct gs_device gs_device_t
  871. .. type:: typedef struct graphics_subsystem graphics_t