Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Beef lang bindings generator #496

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Add Beef lang bindings generator #496

wants to merge 14 commits into from

Conversation

kochol
Copy link
Contributor

@kochol kochol commented Mar 22, 2021

No description provided.

@floooh
Copy link
Owner

floooh commented Mar 22, 2021

Thanks for the PR :) I'll try to give it a whirl soon-ish (I haven't tinkered with beef yet so I first will need to read up on this a bit).

One thing: The submodule should be removed, and instead for now the scripts should expect that the bindings git repo has been checked out manually at the right place. I don't know yet if the current directory structure is final, but in any case the sokol git repository shouldn't contain submodules.

@kochol
Copy link
Contributor Author

kochol commented Mar 23, 2021

https://www.beeflang.org/ is a new programming language similar to C# but without GC and based on LLVM with many awesome features.

I also removed submodule as you requested.

@floooh
Copy link
Owner

floooh commented Mar 24, 2021

I'm currently looking into Beef a bit, just tinkering with the Beef IDE and example project. Really impressive stuff :)

Is the PR ready for merging or still WIP? As soon as you give the go ahead I can look into it. It would probably also be good to port a few examples from the sokol-samples repository.

@kochol kochol changed the title Add Beef lang bindings generator WIP: Add Beef lang bindings generator Mar 25, 2021
@kochol
Copy link
Contributor Author

kochol commented Mar 25, 2021

The below video has some info about language.
https://www.youtube.com/watch?v=L6w4y6_ENdU

For using sokol in Beef you have to create ether a static library or dynamic library to use them.
I try to port some samples so for now I make this PR WIP.

@floooh
Copy link
Owner

floooh commented Mar 25, 2021

Thanks for the link! If possible we should aim for a "batteries included" bindings repository which contains a snapshot of the sokol headers which match the generated bindings, and a simple way to compile those into a library (I would prefer static, but I don't know what's the preference is in the Beef world).

As example, check out how it looks in the Zig and Nim bindings (note the "c" subdirectory):

https://github.com/floooh/sokol-zig/tree/master/src/sokol

https://github.com/floooh/sokol-nim/tree/master/src/sokol

Both Zig and Nim can directly compile C source files though, don't know how this is handled with Beef in a cross-platform way (I guess if the Beef "build system" doesn't support compiling C libraries, then we should add a simple cmake file to the bindings repository which compiles the sokol headers into a library and could look like this snippet:

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    add_library(sokol STATIC sokol/sokol.m ${SOKOL_HEADERS})
    target_link_libraries(sokol PUBLIC
        "-framework QuartzCore"
        "-framework Cocoa"
        "-framework MetalKit"
        "-framework Metal")
else()
    add_library(sokol STATIC sokol/sokol.c ${SOKOL_HEADERS})
    if (CMAKE_SYSTEM_NAME STREQUAL Linux)
        target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL dl m)
        target_link_libraries(sokol PUBLIC Threads::Threads)
    endif()
endif()

(taken from: https://github.com/floooh/cimgui-sokol-starterkit/blob/main/CMakeLists.txt)

@floooh
Copy link
Owner

floooh commented Mar 25, 2021

PS: for porting the samples, it's a good idea to copy-paste the GLSL, HLSL and Metal shader code from the following platform-specific samples, instead of trying to extract the code-generated shader code from the sapp samples (it might make sense to add Beef-output to sokol-shdc later):

@kochol
Copy link
Contributor Author

kochol commented Apr 8, 2021

Hi @floooh
I am learning project management from you. thank you

Beef can not compile c files at this time. I don't know if it will support later or not but can work with both static and dynamic libraries so I add a cmake script to compile sokol into the .lib file.

I also write a sokol-clear example in Beef and every thing works just fine.

below is my example code in Beef

using System;
using sokol;

namespace test_sokol
{
	class Program
	{
		static Gfx.Desc _desc = .();
		static Gfx.PassAction _pass = .();

		static void OnInit()
		{
			_desc.context = Glue.context();
			Gfx.setup(&_desc);
			_pass.colors[0] = .{ action = .CLEAR, value = .{ r=1, g=1, b=0, a=1 } };
		}

		static void OnFrame()
		{
			let g = _pass.colors[0].value.g + 0.01f;
			_pass.colors[0].value.g = g > 1.0f ? 0.0f : g;
			Gfx.beginDefaultPass(&_pass, App.width(), App.height());
			Gfx.endPass();
			Gfx.commit();
		}

		static void OnEvent(App.Event* _event)
		{

		}

		static void OnCleanUp()
		{
			Gfx.shutdown();
		}

		static void OnFail(char8* msg)
		{
			Console.WriteLine(msg);
		}

		public static int Main(String[] args)
		{
			App.Desc desc = .();
			desc.init_cb = => OnInit;
			desc.frame_cb = => OnFrame;
			desc.event_cb = => OnEvent;
			desc.cleanup_cb = => OnCleanUp;
			desc.fail_cb = => OnFail;
			desc.window_title = "Beef-Clear";
			App.run(&desc);

			return 0;
		}
	}
}

@SamuelMarks SamuelMarks mentioned this pull request Aug 2, 2021
@kochol
Copy link
Contributor Author

kochol commented Jul 1, 2022

I updated my beef generator to the latest sokol version and add triangle sample to see the shaders are working or not. Also fixed a bug in my generator.

please check this sample code
https://github.com/kochol/sokol-beef/blob/main/samples/sokol-triangle/src/Program.bf

@kochol kochol changed the title WIP: Add Beef lang bindings generator Add Beef lang bindings generator Jul 1, 2022
@floooh
Copy link
Owner

floooh commented Jul 1, 2022

Ah, thanks for brining the Beef generator to my attention again :) Now that the bindings updates are automated I think it's time again to look into the PR :)

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.

None yet

2 participants