first-screen.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. const VS_LOGO = `
  2. attribute vec4 a_Position;
  3. attribute vec2 a_TexCoord;
  4. varying vec2 v_TexCoord;
  5. void main() {
  6. gl_Position = a_Position;
  7. v_TexCoord = a_TexCoord;
  8. }`;
  9. const FS_LOGO = `
  10. precision mediump float;
  11. uniform sampler2D u_Sampler;
  12. varying vec2 v_TexCoord;
  13. void main() {
  14. gl_FragColor = texture2D(u_Sampler, v_TexCoord);
  15. }`;
  16. const VS_BG = `
  17. attribute vec4 a_Position;
  18. attribute vec2 a_TexCoord;
  19. varying vec2 v_TexCoord;
  20. void main() {
  21. gl_Position = a_Position;
  22. v_TexCoord = a_TexCoord;
  23. }`;
  24. const FS_BG = `
  25. precision mediump float;
  26. uniform sampler2D u_Sampler;
  27. uniform float u_flip;
  28. varying vec2 v_TexCoord;
  29. void main() {
  30. vec2 texCoord = v_TexCoord;
  31. if(u_flip > 0.5) {
  32. texCoord.y = 1.0 - texCoord.y;
  33. }
  34. gl_FragColor = texture2D(u_Sampler, texCoord);
  35. }`;
  36. const VS_PROGRESSBAR = `
  37. precision mediump float;
  38. attribute vec4 a_Position;
  39. attribute float a_Progress;
  40. varying float v_Progress;
  41. void main() {
  42. gl_Position = a_Position;
  43. v_Progress = a_Progress;
  44. }`;
  45. const FS_PROGRESSBAR = `
  46. precision mediump float;
  47. uniform float u_CurrentProgress;
  48. varying float v_Progress;
  49. uniform vec4 u_ProgressBarColor;
  50. uniform vec4 u_ProgressBackground;
  51. void main() {
  52. gl_FragColor = v_Progress <= u_CurrentProgress ? u_ProgressBarColor : u_ProgressBackground;
  53. }`;
  54. const options = {
  55. alpha: false,
  56. antialias: true,
  57. depth: true,
  58. stencil: true,
  59. premultipliedAlpha: false,
  60. preserveDrawingBuffer: false,
  61. powerPreference: 'default',
  62. failIfMajorPerformanceCaveat: false,
  63. };
  64. let gl = null;
  65. let image = null;
  66. let slogan = null;
  67. let bg = null;
  68. let program = null;
  69. let programBg = null;
  70. let programProgress = null;
  71. let rafHandle = null;
  72. let logoTexture = null;
  73. let sloganTexture = null;
  74. let bgTexture = null;
  75. let vertexBuffer = null;
  76. let sloganVertexBuffer = null;
  77. let bgVertexBuffer = null;
  78. let vertexBufferProgress = null;
  79. let progress = 0.0;
  80. let progressBarColor = [61 / 255, 197 / 255, 222 / 255, 1];
  81. let progressBackground = [100 / 255, 111 / 255, 118 / 255, 1];
  82. let afterTick = null;
  83. let backgroundFilp = 1.0; // set 0 to not flip
  84. let displayRatio = 1;
  85. let bgColor = [0.01568627450980392,0.03529411764705882,0.0392156862745098,0.00392156862745098];
  86. let useCustomBg = false;
  87. let useLogo = true;
  88. let useDefaultLogo = true;
  89. let logoName = 'logo.png';
  90. let bgName = 'background.png';
  91. let fitWidth = true;
  92. let fitHeight = true;
  93. function initShaders(vshader, fshader) {
  94. return createProgram(vshader, fshader);
  95. }
  96. function createProgram(vshader, fshader) {
  97. var vertexShader = loadShader(gl.VERTEX_SHADER, vshader);
  98. var fragmentShader = loadShader(gl.FRAGMENT_SHADER, fshader);
  99. var program = gl.createProgram();
  100. gl.attachShader(program, vertexShader);
  101. gl.attachShader(program, fragmentShader);
  102. gl.linkProgram(program);
  103. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  104. if (!linked) {
  105. var error = gl.getProgramInfoLog(program);
  106. console.log('Failed to link program: ' + error);
  107. gl.deleteProgram(program);
  108. program = null;
  109. }
  110. gl.deleteShader(fragmentShader);
  111. gl.deleteShader(vertexShader);
  112. return program;
  113. }
  114. function loadShader(type, source) {
  115. var shader = gl.createShader(type);
  116. gl.shaderSource(shader, source);
  117. gl.compileShader(shader);
  118. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  119. if (!compiled) {
  120. var error = gl.getShaderInfoLog(shader);
  121. console.log('Failed to compile shader: ' + error);
  122. gl.deleteShader(shader);
  123. return null;
  124. }
  125. return shader;
  126. }
  127. function initVertexBuffer() {
  128. const widthRatio = 2 / canvas.width;
  129. const heightRatio = 2 / canvas.height;
  130. const heightOffset = 0.225;
  131. const vertices = new Float32Array([
  132. widthRatio,heightRatio + heightOffset, 1.0, 1.0,
  133. widthRatio, heightRatio + heightOffset, 1.0, 0.0,
  134. -widthRatio, heightRatio + heightOffset, 0.0, 1.0,
  135. -widthRatio, heightRatio + heightOffset, 0.0, 0.0,
  136. ]);
  137. vertexBuffer = gl.createBuffer();
  138. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  139. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  140. }
  141. function initSloganVertexBuffer() {
  142. const widthRatio = 2 / canvas.width;
  143. const heightRatio = 2 / canvas.height;
  144. const vertices = new Float32Array([
  145. widthRatio, heightRatio, 1.0, 1.0,
  146. widthRatio, heightRatio, 1.0, 0.0,
  147. -widthRatio, heightRatio, 0.0, 1.0,
  148. -widthRatio, heightRatio, 0.0, 0.0,
  149. ]);
  150. sloganVertexBuffer = gl.createBuffer();
  151. gl.bindBuffer(gl.ARRAY_BUFFER, sloganVertexBuffer);
  152. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  153. }
  154. function initBgVertexBuffer() {
  155. const vertices = new Float32Array([
  156. 1.0, 1.0, 1.0, 1.0,
  157. 1.0, 0.0, 1.0, 0.0,
  158. 0.0, 1.0, 0.0, 1.0,
  159. 0.0, 0.0, 0.0, 0.0,
  160. ]);
  161. bgVertexBuffer = gl.createBuffer();
  162. gl.bindBuffer(gl.ARRAY_BUFFER, bgVertexBuffer);
  163. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  164. }
  165. function initProgressVertexBuffer() {
  166. // the ratio value may be adjusted according to the image pixels
  167. const widthRatio = 0.5;
  168. const heightRatio = (window.devicePixelRatio >= 2 ? 6 : 3) / canvas.height * 1.35;
  169. const heightOffset = -0.8;
  170. const vertices = new Float32Array([
  171. widthRatio, heightOffset - heightRatio, 1,
  172. widthRatio, heightOffset + heightRatio, 1,
  173. -widthRatio, heightOffset - heightRatio, 0,
  174. -widthRatio, heightOffset + heightRatio, 0,
  175. ]);
  176. vertexBufferProgress = gl.createBuffer();
  177. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress);
  178. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  179. }
  180. function updateVertexBuffer() {
  181. const heightRatio = 1.0 * 0.185 * displayRatio;
  182. const widthRatio = image.width * (canvas.height * 0.185 / image.height) / canvas.width * displayRatio;
  183. const vertices = new Float32Array([
  184. widthRatio, -heightRatio, 1.0, 1.0,
  185. widthRatio, heightRatio, 1.0, 0.0,
  186. -widthRatio, -heightRatio, 0.0, 1.0,
  187. -widthRatio, heightRatio, 0.0, 0.0,
  188. ]);
  189. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  190. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  191. }
  192. function updateSloganVertexBuffer() {
  193. // the ratio value may be adjusted according to the image pixels
  194. const widthRatio = slogan.width / canvas.width * 0.75;
  195. const heightRatio = slogan.height / canvas.height * 0.75;
  196. const logoHeightRatio = image.height / canvas.height * 1.35 * displayRatio;
  197. const heightOffset = (5/12 + logoHeightRatio * 1/2 + heightRatio * 3/2) * (-2) + 1; // 5/12 is ui design layout for logo
  198. const vertices = new Float32Array([
  199. widthRatio, heightOffset - heightRatio, 1.0, 1.0,
  200. widthRatio, heightOffset + heightRatio, 1.0, 0.0,
  201. -widthRatio, heightOffset - heightRatio, 0.0, 1.0,
  202. -widthRatio, heightOffset + heightRatio, 0.0, 0.0,
  203. ]);
  204. gl.bindBuffer(gl.ARRAY_BUFFER, sloganVertexBuffer);
  205. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  206. }
  207. function updateBgVertexBuffer() {
  208. let widthRatio = 1;
  209. let heightRatio = 1;
  210. if(fitWidth && !fitHeight) {
  211. widthRatio = canvas.width;
  212. heightRatio = (canvas.width / bg.width) * bg.height;
  213. } else if(!fitWidth && fitHeight) {
  214. widthRatio = (canvas.height / bg.height) * bg.width;
  215. heightRatio = canvas.height;
  216. } else if(fitWidth && fitHeight) {
  217. if ((bg.width / bg.height) > (canvas.width / canvas.height)) {
  218. widthRatio = canvas.width;
  219. heightRatio = (canvas.width / bg.width) * bg.height;
  220. } else {
  221. widthRatio = (canvas.height / bg.height) * bg.width;
  222. heightRatio = canvas.height;
  223. }
  224. } else if(!fitWidth && !fitHeight) {
  225. if ((bg.width / bg.height) > (canvas.width / canvas.height)) {
  226. widthRatio = (canvas.height / bg.height) * bg.width;
  227. heightRatio = canvas.height;
  228. } else {
  229. widthRatio = canvas.width;
  230. heightRatio = (canvas.width / bg.width) * bg.height;
  231. }
  232. } else {
  233. widthRatio = canvas.width;
  234. heightRatio = canvas.height;
  235. }
  236. widthRatio /= canvas.width;
  237. heightRatio /= canvas.height;
  238. const vertices = new Float32Array([
  239. widthRatio, heightRatio, 1.0, 1.0,
  240. widthRatio, -heightRatio, 1.0, 0.0,
  241. -widthRatio, heightRatio, 0.0, 1.0,
  242. -widthRatio, -heightRatio, 0.0, 0.0,
  243. ]);
  244. gl.bindBuffer(gl.ARRAY_BUFFER, bgVertexBuffer);
  245. gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
  246. }
  247. function loadBackground(bgPath) {
  248. return new Promise((resolve, reject) => {
  249. bg = new Image();
  250. bg.premultiplyAlpha = false;
  251. bg.onload = function() {
  252. resolve(bg);
  253. };
  254. bg.onerror = function(err) {
  255. reject(err);
  256. };
  257. bg.src = bgPath.replace('#', '%23');
  258. });
  259. }
  260. function loadImage(imgPath) {
  261. return new Promise((resolve, reject) => {
  262. image = new Image();
  263. image.premultiplyAlpha = false;
  264. image.onload = function() {
  265. resolve(image);
  266. };
  267. image.onerror = function(err) {
  268. reject(err);
  269. };
  270. image.src = imgPath.replace('#', '%23');
  271. });
  272. }
  273. function loadSlogan(sloganPath) {
  274. return new Promise((resolve, reject) => {
  275. slogan = new Image();
  276. slogan.premultiplyAlpha = false;
  277. slogan.onload = function() {
  278. resolve(slogan);
  279. };
  280. slogan.onerror = function(err) {
  281. reject(err);
  282. };
  283. slogan.src = sloganPath.replace('#', '%23');
  284. });
  285. }
  286. function initLogoTexture() {
  287. logoTexture = gl.createTexture();
  288. gl.activeTexture(gl.TEXTURE0);
  289. gl.bindTexture(gl.TEXTURE_2D, logoTexture);
  290. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  291. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  292. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  293. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  294. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255]));
  295. }
  296. function initSloganTexture() {
  297. sloganTexture = gl.createTexture();
  298. gl.activeTexture(gl.TEXTURE0);
  299. gl.bindTexture(gl.TEXTURE_2D, sloganTexture);
  300. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  301. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  302. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  303. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  304. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255]));
  305. }
  306. function initBgTexture() {
  307. bgTexture = gl.createTexture();
  308. gl.activeTexture(gl.TEXTURE0);
  309. gl.bindTexture(gl.TEXTURE_2D, bgTexture);
  310. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  311. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  312. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  313. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  314. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255]));
  315. }
  316. function updateLogoTexture() {
  317. gl.activeTexture(gl.TEXTURE0);
  318. gl.bindTexture(gl.TEXTURE_2D, logoTexture);
  319. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  320. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  321. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  322. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  323. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  324. }
  325. function updateSloganTexture() {
  326. gl.activeTexture(gl.TEXTURE0);
  327. gl.bindTexture(gl.TEXTURE_2D, sloganTexture);
  328. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  329. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  330. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  331. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  332. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, slogan);
  333. }
  334. function updateBgTexture() {
  335. gl.activeTexture(gl.TEXTURE0);
  336. gl.bindTexture(gl.TEXTURE_2D, bgTexture);
  337. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  338. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  339. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  340. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  341. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bg);
  342. }
  343. function drawTexture(gl, program, texture, vertexBuffer, vertexFormatLength) {
  344. gl.useProgram(program);
  345. gl.activeTexture(gl.TEXTURE0);
  346. gl.bindTexture(gl.TEXTURE_2D, texture);
  347. var uSampler = gl.getUniformLocation(program, 'u_Sampler');
  348. gl.uniform1i(uSampler, 0);
  349. var uFlip = gl.getUniformLocation(program, 'u_flip');
  350. gl.uniform1f(uFlip, backgroundFilp);
  351. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  352. var aPosition = gl.getAttribLocation(program, 'a_Position');
  353. gl.enableVertexAttribArray(aPosition);
  354. gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 4, 0);
  355. var aTexCoord = gl.getAttribLocation(program, 'a_TexCoord');
  356. gl.enableVertexAttribArray(aTexCoord);
  357. gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, vertexFormatLength * 4, vertexFormatLength * 2);
  358. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  359. }
  360. function drawProgressBar(gl, program, vertexBuffer, vertexFormatLength, progress, progressBarColor, progressBackground) {
  361. gl.useProgram(program);
  362. var uCurrentProgress = gl.getUniformLocation(program, 'u_CurrentProgress');
  363. gl.uniform1f(uCurrentProgress, progress);
  364. var uProgressBarColor = gl.getUniformLocation(program, 'u_ProgressBarColor');
  365. gl.uniform4fv(uProgressBarColor, progressBarColor);
  366. var uProgressBackground = gl.getUniformLocation(program, 'u_ProgressBackground');
  367. gl.uniform4fv(uProgressBackground, progressBackground);
  368. gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
  369. var aPosition = gl.getAttribLocation(program, 'a_Position');
  370. gl.enableVertexAttribArray(aPosition);
  371. var vertexFormatLength = 4;
  372. gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 3, 0);
  373. var aProgress = gl.getAttribLocation(program, 'a_Progress');
  374. gl.enableVertexAttribArray(aProgress);
  375. gl.vertexAttribPointer(aProgress, 1, gl.FLOAT, false, vertexFormatLength * 3, vertexFormatLength * 2);
  376. gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  377. }
  378. function draw() {
  379. gl.enable(gl.BLEND);
  380. gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  381. gl.clearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]);
  382. gl.clear(gl.COLOR_BUFFER_BIT);
  383. // draw background
  384. useCustomBg && drawTexture(gl, programBg, bgTexture, bgVertexBuffer, 4);
  385. // draw logo
  386. useLogo && drawTexture(gl, program, logoTexture, vertexBuffer, 4);
  387. // draw slogan
  388. useLogo && useDefaultLogo && drawTexture(gl, program, sloganTexture, sloganVertexBuffer, 4);
  389. // draw progress bar
  390. drawProgressBar(gl, programProgress, vertexBufferProgress, 3, progress, progressBarColor, progressBackground);
  391. }
  392. function tick() {
  393. rafHandle = requestAnimationFrame(() => {
  394. draw();
  395. tick();
  396. if (afterTick) {
  397. afterTick();
  398. afterTick = null;
  399. }
  400. });
  401. }
  402. function end() {
  403. return setProgress(1).then(() => {
  404. cancelAnimationFrame(rafHandle);
  405. gl.useProgram(null);
  406. gl.bindTexture(gl.TEXTURE_2D, null);
  407. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  408. useLogo && gl.deleteTexture(logoTexture);
  409. useLogo && useDefaultLogo && gl.deleteTexture(sloganTexture);
  410. useCustomBg && gl.deleteTexture(bgTexture);
  411. gl.deleteBuffer(vertexBuffer);
  412. useCustomBg && gl.deleteBuffer(bgVertexBuffer);
  413. useLogo && useDefaultLogo && gl.deleteBuffer(sloganVertexBuffer);
  414. gl.deleteBuffer(vertexBufferProgress);
  415. gl.deleteProgram(program);
  416. gl.deleteProgram(programBg);
  417. gl.deleteProgram(programProgress);
  418. });
  419. }
  420. function setProgress(val) {
  421. progress = val;
  422. return new Promise((resolve, reject) => {
  423. afterTick = () => {
  424. resolve();
  425. };
  426. });
  427. }
  428. function start(alpha, antialias, useWebgl2) {
  429. options.alpha = alpha === 'true' ? true : false;
  430. options.antialias = antialias === 'false' ? false : true;
  431. if (useWebgl2 === 'true') {
  432. gl = window.canvas.getContext("webgl2", options);
  433. }
  434. // TODO: this is a hack method to detect whether WebGL2RenderingContext is supported
  435. if (gl) {
  436. window.WebGL2RenderingContext = true;
  437. } else {
  438. window.WebGL2RenderingContext = false;
  439. gl = window.canvas.getContext("webgl", options);
  440. }
  441. initVertexBuffer();
  442. useCustomBg && initBgVertexBuffer();
  443. useLogo && useDefaultLogo && initSloganVertexBuffer();
  444. initProgressVertexBuffer();
  445. initLogoTexture();
  446. useCustomBg && initBgTexture();
  447. useLogo && useDefaultLogo && initSloganTexture();
  448. if (useLogo) {
  449. program = initShaders(VS_LOGO, FS_LOGO);
  450. }
  451. if (useCustomBg) {
  452. programBg = initShaders(VS_BG, FS_BG);
  453. }
  454. programProgress = initShaders(VS_PROGRESSBAR, FS_PROGRESSBAR);
  455. tick();
  456. return Promise.all([
  457. //logo should be loaded earlier than slogan
  458. useLogo && loadImage(logoName).then(() => {
  459. updateVertexBuffer();
  460. updateLogoTexture();
  461. }).then(() => {
  462. return useLogo && useDefaultLogo && loadSlogan('slogan.png').then(() => {
  463. updateSloganVertexBuffer();
  464. updateSloganTexture();
  465. });
  466. }),
  467. useCustomBg && loadBackground(bgName).then(() => {
  468. updateBgVertexBuffer();
  469. updateBgTexture();
  470. })
  471. ]).then(() => {
  472. return setProgress(0);
  473. });
  474. }
  475. module.exports = { start, end, setProgress };