aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2025-10-12 20:13:44 +0200
committerAndre Weissflog <floooh@gmail.com>2025-10-12 20:13:44 +0200
commit583efa929df08065e717c5204506c01792c80dce (patch)
tree5b906d6858a6a2b023bffe7ee53c7fc2ee808479
parent95995c55d0301b5b6fe0e25bdbad8df3ffb95f8a (diff)
sokol_glue.h: sglue_swapchain => sglue_swapchain_next, and code cleanup
-rw-r--r--README.md2
-rw-r--r--sokol_app.h62
-rw-r--r--sokol_gfx.h16
-rw-r--r--sokol_glue.h4
4 files changed, 39 insertions, 45 deletions
diff --git a/README.md b/README.md
index a04d2ba4..381fa53b 100644
--- a/README.md
+++ b/README.md
@@ -168,7 +168,7 @@ static void init(void) {
}
void frame(void) {
- sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
+ sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain_next() });
sg_apply_pipeline(state.pip);
sg_apply_bindings(&state.bind);
sg_draw(0, 3, 1);
diff --git a/sokol_app.h b/sokol_app.h
index 18f31729..dcca71bc 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -2079,9 +2079,9 @@ SOKOL_APP_API_DECL int sapp_height(void);
/* same as sapp_height(), but returns float */
SOKOL_APP_API_DECL float sapp_heightf(void);
/* get default framebuffer color pixel format */
-SOKOL_APP_API_DECL int sapp_color_format(void);
+SOKOL_APP_API_DECL sapp_pixel_format sapp_color_format(void);
/* get default framebuffer depth pixel format */
-SOKOL_APP_API_DECL int sapp_depth_format(void);
+SOKOL_APP_API_DECL sapp_pixel_format sapp_depth_format(void);
/* get default framebuffer sample count */
SOKOL_APP_API_DECL int sapp_sample_count(void);
/* returns true when high_dpi was requested and actually running in a high-dpi scenario */
@@ -2223,11 +2223,6 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#define _SAPP_MAX_TITLE_LENGTH (128)
#define _SAPP_FALLBACK_DEFAULT_WINDOW_WIDTH (640)
#define _SAPP_FALLBACK_DEFAULT_WINDOW_HEIGHT (480)
-// NOTE: the pixel format values *must* be compatible with sg_pixel_format
-#define _SAPP_PIXELFORMAT_RGBA8 (23)
-#define _SAPP_PIXELFORMAT_BGRA8 (28)
-#define _SAPP_PIXELFORMAT_DEPTH (43)
-#define _SAPP_PIXELFORMAT_DEPTH_STENCIL (44)
// check if the config defines are alright
#if defined(__APPLE__)
@@ -3451,24 +3446,24 @@ _SOKOL_PRIVATE sapp_desc _sapp_desc_defaults(const sapp_desc* desc) {
sapp_desc res = *desc;
res.sample_count = _sapp_def(res.sample_count, 1);
res.swap_interval = _sapp_def(res.swap_interval, 1);
- if (0 == res.gl_major_version) {
+ if (0 == res.gl.major_version) {
#if defined(SOKOL_GLCORE)
- res.gl_major_version = 4;
+ res.gl.major_version = 4;
#if defined(_SAPP_APPLE)
- res.gl_minor_version = 1;
+ res.gl.minor_version = 1;
#else
- res.gl_minor_version = 3;
+ res.gl.minor_version = 3;
#endif
#elif defined(SOKOL_GLES3)
- res.gl_major_version = 3;
+ res.gl.major_version = 3;
#if defined(_SAPP_ANDROID) || defined(_SAPP_LINUX)
- res.gl_minor_version = 1;
+ res.gl.minor_version = 1;
#else
- res.gl_minor_version = 0;
+ res.gl.minor_version = 0;
#endif
#endif
}
- res.html5_canvas_selector = _sapp_def(res.html5_canvas_selector, "#canvas");
+ res.html5.canvas_selector = _sapp_def(res.html5.canvas_selector, "#canvas");
res.clipboard_size = _sapp_def(res.clipboard_size, 8192);
res.max_dropped_files = _sapp_def(res.max_dropped_files, 1);
res.max_dropped_file_path_length = _sapp_def(res.max_dropped_file_path_length, 2048);
@@ -3495,9 +3490,9 @@ _SOKOL_PRIVATE void _sapp_init_state(const sapp_desc* desc) {
_sapp.framebuffer_height = _sapp.window_height;
_sapp.sample_count = _sapp.desc.sample_count;
_sapp.swap_interval = _sapp.desc.swap_interval;
- _sapp_strcpy(_sapp.desc.html5_canvas_selector, _sapp.html5_canvas_selector, sizeof(_sapp.html5_canvas_selector));
- _sapp.desc.html5_canvas_selector = _sapp.html5_canvas_selector;
- _sapp.html5_ask_leave_site = _sapp.desc.html5_ask_leave_site;
+ _sapp_strcpy(_sapp.desc.html5.canvas_selector, _sapp.html5_canvas_selector, sizeof(_sapp.html5_canvas_selector));
+ _sapp.desc.html5.canvas_selector = _sapp.html5_canvas_selector;
+ _sapp.html5_ask_leave_site = _sapp.desc.html5.ask_leave_site;
_sapp.clipboard.enabled = _sapp.desc.enable_clipboard;
if (_sapp.clipboard.enabled) {
_sapp.clipboard.buf_size = _sapp.desc.clipboard_size;
@@ -11559,8 +11554,8 @@ _SOKOL_PRIVATE void _sapp_glx_create_context(void) {
}
_sapp_x11_grab_error_handler();
const int attribs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, _sapp.desc.gl_major_version,
- GLX_CONTEXT_MINOR_VERSION_ARB, _sapp.desc.gl_minor_version,
+ GLX_CONTEXT_MAJOR_VERSION_ARB, _sapp.desc.gl.major_version,
+ GLX_CONTEXT_MINOR_VERSION_ARB, _sapp.desc.gl.minor_version,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0, 0
@@ -13030,26 +13025,26 @@ SOKOL_API_IMPL float sapp_heightf(void) {
return (float)sapp_height();
}
-SOKOL_API_IMPL int sapp_color_format(void) {
+SOKOL_API_IMPL sapp_pixel_format sapp_color_format(void) {
#if defined(SOKOL_WGPU)
switch (_sapp.wgpu.render_format) {
case WGPUTextureFormat_RGBA8Unorm:
- return _SAPP_PIXELFORMAT_RGBA8;
+ return SAPP_PIXELFORMAT_RGBA8;
case WGPUTextureFormat_BGRA8Unorm:
- return _SAPP_PIXELFORMAT_BGRA8;
+ return SAPP_PIXELFORMAT_BGRA8;
default:
SOKOL_UNREACHABLE;
return 0;
}
#elif defined(SOKOL_METAL) || defined(SOKOL_D3D11)
- return _SAPP_PIXELFORMAT_BGRA8;
+ return SAPP_PIXELFORMAT_BGRA8;
#else
- return _SAPP_PIXELFORMAT_RGBA8;
+ return SAPP_PIXELFORMAT_RGBA8;
#endif
}
-SOKOL_API_IMPL int sapp_depth_format(void) {
- return _SAPP_PIXELFORMAT_DEPTH_STENCIL;
+SOKOL_API_IMPL sapp_pixel_format sapp_depth_format(void) {
+ return SAPP_PIXELFORMAT_DEPTH_STENCIL;
}
SOKOL_API_IMPL int sapp_sample_count(void) {
@@ -13413,14 +13408,13 @@ SOKOL_API_IMPL sapp_environment sapp_get_environment(void) {
SOKOL_API_IMPL sapp_swapchain sapp_swapchain_next(void) {
SOKOL_ASSERT(_sapp.valid);
- // FIXME: make sure that this is only called once per frame?
sapp_swapchain res;
_sapp_clear(&res, sizeof(res));
- res.width =
- res.height =
+ res.width = sapp_width();
+ res.height = sapp_height();
res.color_format = sapp_color_format();
res.depth_format = sapp_depth_format();
- res.sample_count = sapp_color_format();
+ res.sample_count = sapp_sample_count();
#if defined(SOKOL_METAL)
#if defined(_SAPP_MACOS)
res.metal.current_drawable = (__bridge const void*) [_sapp.macos.view currentDrawable];
@@ -13455,7 +13449,7 @@ SOKOL_API_IMPL sapp_swapchain sapp_swapchain_next(void) {
res.wgpu.depth_stencil_view = (const void*) _sapp.wgpu.depth_stencil_view;
#endif
#if defined(_SAPP_ANY_GL)
- res.framebuffer = _sapp.gl.framebuffer;
+ res.gl.framebuffer = _sapp.gl.framebuffer;
#endif
return res;
}
@@ -13501,7 +13495,7 @@ SOKOL_API_IMPL const void* sapp_win32_get_hwnd(void) {
SOKOL_API_IMPL int sapp_gl_get_major_version(void) {
SOKOL_ASSERT(_sapp.valid);
#if defined(_SAPP_ANY_GL)
- return _sapp.desc.gl_major_version;
+ return _sapp.desc.gl.major_version;
#else
return 0;
#endif
@@ -13510,7 +13504,7 @@ SOKOL_API_IMPL int sapp_gl_get_major_version(void) {
SOKOL_API_IMPL int sapp_gl_get_minor_version(void) {
SOKOL_ASSERT(_sapp.valid);
#if defined(_SAPP_ANY_GL)
- return _sapp.desc.gl_minor_version;
+ return _sapp.desc.gl.minor_version;
#else
return 0;
#endif
diff --git a/sokol_gfx.h b/sokol_gfx.h
index c00242d0..1810ce10 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -145,7 +145,7 @@
presents the rendering result on the display. Such a 'swapchain pass'
is started like this:
- sg_begin_pass(&(sg_pass){ .action = { ... }, .swapchain = sglue_swapchain() })
+ sg_begin_pass(&(sg_pass){ .action = { ... }, .swapchain = sglue_swapchain_next() })
...where .action is an sg_pass_action struct containing actions to be performed
at the start and end of a render pass (such as clearing the render surfaces to
@@ -509,7 +509,7 @@
A frame must have at least one 'swapchain render pass' which renders into an
externally provided swapchain provided as an sg_swapchain struct to the
sg_begin_pass() function. If you use sokol_gfx.h together with sokol_app.h,
- just call the sglue_swapchain() helper function in sokol_glue.h to
+ just call the sglue_swapchain_next() helper function in sokol_glue.h to
provide the swapchain information. Otherwise the following information
must be provided:
@@ -547,9 +547,9 @@
initialized sg_swapchain struct by value. This can then be directly plugged
into the sg_begin_pass function like this:
- sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() });
+ sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain_next() });
- As an example for such a helper function check out the function sglue_swapchain()
+ As an example for such a helper function check out the function sglue_swapchain_next()
in the sokol_glue.h header.
For offscreen render passes, the render target images used in a render pass
@@ -679,7 +679,7 @@
sg_begin_pass(&(sg_pass){
.action = pass_action,
- .swapchain = sglue_swapchain()
+ .swapchain = sglue_swapchain_next()
});
...
sg_end_pass();
@@ -2914,7 +2914,7 @@ typedef struct sg_pass_action {
It's a good practice to write a helper function which returns an initialized
sg_swapchain struct, which can then be plugged directly into
- sg_pass.swapchain. Look at the function sglue_swapchain() in the sokol_glue.h
+ sg_pass.swapchain. Look at the function sglue_swapchain_next() in the sokol_glue.h
as an example.
*/
typedef struct sg_metal_swapchain {
@@ -2991,12 +2991,12 @@ typedef struct sg_attachments {
function.
For a swapchain render pass, provide an sg_pass_action and sg_swapchain
- struct (for instance via the sglue_swapchain() helper function from
+ struct (for instance via the sglue_swapchain_next() helper function from
sokol_glue.h):
sg_begin_pass(&(sg_pass){
.action = { ... },
- .swapchain = sglue_swapchain(),
+ .swapchain = sglue_swapchain_next(),
});
For an offscreen render pass, provide an sg_pass_action struct with
diff --git a/sokol_glue.h b/sokol_glue.h
index 551fd113..7a4295c0 100644
--- a/sokol_glue.h
+++ b/sokol_glue.h
@@ -53,7 +53,7 @@
functions. Use this in sg_begin_pass() for a 'swapchain pass' like
this:
- sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain(), ... });
+ sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain_next(), ... });
LICENSE
=======
@@ -104,7 +104,7 @@ extern "C" {
#endif
SOKOL_GLUE_API_DECL sg_environment sglue_environment(void);
-SOKOL_GLUE_API_DECL sg_swapchain sglue_swapchain(void);
+SOKOL_GLUE_API_DECL sg_swapchain sglue_swapchain_next(void);
#ifdef __cplusplus
} /* extern "C" */