Skip to content

Commit 69c8e29

Browse files
author
GH Action
committed
1 parent c89c47d commit 69c8e29

File tree

4 files changed

+70
-41
lines changed

4 files changed

+70
-41
lines changed

sokol/app/module.jai

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@
333333
334334
int sapp_gl_get_major_version(void)
335335
int sapp_gl_get_minor_version(void)
336-
Returns the major and minor version of the GL context
337-
(only for SOKOL_GLCORE, all other backends return zero here, including SOKOL_GLES3)
336+
bool sapp_gl_is_gles(void)
337+
Returns the major and minor version of the GL context and
338+
whether the GL context is a GLES context
338339
339340
const void* sapp_android_get_native_activity(void);
340341
On Android, get the native activity ANativeActivity pointer, otherwise
@@ -1470,10 +1471,12 @@ sapp_wgpu_get_resolve_view :: () -> *void #foreign sokol_app_clib;
14701471
sapp_wgpu_get_depth_stencil_view :: () -> *void #foreign sokol_app_clib;
14711472
// GL: get framebuffer object
14721473
sapp_gl_get_framebuffer :: () -> u32 #foreign sokol_app_clib;
1473-
// GL: get major version (only valid for desktop GL)
1474+
// GL: get major version
14741475
sapp_gl_get_major_version :: () -> s32 #foreign sokol_app_clib;
1475-
// GL: get minor version (only valid for desktop GL)
1476+
// GL: get minor version
14761477
sapp_gl_get_minor_version :: () -> s32 #foreign sokol_app_clib;
1478+
// GL: return true if the context is GLES
1479+
sapp_gl_is_gles :: () -> bool #foreign sokol_app_clib;
14771480
// X11: get Window
14781481
sapp_x11_get_window :: () -> *void #foreign sokol_app_clib;
14791482
// X11: get Display

sokol/c/sokol_app.h

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@
334334
335335
int sapp_gl_get_major_version(void)
336336
int sapp_gl_get_minor_version(void)
337-
Returns the major and minor version of the GL context
338-
(only for SOKOL_GLCORE, all other backends return zero here, including SOKOL_GLES3)
337+
bool sapp_gl_is_gles(void)
338+
Returns the major and minor version of the GL context and
339+
whether the GL context is a GLES context
339340
340341
const void* sapp_android_get_native_activity(void);
341342
On Android, get the native activity ANativeActivity pointer, otherwise
@@ -1818,7 +1819,7 @@ typedef struct sapp_desc {
18181819
sapp_logger logger; // logging callback override (default: NO LOGGING!)
18191820

18201821
// backend-specific options
1821-
int gl_major_version; // override GL major and minor version (the default GL version is 4.1 on macOS, 4.3 elsewhere)
1822+
int gl_major_version; // override GL/GLES major and minor version (defaults: GL4.1 (macOS) or GL4.3, GLES3.1 (Android) or GLES3.0
18221823
int gl_minor_version;
18231824
bool win32_console_utf8; // if true, set the output console codepage to UTF-8
18241825
bool win32_console_create; // if true, attach stdout/stderr to a new console window
@@ -2010,10 +2011,12 @@ SOKOL_APP_API_DECL const void* sapp_wgpu_get_depth_stencil_view(void);
20102011

20112012
/* GL: get framebuffer object */
20122013
SOKOL_APP_API_DECL uint32_t sapp_gl_get_framebuffer(void);
2013-
/* GL: get major version (only valid for desktop GL) */
2014+
/* GL: get major version */
20142015
SOKOL_APP_API_DECL int sapp_gl_get_major_version(void);
2015-
/* GL: get minor version (only valid for desktop GL) */
2016+
/* GL: get minor version */
20162017
SOKOL_APP_API_DECL int sapp_gl_get_minor_version(void);
2018+
/* GL: return true if the context is GLES */
2019+
SOKOL_APP_API_DECL bool sapp_gl_is_gles(void);
20172020

20182021
/* X11: get Window */
20192022
SOKOL_APP_API_DECL const void* sapp_x11_get_window(void);
@@ -3216,17 +3219,21 @@ _SOKOL_PRIVATE sapp_desc _sapp_desc_defaults(const sapp_desc* desc) {
32163219
sapp_desc res = *desc;
32173220
res.sample_count = _sapp_def(res.sample_count, 1);
32183221
res.swap_interval = _sapp_def(res.swap_interval, 1);
3219-
// NOTE: can't patch the default for gl_major_version and gl_minor_version
3220-
// independently, because a desired version 4.0 would be patched to 4.2
3221-
// (or expressed differently: zero is a valid value for gl_minor_version
3222-
// and can't be used to indicate 'default')
32233222
if (0 == res.gl_major_version) {
3224-
#if defined(_SAPP_APPLE)
3225-
res.gl_major_version = 4;
3226-
res.gl_minor_version = 1;
3227-
#else
3223+
#if defined(SOKOL_GLCORE)
32283224
res.gl_major_version = 4;
3229-
res.gl_minor_version = 3;
3225+
#if defined(_SAPP_APPLE)
3226+
res.gl_minor_version = 1;
3227+
#else
3228+
res.gl_minor_version = 3;
3229+
#endif
3230+
#elif defined(SOKOL_GLES3)
3231+
res.gl_major_version = 3;
3232+
#if defined(_SAPP_ANDROID) || defined(_SAPP_LINUX)
3233+
res.gl_minor_version = 1;
3234+
#else
3235+
res.gl_minor_version = 0;
3236+
#endif
32303237
#endif
32313238
}
32323239
res.html5_canvas_selector = _sapp_def(res.html5_canvas_selector, "#canvas");
@@ -8332,7 +8339,8 @@ _SOKOL_PRIVATE bool _sapp_android_init_egl(void) {
83328339
}
83338340

83348341
EGLint ctx_attributes[] = {
8335-
EGL_CONTEXT_CLIENT_VERSION, 3,
8342+
EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl_major_version,
8343+
EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl_minor_version,
83368344
EGL_NONE,
83378345
};
83388346
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attributes);
@@ -11648,12 +11656,10 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) {
1164811656
}
1164911657

