Skip to content

Emscripten build (aka too much webdev part 2)#27

Open
sppmacd wants to merge 15 commits intomainfrom
emscripten2
Open

Emscripten build (aka too much webdev part 2)#27
sppmacd wants to merge 15 commits intomainfrom
emscripten2

Conversation

@sppmacd
Copy link
Copy Markdown
Collaborator

@sppmacd sppmacd commented Jul 29, 2023

image

As a bonus, fix some annoying red wiggles shown by clang(d).

You can use this code to test it (place in your binary dir):

<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Emscripten-Generated Code</title>
    <style>
      body {
        margin: 0;
      }
      canvas {
        position: absolute;
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <canvas id="canvas" tabindex="-1" oncontextmenu="e.preventDefault()"> </canvas>

    <script type="text/javascript">
      function createCanvas() {
        var canvas = document.querySelector("canvas");

        // As a default initial behavior, pop up an alert when webgl context is lost. To make your
        // application robust, you may want to override this behavior before shipping!
        // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
        canvas.addEventListener(
          "webglcontextlost",
          (e) => {
            alert("WebGL context lost. You will need to reload the page.");
            e.preventDefault();
          },
          false
        );

        return canvas;
      }

      var Module = {
        preRun: [],
        postRun: [],
        print: (function () {
          return function (text) {
            if (arguments.length > 1)
              text = Array.prototype.slice.call(arguments).join(" ");
            // These replacements are necessary if you render to raw HTML
            //text = text.replace(/&/g, "&amp;");
            //text = text.replace(/</g, "&lt;");
            //text = text.replace(/>/g, "&gt;");
            //text = text.replace('\n', '<br>', 'g');
            console.log(text);
          };
        })(),
        canvas: createCanvas(),
        setStatus: (text) => {
          console.log("Status");
        },
      };
    </script>
    <script async src="examples/essa-gui-text-editor.js"></script>
  </body>
</html>

TODO (not this PR):

  • fix some CMake hacks
  • make closing dialogs properly return to a main loop (requires The Dialog Refactoring #28 p. 6)
  • fix multiple shaders (will require API changes because of layout(location) not supported on WebGL ??)
  • CI workflow

@sppmacd sppmacd force-pushed the emscripten2 branch 3 times, most recently from ac19df0 to 84b8d18 Compare August 2, 2023 13:12
@sppmacd sppmacd requested a review from Adam-Ratajczak August 2, 2023 13:15
@sppmacd sppmacd marked this pull request as draft August 2, 2023 13:24
sppmacd added 13 commits August 6, 2023 21:02
Clang fails to deduce template params from aggregated init.
Fixes clang complaining about something ABI
Fixes -Wunknown-warning-option error on Clang.
- Change some functions & constants to these available on GLES3
- Assign depth renderbuffer to framebuffer in correct place (Not
tested but previously it didn't make sense!)
- Don't create fbo scope if not resizing
- Add comments in FBO::resize()
Fixes build on Clang (and annoying red wiggles in editor)
It is supported on GLES3, unlike FLOAT.
It is not supported apparently (or at least compilation fails for me)
error_t is a GCC extension (?)
This optimization is actually a hack to make dialogs work on Emscripten.
Things left to do:
- port all shaders to GLES (Basic and Lighting are left)
- async dialogs (part of The Dialog Refactoring #28)

This is not ideal:
- there is a fmt include hack
- threading is not implemented (is it even supported?)
- passthrough example is not included as it requires direct X11
- multiple windows don't work (this is Emscripten limitation)
@sppmacd sppmacd marked this pull request as ready for review August 6, 2023 19:34
This fails to compile on GCC 12 for some reason
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant