gl-subsystem.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Copyright (C) 2014 by Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #include <graphics/matrix3.h>
  16. #include "gl-subsystem.h"
  17. /* Goofy Windows.h macros need to be removed */
  18. #undef far
  19. #undef near
  20. /* #define SHOW_ALL_GL_MESSAGES */
  21. #ifdef _DEBUG
  22. static void APIENTRY gl_debug_proc(
  23. GLenum source, GLenum type, GLuint id, GLenum severity,
  24. GLsizei length, const GLchar *message, const GLvoid *data )
  25. {
  26. UNUSED_PARAMETER(id);
  27. UNUSED_PARAMETER(data);
  28. char *source_str, *type_str, *severity_str;
  29. /* frames can get a bit too much spam with irrelevant/insignificant opengl
  30. * debug messages */
  31. #ifndef SHOW_ALL_GL_MESSAGES
  32. if (type > GL_DEBUG_TYPE_PORTABILITY &&
  33. severity != GL_DEBUG_SEVERITY_HIGH) {
  34. return;
  35. }
  36. #endif
  37. switch(source) {
  38. case GL_DEBUG_SOURCE_API:
  39. source_str = "API"; break;
  40. case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
  41. source_str = "Window System"; break;
  42. case GL_DEBUG_SOURCE_SHADER_COMPILER:
  43. source_str = "Shader Compiler"; break;
  44. case GL_DEBUG_SOURCE_THIRD_PARTY:
  45. source_str = "Third Party"; break;
  46. case GL_DEBUG_SOURCE_APPLICATION:
  47. source_str = "Application"; break;
  48. case GL_DEBUG_SOURCE_OTHER:
  49. source_str = "Other"; break;
  50. default:
  51. source_str = "Unknown";
  52. }
  53. switch(type) {
  54. case GL_DEBUG_TYPE_ERROR:
  55. type_str = "Error"; break;
  56. case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
  57. type_str = "Deprecated Behavior"; break;
  58. case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
  59. type_str = "Undefined Behavior"; break;
  60. case GL_DEBUG_TYPE_PORTABILITY:
  61. type_str = "Portability"; break;
  62. case GL_DEBUG_TYPE_PERFORMANCE:
  63. type_str = "Performance"; break;
  64. case GL_DEBUG_TYPE_OTHER:
  65. type_str = "Other"; break;
  66. default:
  67. type_str = "Unknown";
  68. }
  69. switch(severity) {
  70. case GL_DEBUG_SEVERITY_HIGH:
  71. severity_str = "High"; break;
  72. case GL_DEBUG_SEVERITY_MEDIUM:
  73. severity_str = "Medium"; break;
  74. case GL_DEBUG_SEVERITY_LOW:
  75. severity_str = "Low"; break;
  76. case GL_DEBUG_SEVERITY_NOTIFICATION:
  77. severity_str = "Notification"; break;
  78. default:
  79. severity_str = "Unknown";
  80. }
  81. blog(LOG_DEBUG,
  82. "[%s][%s]{%s}: %.*s",
  83. source_str, type_str, severity_str,
  84. length, message
  85. );
  86. }
  87. static void gl_enable_debug()
  88. {
  89. if (GLAD_GL_VERSION_4_3) {
  90. glDebugMessageCallback(gl_debug_proc, NULL);
  91. gl_enable(GL_DEBUG_OUTPUT);
  92. } else if (GLAD_GL_ARB_debug_output) {
  93. glDebugMessageCallbackARB(gl_debug_proc, NULL);
  94. } else {
  95. blog(LOG_DEBUG, "Failed to set GL debug callback as it is "
  96. "not supported.");
  97. }
  98. }
  99. #else
  100. static void gl_enable_debug() {}
  101. #endif
  102. static bool gl_init_extensions(struct gs_device* device)
  103. {
  104. if (!GLAD_GL_VERSION_2_1) {
  105. blog(LOG_ERROR, "obs-studio requires OpenGL version 2.1 or "
  106. "higher.");
  107. return false;
  108. }
  109. gl_enable_debug();
  110. if (!GLAD_GL_VERSION_3_0 && !GLAD_GL_ARB_framebuffer_object) {
  111. blog(LOG_ERROR, "OpenGL extension ARB_framebuffer_object "
  112. "is required.");
  113. return false;
  114. }
  115. if (GLAD_GL_VERSION_3_2 || GLAD_GL_ARB_seamless_cube_map) {
  116. gl_enable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
  117. }
  118. if (GLAD_GL_VERSION_4_3 || GLAD_GL_ARB_copy_image)
  119. device->copy_type = COPY_TYPE_ARB;
  120. else if (GLAD_GL_NV_copy_image)
  121. device->copy_type = COPY_TYPE_NV;
  122. else
  123. device->copy_type = COPY_TYPE_FBO_BLIT;
  124. return true;
  125. }
  126. static void clear_textures(struct gs_device *device)
  127. {
  128. GLenum i;
  129. for (i = 0; i < GS_MAX_TEXTURES; i++) {
  130. if (device->cur_textures[i]) {
  131. gl_active_texture(GL_TEXTURE0 + i);
  132. gl_bind_texture(device->cur_textures[i]->gl_target, 0);
  133. device->cur_textures[i] = NULL;
  134. }
  135. }
  136. }
  137. void convert_sampler_info(struct gs_sampler_state *sampler,
  138. const struct gs_sampler_info *info)
  139. {
  140. GLint max_anisotropy_max;
  141. convert_filter(info->filter, &sampler->min_filter,
  142. &sampler->mag_filter);
  143. sampler->address_u = convert_address_mode(info->address_u);
  144. sampler->address_v = convert_address_mode(info->address_v);
  145. sampler->address_w = convert_address_mode(info->address_w);
  146. sampler->max_anisotropy = info->max_anisotropy;
  147. max_anisotropy_max = 1;
  148. glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy_max);
  149. gl_success("glGetIntegerv(GL_MAX_TEXTURE_ANISOTROPY_MAX)");
  150. if (1 <= sampler->max_anisotropy &&
  151. sampler->max_anisotropy <= max_anisotropy_max)
  152. return;
  153. if (sampler->max_anisotropy < 1)
  154. sampler->max_anisotropy = 1;
  155. else if (sampler->max_anisotropy > max_anisotropy_max)
  156. sampler->max_anisotropy = max_anisotropy_max;
  157. blog(LOG_DEBUG, "convert_sampler_info: 1 <= max_anisotropy <= "
  158. "%d violated, selected: %d, set: %d",
  159. max_anisotropy_max,
  160. info->max_anisotropy, sampler->max_anisotropy);
  161. }
  162. const char *device_get_name(void)
  163. {
  164. return "OpenGL";
  165. }
  166. int device_get_type(void)
  167. {
  168. return GS_DEVICE_OPENGL;
  169. }
  170. const char *device_preprocessor_name(void)
  171. {
  172. return "_OPENGL";
  173. }
  174. int device_create(gs_device_t **p_device, uint32_t adapter)
  175. {
  176. struct gs_device *device = bzalloc(sizeof(struct gs_device));
  177. int errorcode = GS_ERROR_FAIL;
  178. blog(LOG_INFO, "---------------------------------");
  179. blog(LOG_INFO, "Initializing OpenGL...");
  180. device->plat = gl_platform_create(device, adapter);
  181. if (!device->plat)
  182. goto fail;
  183. if (!gl_init_extensions(device)) {
  184. errorcode = GS_ERROR_NOT_SUPPORTED;
  185. goto fail;
  186. }
  187. blog(LOG_INFO, "OpenGL version: %s", glGetString(GL_VERSION));
  188. gl_enable(GL_CULL_FACE);
  189. device_leave_context(device);
  190. device->cur_swap = NULL;
  191. #ifdef _WIN32
  192. blog(LOG_INFO, "Warning: The OpenGL renderer is currently in use. "
  193. "On windows, the OpenGL renderer can decrease "
  194. "capture performance due to the lack of specific "
  195. "features used to maximize capture performance. "
  196. "The Direct3D 11 renderer is recommended instead.");
  197. #endif
  198. *p_device = device;
  199. return GS_SUCCESS;
  200. fail:
  201. blog(LOG_ERROR, "device_create (GL) failed");
  202. bfree(device);
  203. *p_device = NULL;
  204. return errorcode;
  205. }
  206. void device_destroy(gs_device_t *device)
  207. {
  208. if (device) {
  209. size_t i;
  210. for (i = 0; i < device->fbos.num; i++)
  211. fbo_info_destroy(device->fbos.array[i]);
  212. while (device->first_program)
  213. gs_program_destroy(device->first_program);
  214. da_free(device->proj_stack);
  215. da_free(device->fbos);
  216. gl_platform_destroy(device->plat);
  217. bfree(device);
  218. }
  219. }
  220. gs_swapchain_t *device_swapchain_create(gs_device_t *device,
  221. const struct gs_init_data *info)
  222. {
  223. struct gs_swap_chain *swap = bzalloc(sizeof(struct gs_swap_chain));
  224. swap->device = device;
  225. swap->info = *info;
  226. swap->wi = gl_windowinfo_create(info);
  227. if (!swap->wi) {
  228. blog(LOG_ERROR, "device_swapchain_create (GL) failed");
  229. gs_swapchain_destroy(swap);
  230. return NULL;
  231. }
  232. if (!gl_platform_init_swapchain(swap)) {
  233. blog(LOG_ERROR, "gl_platform_init_swapchain failed");
  234. gs_swapchain_destroy(swap);
  235. return NULL;
  236. }
  237. return swap;
  238. }
  239. void device_resize(gs_device_t *device, uint32_t cx, uint32_t cy)
  240. {
  241. /* GL automatically resizes the device, so it doesn't do much */
  242. if (device->cur_swap) {
  243. device->cur_swap->info.cx = cx;
  244. device->cur_swap->info.cy = cy;
  245. } else {
  246. blog(LOG_WARNING, "device_resize (GL): No active swap");
  247. }
  248. gl_update(device);
  249. }
  250. void device_get_size(const gs_device_t *device, uint32_t *cx, uint32_t *cy)
  251. {
  252. if (device->cur_swap) {
  253. *cx = device->cur_swap->info.cx;
  254. *cy = device->cur_swap->info.cy;
  255. } else {
  256. blog(LOG_WARNING, "device_get_size (GL): No active swap");
  257. *cx = 0;
  258. *cy = 0;
  259. }
  260. }
  261. uint32_t device_get_width(const gs_device_t *device)
  262. {
  263. if (device->cur_swap) {
  264. return device->cur_swap->info.cx;
  265. } else {
  266. blog(LOG_WARNING, "device_get_width (GL): No active swap");
  267. return 0;
  268. }
  269. }
  270. uint32_t device_get_height(const gs_device_t *device)
  271. {
  272. if (device->cur_swap) {
  273. return device->cur_swap->info.cy;
  274. } else {
  275. blog(LOG_WARNING, "device_get_height (GL): No active swap");
  276. return 0;
  277. }
  278. }
  279. gs_texture_t *device_voltexture_create(gs_device_t *device, uint32_t width,
  280. uint32_t height, uint32_t depth,
  281. enum gs_color_format color_format, uint32_t levels,
  282. const uint8_t **data, uint32_t flags)
  283. {
  284. /* TODO */
  285. UNUSED_PARAMETER(device);
  286. UNUSED_PARAMETER(width);
  287. UNUSED_PARAMETER(height);
  288. UNUSED_PARAMETER(depth);
  289. UNUSED_PARAMETER(color_format);
  290. UNUSED_PARAMETER(levels);
  291. UNUSED_PARAMETER(data);
  292. UNUSED_PARAMETER(flags);
  293. return NULL;
  294. }
  295. gs_samplerstate_t *device_samplerstate_create(gs_device_t *device,
  296. const struct gs_sampler_info *info)
  297. {
  298. struct gs_sampler_state *sampler;
  299. sampler = bzalloc(sizeof(struct gs_sampler_state));
  300. sampler->device = device;
  301. sampler->ref = 1;
  302. convert_sampler_info(sampler, info);
  303. return sampler;
  304. }
  305. enum gs_texture_type device_get_texture_type(const gs_texture_t *texture)
  306. {
  307. return texture->type;
  308. }
  309. static void strip_mipmap_filter(GLint *filter)
  310. {
  311. switch (*filter) {
  312. case GL_NEAREST:
  313. case GL_LINEAR:
  314. return;
  315. case GL_NEAREST_MIPMAP_NEAREST:
  316. case GL_NEAREST_MIPMAP_LINEAR:
  317. *filter = GL_NEAREST;
  318. return;
  319. case GL_LINEAR_MIPMAP_NEAREST:
  320. case GL_LINEAR_MIPMAP_LINEAR:
  321. *filter = GL_LINEAR;
  322. return;
  323. }
  324. *filter = GL_NEAREST;
  325. }
  326. static inline void apply_swizzle(struct gs_texture *tex)
  327. {
  328. if (tex->format == GS_A8) {
  329. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_R, GL_ONE);
  330. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_G, GL_ONE);
  331. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_B, GL_ONE);
  332. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_A, GL_RED);
  333. }
  334. }
  335. static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
  336. {
  337. bool success = true;
  338. GLint min_filter;
  339. if (tex->cur_sampler == ss)
  340. return true;
  341. if (tex->cur_sampler)
  342. samplerstate_release(tex->cur_sampler);
  343. tex->cur_sampler = ss;
  344. if (!ss)
  345. return true;
  346. samplerstate_addref(ss);
  347. min_filter = ss->min_filter;
  348. if (gs_texture_is_rect(tex))
  349. strip_mipmap_filter(&min_filter);
  350. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MIN_FILTER,
  351. min_filter))
  352. success = false;
  353. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAG_FILTER,
  354. ss->mag_filter))
  355. success = false;
  356. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_S, ss->address_u))
  357. success = false;
  358. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_T, ss->address_v))
  359. success = false;
  360. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_R, ss->address_w))
  361. success = false;
  362. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
  363. ss->max_anisotropy))
  364. success = false;
  365. apply_swizzle(tex);
  366. return success;
  367. }
  368. static inline struct gs_shader_param *get_texture_param(gs_device_t *device,
  369. int unit)
  370. {
  371. struct gs_shader *shader = device->cur_pixel_shader;
  372. size_t i;
  373. for (i = 0; i < shader->params.num; i++) {
  374. struct gs_shader_param *param = shader->params.array+i;
  375. if (param->type == GS_SHADER_PARAM_TEXTURE) {
  376. if (param->texture_id == unit)
  377. return param;
  378. }
  379. }
  380. return NULL;
  381. }
  382. void device_load_texture(gs_device_t *device, gs_texture_t *tex, int unit)
  383. {
  384. struct gs_shader_param *param;
  385. struct gs_sampler_state *sampler;
  386. struct gs_texture *cur_tex = device->cur_textures[unit];
  387. /* need a pixel shader to properly bind textures */
  388. if (!device->cur_pixel_shader)
  389. goto fail;
  390. if (cur_tex == tex)
  391. return;
  392. if (!gl_active_texture(GL_TEXTURE0 + unit))
  393. goto fail;
  394. /* the target for the previous text may not be the same as the
  395. * next texture, so unbind the previous texture first to be safe */
  396. if (cur_tex && (!tex || cur_tex->gl_target != tex->gl_target))
  397. gl_bind_texture(cur_tex->gl_target, 0);
  398. device->cur_textures[unit] = tex;
  399. param = get_texture_param(device, unit);
  400. if (!param)
  401. return;
  402. param->texture = tex;
  403. if (!tex)
  404. return;
  405. // texelFetch doesn't need a sampler
  406. if (param->sampler_id != (size_t)-1)
  407. sampler = device->cur_samplers[param->sampler_id];
  408. else
  409. sampler = NULL;
  410. if (!gl_bind_texture(tex->gl_target, tex->texture))
  411. goto fail;
  412. if (sampler && !load_texture_sampler(tex, sampler))
  413. goto fail;
  414. return;
  415. fail:
  416. blog(LOG_ERROR, "device_load_texture (GL) failed");
  417. }
  418. static bool load_sampler_on_textures(gs_device_t *device, gs_samplerstate_t *ss,
  419. int sampler_unit)
  420. {
  421. struct gs_shader *shader = device->cur_pixel_shader;
  422. size_t i;
  423. for (i = 0; i < shader->params.num; i++) {
  424. struct gs_shader_param *param = shader->params.array+i;
  425. if (param->type == GS_SHADER_PARAM_TEXTURE &&
  426. param->sampler_id == (uint32_t)sampler_unit &&
  427. param->texture) {
  428. if (!gl_active_texture(GL_TEXTURE0 + param->texture_id))
  429. return false;
  430. if (!load_texture_sampler(param->texture, ss))
  431. return false;
  432. }
  433. }
  434. return true;
  435. }
  436. void device_load_samplerstate(gs_device_t *device, gs_samplerstate_t *ss,
  437. int unit)
  438. {
  439. /* need a pixel shader to properly bind samplers */
  440. if (!device->cur_pixel_shader)
  441. ss = NULL;
  442. if (device->cur_samplers[unit] == ss)
  443. return;
  444. device->cur_samplers[unit] = ss;
  445. if (!ss)
  446. return;
  447. if (!load_sampler_on_textures(device, ss, unit))
  448. blog(LOG_ERROR, "device_load_samplerstate (GL) failed");
  449. return;
  450. }
  451. void device_load_vertexshader(gs_device_t *device, gs_shader_t *vertshader)
  452. {
  453. if (device->cur_vertex_shader == vertshader)
  454. return;
  455. if (vertshader && vertshader->type != GS_SHADER_VERTEX) {
  456. blog(LOG_ERROR, "Specified shader is not a vertex shader");
  457. blog(LOG_ERROR, "device_load_vertexshader (GL) failed");
  458. return;
  459. }
  460. device->cur_vertex_shader = vertshader;
  461. }
  462. static void load_default_pixelshader_samplers(struct gs_device *device,
  463. struct gs_shader *ps)
  464. {
  465. size_t i;
  466. if (!ps)
  467. return;
  468. for (i = 0; i < ps->samplers.num; i++) {
  469. struct gs_sampler_state *ss = ps->samplers.array[i];
  470. device->cur_samplers[i] = ss;
  471. }
  472. for (; i < GS_MAX_TEXTURES; i++)
  473. device->cur_samplers[i] = NULL;
  474. }
  475. void device_load_pixelshader(gs_device_t *device, gs_shader_t *pixelshader)
  476. {
  477. if (device->cur_pixel_shader == pixelshader)
  478. return;
  479. if (pixelshader && pixelshader->type != GS_SHADER_PIXEL) {
  480. blog(LOG_ERROR, "Specified shader is not a pixel shader");
  481. goto fail;
  482. }
  483. device->cur_pixel_shader = pixelshader;
  484. clear_textures(device);
  485. if (pixelshader)
  486. load_default_pixelshader_samplers(device, pixelshader);
  487. return;
  488. fail:
  489. blog(LOG_ERROR, "device_load_pixelshader (GL) failed");
  490. }
  491. void device_load_default_samplerstate(gs_device_t *device, bool b_3d, int unit)
  492. {
  493. /* TODO */
  494. UNUSED_PARAMETER(device);
  495. UNUSED_PARAMETER(b_3d);
  496. UNUSED_PARAMETER(unit);
  497. }
  498. gs_shader_t *device_get_vertex_shader(const gs_device_t *device)
  499. {
  500. return device->cur_vertex_shader;
  501. }
  502. gs_shader_t *device_get_pixel_shader(const gs_device_t *device)
  503. {
  504. return device->cur_pixel_shader;
  505. }
  506. gs_texture_t *device_get_render_target(const gs_device_t *device)
  507. {
  508. return device->cur_render_target;
  509. }
  510. gs_zstencil_t *device_get_zstencil_target(const gs_device_t *device)
  511. {
  512. return device->cur_zstencil_buffer;
  513. }
  514. static bool get_tex_dimensions(gs_texture_t *tex, uint32_t *width,
  515. uint32_t *height)
  516. {
  517. if (tex->type == GS_TEXTURE_2D) {
  518. struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
  519. *width = tex2d->width;
  520. *height = tex2d->height;
  521. return true;
  522. } else if (tex->type == GS_TEXTURE_CUBE) {
  523. struct gs_texture_cube *cube = (struct gs_texture_cube*)tex;
  524. *width = cube->size;
  525. *height = cube->size;
  526. return true;
  527. }
  528. blog(LOG_ERROR, "Texture must be 2D or cubemap");
  529. return false;
  530. }
  531. /*
  532. * This automatically manages FBOs so that render targets are always given
  533. * an FBO that matches their width/height/format to maximize optimization
  534. */
  535. struct fbo_info *get_fbo(struct gs_device *device,
  536. uint32_t width, uint32_t height, enum gs_color_format format)
  537. {
  538. size_t i;
  539. GLuint fbo;
  540. struct fbo_info *ptr;
  541. for (i = 0; i < device->fbos.num; i++) {
  542. ptr = device->fbos.array[i];
  543. if (ptr->width == width && ptr->height == height &&
  544. ptr->format == format)
  545. return ptr;
  546. }
  547. glGenFramebuffers(1, &fbo);
  548. if (!gl_success("glGenFramebuffers"))
  549. return NULL;
  550. ptr = bmalloc(sizeof(struct fbo_info));
  551. ptr->fbo = fbo;
  552. ptr->width = width;
  553. ptr->height = height;
  554. ptr->format = format;
  555. ptr->cur_render_target = NULL;
  556. ptr->cur_render_side = 0;
  557. ptr->cur_zstencil_buffer = NULL;
  558. da_push_back(device->fbos, &ptr);
  559. return ptr;
  560. }
  561. static inline struct fbo_info *get_fbo_by_tex(struct gs_device *device,
  562. gs_texture_t *tex)
  563. {
  564. uint32_t width, height;
  565. if (!get_tex_dimensions(tex, &width, &height))
  566. return NULL;
  567. return get_fbo(device, width, height, tex->format);
  568. }
  569. static bool set_current_fbo(gs_device_t *device, struct fbo_info *fbo)
  570. {
  571. if (device->cur_fbo != fbo) {
  572. GLuint fbo_obj = fbo ? fbo->fbo : 0;
  573. if (!gl_bind_framebuffer(GL_DRAW_FRAMEBUFFER, fbo_obj))
  574. return false;
  575. if (device->cur_fbo) {
  576. device->cur_fbo->cur_render_target = NULL;
  577. device->cur_fbo->cur_zstencil_buffer = NULL;
  578. }
  579. }
  580. device->cur_fbo = fbo;
  581. return true;
  582. }
  583. static bool attach_rendertarget(struct fbo_info *fbo, gs_texture_t *tex,
  584. int side)
  585. {
  586. if (fbo->cur_render_target == tex)
  587. return true;
  588. fbo->cur_render_target = tex;
  589. if (tex->type == GS_TEXTURE_2D) {
  590. glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
  591. GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
  592. tex->texture, 0);
  593. } else if (tex->type == GS_TEXTURE_CUBE) {
  594. glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
  595. GL_COLOR_ATTACHMENT0,
  596. GL_TEXTURE_CUBE_MAP_POSITIVE_X + side,
  597. tex->texture, 0);
  598. } else {
  599. return false;
  600. }
  601. return gl_success("glFramebufferTexture2D");
  602. }
  603. static bool attach_zstencil(struct fbo_info *fbo, gs_zstencil_t *zs)
  604. {
  605. GLuint zsbuffer = 0;
  606. GLenum zs_attachment = GL_DEPTH_STENCIL_ATTACHMENT;
  607. if (fbo->cur_zstencil_buffer == zs)
  608. return true;
  609. fbo->cur_zstencil_buffer = zs;
  610. if (zs) {
  611. zsbuffer = zs->buffer;
  612. zs_attachment = zs->attachment;
  613. }
  614. glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,
  615. zs_attachment, GL_RENDERBUFFER, zsbuffer);
  616. if (!gl_success("glFramebufferRenderbuffer"))
  617. return false;
  618. return true;
  619. }
  620. static bool set_target(gs_device_t *device, gs_texture_t *tex, int side,
  621. gs_zstencil_t *zs)
  622. {
  623. struct fbo_info *fbo;
  624. if (device->cur_render_target == tex &&
  625. device->cur_zstencil_buffer == zs &&
  626. device->cur_render_side == side)
  627. return true;
  628. device->cur_render_target = tex;
  629. device->cur_render_side = side;
  630. device->cur_zstencil_buffer = zs;
  631. if (!tex)
  632. return set_current_fbo(device, NULL);
  633. fbo = get_fbo_by_tex(device, tex);
  634. if (!fbo)
  635. return false;
  636. set_current_fbo(device, fbo);
  637. if (!attach_rendertarget(fbo, tex, side))
  638. return false;
  639. if (!attach_zstencil(fbo, zs))
  640. return false;
  641. return true;
  642. }
  643. void device_set_render_target(gs_device_t *device, gs_texture_t *tex,
  644. gs_zstencil_t *zstencil)
  645. {
  646. if (tex) {
  647. if (tex->type != GS_TEXTURE_2D) {
  648. blog(LOG_ERROR, "Texture is not a 2D texture");
  649. goto fail;
  650. }
  651. if (!tex->is_render_target) {
  652. blog(LOG_ERROR, "Texture is not a render target");
  653. goto fail;
  654. }
  655. }
  656. if (!set_target(device, tex, 0, zstencil))
  657. goto fail;
  658. return;
  659. fail:
  660. blog(LOG_ERROR, "device_set_render_target (GL) failed");
  661. }
  662. void device_set_cube_render_target(gs_device_t *device, gs_texture_t *cubetex,
  663. int side, gs_zstencil_t *zstencil)
  664. {
  665. if (cubetex) {
  666. if (cubetex->type != GS_TEXTURE_CUBE) {
  667. blog(LOG_ERROR, "Texture is not a cube texture");
  668. goto fail;
  669. }
  670. if (!cubetex->is_render_target) {
  671. blog(LOG_ERROR, "Texture is not a render target");
  672. goto fail;
  673. }
  674. }
  675. if (!set_target(device, cubetex, side, zstencil))
  676. goto fail;
  677. return;
  678. fail:
  679. blog(LOG_ERROR, "device_set_cube_render_target (GL) failed");
  680. }
  681. void device_copy_texture_region(gs_device_t *device,
  682. gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
  683. gs_texture_t *src, uint32_t src_x, uint32_t src_y,
  684. uint32_t src_w, uint32_t src_h)
  685. {
  686. struct gs_texture_2d *src2d = (struct gs_texture_2d*)src;
  687. struct gs_texture_2d *dst2d = (struct gs_texture_2d*)dst;
  688. if (!src) {
  689. blog(LOG_ERROR, "Source texture is NULL");
  690. goto fail;
  691. }
  692. if (!dst) {
  693. blog(LOG_ERROR, "Destination texture is NULL");
  694. goto fail;
  695. }
  696. if (dst->type != GS_TEXTURE_2D || src->type != GS_TEXTURE_2D) {
  697. blog(LOG_ERROR, "Source and destination textures must be 2D "
  698. "textures");
  699. goto fail;
  700. }
  701. if (dst->format != src->format) {
  702. blog(LOG_ERROR, "Source and destination formats do not match");
  703. goto fail;
  704. }
  705. uint32_t nw = (uint32_t)src_w ?
  706. (uint32_t)src_w : (src2d->width - src_x);
  707. uint32_t nh = (uint32_t)src_h ?
  708. (uint32_t)src_h : (src2d->height - src_y);
  709. if (dst2d->width - dst_x < nw || dst2d->height - dst_y < nh) {
  710. blog(LOG_ERROR, "Destination texture region is not big "
  711. "enough to hold the source region");
  712. goto fail;
  713. }
  714. if (!gl_copy_texture(device, dst->texture, dst->gl_target, dst_x, dst_y,
  715. src->texture, src->gl_target, src_x, src_y,
  716. nw, nh, src->format))
  717. goto fail;
  718. return;
  719. fail:
  720. blog(LOG_ERROR, "device_copy_texture (GL) failed");
  721. }
  722. void device_copy_texture(gs_device_t *device, gs_texture_t *dst,
  723. gs_texture_t *src)
  724. {
  725. device_copy_texture_region(device, dst, 0, 0, src, 0, 0, 0, 0);
  726. }
  727. void device_begin_scene(gs_device_t *device)
  728. {
  729. clear_textures(device);
  730. }
  731. static inline bool can_render(const gs_device_t *device)
  732. {
  733. if (!device->cur_vertex_shader) {
  734. blog(LOG_ERROR, "No vertex shader specified");
  735. return false;
  736. }
  737. if (!device->cur_pixel_shader) {
  738. blog(LOG_ERROR, "No pixel shader specified");
  739. return false;
  740. }
  741. if (!device->cur_vertex_buffer) {
  742. blog(LOG_ERROR, "No vertex buffer specified");
  743. return false;
  744. }
  745. if (!device->cur_swap && !device->cur_render_target) {
  746. blog(LOG_ERROR, "No active swap chain or render target");
  747. return false;
  748. }
  749. return true;
  750. }
  751. static void update_viewproj_matrix(struct gs_device *device)
  752. {
  753. struct gs_shader *vs = device->cur_vertex_shader;
  754. struct matrix4 cur_proj;
  755. gs_matrix_get(&device->cur_view);
  756. matrix4_copy(&cur_proj, &device->cur_proj);
  757. if (device->cur_fbo) {
  758. cur_proj.x.y = -cur_proj.x.y;
  759. cur_proj.y.y = -cur_proj.y.y;
  760. cur_proj.z.y = -cur_proj.z.y;
  761. cur_proj.t.y = -cur_proj.t.y;
  762. glFrontFace(GL_CW);
  763. } else {
  764. glFrontFace(GL_CCW);
  765. }
  766. gl_success("glFrontFace");
  767. matrix4_mul(&device->cur_viewproj, &device->cur_view, &cur_proj);
  768. matrix4_transpose(&device->cur_viewproj, &device->cur_viewproj);
  769. if (vs->viewproj)
  770. gs_shader_set_matrix4(vs->viewproj, &device->cur_viewproj);
  771. }
  772. static inline struct gs_program *find_program(const struct gs_device *device)
  773. {
  774. struct gs_program *program = device->first_program;
  775. while (program) {
  776. if (program->vertex_shader == device->cur_vertex_shader &&
  777. program->pixel_shader == device->cur_pixel_shader)
  778. return program;
  779. program = program->next;
  780. }
  781. return NULL;
  782. }
  783. static inline struct gs_program *get_shader_program(struct gs_device *device)
  784. {
  785. struct gs_program *program = find_program(device);
  786. if (!program)
  787. program = gs_program_create(device);
  788. return program;
  789. }
  790. void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
  791. uint32_t start_vert, uint32_t num_verts)
  792. {
  793. struct gs_index_buffer *ib = device->cur_index_buffer;
  794. GLenum topology = convert_gs_topology(draw_mode);
  795. gs_effect_t *effect = gs_get_effect();
  796. struct gs_program *program;
  797. if (!can_render(device))
  798. goto fail;
  799. if (effect)
  800. gs_effect_update_params(effect);
  801. program = get_shader_program(device);
  802. if (!program)
  803. goto fail;
  804. load_vb_buffers(program, device->cur_vertex_buffer, ib);
  805. if (program != device->cur_program && device->cur_program) {
  806. glUseProgram(0);
  807. gl_success("glUseProgram (zero)");
  808. }
  809. if (program != device->cur_program) {
  810. device->cur_program = program;
  811. glUseProgram(program->obj);
  812. if (!gl_success("glUseProgram"))
  813. goto fail;
  814. }
  815. update_viewproj_matrix(device);
  816. program_update_params(program);
  817. if (ib) {
  818. if (num_verts == 0)
  819. num_verts = (uint32_t)device->cur_index_buffer->num;
  820. glDrawElements(topology, num_verts, ib->gl_type,
  821. (const GLvoid*)(start_vert * ib->width));
  822. if (!gl_success("glDrawElements"))
  823. goto fail;
  824. } else {
  825. if (num_verts == 0)
  826. num_verts = (uint32_t)device->cur_vertex_buffer->num;
  827. glDrawArrays(topology, start_vert, num_verts);
  828. if (!gl_success("glDrawArrays"))
  829. goto fail;
  830. }
  831. return;
  832. fail:
  833. blog(LOG_ERROR, "device_draw (GL) failed");
  834. }
  835. void device_end_scene(gs_device_t *device)
  836. {
  837. /* does nothing */
  838. UNUSED_PARAMETER(device);
  839. }
  840. void device_clear(gs_device_t *device, uint32_t clear_flags,
  841. const struct vec4 *color, float depth, uint8_t stencil)
  842. {
  843. GLbitfield gl_flags = 0;
  844. if (clear_flags & GS_CLEAR_COLOR) {
  845. glClearColor(color->x, color->y, color->z, color->w);
  846. gl_flags |= GL_COLOR_BUFFER_BIT;
  847. }
  848. if (clear_flags & GS_CLEAR_DEPTH) {
  849. glClearDepth(depth);
  850. gl_flags |= GL_DEPTH_BUFFER_BIT;
  851. }
  852. if (clear_flags & GS_CLEAR_STENCIL) {
  853. glClearStencil(stencil);
  854. gl_flags |= GL_STENCIL_BUFFER_BIT;
  855. }
  856. glClear(gl_flags);
  857. if (!gl_success("glClear"))
  858. blog(LOG_ERROR, "device_clear (GL) failed");
  859. UNUSED_PARAMETER(device);
  860. }
  861. void device_flush(gs_device_t *device)
  862. {
  863. #ifdef __APPLE__
  864. if (!device->cur_swap)
  865. glFlush();
  866. #else
  867. glFlush();
  868. #endif
  869. UNUSED_PARAMETER(device);
  870. }
  871. void device_set_cull_mode(gs_device_t *device, enum gs_cull_mode mode)
  872. {
  873. if (device->cur_cull_mode == mode)
  874. return;
  875. if (device->cur_cull_mode == GS_NEITHER)
  876. gl_enable(GL_CULL_FACE);
  877. device->cur_cull_mode = mode;
  878. if (mode == GS_BACK)
  879. gl_cull_face(GL_BACK);
  880. else if (mode == GS_FRONT)
  881. gl_cull_face(GL_FRONT);
  882. else
  883. gl_disable(GL_CULL_FACE);
  884. }
  885. enum gs_cull_mode device_get_cull_mode(const gs_device_t *device)
  886. {
  887. return device->cur_cull_mode;
  888. }
  889. void device_enable_blending(gs_device_t *device, bool enable)
  890. {
  891. if (enable)
  892. gl_enable(GL_BLEND);
  893. else
  894. gl_disable(GL_BLEND);
  895. UNUSED_PARAMETER(device);
  896. }
  897. void device_enable_depth_test(gs_device_t *device, bool enable)
  898. {
  899. if (enable)
  900. gl_enable(GL_DEPTH_TEST);
  901. else
  902. gl_disable(GL_DEPTH_TEST);
  903. UNUSED_PARAMETER(device);
  904. }
  905. void device_enable_stencil_test(gs_device_t *device, bool enable)
  906. {
  907. if (enable)
  908. gl_enable(GL_STENCIL_TEST);
  909. else
  910. gl_disable(GL_STENCIL_TEST);
  911. UNUSED_PARAMETER(device);
  912. }
  913. void device_enable_stencil_write(gs_device_t *device, bool enable)
  914. {
  915. if (enable)
  916. glStencilMask(0xFFFFFFFF);
  917. else
  918. glStencilMask(0);
  919. UNUSED_PARAMETER(device);
  920. }
  921. void device_enable_color(gs_device_t *device, bool red, bool green,
  922. bool blue, bool alpha)
  923. {
  924. glColorMask(red, green, blue, alpha);
  925. UNUSED_PARAMETER(device);
  926. }
  927. void device_blend_function(gs_device_t *device, enum gs_blend_type src,
  928. enum gs_blend_type dest)
  929. {
  930. GLenum gl_src = convert_gs_blend_type(src);
  931. GLenum gl_dst = convert_gs_blend_type(dest);
  932. glBlendFunc(gl_src, gl_dst);
  933. if (!gl_success("glBlendFunc"))
  934. blog(LOG_ERROR, "device_blend_function (GL) failed");
  935. UNUSED_PARAMETER(device);
  936. }
  937. void device_blend_function_separate(gs_device_t *device,
  938. enum gs_blend_type src_c, enum gs_blend_type dest_c,
  939. enum gs_blend_type src_a, enum gs_blend_type dest_a)
  940. {
  941. GLenum gl_src_c = convert_gs_blend_type(src_c);
  942. GLenum gl_dst_c = convert_gs_blend_type(dest_c);
  943. GLenum gl_src_a = convert_gs_blend_type(src_a);
  944. GLenum gl_dst_a = convert_gs_blend_type(dest_a);
  945. glBlendFuncSeparate(gl_src_c, gl_dst_c, gl_src_a, gl_dst_a);
  946. if (!gl_success("glBlendFuncSeparate"))
  947. blog(LOG_ERROR, "device_blend_function_separate (GL) failed");
  948. UNUSED_PARAMETER(device);
  949. }
  950. void device_depth_function(gs_device_t *device, enum gs_depth_test test)
  951. {
  952. GLenum gl_test = convert_gs_depth_test(test);
  953. glDepthFunc(gl_test);
  954. if (!gl_success("glDepthFunc"))
  955. blog(LOG_ERROR, "device_depth_function (GL) failed");
  956. UNUSED_PARAMETER(device);
  957. }
  958. void device_stencil_function(gs_device_t *device, enum gs_stencil_side side,
  959. enum gs_depth_test test)
  960. {
  961. GLenum gl_side = convert_gs_stencil_side(side);
  962. GLenum gl_test = convert_gs_depth_test(test);
  963. glStencilFuncSeparate(gl_side, gl_test, 0, 0xFFFFFFFF);
  964. if (!gl_success("glStencilFuncSeparate"))
  965. blog(LOG_ERROR, "device_stencil_function (GL) failed");
  966. UNUSED_PARAMETER(device);
  967. }
  968. void device_stencil_op(gs_device_t *device, enum gs_stencil_side side,
  969. enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail,
  970. enum gs_stencil_op_type zpass)
  971. {
  972. GLenum gl_side = convert_gs_stencil_side(side);
  973. GLenum gl_fail = convert_gs_stencil_op(fail);
  974. GLenum gl_zfail = convert_gs_stencil_op(zfail);
  975. GLenum gl_zpass = convert_gs_stencil_op(zpass);
  976. glStencilOpSeparate(gl_side, gl_fail, gl_zfail, gl_zpass);
  977. if (!gl_success("glStencilOpSeparate"))
  978. blog(LOG_ERROR, "device_stencil_op (GL) failed");
  979. UNUSED_PARAMETER(device);
  980. }
  981. static inline uint32_t get_target_height(const struct gs_device *device)
  982. {
  983. if (!device->cur_render_target)
  984. return device_get_height(device);
  985. if (device->cur_render_target->type == GS_TEXTURE_2D)
  986. return gs_texture_get_height(device->cur_render_target);
  987. else /* cube map */
  988. return gs_cubetexture_get_size(device->cur_render_target);
  989. }
  990. void device_set_viewport(gs_device_t *device, int x, int y, int width,
  991. int height)
  992. {
  993. uint32_t base_height;
  994. /* GL uses bottom-up coordinates for viewports. We want top-down */
  995. if (device->cur_render_target) {
  996. base_height = get_target_height(device);
  997. } else {
  998. uint32_t dw;
  999. gl_getclientsize(device->cur_swap, &dw, &base_height);
  1000. }
  1001. glViewport(x, base_height - y - height, width, height);
  1002. if (!gl_success("glViewport"))
  1003. blog(LOG_ERROR, "device_set_viewport (GL) failed");
  1004. device->cur_viewport.x = x;
  1005. device->cur_viewport.y = y;
  1006. device->cur_viewport.cx = width;
  1007. device->cur_viewport.cy = height;
  1008. }
  1009. void device_get_viewport(const gs_device_t *device, struct gs_rect *rect)
  1010. {
  1011. *rect = device->cur_viewport;
  1012. }
  1013. void device_set_scissor_rect(gs_device_t *device, const struct gs_rect *rect)
  1014. {
  1015. UNUSED_PARAMETER(device);
  1016. if (rect != NULL) {
  1017. glScissor(rect->x, rect->y, rect->cx, rect->cy);
  1018. if (gl_success("glScissor") && gl_enable(GL_SCISSOR_TEST))
  1019. return;
  1020. } else if (gl_disable(GL_SCISSOR_TEST)) {
  1021. return;
  1022. }
  1023. blog(LOG_ERROR, "device_set_scissor_rect (GL) failed");
  1024. }
  1025. void device_ortho(gs_device_t *device, float left, float right,
  1026. float top, float bottom, float near, float far)
  1027. {
  1028. struct matrix4 *dst = &device->cur_proj;
  1029. float rml = right-left;
  1030. float bmt = bottom-top;
  1031. float fmn = far-near;
  1032. vec4_zero(&dst->x);
  1033. vec4_zero(&dst->y);
  1034. vec4_zero(&dst->z);
  1035. vec4_zero(&dst->t);
  1036. dst->x.x = 2.0f / rml;
  1037. dst->t.x = (left+right) / -rml;
  1038. dst->y.y = 2.0f / -bmt;
  1039. dst->t.y = (bottom+top) / bmt;
  1040. dst->z.z = -2.0f / fmn;
  1041. dst->t.z = (far+near) / -fmn;
  1042. dst->t.w = 1.0f;
  1043. }
  1044. void device_frustum(gs_device_t *device, float left, float right,
  1045. float top, float bottom, float near, float far)
  1046. {
  1047. struct matrix4 *dst = &device->cur_proj;
  1048. float rml = right-left;
  1049. float tmb = top-bottom;
  1050. float nmf = near-far;
  1051. float nearx2 = 2.0f*near;
  1052. vec4_zero(&dst->x);
  1053. vec4_zero(&dst->y);
  1054. vec4_zero(&dst->z);
  1055. vec4_zero(&dst->t);
  1056. dst->x.x = nearx2 / rml;
  1057. dst->z.x = (left+right) / rml;
  1058. dst->y.y = nearx2 / tmb;
  1059. dst->z.y = (bottom+top) / tmb;
  1060. dst->z.z = (far+near) / nmf;
  1061. dst->t.z = 2.0f * (near*far) / nmf;
  1062. dst->z.w = -1.0f;
  1063. }
  1064. void device_projection_push(gs_device_t *device)
  1065. {
  1066. da_push_back(device->proj_stack, &device->cur_proj);
  1067. }
  1068. void device_projection_pop(gs_device_t *device)
  1069. {
  1070. struct matrix4 *end;
  1071. if (!device->proj_stack.num)
  1072. return;
  1073. end = da_end(device->proj_stack);
  1074. device->cur_proj = *end;
  1075. da_pop_back(device->proj_stack);
  1076. }
  1077. void gs_swapchain_destroy(gs_swapchain_t *swapchain)
  1078. {
  1079. if (!swapchain)
  1080. return;
  1081. if (swapchain->device->cur_swap == swapchain)
  1082. device_load_swapchain(swapchain->device, NULL);
  1083. gl_platform_cleanup_swapchain(swapchain);
  1084. gl_windowinfo_destroy(swapchain->wi);
  1085. bfree(swapchain);
  1086. }
  1087. void gs_voltexture_destroy(gs_texture_t *voltex)
  1088. {
  1089. /* TODO */
  1090. UNUSED_PARAMETER(voltex);
  1091. }
  1092. uint32_t gs_voltexture_get_width(const gs_texture_t *voltex)
  1093. {
  1094. /* TODO */
  1095. UNUSED_PARAMETER(voltex);
  1096. return 0;
  1097. }
  1098. uint32_t gs_voltexture_get_height(const gs_texture_t *voltex)
  1099. {
  1100. /* TODO */
  1101. UNUSED_PARAMETER(voltex);
  1102. return 0;
  1103. }
  1104. uint32_t gs_voltexture_get_depth(const gs_texture_t *voltex)
  1105. {
  1106. /* TODO */
  1107. UNUSED_PARAMETER(voltex);
  1108. return 0;
  1109. }
  1110. enum gs_color_format gs_voltexture_get_color_format(const gs_texture_t *voltex)
  1111. {
  1112. /* TODO */
  1113. UNUSED_PARAMETER(voltex);
  1114. return GS_UNKNOWN;
  1115. }
  1116. void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
  1117. {
  1118. if (!samplerstate)
  1119. return;
  1120. if (samplerstate->device)
  1121. for (int i = 0; i < GS_MAX_TEXTURES; i++)
  1122. if (samplerstate->device->cur_samplers[i] ==
  1123. samplerstate)
  1124. samplerstate->device->cur_samplers[i] = NULL;
  1125. samplerstate_release(samplerstate);
  1126. }