Home Reference Source

cables_dev/cables_ui/src/ui/components/overlay/overlaymeshes.js

  1. import { mat4, vec3 } from "gl-matrix";
  2. import { Framebuffer2, Geometry, Mesh, Shader, Uniform } from "cables-corelibs";
  3. import { DEG2RAD } from "cables-corelibs/cgl/cgl_utils.js";
  4. import { nl } from "cables-corelibs/cg/constants.js";
  5. import overlayShaderVert from "./overlaymeshes.vert";
  6. import { gui } from "../../gui.js";
  7. const helperMeshes = {};
  8. helperMeshes.count = 0;
  9. export default helperMeshes;
  10. helperMeshes.startFramebuffer = function (cgl)
  11. {
  12. if (!helperMeshes.FB || !helperMeshes.FB.fb)
  13. {
  14. helperMeshes.FB = {};
  15. helperMeshes.FB.fb = new Framebuffer2(cgl, 8, 8, {
  16. "isFloatingPointTexture": false,
  17. "depth": true,
  18. "clear": false,
  19. "multisampling": true,
  20. "multisamplingSamples": 4,
  21. });
  22. }
  23. if (helperMeshes.FB.oldWidth != cgl.getViewPort()[2] || helperMeshes.FB.oldHeight != cgl.getViewPort()[3])
  24. {
  25. helperMeshes.FB.fb.setSize(cgl.getViewPort()[2], cgl.getViewPort()[3]);
  26. helperMeshes.FB.oldWidth = cgl.getViewPort()[2];
  27. helperMeshes.FB.oldHeight = cgl.getViewPort()[3];
  28. }
  29. helperMeshes.FB.fb.renderStart(cgl);
  30. if (cgl.frameCycler != helperMeshes.FB.oldFrameCycle)
  31. {
  32. cgl.gl.clearColor(0, 0, 0, 0);
  33. cgl.gl.clear(cgl.gl.COLOR_BUFFER_BIT | cgl.gl.DEPTH_BUFFER_BIT);
  34. helperMeshes.FB.oldFrameCycle = cgl.frameCycler;
  35. }
  36. };
  37. helperMeshes.endFramebuffer = function (cgl)
  38. {
  39. helperMeshes.FB.fb.renderEnd();
  40. };
  41. helperMeshes.getDefaultShader = function (cgl, options = {})
  42. {
  43. let name = "defaultShader";
  44. if (options.billboarded)name = "defaultShaderBillboard";
  45. if (!helperMeshes[name])
  46. {
  47. helperMeshes[name] = new Shader(cgl, "marker shader");
  48. helperMeshes[name].setSource(overlayShaderVert, Shader.getDefaultFragmentShader(0.6, 0.6, 0.6));
  49. if (options.billboarded)helperMeshes[name].toggleDefine("BILLBOARD", true);
  50. }
  51. return helperMeshes[name];
  52. };
  53. helperMeshes.getSelectedShader = function (cgl, options = {})
  54. {
  55. let name = "selectedShader";
  56. if (options.billboarded)name = "selectedShaderBillboard";
  57. if (!helperMeshes[name])
  58. {
  59. helperMeshes[name] = new Shader(cgl, "marker shader");
  60. helperMeshes[name].setSource(overlayShaderVert, Shader.getDefaultFragmentShader(0, 1, 1));
  61. if (options.billboarded)helperMeshes[name].toggleDefine("BILLBOARD", true);
  62. }
  63. return helperMeshes[name];
  64. };
  65. helperMeshes.drawCircle = function (op, size)
  66. {
  67. /** @type {CglContext} */
  68. const cgl = op.patch.cgl;
  69. if (!helperMeshes.CIRCLE)
  70. {
  71. helperMeshes.CIRCLE = {};
  72. helperMeshes.CIRCLE.vScale = vec3.create();
  73. function bufferData()
  74. {
  75. let verts = [];
  76. let tc = [];
  77. const segments = 80;
  78. let degInRad = 0;
  79. const radius = 1;
  80. for (let i = 0; i <= Math.round(segments); i++)
  81. {
  82. degInRad = (360.0 / Math.round(segments)) * i * DEG2RAD;
  83. verts.push(
  84. Math.cos(degInRad) * radius,
  85. Math.sin(degInRad) * radius,
  86. 0
  87. );
  88. tc.push(0, 0);
  89. }
  90. let geom = new Geometry("sphere marker");
  91. geom.setPointVertices(verts);
  92. geom.setTexCoords(tc);
  93. geom.vertexNormals = verts.slice();
  94. helperMeshes.CIRCLE.mesh = new Mesh(cgl, geom);
  95. }
  96. bufferData();
  97. }
  98. if (cgl.lastMesh) cgl.lastMesh.unBind();
  99. cgl.pushModelMatrix();
  100. helperMeshes.startFramebuffer(cgl);
  101. vec3.set(helperMeshes.CIRCLE.vScale, size, size, size);
  102. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.CIRCLE.vScale);
  103. let shader = helperMeshes.getDefaultShader(cgl, { "billboarded": true });
  104. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl, { "billboarded": true });
  105. shader.glPrimitive = cgl.gl.LINE_STRIP;
  106. helperMeshes.CIRCLE.mesh.render(shader);
  107. helperMeshes.count++;
  108. cgl.popModelMatrix();
  109. helperMeshes.endFramebuffer(cgl);
  110. };
  111. helperMeshes.drawSphere = function (op, size)
  112. {
  113. const cgl = op.patch.cgl;
  114. if (!helperMeshes.SPHERE)
  115. {
  116. helperMeshes.SPHERE = {};
  117. helperMeshes.SPHERE.vScale = vec3.create();
  118. function bufferData()
  119. {
  120. let verts = [];
  121. let tc = [];
  122. const segments = 80;
  123. let i = 0, degInRad = 0;
  124. const radius = 1;
  125. for (i = 0; i <= Math.round(segments); i++)
  126. {
  127. degInRad = (360.0 / Math.round(segments)) * i * DEG2RAD;
  128. verts.push(Math.cos(degInRad) * radius);
  129. verts.push(0);
  130. verts.push(Math.sin(degInRad) * radius);
  131. tc.push(0, 0);
  132. }
  133. const geom = new Geometry("sphere marker");
  134. geom.setPointVertices(verts);
  135. geom.setTexCoords(tc);
  136. geom.vertexNormals = verts.slice();
  137. //---
  138. verts = [];
  139. tc = [];
  140. for (i = 0; i <= Math.round(segments); i++)
  141. {
  142. degInRad = (360.0 / Math.round(segments)) * i * DEG2RAD;
  143. verts.push(Math.cos(degInRad) * radius);
  144. verts.push(Math.sin(degInRad) * radius);
  145. verts.push(0);
  146. tc.push(0, 0);
  147. }
  148. const geom2 = new Geometry("sphere marker");
  149. geom2.setPointVertices(verts);
  150. geom2.setTexCoords(tc);
  151. geom2.vertexNormals = verts.slice();
  152. //---
  153. verts = [];
  154. tc = [];
  155. for (i = 0; i <= Math.round(segments); i++)
  156. {
  157. degInRad = (360.0 / Math.round(segments)) * i * DEG2RAD;
  158. verts.push(0);
  159. verts.push(Math.cos(degInRad) * radius);
  160. verts.push(Math.sin(degInRad) * radius);
  161. tc.push(0, 0);
  162. }
  163. const geom3 = new Geometry("sphere marker");
  164. geom3.setPointVertices(verts);
  165. geom3.setTexCoords(tc);
  166. geom3.vertexNormals = verts.slice();
  167. geom.merge(geom2);
  168. geom.merge(geom3);
  169. helperMeshes.SPHERE.mesh = new Mesh(cgl, geom);
  170. }
  171. bufferData();
  172. }
  173. if (cgl.lastMesh) cgl.lastMesh.unBind();
  174. cgl.pushModelMatrix();
  175. helperMeshes.startFramebuffer(cgl);
  176. vec3.set(helperMeshes.SPHERE.vScale, size, size, size);
  177. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.SPHERE.vScale);
  178. let shader = helperMeshes.getDefaultShader(cgl);
  179. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl);
  180. shader.glPrimitive = cgl.gl.LINE_STRIP;
  181. helperMeshes.SPHERE.mesh.render(shader);
  182. helperMeshes.count++;
  183. cgl.popModelMatrix();
  184. helperMeshes.endFramebuffer(cgl);
  185. };
  186. helperMeshes.drawAxisMarker = function (op, size)
  187. {
  188. const cgl = op.patch.cgl;
  189. if (!helperMeshes.MARKER)
  190. {
  191. helperMeshes.MARKER = {};
  192. const geom = new Geometry("marker");
  193. geom.setPointVertices([
  194. 0.00001, 0, 0, 1, 0, 0,
  195. 0, 0.00001, 0, 0, 1, 0,
  196. 0, 0, 0.00001, 0, 0, 1
  197. ]);
  198. // geom.resetTextureCoords();
  199. helperMeshes.MARKER.mesh = new Mesh(cgl, geom, { "glPrimitive": cgl.gl.LINES });
  200. helperMeshes.MARKER.mesh.setGeom(geom);
  201. const frag = "" + nl + "IN vec3 axisColor;" + nl + "void main()" + nl + "{" + nl + " vec4 col=vec4(axisColor,1.0);" + nl + " outColor = col;" + nl + "}";
  202. const vert = "" + nl
  203. + "IN vec3 vPosition;" + nl
  204. + "UNI mat4 projMatrix;" + nl
  205. + "UNI mat4 mvMatrix;" + nl
  206. + "OUT vec3 axisColor;" + nl
  207. + "void main()" + nl
  208. + "{" + nl
  209. + " vec4 pos=vec4(vPosition, 1.0);" + nl
  210. + " if(pos.x!=0.0)axisColor=vec3(1.0,0.3,0.0);" + nl
  211. + " if(pos.y!=0.0)axisColor=vec3(0.0,1.0,0.2);" + nl
  212. + " if(pos.z!=0.0)axisColor=vec3(0.0,0.5,1.0);" + nl
  213. + " gl_Position = projMatrix * mvMatrix * pos;" + nl
  214. + "}";
  215. helperMeshes.MARKER.shader = new Shader(cgl, "markermaterial");
  216. helperMeshes.MARKER.shader.setSource(vert, frag);
  217. helperMeshes.MARKER.vScale = vec3.create();
  218. }
  219. helperMeshes.startFramebuffer(cgl);
  220. if (size === undefined) size = 2;
  221. cgl.pushModelMatrix();
  222. cgl.pushShader(helperMeshes.MARKER.shader);
  223. vec3.set(helperMeshes.MARKER.vScale, size, size, size);
  224. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.MARKER.vScale);
  225. cgl.pushDepthTest(false);
  226. helperMeshes.MARKER.mesh.render(cgl.getShader());
  227. helperMeshes.count++;
  228. cgl.popDepthTest();
  229. cgl.popShader();
  230. cgl.popModelMatrix();
  231. helperMeshes.endFramebuffer(cgl);
  232. };
  233. helperMeshes.drawLineSourceDest = function (op, sourceX, sourceY, sourceZ, destX, destY, destZ)
  234. {
  235. const cgl = op.patch.cgl;
  236. if (!helperMeshes.ARROW_SRC_DST)
  237. {
  238. helperMeshes.ARROW_SRC_DST = {};
  239. const verts = [];
  240. verts.push(sourceX, sourceY, sourceZ);
  241. verts.push(destX, destY, destZ);
  242. const tc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  243. const geom = new Geometry("helpermesh");
  244. geom.vertices = verts;
  245. geom.setTexCoords(tc);
  246. geom.vertexNormals = verts.slice();
  247. helperMeshes.ARROW_SRC_DST.geom = geom;
  248. helperMeshes.ARROW_SRC_DST.cube = new Mesh(cgl, geom, { "glPrimitive": cgl.gl.LINES });
  249. }
  250. else
  251. {
  252. helperMeshes.ARROW_SRC_DST.geom.setVertices([sourceX, sourceY, sourceZ, destX, destY, destZ]);
  253. helperMeshes.ARROW_SRC_DST.cube.updateVertices(helperMeshes.ARROW_SRC_DST.geom);
  254. }
  255. if (cgl.lastMesh) cgl.lastMesh.unBind();
  256. cgl.pushModelMatrix();
  257. helperMeshes.startFramebuffer(cgl);
  258. let shader = helperMeshes.getDefaultShader(cgl);
  259. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl);
  260. helperMeshes.ARROW_SRC_DST.cube.render(shader);
  261. helperMeshes.count++;
  262. cgl.popModelMatrix();
  263. helperMeshes.endFramebuffer(cgl);
  264. };
  265. helperMeshes.drawArrow = function (op, sizeX, rotX, rotY, rotZ)
  266. {
  267. const cgl = op.patch.cgl;
  268. if (!helperMeshes.ARROW)
  269. {
  270. helperMeshes.ARROW = {};
  271. helperMeshes.ARROW.vScale = vec3.create();
  272. function bufferData()
  273. {
  274. const verts = [];
  275. verts.push(0, -1, 0);
  276. verts.push(0.25, -0.75, 0);
  277. verts.push(0, -1, 0);
  278. verts.push(-0.25, -0.75, 0);
  279. verts.push(0, -1, 0);
  280. verts.push(0, 0, 0);
  281. const tc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  282. const geom = new Geometry("helpermesh");
  283. geom.vertices = verts;
  284. geom.setTexCoords(tc);
  285. geom.vertexNormals = verts.slice();
  286. helperMeshes.ARROW.cube = new Mesh(cgl, geom, { "glPrimitive": cgl.gl.LINES });
  287. }
  288. bufferData();
  289. }
  290. if (cgl.lastMesh) cgl.lastMesh.unBind();
  291. cgl.pushModelMatrix();
  292. helperMeshes.startFramebuffer(cgl);
  293. vec3.set(helperMeshes.ARROW.vScale, sizeX, sizeX, sizeX);
  294. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.ARROW.vScale);
  295. if (rotX) mat4.rotateX(cgl.mvMatrix, cgl.mvMatrix, rotX * DEG2RAD);
  296. if (rotY) mat4.rotateY(cgl.mvMatrix, cgl.mvMatrix, rotY * DEG2RAD);
  297. if (rotZ) mat4.rotateZ(cgl.mvMatrix, cgl.mvMatrix, rotZ * DEG2RAD);
  298. let shader = helperMeshes.getDefaultShader(cgl);
  299. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl);
  300. helperMeshes.ARROW.cube.render(shader);
  301. helperMeshes.count++;
  302. cgl.popModelMatrix();
  303. helperMeshes.endFramebuffer(cgl);
  304. };
  305. helperMeshes.drawXPlane = function (op, sizeX, rotX, rotY, rotZ)
  306. {
  307. const cgl = op.patch.cgl;
  308. if (!helperMeshes.XPLANE)
  309. {
  310. helperMeshes.XPLANE = {};
  311. helperMeshes.XPLANE.vScale = vec3.create();
  312. function bufferData()
  313. {
  314. const verts = [
  315. -1, -1, 0,
  316. 1, 1, 0,
  317. -1, 1, 0,
  318. 1, -1, 0,
  319. 1, 1, 0,
  320. -1, 1, 0,
  321. -1, -1, 0,
  322. 1, -1, 0
  323. ];
  324. const tc = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  325. const geom = new Geometry("helpermesh");
  326. geom.vertices = verts;
  327. geom.setTexCoords(tc);
  328. geom.vertexNormals = verts.slice();
  329. helperMeshes.XPLANE.mesh = new Mesh(cgl, geom, cgl.gl.LINE_STRIP);
  330. }
  331. bufferData();
  332. }
  333. if (cgl.lastMesh) cgl.lastMesh.unBind();
  334. cgl.pushModelMatrix();
  335. helperMeshes.startFramebuffer(cgl);
  336. vec3.set(helperMeshes.XPLANE.vScale, sizeX, sizeX, sizeX);
  337. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.XPLANE.vScale);
  338. if (rotX) mat4.rotateX(cgl.mvMatrix, cgl.mvMatrix, rotX * DEG2RAD);
  339. if (rotY) mat4.rotateY(cgl.mvMatrix, cgl.mvMatrix, rotY * DEG2RAD);
  340. if (rotZ) mat4.rotateZ(cgl.mvMatrix, cgl.mvMatrix, rotZ * DEG2RAD);
  341. let shader = helperMeshes.getDefaultShader(cgl);
  342. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl);
  343. helperMeshes.XPLANE.mesh.render(shader);
  344. helperMeshes.count++;
  345. cgl.popModelMatrix();
  346. helperMeshes.endFramebuffer(cgl);
  347. };
  348. helperMeshes.drawCube = function (op, sizeX, sizeY, sizeZ)
  349. {
  350. const cgl = op.patch.cgl;
  351. if (!helperMeshes.CUBE)
  352. {
  353. helperMeshes.CUBE = {};
  354. helperMeshes.CUBE.vScale = vec3.create();
  355. function bufferData()
  356. {
  357. const verts = new Float32Array([
  358. -1, -1, 1,
  359. 1, -1, 1,
  360. 1, 1, 1,
  361. -1, 1, 1,
  362. -1, -1, 1,
  363. -1, -1, -1,
  364. 1, -1, -1,
  365. 1, 1, -1,
  366. -1, 1, -1,
  367. -1, -1, -1,
  368. -1, -1, -1,
  369. -1, 1, -1,
  370. -1, 1, 1,
  371. -1, -1, 1,
  372. -1, -1, -1,
  373. 1, -1, -1,
  374. 1, 1, -1,
  375. 1, 1, 1,
  376. 1, -1, 1,
  377. 1, -1, -1
  378. ]);
  379. const tc = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  380. const geom = new Geometry("helpermesh");
  381. geom.vertices = verts;
  382. geom.setTexCoords(tc);
  383. geom.vertexNormals = verts.slice();
  384. helperMeshes.CUBE.mesh = new Mesh(cgl, geom, cgl.gl.LINE_STRIP);
  385. }
  386. bufferData();
  387. }
  388. if (cgl.lastMesh) cgl.lastMesh.unBind();
  389. cgl.pushModelMatrix();
  390. helperMeshes.startFramebuffer(cgl);
  391. if (sizeY == undefined) sizeY = sizeX;
  392. if (sizeZ == undefined) sizeZ = sizeX;
  393. vec3.set(helperMeshes.CUBE.vScale, sizeX, sizeY, sizeZ);
  394. mat4.scale(cgl.mvMatrix, cgl.mvMatrix, helperMeshes.CUBE.vScale);
  395. let shader = helperMeshes.getDefaultShader(cgl);
  396. if (gui.patchView.isCurrentOp(op)) shader = helperMeshes.getSelectedShader(cgl);
  397. helperMeshes.CUBE.mesh.render(shader);
  398. helperMeshes.count++;
  399. cgl.popModelMatrix();
  400. helperMeshes.endFramebuffer(cgl);
  401. };
  402. helperMeshes.drawMarkerLayer = function (cgl, size)
  403. {
  404. if (!gui.shouldDrawOverlay) return;
  405. if (helperMeshes.count == 0) return;
  406. helperMeshes.count = 0;
  407. if (!helperMeshes.FB || !helperMeshes.FB.fb) return;
  408. const currentViewPort = cgl.getViewPort();
  409. const w = currentViewPort[2];
  410. const h = currentViewPort[3];
  411. if (!helperMeshes.fullscreenRectMesh || helperMeshes.FSWIDTH != w || helperMeshes.FSHEIGHT != h)
  412. {
  413. const fsGeom = new Geometry("fullscreen rectangle");
  414. helperMeshes.FSWIDTH = w;
  415. helperMeshes.FSHEIGHT = h;
  416. // prettier-ignore
  417. fsGeom.vertices = new Float32Array([
  418. w, h, 0,
  419. 0, h, 0,
  420. w, 0, 0,
  421. 0, 0, 0
  422. ]);
  423. fsGeom.texCoords = new Float32Array([
  424. 1.0, 1.0,
  425. 0.0, 1.0,
  426. 1.0, 0.0,
  427. 0.0, 0.0,
  428. ]);
  429. fsGeom.vertexNormals = new Float32Array([
  430. 0, 0, 1,
  431. 0, 0, 1,
  432. 0, 0, 1,
  433. 0, 0, 1
  434. ]);
  435. fsGeom.verticesIndices = new Uint16Array([
  436. 0, 1, 2,
  437. 3, 1, 2,
  438. ]);
  439. // helperMeshes.fsGeom=fsGeom;
  440. if (!helperMeshes.fullscreenRectMesh) helperMeshes.fullscreenRectMesh = new Mesh(cgl, fsGeom);
  441. else helperMeshes.fullscreenRectMesh.setGeom(fsGeom);
  442. // ------------
  443. if (!helperMeshes.fullscreenRectShader)
  444. {
  445. const shader = new Shader(cgl, "marker overlay");
  446. const shader_frag = "" + nl
  447. + "UNI sampler2D tex;" + nl
  448. + "IN vec2 texCoord;" + nl
  449. + "void main()" + nl
  450. + "{"
  451. /*
  452. * +nl+' vec3 gray = vec3(dot( vec3(0.2126,0.7152,0.0722), texture2D(tex,vec2(texCoord.x,(1.0-texCoord.y))).rgb ));'
  453. * +nl+' gl_FragColor = vec4(gray,1.0);'
  454. */
  455. + nl
  456. + " gl_FragColor = texture2D(tex,texCoord);"
  457. // +nl+' if(gl_FragColor.a<0.5)gl_FragColor.a=0.7;'
  458. + nl
  459. + "}";
  460. const shader_vert = "" + nl
  461. + "IN vec3 vPosition;" + nl
  462. + "UNI mat4 projMatrix;" + nl
  463. + "UNI mat4 mvMatrix;" + nl
  464. + "OUT vec2 texCoord;" + nl
  465. + "IN vec2 attrTexCoord;" + nl
  466. + "void main()" + nl
  467. + "{" + nl
  468. + " vec4 pos=vec4(vPosition, 1.0);" + nl
  469. + " texCoord=vec2(attrTexCoord.x,1.0-attrTexCoord.y);" + nl
  470. + " gl_Position = projMatrix * mvMatrix * pos;" + nl
  471. + "}";
  472. shader.setSource(shader_vert, shader_frag);
  473. shader.texUniform = new Uniform(shader, "t", "tex", 0);
  474. helperMeshes.fullscreenRectShader = shader;
  475. /*
  476. * shader.bindTextures = function ()
  477. * {
  478. * cgl.gl.activeTexture(cgl.gl.TEXTURE0);
  479. * cgl.gl.bindTexture(cgl.gl.TEXTURE_2D, helperMeshes.FB.fb.getTextureColor().tex);
  480. * };
  481. */
  482. }
  483. }
  484. cgl.gl.clear(cgl.gl.DEPTH_BUFFER_BIT);
  485. cgl.pushPMatrix();
  486. mat4.identity(cgl.pMatrix);
  487. mat4.ortho(cgl.pMatrix, 0, w, h, 0, -10.0, 1000);
  488. cgl.pushModelMatrix();
  489. mat4.identity(cgl.mvMatrix);
  490. cgl.pushViewMatrix();
  491. mat4.identity(cgl.vMatrix);
  492. helperMeshes.fullscreenRectShader.popTextures();
  493. helperMeshes.fullscreenRectShader.pushTexture(helperMeshes.fullscreenRectShader.texUniform, helperMeshes.FB.fb.getTextureColor().tex);
  494. cgl.pushShader(helperMeshes.fullscreenRectShader);
  495. /*
  496. * helperMeshes.fullscreenRectShader.bind();
  497. * cgl.getShader().bind
  498. */
  499. /*
  500. * for (var i =0;i< cgl.gl.getProgramParameter(cgl.getShader().getProgram(), cgl.gl.ACTIVE_ATTRIBUTES) ; i++)
  501. * {
  502. * console.log(i, cgl.gl.getActiveAttrib(cgl.getShader().getProgram(), i) );
  503. * }
  504. */
  505. cgl.pushBlend(true);
  506. cgl.gl.blendEquation(cgl.gl.FUNC_ADD);
  507. cgl.gl.blendFunc(cgl.gl.ONE, cgl.gl.ONE_MINUS_SRC_ALPHA);
  508. helperMeshes.fullscreenRectMesh.render(cgl.getShader());
  509. cgl.gl.blendFunc(cgl.gl.SRC_ALPHA, cgl.gl.ONE_MINUS_SRC_ALPHA);
  510. cgl.gl.clear(cgl.gl.DEPTH_BUFFER_BIT);
  511. cgl.popBlend();
  512. cgl.popShader();
  513. cgl.popPMatrix();
  514. cgl.popModelMatrix();
  515. cgl.popViewMatrix();
  516. cgl.frameCycler = !cgl.frameCycler;
  517. };