reference-libobs-graphics-graphics.rst 38 KB

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