graphics.c 37 KB

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