1
0

graphics.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <assert.h>
  15. #include "../util/base.h"
  16. #include "../util/bmem.h"
  17. #include "../util/platform.h"
  18. #include "graphics-internal.h"
  19. #include "vec2.h"
  20. #include "vec3.h"
  21. #include "quat.h"
  22. #include "axisang.h"
  23. #include "effect-parser.h"
  24. #include "effect.h"
  25. #if 0
  26. #ifdef _MSC_VER
  27. static __declspec(thread) graphics_t thread_graphics = NULL;
  28. #else /* assume GCC or that other compiler we dare not mention */
  29. static __thread graphics_t thread_graphics = NULL;
  30. #endif
  31. #else
  32. static graphics_t thread_graphics = NULL;
  33. #endif
  34. #define IMMEDIATE_VERTEX_COUNT 512
  35. bool load_graphics_imports(struct gs_exports *exports, void *module,
  36. const char *module_name);
  37. static bool graphics_init(struct graphics_subsystem *graphics)
  38. {
  39. struct matrix3 top_mat;
  40. struct vb_data *vbd;
  41. matrix3_identity(&top_mat);
  42. da_push_back(graphics->matrix_stack, &top_mat);
  43. vbd = vbdata_create();
  44. vbd->num = IMMEDIATE_VERTEX_COUNT;
  45. vbd->points = bmalloc(sizeof(struct vec3) * IMMEDIATE_VERTEX_COUNT);
  46. vbd->normals = bmalloc(sizeof(struct vec3) * IMMEDIATE_VERTEX_COUNT);
  47. vbd->colors = bmalloc(sizeof(uint32_t) * IMMEDIATE_VERTEX_COUNT);
  48. vbd->num_tex = 1;
  49. vbd->tvarray = bmalloc(sizeof(struct tvertarray));
  50. vbd->tvarray[0].width = 2;
  51. vbd->tvarray[0].array =
  52. bmalloc(sizeof(struct vec2) * IMMEDIATE_VERTEX_COUNT);
  53. graphics->immediate_vertbuffer = graphics->exports.
  54. device_create_vertexbuffer(graphics->device, vbd, GS_DYNAMIC);
  55. if (!graphics->immediate_vertbuffer)
  56. return false;
  57. vbd = vbdata_create();
  58. vbd->num = 4;
  59. vbd->points = bmalloc(sizeof(struct vec3) * 4);
  60. vbd->num_tex = 1;
  61. vbd->tvarray = bmalloc(sizeof(struct tvertarray));
  62. vbd->tvarray[0].width = 2;
  63. vbd->tvarray[0].array = bmalloc(sizeof(struct vec2) * 4);
  64. memset(vbd->points, 0, sizeof(struct vec3) * 4);
  65. memset(vbd->tvarray[0].array, 0, sizeof(struct vec2) * 4);
  66. graphics->sprite_buffer = graphics->exports.
  67. device_create_vertexbuffer(graphics->device, vbd, GS_DYNAMIC);
  68. if (!graphics->sprite_buffer)
  69. return false;
  70. return true;
  71. }
  72. int gs_create(graphics_t *pgraphics, const char *module,
  73. struct gs_init_data *data)
  74. {
  75. int errcode = GS_ERROR_FAIL;
  76. graphics_t graphics = bmalloc(sizeof(struct graphics_subsystem));
  77. memset(graphics, 0, sizeof(struct graphics_subsystem));
  78. graphics->module = os_dlopen(module);
  79. if (!graphics->module) {
  80. errcode = GS_ERROR_MODULENOTFOUND;
  81. goto error;
  82. }
  83. if (!load_graphics_imports(&graphics->exports, graphics->module,
  84. module))
  85. goto error;
  86. graphics->device = graphics->exports.device_create(data);
  87. if (!graphics->device)
  88. goto error;
  89. if (!graphics_init(graphics))
  90. goto error;
  91. *pgraphics = graphics;
  92. return GS_SUCCESS;
  93. error:
  94. gs_destroy(graphics);
  95. return errcode;
  96. }
  97. void gs_destroy(graphics_t graphics)
  98. {
  99. if (!graphics)
  100. return;
  101. if (graphics->module) {
  102. graphics->exports.vertexbuffer_destroy(graphics->sprite_buffer);
  103. graphics->exports.vertexbuffer_destroy(
  104. graphics->immediate_vertbuffer);
  105. graphics->exports.device_destroy(graphics->device);
  106. }
  107. da_free(graphics->matrix_stack);
  108. da_free(graphics->viewport_stack);
  109. os_dlclose(graphics->module);
  110. bfree(graphics);
  111. if (thread_graphics == graphics)
  112. thread_graphics = NULL;
  113. }
  114. void gs_setcontext(graphics_t graphics)
  115. {
  116. thread_graphics = graphics;
  117. }
  118. graphics_t gs_getcontext(void)
  119. {
  120. return thread_graphics;
  121. }
  122. static inline struct matrix3 *top_matrix(graphics_t graphics)
  123. {
  124. return graphics->matrix_stack.array + graphics->cur_matrix;
  125. }
  126. void gs_matrix_push(void)
  127. {
  128. graphics_t graphics = thread_graphics;
  129. struct matrix3 mat, *top_mat = top_matrix(graphics);
  130. memcpy(&mat, top_mat, sizeof(struct matrix3));
  131. da_push_back(graphics->matrix_stack, &mat);
  132. graphics->cur_matrix++;
  133. }
  134. void gs_matrix_pop(void)
  135. {
  136. graphics_t graphics = thread_graphics;
  137. if (graphics->cur_matrix == 0) {
  138. blog(LOG_ERROR, "Tried to pop last matrix on stack");
  139. return;
  140. }
  141. da_erase(graphics->matrix_stack, graphics->cur_matrix);
  142. graphics->cur_matrix--;
  143. }
  144. void gs_matrix_identity(void)
  145. {
  146. struct matrix3 *top_mat = top_matrix(thread_graphics);
  147. matrix3_identity(top_mat);
  148. }
  149. void gs_matrix_transpose(void)
  150. {
  151. struct matrix3 *top_mat = top_matrix(thread_graphics);
  152. matrix3_transpose(top_mat, top_mat);
  153. }
  154. void gs_matrix_set(const struct matrix3 *matrix)
  155. {
  156. struct matrix3 *top_mat = top_matrix(thread_graphics);
  157. matrix3_copy(top_mat, matrix);
  158. }
  159. void gs_matrix_get(struct matrix3 *dst)
  160. {
  161. struct matrix3 *top_mat = top_matrix(thread_graphics);
  162. matrix3_copy(dst, top_mat);
  163. }
  164. void gs_matrix_mul(const struct matrix3 *matrix)
  165. {
  166. struct matrix3 *top_mat = top_matrix(thread_graphics);
  167. matrix3_mul(top_mat, top_mat, matrix);
  168. }
  169. void gs_matrix_rotquat(const struct quat *rot)
  170. {
  171. struct matrix3 *top_mat = top_matrix(thread_graphics);
  172. matrix3_rotate(top_mat, top_mat, rot);
  173. }
  174. void gs_matrix_rotaa(const struct axisang *rot)
  175. {
  176. struct matrix3 *top_mat = top_matrix(thread_graphics);
  177. matrix3_rotate_aa(top_mat, top_mat, rot);
  178. }
  179. void gs_matrix_translate(const struct vec3 *pos)
  180. {
  181. struct matrix3 *top_mat = top_matrix(thread_graphics);
  182. matrix3_translate(top_mat, top_mat, pos);
  183. }
  184. void gs_matrix_scale(const struct vec3 *scale)
  185. {
  186. struct matrix3 *top_mat = top_matrix(thread_graphics);
  187. matrix3_scale(top_mat, top_mat, scale);
  188. }
  189. void gs_matrix_rotaa4f(float x, float y, float z, float angle)
  190. {
  191. struct matrix3 *top_mat = top_matrix(thread_graphics);
  192. struct axisang aa;
  193. axisang_set(&aa, x, y, z, angle);
  194. matrix3_rotate_aa(top_mat, top_mat, &aa);
  195. }
  196. void gs_matrix_translate3f(float x, float y, float z)
  197. {
  198. struct matrix3 *top_mat = top_matrix(thread_graphics);
  199. struct vec3 p;
  200. vec3_set(&p, x, y, z);
  201. matrix3_translate(top_mat, top_mat, &p);
  202. }
  203. void gs_matrix_scale3f(float x, float y, float z)
  204. {
  205. struct matrix3 *top_mat = top_matrix(thread_graphics);
  206. struct vec3 p;
  207. vec3_set(&p, x, y, z);
  208. matrix3_scale(top_mat, top_mat, &p);
  209. }
  210. static inline void reset_immediate_arrays(graphics_t graphics)
  211. {
  212. size_t i;
  213. da_init(graphics->verts);
  214. da_init(graphics->norms);
  215. da_init(graphics->colors);
  216. for (i = 0; i < 16; i++)
  217. da_init(graphics->texverts[i]);
  218. }
  219. void gs_renderstart(bool b_new)
  220. {
  221. graphics_t graphics = thread_graphics;
  222. graphics->using_immediate = !b_new;
  223. reset_immediate_arrays(graphics);
  224. if (b_new) {
  225. graphics->vbd = vbdata_create();
  226. } else {
  227. graphics->vbd = vertexbuffer_getdata(
  228. graphics->immediate_vertbuffer);
  229. memset(graphics->vbd->colors, 0xFF,
  230. sizeof(uint32_t) * IMMEDIATE_VERTEX_COUNT);
  231. graphics->verts.array = graphics->vbd->points;
  232. graphics->norms.array = graphics->vbd->normals;
  233. graphics->colors.array = graphics->vbd->colors;
  234. graphics->texverts[0].array = graphics->vbd->tvarray[0].array;
  235. graphics->verts.capacity = IMMEDIATE_VERTEX_COUNT;
  236. graphics->norms.capacity = IMMEDIATE_VERTEX_COUNT;
  237. graphics->colors.capacity = IMMEDIATE_VERTEX_COUNT;
  238. graphics->texverts[0].capacity = IMMEDIATE_VERTEX_COUNT;
  239. }
  240. }
  241. static inline size_t min_size(const size_t a, const size_t b)
  242. {
  243. return (a < b) ? a : b;
  244. }
  245. void gs_renderstop(enum gs_draw_mode mode)
  246. {
  247. graphics_t graphics = thread_graphics;
  248. size_t i, num = graphics->verts.num;
  249. if (!num) {
  250. if (!graphics->using_immediate) {
  251. da_free(graphics->verts);
  252. da_free(graphics->norms);
  253. da_free(graphics->colors);
  254. for (i = 0; i < 16; i++)
  255. da_free(graphics->texverts[i]);
  256. vbdata_destroy(graphics->vbd);
  257. }
  258. return;
  259. }
  260. if (graphics->norms.num &&
  261. (graphics->norms.num != graphics->verts.num)) {
  262. blog(LOG_WARNING, "gs_renderstop: normal count does "
  263. "not match vertex count");
  264. num = min_size(num, graphics->norms.num);
  265. }
  266. if (graphics->colors.num &&
  267. (graphics->colors.num != graphics->verts.num)) {
  268. blog(LOG_WARNING, "gs_renderstop: color count does "
  269. "not match vertex count");
  270. num = min_size(num, graphics->colors.num);
  271. }
  272. if (graphics->texverts[0].num &&
  273. (graphics->texverts[0].num != graphics->verts.num)) {
  274. blog(LOG_WARNING, "gs_renderstop: texture vertex count does "
  275. "not match vertex count");
  276. num = min_size(num, graphics->texverts[0].num);
  277. }
  278. if (graphics->using_immediate) {
  279. vertexbuffer_flush(graphics->immediate_vertbuffer, false);
  280. gs_load_vertexbuffer(graphics->immediate_vertbuffer);
  281. gs_load_indexbuffer(NULL);
  282. gs_draw(mode, 0, (uint32_t)num);
  283. reset_immediate_arrays(graphics);
  284. } else {
  285. vertbuffer_t vb = gs_rendersave();
  286. gs_load_vertexbuffer(vb);
  287. gs_load_indexbuffer(NULL);
  288. gs_draw(mode, 0, 0);
  289. vertexbuffer_destroy(vb);
  290. }
  291. graphics->vbd = NULL;
  292. }
  293. vertbuffer_t gs_rendersave(void)
  294. {
  295. graphics_t graphics = thread_graphics;
  296. size_t num_tex, i;
  297. if (graphics->using_immediate)
  298. return NULL;
  299. if (!graphics->vbd->num) {
  300. vbdata_destroy(graphics->vbd);
  301. return NULL;
  302. }
  303. for (num_tex = 0; num_tex < 16; num_tex++) {
  304. if (!graphics->texverts[num_tex].num)
  305. break;
  306. }
  307. graphics->vbd->points = graphics->verts.array;
  308. graphics->vbd->normals = graphics->norms.array;
  309. graphics->vbd->colors = graphics->colors.array;
  310. graphics->vbd->num = graphics->verts.num;
  311. graphics->vbd->num_tex = num_tex;
  312. graphics->vbd->tvarray = bmalloc(sizeof(struct tvertarray) * num_tex);
  313. for (i = 0; i < num_tex; i++) {
  314. graphics->vbd->tvarray[i].width = 2;
  315. graphics->vbd->tvarray[i].array = graphics->texverts[i].array;
  316. }
  317. reset_immediate_arrays(graphics);
  318. return gs_create_vertexbuffer(graphics->vbd, 0);
  319. }
  320. void gs_vertex2f(float x, float y)
  321. {
  322. struct vec3 v3;
  323. vec3_set(&v3, x, y, 0.0f);
  324. gs_vertex3v(&v3);
  325. }
  326. void gs_vertex3f(float x, float y, float z)
  327. {
  328. struct vec3 v3;
  329. vec3_set(&v3, x, y, z);
  330. gs_vertex3v(&v3);
  331. }
  332. void gs_normal3f(float x, float y, float z)
  333. {
  334. struct vec3 v3;
  335. vec3_set(&v3, x, y, z);
  336. gs_normal3v(&v3);
  337. }
  338. static inline bool validvertsize(graphics_t graphics, size_t num,
  339. const char *name)
  340. {
  341. if (graphics->using_immediate &&
  342. graphics->colors.num == IMMEDIATE_VERTEX_COUNT) {
  343. blog(LOG_WARNING, "%s: tried to use over %u "
  344. "for immediate rendering",
  345. name, IMMEDIATE_VERTEX_COUNT);
  346. return false;
  347. }
  348. return true;
  349. }
  350. void gs_color(uint32_t color)
  351. {
  352. graphics_t graphics = thread_graphics;
  353. if (!validvertsize(graphics, graphics->colors.num, "gs_color"))
  354. return;
  355. da_push_back(graphics->colors, &color);
  356. }
  357. void gs_texcoord(float x, float y, int unit)
  358. {
  359. struct vec2 v2;
  360. vec2_set(&v2, x, y);
  361. gs_texcoord2v(&v2, unit);
  362. }
  363. void gs_vertex2v(const struct vec2 *v)
  364. {
  365. struct vec3 v3;
  366. vec3_set(&v3, v->x, v->y, 0.0f);
  367. gs_vertex3v(&v3);
  368. }
  369. void gs_vertex3v(const struct vec3 *v)
  370. {
  371. graphics_t graphics = thread_graphics;
  372. if (!validvertsize(graphics, graphics->verts.num, "gs_vertex"))
  373. return;
  374. da_push_back(graphics->verts, v);
  375. }
  376. void gs_normal3v(const struct vec3 *v)
  377. {
  378. graphics_t graphics = thread_graphics;
  379. if (!validvertsize(graphics, graphics->norms.num, "gs_normal"))
  380. return;
  381. da_push_back(graphics->norms, v);
  382. }
  383. void gs_color4v(const struct vec4 *v)
  384. {
  385. /* TODO */
  386. }
  387. void gs_texcoord2v(const struct vec2 *v, int unit)
  388. {
  389. graphics_t graphics = thread_graphics;
  390. if (!validvertsize(graphics, graphics->texverts[unit].num,
  391. "gs_texcoord"))
  392. return;
  393. da_push_back(graphics->texverts[unit], v);
  394. }
  395. input_t gs_getinput(void)
  396. {
  397. /* TODO */
  398. return NULL;
  399. }
  400. effect_t gs_geteffect(void)
  401. {
  402. return thread_graphics->cur_effect;
  403. }
  404. effect_t gs_create_effect_from_file(const char *file, char **error_string)
  405. {
  406. char *file_string;
  407. effect_t effect = NULL;
  408. file_string = os_quick_read_utf8_file(file);
  409. if (!file_string) {
  410. blog(LOG_WARNING, "Could not load effect file '%s'", file);
  411. return NULL;
  412. }
  413. effect = gs_create_effect(file_string, file, error_string);
  414. bfree(file_string);
  415. return effect;
  416. }
  417. effect_t gs_create_effect(const char *effect_string, const char *filename,
  418. char **error_string)
  419. {
  420. struct gs_effect *effect = bmalloc(sizeof(struct gs_effect));
  421. struct effect_parser parser;
  422. bool success;
  423. memset(effect, 0, sizeof(struct gs_effect));
  424. effect->graphics = thread_graphics;
  425. ep_init(&parser);
  426. success = ep_parse(&parser, effect, effect_string, filename);
  427. if (!success) {
  428. *error_string = error_data_buildstring(
  429. &parser.cfp.error_list);
  430. effect_destroy(effect);
  431. effect = NULL;
  432. }
  433. ep_free(&parser);
  434. return effect;
  435. }
  436. shader_t gs_create_vertexshader_from_file(const char *file,
  437. char **error_string)
  438. {
  439. char *file_string;
  440. shader_t shader = NULL;
  441. file_string = os_quick_read_utf8_file(file);
  442. if (!file_string) {
  443. blog(LOG_WARNING, "Could not load vertex shader file '%s'",
  444. file);
  445. return NULL;
  446. }
  447. shader = gs_create_vertexshader(file_string, file, error_string);
  448. bfree(file_string);
  449. return shader;
  450. }
  451. shader_t gs_create_pixelshader_from_file(const char *file,
  452. char **error_string)
  453. {
  454. char *file_string;
  455. shader_t shader = NULL;
  456. file_string = os_quick_read_utf8_file(file);
  457. if (!file_string) {
  458. blog(LOG_WARNING, "Could not load pixel shader file '%s'",
  459. file);
  460. return NULL;
  461. }
  462. shader = gs_create_pixelshader(file_string, file, error_string);
  463. bfree(file_string);
  464. return shader;
  465. }
  466. texture_t gs_create_texture_from_file(const char *file, uint32_t flags)
  467. {
  468. /* TODO */
  469. return NULL;
  470. }
  471. texture_t gs_create_cubetexture_from_file(const char *flie, uint32_t flags)
  472. {
  473. /* TODO */
  474. return NULL;
  475. }
  476. texture_t gs_create_volumetexture_from_file(const char *flie, uint32_t flags)
  477. {
  478. /* TODO */
  479. return NULL;
  480. }
  481. void gs_draw_sprite(texture_t tex)
  482. {
  483. graphics_t graphics = thread_graphics;
  484. float fcx, fcy;
  485. struct vb_data *data;
  486. struct vec2 *tvarray;
  487. assert(tex);
  488. if (gs_gettexturetype(tex) != GS_TEXTURE_2D) {
  489. blog(LOG_ERROR, "A sprite must be a 2D texture");
  490. return;
  491. }
  492. fcx = (float)texture_getwidth(tex);
  493. fcy = (float)texture_getheight(tex);
  494. data = vertexbuffer_getdata(graphics->sprite_buffer);
  495. tvarray = data->tvarray[0].array;
  496. vec3_zero(data->points);
  497. vec3_set(data->points+1, fcx, 0.0f, 0.0f);
  498. vec3_set(data->points+2, 0.0f, fcy, 0.0f);
  499. vec3_set(data->points+3, fcx, fcy, 0.0f);
  500. vec2_zero(tvarray);
  501. vec2_set(tvarray+1, 1.0f, 0.0f);
  502. vec2_set(tvarray+2, 0.0f, 1.0f);
  503. vec2_set(tvarray+3, 1.0f, 1.0f);
  504. vertexbuffer_flush(graphics->sprite_buffer, false);
  505. gs_load_vertexbuffer(graphics->sprite_buffer);
  506. gs_draw(GS_TRISTRIP, 0, 0);
  507. }
  508. void gs_draw_cube_backdrop(texture_t cubetex, const struct quat *rot,
  509. float left, float right, float top, float bottom, float znear)
  510. {
  511. /* TODO */
  512. }
  513. void gs_resetviewport(void)
  514. {
  515. uint32_t cx, cy;
  516. gs_getsize(&cx, &cy);
  517. gs_setviewport(0, 0, cx, cy);
  518. }
  519. void gs_set2dmode(void)
  520. {
  521. uint32_t cx, cy;
  522. gs_getsize(&cx, &cy);
  523. gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -1.0, -1024.0f);
  524. }
  525. void gs_set3dmode(double fovy, double znear, double zvar)
  526. {
  527. /* TODO */
  528. }
  529. void gs_viewport_push(void)
  530. {
  531. struct gs_rect *rect = da_push_back_new(
  532. thread_graphics->viewport_stack);
  533. gs_getviewport(rect);
  534. }
  535. void gs_viewport_pop(void)
  536. {
  537. struct gs_rect *rect;
  538. if (!thread_graphics->viewport_stack.num)
  539. return;
  540. rect = da_end(thread_graphics->viewport_stack);
  541. gs_setviewport(rect->x, rect->y, rect->cx, rect->cy);
  542. da_pop_back(thread_graphics->viewport_stack);
  543. }
  544. void texture_setimage(texture_t tex, const void *data, uint32_t byte_width)
  545. {
  546. /* TODO */
  547. }
  548. void cubetexture_setimage(texture_t cubetex, uint32_t side, const void *data,
  549. uint32_t byte_width)
  550. {
  551. /* TODO */
  552. }
  553. /* ------------------------------------------------------------------------- */
  554. swapchain_t gs_create_swapchain(struct gs_init_data *data)
  555. {
  556. graphics_t graphics = thread_graphics;
  557. return graphics->exports.device_create_swapchain(graphics->device,
  558. data);
  559. }
  560. void gs_resize(uint32_t x, uint32_t y)
  561. {
  562. graphics_t graphics = thread_graphics;
  563. graphics->exports.device_resize(graphics->device, x, y);
  564. }
  565. void gs_getsize(uint32_t *x, uint32_t *y)
  566. {
  567. graphics_t graphics = thread_graphics;
  568. graphics->exports.device_getsize(graphics->device, x, y);
  569. }
  570. uint32_t gs_getwidth(void)
  571. {
  572. graphics_t graphics = thread_graphics;
  573. return graphics->exports.device_getwidth(graphics->device);
  574. }
  575. uint32_t gs_getheight(void)
  576. {
  577. graphics_t graphics = thread_graphics;
  578. return graphics->exports.device_getheight(graphics->device);
  579. }
  580. texture_t gs_create_texture(uint32_t width, uint32_t height,
  581. enum gs_color_format color_format, void *data, uint32_t flags)
  582. {
  583. graphics_t graphics = thread_graphics;
  584. return graphics->exports.device_create_texture(graphics->device,
  585. width, height, color_format, data, flags);
  586. }
  587. texture_t gs_create_cubetexture(uint32_t size,
  588. enum gs_color_format color_format, void *data[6],
  589. uint32_t flags)
  590. {
  591. graphics_t graphics = thread_graphics;
  592. return graphics->exports.device_create_cubetexture(graphics->device,
  593. size, color_format, data, flags);
  594. }
  595. texture_t gs_create_volumetexture(uint32_t width, uint32_t height,
  596. uint32_t depth, enum gs_color_format color_format, void *data,
  597. uint32_t flags)
  598. {
  599. graphics_t graphics = thread_graphics;
  600. return graphics->exports.device_create_volumetexture(graphics->device,
  601. width, height, depth, color_format, data, flags);
  602. }
  603. zstencil_t gs_create_zstencil(uint32_t width, uint32_t height,
  604. enum gs_zstencil_format format)
  605. {
  606. graphics_t graphics = thread_graphics;
  607. return graphics->exports.device_create_zstencil(graphics->device,
  608. width, height, format);
  609. }
  610. stagesurf_t gs_create_stagesurface(uint32_t width, uint32_t height,
  611. enum gs_color_format color_format)
  612. {
  613. graphics_t graphics = thread_graphics;
  614. return graphics->exports.device_create_stagesurface(graphics->device,
  615. width, height, color_format);
  616. }
  617. samplerstate_t gs_create_samplerstate(struct gs_sampler_info *info)
  618. {
  619. graphics_t graphics = thread_graphics;
  620. return graphics->exports.device_create_samplerstate(graphics->device,
  621. info);
  622. }
  623. shader_t gs_create_vertexshader(const char *shader, const char *file,
  624. char **error_string)
  625. {
  626. graphics_t graphics = thread_graphics;
  627. return graphics->exports.device_create_vertexshader(graphics->device,
  628. shader, file, error_string);
  629. }
  630. shader_t gs_create_pixelshader(const char *shader,
  631. const char *file, char **error_string)
  632. {
  633. graphics_t graphics = thread_graphics;
  634. return graphics->exports.device_create_pixelshader(graphics->device,
  635. shader, file, error_string);
  636. }
  637. vertbuffer_t gs_create_vertexbuffer(struct vb_data *data,
  638. uint32_t flags)
  639. {
  640. graphics_t graphics = thread_graphics;
  641. return graphics->exports.device_create_vertexbuffer(graphics->device,
  642. data, flags);
  643. }
  644. indexbuffer_t gs_create_indexbuffer(enum gs_index_type type,
  645. void *indices, size_t num, uint32_t flags)
  646. {
  647. graphics_t graphics = thread_graphics;
  648. return graphics->exports.device_create_indexbuffer(graphics->device,
  649. type, indices, num, flags);
  650. }
  651. enum gs_texture_type gs_gettexturetype(texture_t texture)
  652. {
  653. graphics_t graphics = thread_graphics;
  654. return graphics->exports.device_gettexturetype(graphics->device,
  655. texture);
  656. }
  657. void gs_load_vertexbuffer(vertbuffer_t vertbuffer)
  658. {
  659. graphics_t graphics = thread_graphics;
  660. graphics->exports.device_load_vertexbuffer(graphics->device,
  661. vertbuffer);
  662. }
  663. void gs_load_indexbuffer(indexbuffer_t indexbuffer)
  664. {
  665. graphics_t graphics = thread_graphics;
  666. graphics->exports.device_load_indexbuffer(graphics->device,
  667. indexbuffer);
  668. }
  669. void gs_load_texture(texture_t tex, int unit)
  670. {
  671. graphics_t graphics = thread_graphics;
  672. graphics->exports.device_load_texture(graphics->device, tex, unit);
  673. }
  674. void gs_load_samplerstate(samplerstate_t samplerstate, int unit)
  675. {
  676. graphics_t graphics = thread_graphics;
  677. graphics->exports.device_load_samplerstate(graphics->device,
  678. samplerstate, unit);
  679. }
  680. void gs_load_vertexshader(shader_t vertshader)
  681. {
  682. graphics_t graphics = thread_graphics;
  683. graphics->exports.device_load_vertexshader(graphics->device,
  684. vertshader);
  685. }
  686. void gs_load_pixelshader(shader_t pixelshader)
  687. {
  688. graphics_t graphics = thread_graphics;
  689. graphics->exports.device_load_pixelshader(graphics->device,
  690. pixelshader);
  691. }
  692. void gs_load_defaultsamplerstate(bool b_3d, int unit)
  693. {
  694. graphics_t graphics = thread_graphics;
  695. graphics->exports.device_load_defaultsamplerstate(graphics->device,
  696. b_3d, unit);
  697. }
  698. shader_t gs_getvertexshader(void)
  699. {
  700. graphics_t graphics = thread_graphics;
  701. return graphics->exports.device_getvertexshader(graphics->device);
  702. }
  703. shader_t gs_getpixelshader(void)
  704. {
  705. graphics_t graphics = thread_graphics;
  706. return graphics->exports.device_getpixelshader(graphics->device);
  707. }
  708. texture_t gs_getrendertarget(void)
  709. {
  710. graphics_t graphics = thread_graphics;
  711. return graphics->exports.device_getrendertarget(graphics->device);
  712. }
  713. zstencil_t gs_getzstenciltarget(void)
  714. {
  715. graphics_t graphics = thread_graphics;
  716. return graphics->exports.device_getzstenciltarget(graphics->device);
  717. }
  718. void gs_setrendertarget(texture_t tex, zstencil_t zstencil)
  719. {
  720. graphics_t graphics = thread_graphics;
  721. graphics->exports.device_setrendertarget(graphics->device, tex,
  722. zstencil);
  723. }
  724. void gs_setcuberendertarget(texture_t cubetex, int side, zstencil_t zstencil)
  725. {
  726. graphics_t graphics = thread_graphics;
  727. graphics->exports.device_setcuberendertarget(graphics->device, cubetex,
  728. side, zstencil);
  729. }
  730. void gs_copy_texture(texture_t dst, texture_t src)
  731. {
  732. graphics_t graphics = thread_graphics;
  733. graphics->exports.device_copy_texture(graphics->device, dst, src);
  734. }
  735. void gs_stage_texture(stagesurf_t dst, texture_t src)
  736. {
  737. graphics_t graphics = thread_graphics;
  738. graphics->exports.device_stage_texture(graphics->device, dst, src);
  739. }
  740. void gs_beginscene(void)
  741. {
  742. graphics_t graphics = thread_graphics;
  743. graphics->exports.device_beginscene(graphics->device);
  744. }
  745. void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert,
  746. uint32_t num_verts)
  747. {
  748. graphics_t graphics = thread_graphics;
  749. graphics->exports.device_draw(graphics->device, draw_mode,
  750. start_vert, num_verts);
  751. }
  752. void gs_endscene(void)
  753. {
  754. graphics_t graphics = thread_graphics;
  755. graphics->exports.device_endscene(graphics->device);
  756. }
  757. void gs_load_swapchain(swapchain_t swapchain)
  758. {
  759. graphics_t graphics = thread_graphics;
  760. graphics->exports.device_load_swapchain(graphics->device, swapchain);
  761. }
  762. void gs_clear(uint32_t clear_flags, struct vec4 *color, float depth,
  763. uint8_t stencil)
  764. {
  765. graphics_t graphics = thread_graphics;
  766. graphics->exports.device_clear(graphics->device, clear_flags, color,
  767. depth, stencil);
  768. }
  769. void gs_present(void)
  770. {
  771. graphics_t graphics = thread_graphics;
  772. graphics->exports.device_present(graphics->device);
  773. }
  774. void gs_setcullmode(enum gs_cull_mode mode)
  775. {
  776. graphics_t graphics = thread_graphics;
  777. graphics->exports.device_setcullmode(graphics->device, mode);
  778. }
  779. enum gs_cull_mode gs_getcullmode(void)
  780. {
  781. graphics_t graphics = thread_graphics;
  782. return graphics->exports.device_getcullmode(graphics->device);
  783. }
  784. void gs_enable_blending(bool enable)
  785. {
  786. graphics_t graphics = thread_graphics;
  787. graphics->exports.device_enable_blending(graphics->device, enable);
  788. }
  789. void gs_enable_depthtest(bool enable)
  790. {
  791. graphics_t graphics = thread_graphics;
  792. graphics->exports.device_enable_depthtest(graphics->device, enable);
  793. }
  794. void gs_enable_stenciltest(bool enable)
  795. {
  796. graphics_t graphics = thread_graphics;
  797. graphics->exports.device_enable_stenciltest(graphics->device, enable);
  798. }
  799. void gs_enable_stencilwrite(bool enable)
  800. {
  801. graphics_t graphics = thread_graphics;
  802. graphics->exports.device_enable_stencilwrite(graphics->device, enable);
  803. }
  804. void gs_enable_color(bool red, bool blue, bool green, bool alpha)
  805. {
  806. graphics_t graphics = thread_graphics;
  807. graphics->exports.device_enable_color(graphics->device, red, blue,
  808. green, alpha);
  809. }
  810. void gs_blendfunction(enum gs_blend_type src, enum gs_blend_type dest)
  811. {
  812. graphics_t graphics = thread_graphics;
  813. graphics->exports.device_blendfunction(graphics->device, src, dest);
  814. }
  815. void gs_depthfunction(enum gs_depth_test test)
  816. {
  817. graphics_t graphics = thread_graphics;
  818. graphics->exports.device_depthfunction(graphics->device, test);
  819. }
  820. void gs_stencilfunction(enum gs_stencil_side side, enum gs_depth_test test)
  821. {
  822. graphics_t graphics = thread_graphics;
  823. graphics->exports.device_stencilfunction(graphics->device, side, test);
  824. }
  825. void gs_stencilop(enum gs_stencil_side side, enum gs_stencil_op fail,
  826. enum gs_stencil_op zfail, enum gs_stencil_op zpass)
  827. {
  828. graphics_t graphics = thread_graphics;
  829. graphics->exports.device_stencilop(graphics->device, side, fail, zfail,
  830. zpass);
  831. }
  832. void gs_enable_fullscreen(bool enable)
  833. {
  834. graphics_t graphics = thread_graphics;
  835. graphics->exports.device_enable_fullscreen(graphics->device, enable);
  836. }
  837. int gs_fullscreen_enabled(void)
  838. {
  839. graphics_t graphics = thread_graphics;
  840. return graphics->exports.device_fullscreen_enabled(graphics->device);
  841. }
  842. void gs_setdisplaymode(const struct gs_display_mode *mode)
  843. {
  844. graphics_t graphics = thread_graphics;
  845. graphics->exports.device_setdisplaymode(graphics->device, mode);
  846. }
  847. void gs_getdisplaymode(struct gs_display_mode *mode)
  848. {
  849. graphics_t graphics = thread_graphics;
  850. graphics->exports.device_getdisplaymode(graphics->device, mode);
  851. }
  852. void gs_setcolorramp(float gamma, float brightness, float contrast)
  853. {
  854. graphics_t graphics = thread_graphics;
  855. graphics->exports.device_setcolorramp(graphics->device, gamma,
  856. brightness, contrast);
  857. }
  858. void gs_setviewport(int x, int y, int width, int height)
  859. {
  860. graphics_t graphics = thread_graphics;
  861. graphics->exports.device_setviewport(graphics->device, x, y, width,
  862. height);
  863. }
  864. void gs_getviewport(struct gs_rect *rect)
  865. {
  866. graphics_t graphics = thread_graphics;
  867. graphics->exports.device_getviewport(graphics->device, rect);
  868. }
  869. void gs_setscissorrect(struct gs_rect *rect)
  870. {
  871. graphics_t graphics = thread_graphics;
  872. graphics->exports.device_setscissorrect(graphics->device, rect);
  873. }
  874. void gs_ortho(float left, float right, float top, float bottom, float znear,
  875. float zfar)
  876. {
  877. graphics_t graphics = thread_graphics;
  878. graphics->exports.device_ortho(graphics->device, left, right, top,
  879. bottom, znear, zfar);
  880. }
  881. void gs_frustum(float left, float right, float top, float bottom, float znear,
  882. float zfar)
  883. {
  884. graphics_t graphics = thread_graphics;
  885. graphics->exports.device_frustum(graphics->device, left, right, top,
  886. bottom, znear, zfar);
  887. }
  888. void gs_perspective(float fovy, float aspect, float znear, float zfar)
  889. {
  890. graphics_t graphics = thread_graphics;
  891. graphics->exports.device_perspective(graphics->device, fovy, aspect,
  892. znear, zfar);
  893. }
  894. void gs_projection_push(void)
  895. {
  896. graphics_t graphics = thread_graphics;
  897. graphics->exports.device_projection_push(graphics->device);
  898. }
  899. void gs_projection_pop(void)
  900. {
  901. graphics_t graphics = thread_graphics;
  902. graphics->exports.device_projection_pop(graphics->device);
  903. }
  904. void swapchain_destroy(swapchain_t swapchain)
  905. {
  906. graphics_t graphics = thread_graphics;
  907. graphics->exports.swapchain_destroy(swapchain);
  908. }
  909. void shader_destroy(shader_t shader)
  910. {
  911. graphics_t graphics = thread_graphics;
  912. graphics->exports.shader_destroy(shader);
  913. }
  914. int shader_numparams(shader_t shader)
  915. {
  916. graphics_t graphics = thread_graphics;
  917. return graphics->exports.shader_numparams(shader);
  918. }
  919. sparam_t shader_getparambyidx(shader_t shader, int param)
  920. {
  921. graphics_t graphics = thread_graphics;
  922. return graphics->exports.shader_getparambyidx(shader, param);
  923. }
  924. sparam_t shader_getparambyname(shader_t shader, const char *name)
  925. {
  926. graphics_t graphics = thread_graphics;
  927. return graphics->exports.shader_getparambyname(shader, name);
  928. }
  929. void shader_getparaminfo(shader_t shader, sparam_t param,
  930. struct shader_param_info *info)
  931. {
  932. graphics_t graphics = thread_graphics;
  933. graphics->exports.shader_getparaminfo(shader, param, info);
  934. }
  935. sparam_t shader_getviewprojmatrix(shader_t shader)
  936. {
  937. graphics_t graphics = thread_graphics;
  938. return graphics->exports.shader_getviewprojmatrix(shader);
  939. }
  940. sparam_t shader_getworldmatrix(shader_t shader)
  941. {
  942. graphics_t graphics = thread_graphics;
  943. return graphics->exports.shader_getworldmatrix(shader);
  944. }
  945. void shader_setbool(shader_t shader, sparam_t param, bool val)
  946. {
  947. graphics_t graphics = thread_graphics;
  948. graphics->exports.shader_setbool(shader, param, val);
  949. }
  950. void shader_setfloat(shader_t shader, sparam_t param, float val)
  951. {
  952. graphics_t graphics = thread_graphics;
  953. graphics->exports.shader_setfloat(shader, param, val);
  954. }
  955. void shader_setint(shader_t shader, sparam_t param, int val)
  956. {
  957. graphics_t graphics = thread_graphics;
  958. graphics->exports.shader_setint(shader, param, val);
  959. }
  960. void shader_setmatrix3(shader_t shader, sparam_t param,
  961. const struct matrix3 *val)
  962. {
  963. graphics_t graphics = thread_graphics;
  964. graphics->exports.shader_setmatrix3(shader, param, val);
  965. }
  966. void shader_setmatrix4(shader_t shader, sparam_t param,
  967. const struct matrix4 *val)
  968. {
  969. graphics_t graphics = thread_graphics;
  970. graphics->exports.shader_setmatrix4(shader, param, val);
  971. }
  972. void shader_setvec2(shader_t shader, sparam_t param,
  973. const struct vec2 *val)
  974. {
  975. graphics_t graphics = thread_graphics;
  976. graphics->exports.shader_setvec2(shader, param, val);
  977. }
  978. void shader_setvec3(shader_t shader, sparam_t param,
  979. const struct vec3 *val)
  980. {
  981. graphics_t graphics = thread_graphics;
  982. graphics->exports.shader_setvec3(shader, param, val);
  983. }
  984. void shader_setvec4(shader_t shader, sparam_t param,
  985. const struct vec4 *val)
  986. {
  987. graphics_t graphics = thread_graphics;
  988. graphics->exports.shader_setvec4(shader, param, val);
  989. }
  990. void shader_settexture(shader_t shader, sparam_t param, texture_t val)
  991. {
  992. graphics_t graphics = thread_graphics;
  993. graphics->exports.shader_settexture(shader, param, val);
  994. }
  995. void shader_setval(shader_t shader, sparam_t param, const void *val,
  996. size_t size)
  997. {
  998. graphics_t graphics = thread_graphics;
  999. graphics->exports.shader_setval(shader, param, val, size);
  1000. }
  1001. void shader_setdefault(shader_t shader, sparam_t param)
  1002. {
  1003. graphics_t graphics = thread_graphics;
  1004. graphics->exports.shader_setdefault(shader, param);
  1005. }
  1006. void texture_destroy(texture_t tex)
  1007. {
  1008. graphics_t graphics = thread_graphics;
  1009. graphics->exports.texture_destroy(tex);
  1010. }
  1011. uint32_t texture_getwidth(texture_t tex)
  1012. {
  1013. graphics_t graphics = thread_graphics;
  1014. return graphics->exports.texture_getwidth(tex);
  1015. }
  1016. uint32_t texture_getheight(texture_t tex)
  1017. {
  1018. graphics_t graphics = thread_graphics;
  1019. return graphics->exports.texture_getheight(tex);
  1020. }
  1021. enum gs_color_format texture_getcolorformat(texture_t tex)
  1022. {
  1023. graphics_t graphics = thread_graphics;
  1024. return graphics->exports.texture_getcolorformat(tex);
  1025. }
  1026. bool texture_map(texture_t tex, void **ptr, uint32_t *byte_width)
  1027. {
  1028. graphics_t graphics = thread_graphics;
  1029. return graphics->exports.texture_map(tex, ptr, byte_width);
  1030. }
  1031. void texture_unmap(texture_t tex)
  1032. {
  1033. graphics_t graphics = thread_graphics;
  1034. graphics->exports.texture_unmap(tex);
  1035. }
  1036. void cubetexture_destroy(texture_t cubetex)
  1037. {
  1038. graphics_t graphics = thread_graphics;
  1039. graphics->exports.cubetexture_destroy(cubetex);
  1040. }
  1041. uint32_t cubetexture_getsize(texture_t cubetex)
  1042. {
  1043. graphics_t graphics = thread_graphics;
  1044. return graphics->exports.cubetexture_getsize(cubetex);
  1045. }
  1046. enum gs_color_format cubetexture_getcolorformat(texture_t cubetex)
  1047. {
  1048. graphics_t graphics = thread_graphics;
  1049. return graphics->exports.cubetexture_getcolorformat(cubetex);
  1050. }
  1051. void volumetexture_destroy(texture_t voltex)
  1052. {
  1053. graphics_t graphics = thread_graphics;
  1054. graphics->exports.volumetexture_destroy(voltex);
  1055. }
  1056. uint32_t volumetexture_getwidth(texture_t voltex)
  1057. {
  1058. graphics_t graphics = thread_graphics;
  1059. return graphics->exports.volumetexture_getwidth(voltex);
  1060. }
  1061. uint32_t volumetexture_getheight(texture_t voltex)
  1062. {
  1063. graphics_t graphics = thread_graphics;
  1064. return graphics->exports.volumetexture_getheight(voltex);
  1065. }
  1066. uint32_t volumetexture_getdepth(texture_t voltex)
  1067. {
  1068. graphics_t graphics = thread_graphics;
  1069. return graphics->exports.volumetexture_getdepth(voltex);
  1070. }
  1071. enum gs_color_format volumetexture_getcolorformat(texture_t voltex)
  1072. {
  1073. graphics_t graphics = thread_graphics;
  1074. return graphics->exports.volumetexture_getcolorformat(voltex);
  1075. }
  1076. void stagesurface_destroy(stagesurf_t stagesurf)
  1077. {
  1078. graphics_t graphics = thread_graphics;
  1079. graphics->exports.stagesurface_destroy(stagesurf);
  1080. }
  1081. uint32_t stagesurface_getwidth(stagesurf_t stagesurf)
  1082. {
  1083. graphics_t graphics = thread_graphics;
  1084. return graphics->exports.stagesurface_getwidth(stagesurf);
  1085. }
  1086. uint32_t stagesurface_getheight(stagesurf_t stagesurf)
  1087. {
  1088. graphics_t graphics = thread_graphics;
  1089. return graphics->exports.stagesurface_getheight(stagesurf);
  1090. }
  1091. enum gs_color_format stagesurface_getcolorformat(stagesurf_t stagesurf)
  1092. {
  1093. graphics_t graphics = thread_graphics;
  1094. return graphics->exports.stagesurface_getcolorformat(stagesurf);
  1095. }
  1096. bool stagesurface_map(stagesurf_t stagesurf, const void **data,
  1097. uint32_t *byte_width)
  1098. {
  1099. graphics_t graphics = thread_graphics;
  1100. return graphics->exports.stagesurface_map(stagesurf, data, byte_width);
  1101. }
  1102. void stagesurface_unmap(stagesurf_t stagesurf)
  1103. {
  1104. graphics_t graphics = thread_graphics;
  1105. graphics->exports.stagesurface_unmap(stagesurf);
  1106. }
  1107. void zstencil_destroy(zstencil_t zstencil)
  1108. {
  1109. thread_graphics->exports.zstencil_destroy(zstencil);
  1110. }
  1111. void samplerstate_destroy(samplerstate_t samplerstate)
  1112. {
  1113. thread_graphics->exports.samplerstate_destroy(samplerstate);
  1114. }
  1115. void vertexbuffer_destroy(vertbuffer_t vertbuffer)
  1116. {
  1117. graphics_t graphics = thread_graphics;
  1118. graphics->exports.vertexbuffer_destroy(vertbuffer);
  1119. }
  1120. void vertexbuffer_flush(vertbuffer_t vertbuffer, bool rebuild)
  1121. {
  1122. thread_graphics->exports.vertexbuffer_flush(vertbuffer, rebuild);
  1123. }
  1124. struct vb_data *vertexbuffer_getdata(vertbuffer_t vertbuffer)
  1125. {
  1126. return thread_graphics->exports.vertexbuffer_getdata(vertbuffer);
  1127. }
  1128. void indexbuffer_destroy(indexbuffer_t indexbuffer)
  1129. {
  1130. graphics_t graphics = thread_graphics;
  1131. graphics->exports.indexbuffer_destroy(indexbuffer);
  1132. }
  1133. void indexbuffer_flush(indexbuffer_t indexbuffer)
  1134. {
  1135. thread_graphics->exports.indexbuffer_flush(indexbuffer);
  1136. }
  1137. void *indexbuffer_getdata(indexbuffer_t indexbuffer)
  1138. {
  1139. return thread_graphics->exports.indexbuffer_getdata(indexbuffer);
  1140. }
  1141. size_t indexbuffer_numindices(indexbuffer_t indexbuffer)
  1142. {
  1143. return thread_graphics->exports.indexbuffer_numindices(indexbuffer);
  1144. }
  1145. enum gs_index_type indexbuffer_gettype(indexbuffer_t indexbuffer)
  1146. {
  1147. return thread_graphics->exports.indexbuffer_gettype(indexbuffer);
  1148. }