Skip to content

Commit

Permalink
Remove GLES2/WebGL1 support. (#821)
Browse files Browse the repository at this point in the history
notable changes:

- depth/stencil images are now regular gl textures
- SG_PIXELFORMAT_DEPTH now resolves to GL_DEPTH_COMPONENT32F
- sg_gl_context_desc and sg_desc.gl removed
- in sg_begin_pass() only use glClearBuffer functions
- in sg_end_pass() MSAA resolve now does glInvalidateFramebuffer() on the MSAA buffer
- sg_features: instancing, multiple_render_targets, msaa_render_targets, imagetype_3d, imagetype_array removed
- sapp_desc.gl_force_gles2 removed
- sapp_gles2() function removed
- any GLES3-to-GLES2 fallbacks removed
  • Loading branch information
floooh committed Apr 30, 2023
1 parent 7373dda commit 6cca6e3
Show file tree
Hide file tree
Showing 16 changed files with 852 additions and 1,409 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
## Updates

- **29-Apr-2023**: GLES2/WebGL1 support has been removed from the sokol headers (now that
all browsers support WebGL2, and WebGPU is around the corner I feel like it's finally
time to ditch GLES2.

This is a breaking API change in sokol_gfx.h and sokol_app.h.

Common changes across all headers:
- (breaking change) the `SOKOL_GLES2` config macro is no longer accepted and will cause a compile error
(use `SOKOL_GLES3` instead)
- (breaking change) on Emscripten use the linker option `-s USE_WEBGL2=1`
- any embedded GLES shaders have been updated from glsl100 to glsl300es (but glsl100 shaders
still work fine with the GLES3 backend)

Changes in sokol_gfx.h:
- (breaking change) the following `sg_feature` members have been removed (because those features
are no longer optional, but guaranteed across all backends):
- `sg_feature.instancing`
- `sg_feature.multiple_render_targets`
- `sg_feature.msaa_render_targets`
- `imagetype_3d`
- `imagetype_array`
- (breaking change) the struct `sg_gl_context_desc` and its embedded instance `sg_desc.gl` have been removed
- `sg_image` objects with `SG_PIXELFORMAT_DEPTH` or `SG_PIXELFORMAT_DEPTH_STENCIL` with
a `sample_count == 1` are now regular textures in the GL backend (this is not true
for MSAA depth textures unfortunately, those are still GL render buffer objects)
- in the GL backend, `SG_PIXELFORMAT_DEPTH` now resolves to `GL_DEPTH_COMPONENT32F` (same
as in the other backends), previously it was `GL_DEPTH_COMPONENT16`
- in `sg_begin_pass()`, the GL backend now only uses the new `glClearBuffer*` functions, the
old GLES2 clear functions have been removed
- in `sg_end_pass()`, the GLES3 backend now invalidates MSAA render buffers after they have
been resolved (via `glInvalidateFramebuffer`) - more control over this will come soon-ish
when this ticket is implemented: https://github.com/floooh/sokol/issues/816
- the instanced rendering functions are no longer wrapped in C macros in the GL backend

Changes in sokol_app.h:
- (breaking) the config item `sapp_desc.gl_force_gles2` has been removed
- (breaking) the function `sapp_gles2()` has been removed
- any fallback logic from GLES3 to GLES2 has been removed (in the Emscripten, Android and
iOS backends)

- **20-Feb-2023**: sokol_gfx.h has a new set of functions to get a 'best-effort'
desc struct with the creation parameters of a specific resource object:

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Simple
[STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)
cross-platform libraries for C and C++, written in C.

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**20-Feb-2023** a new set of functions in sokol_gfx.h
to get a pre-filled 'desc struct' for a resource)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**29-Apr-2023** breaking change: GLES2/WebGL1 support has been removed!)

