TotallyGamerJet / onlygo

Generate pure go wrappers to c functions
MIT License
11 stars 0 forks source link

Collaboration - Input #1

Open jensfredgaard opened 2 years ago

jensfredgaard commented 2 years ago

Hey TotallyGamerJet!

I have been checking in on your work from time to time and I really like what you are trying to do! In 2018 I began developing an ambitious RTS game in Go and it has been a blast so far. Since I began this project i knew that some day I would have to swap OpenGL4.3 out for Vulkan. With Apple announcing their Metal 3 API it seems that time is now. In addition, since I upgraded from GL3.3 to GL4.3 I have only made game code from my Windows machine and with the new M2 chip, I would actually love to make a full jump back to OSX.

Based on your experience, what would your approach be to make Vulkan bindings or is this already something you have planned?

TotallyGamerJet commented 2 years ago

Hey! There are already Vulkan bindings for Go here which uses Cgo. Unless you are asking for a Cgo-less version. I don't believe such a thing exists. However, it shouldn't be too hard to make with using purego which is where all my time has been focused.

jensfredgaard commented 2 years ago

Yep, I want to run without cgo, which is why I think your projects are interesting! Can you provide an example for purego?

By looking at the code I am guessing that you load a library, get the ProcAddress and then create go corresponding function with matching parameters.

TotallyGamerJet commented 2 years ago

Sure thing! purego is an Ebitengine project and used in Ebitengine. It's used in the OpenGL part for macOS. The steps are to purego.Dlopen the framework and then purego.Dlsym each function you want to call. Then use purego.SyscallN to call the function. Note that right now only up to 9 arguments are supported.

This won't help with creating a window though which still requires Cgo through something like GLFW. I'm planning on fixing that in Ebitengine but I first need to finish adding Objective-C support to purego.

jensfredgaard commented 2 years ago

Great!

Kinda funny, about two weeks ago I made support for "disable sticky keys and shortcuts" on Windows, which led me to begin building my own cross platform window manager... basically the same as your GWL :D

I will start looking at the best approach for Vulkan bindings.