gl-subsystem.c 32 KB

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