[![Build](/../../actions/workflows/main.yml/badge.svg)](/../../actions/workflows/main.yml) [![Bindings](/../../actions/workflows/gen_bindings.yml/badge.svg)](/../../actions/workflows/gen_bindings.yml) [![build](https://github.com/floooh/sokol-zig/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-zig/actions/workflows/main.yml) [![build](https://github.com/floooh/sokol-nim/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-nim/actions/workflows/main.yml) [![Odin](https://github.com/floooh/sokol-odin/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-odin/actions/workflows/main.yml)[![Rust](https://github.com/floooh/sokol-rust/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-rust/actions/workflows/main.yml)

Expand Down Expand Up @@ -87,7 +86,7 @@ A blog post with more background info: [A Tour of sokol_gfx.h](http://floooh.git

# sokol_gfx.h:

- simple, modern wrapper around GLES2/WebGL, GLES3/WebGL2, GL3.3, D3D11 and Metal
- simple, modern wrapper around GLES3/WebGL2, GL3.3, D3D11 and Metal
- buffers, images, shaders, pipeline-state-objects and render-passes
- does *not* handle window creation or 3D API context initialization
- does *not* provide shader dialect cross-translation (**BUT** there's now an 'official' shader-cross-compiler solution which
Expand Down Expand Up @@ -200,7 +199,7 @@ A minimal cross-platform application-wrapper library:
- 3D context initialization
- event-based keyboard, mouse and touch input
- supported platforms: Win32, MacOS, Linux (X11), iOS, WASM, Android, UWP
- supported 3D-APIs: GL3.3 (GLX/WGL), Metal, D3D11, GLES2/WebGL, GLES3/WebGL2
- supported 3D-APIs: GL3.3 (GLX/WGL), Metal, D3D11, GLES3/WebGL2

A simple clear-loop sample using sokol_app.h and sokol_gfx.h (does not include
separate sokol.c/.m implementation file which is necessary
Expand Down
92 changes: 18 additions & 74 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
project):
#define SOKOL_GLCORE33
#define SOKOL_GLES2
#define SOKOL_GLES3
#define SOKOL_D3D11
#define SOKOL_METAL
Expand Down Expand Up @@ -88,14 +87,13 @@
- makes the rendered frame visible
- provides keyboard-, mouse- and low-level touch-events
- platforms: MacOS, iOS, HTML5, Win32, Linux/RaspberryPi, Android
- 3D-APIs: Metal, D3D11, GL3.2, GLES2, GLES3, WebGL, WebGL2
- 3D-APIs: Metal, D3D11, GL3.2, GLES3, WebGL, WebGL2
FEATURE/PLATFORM MATRIX
=======================
| Windows | macOS | Linux | iOS | Android | HTML5
--------------------+---------+-------+-------+-------+---------+--------
gl 3.x | YES | YES | YES | --- | --- | ---
gles2/webgl | --- | --- | YES(2)| YES | YES | YES
gles3/webgl2 | --- | --- | YES(2)| YES | YES | YES
metal | --- | YES | --- | YES | --- | ---
d3d11 | YES | --- | --- | --- | --- | ---
Expand Down Expand Up @@ -267,11 +265,6 @@
int sapp_sample_count(void)
Return the MSAA sample count of the default framebuffer.
bool sapp_gles2(void)
Returns true if a GLES2 or WebGL context has been created. This
is useful when a GLES3/WebGL2 context was requested but is not
available so that sokol_app.h had to fallback to GLES2/WebGL.
const void* sapp_metal_get_device(void)
const void* sapp_metal_get_renderpass_descriptor(void)
const void* sapp_metal_get_drawable(void)
Expand Down Expand Up @@ -1641,7 +1634,6 @@ typedef struct sapp_desc {
sapp_logger logger; // logging callback override (default: NO LOGGING!)

/* backend-specific options */
bool gl_force_gles2; // if true, setup GLES2/WebGL even if GLES3/WebGL2 is available
int gl_major_version; // override GL major and minor version (the default GL version is 3.2)
int gl_minor_version;
bool win32_console_utf8; // if true, set the output console codepage to UTF-8
Expand Down Expand Up @@ -1780,9 +1772,6 @@ SOKOL_APP_API_DECL const void* sapp_egl_get_display(void);
/* EGL: get EGLContext object */
SOKOL_APP_API_DECL const void* sapp_egl_get_context(void);

/* GL: return true when GLES2 fallback is active (to detect fallback from GLES3) */
SOKOL_APP_API_DECL bool sapp_gles2(void);

/* HTML5: enable or disable the hardwired "Leave Site?" dialog box */
SOKOL_APP_API_DECL void sapp_html5_ask_leave_site(bool ask);
/* HTML5: get byte size of a dropped file */
Expand Down Expand Up @@ -1889,8 +1878,8 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#elif defined(__EMSCRIPTEN__)
/* emscripten (asm.js or wasm) */
#define _SAPP_EMSCRIPTEN (1)
#if !defined(SOKOL_GLES3) && !defined(SOKOL_GLES2) && !defined(SOKOL_WGPU)
#error("sokol_app.h: unknown 3D API selected for emscripten, must be SOKOL_GLES3, SOKOL_GLES2 or SOKOL_WGPU")
#if !defined(SOKOL_GLES3) && !defined(SOKOL_WGPU)
#error("sokol_app.h: unknown 3D API selected for emscripten, must be SOKOL_GLES3 or SOKOL_WGPU")
#endif
#elif defined(_WIN32)
/* Windows (D3D11 or GL) */
Expand All @@ -1901,8 +1890,8 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#elif defined(__ANDROID__)
/* Android */
#define _SAPP_ANDROID (1)
#if !defined(SOKOL_GLES3) && !defined(SOKOL_GLES2)
#error("sokol_app.h: unknown 3D API selected for Android, must be SOKOL_GLES3 or SOKOL_GLES2")
#if !defined(SOKOL_GLES3)
#error("sokol_app.h: unknown 3D API selected for Android, must be SOKOL_GLES3")
#endif
#if defined(SOKOL_NO_ENTRY)
#error("sokol_app.h: SOKOL_NO_ENTRY is not supported on Android")
Expand All @@ -1914,8 +1903,8 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#if !defined(SOKOL_FORCE_EGL)
#define _SAPP_GLX (1)
#endif
#elif !defined(SOKOL_GLES3) && !defined(SOKOL_GLES2)
#error("sokol_app.h: unknown 3D API selected for Linux, must be SOKOL_GLCORE33, SOKOL_GLES3 or SOKOL_GLES2")
#elif !defined(SOKOL_GLES3)
#error("sokol_app.h: unknown 3D API selected for Linux, must be SOKOL_GLCORE33, SOKOL_GLES3")
#endif
#else
#error "sokol_app.h: Unknown platform"
Expand Down Expand Up @@ -2746,7 +2735,6 @@ typedef struct {
sapp_desc desc;
bool valid;
bool fullscreen;
bool gles2_fallback;
bool first_frame;
bool init_called;
bool cleanup_called;
Expand Down Expand Up @@ -4430,17 +4418,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) {
_sapp.ios.view_ctrl.view = _sapp.ios.view;
_sapp.ios.window.rootViewController = _sapp.ios.view_ctrl;
#else
if (_sapp.desc.gl_force_gles2) {
_sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
_sapp.gles2_fallback = true;
}
else {
_sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (_sapp.ios.eagl_ctx == nil) {
_sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
_sapp.gles2_fallback = true;
}
}
_sapp.ios.eagl_ctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
_sapp.ios.view = [[_sapp_ios_view alloc] initWithFrame:screen_rect];
_sapp.ios.view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
_sapp.ios.view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
Expand Down Expand Up @@ -5542,7 +5520,7 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_blur_cb(int emsc_type, const EmscriptenFocusEv
return true;
}

#if defined(SOKOL_GLES2) || defined(SOKOL_GLES3)
#if defined(SOKOL_GLES3)
_SOKOL_PRIVATE EM_BOOL _sapp_emsc_webgl_context_cb(int emsc_type, const void* reserved, void* user_data) {
_SOKOL_UNUSED(reserved);
_SOKOL_UNUSED(user_data);
Expand All @@ -5569,21 +5547,9 @@ _SOKOL_PRIVATE void _sapp_emsc_webgl_init(void) {
attrs.premultipliedAlpha = _sapp.desc.html5_premultiplied_alpha;
attrs.preserveDrawingBuffer = _sapp.desc.html5_preserve_drawing_buffer;
attrs.enableExtensionsByDefault = true;
#if defined(SOKOL_GLES3)
if (_sapp.desc.gl_force_gles2) {
attrs.majorVersion = 1;
_sapp.gles2_fallback = true;
}
else {
attrs.majorVersion = 2;
}
#endif
attrs.majorVersion = 2;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(_sapp.html5_canvas_selector, &attrs);
if (!ctx) {
attrs.majorVersion = 1;
ctx = emscripten_webgl_create_context(_sapp.html5_canvas_selector, &attrs);
_sapp.gles2_fallback = true;
}
// FIXME: error message?
emscripten_webgl_make_context_current(ctx);

/* some WebGL extension are not enabled automatically by emscripten */
Expand Down Expand Up @@ -5726,7 +5692,7 @@ _SOKOL_PRIVATE void _sapp_emsc_register_eventhandlers(void) {
if (_sapp.drop.enabled) {
sapp_js_add_dragndrop_listeners(&_sapp.html5_canvas_selector[1]);
}
#if defined(SOKOL_GLES2) || defined(SOKOL_GLES3)
#if defined(SOKOL_GLES3)
emscripten_set_webglcontextlost_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_webgl_context_cb);
emscripten_set_webglcontextrestored_callback(_sapp.html5_canvas_selector, 0, true, _sapp_emsc_webgl_context_cb);
#endif
Expand Down Expand Up @@ -5757,7 +5723,7 @@ _SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers() {
if (_sapp.drop.enabled) {
sapp_js_remove_dragndrop_listeners(&_sapp.html5_canvas_selector[1]);
}
#if defined(SOKOL_GLES2) || defined(SOKOL_GLES3)
#if defined(SOKOL_GLES3)
emscripten_set_webglcontextlost_callback(_sapp.html5_canvas_selector, 0, true, 0);
emscripten_set_webglcontextrestored_callback(_sapp.html5_canvas_selector, 0, true, 0);
#endif
Expand Down Expand Up @@ -5830,7 +5796,7 @@ _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) {
_sapp.framebuffer_width = (int)roundf(w * _sapp.dpi_scale);
_sapp.framebuffer_height = (int)roundf(h * _sapp.dpi_scale);
emscripten_set_canvas_element_size(_sapp.html5_canvas_selector, _sapp.framebuffer_width, _sapp.framebuffer_height);
#if defined(SOKOL_GLES2) || defined(SOKOL_GLES3)
#if defined(SOKOL_GLES3)
_sapp_emsc_webgl_init();
#elif defined(SOKOL_WGPU)
sapp_js_wgpu_init();
Expand Down Expand Up @@ -7853,16 +7819,10 @@ _SOKOL_PRIVATE bool _sapp_android_init_egl(void) {
if (eglInitialize(display, NULL, NULL) == EGL_FALSE) {
return false;
}
_sapp.gles2_fallback = _sapp.desc.gl_force_gles2;

EGLint alpha_size = _sapp.desc.alpha ? 8 : 0;
const EGLint cfg_attributes[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
#if defined(SOKOL_GLES3)
EGL_RENDERABLE_TYPE, _sapp.desc.gl_force_gles2?EGL_OPENGL_ES2_BIT:EGL_OPENGL_ES3_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#endif
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
Expand Down Expand Up @@ -7899,11 +7859,7 @@ _SOKOL_PRIVATE bool _sapp_android_init_egl(void) {
}

EGLint ctx_attributes[] = {
#if defined(SOKOL_GLES3)
EGL_CONTEXT_CLIENT_VERSION, _sapp.desc.gl_force_gles2 ? 2 : 3,
#else
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE,
};
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attributes);
Expand Down Expand Up @@ -10758,9 +10714,7 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) {
#if defined(SOKOL_GLCORE33)
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#elif defined(SOKOL_GLES3)
EGL_RENDERABLE_TYPE, _sapp.desc.gl_force_gles2 ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_ES3_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
#endif
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
Expand Down Expand Up @@ -10825,9 +10779,7 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) {
EGL_CONTEXT_MINOR_VERSION, _sapp.desc.gl_minor_version,
EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
#elif defined(SOKOL_GLES3)
EGL_CONTEXT_CLIENT_VERSION, _sapp.desc.gl_force_gles2 ? 2 : 3,
#else
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
EGL_NONE,
};
Expand All @@ -10842,10 +10794,6 @@ _SOKOL_PRIVATE void _sapp_egl_init(void) {
}

eglSwapInterval(_sapp.egl.display, _sapp.swap_interval);

#if defined(SOKOL_GLES3)
_sapp.gles2_fallback = _sapp.desc.gl_force_gles2;
#endif
}

_SOKOL_PRIVATE void _sapp_egl_destroy(void) {
Expand Down Expand Up @@ -11091,10 +11039,6 @@ SOKOL_APP_IMPL const void* sapp_egl_get_context(void) {
#endif
}

SOKOL_API_IMPL bool sapp_gles2(void) {
return _sapp.gles2_fallback;
}

SOKOL_API_IMPL void sapp_show_keyboard(bool show) {
#if defined(_SAPP_IOS)
_sapp_ios_show_keyboard(show);
Expand Down

0 comments on commit 6cca6e3

Please sign in to comment.