node-3d / glfw-raub

GLFW for Node.js
https://github.com/node-3d/node-3d
MIT License
57 stars 12 forks source link

upgrade glfw to version 3.4+ #11

Closed wis closed 3 years ago

wis commented 3 years ago

The Node3D project is awesome!

I need to use new features in 3.4 like MOUSE_PASSTHROUGH hint, currently there's no binding for it because the pre-built library version is 3.3, so I'm getting this error:

glfw.windowHint(glfw.MOUSE_PASSTHROUGH, 1);
     ^

Error: Argument 0 must be of type `Uint32`
raub commented 3 years ago

Hello. What is GLFW 3.4 anyway? There is no actual 3.4 release of GLFW. I will build an updated version of glfw-raub as soon as 3.4 gets released.

If you want it right now, at any cost, you can easily fork the related modules and rebuild it against the current snapshot of GLFW master branch. I may provide further instructions, if you decide to take this route.

wis commented 3 years ago

oh, damn it, sorry I didn't realize GLFW had a release schedule that's this infrequent, I though 3.4 was already released with this feature (this comment and commit to master is from July).

Yeah, I would really appreciate it if you can give me instructions on how to add this missing hint binding, make a pre-built of the master branch and use it in my project (add a path to the package to my package.json?)

raub commented 3 years ago

How to rebuild:

Make a fork of https://github.com/node-3d/deps-opengl-raub. Go to src, replace glfw-3.3.zip with the new one. Update the *-glfw.sh files with the new ZIP name. Note: there is no SH file for Windows because I simply downloaded the official binaries. Also update the headers: https://github.com/node-3d/deps-opengl-raub/tree/master/include/GLFW

You can use Travis CI to build the binaries, if you dont't have physical devices. You will have to provide a GITHUB_TOKEN configuration in your version of this https://travis-ci.com/github/node-3d/deps-opengl-raub/settings page (for your fork). Github will also need your confirmation to allow Travis CI reading your repositories. Then, push a commit, starting with :hammer: emoji in its message. That would trigger a build on CI. A successfull build will result in 2 draft releases created (with CI deploy step) on your fork. You may download the attached binaries and use those how you like. If/when the CI build/deploy fails, edit the files and push yet another :hammer: commit.

You may also run the SH files locally, given you have the needed machines. This is the only way to build for Windows, because Travis CI somehow fails on Windows builds (I wonder if they have actually fixed it after a year). And you will have to come up with your own build script to run CMake. Anyway, Windows build script should be almost identical to that for any other platform (because CMake). That is, if you target Windows at all.


Deploy

Let's imagine, you succeeded with the build. What then? You have to set up the installation. First, edit this file https://github.com/node-3d/deps-opengl-raub/blob/master/install.js so that it links to your fork. Then edit https://github.com/node-3d/deps-opengl-raub/blob/master/package.json here:

    "config": {
        "install": "v3.0.0"
    },

This is a tag/version of the Github release to take binaries from. You might want to use something new, like "v.3.4.0-pre" or anything. Edit that and push a new commit (without :hammer: this time). The CI will also fail this time because there is no such release/tag. Let's create it: go to Releases section of your fork, create a new release, and tag it the same v.3.4.0-pre. Attach the binaries you now have. The names to be: windows.zip, linux.zip and osx.zip. You are going to end up with something like this: https://github.com/node-3d/deps-opengl-raub/releases/tag/v3.0.0

After that, a new CI run (triggered by the release) should succeed, since now the downloads are available.


GLFW

It's probably a bit easier, since you've got acquainted with the workflow. Again, make a fork. In both https://github.com/node-3d/glfw-raub/blob/master/package.json and https://github.com/node-3d/glfw-raub/blob/master/src/package.json, replace "deps-opengl-raub": "3.0.x" with "deps-opengl-raub": "https://github.com/wis/deps-opengl-raub" (I guess the name of your fork will be that). Then go to https://github.com/node-3d/glfw-raub/tree/master/src and run npm i (and not npm ci). Now you should have installed the GLFW dependency from your own fork, and rebuilt glfw.node locally against it. You may also run npm run build inside src. This command builds the addon locally and copies it to the root of your fork, there it is searched by the examples. At this point we might validate if the new build is what we wanted. Head to https://github.com/node-3d/glfw-raub/tree/master/examples and hijack any of those (or create a new one) to try the new window hint.

Instead of glfw.windowHint(glfw.MOUSE_PASSTHROUGH, 1);, Use glfw.windowHint(0x0002000D, 1); (I got this constant directly from https://github.com/glfw/glfw/blob/master/include/GLFW/glfw3.h).

Using this constant as an immediate value allows us to avoid editing glfw.node sources. Now, building the binaries is almost the same scenario, but the standard node-gyp is used instead of CMake. You just push a :hammer: ... commit and see if it yields any binaries. Don't forget to provide the same GITHUB_TOKEN again, for this fork. On Windows, I personally, always build locally (hence no CI set up to do that). Anyway, sooner or later, you will have up to 3 binary modules, which go to their respective ZIP files as it was with the release of deps-opengl-raub. You may also see https://github.com/node-3d/glfw-raub/releases/tag/v4.5.0 for reference. After building the binaries, you have to tweak the installation the same way as above: install.js and package.json have to reference your fork and the upcoming release tag. Then push and publish the release. See if CI successfully validates the installation.


And there you have it. The new GLFW Node.js addon, built against version 3.4 of GLFW. You may further reference it with its Github link instead of NPM version.

raub commented 3 years ago

A small update on this. There is now a more convenient way to build the binaries (at https://github.com/node-3d/deps-opengl-raub/tree/master/.github/workflows) using GitHub Actions. And the latest glfw@3.3.4 is used in glfw-raub@4.6.0.

Yeah, it's still not glfw@3.4, but now it's easier to fork and build whatever version you want. As before, the binary will land as a draft release, and it's up to you how to use it.