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

[portability] Could it be used within Libretro core? #1109

Open
Des-Nerger opened this issue Sep 14, 2024 · 1 comment
Open

[portability] Could it be used within Libretro core? #1109

Des-Nerger opened this issue Sep 14, 2024 · 1 comment

Comments

@Des-Nerger
Copy link

Des-Nerger commented Sep 14, 2024

Could sokol be easily used within a Libretro core? Which boils down to basically:

  • Only get OpenGL symbols through a retro_hw_get_proc_address_t function (which is an analogue of SDL's SDL_GL_GetProcAddress and GLFW's glfwGetProcAddress).
  • Do not ever render to the real back buffer. Always use a FBO gotten from a retro_hw_get_current_framebuffer_t function.

https://docs.libretro.com/development/cores/opengl-cores/

@Des-Nerger Des-Nerger changed the title [portability] Could it be run within Libretro core? [portability] Could it be used within Libretro core? Sep 14, 2024
@floooh
Copy link
Owner

floooh commented Sep 15, 2024

Hmm... let's see...

The second point is easy, sokol-gfx will render to the GL framebuffer that's injected via the sg_swapchain struct in the sg_begin_pass() function, e.g. that would simply need to be filled with the result of retro_hw_get_current_framebuffer_t function in each sg_begin_pass() call.

sokol/sokol_gfx.h

Lines 2628 to 2642 in 1eb96dd

typedef struct sg_gl_swapchain {
uint32_t framebuffer; // GL framebuffer object
} sg_gl_swapchain;
typedef struct sg_swapchain {
int width;
int height;
int sample_count;
sg_pixel_format color_format;
sg_pixel_format depth_format;
sg_metal_swapchain metal;
sg_d3d11_swapchain d3d11;
sg_wgpu_swapchain wgpu;
sg_gl_swapchain gl;
} sg_swapchain;

The first point (GL functions) requires some work, but should be doable without changes to sokol_gfx.h. You basically need to define SOKOL_EXTERNAL_GL_LOADER before including the sokol_gfx.h implementation (this will skip sokol_gfx.h's own minimal GL loader on Windows, or including any system GL headers) and then create your own GL loader that's based on the retro_hw_get_proc_address_t function to populate GL function pointers.

The multiwindow_glfw.c sample uses FlextGL as external GL loader which you can use as 'inspiration' of how it could work:

https://github.com/floooh/sokol-samples/blob/master/glfw/multiwindow-glfw.c

(instead of GL 3.3 you should use GL 4.1 though if possible, GL 3.3 still works, but probably not for long, also the 'external GL loader code path' hasn't been tested with the SOKOL_GLES3 backend so far, only with SOKOL_GLCORE.

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

No branches or pull requests

2 participants