reference-libobs-graphics-graphics.rst 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  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's source and destination factors
  470. :param src: Blend type for the blending equation's source factors
  471. :param dest: Blend type for the blending equation's destination factors
  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's source and destination factors for RGB and alpha separately
  475. :param src_c: Blend type for the blending equation's source RGB factor
  476. :param dest_c: Blend type for the blending equation's destination RGB factor
  477. :param src_a: Blend type for the blending equation's source alpha factor
  478. :param dest_a: Blend type for the blending equation's destination alpha factor
  479. ---------------------
  480. .. function:: void gs_blend_op(enum gs_blend_op_type op)
  481. Sets the blend function's operation type
  482. :param op: Operation type for the blending equation
  483. ---------------------
  484. .. function:: void gs_depth_function(enum gs_depth_test test)
  485. Sets the depth function
  486. :param test: Sets the depth test type
  487. ---------------------
  488. .. function:: void gs_stencil_function(enum gs_stencil_side side, enum gs_depth_test test)
  489. Sets the stencil function
  490. :param side: Stencil side
  491. :param test: Depth test
  492. ---------------------
  493. .. 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)
  494. Sets the stencil operation
  495. :param side: Stencil side
  496. :param fail: Operation to perform on stencil test failure
  497. :param zfail: Operation to perform on depth test failure
  498. :param zpass: Operation to perform on depth test success
  499. ---------------------
  500. .. function:: void gs_set_viewport(int x, int y, int width, int height)
  501. Sets the current viewport
  502. :param x: X position relative to upper left
  503. :param y: Y position relative to upper left
  504. :param width: Width of the viewport
  505. :param height: Height of the viewport
  506. ---------------------
  507. .. function:: void gs_get_viewport(struct gs_rect *rect)
  508. Gets the current viewport
  509. :param rect: Pointer to receive viewport rectangle
  510. ---------------------
  511. .. function:: void gs_set_scissor_rect(const struct gs_rect *rect)
  512. Sets or clears the current scissor rectangle
  513. :rect: Scissor rectangle, or *NULL* to clear
  514. ---------------------
  515. .. function:: void gs_ortho(float left, float right, float top, float bottom, float znear, float zfar)
  516. Sets the projection matrix to an orthographic matrix
  517. ---------------------
  518. .. function:: void gs_frustum(float left, float right, float top, float bottom, float znear, float zfar)
  519. Sets the projection matrix to a frustum matrix
  520. ---------------------
  521. .. function:: void gs_projection_push(void)
  522. Pushes/stores the current projection matrix
  523. ---------------------
  524. .. function:: void gs_projection_pop(void)
  525. Pops/restores the last projection matrix pushed
  526. ---------------------
  527. Texture Functions
  528. -----------------
  529. .. 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)
  530. Creates a texture.
  531. :param width: Width
  532. :param height: Height
  533. :param color_format: Color format
  534. :param levels: Number of total texture levels. Set to 1 if no
  535. mip-mapping
  536. :param data: Pointer to array of texture data pointers
  537. :param flags: Can be 0 or a bitwise-OR combination of one or
  538. more of the following value:
  539. - GS_BUILD_MIPMAPS - Automatically builds
  540. mipmaps (Note: not fully tested)
  541. - GS_DYNAMIC - Dynamic
  542. - GS_RENDER_TARGET - Render target
  543. :return: A new texture object
  544. ---------------------
  545. .. function:: gs_texture_t *gs_texture_create_from_file(const char *file)
  546. Creates a texture from a file. Note that this isn't recommended for
  547. animated gifs -- instead use the :ref:`image_file_helper`.
  548. :param file: Image file to open
  549. ---------------------
  550. .. function:: void gs_texture_destroy(gs_texture_t *tex)
  551. Destroys a texture
  552. :param tex: Texture object
  553. ---------------------
  554. .. function:: uint32_t gs_texture_get_width(const gs_texture_t *tex)
  555. Gets the texture's width
  556. :param tex: Texture object
  557. :return: The texture's width
  558. ---------------------
  559. .. function:: uint32_t gs_texture_get_height(const gs_texture_t *tex)
  560. Gets the texture's height
  561. :param tex: Texture object
  562. :return: The texture's height
  563. ---------------------
  564. .. function:: enum gs_color_format gs_texture_get_color_format(const gs_texture_t *tex)
  565. Gets the texture's color format
  566. :param tex: Texture object
  567. :return: The texture's color format
  568. ---------------------
  569. .. function:: bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize)
  570. Maps a texture.
  571. :param tex: Texture object
  572. :param ptr: Pointer to receive the pointer to the texture data
  573. to write to
  574. :param linesize: Pointer to receive the line size (pitch) of the
  575. texture
  576. ---------------------
  577. .. function:: void gs_texture_unmap(gs_texture_t *tex)
  578. Unmaps a texture.
  579. :param tex: Texture object
  580. ---------------------
  581. .. function:: void gs_texture_set_image(gs_texture_t *tex, const uint8_t *data, uint32_t linesize, bool invert)
  582. Sets the image of a dynamic texture
  583. :param tex: Texture object
  584. :param data: Data to set as the image
  585. :param linesize: Line size (pitch) of the data
  586. :param invert: *true* to invert vertically, *false* otherwise
  587. ---------------------
  588. .. function:: gs_texture_t *gs_texture_create_from_dmabuf(unsigned int width, unsigned int height, uint32_t drm_format, enum gs_color_format color_format, uint32_t n_planes, const int *fds, const uint32_t *strides, const uint32_t *offsets, const uint64_t *modifiers)
  589. **Linux only:** Creates a texture from DMA-BUF metadata.
  590. Exchanging DMA-BUFs is a verbose process because of its multiplanar nature.
  591. For example, YUV can have each plane as a color channel, or a monitor buffer
  592. can have the cursor stored in a separate plane.
  593. This function treats the OBS Studio format and the DRM format separately.
  594. This allows creating textures from DMA-BUFs with unsupported formats (e.g.
  595. YUV) and perform the color format conversion using shaders. However, be
  596. careful to always try and match the formats correctly, otherwise textures
  597. can fail to be created or rendered.
  598. All modifiers passed in the modifiers array must be equal. Passing different
  599. modifiers for each plane is unsupported.
  600. :param width: Width of the texture
  601. :param height: Height of the texture
  602. :param drm_format: DRM format of the DMA-BUF buffer
  603. :param color_format: Color format compatible with OBS Studio
  604. :param n_planes: Number of planes of the DMA-BUF
  605. :param fds: Array of size *n_planes* with the file descriptor of each plane
  606. :param strides: Array of size *n_planes* with the stride of each plane
  607. :param offsets: Array of size *n_planes* with the offset of each plane
  608. :param modifiers: Array of size *n_planes* with the modifier of each plane
  609. :return: A texture object on success, or *NULL* on failure
  610. :rtype: gs_texture_t*
  611. ---------------------
  612. .. function:: gs_texture_t *gs_texture_create_from_iosurface(void *iosurf)
  613. **Mac only:** Creates a texture from an IOSurface.
  614. :param iosurf: IOSurface object
  615. ---------------------
  616. .. function:: bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
  617. **Mac only:** Rebinds a texture to another IOSurface
  618. :param texture: Texture object
  619. :param iosuf: IOSurface object
  620. ---------------------
  621. .. function:: gs_texture_t *gs_texture_create_gdi(uint32_t width, uint32_t height)
  622. **Windows only:** Creates a GDI-interop texture
  623. :param width: Width
  624. :param height: Height
  625. ---------------------
  626. .. function:: void *gs_texture_get_dc(gs_texture_t *gdi_tex)
  627. **Windows only:** Gets the HDC of a GDI-interop texture. Call
  628. :c:func:`gs_texture_release_dc()` to release the HDC.
  629. :param gdi_tex: GDI-interop texture object
  630. :return: HDC object
  631. ---------------------
  632. .. function:: void gs_texture_release_dc(gs_texture_t *gdi_tex)
  633. **Windows only:** Releases the HDC of the GDI-interop texture.
  634. :param gdi_tex: GDI-interop texture object
  635. ---------------------
  636. .. function:: gs_texture_t *gs_texture_open_shared(uint32_t handle)
  637. **Windows only:** Creates a texture from a shared texture handle.
  638. :param handle: Shared texture handle
  639. :return: A texture object
  640. ---------------------
  641. .. function:: bool gs_gdi_texture_available(void)
  642. **Windows only:** Returns whether GDI-interop textures are available.
  643. :return: *true* if available, *false* otherwise
  644. ---------------------
  645. .. function:: bool gs_shared_texture_available(void)
  646. **Windows only:** Returns whether shared textures are available.
  647. :return: *true* if available, *false* otherwise
  648. ---------------------
  649. Cube Texture Functions
  650. ----------------------
  651. .. 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)
  652. Creates a cubemap texture.
  653. :param size: Width/height/depth value
  654. :param color_format: Color format
  655. :param levels: Number of texture levels
  656. :param data: Pointer to array of texture data pointers
  657. :param flags: Can be 0 or a bitwise-OR combination of one or
  658. more of the following value:
  659. - GS_BUILD_MIPMAPS - Automatically builds
  660. mipmaps (Note: not fully tested)
  661. - GS_DYNAMIC - Dynamic
  662. - GS_RENDER_TARGET - Render target
  663. :return: A new cube texture object
  664. ---------------------
  665. .. function:: void gs_cubetexture_destroy(gs_texture_t *cubetex)
  666. Destroys a cube texture.
  667. :param cubetex: Cube texture object
  668. ---------------------
  669. .. function:: uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex)
  670. Get the width/height/depth value of a cube texture.
  671. :param cubetex: Cube texture object
  672. :return: The width/height/depth value of the cube texture
  673. ---------------------
  674. .. function:: enum gs_color_format gs_cubetexture_get_color_format(const gs_texture_t *cubetex)
  675. Gets the color format of a cube texture.
  676. :param cubetex: Cube texture object
  677. :return: The color format of the cube texture
  678. ---------------------
  679. .. function:: void gs_cubetexture_set_image(gs_texture_t *cubetex, uint32_t side, const void *data, uint32_t linesize, bool invert)
  680. Sets an image of a cube texture side.
  681. :param cubetex: Cube texture object
  682. :param side: Side
  683. :param data: Texture data to set
  684. :param linesize: Line size (pitch) of the texture data
  685. :param invert: *true* to invert texture data, *false* otherwise
  686. ---------------------
  687. Staging Surface Functions
  688. -------------------------
  689. Staging surfaces are used to efficiently copy textures from VRAM to RAM.
  690. .. function:: gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height, enum gs_color_format color_format)
  691. Creates a staging surface.
  692. :param width: Width
  693. :param height: Height
  694. :param color_format: Color format
  695. :return: The staging surface object
  696. ---------------------
  697. .. function:: void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf)
  698. Destroys a staging surface.
  699. :param stagesurf: Staging surface object
  700. ---------------------
  701. .. function:: uint32_t gs_stagesurface_get_width(const gs_stagesurf_t *stagesurf)
  702. uint32_t gs_stagesurface_get_height(const gs_stagesurf_t *stagesurf)
  703. Gets the width/height of a staging surface object.
  704. :param stagesurf: Staging surface object
  705. :return: Width/height of the staging surface
  706. ---------------------
  707. .. function:: enum gs_color_format gs_stagesurface_get_color_format(const gs_stagesurf_t *stagesurf)
  708. Gets the color format of a staging surface object.
  709. :param stagesurf: Staging surface object
  710. :return: Color format of the staging surface
  711. ---------------------
  712. .. function:: bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data, uint32_t *linesize)
  713. Maps the staging surface texture (for reading). Call
  714. :c:func:`gs_stagesurface_unmap()` to unmap when complete.
  715. :param stagesurf: Staging surface object
  716. :param data: Pointer to receive texture data pointer
  717. :param linesize: Pointer to receive line size (pitch) of the texture
  718. data
  719. :return: *true* if map successful, *false* otherwise
  720. ---------------------
  721. .. function:: void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf)
  722. Unmaps a staging surface.
  723. :param stagesurf: Staging surface object
  724. ---------------------
  725. Z-Stencil Functions
  726. -------------------
  727. .. function:: gs_zstencil_t *gs_zstencil_create(uint32_t width, uint32_t height, enum gs_zstencil_format format)
  728. Creates a Z-stencil surface object.
  729. :param width: Width
  730. :param height: Height
  731. :param format: Format
  732. :return: New Z-stencil surface object, or *NULL* if failed
  733. ---------------------
  734. .. function:: void gs_zstencil_destroy(gs_zstencil_t *zstencil)
  735. Destroys a Z-stencil buffer.
  736. :param zstencil: Z-stencil surface object
  737. ---------------------
  738. Sampler State Functions
  739. -----------------------
  740. .. function:: gs_samplerstate_t *gs_samplerstate_create(const struct gs_sampler_info *info)
  741. Creates a sampler state object.
  742. :param info: Sampler state information
  743. :return: New sampler state object
  744. ---------------------
  745. .. function:: void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
  746. Destroys a sampler state object.
  747. :param samplerstate: Sampler state object
  748. ---------------------
  749. Vertex Buffer Functions
  750. -----------------------
  751. .. function:: gs_vertbuffer_t *gs_vertexbuffer_create(struct gs_vb_data *data, uint32_t flags)
  752. Creates a vertex buffer.
  753. :param data: Vertex buffer data to create vertex buffer with. The
  754. structure should be created with gs_vbdata_create(),
  755. and then buffers in this structure should be allocated
  756. with :c:func:`bmalloc()`, :c:func:`bzalloc()`, or
  757. :c:func:`brealloc()`. The ownership of the gs_vb_data
  758. pointer is then passed to the function, and they should
  759. not be destroyed by the caller once passed
  760. :param flags: Creation flags. Can be 0 or a bitwise-OR combination
  761. of any of the following values:
  762. - GS_DYNAMIC - Can be dynamically updated in real time.
  763. - GS_DUP_BUFFER - Do not pass buffer ownership of the
  764. structure or the buffer pointers within the
  765. structure.
  766. :return: A new vertex buffer object, or *NULL* if failed
  767. ---------------------
  768. .. function:: void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer)
  769. Destroys a vertex buffer object.
  770. :param vertbuffer: Vertex buffer object
  771. ---------------------
  772. .. function:: void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer)
  773. Flushes a vertex buffer to its interval vertex data object. To
  774. modify its internal vertex data, call
  775. :c:func:`gs_vertexbuffer_get_data()`.
  776. Can only be used with dynamic vertex buffer objects.
  777. :param vertbuffer: Vertex buffer object
  778. ---------------------
  779. .. function:: void gs_vertexbuffer_flush_direct(gs_vertbuffer_t *vertbuffer, const struct gs_vb_data *data)
  780. Directly flushes a vertex buffer to the specified vertex buffer data.
  781. .
  782. Can only be used with dynamic vertex buffer objects.
  783. :param vertbuffer: Vertex buffer object
  784. :param data: Vertex buffer data to flush. Components that
  785. don't need to be flushed can be left *NULL*
  786. ---------------------
  787. .. function:: struct gs_vb_data *gs_vertexbuffer_get_data(const gs_vertbuffer_t *vertbuffer)
  788. Gets the vertex buffer data associated with a vertex buffer object.
  789. This data can be changed and vertex buffer can be updated with
  790. :c:func:`gs_vertexbuffer_flush()`.
  791. Can only be used with dynamic vertex buffer objects.
  792. :param vertbuffer: Vertex buffer object
  793. :return: Vertex buffer data structure
  794. ---------------------
  795. Index Buffer Functions
  796. ----------------------
  797. .. function:: gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type, void *indices, size_t num, uint32_t flags)
  798. Creates an index buffer.
  799. :param type: Index buffer type
  800. :param indices: Index buffer data. This buffer must be allocated
  801. with :c:func:`bmalloc()`, :c:func:`bzalloc()`, or
  802. :c:func:`bralloc()`, and ownership of this buffer is
  803. passed to the index buffer object.
  804. :param num: Number of indices in the buffer
  805. :param flags: Creation flags. Can be 0 or a bitwise-OR combination
  806. of any of the following values:
  807. - GS_DYNAMIC - Can be dynamically updated in real time.
  808. - GS_DUP_BUFFER - Do not pass buffer ownership
  809. :return: A new index buffer object, or *NULL* if failed
  810. ---------------------
  811. .. function:: void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer)
  812. Destroys an index buffer object.
  813. :param indexbuffer: Index buffer object
  814. ---------------------
  815. .. function:: void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer)
  816. Flushes a index buffer to its interval index data object. To modify
  817. its internal index data, call :c:func:`gs_indexbuffer_get_data()`.
  818. Can only be used with dynamic index buffer objects.
  819. :param indexbuffer: Index buffer object
  820. ---------------------
  821. .. function:: void gs_indexbuffer_flush_direct(gs_indexbuffer_t *indexbuffer, const void *data)
  822. Flushes a index buffer to the specified index buffer data.
  823. Can only be used with dynamic index buffer objects.
  824. :param indexbuffer: Index buffer object
  825. :param data: Index buffer data to flush
  826. ---------------------
  827. .. function:: void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer)
  828. Gets the index buffer data associated with a index buffer object.
  829. This data can be changed and index buffer can be updated with
  830. :c:func:`gs_indexbuffer_flush()`.
  831. Can only be used with dynamic index buffer objects.
  832. :param vertbuffer: Index buffer object
  833. :return: Index buffer data pointer
  834. ---------------------
  835. .. function:: size_t gs_indexbuffer_get_num_indices(const gs_indexbuffer_t *indexbuffer)
  836. Gets the number of indices associated with this index buffer.
  837. :param indexbuffer: Index buffer object
  838. :return: Number of indices the vertex buffer object has
  839. ---------------------
  840. .. function:: enum gs_index_type gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer)
  841. Gets the type of index buffer.
  842. :param indexbuffer: Index buffer object
  843. :return: Index buffer type
  844. ---------------------
  845. Display Duplicator (Windows Only)
  846. ---------------------------------
  847. .. function:: gs_duplicator_t *gs_duplicator_create(int monitor_idx)
  848. ---------------------
  849. .. function:: void gs_duplicator_destroy(gs_duplicator_t *duplicator)
  850. ---------------------
  851. .. function:: bool gs_duplicator_update_frame(gs_duplicator_t *duplicator)
  852. ---------------------
  853. .. function:: gs_texture_t *gs_duplicator_get_texture(gs_duplicator_t *duplicator)
  854. ---------------------
  855. .. function:: bool gs_get_duplicator_monitor_info(int monitor_idx, struct gs_monitor_info *monitor_info)
  856. ---------------------
  857. Render Helper Functions
  858. -----------------------
  859. .. function:: void gs_render_start(bool b_new)
  860. ---------------------
  861. .. function:: void gs_render_stop(enum gs_draw_mode mode)
  862. ---------------------
  863. .. function:: gs_vertbuffer_t *gs_render_save(void)
  864. ---------------------
  865. .. function:: void gs_vertex2f(float x, float y)
  866. ---------------------
  867. .. function:: void gs_vertex3f(float x, float y, float z)
  868. ---------------------
  869. .. function:: void gs_normal3f(float x, float y, float z)
  870. ---------------------
  871. .. function:: void gs_color(uint32_t color)
  872. ---------------------
  873. .. function:: void gs_texcoord(float x, float y, int unit)
  874. ---------------------
  875. .. function:: void gs_vertex2v(const struct vec2 *v)
  876. ---------------------
  877. .. function:: void gs_vertex3v(const struct vec3 *v)
  878. ---------------------
  879. .. function:: void gs_normal3v(const struct vec3 *v)
  880. ---------------------
  881. .. function:: void gs_color4v(const struct vec4 *v)
  882. ---------------------
  883. .. function:: void gs_texcoord2v(const struct vec2 *v, int unit)
  884. ---------------------
  885. Graphics Types
  886. --------------
  887. .. type:: typedef struct gs_duplicator gs_duplicator_t
  888. .. type:: typedef struct gs_texture gs_texture_t
  889. .. type:: typedef struct gs_stage_surface gs_stagesurf_t
  890. .. type:: typedef struct gs_zstencil_buffer gs_zstencil_t
  891. .. type:: typedef struct gs_vertex_buffer gs_vertbuffer_t
  892. .. type:: typedef struct gs_index_buffer gs_indexbuffer_t
  893. .. type:: typedef struct gs_sampler_state gs_samplerstate_t
  894. .. type:: typedef struct gs_swap_chain gs_swapchain_t
  895. .. type:: typedef struct gs_texture_render gs_texrender_t
  896. .. type:: typedef struct gs_shader gs_shader_t
  897. .. type:: typedef struct gs_shader_param gs_sparam_t
  898. .. type:: typedef struct gs_device gs_device_t
  899. .. type:: typedef struct graphics_subsystem graphics_t