sokol_entry

Created on 2 Nov 2017  路  3Comments  路  Source: floooh/sokol

I started a library thats similar to https://github.com/jimon/entrypoint
The point of it:

  • Support: Windows, OSX, IOS, Android, X11
  • provide an entrypoint for your application
  • lifetime events
  • window/drawing surface & basic setup for Metal/OpenGL/DX11/WebGL
  • provide touch, gamepad, keyboard, mouse ect.
  • dragNdrop for OSX/Windows/X11

Other features I want to add but I'm not sure about them, or maybe add it after a 1.0:

  • async IO
  • network primitives (http requests ect.)
  • Android/iOS shop integration
  • iOS GameCenter
  • DX12 & Vulkan entrypoints

So the way its used its pretty similar to your sokol samples, in fact these entry points there is what I started with.
Currently I'm implementing OSX and iOS, both supporting Metal & OpenGL (for OpenGL it looks like I still need something like glad)

So this is how your clear-metal looks now with sokol_entry, not much changed, in fact for OSX/iOS its mostly renaming...

//------------------------------------------------------------------------------
//  clear-metal.c
//------------------------------------------------------------------------------
#include "sokol_gfx.h"
#include "sokol_entry/sokol_entry.h"

sg_pass_action pass_action;

void init(const sg_gfx_init_data *data) {
    sg_desc desc = {
        .mtl_device = data->mtl_device,
        .mtl_renderpass_descriptor_cb = data->mtl_renderpass_descriptor_cb,
        .mtl_drawable_cb = data->mtl_drawable_cb
    };
    sg_setup(&desc);
    pass_action = (sg_pass_action) {
        .colors[0] = { .action = SG_ACTION_CLEAR, .val = { 1.0f, 0.0f, 0.0f, 1.0f } }
    };
}
static bool wasFullscreen;
void frame() {
    sg_set_window_fullscreen(true);
    if (sg_is_window_fullscreen()) {
        wasFullscreen = true;
    }
    if (!sg_is_window_fullscreen() && wasFullscreen) {
        sg_quite();
    }

    /* animate clear colors */
    float g = pass_action.colors[0].val[1] + 0.01f;
    if (g > 1.0f) g = 0.0f;
    pass_action.colors[0].val[1] = g;

    /* draw one frame */
    sg_begin_default_pass(&pass_action, sg_get_window_width(), sg_get_window_width());
    sg_end_pass();
    sg_commit();
}

void shutdown() {
    sg_shutdown();
}

void sg_main() {
    sg_start(840, 480, 1, "Sokol Clear (Metal)", init, frame, shutdown);
}

So.. do you have interest in this? If not I will rename it to something else. Also any feedback is very welcome.

You can see my current WiP code here:
https://github.com/pjako/sokol/tree/entry/sokol_entry

Most helpful comment

Looks nice :) I'll give it a try ASAP and try to give some feedback. One reason why I didn't do this right away was the overlap with GLFW, and I also didn't want to accidently limit sokol_gfx to a frame-callback model (but for a general entry-point lib this is the only way to go).

Oh and another thing: I was thinking that only the sokol_gfx header should use the sg_ prefix (for sokolgfx. Other headers would use something different, e.g. an sokol_input.h would use si_.

All 3 comments

Looks nice :) I'll give it a try ASAP and try to give some feedback. One reason why I didn't do this right away was the overlap with GLFW, and I also didn't want to accidently limit sokol_gfx to a frame-callback model (but for a general entry-point lib this is the only way to go).

Oh and another thing: I was thinking that only the sokol_gfx header should use the sg_ prefix (for sokolgfx. Other headers would use something different, e.g. an sokol_input.h would use si_.

I think I finally made up my mind about an application wrapper sokol header... My main problem was what needs to be different from GLFW to justify the effort. I'll start sketching out a sokol_app.h header, this will be fairly low prio until I have finished the move of Oryol to sokol-gfx.

I hope you don't mind that I'm not forking sokol_entry.h ;)

Here's what I thought up so far:

  • no support for multiple windows, at least in the beginning (mobile and web cannot support multiple windows anyway, this would be the 1st thing that's different from GLFW)
  • likewise no multimonitor support (only the minimum needed for HighDPI)
  • minimal HighDPI support like implemented in Oryol
  • initial platform support same as Oryol: Win32+GL+D3D11, OSX+GL+Metal, iOS+GL+Metal, Linux+GL, emscripten+WebGL+WebGL2, Android+GLES2+GLES3, RaspberryPi+GLES2,
  • must use a frame-callback function because of restrictions on some platforms (3nd thing that's different from GLFW)
  • needs to completely hijack the main() function (since some platforms don't have a main function, another point that's different to GLFW)
  • keep the API for input as small as possible (most likely only a single input event struct and event handler callback - have a separate sokol_input.h later with a more convenient input API)
  • ...still have a SOKOL_GLFW define to fallback to GLFW (mainly for testing and robustness)

The main difference to sokol_entry.h would be that there will be less API functions for window control, basically I want to avoid functions that are not needed on mobile platforms as long as possible :)

I don't mind at all, its pretty sketchy in its current state anyways.

Reducing the input api sounds like a good idea to me. I was even thinking about delivering everything you need to do a frame update in a single big struct as a parameter of your frame update callback. (But this approach has some problems in some cases)

So I guess we can close this issue, looking forward to sokol_app.h :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

floooh picture floooh  路  3Comments

septag picture septag  路  6Comments

siavashserver picture siavashserver  路  6Comments

floooh picture floooh  路  7Comments

DomDumont picture DomDumont  路  6Comments