gl-subsystem.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. device->plat = gl_platform_create(device, adapter);
  179. if (!device->plat)
  180. goto fail;
  181. if (!gl_init_extensions(device)) {
  182. errorcode = GS_ERROR_NOT_SUPPORTED;
  183. goto fail;
  184. }
  185. gl_enable(GL_CULL_FACE);
  186. device_leave_context(device);
  187. device->cur_swap = NULL;
  188. *p_device = device;
  189. return GS_SUCCESS;
  190. fail:
  191. blog(LOG_ERROR, "device_create (GL) failed");
  192. bfree(device);
  193. *p_device = NULL;
  194. return errorcode;
  195. }
  196. void device_destroy(gs_device_t *device)
  197. {
  198. if (device) {
  199. size_t i;
  200. for (i = 0; i < device->fbos.num; i++)
  201. fbo_info_destroy(device->fbos.array[i]);
  202. while (device->first_program)
  203. gs_program_destroy(device->first_program);
  204. da_free(device->proj_stack);
  205. da_free(device->fbos);
  206. gl_platform_destroy(device->plat);
  207. bfree(device);
  208. }
  209. }
  210. gs_swapchain_t *device_swapchain_create(gs_device_t *device,
  211. const struct gs_init_data *info)
  212. {
  213. struct gs_swap_chain *swap = bzalloc(sizeof(struct gs_swap_chain));
  214. swap->device = device;
  215. swap->info = *info;
  216. swap->wi = gl_windowinfo_create(info);
  217. if (!swap->wi) {
  218. blog(LOG_ERROR, "device_swapchain_create (GL) failed");
  219. gs_swapchain_destroy(swap);
  220. return NULL;
  221. }
  222. if (!gl_platform_init_swapchain(swap)) {
  223. blog(LOG_ERROR, "gl_platform_init_swapchain failed");
  224. gs_swapchain_destroy(swap);
  225. return NULL;
  226. }
  227. return swap;
  228. }
  229. void device_resize(gs_device_t *device, uint32_t cx, uint32_t cy)
  230. {
  231. /* GL automatically resizes the device, so it doesn't do much */
  232. if (device->cur_swap) {
  233. device->cur_swap->info.cx = cx;
  234. device->cur_swap->info.cy = cy;
  235. } else {
  236. blog(LOG_WARNING, "device_resize (GL): No active swap");
  237. }
  238. gl_update(device);
  239. }
  240. void device_get_size(const gs_device_t *device, uint32_t *cx, uint32_t *cy)
  241. {
  242. if (device->cur_swap) {
  243. *cx = device->cur_swap->info.cx;
  244. *cy = device->cur_swap->info.cy;
  245. } else {
  246. blog(LOG_WARNING, "device_get_size (GL): No active swap");
  247. *cx = 0;
  248. *cy = 0;
  249. }
  250. }
  251. uint32_t device_get_width(const gs_device_t *device)
  252. {
  253. if (device->cur_swap) {
  254. return device->cur_swap->info.cx;
  255. } else {
  256. blog(LOG_WARNING, "device_get_width (GL): No active swap");
  257. return 0;
  258. }
  259. }
  260. uint32_t device_get_height(const gs_device_t *device)
  261. {
  262. if (device->cur_swap) {
  263. return device->cur_swap->info.cy;
  264. } else {
  265. blog(LOG_WARNING, "device_get_height (GL): No active swap");
  266. return 0;
  267. }
  268. }
  269. gs_texture_t *device_voltexture_create(gs_device_t *device, uint32_t width,
  270. uint32_t height, uint32_t depth,
  271. enum gs_color_format color_format, uint32_t levels,
  272. const uint8_t **data, uint32_t flags)
  273. {
  274. /* TODO */
  275. UNUSED_PARAMETER(device);
  276. UNUSED_PARAMETER(width);
  277. UNUSED_PARAMETER(height);
  278. UNUSED_PARAMETER(depth);
  279. UNUSED_PARAMETER(color_format);
  280. UNUSED_PARAMETER(levels);
  281. UNUSED_PARAMETER(data);
  282. UNUSED_PARAMETER(flags);
  283. return NULL;
  284. }
  285. gs_samplerstate_t *device_samplerstate_create(gs_device_t *device,
  286. const struct gs_sampler_info *info)
  287. {
  288. struct gs_sampler_state *sampler;
  289. sampler = bzalloc(sizeof(struct gs_sampler_state));
  290. sampler->device = device;
  291. sampler->ref = 1;
  292. convert_sampler_info(sampler, info);
  293. return sampler;
  294. }
  295. enum gs_texture_type device_get_texture_type(const gs_texture_t *texture)
  296. {
  297. return texture->type;
  298. }
  299. static void strip_mipmap_filter(GLint *filter)
  300. {
  301. switch (*filter) {
  302. case GL_NEAREST:
  303. case GL_LINEAR:
  304. return;
  305. case GL_NEAREST_MIPMAP_NEAREST:
  306. case GL_NEAREST_MIPMAP_LINEAR:
  307. *filter = GL_NEAREST;
  308. return;
  309. case GL_LINEAR_MIPMAP_NEAREST:
  310. case GL_LINEAR_MIPMAP_LINEAR:
  311. *filter = GL_LINEAR;
  312. return;
  313. }
  314. *filter = GL_NEAREST;
  315. }
  316. static inline void apply_swizzle(struct gs_texture *tex)
  317. {
  318. if (tex->format == GS_A8) {
  319. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_R, GL_ONE);
  320. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_G, GL_ONE);
  321. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_B, GL_ONE);
  322. gl_tex_param_i(tex->gl_target, GL_TEXTURE_SWIZZLE_A, GL_RED);
  323. }
  324. }
  325. static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
  326. {
  327. bool success = true;
  328. GLint min_filter;
  329. if (tex->cur_sampler == ss)
  330. return true;
  331. if (tex->cur_sampler)
  332. samplerstate_release(tex->cur_sampler);
  333. tex->cur_sampler = ss;
  334. if (!ss)
  335. return true;
  336. samplerstate_addref(ss);
  337. min_filter = ss->min_filter;
  338. if (gs_texture_is_rect(tex))
  339. strip_mipmap_filter(&min_filter);
  340. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MIN_FILTER,
  341. min_filter))
  342. success = false;
  343. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAG_FILTER,
  344. ss->mag_filter))
  345. success = false;
  346. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_S, ss->address_u))
  347. success = false;
  348. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_T, ss->address_v))
  349. success = false;
  350. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_R, ss->address_w))
  351. success = false;
  352. if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
  353. ss->max_anisotropy))
  354. success = false;
  355. apply_swizzle(tex);
  356. return success;
  357. }
  358. static inline struct gs_shader_param *get_texture_param(gs_device_t *device,
  359. int unit)
  360. {
  361. struct gs_shader *shader = device->cur_pixel_shader;
  362. size_t i;
  363. for (i = 0; i < shader->params.num; i++) {
  364. struct gs_shader_param *param = shader->params.array+i;
  365. if (param->type == GS_SHADER_PARAM_TEXTURE) {
  366. if (param->texture_id == unit)
  367. return param;
  368. }
  369. }
  370. return NULL;
  371. }
  372. void device_load_texture(gs_device_t *device, gs_texture_t *tex, int unit)
  373. {
  374. struct gs_shader_param *param;
  375. struct gs_sampler_state *sampler;
  376. struct gs_texture *cur_tex = device->cur_textures[unit];
  377. /* need a pixel shader to properly bind textures */
  378. if (!device->cur_pixel_shader)
  379. tex = NULL;
  380. if (cur_tex == tex)
  381. return;
  382. if (!gl_active_texture(GL_TEXTURE0 + unit))
  383. goto fail;
  384. /* the target for the previous text may not be the same as the
  385. * next texture, so unbind the previous texture first to be safe */
  386. if (cur_tex && (!tex || cur_tex->gl_target != tex->gl_target))
  387. gl_bind_texture(cur_tex->gl_target, 0);
  388. device->cur_textures[unit] = tex;
  389. param = get_texture_param(device, unit);
  390. if (!param)
  391. return;
  392. param->texture = tex;
  393. if (!tex)
  394. return;
  395. sampler = device->cur_samplers[param->sampler_id];
  396. if (!gl_bind_texture(tex->gl_target, tex->texture))
  397. goto fail;
  398. if (sampler && !load_texture_sampler(tex, sampler))
  399. goto fail;
  400. return;
  401. fail:
  402. blog(LOG_ERROR, "device_load_texture (GL) failed");
  403. }
  404. static bool load_sampler_on_textures(gs_device_t *device, gs_samplerstate_t *ss,
  405. int sampler_unit)
  406. {
  407. struct gs_shader *shader = device->cur_pixel_shader;
  408. size_t i;
  409. for (i = 0; i < shader->params.num; i++) {
  410. struct gs_shader_param *param = shader->params.array+i;
  411. if (param->type == GS_SHADER_PARAM_TEXTURE &&
  412. param->sampler_id == (uint32_t)sampler_unit &&
  413. param->texture) {
  414. if (!gl_active_texture(GL_TEXTURE0 + param->texture_id))
  415. return false;
  416. if (!load_texture_sampler(param->texture, ss))
  417. return false;
  418. }
  419. }
  420. return true;
  421. }
  422. void device_load_samplerstate(gs_device_t *device, gs_samplerstate_t *ss,
  423. int unit)
  424. {
  425. /* need a pixel shader to properly bind samplers */
  426. if (!device->cur_pixel_shader)
  427. ss = NULL;
  428. if (device->cur_samplers[unit] == ss)
  429. return;
  430. device->cur_samplers[unit] = ss;
  431. if (!ss)
  432. return;
  433. if (!load_sampler_on_textures(device, ss, unit))
  434. blog(LOG_ERROR, "device_load_samplerstate (GL) failed");
  435. return;
  436. }
  437. void device_load_vertexshader(gs_device_t *device, gs_shader_t *vertshader)
  438. {
  439. if (device->cur_vertex_shader == vertshader)
  440. return;
  441. if (vertshader && vertshader->type != GS_SHADER_VERTEX) {
  442. blog(LOG_ERROR, "Specified shader is not a vertex shader");
  443. blog(LOG_ERROR, "device_load_vertexshader (GL) failed");
  444. return;
  445. }
  446. device->cur_vertex_shader = vertshader;
  447. }
  448. static void load_default_pixelshader_samplers(struct gs_device *device,
  449. struct gs_shader *ps)
  450. {
  451. size_t i;
  452. if (!ps)
  453. return;
  454. for (i = 0; i < ps->samplers.num; i++) {
  455. struct gs_sampler_state *ss = ps->samplers.array[i];
  456. device->cur_samplers[i] = ss;
  457. }
  458. for (; i < GS_MAX_TEXTURES; i++)
  459. device->cur_samplers[i] = NULL;
  460. }
  461. void device_load_pixelshader(gs_device_t *device, gs_shader_t *pixelshader)
  462. {
  463. if (device->cur_pixel_shader == pixelshader)
  464. return;
  465. if (pixelshader && pixelshader->type != GS_SHADER_PIXEL) {
  466. blog(LOG_ERROR, "Specified shader is not a pixel shader");
  467. goto fail;
  468. }
  469. device->cur_pixel_shader = pixelshader;
  470. clear_textures(device);
  471. if (pixelshader)
  472. load_default_pixelshader_samplers(device, pixelshader);
  473. return;
  474. fail:
  475. blog(LOG_ERROR, "device_load_pixelshader (GL) failed");
  476. }
  477. void device_load_default_samplerstate(gs_device_t *device, bool b_3d, int unit)
  478. {
  479. /* TODO */
  480. UNUSED_PARAMETER(device);
  481. UNUSED_PARAMETER(b_3d);
  482. UNUSED_PARAMETER(unit);
  483. }
  484. gs_shader_t *device_get_vertex_shader(const gs_device_t *device)
  485. {
  486. return device->cur_vertex_shader;
  487. }
  488. gs_shader_t *device_get_pixel_shader(const gs_device_t *device)
  489. {
  490. return device->cur_pixel_shader;
  491. }
  492. gs_texture_t *device_get_render_target(const gs_device_t *device)
  493. {
  494. return device->cur_render_target;
  495. }
  496. gs_zstencil_t *device_get_zstencil_target(const gs_device_t *device)
  497. {
  498. return device->cur_zstencil_buffer;
  499. }
  500. static bool get_tex_dimensions(gs_texture_t *tex, uint32_t *width,
  501. uint32_t *height)
  502. {
  503. if (tex->type == GS_TEXTURE_2D) {
  504. struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
  505. *width = tex2d->width;
  506. *height = tex2d->height;
  507. return true;
  508. } else if (tex->type == GS_TEXTURE_CUBE) {
  509. struct gs_texture_cube *cube = (struct gs_texture_cube*)tex;
  510. *width = cube->size;
  511. *height = cube->size;
  512. return true;
  513. }
  514. blog(LOG_ERROR, "Texture must be 2D or cubemap");
  515. return false;
  516. }
  517. /*
  518. * This automatically manages FBOs so that render targets are always given
  519. * an FBO that matches their width/height/format to maximize optimization
  520. */
  521. struct fbo_info *get_fbo(struct gs_device *device,
  522. uint32_t width, uint32_t height, enum gs_color_format format)
  523. {
  524. size_t i;
  525. GLuint fbo;
  526. struct fbo_info *ptr;
  527. for (i = 0; i < device->fbos.num; i++) {
  528. ptr = device->fbos.array[i];
  529. if (ptr->width == width && ptr->height == height &&
  530. ptr->format == format)
  531. return ptr;
  532. }
  533. glGenFramebuffers(1, &fbo);
  534. if (!gl_success("glGenFramebuffers"))
  535. return NULL;
  536. ptr = bmalloc(sizeof(struct fbo_info));
  537. ptr->fbo = fbo;
  538. ptr->width = width;
  539. ptr->height = height;
  540. ptr->format = format;
  541. ptr->cur_render_target = NULL;
  542. ptr->cur_render_side = 0;
  543. ptr->cur_zstencil_buffer = NULL;
  544. da_push_back(device->fbos, &ptr);
  545. return ptr;
  546. }
  547. static inline struct fbo_info *get_fbo_by_tex(struct gs_device *device,
  548. gs_texture_t *tex)
  549. {
  550. uint32_t width, height;
  551. if (!get_tex_dimensions(tex, &width, &height))
  552. return NULL;
  553. return get_fbo(device, width, height, tex->format);
  554. }
  555. static bool set_current_fbo(gs_device_t *device, struct fbo_info *fbo)
  556. {
  557. if (device->cur_fbo != fbo) {
  558. GLuint fbo_obj = fbo ? fbo->fbo : 0;
  559. if (!gl_bind_framebuffer(GL_DRAW_FRAMEBUFFER, fbo_obj))
  560. return false;
  561. if (device->cur_fbo) {
  562. device->cur_fbo->cur_render_target = NULL;
  563. device->cur_fbo->cur_zstencil_buffer = NULL;
  564. }
  565. }
  566. device->cur_fbo = fbo;
  567. return true;
  568. }
  569. static bool attach_rendertarget(struct fbo_info *fbo, gs_texture_t *tex,
  570. int side)
  571. {
  572. if (fbo->cur_render_target == tex)
  573. return true;
  574. fbo->cur_render_target = tex;
  575. if (tex->type == GS_TEXTURE_2D) {
  576. glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
  577. GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
  578. tex->texture, 0);
  579. } else if (tex->type == GS_TEXTURE_CUBE) {
  580. glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
  581. GL_COLOR_ATTACHMENT0,
  582. GL_TEXTURE_CUBE_MAP_POSITIVE_X + side,
  583. tex->texture, 0);
  584. } else {
  585. return false;
  586. }
  587. return gl_success("glFramebufferTexture2D");
  588. }
  589. static bool attach_zstencil(struct fbo_info *fbo, gs_zstencil_t *zs)
  590. {
  591. GLuint zsbuffer = 0;
  592. GLenum zs_attachment = GL_DEPTH_STENCIL_ATTACHMENT;
  593. if (fbo->cur_zstencil_buffer == zs)
  594. return true;
  595. fbo->cur_zstencil_buffer = zs;
  596. if (zs) {
  597. zsbuffer = zs->buffer;
  598. zs_attachment = zs->attachment;
  599. }
  600. glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,
  601. zs_attachment, GL_RENDERBUFFER, zsbuffer);
  602. if (!gl_success("glFramebufferRenderbuffer"))
  603. return false;
  604. return true;
  605. }
  606. static bool set_target(gs_device_t *device, gs_texture_t *tex, int side,
  607. gs_zstencil_t *zs)
  608. {
  609. struct fbo_info *fbo;
  610. if (device->cur_render_target == tex &&
  611. device->cur_zstencil_buffer == zs &&
  612. device->cur_render_side == side)
  613. return true;
  614. device->cur_render_target = tex;
  615. device->cur_render_side = side;
  616. device->cur_zstencil_buffer = zs;
  617. if (!tex)
  618. return set_current_fbo(device, NULL);
  619. fbo = get_fbo_by_tex(device, tex);
  620. if (!fbo)
  621. return false;
  622. set_current_fbo(device, fbo);
  623. if (!attach_rendertarget(fbo, tex, side))
  624. return false;
  625. if (!attach_zstencil(fbo, zs))
  626. return false;
  627. return true;
  628. }
  629. void device_set_render_target(gs_device_t *device, gs_texture_t *tex,
  630. gs_zstencil_t *zstencil)
  631. {
  632. if (tex) {
  633. if (tex->type != GS_TEXTURE_2D) {
  634. blog(LOG_ERROR, "Texture is not a 2D texture");
  635. goto fail;
  636. }
  637. if (!tex->is_render_target) {
  638. blog(LOG_ERROR, "Texture is not a render target");
  639. goto fail;
  640. }
  641. }
  642. if (!set_target(device, tex, 0, zstencil))
  643. goto fail;
  644. return;
  645. fail:
  646. blog(LOG_ERROR, "device_set_render_target (GL) failed");
  647. }
  648. void device_set_cube_render_target(gs_device_t *device, gs_texture_t *cubetex,
  649. int side, gs_zstencil_t *zstencil)
  650. {
  651. if (cubetex) {
  652. if (cubetex->type != GS_TEXTURE_CUBE) {
  653. blog(LOG_ERROR, "Texture is not a cube texture");
  654. goto fail;
  655. }
  656. if (!cubetex->is_render_target) {
  657. blog(LOG_ERROR, "Texture is not a render target");
  658. goto fail;
  659. }
  660. }
  661. if (!set_target(device, cubetex, side, zstencil))
  662. goto fail;
  663. return;
  664. fail:
  665. blog(LOG_ERROR, "device_set_cube_render_target (GL) failed");
  666. }
  667. void device_copy_texture_region(gs_device_t *device,
  668. gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
  669. gs_texture_t *src, uint32_t src_x, uint32_t src_y,
  670. uint32_t src_w, uint32_t src_h)
  671. {
  672. struct gs_texture_2d *src2d = (struct gs_texture_2d*)src;
  673. struct gs_texture_2d *dst2d = (struct gs_texture_2d*)dst;
  674. if (!src) {
  675. blog(LOG_ERROR, "Source texture is NULL");
  676. goto fail;
  677. }
  678. if (!dst) {
  679. blog(LOG_ERROR, "Destination texture is NULL");
  680. goto fail;
  681. }
  682. if (dst->type != GS_TEXTURE_2D || src->type != GS_TEXTURE_2D) {
  683. blog(LOG_ERROR, "Source and destination textures must be 2D "
  684. "textures");
  685. goto fail;
  686. }
  687. if (dst->format != src->format) {
  688. blog(LOG_ERROR, "Source and destination formats do not match");
  689. goto fail;
  690. }
  691. uint32_t nw = (uint32_t)src_w ?
  692. (uint32_t)src_w : (src2d->width - src_x);
  693. uint32_t nh = (uint32_t)src_h ?
  694. (uint32_t)src_h : (src2d->height - src_y);
  695. if (dst2d->width - dst_x < nw || dst2d->height - dst_y < nh) {
  696. blog(LOG_ERROR, "Destination texture region is not big "
  697. "enough to hold the source region");
  698. goto fail;
  699. }
  700. if (!gl_copy_texture(device, dst->texture, dst->gl_target, dst_x, dst_y,
  701. src->texture, src->gl_target, src_x, src_y,
  702. nw, nh, src->format))
  703. goto fail;
  704. return;
  705. fail:
  706. blog(LOG_ERROR, "device_copy_texture (GL) failed");
  707. }
  708. void device_copy_texture(gs_device_t *device, gs_texture_t *dst,
  709. gs_texture_t *src)
  710. {
  711. device_copy_texture_region(device, dst, 0, 0, src, 0, 0, 0, 0);
  712. }
  713. void device_begin_scene(gs_device_t *device)
  714. {
  715. clear_textures(device);
  716. }
  717. static inline bool can_render(const gs_device_t *device)
  718. {
  719. if (!device->cur_vertex_shader) {
  720. blog(LOG_ERROR, "No vertex shader specified");
  721. return false;
  722. }
  723. if (!device->cur_pixel_shader) {
  724. blog(LOG_ERROR, "No pixel shader specified");
  725. return false;
  726. }
  727. if (!device->cur_vertex_buffer) {
  728. blog(LOG_ERROR, "No vertex buffer specified");
  729. return false;
  730. }
  731. if (!device->cur_swap && !device->cur_render_target) {
  732. blog(LOG_ERROR, "No active swap chain or render target");
  733. return false;
  734. }
  735. return true;
  736. }
  737. static void update_viewproj_matrix(struct gs_device *device)
  738. {
  739. struct gs_shader *vs = device->cur_vertex_shader;
  740. struct matrix4 cur_proj;
  741. gs_matrix_get(&device->cur_view);
  742. matrix4_copy(&cur_proj, &device->cur_proj);
  743. if (device->cur_fbo) {
  744. cur_proj.x.y = -cur_proj.x.y;
  745. cur_proj.y.y = -cur_proj.y.y;
  746. cur_proj.z.y = -cur_proj.z.y;
  747. cur_proj.t.y = -cur_proj.t.y;
  748. glFrontFace(GL_CW);
  749. } else {
  750. glFrontFace(GL_CCW);
  751. }
  752. gl_success("glFrontFace");
  753. matrix4_mul(&device->cur_viewproj, &device->cur_view, &cur_proj);
  754. matrix4_transpose(&device->cur_viewproj, &device->cur_viewproj);
  755. if (vs->viewproj)
  756. gs_shader_set_matrix4(vs->viewproj, &device->cur_viewproj);
  757. }
  758. static inline struct gs_program *find_program(const struct gs_device *device)
  759. {
  760. struct gs_program *program = device->first_program;
  761. while (program) {
  762. if (program->vertex_shader == device->cur_vertex_shader &&
  763. program->pixel_shader == device->cur_pixel_shader)
  764. return program;
  765. program = program->next;
  766. }
  767. return NULL;
  768. }
  769. static inline struct gs_program *get_shader_program(struct gs_device *device)
  770. {
  771. struct gs_program *program = find_program(device);
  772. if (!program)
  773. program = gs_program_create(device);
  774. return program;
  775. }
  776. void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
  777. uint32_t start_vert, uint32_t num_verts)
  778. {
  779. struct gs_index_buffer *ib = device->cur_index_buffer;
  780. GLenum topology = convert_gs_topology(draw_mode);
  781. gs_effect_t *effect = gs_get_effect();
  782. struct gs_program *program;
  783. if (!can_render(device))
  784. goto fail;
  785. if (effect)
  786. gs_effect_update_params(effect);
  787. program = get_shader_program(device);
  788. if (!program)
  789. goto fail;
  790. load_vb_buffers(program, device->cur_vertex_buffer);
  791. if (program != device->cur_program && device->cur_program) {
  792. glUseProgram(0);
  793. gl_success("glUseProgram (zero)");
  794. }
  795. if (program != device->cur_program) {
  796. device->cur_program = program;
  797. glUseProgram(program->obj);
  798. if (!gl_success("glUseProgram"))
  799. goto fail;
  800. }
  801. update_viewproj_matrix(device);
  802. program_update_params(program);
  803. if (ib) {
  804. if (num_verts == 0)
  805. num_verts = (uint32_t)device->cur_index_buffer->num;
  806. glDrawElements(topology, num_verts, ib->gl_type,
  807. (const GLvoid*)(start_vert * ib->width));
  808. if (!gl_success("glDrawElements"))
  809. goto fail;
  810. } else {
  811. if (num_verts == 0)
  812. num_verts = (uint32_t)device->cur_vertex_buffer->num;
  813. glDrawArrays(topology, start_vert, num_verts);
  814. if (!gl_success("glDrawArrays"))
  815. goto fail;
  816. }
  817. return;
  818. fail:
  819. blog(LOG_ERROR, "device_draw (GL) failed");
  820. }
  821. void device_end_scene(gs_device_t *device)
  822. {
  823. /* does nothing */
  824. UNUSED_PARAMETER(device);
  825. }
  826. void device_clear(gs_device_t *device, uint32_t clear_flags,
  827. const struct vec4 *color, float depth, uint8_t stencil)
  828. {
  829. GLbitfield gl_flags = 0;
  830. if (clear_flags & GS_CLEAR_COLOR) {
  831. glClearColor(color->x, color->y, color->z, color->w);
  832. gl_flags |= GL_COLOR_BUFFER_BIT;
  833. }
  834. if (clear_flags & GS_CLEAR_DEPTH) {
  835. glClearDepth(depth);
  836. gl_flags |= GL_DEPTH_BUFFER_BIT;
  837. }
  838. if (clear_flags & GS_CLEAR_STENCIL) {
  839. glClearStencil(stencil);
  840. gl_flags |= GL_STENCIL_BUFFER_BIT;
  841. }
  842. glClear(gl_flags);
  843. if (!gl_success("glClear"))
  844. blog(LOG_ERROR, "device_clear (GL) failed");
  845. UNUSED_PARAMETER(device);
  846. }
  847. void device_flush(gs_device_t *device)
  848. {
  849. #ifdef __APPLE__
  850. if (!device->cur_swap)
  851. glFlush();
  852. #else
  853. glFlush();
  854. #endif
  855. UNUSED_PARAMETER(device);
  856. }
  857. void device_set_cull_mode(gs_device_t *device, enum gs_cull_mode mode)
  858. {
  859. if (device->cur_cull_mode == mode)
  860. return;
  861. if (device->cur_cull_mode == GS_NEITHER)
  862. gl_enable(GL_CULL_FACE);
  863. device->cur_cull_mode = mode;
  864. if (mode == GS_BACK)
  865. gl_cull_face(GL_BACK);
  866. else if (mode == GS_FRONT)
  867. gl_cull_face(GL_FRONT);
  868. else
  869. gl_disable(GL_CULL_FACE);
  870. }
  871. enum gs_cull_mode device_get_cull_mode(const gs_device_t *device)
  872. {
  873. return device->cur_cull_mode;
  874. }
  875. void device_enable_blending(gs_device_t *device, bool enable)
  876. {
  877. if (enable)
  878. gl_enable(GL_BLEND);
  879. else
  880. gl_disable(GL_BLEND);
  881. UNUSED_PARAMETER(device);
  882. }
  883. void device_enable_depth_test(gs_device_t *device, bool enable)
  884. {
  885. if (enable)
  886. gl_enable(GL_DEPTH_TEST);
  887. else
  888. gl_disable(GL_DEPTH_TEST);
  889. UNUSED_PARAMETER(device);
  890. }
  891. void device_enable_stencil_test(gs_device_t *device, bool enable)
  892. {
  893. if (enable)
  894. gl_enable(GL_STENCIL_TEST);
  895. else
  896. gl_disable(GL_STENCIL_TEST);
  897. UNUSED_PARAMETER(device);
  898. }
  899. void device_enable_stencil_write(gs_device_t *device, bool enable)
  900. {
  901. if (enable)
  902. glStencilMask(0xFFFFFFFF);
  903. else
  904. glStencilMask(0);
  905. UNUSED_PARAMETER(device);
  906. }
  907. void device_enable_color(gs_device_t *device, bool red, bool green,
  908. bool blue, bool alpha)
  909. {
  910. glColorMask(red, green, blue, alpha);
  911. UNUSED_PARAMETER(device);
  912. }
  913. void device_blend_function(gs_device_t *device, enum gs_blend_type src,
  914. enum gs_blend_type dest)
  915. {
  916. GLenum gl_src = convert_gs_blend_type(src);
  917. GLenum gl_dst = convert_gs_blend_type(dest);
  918. glBlendFunc(gl_src, gl_dst);
  919. if (!gl_success("glBlendFunc"))
  920. blog(LOG_ERROR, "device_blend_function (GL) failed");
  921. UNUSED_PARAMETER(device);
  922. }
  923. void device_blend_function_separate(gs_device_t *device,
  924. enum gs_blend_type src_c, enum gs_blend_type dest_c,
  925. enum gs_blend_type src_a, enum gs_blend_type dest_a)
  926. {
  927. GLenum gl_src_c = convert_gs_blend_type(src_c);
  928. GLenum gl_dst_c = convert_gs_blend_type(dest_c);
  929. GLenum gl_src_a = convert_gs_blend_type(src_a);
  930. GLenum gl_dst_a = convert_gs_blend_type(dest_a);
  931. glBlendFuncSeparate(gl_src_c, gl_dst_c, gl_src_a, gl_dst_a);
  932. if (!gl_success("glBlendFuncSeparate"))
  933. blog(LOG_ERROR, "device_blend_function_separate (GL) failed");
  934. UNUSED_PARAMETER(device);
  935. }
  936. void device_depth_function(gs_device_t *device, enum gs_depth_test test)
  937. {
  938. GLenum gl_test = convert_gs_depth_test(test);
  939. glDepthFunc(gl_test);
  940. if (!gl_success("glDepthFunc"))
  941. blog(LOG_ERROR, "device_depth_function (GL) failed");
  942. UNUSED_PARAMETER(device);
  943. }
  944. void device_stencil_function(gs_device_t *device, enum gs_stencil_side side,
  945. enum gs_depth_test test)
  946. {
  947. GLenum gl_side = convert_gs_stencil_side(side);
  948. GLenum gl_test = convert_gs_depth_test(test);
  949. glStencilFuncSeparate(gl_side, gl_test, 0, 0xFFFFFFFF);
  950. if (!gl_success("glStencilFuncSeparate"))
  951. blog(LOG_ERROR, "device_stencil_function (GL) failed");
  952. UNUSED_PARAMETER(device);
  953. }
  954. void device_stencil_op(gs_device_t *device, enum gs_stencil_side side,
  955. enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail,
  956. enum gs_stencil_op_type zpass)
  957. {
  958. GLenum gl_side = convert_gs_stencil_side(side);
  959. GLenum gl_fail = convert_gs_stencil_op(fail);
  960. GLenum gl_zfail = convert_gs_stencil_op(zfail);
  961. GLenum gl_zpass = convert_gs_stencil_op(zpass);
  962. glStencilOpSeparate(gl_side, gl_fail, gl_zfail, gl_zpass);
  963. if (!gl_success("glStencilOpSeparate"))
  964. blog(LOG_ERROR, "device_stencil_op (GL) failed");
  965. UNUSED_PARAMETER(device);
  966. }
  967. static inline uint32_t get_target_height(const struct gs_device *device)
  968. {
  969. if (!device->cur_render_target)
  970. return device_get_height(device);
  971. if (device->cur_render_target->type == GS_TEXTURE_2D)
  972. return gs_texture_get_height(device->cur_render_target);
  973. else /* cube map */
  974. return gs_cubetexture_get_size(device->cur_render_target);
  975. }
  976. void device_set_viewport(gs_device_t *device, int x, int y, int width,
  977. int height)
  978. {
  979. uint32_t base_height;
  980. /* GL uses bottom-up coordinates for viewports. We want top-down */
  981. if (device->cur_render_target) {
  982. base_height = get_target_height(device);
  983. } else {
  984. uint32_t dw;
  985. gl_getclientsize(device->cur_swap, &dw, &base_height);
  986. }
  987. glViewport(x, base_height - y - height, width, height);
  988. if (!gl_success("glViewport"))
  989. blog(LOG_ERROR, "device_set_viewport (GL) failed");
  990. device->cur_viewport.x = x;
  991. device->cur_viewport.y = y;
  992. device->cur_viewport.cx = width;
  993. device->cur_viewport.cy = height;
  994. }
  995. void device_get_viewport(const gs_device_t *device, struct gs_rect *rect)
  996. {
  997. *rect = device->cur_viewport;
  998. }
  999. void device_set_scissor_rect(gs_device_t *device, const struct gs_rect *rect)
  1000. {
  1001. UNUSED_PARAMETER(device);
  1002. if (rect != NULL) {
  1003. glScissor(rect->x, rect->y, rect->cx, rect->cy);
  1004. if (gl_success("glScissor") && gl_enable(GL_SCISSOR_TEST))
  1005. return;
  1006. } else if (gl_disable(GL_SCISSOR_TEST)) {
  1007. return;
  1008. }
  1009. blog(LOG_ERROR, "device_set_scissor_rect (GL) failed");
  1010. }
  1011. void device_ortho(gs_device_t *device, float left, float right,
  1012. float top, float bottom, float near, float far)
  1013. {
  1014. struct matrix4 *dst = &device->cur_proj;
  1015. float rml = right-left;
  1016. float bmt = bottom-top;
  1017. float fmn = far-near;
  1018. vec4_zero(&dst->x);
  1019. vec4_zero(&dst->y);
  1020. vec4_zero(&dst->z);
  1021. vec4_zero(&dst->t);
  1022. dst->x.x = 2.0f / rml;
  1023. dst->t.x = (left+right) / -rml;
  1024. dst->y.y = 2.0f / -bmt;
  1025. dst->t.y = (bottom+top) / bmt;
  1026. dst->z.z = -2.0f / fmn;
  1027. dst->t.z = (far+near) / -fmn;
  1028. dst->t.w = 1.0f;
  1029. }
  1030. void device_frustum(gs_device_t *device, float left, float right,
  1031. float top, float bottom, float near, float far)
  1032. {
  1033. struct matrix4 *dst = &device->cur_proj;
  1034. float rml = right-left;
  1035. float tmb = top-bottom;
  1036. float nmf = near-far;
  1037. float nearx2 = 2.0f*near;
  1038. vec4_zero(&dst->x);
  1039. vec4_zero(&dst->y);
  1040. vec4_zero(&dst->z);
  1041. vec4_zero(&dst->t);
  1042. dst->x.x = nearx2 / rml;
  1043. dst->z.x = (left+right) / rml;
  1044. dst->y.y = nearx2 / tmb;
  1045. dst->z.y = (bottom+top) / tmb;
  1046. dst->z.z = (far+near) / nmf;
  1047. dst->t.z = 2.0f * (near*far) / nmf;
  1048. dst->z.w = -1.0f;
  1049. }
  1050. void device_projection_push(gs_device_t *device)
  1051. {
  1052. da_push_back(device->proj_stack, &device->cur_proj);
  1053. }
  1054. void device_projection_pop(gs_device_t *device)
  1055. {
  1056. struct matrix4 *end;
  1057. if (!device->proj_stack.num)
  1058. return;
  1059. end = da_end(device->proj_stack);
  1060. device->cur_proj = *end;
  1061. da_pop_back(device->proj_stack);
  1062. }
  1063. void gs_swapchain_destroy(gs_swapchain_t *swapchain)
  1064. {
  1065. if (!swapchain)
  1066. return;
  1067. if (swapchain->device->cur_swap == swapchain)
  1068. device_load_swapchain(swapchain->device, NULL);
  1069. gl_platform_cleanup_swapchain(swapchain);
  1070. gl_windowinfo_destroy(swapchain->wi);
  1071. bfree(swapchain);
  1072. }
  1073. void gs_voltexture_destroy(gs_texture_t *voltex)
  1074. {
  1075. /* TODO */
  1076. UNUSED_PARAMETER(voltex);
  1077. }
  1078. uint32_t gs_voltexture_get_width(const gs_texture_t *voltex)
  1079. {
  1080. /* TODO */
  1081. UNUSED_PARAMETER(voltex);
  1082. return 0;
  1083. }
  1084. uint32_t gs_voltexture_get_height(const gs_texture_t *voltex)
  1085. {
  1086. /* TODO */
  1087. UNUSED_PARAMETER(voltex);
  1088. return 0;
  1089. }
  1090. uint32_t gs_voltexture_get_depth(const gs_texture_t *voltex)
  1091. {
  1092. /* TODO */
  1093. UNUSED_PARAMETER(voltex);
  1094. return 0;
  1095. }
  1096. enum gs_color_format gs_voltexture_get_color_format(const gs_texture_t *voltex)
  1097. {
  1098. /* TODO */
  1099. UNUSED_PARAMETER(voltex);
  1100. return GS_UNKNOWN;
  1101. }
  1102. void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
  1103. {
  1104. if (!samplerstate)
  1105. return;
  1106. if (samplerstate->device)
  1107. for (int i = 0; i < GS_MAX_TEXTURES; i++)
  1108. if (samplerstate->device->cur_samplers[i] ==
  1109. samplerstate)
  1110. samplerstate->device->cur_samplers[i] = NULL;
  1111. samplerstate_release(samplerstate);
  1112. }