reference-libobs-graphics-graphics.rst 47 KB

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