texturev.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. /*
  2. * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include "common.h"
  6. #include <bgfx/bgfx.h>
  7. #include <bx/commandline.h>
  8. #include <bx/easing.h>
  9. #include <bx/file.h>
  10. #include <bx/filepath.h>
  11. #include <bx/math.h>
  12. #include <bx/os.h>
  13. #include <bx/process.h>
  14. #include <bx/settings.h>
  15. #include <bx/uint32_t.h>
  16. #include <entry/entry.h>
  17. #include <entry/input.h>
  18. #include <entry/cmd.h>
  19. #include <imgui/imgui.h>
  20. #include <bgfx_utils.h>
  21. #include <dirent.h>
  22. #include <tinystl/allocator.h>
  23. #include <tinystl/vector.h>
  24. namespace stl = tinystl;
  25. #include <string>
  26. #include <algorithm>
  27. #include <bimg/decode.h>
  28. #include <bgfx/embedded_shader.h>
  29. #include "vs_texture.bin.h"
  30. #include "vs_texture_cube.bin.h"
  31. #include "fs_texture.bin.h"
  32. #include "fs_texture_array.bin.h"
  33. #include "fs_texture_cube.bin.h"
  34. #include "fs_texture_cube2.bin.h"
  35. #include "fs_texture_sdf.bin.h"
  36. #include "fs_texture_msdf.bin.h"
  37. #include "fs_texture_3d.bin.h"
  38. #define BACKGROUND_VIEW_ID 0
  39. #define IMAGE_VIEW_ID 1
  40. #define BGFX_TEXTUREV_VERSION_MAJOR 1
  41. #define BGFX_TEXTUREV_VERSION_MINOR 0
  42. const float kEvMin = -10.0f;
  43. const float kEvMax = 20.0f;
  44. static const bgfx::EmbeddedShader s_embeddedShaders[] =
  45. {
  46. BGFX_EMBEDDED_SHADER(vs_texture),
  47. BGFX_EMBEDDED_SHADER(fs_texture),
  48. BGFX_EMBEDDED_SHADER(fs_texture_array),
  49. BGFX_EMBEDDED_SHADER(vs_texture_cube),
  50. BGFX_EMBEDDED_SHADER(fs_texture_cube),
  51. BGFX_EMBEDDED_SHADER(fs_texture_cube2),
  52. BGFX_EMBEDDED_SHADER(fs_texture_sdf),
  53. BGFX_EMBEDDED_SHADER(fs_texture_msdf),
  54. BGFX_EMBEDDED_SHADER(fs_texture_3d),
  55. BGFX_EMBEDDED_SHADER_END()
  56. };
  57. static const char* s_supportedExt[] =
  58. {
  59. "bmp",
  60. "dds",
  61. "exr",
  62. "gif",
  63. "gnf",
  64. "jpg",
  65. "jpeg",
  66. "hdr",
  67. "ktx",
  68. "pgm",
  69. "png",
  70. "ppm",
  71. "psd",
  72. "pvr",
  73. "tga",
  74. };
  75. struct Binding
  76. {
  77. enum Enum
  78. {
  79. App,
  80. View,
  81. Help,
  82. Count
  83. };
  84. };
  85. struct Geometry
  86. {
  87. enum Enum
  88. {
  89. Quad,
  90. Cross,
  91. Hexagon,
  92. Count
  93. };
  94. };
  95. static const InputBinding s_bindingApp[] =
  96. {
  97. { entry::Key::KeyQ, entry::Modifier::None, 1, NULL, "exit" },
  98. { entry::Key::KeyF, entry::Modifier::None, 1, NULL, "graphics fullscreen" },
  99. INPUT_BINDING_END
  100. };
  101. const char* s_resetCmd =
  102. "view zoom 1.0\n"
  103. "view rotate 0\n"
  104. "view cubemap\n"
  105. "view pan\n"
  106. "view ev\n"
  107. ;
  108. static const InputBinding s_bindingView[] =
  109. {
  110. { entry::Key::Esc, entry::Modifier::None, 1, NULL, "exit" },
  111. { entry::Key::Comma, entry::Modifier::None, 1, NULL, "view mip prev" },
  112. { entry::Key::Period, entry::Modifier::None, 1, NULL, "view mip next" },
  113. { entry::Key::Comma, entry::Modifier::LeftShift, 1, NULL, "view mip" },
  114. { entry::Key::Comma, entry::Modifier::RightShift, 1, NULL, "view mip" },
  115. { entry::Key::Slash, entry::Modifier::None, 1, NULL, "view filter" },
  116. { entry::Key::Key1, entry::Modifier::None, 1, NULL, "view zoom 1.0\n"
  117. "view fit\n" },
  118. { entry::Key::Key0, entry::Modifier::None, 1, NULL, s_resetCmd },
  119. { entry::Key::Plus, entry::Modifier::None, 1, NULL, "view zoom +0.1" },
  120. { entry::Key::Minus, entry::Modifier::None, 1, NULL, "view zoom -0.1" },
  121. { entry::Key::KeyZ, entry::Modifier::None, 1, NULL, "view rotate -90" },
  122. { entry::Key::KeyZ, entry::Modifier::LeftShift, 1, NULL, "view rotate +90" },
  123. { entry::Key::Up, entry::Modifier::None, 1, NULL, "view pan\n"
  124. "view file-up" },
  125. { entry::Key::Down, entry::Modifier::None, 1, NULL, "view pan\n"
  126. "view file-down" },
  127. { entry::Key::PageUp, entry::Modifier::None, 1, NULL, "view pan\n"
  128. "view file-pgup" },
  129. { entry::Key::PageDown, entry::Modifier::None, 1, NULL, "view pan\n"
  130. "view file-pgdown" },
  131. { entry::Key::Left, entry::Modifier::None, 1, NULL, "view layer prev" },
  132. { entry::Key::Right, entry::Modifier::None, 1, NULL, "view layer next" },
  133. { entry::Key::KeyR, entry::Modifier::None, 1, NULL, "view rgb r" },
  134. { entry::Key::KeyG, entry::Modifier::None, 1, NULL, "view rgb g" },
  135. { entry::Key::KeyB, entry::Modifier::None, 1, NULL, "view rgb b" },
  136. { entry::Key::KeyA, entry::Modifier::None, 1, NULL, "view rgb a" },
  137. { entry::Key::KeyI, entry::Modifier::None, 1, NULL, "view info" },
  138. { entry::Key::KeyH, entry::Modifier::None, 1, NULL, "view help" },
  139. { entry::Key::Return, entry::Modifier::None, 1, NULL, "view files" },
  140. { entry::Key::KeyS, entry::Modifier::None, 1, NULL, "view sdf" },
  141. { entry::Key::Space, entry::Modifier::None, 1, NULL, "view geo\n"
  142. "view pan\n" },
  143. INPUT_BINDING_END
  144. };
  145. static const InputBinding s_bindingHelp[] =
  146. {
  147. { entry::Key::Esc, entry::Modifier::None, 1, NULL, "view help" },
  148. { entry::Key::KeyH, entry::Modifier::None, 1, NULL, "view help" },
  149. INPUT_BINDING_END
  150. };
  151. static const char* s_bindingName[] =
  152. {
  153. "App",
  154. "View",
  155. "Help",
  156. };
  157. BX_STATIC_ASSERT(Binding::Count == BX_COUNTOF(s_bindingName) );
  158. static const InputBinding* s_binding[] =
  159. {
  160. s_bindingApp,
  161. s_bindingView,
  162. s_bindingHelp,
  163. };
  164. BX_STATIC_ASSERT(Binding::Count == BX_COUNTOF(s_binding) );
  165. struct View
  166. {
  167. View()
  168. : m_cubeMapGeo(Geometry::Quad)
  169. , m_fileIndex(0)
  170. , m_scaleFn(0)
  171. , m_mip(0)
  172. , m_layer(0)
  173. , m_abgr(UINT32_MAX)
  174. , m_ev(0.0f)
  175. , m_evMin(kEvMin)
  176. , m_evMax(kEvMax)
  177. , m_posx(0.0f)
  178. , m_posy(0.0f)
  179. , m_angx(0.0f)
  180. , m_angy(0.0f)
  181. , m_zoom(1.0f)
  182. , m_angle(0.0f)
  183. , m_orientation(0.0f)
  184. , m_flipH(0.0f)
  185. , m_flipV(0.0f)
  186. , m_transitionTime(1.0f)
  187. , m_filter(true)
  188. , m_fit(true)
  189. , m_alpha(false)
  190. , m_help(false)
  191. , m_info(false)
  192. , m_files(false)
  193. , m_sdf(false)
  194. , m_inLinear(false)
  195. {
  196. load();
  197. m_textureInfo.format = bgfx::TextureFormat::Count;
  198. }
  199. ~View()
  200. {
  201. }
  202. int32_t cmd(int32_t _argc, char const* const* _argv)
  203. {
  204. if (_argc >= 2)
  205. {
  206. if (0 == bx::strCmp(_argv[1], "mip") )
  207. {
  208. if (_argc >= 3)
  209. {
  210. uint32_t mip = m_mip;
  211. if (0 == bx::strCmp(_argv[2], "next") )
  212. {
  213. ++mip;
  214. }
  215. else if (0 == bx::strCmp(_argv[2], "prev") )
  216. {
  217. --mip;
  218. }
  219. else if (0 == bx::strCmp(_argv[2], "last") )
  220. {
  221. mip = INT32_MAX;
  222. }
  223. else
  224. {
  225. bx::fromString(&mip, _argv[2]);
  226. }
  227. m_mip = bx::uint32_iclamp(mip, 0, m_textureInfo.numMips-1);
  228. }
  229. else
  230. {
  231. m_mip = 0;
  232. }
  233. }
  234. else if (0 == bx::strCmp(_argv[1], "layer") )
  235. {
  236. if (_argc >= 3)
  237. {
  238. uint32_t layer = m_layer;
  239. if (0 == bx::strCmp(_argv[2], "next") )
  240. {
  241. ++layer;
  242. }
  243. else if (0 == bx::strCmp(_argv[2], "prev") )
  244. {
  245. --layer;
  246. }
  247. else if (0 == bx::strCmp(_argv[2], "last") )
  248. {
  249. layer = INT32_MAX;
  250. }
  251. else
  252. {
  253. bx::fromString(&layer, _argv[2]);
  254. }
  255. m_layer = bx::uint32_iclamp(layer, 0, m_textureInfo.numLayers-1);
  256. }
  257. else
  258. {
  259. m_layer = 0;
  260. }
  261. }
  262. else if (0 == bx::strCmp(_argv[1], "ev") )
  263. {
  264. if (_argc >= 3)
  265. {
  266. float ev = m_ev;
  267. bx::fromString(&ev, _argv[2]);
  268. m_ev = bx::clamp(ev, kEvMin, kEvMax);
  269. }
  270. else
  271. {
  272. m_ev = 0.0f;
  273. }
  274. }
  275. else if (0 == bx::strCmp(_argv[1], "pan") )
  276. {
  277. if (_argc >= 3)
  278. {
  279. if (_argc >= 4)
  280. {
  281. float yy;
  282. bx::fromString(&yy, _argv[3]);
  283. if (_argv[3][0] == '+'
  284. || _argv[3][0] == '-')
  285. {
  286. m_posy += yy;
  287. }
  288. else
  289. {
  290. m_posy = yy;
  291. }
  292. }
  293. float xx;
  294. bx::fromString(&xx, _argv[2]);
  295. if (_argv[2][0] == '+'
  296. || _argv[2][0] == '-')
  297. {
  298. m_posx += xx;
  299. }
  300. else
  301. {
  302. m_posx = xx;
  303. }
  304. }
  305. else
  306. {
  307. m_posx = 0.0f;
  308. m_posy = 0.0f;
  309. }
  310. }
  311. else if (0 == bx::strCmp(_argv[1], "cubemap") )
  312. {
  313. if (_argc >= 3)
  314. {
  315. if (_argc >= 4)
  316. {
  317. float yy;
  318. bx::fromString(&yy, _argv[3]);
  319. if (_argv[3][0] == '+'
  320. || _argv[3][0] == '-')
  321. {
  322. m_angy += bx::toRad(yy);
  323. }
  324. else
  325. {
  326. m_angy = bx::toRad(yy);
  327. }
  328. }
  329. float xx;
  330. bx::fromString(&xx, _argv[2]);
  331. if (_argv[2][0] == '+'
  332. || _argv[2][0] == '-')
  333. {
  334. m_angx += bx::toRad(xx);
  335. }
  336. else
  337. {
  338. m_angx = bx::toRad(xx);
  339. }
  340. }
  341. else
  342. {
  343. m_angx = 0.0f;
  344. m_angy = 0.0f;
  345. }
  346. }
  347. else if (0 == bx::strCmp(_argv[1], "zoom") )
  348. {
  349. if (_argc >= 3)
  350. {
  351. float zoom;
  352. bx::fromString(&zoom, _argv[2]);
  353. if (_argv[2][0] == '+'
  354. || _argv[2][0] == '-')
  355. {
  356. m_zoom += zoom;
  357. }
  358. else
  359. {
  360. m_zoom = zoom;
  361. }
  362. m_zoom = bx::clamp(m_zoom, 0.01f, 10.0f);
  363. }
  364. else
  365. {
  366. m_zoom = 1.0f;
  367. }
  368. }
  369. else if (0 == bx::strCmp(_argv[1], "rotate") )
  370. {
  371. if (_argc >= 3)
  372. {
  373. float angle;
  374. bx::fromString(&angle, _argv[2]);
  375. if (_argv[2][0] == '+'
  376. || _argv[2][0] == '-')
  377. {
  378. m_angle += bx::toRad(angle);
  379. }
  380. else
  381. {
  382. m_angle = bx::toRad(angle);
  383. }
  384. m_angle = bx::wrap(m_angle, bx::kPi*2.0f);
  385. }
  386. else
  387. {
  388. m_angle = 0.0f;
  389. }
  390. }
  391. else if (0 == bx::strCmp(_argv[1], "orientation") )
  392. {
  393. if (_argc >= 3)
  394. {
  395. float* dst = NULL;
  396. char axis = bx::toLower(_argv[2][0]);
  397. switch (axis)
  398. {
  399. case 'x': dst = &m_flipV; break;
  400. case 'y': dst = &m_flipH; break;
  401. case 'z': dst = &m_orientation; break;
  402. default: break;
  403. }
  404. if (NULL != dst)
  405. {
  406. if (_argc >= 4)
  407. {
  408. float angle;
  409. bx::fromString(&angle, _argv[3]);
  410. *dst = bx::toRad(angle);
  411. }
  412. else
  413. {
  414. *dst = 0.0f;
  415. }
  416. }
  417. }
  418. else
  419. {
  420. m_flipH = 0.0f;
  421. m_flipV = 0.0f;
  422. m_orientation = 0.0f;
  423. }
  424. }
  425. else if (0 == bx::strCmp(_argv[1], "transition") )
  426. {
  427. if (_argc >= 3)
  428. {
  429. float time;
  430. bx::fromString(&time, _argv[2]);
  431. m_transitionTime = bx::clamp(time, 0.0f, 5.0f);
  432. }
  433. else
  434. {
  435. m_transitionTime = 1.0f;
  436. }
  437. }
  438. else if (0 == bx::strCmp(_argv[1], "filter") )
  439. {
  440. if (_argc >= 3)
  441. {
  442. bx::fromString(&m_filter, _argv[2]);
  443. }
  444. else
  445. {
  446. m_filter ^= true;
  447. }
  448. }
  449. else if (0 == bx::strCmp(_argv[1], "fit") )
  450. {
  451. if (_argc >= 3)
  452. {
  453. bx::fromString(&m_fit, _argv[2]);
  454. }
  455. else
  456. {
  457. m_fit ^= true;
  458. }
  459. }
  460. else if (0 == bx::strCmp(_argv[1], "file-up") )
  461. {
  462. m_fileIndex = bx::uint32_satsub(m_fileIndex, 1);
  463. }
  464. else if (0 == bx::strCmp(_argv[1], "file-down") )
  465. {
  466. uint32_t numFiles = bx::uint32_satsub(uint32_t(m_fileList.size() ), 1);
  467. ++m_fileIndex;
  468. m_fileIndex = bx::uint32_min(m_fileIndex, numFiles);
  469. }
  470. else if (0 == bx::strCmp(_argv[1], "rgb") )
  471. {
  472. if (_argc >= 3)
  473. {
  474. if (_argv[2][0] == 'r')
  475. {
  476. m_abgr ^= 0x000000ff;
  477. }
  478. else if (_argv[2][0] == 'g')
  479. {
  480. m_abgr ^= 0x0000ff00;
  481. }
  482. else if (_argv[2][0] == 'b')
  483. {
  484. m_abgr ^= 0x00ff0000;
  485. }
  486. else if (_argv[2][0] == 'a')
  487. {
  488. m_alpha ^= true;
  489. }
  490. }
  491. else
  492. {
  493. m_abgr = UINT32_MAX;
  494. m_alpha = false;
  495. }
  496. }
  497. else if (0 == bx::strCmp(_argv[1], "sdf") )
  498. {
  499. m_sdf ^= true;
  500. }
  501. else if (0 == bx::strCmp(_argv[1], "geo") )
  502. {
  503. if (_argc >= 3)
  504. {
  505. if (bx::toLower(_argv[2][0]) == 'c')
  506. {
  507. m_cubeMapGeo = Geometry::Cross;
  508. }
  509. else if (bx::toLower(_argv[2][0]) == 'h')
  510. {
  511. m_cubeMapGeo = Geometry::Hexagon;
  512. }
  513. else
  514. {
  515. m_cubeMapGeo = Geometry::Quad;
  516. }
  517. }
  518. else
  519. {
  520. m_cubeMapGeo = Geometry::Enum( (m_cubeMapGeo + 1) % Geometry::Count);
  521. }
  522. }
  523. else if (0 == bx::strCmp(_argv[1], "help") )
  524. {
  525. m_help ^= true;
  526. }
  527. else if (0 == bx::strCmp(_argv[1], "save") )
  528. {
  529. save();
  530. }
  531. else if (0 == bx::strCmp(_argv[1], "info") )
  532. {
  533. m_info ^= true;
  534. }
  535. else if (0 == bx::strCmp(_argv[1], "files") )
  536. {
  537. m_files ^= true;
  538. }
  539. }
  540. return 0;
  541. }
  542. static bool sortNameAscending(const std::string& _lhs, const std::string& _rhs)
  543. {
  544. return 0 > bx::strCmpV(_lhs.c_str(), _rhs.c_str() );
  545. }
  546. void updateFileList(const bx::FilePath& _filePath)
  547. {
  548. DIR* dir = opendir(_filePath.get() );
  549. if (NULL == dir)
  550. {
  551. m_path = _filePath.getPath();
  552. dir = opendir(m_path.get() );
  553. }
  554. else
  555. {
  556. m_path = _filePath;
  557. }
  558. if (NULL != dir)
  559. {
  560. for (dirent* item = readdir(dir); NULL != item; item = readdir(dir) )
  561. {
  562. if (0 == (item->d_type & DT_DIR) )
  563. {
  564. const char* ext = bx::strRFind(item->d_name, '.');
  565. if (NULL != ext)
  566. {
  567. ext += 1;
  568. bool supported = false;
  569. for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
  570. {
  571. if (0 == bx::strCmpI(ext, s_supportedExt[ii]) )
  572. {
  573. supported = true;
  574. break;
  575. }
  576. }
  577. if (supported)
  578. {
  579. m_fileList.push_back(item->d_name);
  580. }
  581. }
  582. }
  583. }
  584. std::sort(m_fileList.begin(), m_fileList.end(), sortNameAscending);
  585. m_fileIndex = 0;
  586. uint32_t idx = 0;
  587. for (FileList::const_iterator it = m_fileList.begin(); it != m_fileList.end(); ++it, ++idx)
  588. {
  589. if (0 == bx::strCmpI(it->c_str(), _filePath.getFileName() ) )
  590. {
  591. // If it is case-insensitive match then might be correct one, but keep
  592. // searching.
  593. m_fileIndex = idx;
  594. if (0 == bx::strCmp(it->c_str(), _filePath.getFileName() ) )
  595. {
  596. // If it is exact match we're done.
  597. break;
  598. }
  599. }
  600. }
  601. closedir(dir);
  602. }
  603. }
  604. void load()
  605. {
  606. bx::FilePath filePath(bx::Dir::Home);
  607. filePath.join(".config/bgfx/texturev.ini");
  608. bx::Settings settings(entry::getAllocator() );
  609. bx::FileReader reader;
  610. if (bx::open(&reader, filePath) )
  611. {
  612. bx::read(&reader, settings);
  613. bx::close(&reader);
  614. if (!bx::fromString(&m_transitionTime, settings.get("view/transition") ) )
  615. {
  616. m_transitionTime = 1.0f;
  617. }
  618. }
  619. }
  620. void save()
  621. {
  622. bx::FilePath filePath(bx::Dir::Home);
  623. filePath.join(".config/bgfx/texturev.ini");
  624. if (bx::makeAll(filePath.getPath() ) )
  625. {
  626. bx::Settings settings(entry::getAllocator() );
  627. char tmp[256];
  628. bx::toString(tmp, sizeof(tmp), m_transitionTime);
  629. settings.set("view/transition", tmp);
  630. bx::FileWriter writer;
  631. if (bx::open(&writer, filePath) )
  632. {
  633. bx::write(&writer, settings);
  634. bx::close(&writer);
  635. }
  636. }
  637. }
  638. bx::FilePath m_path;
  639. typedef stl::vector<std::string> FileList;
  640. FileList m_fileList;
  641. bgfx::TextureInfo m_textureInfo;
  642. Geometry::Enum m_cubeMapGeo;
  643. uint32_t m_fileIndex;
  644. uint32_t m_scaleFn;
  645. uint32_t m_mip;
  646. uint32_t m_layer;
  647. uint32_t m_abgr;
  648. float m_ev;
  649. float m_evMin;
  650. float m_evMax;
  651. float m_posx;
  652. float m_posy;
  653. float m_angx;
  654. float m_angy;
  655. float m_zoom;
  656. float m_angle;
  657. float m_orientation;
  658. float m_flipH;
  659. float m_flipV;
  660. float m_transitionTime;
  661. bool m_filter;
  662. bool m_fit;
  663. bool m_alpha;
  664. bool m_help;
  665. bool m_info;
  666. bool m_files;
  667. bool m_sdf;
  668. bool m_inLinear;
  669. };
  670. int cmdView(CmdContext* /*_context*/, void* _userData, int _argc, char const* const* _argv)
  671. {
  672. View* view = static_cast<View*>(_userData);
  673. return view->cmd(_argc, _argv);
  674. }
  675. struct PosUvwColorVertex
  676. {
  677. float m_x;
  678. float m_y;
  679. float m_u;
  680. float m_v;
  681. float m_w;
  682. uint32_t m_abgr;
  683. static void init()
  684. {
  685. ms_decl
  686. .begin()
  687. .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
  688. .add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float)
  689. .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
  690. .end();
  691. }
  692. void set(float _x, float _y, float _u, float _v, float _w, uint32_t _abgr)
  693. {
  694. m_x = _x;
  695. m_y = _y;
  696. m_u = _u;
  697. m_v = _v;
  698. m_w = _w;
  699. m_abgr = _abgr;
  700. }
  701. static bgfx::VertexDecl ms_decl;
  702. };
  703. bgfx::VertexDecl PosUvwColorVertex::ms_decl;
  704. static uint32_t addQuad(uint16_t* _indices, uint16_t _idx0, uint16_t _idx1, uint16_t _idx2, uint16_t _idx3)
  705. {
  706. _indices[0] = _idx0;
  707. _indices[1] = _idx3;
  708. _indices[2] = _idx1;
  709. _indices[3] = _idx1;
  710. _indices[4] = _idx3;
  711. _indices[5] = _idx2;
  712. return 6;
  713. }
  714. void setGeometry(
  715. Geometry::Enum _type
  716. , int32_t _x
  717. , int32_t _y
  718. , uint32_t _width
  719. , uint32_t _height
  720. , uint32_t _abgr
  721. , float _maxu = 1.0f
  722. , float _maxv = 1.0f
  723. )
  724. {
  725. if (Geometry::Quad == _type)
  726. {
  727. if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvwColorVertex::ms_decl) )
  728. {
  729. bgfx::TransientVertexBuffer vb;
  730. bgfx::allocTransientVertexBuffer(&vb, 6, PosUvwColorVertex::ms_decl);
  731. PosUvwColorVertex* vertex = (PosUvwColorVertex*)vb.data;
  732. const float widthf = float(_width);
  733. const float heightf = float(_height);
  734. const float minx = float(_x);
  735. const float miny = float(_y);
  736. const float maxx = minx+widthf;
  737. const float maxy = miny+heightf;
  738. const float minu = 0.0f;
  739. const float maxu = _maxu;
  740. const float minv = 0.0f;
  741. const float maxv = _maxv;
  742. vertex->set(minx, miny, minu, minv, 0.0f, _abgr); ++vertex;
  743. vertex->set(maxx, miny, maxu, minv, 0.0f, _abgr); ++vertex;
  744. vertex->set(maxx, maxy, maxu, maxv, 0.0f, _abgr); ++vertex;
  745. vertex->set(maxx, maxy, maxu, maxv, 0.0f, _abgr); ++vertex;
  746. vertex->set(minx, maxy, minu, maxv, 0.0f, _abgr); ++vertex;
  747. vertex->set(minx, miny, minu, minv, 0.0f, _abgr); ++vertex;
  748. bgfx::setVertexBuffer(0, &vb);
  749. }
  750. }
  751. else
  752. {
  753. const uint32_t numVertices = 14;
  754. const uint32_t numIndices = 36;
  755. if (checkAvailTransientBuffers(numVertices, PosUvwColorVertex::ms_decl, numIndices) )
  756. {
  757. bgfx::TransientVertexBuffer tvb;
  758. bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosUvwColorVertex::ms_decl);
  759. bgfx::TransientIndexBuffer tib;
  760. bgfx::allocTransientIndexBuffer(&tib, numIndices);
  761. PosUvwColorVertex* vertex = (PosUvwColorVertex*)tvb.data;
  762. uint16_t* indices = (uint16_t*)tib.data;
  763. if (Geometry::Cross == _type)
  764. {
  765. const float sx = _width /1.5f;
  766. const float sy = _height/1.5f;
  767. const float px = float(_x)-sx/4.0f;
  768. const float py = float(_y);
  769. vertex->set(0.0f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  770. vertex->set(0.0f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  771. vertex->set(0.5f*sx+px, 0.0f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  772. vertex->set(0.5f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  773. vertex->set(0.5f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, 1.0f, _abgr); ++vertex;
  774. vertex->set(0.5f*sx+px, 1.5f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  775. vertex->set(1.0f*sx+px, 0.0f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  776. vertex->set(1.0f*sx+px, 0.5f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  777. vertex->set(1.0f*sx+px, 1.0f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
  778. vertex->set(1.0f*sx+px, 1.5f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  779. vertex->set(1.5f*sx+px, 0.5f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  780. vertex->set(1.5f*sx+px, 1.0f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  781. vertex->set(2.0f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  782. vertex->set(2.0f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  783. indices += addQuad(indices, 0, 3, 4, 1);
  784. indices += addQuad(indices, 2, 6, 7, 3);
  785. indices += addQuad(indices, 3, 7, 8, 4);
  786. indices += addQuad(indices, 4, 8, 9, 5);
  787. indices += addQuad(indices, 7, 10, 11, 8);
  788. indices += addQuad(indices, 10, 12, 13, 11);
  789. }
  790. else
  791. {
  792. const float sx = float(_width);
  793. const float sy = float(_height);
  794. const float px = float(_x) - sx/2.0f;
  795. const float py = float(_y);
  796. vertex->set(0.0f*sx+px, 0.25f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  797. vertex->set(0.0f*sx+px, 0.75f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  798. vertex->set(0.5f*sx+px, 0.00f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  799. vertex->set(0.5f*sx+px, 0.50f*sy+py, -1.0f, -1.0f, 1.0f, _abgr); ++vertex;
  800. vertex->set(0.5f*sx+px, 1.00f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  801. vertex->set(1.0f*sx+px, 0.25f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  802. vertex->set(1.0f*sx+px, 0.75f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
  803. vertex->set(1.0f*sx+px, 0.25f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  804. vertex->set(1.0f*sx+px, 0.75f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
  805. vertex->set(1.5f*sx+px, 0.00f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
  806. vertex->set(1.5f*sx+px, 0.50f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  807. vertex->set(1.5f*sx+px, 1.00f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  808. vertex->set(2.0f*sx+px, 0.25f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
  809. vertex->set(2.0f*sx+px, 0.75f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
  810. indices += addQuad(indices, 0, 2, 3, 1);
  811. indices += addQuad(indices, 1, 3, 6, 4);
  812. indices += addQuad(indices, 2, 5, 6, 3);
  813. indices += addQuad(indices, 7, 9, 12, 10);
  814. indices += addQuad(indices, 7, 10, 11, 8);
  815. indices += addQuad(indices, 10, 12, 13, 11);
  816. }
  817. bgfx::setVertexBuffer(0, &tvb);
  818. bgfx::setIndexBuffer(&tib);
  819. }
  820. }
  821. }
  822. template<bx::LerpFn lerpT, bx::EaseFn easeT>
  823. struct InterpolatorT
  824. {
  825. float from;
  826. float to;
  827. float duration;
  828. int64_t offset;
  829. InterpolatorT(float _value)
  830. {
  831. reset(_value);
  832. }
  833. void reset(float _value)
  834. {
  835. from = _value;
  836. to = _value;
  837. duration = 0.0;
  838. offset = bx::getHPCounter();
  839. }
  840. void set(float _value, float _duration)
  841. {
  842. if (_value != to)
  843. {
  844. from = getValue();
  845. to = _value;
  846. duration = _duration;
  847. offset = bx::getHPCounter();
  848. }
  849. }
  850. float getValue()
  851. {
  852. if (duration > 0.0)
  853. {
  854. const double freq = double(bx::getHPFrequency() );
  855. int64_t now = bx::getHPCounter();
  856. float time = (float)(double(now - offset) / freq);
  857. float lerp = bx::clamp(time, 0.0f, duration) / duration;
  858. return lerpT(from, to, easeT(lerp) );
  859. }
  860. return to;
  861. }
  862. };
  863. typedef InterpolatorT<bx::lerp, bx::easeInOutQuad> Interpolator;
  864. typedef InterpolatorT<bx::angleLerp, bx::easeInOutCubic> InterpolatorAngle;
  865. typedef InterpolatorT<bx::lerp, bx::easeLinear> InterpolatorLinear;
  866. void keyBindingHelp(const char* _bindings, const char* _description)
  867. {
  868. ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), _bindings);
  869. ImGui::SameLine(100);
  870. ImGui::Text(_description);
  871. }
  872. void associate()
  873. {
  874. #if BX_PLATFORM_WINDOWS
  875. std::string str;
  876. char exec[MAX_PATH];
  877. GetModuleFileNameA(GetModuleHandleA(NULL), exec, MAX_PATH);
  878. std::string strExec = bx::replaceAll<std::string>(exec, "\\", "\\\\");
  879. std::string value;
  880. bx::stringPrintf(value, "@=\"\\\"%s\\\" \\\"%%1\\\"\"\r\n\r\n", strExec.c_str() );
  881. str += "Windows Registry Editor Version 5.00\r\n\r\n";
  882. str += "[HKEY_CLASSES_ROOT\\texturev\\shell\\open\\command]\r\n";
  883. str += value;
  884. str += "[HKEY_CLASSES_ROOT\\Applications\\texturev.exe\\shell\\open\\command]\r\n";
  885. str += value;
  886. for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
  887. {
  888. const char* ext = s_supportedExt[ii];
  889. bx::stringPrintf(str, "[-HKEY_CLASSES_ROOT\\.%s]\r\n\r\n", ext);
  890. bx::stringPrintf(str, "[-HKEY_CURRENT_USER\\Software\\Classes\\.%s]\r\n\r\n", ext);
  891. bx::stringPrintf(str, "[HKEY_CLASSES_ROOT\\.%s]\r\n@=\"texturev\"\r\n\r\n", ext);
  892. bx::stringPrintf(str, "[HKEY_CURRENT_USER\\Software\\Classes\\.%s]\r\n@=\"texturev\"\r\n\r\n", ext);
  893. }
  894. bx::FilePath filePath(bx::Dir::Temp);
  895. filePath.join("texture.reg");
  896. bx::FileWriter writer;
  897. bx::Error err;
  898. if (bx::open(&writer, filePath, false, &err) )
  899. {
  900. bx::write(&writer, str.c_str(), uint32_t(str.length()), &err);
  901. bx::close(&writer);
  902. if (err.isOk() )
  903. {
  904. std::string cmd;
  905. bx::stringPrintf(cmd, "/s %s", filePath.get() );
  906. bx::ProcessReader reader;
  907. if (bx::open(&reader, "regedit.exe", cmd.c_str(), &err) )
  908. {
  909. bx::close(&reader);
  910. }
  911. }
  912. }
  913. #elif BX_PLATFORM_LINUX
  914. std::string str;
  915. str += "#/bin/bash\n\n";
  916. for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
  917. {
  918. const char* ext = s_supportedExt[ii];
  919. bx::stringPrintf(str, "xdg-mime default texturev.desktop image/%s\n", ext);
  920. }
  921. bx::stringPrintf(str, "xdg-mime default texturev.desktop image/x-dds\n");
  922. str += "\n";
  923. bx::FileWriter writer;
  924. bx::Error err;
  925. if (bx::open(&writer, "/tmp/texturev.sh", false, &err) )
  926. {
  927. bx::write(&writer, str.c_str(), uint32_t(str.length()), &err);
  928. bx::close(&writer);
  929. if (err.isOk() )
  930. {
  931. bx::ProcessReader reader;
  932. if (bx::open(&reader, "/bin/bash", "/tmp/texturev.sh", &err) )
  933. {
  934. bx::close(&reader);
  935. }
  936. }
  937. }
  938. #endif // BX_PLATFORM_WINDOWS
  939. }
  940. void help(const char* _error = NULL)
  941. {
  942. if (NULL != _error)
  943. {
  944. fprintf(stderr, "Error:\n%s\n\n", _error);
  945. }
  946. fprintf(stderr
  947. , "texturev, bgfx texture viewer tool, version %d.%d.%d.\n"
  948. "Copyright 2011-2018 Branimir Karadzic. All rights reserved.\n"
  949. "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n\n"
  950. , BGFX_TEXTUREV_VERSION_MAJOR
  951. , BGFX_TEXTUREV_VERSION_MINOR
  952. , BGFX_API_VERSION
  953. );
  954. fprintf(stderr
  955. , "Usage: texturev <file path>\n"
  956. "\n"
  957. "Supported input file types:\n"
  958. );
  959. for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
  960. {
  961. fprintf(stderr, " *.%s\n", s_supportedExt[ii]);
  962. }
  963. fprintf(stderr
  964. , "\n"
  965. "Options:\n"
  966. " -h, --help Help.\n"
  967. " -v, --version Version information only.\n"
  968. " --associate Associate file extensions with texturev.\n"
  969. "\n"
  970. "For additional information, see https://github.com/bkaradzic/bgfx\n"
  971. );
  972. }
  973. int _main_(int _argc, char** _argv)
  974. {
  975. bx::CommandLine cmdLine(_argc, _argv);
  976. if (cmdLine.hasArg('v', "version") )
  977. {
  978. fprintf(stderr
  979. , "texturev, bgfx texture viewer tool, version %d.%d.%d.\n"
  980. , BGFX_TEXTUREV_VERSION_MAJOR
  981. , BGFX_TEXTUREV_VERSION_MINOR
  982. , BGFX_API_VERSION
  983. );
  984. return bx::kExitSuccess;
  985. }
  986. if (cmdLine.hasArg('h', "help") )
  987. {
  988. help();
  989. return bx::kExitFailure;
  990. }
  991. else if (cmdLine.hasArg("associate") )
  992. {
  993. associate();
  994. return bx::kExitFailure;
  995. }
  996. uint32_t width = 1280;
  997. uint32_t height = 720;
  998. uint32_t debug = BGFX_DEBUG_TEXT;
  999. uint32_t reset = BGFX_RESET_VSYNC;
  1000. inputAddBindings(s_bindingName[Binding::App], s_binding[Binding::App]);
  1001. inputAddBindings(s_bindingName[Binding::View], s_binding[Binding::View]);
  1002. View view;
  1003. cmdAdd("view", cmdView, &view);
  1004. entry::setWindowFlags(entry::WindowHandle{0}, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false);
  1005. bgfx::init();
  1006. bgfx::reset(width, height, reset);
  1007. // Set view 0 clear state.
  1008. bgfx::setViewClear(BACKGROUND_VIEW_ID
  1009. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  1010. , 0x000000ff
  1011. , 1.0f
  1012. , 0
  1013. );
  1014. imguiCreate();
  1015. PosUvwColorVertex::init();
  1016. const bgfx::Caps* caps = bgfx::getCaps();
  1017. bgfx::RendererType::Enum type = caps->rendererType;
  1018. bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
  1019. bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4);
  1020. bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4);
  1021. bgfx::ShaderHandle vsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture");
  1022. bgfx::ShaderHandle fsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture");
  1023. bgfx::ShaderHandle fsTextureArray = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_array");
  1024. bgfx::ProgramHandle textureProgram = bgfx::createProgram(
  1025. vsTexture
  1026. , fsTexture
  1027. , true
  1028. );
  1029. bgfx::ProgramHandle textureArrayProgram = bgfx::createProgram(
  1030. vsTexture
  1031. , bgfx::isValid(fsTextureArray)
  1032. ? fsTextureArray
  1033. : fsTexture
  1034. , true
  1035. );
  1036. bgfx::ProgramHandle textureCubeProgram = bgfx::createProgram(
  1037. bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture_cube")
  1038. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_cube")
  1039. , true
  1040. );
  1041. bgfx::ProgramHandle textureCube2Program = bgfx::createProgram(
  1042. vsTexture
  1043. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_cube2")
  1044. , true
  1045. );
  1046. bgfx::ProgramHandle textureSdfProgram = bgfx::createProgram(
  1047. vsTexture
  1048. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_sdf")
  1049. , true
  1050. );
  1051. bgfx::ProgramHandle textureMsdfProgram = bgfx::createProgram(
  1052. vsTexture
  1053. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_msdf")
  1054. , true
  1055. );
  1056. bgfx::ProgramHandle texture3DProgram = bgfx::createProgram(
  1057. vsTexture
  1058. , bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_3d")
  1059. , true
  1060. );
  1061. const uint32_t checkerBoardSize = 64;
  1062. bgfx::TextureHandle checkerBoard;
  1063. {
  1064. const bgfx::Memory* mem = bgfx::alloc(checkerBoardSize*checkerBoardSize*4);
  1065. bimg::imageCheckerboard(mem->data, checkerBoardSize, checkerBoardSize, 8, 0xff8e8e8e, 0xff5d5d5d);
  1066. checkerBoard = bgfx::createTexture2D(checkerBoardSize, checkerBoardSize, false, 1
  1067. , bgfx::TextureFormat::BGRA8
  1068. , 0
  1069. | BGFX_TEXTURE_MIN_POINT
  1070. | BGFX_TEXTURE_MIP_POINT
  1071. | BGFX_TEXTURE_MAG_POINT
  1072. , mem
  1073. );
  1074. }
  1075. float speed = 0.37f;
  1076. float time = 0.0f;
  1077. Interpolator mip(0.0f);
  1078. Interpolator layer(0.0f);
  1079. InterpolatorLinear ev(0.0f);
  1080. Interpolator zoom(1.0f);
  1081. Interpolator scale(1.0f);
  1082. Interpolator posx(0.0f);
  1083. Interpolator posy(0.0f);
  1084. InterpolatorAngle angle(0.0f);
  1085. InterpolatorAngle angx(0.0f);
  1086. InterpolatorAngle angy(0.0f);
  1087. const char* filePath = _argc < 2 ? "" : _argv[1];
  1088. std::string path = filePath;
  1089. {
  1090. bx::FilePath fp(filePath);
  1091. view.updateFileList(fp);
  1092. }
  1093. int exitcode = bx::kExitSuccess;
  1094. bgfx::TextureHandle texture = BGFX_INVALID_HANDLE;
  1095. {
  1096. uint32_t fileIndex = 0;
  1097. bool dragging = false;
  1098. entry::WindowState windowState;
  1099. entry::MouseState mouseStatePrev;
  1100. while (!entry::processWindowEvents(windowState, debug, reset) )
  1101. {
  1102. const entry::MouseState& mouseState = windowState.m_mouse;
  1103. width = windowState.m_width;
  1104. height = windowState.m_height;
  1105. if (!windowState.m_dropFile.isEmpty() )
  1106. {
  1107. view.updateFileList(windowState.m_dropFile);
  1108. windowState.m_dropFile.clear();
  1109. }
  1110. imguiBeginFrame(mouseState.m_mx
  1111. , mouseState.m_my
  1112. , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
  1113. | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
  1114. | (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
  1115. , mouseState.m_mz
  1116. , uint16_t(width)
  1117. , uint16_t(height)
  1118. );
  1119. static bool help = false;
  1120. static bool mouseDelta = false;
  1121. if (!mouseDelta)
  1122. {
  1123. mouseStatePrev = mouseState;
  1124. mouseDelta = true;
  1125. }
  1126. int32_t zoomDelta = mouseState.m_mz - mouseStatePrev.m_mz;
  1127. if (zoomDelta != 0)
  1128. {
  1129. char exec[64];
  1130. bx::snprintf(exec, BX_COUNTOF(exec), "view zoom %+f", -zoomDelta*0.1f);
  1131. cmdExec(exec);
  1132. }
  1133. const float xDelta = float(mouseStatePrev.m_mx - mouseState.m_mx);
  1134. const float yDelta = float(mouseStatePrev.m_my - mouseState.m_my);
  1135. if (!ImGui::MouseOverArea()
  1136. && !help
  1137. && mouseState.m_buttons[entry::MouseButton::Left] != mouseStatePrev.m_buttons[entry::MouseButton::Left])
  1138. {
  1139. dragging = !!mouseState.m_buttons[entry::MouseButton::Left];
  1140. }
  1141. if (dragging)
  1142. {
  1143. if (view.m_textureInfo.cubeMap
  1144. && Geometry::Quad == view.m_cubeMapGeo)
  1145. {
  1146. char exec[64];
  1147. bx::snprintf(exec, BX_COUNTOF(exec), "view cubemap %+f %+f", -yDelta, -xDelta);
  1148. cmdExec(exec);
  1149. }
  1150. else
  1151. {
  1152. char exec[64];
  1153. bx::snprintf(exec, BX_COUNTOF(exec), "view pan %+f %+f", xDelta, yDelta);
  1154. cmdExec(exec);
  1155. }
  1156. }
  1157. mouseStatePrev = mouseState;
  1158. if (ImGui::BeginPopupContextVoid("Menu") )
  1159. {
  1160. if (ImGui::MenuItem("Files", NULL, view.m_files) )
  1161. {
  1162. cmdExec("view files");
  1163. }
  1164. if (ImGui::MenuItem("Info", NULL, view.m_info) )
  1165. {
  1166. cmdExec("view info");
  1167. }
  1168. // if (ImGui::MenuItem("Save As") )
  1169. {
  1170. }
  1171. if (ImGui::MenuItem("Reset") )
  1172. {
  1173. cmdExec(s_resetCmd);
  1174. }
  1175. ImGui::Separator();
  1176. if (ImGui::BeginMenu("Options"))
  1177. {
  1178. bool filter = view.m_filter;
  1179. if (ImGui::MenuItem("Filter", NULL, &filter) )
  1180. {
  1181. cmdExec("view filter");
  1182. }
  1183. bool animate = 0.0f < view.m_transitionTime;
  1184. if (ImGui::MenuItem("Animate", NULL, &animate) )
  1185. {
  1186. cmdExec("view transition %f", animate ? 1.0f : 0.0f);
  1187. }
  1188. if (ImGui::BeginMenu("Cubemap", view.m_textureInfo.cubeMap) )
  1189. {
  1190. if (ImGui::MenuItem("Quad", NULL, Geometry::Quad == view.m_cubeMapGeo) )
  1191. {
  1192. cmdExec("view geo quad");
  1193. }
  1194. if (ImGui::MenuItem("Cross", NULL, Geometry::Cross == view.m_cubeMapGeo) )
  1195. {
  1196. cmdExec("view geo cross");
  1197. }
  1198. if (ImGui::MenuItem("Hexagon", NULL, Geometry::Hexagon == view.m_cubeMapGeo) )
  1199. {
  1200. cmdExec("view geo hexagon");
  1201. }
  1202. ImGui::EndMenu();
  1203. }
  1204. bool sdf = view.m_sdf;
  1205. if (ImGui::MenuItem("SDF", NULL, &sdf) )
  1206. {
  1207. cmdExec("view sdf");
  1208. }
  1209. bool rr = 0 != (view.m_abgr & 0x000000ff);
  1210. if (ImGui::MenuItem("R", NULL, &rr) )
  1211. {
  1212. cmdExec("view rgb r");
  1213. }
  1214. bool gg = 0 != (view.m_abgr & 0x0000ff00);
  1215. if (ImGui::MenuItem("G", NULL, &gg) )
  1216. {
  1217. cmdExec("view rgb g");
  1218. }
  1219. bool bb = 0 != (view.m_abgr & 0x00ff0000);
  1220. if (ImGui::MenuItem("B", NULL, &bb) )
  1221. {
  1222. cmdExec("view rgb b");
  1223. }
  1224. bool alpha = view.m_alpha;
  1225. if (ImGui::MenuItem("Checkerboard", NULL, &alpha) )
  1226. {
  1227. cmdExec("view rgb a");
  1228. }
  1229. ImGui::Separator();
  1230. if (ImGui::MenuItem("Save Options") )
  1231. {
  1232. cmdExec("view save");
  1233. }
  1234. ImGui::EndMenu();
  1235. }
  1236. ImGui::Separator();
  1237. if (ImGui::MenuItem("Help") )
  1238. {
  1239. cmdExec("view help");
  1240. }
  1241. ImGui::Separator();
  1242. if (ImGui::MenuItem("Exit") )
  1243. {
  1244. cmdExec("exit");
  1245. }
  1246. ImGui::EndPopup();
  1247. }
  1248. if (help != view.m_help)
  1249. {
  1250. if (!help)
  1251. {
  1252. ImGui::OpenPopup("Help");
  1253. inputRemoveBindings(s_bindingName[Binding::View]);
  1254. inputAddBindings(s_bindingName[Binding::Help], s_binding[Binding::Help]);
  1255. }
  1256. else
  1257. {
  1258. inputRemoveBindings(s_bindingName[Binding::Help]);
  1259. inputAddBindings(s_bindingName[Binding::View], s_binding[Binding::View]);
  1260. }
  1261. help = view.m_help;
  1262. }
  1263. if (view.m_info)
  1264. {
  1265. ImGui::SetNextWindowSize(
  1266. ImVec2(300.0f, 300.0f)
  1267. , ImGuiCond_FirstUseEver
  1268. );
  1269. if (ImGui::Begin("Info", NULL, ImGuiWindowFlags_AlwaysAutoResize) )
  1270. {
  1271. if (ImGui::BeginChild("##info", ImVec2(0.0f, 0.0f) ) )
  1272. {
  1273. if (!bgfx::isValid(texture) )
  1274. {
  1275. ImGui::Text("Texture is not loaded.");
  1276. }
  1277. else
  1278. {
  1279. ImGui::Text("Dimensions: %d x %d"
  1280. , view.m_textureInfo.width
  1281. , view.m_textureInfo.height
  1282. );
  1283. ImGui::Text("Format: %s"
  1284. , bimg::getName(bimg::TextureFormat::Enum(view.m_textureInfo.format) )
  1285. );
  1286. uint32_t numLayers = view.m_textureInfo.numLayers;
  1287. if (1 < view.m_textureInfo.depth)
  1288. {
  1289. numLayers = bx::max(1, view.m_textureInfo.depth >> view.m_mip);
  1290. }
  1291. view.m_layer = bx::clamp<int32_t>(view.m_layer, 0, numLayers - 1);
  1292. ImGui::SliderInt("Layer", (int32_t*)&view.m_layer, 0, numLayers - 1);
  1293. ImGui::SliderInt("Mip", (int32_t*)&view.m_mip, 0, view.m_textureInfo.numMips - 1);
  1294. ImGui::Separator();
  1295. ImGui::Checkbox("Input linear", &view.m_inLinear);
  1296. ImGui::RangeSliderFloat("EV range", &view.m_evMin, &view.m_evMax, kEvMin, kEvMax);
  1297. ImGui::SliderFloat("EV", &view.m_ev, view.m_evMin, view.m_evMax);
  1298. ImGui::Separator();
  1299. ImGui::Checkbox("Fit to window", &view.m_fit);
  1300. ImGui::SliderFloat("Scale", &view.m_zoom, 0.01f, 10.0f);
  1301. }
  1302. ImGui::EndChild();
  1303. }
  1304. ImGui::End();
  1305. }
  1306. }
  1307. if (view.m_files)
  1308. {
  1309. char temp[bx::kMaxFilePath];
  1310. bx::snprintf(temp, BX_COUNTOF(temp), "%s##File", view.m_path.get() );
  1311. ImGui::SetNextWindowSize(
  1312. ImVec2(400.0f, 400.0f)
  1313. , ImGuiCond_FirstUseEver
  1314. );
  1315. if (ImGui::Begin(temp, NULL) )
  1316. {
  1317. if (ImGui::BeginChild("##file_list", ImVec2(0.0f, 0.0f) ) )
  1318. {
  1319. ImGui::PushFont(ImGui::Font::Mono);
  1320. const float itemHeight = ImGui::GetTextLineHeightWithSpacing();
  1321. const float listHeight =
  1322. bx::max(1.0f, bx::floor(ImGui::GetWindowHeight()/itemHeight) )
  1323. * itemHeight
  1324. ;
  1325. ImGui::PushItemWidth(-1);
  1326. if (ImGui::ListBoxHeader("##empty", ImVec2(0.0f, listHeight) ) )
  1327. {
  1328. const int32_t itemCount = int32_t(view.m_fileList.size() );
  1329. int32_t start, end;
  1330. ImGui::CalcListClipping(itemCount, itemHeight, &start, &end);
  1331. const int32_t index = int32_t(view.m_fileIndex);
  1332. if (index <= start)
  1333. {
  1334. ImGui::SetScrollY(ImGui::GetScrollY() - (start-index+1)*itemHeight);
  1335. }
  1336. else if (index >= end)
  1337. {
  1338. ImGui::SetScrollY(ImGui::GetScrollY() + (index-end+1)*itemHeight);
  1339. }
  1340. ImGuiListClipper clipper(itemCount, itemHeight);
  1341. for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos)
  1342. {
  1343. ImGui::PushID(pos);
  1344. bool isSelected = uint32_t(pos) == view.m_fileIndex;
  1345. if (ImGui::Selectable(view.m_fileList[pos].c_str(), &isSelected) )
  1346. {
  1347. view.m_fileIndex = pos;
  1348. }
  1349. ImGui::PopID();
  1350. }
  1351. clipper.End();
  1352. ImGui::ListBoxFooter();
  1353. }
  1354. ImGui::PopFont();
  1355. ImGui::EndChild();
  1356. }
  1357. ImGui::End();
  1358. }
  1359. }
  1360. if (ImGui::BeginPopupModal("Help", NULL, ImGuiWindowFlags_AlwaysAutoResize) )
  1361. {
  1362. ImGui::SetWindowFontScale(1.0f);
  1363. ImGui::Text(
  1364. "texturev, bgfx texture viewer tool " ICON_KI_WRENCH ", version %d.%d.%d.\n"
  1365. "Copyright 2011-2018 Branimir Karadzic. All rights reserved.\n"
  1366. "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n"
  1367. , BGFX_TEXTUREV_VERSION_MAJOR
  1368. , BGFX_TEXTUREV_VERSION_MINOR
  1369. , BGFX_API_VERSION
  1370. );
  1371. ImGui::Separator();
  1372. ImGui::NextLine();
  1373. ImGui::Text("Key bindings:\n\n");
  1374. ImGui::PushFont(ImGui::Font::Mono);
  1375. keyBindingHelp("ESC", "Exit.");
  1376. keyBindingHelp("h", "Toggle help screen.");
  1377. keyBindingHelp("f", "Toggle full-screen.");
  1378. ImGui::NextLine();
  1379. keyBindingHelp("LMB+drag", "Pan.");
  1380. keyBindingHelp("=/- or MW", "Zoom in/out.");
  1381. keyBindingHelp("z/Z", "Rotate.");
  1382. keyBindingHelp("0", "Reset.");
  1383. keyBindingHelp("1", "Fit to window.");
  1384. ImGui::NextLine();
  1385. keyBindingHelp("<", "Reset MIP level.");
  1386. keyBindingHelp(",/,", "MIP level up/down.");
  1387. keyBindingHelp("/", "Toggle linear/point texture sampling.");
  1388. keyBindingHelp("[space]", "Change cubemap mode.");
  1389. ImGui::NextLine();
  1390. keyBindingHelp("left", "Previous layer in texture array.");
  1391. keyBindingHelp("right", "Next layer in texture array.");
  1392. ImGui::NextLine();
  1393. keyBindingHelp("up", "Previous texture.");
  1394. keyBindingHelp("down", "Next texture.");
  1395. ImGui::NextLine();
  1396. keyBindingHelp("r/g/b", "Toggle R, G, or B color channel.");
  1397. keyBindingHelp("a", "Toggle alpha blending.");
  1398. ImGui::NextLine();
  1399. keyBindingHelp("s", "Toggle Multi-channel SDF rendering");
  1400. ImGui::NextLine();
  1401. ImGui::PopFont();
  1402. ImGui::Dummy(ImVec2(0.0f, 0.0f) );
  1403. ImGui::SameLine(ImGui::GetWindowWidth() - 136.0f);
  1404. if (ImGui::Button("Close", ImVec2(128.0f, 0.0f) )
  1405. || !view.m_help)
  1406. {
  1407. view.m_help = false;
  1408. ImGui::CloseCurrentPopup();
  1409. }
  1410. ImGui::EndPopup();
  1411. }
  1412. imguiEndFrame();
  1413. if ( (!bgfx::isValid(texture) || view.m_fileIndex != fileIndex)
  1414. && 0 != view.m_fileList.size() )
  1415. {
  1416. if (bgfx::isValid(texture) )
  1417. {
  1418. bgfx::destroy(texture);
  1419. }
  1420. fileIndex = view.m_fileIndex;
  1421. bx::FilePath fp = view.m_path;
  1422. fp.join(view.m_fileList[view.m_fileIndex].c_str() );
  1423. bimg::Orientation::Enum orientation;
  1424. texture = loadTexture(fp.get()
  1425. , 0
  1426. | BGFX_TEXTURE_U_CLAMP
  1427. | BGFX_TEXTURE_V_CLAMP
  1428. | BGFX_TEXTURE_W_CLAMP
  1429. , 0
  1430. , &view.m_textureInfo
  1431. , &orientation
  1432. );
  1433. bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(view.m_textureInfo.format);
  1434. if (format < bimg::TextureFormat::Count)
  1435. {
  1436. view.m_inLinear = bimg::isFloat(format);
  1437. switch (orientation)
  1438. {
  1439. default:
  1440. case bimg::Orientation::R0: cmdExec("view orientation\nview orientation z 0"); break;
  1441. case bimg::Orientation::R90: cmdExec("view orientation\nview orientation z -90"); break;
  1442. case bimg::Orientation::R180: cmdExec("view orientation\nview orientation z -180"); break;
  1443. case bimg::Orientation::R270: cmdExec("view orientation\nview orientation z -270"); break;
  1444. case bimg::Orientation::HFlip: cmdExec("view orientation\nview orientation x -180"); break;
  1445. case bimg::Orientation::HFlipR90: cmdExec("view orientation\nview orientation z -90\nview orientation x -180"); break;
  1446. case bimg::Orientation::HFlipR270: cmdExec("view orientation\nview orientation z -270\nview orientation x -180"); break;
  1447. case bimg::Orientation::VFlip: cmdExec("view orientation\nview orientation y -180"); break;
  1448. }
  1449. }
  1450. std::string title;
  1451. if (isValid(texture) )
  1452. {
  1453. const char* name = "";
  1454. if (view.m_textureInfo.cubeMap)
  1455. {
  1456. name = " CubeMap";
  1457. }
  1458. else if (1 < view.m_textureInfo.depth)
  1459. {
  1460. name = " 3D";
  1461. view.m_textureInfo.numLayers = view.m_textureInfo.depth;
  1462. }
  1463. else if (1 < view.m_textureInfo.numLayers)
  1464. {
  1465. name = " 2D Array";
  1466. }
  1467. bx::stringPrintf(title, "%s (%d x %d%s, mips: %d, layers %d, %s)"
  1468. , fp.get()
  1469. , view.m_textureInfo.width
  1470. , view.m_textureInfo.height
  1471. , name
  1472. , view.m_textureInfo.numMips
  1473. , view.m_textureInfo.numLayers
  1474. , bimg::getName(bimg::TextureFormat::Enum(view.m_textureInfo.format) )
  1475. );
  1476. }
  1477. else
  1478. {
  1479. bx::stringPrintf(title, "Failed to load %s!", filePath);
  1480. }
  1481. entry::WindowHandle handle = { 0 };
  1482. entry::setWindowTitle(handle, title.c_str() );
  1483. }
  1484. int64_t now = bx::getHPCounter();
  1485. static int64_t last = now;
  1486. const int64_t frameTime = now - last;
  1487. last = now;
  1488. const double freq = double(bx::getHPFrequency() );
  1489. time += (float)(frameTime*speed/freq);
  1490. float transitionTime = dragging ? 0.0f : 0.25f*view.m_transitionTime;
  1491. posx.set(view.m_posx, transitionTime);
  1492. posy.set(view.m_posy, transitionTime);
  1493. float ortho[16];
  1494. bx::mtxOrtho(
  1495. ortho
  1496. , 0.0f
  1497. , float(width)
  1498. , float(height)
  1499. , 0.0f
  1500. , 0.0f
  1501. , 1000.0f
  1502. , 0.0f
  1503. , caps->homogeneousDepth
  1504. );
  1505. bgfx::setViewTransform(BACKGROUND_VIEW_ID, NULL, ortho);
  1506. bgfx::setViewRect(BACKGROUND_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) );
  1507. setGeometry(Geometry::Quad
  1508. , 0
  1509. , 0
  1510. , width
  1511. , height
  1512. , view.m_alpha || !bgfx::isValid(texture) ? UINT32_MAX : 0
  1513. , float(width )/float(checkerBoardSize)
  1514. , float(height)/float(checkerBoardSize)
  1515. );
  1516. bgfx::setTexture(0
  1517. , s_texColor
  1518. , checkerBoard
  1519. );
  1520. bgfx::setState(0
  1521. | BGFX_STATE_WRITE_RGB
  1522. | BGFX_STATE_WRITE_A
  1523. );
  1524. bgfx::submit(BACKGROUND_VIEW_ID
  1525. , textureProgram
  1526. );
  1527. float px = posx.getValue();
  1528. float py = posy.getValue();
  1529. bx::mtxOrtho(
  1530. ortho
  1531. , px-width/2.0f
  1532. , px+width/2.0f
  1533. , py+height/2.0f
  1534. , py-height/2.0f
  1535. , -10.0f
  1536. , 10.0f
  1537. , 0.0f
  1538. , caps->homogeneousDepth
  1539. );
  1540. bgfx::setViewTransform(IMAGE_VIEW_ID, NULL, ortho);
  1541. bgfx::setViewRect(IMAGE_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) );
  1542. bgfx::dbgTextClear();
  1543. float orientation[16];
  1544. bx::mtxRotateXYZ(orientation, view.m_flipH, view.m_flipV, angle.getValue()+view.m_orientation);
  1545. if (view.m_fit)
  1546. {
  1547. float wh[3] = { float(view.m_textureInfo.width), float(view.m_textureInfo.height), 0.0f };
  1548. float result[3];
  1549. bx::vec3MulMtx(result, wh, orientation);
  1550. result[0] = bx::round(bx::abs(result[0]) );
  1551. result[1] = bx::round(bx::abs(result[1]) );
  1552. scale.set(bx::min(float(width) / result[0]
  1553. , float(height) / result[1])
  1554. , 0.1f*view.m_transitionTime
  1555. );
  1556. }
  1557. else
  1558. {
  1559. scale.set(1.0f, 0.1f*view.m_transitionTime);
  1560. }
  1561. zoom.set(view.m_zoom, transitionTime);
  1562. angle.set(view.m_angle, transitionTime);
  1563. angx.set(view.m_angx, transitionTime);
  1564. angy.set(view.m_angy, transitionTime);
  1565. float ss = scale.getValue()
  1566. * zoom.getValue()
  1567. ;
  1568. setGeometry(view.m_textureInfo.cubeMap ? view.m_cubeMapGeo : Geometry::Quad
  1569. , -int(view.m_textureInfo.width * ss)/2
  1570. , -int(view.m_textureInfo.height * ss)/2
  1571. , int(view.m_textureInfo.width * ss)
  1572. , int(view.m_textureInfo.height * ss)
  1573. , view.m_abgr
  1574. );
  1575. bgfx::setTransform(orientation);
  1576. float mtx[16];
  1577. bx::mtxRotateXY(mtx, angx.getValue(), angy.getValue() );
  1578. bgfx::setUniform(u_mtx, mtx);
  1579. mip.set(float(view.m_mip), 0.5f*view.m_transitionTime);
  1580. layer.set(float(view.m_layer), 0.25f*view.m_transitionTime);
  1581. ev.set(view.m_ev, 0.5f*view.m_transitionTime);
  1582. float params[4] = { mip.getValue(), layer.getValue(), view.m_inLinear ? 1.0f : 0.0f, ev.getValue() };
  1583. if (1 < view.m_textureInfo.depth)
  1584. {
  1585. params[1] = layer.getValue()/float(bx::max(1, view.m_textureInfo.depth >> view.m_mip) );
  1586. }
  1587. bgfx::setUniform(u_params, params);
  1588. const uint32_t textureFlags = 0
  1589. | BGFX_TEXTURE_U_CLAMP
  1590. | BGFX_TEXTURE_V_CLAMP
  1591. | BGFX_TEXTURE_W_CLAMP
  1592. | (view.m_filter ? 0 : 0
  1593. | BGFX_TEXTURE_MIN_POINT
  1594. | BGFX_TEXTURE_MIP_POINT
  1595. | BGFX_TEXTURE_MAG_POINT
  1596. )
  1597. ;
  1598. bgfx::setTexture(0
  1599. , s_texColor
  1600. , texture
  1601. , textureFlags
  1602. );
  1603. bgfx::setState(0
  1604. | BGFX_STATE_WRITE_RGB
  1605. | BGFX_STATE_WRITE_A
  1606. | (view.m_alpha ? BGFX_STATE_BLEND_ALPHA : BGFX_STATE_NONE)
  1607. );
  1608. bgfx:: ProgramHandle program = textureProgram;
  1609. if (1 < view.m_textureInfo.depth)
  1610. {
  1611. program = texture3DProgram;
  1612. }
  1613. else if (view.m_textureInfo.cubeMap)
  1614. {
  1615. program = Geometry::Quad == view.m_cubeMapGeo
  1616. ? textureCubeProgram
  1617. : textureCube2Program
  1618. ;
  1619. }
  1620. else if (1 < view.m_textureInfo.numLayers)
  1621. {
  1622. program = textureArrayProgram;
  1623. }
  1624. else if (view.m_sdf)
  1625. {
  1626. if (8 < bimg::getBitsPerPixel(bimg::TextureFormat::Enum(view.m_textureInfo.format) ) )
  1627. {
  1628. program = textureMsdfProgram;
  1629. }
  1630. else
  1631. {
  1632. program = textureSdfProgram;
  1633. }
  1634. }
  1635. if (bgfx::isValid(texture) )
  1636. {
  1637. bgfx::submit(IMAGE_VIEW_ID, program);
  1638. }
  1639. else
  1640. {
  1641. bgfx::discard();
  1642. }
  1643. bgfx::frame();
  1644. }
  1645. }
  1646. if (bgfx::isValid(texture) )
  1647. {
  1648. bgfx::destroy(texture);
  1649. }
  1650. bgfx::destroy(checkerBoard);
  1651. bgfx::destroy(s_texColor);
  1652. bgfx::destroy(u_mtx);
  1653. bgfx::destroy(u_params);
  1654. bgfx::destroy(textureProgram);
  1655. bgfx::destroy(textureArrayProgram);
  1656. bgfx::destroy(textureCubeProgram);
  1657. bgfx::destroy(textureCube2Program);
  1658. bgfx::destroy(textureSdfProgram);
  1659. bgfx::destroy(textureMsdfProgram);
  1660. bgfx::destroy(texture3DProgram);
  1661. imguiDestroy();
  1662. bgfx::shutdown();
  1663. return exitcode;
  1664. }