Home Reference Source

cables_dev/cables_ui/src/ui/components/tabs/tab_profiler_drawcalls.js

  1. import { uuid } from "cables/src/core/utils.js";
  2. import { ele } from "cables-shared-client";
  3. import defaultOps from "../../defaultops.js";
  4. import Tab from "../../elements/tabpanel/tab.js";
  5. import { gui } from "../../gui.js";
  6. export class ProfilerDrawCalls
  7. {
  8. /**
  9. * @param {import("../../elements/tabpanel/tabpanel.js").default} tabs
  10. */
  11. constructor(tabs)
  12. {
  13. this._tab = new Tab("GPU Profiler", { "icon": "pie-chart", "singleton": true, "infotext": "tab_profiler", "padding": true });
  14. tabs.addTab(this._tab, true);
  15. const glQueryExt = gui.corePatch().cgl.gl.getExtension("EXT_disjoint_timer_query_webgl2");
  16. if (glQueryExt)gui.corePatch().cgl.profileData.doProfileGlQuery = true;
  17. // gui.corePatch().cgl.profileData.glQueryData = {};
  18. // this.update();
  19. let html = "<div class=\"tabContentScrollContainer\"><h2>Drawcalls</h2>";
  20. html += "<a id=\"updatedc\" class=\"cblbutton\" >update</a>";
  21. html += "<div id=\"dcresults\"></div>";
  22. this._tab.html(html);
  23. ele.clickable(ele.byId("updatedc"), () =>
  24. {
  25. this.update();
  26. });
  27. this.update();
  28. }
  29. update()
  30. {
  31. // const glQueryData = gui.corePatch().cgl.profileData.glQueryData;
  32. const cgl = gui.corePatch().cgl;
  33. const l1 = cgl.on("beginFrame", () =>
  34. {
  35. cgl.off(l1);
  36. cgl.profileData.profileDrawCalls = [];
  37. const l2 = cgl.on("endFrame", () =>
  38. {
  39. console.log("sresresr", gui.corePatch().cgl.profileData.profileDrawCalls);
  40. cgl.off(l2);
  41. const calls = gui.corePatch().cgl.profileData.profileDrawCalls;
  42. let html = "";
  43. html += calls.length + " drawcalls";
  44. html += "<div class=\"editor_spreadsheet\">";
  45. html += "<table class=\"spreadsheet\">";
  46. html += "<tr>";
  47. html += "<td class=\"colname\">mesh</td>";
  48. html += "<td class=\"colname\">shader</td>";
  49. html += "<td class=\"colname\">verts</td>";
  50. html += "<td class=\"colname\">instances </td>";
  51. html += "<td class=\"colname\"></td>";
  52. html += "</tr>";
  53. for (let i = 0; i < calls.length; i++)
  54. {
  55. html += "<tr>";
  56. html += "<td>" + calls[i].name + "</td>";
  57. html += "<td>" + calls[i].shader + "</td>";
  58. html += "<td>" + calls[i].verts + "</td>";
  59. html += "<td>" + calls[i].instances || 1 + "</td>";
  60. if (calls[i].opId)html += "<td><a onclick=\"gui.patchView.focusOpAnim('" + calls[i].opId + "');gui.patchView.centerSelectOp('" + calls[i].opId + "');\" class=\"cblbutton\" >mesh</a></td>";
  61. html += "</tr>";
  62. }
  63. ele.byId("dcresults").innerHTML = html;
  64. cgl.profileData.profileDrawCalls = null;
  65. });
  66. });
  67. }
  68. }