1165011658
EGLint ctx_attrs[] = {
11659+
EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl_major_version,
11660+
EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl_minor_version,
1165111661
#if defined(SOKOL_GLCORE)
11652-
EGL_CONTEXT_MAJOR_VERSION, _sapp.desc.gl_major_version,
11653-
EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl_minor_version,
1165411662
EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
11655-
#elif defined(SOKOL_GLES3)
11656-
EGL_CONTEXT_CLIENT_VERSION, 3,
1165711663
#endif
1165811664
EGL_NONE,
1165911665
};
@@ -12374,7 +12380,7 @@ SOKOL_API_IMPL uint32_t sapp_gl_get_framebuffer(void) {
1237412380

1237512381
SOKOL_API_IMPL int sapp_gl_get_major_version(void) {
1237612382
SOKOL_ASSERT(_sapp.valid);
12377-
#if defined(SOKOL_GLCORE)
12383+
#if defined(_SAPP_ANY_GL)
1237812384
return _sapp.desc.gl_major_version;
1237912385
#else
1238012386
return 0;
@@ -12383,13 +12389,21 @@ SOKOL_API_IMPL int sapp_gl_get_major_version(void) {
1238312389

1238412390
SOKOL_API_IMPL int sapp_gl_get_minor_version(void) {
1238512391
SOKOL_ASSERT(_sapp.valid);
12386-
#if defined(SOKOL_GLCORE)
12392+
#if defined(_SAPP_ANY_GL)
1238712393
return _sapp.desc.gl_minor_version;
1238812394
#else
1238912395
return 0;
1239012396
#endif
1239112397
}
1239212398

12399+
SOKOL_API_IMPL bool sapp_gl_is_gles(void) {
12400+
#if defined(SOKOL_GLES3)
12401+
return true;
12402+
#else
12403+
return false;
12404+
#endif
12405+
}
12406+
1239312407
SOKOL_API_IMPL const void* sapp_x11_get_window(void) {
1239412408
#if defined(_SAPP_LINUX)
1239512409
return (void*)_sapp.x11.window;

sokol/c/sokol_gfx.h

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,17 @@
711711

712712
- macOS and iOS with Metal
713713
- Windows with D3D11 and OpenGL
714-
- Linux with OpenGL
715-
- web with WebGPU
714+
- Linux with OpenGL or GLES3.1+
715+
- Web with WebGPU
716+
- Android with GLES3.1+
716717

717718
...this means compute shaders can't be used on the following platform/backend
718719
combos (the same restrictions apply to using storage buffers without compute
719720
shaders):
720721

721722
- macOS with GL
722723
- iOS with GLES3
723-
- Android
724-
- web with WebGL2
724+
- Web with WebGL2
725725

726726
A compute pass is started with:
727727

@@ -1185,8 +1185,7 @@
11851185
Storage buffers are *NOT* supported on the following platform/backend combos:
11861186

11871187
- macOS+GL (because storage buffers require GL 4.3, while macOS only goes up to GL 4.1)
1188-
- all GLES3 platforms (WebGL2, iOS, Android - with the option that support on
1189-
Android may be added at a later point)
1188+
- platforms which only support a GLES3.0 context (WebGL2 and iOS)
11901189

11911190
To use storage buffers, the following steps are required:
11921191

@@ -4979,17 +4978,20 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
49794978
#include <OpenGLES/ES3/gl.h>
49804979
#include <OpenGLES/ES3/glext.h>
49814980
#endif
4982-
#elif defined(__EMSCRIPTEN__) || defined(__ANDROID__)
4981+
#elif defined(__EMSCRIPTEN__)
49834982
#if defined(SOKOL_GLES3)
49844983
#include <GLES3/gl3.h>
49854984
#endif
4985+
#elif defined(__ANDROID__)
4986+
#define _SOKOL_GL_HAS_COMPUTE (1)
4987+
#include <GLES3/gl31.h>
49864988
#elif defined(__linux__) || defined(__unix__)
4989+
#define _SOKOL_GL_HAS_COMPUTE (1)
49874990
#if defined(SOKOL_GLCORE)
49884991
#define GL_GLEXT_PROTOTYPES
49894992
#include <GL/gl.h>
4990-
#define _SOKOL_GL_HAS_COMPUTE (1)
49914993
#else
4992-
#include <GLES3/gl3.h>
4994+
#include <GLES3/gl31.h>
49934995
#include <GLES3/gl3ext.h>
49944996
#endif
49954997
#endif
@@ -8346,11 +8348,16 @@ _SOKOL_PRIVATE void _sg_gl_init_caps_glcore(void) {
83468348
_SOKOL_PRIVATE void _sg_gl_init_caps_gles3(void) {
83478349
_sg.backend = SG_BACKEND_GLES3;
83488350

8351+
GLint major_version = 0;
8352+
GLint minor_version = 0;
8353+
glGetIntegerv(GL_MAJOR_VERSION, &major_version);
8354+
glGetIntegerv(GL_MINOR_VERSION, &minor_version);
8355+
const int version = major_version * 100 + minor_version * 10;
83498356
_sg.features.origin_top_left = false;
83508357
_sg.features.image_clamp_to_border = false;
83518358
_sg.features.mrt_independent_blend_state = false;
83528359
_sg.features.mrt_independent_write_mask = false;
8353-
_sg.features.compute = false;
8360+
_sg.features.compute = version >= 310;
83548361
_sg.features.msaa_image_bindings = false;
83558362

83568363
bool has_s3tc = false; // BC1..BC3
@@ -9998,6 +10005,9 @@ _SOKOL_PRIVATE void _sg_gl_apply_pipeline(_sg_pipeline_t* pip) {
999810005

999910006
#if defined _SOKOL_GL_HAS_COMPUTE
1000010007
_SOKOL_PRIVATE void _sg_gl_handle_memory_barriers(const _sg_shader_t* shd, const _sg_bindings_t* bnd) {
10008+
if (!_sg.features.compute) {
10009+
return;
10010+
}
1000110011
// NOTE: currently only storage buffers can be GPU-written, and storage
1000210012
// buffers cannot be bound as vertex- or index-buffers.
1000310013
bool needs_barrier = false;
@@ -10221,6 +10231,9 @@ _SOKOL_PRIVATE void _sg_gl_draw(int base_element, int num_elements, int num_inst
1022110231

1022210232
_SOKOL_PRIVATE void _sg_gl_dispatch(int num_groups_x, int num_groups_y, int num_groups_z) {
1022310233
#if defined(_SOKOL_GL_HAS_COMPUTE)
10234+
if (!_sg.features.compute) {
10235+
return;
10236+
}
1022410237
glDispatchCompute((GLuint)num_groups_x, (GLuint)num_groups_y, (GLuint)num_groups_z);
1022510238
#else
1022610239
(void)num_groups_x; (void)num_groups_y; (void)num_groups_z;

sokol/gfx/module.jai

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,17 +710,17 @@
710710
711711
- macOS and iOS with Metal
712712
- Windows with D3D11 and OpenGL
713-
- Linux with OpenGL
714-
- web with WebGPU
713+
- Linux with OpenGL or GLES3.1+
714+
- Web with WebGPU
715+
- Android with GLES3.1+
715716
716717
...this means compute shaders can't be used on the following platform/backend
717718
combos (the same restrictions apply to using storage buffers without compute
718719
shaders):
719720
720721
- macOS with GL
721722
- iOS with GLES3
722-
- Android
723-
- web with WebGL2
723+
- Web with WebGL2
724724
725725
A compute pass is started with:
726726
@@ -1184,8 +1184,7 @@
11841184
Storage buffers are *NOT* supported on the following platform/backend combos:
11851185
11861186
- macOS+GL (because storage buffers require GL 4.3, while macOS only goes up to GL 4.1)
1187-
- all GLES3 platforms (WebGL2, iOS, Android - with the option that support on
1188-
Android may be added at a later point)
1187+
- platforms which only support a GLES3.0 context (WebGL2 and iOS)
11891188
11901189
To use storage buffers, the following steps are required:
11911190

0 commit comments

Comments
 (0)