1
0

graphics.c 37 KB

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