aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Collyer <ovcollyer@mac.com>2020-12-04 11:17:44 +0000
committerOliver Collyer <ovcollyer@mac.com>2020-12-04 11:17:44 +0000
commit100a28d7d4713f3ff3e8aa847362b310e0f97db4 (patch)
tree5062fe70846f21fc17c6ef529fee1704a1639042
parentb2c57f2ef9a6202fbd17883933fa336e1b94627e (diff)
parent64a6f2e2fac607ddcd4ccc5bd8bcd25946293550 (diff)
Merge branch 'master' into sokol-audio-avaudiosession
-rw-r--r--README.md32
-rw-r--r--sokol_app.h128
-rw-r--r--sokol_args.h52
-rw-r--r--sokol_audio.h48
-rw-r--r--sokol_fetch.h56
-rw-r--r--sokol_gfx.h466
-rw-r--r--sokol_glue.h30
-rw-r--r--sokol_time.h48
-rw-r--r--util/sokol_debugtext.h102
-rw-r--r--util/sokol_fontstash.h29
-rw-r--r--util/sokol_gfx_imgui.h356
-rw-r--r--util/sokol_gl.h170
-rw-r--r--util/sokol_imgui.h33
-rw-r--r--util/sokol_memtrack.h25
-rw-r--r--util/sokol_shape.h74
15 files changed, 1131 insertions, 518 deletions
diff --git a/README.md b/README.md
index 81720c3f..2bb635e3 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,9 @@ 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](#updates) (**17-Nov-2020** new utility header: sokol_shape.h)
+[**See what's new**](#updates) (**02-Dec-2020** sokol_gfx.h: new sg_uninit_xxx() and sg_dealloc_xxx() functions)
+
+## Examples and Related Projects
[Live Samples](https://floooh.github.io/sokol-html5/index.html) via WASM.
@@ -16,10 +18,10 @@ Sample code is in a separate repo: https://github.com/floooh/sokol-samples
[Dear ImGui starterkit](https://github.com/floooh/cimgui-sokol-starterkit) a self-contained starterkit for writing Dear ImGui apps in C.
-Command line tools: https://github.com/floooh/sokol-tools
-
Tiny 8-bit emulators: https://floooh.github.io/tiny8bit/
+Command line tools: https://github.com/floooh/sokol-tools
+
## Core libraries
- [**sokol\_gfx.h**](https://github.com/floooh/sokol/blob/master/sokol_gfx.h): 3D-API wrapper (GL + Metal + D3D11)
@@ -439,6 +441,30 @@ Emulators](https://floooh.github.io/tiny8bit/) for more interesting usage exampl
# Updates
+- **02-Dec-2020**: sokol_gfx.h has a couple new public API functions for
+destroying resources in two steps:
+ - sg_uninit_buffer + sg_dealloc_buffer
+ - sg_uninit_image + sg_dealloc_image
+ - sg_uninit_shader + sg_dealloc_shader
+ - sg_uninit_pipeline + sg_dealloc_pipeline
+ - sg_uninit_pass + sg_dealloc_pass
+
+ Calling both functions in this order is identical with calling the
+ traditional sg_destroy_xxx() functions. See this PR for more details:
+ https://github.com/floooh/sokol/pull/435. Many thanks to @oviano for the
+ PR!
+
+- **28-Nov-2020**: In addition to the generic SOKOL_API_DECL and SOKOL_IMPL
+defines there are now header-specific versions SOKOL_xxx_API_DECL and
+SOKOL_xxx_IMPL (for instance SOKOL_GFX_API_DECL and SOKOL_GFX_IMPL). The
+original motivation for splitting the SOKOL_API_DECL defines up is described
+here: https://github.com/floooh/sokol/issues/428). The same change for
+SOKOL_IMPL also finally unifies the approach used in the utility headers (in
+the ```util``` subdirectory), which exclusively used the SOKOL_xxx_IMPL
+pattern with the core headers which exclusively used SOKOL_IMPL before (all
+headers accept both patterns now). Many thanks to @iboB for providing the
+API_DECL PR!
+
- **17-Nov-2020**: A new utility header **sokol_shape.h** to generate
vertices+indices for simple shapes (plane, box, sphere, cylinder and torus),
which seamlessly plug into the sokol_gfx.h resource creation functions. As
diff --git a/sokol_app.h b/sokol_app.h
index aa67a216..0bdc30ba 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_APP_IMPL)
+#define SOKOL_APP_IMPL
+#endif
#ifndef SOKOL_APP_INCLUDED
/*
sokol_app.h -- cross-platform application wrapper
@@ -5,7 +8,8 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_APP_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -29,7 +33,8 @@
SOKOL_ABORT() - called after an unrecoverable error (default: abort())
SOKOL_WIN32_FORCE_MAIN - define this on Win32 to use a main() entry point instead of WinMain
SOKOL_NO_ENTRY - define this if sokol_app.h shouldn't "hijack" the main() function
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_APP_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_APP_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_CALLOC - your own calloc function (default: calloc(n, s))
SOKOL_FREE - your own free function (default: free(p))
@@ -44,7 +49,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_APP_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
If you use sokol_app.h together with sokol_gfx.h, include both headers
@@ -859,13 +864,16 @@
#include <stdint.h>
#include <stdbool.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_APP_API_DECL)
+#define SOKOL_APP_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_APP_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_APP_IMPL)
+#define SOKOL_APP_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_APP_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_APP_API_DECL extern
#endif
#endif
@@ -1146,108 +1154,108 @@ typedef struct sapp_html5_fetch_request {
extern sapp_desc sokol_main(int argc, char* argv[]);
/* returns true after sokol-app has been initialized */
-SOKOL_API_DECL bool sapp_isvalid(void);
+SOKOL_APP_API_DECL bool sapp_isvalid(void);
/* returns the current framebuffer width in pixels */
-SOKOL_API_DECL int sapp_width(void);
+SOKOL_APP_API_DECL int sapp_width(void);
/* returns the current framebuffer height in pixels */
-SOKOL_API_DECL int sapp_height(void);
+SOKOL_APP_API_DECL int sapp_height(void);
/* get default framebuffer color pixel format */
-SOKOL_API_DECL int sapp_color_format(void);
+SOKOL_APP_API_DECL int sapp_color_format(void);
/* get default framebuffer depth pixel format */
-SOKOL_API_DECL int sapp_depth_format(void);
+SOKOL_APP_API_DECL int sapp_depth_format(void);
/* get default framebuffer sample count */
-SOKOL_API_DECL int sapp_sample_count(void);
+SOKOL_APP_API_DECL int sapp_sample_count(void);
/* returns true when high_dpi was requested and actually running in a high-dpi scenario */
-SOKOL_API_DECL bool sapp_high_dpi(void);
+SOKOL_APP_API_DECL bool sapp_high_dpi(void);
/* returns the dpi scaling factor (window pixels to framebuffer pixels) */
-SOKOL_API_DECL float sapp_dpi_scale(void);
+SOKOL_APP_API_DECL float sapp_dpi_scale(void);
/* show or hide the mobile device onscreen keyboard */
-SOKOL_API_DECL void sapp_show_keyboard(bool show);
+SOKOL_APP_API_DECL void sapp_show_keyboard(bool show);
/* return true if the mobile device onscreen keyboard is currently shown */
-SOKOL_API_DECL bool sapp_keyboard_shown(void);
+SOKOL_APP_API_DECL bool sapp_keyboard_shown(void);
/* query fullscreen mode */
-SOKOL_API_DECL bool sapp_is_fullscreen(void);
+SOKOL_APP_API_DECL bool sapp_is_fullscreen(void);
/* toggle fullscreen mode */
-SOKOL_API_DECL void sapp_toggle_fullscreen(void);
+SOKOL_APP_API_DECL void sapp_toggle_fullscreen(void);
/* show or hide the mouse cursor */
-SOKOL_API_DECL void sapp_show_mouse(bool show);
+SOKOL_APP_API_DECL void sapp_show_mouse(bool show);
/* show or hide the mouse cursor */
-SOKOL_API_DECL bool sapp_mouse_shown();
+SOKOL_APP_API_DECL bool sapp_mouse_shown();
/* enable/disable mouse-pointer-lock mode */
-SOKOL_API_DECL void sapp_lock_mouse(bool lock);
+SOKOL_APP_API_DECL void sapp_lock_mouse(bool lock);
/* return true if in mouse-pointer-lock mode (this may toggle a few frames later) */
-SOKOL_API_DECL bool sapp_mouse_locked(void);
+SOKOL_APP_API_DECL bool sapp_mouse_locked(void);
/* return the userdata pointer optionally provided in sapp_desc */
-SOKOL_API_DECL void* sapp_userdata(void);
+SOKOL_APP_API_DECL void* sapp_userdata(void);
/* return a copy of the sapp_desc structure */
-SOKOL_API_DECL sapp_desc sapp_query_desc(void);
+SOKOL_APP_API_DECL sapp_desc sapp_query_desc(void);
/* initiate a "soft quit" (sends SAPP_EVENTTYPE_QUIT_REQUESTED) */
-SOKOL_API_DECL void sapp_request_quit(void);
+SOKOL_APP_API_DECL void sapp_request_quit(void);
/* cancel a pending quit (when SAPP_EVENTTYPE_QUIT_REQUESTED has been received) */
-SOKOL_API_DECL void sapp_cancel_quit(void);
+SOKOL_APP_API_DECL void sapp_cancel_quit(void);
/* initiate a "hard quit" (quit application without sending SAPP_EVENTTYPE_QUIT_REQUSTED) */
-SOKOL_API_DECL void sapp_quit(void);
+SOKOL_APP_API_DECL void sapp_quit(void);
/* call from inside event callback to consume the current event (don't forward to platform) */
-SOKOL_API_DECL void sapp_consume_event(void);
+SOKOL_APP_API_DECL void sapp_consume_event(void);
/* get the current frame counter (for comparison with sapp_event.frame_count) */
-SOKOL_API_DECL uint64_t sapp_frame_count(void);
+SOKOL_APP_API_DECL uint64_t sapp_frame_count(void);
/* write string into clipboard */
-SOKOL_API_DECL void sapp_set_clipboard_string(const char* str);
+SOKOL_APP_API_DECL void sapp_set_clipboard_string(const char* str);
/* read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) */
-SOKOL_API_DECL const char* sapp_get_clipboard_string(void);
+SOKOL_APP_API_DECL const char* sapp_get_clipboard_string(void);
/* set the window title (only on desktop platforms) */
-SOKOL_API_DECL void sapp_set_window_title(const char* str);
+SOKOL_APP_API_DECL void sapp_set_window_title(const char* str);
/* gets the total number of dropped files (after an SAPP_EVENTTYPE_FILES_DROPPED event) */
-SOKOL_API_DECL int sapp_get_num_dropped_files(void);
+SOKOL_APP_API_DECL int sapp_get_num_dropped_files(void);
/* gets the dropped file paths */
-SOKOL_API_DECL const char* sapp_get_dropped_file_path(int index);
+SOKOL_APP_API_DECL const char* sapp_get_dropped_file_path(int index);
/* special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub) */
-SOKOL_API_DECL int sapp_run(const sapp_desc* desc);
+SOKOL_APP_API_DECL int sapp_run(const sapp_desc* desc);
/* GL: return true when GLES2 fallback is active (to detect fallback from GLES3) */
-SOKOL_API_DECL bool sapp_gles2(void);
+SOKOL_APP_API_DECL bool sapp_gles2(void);
/* HTML5: enable or disable the hardwired "Leave Site?" dialog box */
-SOKOL_API_DECL void sapp_html5_ask_leave_site(bool ask);
+SOKOL_APP_API_DECL void sapp_html5_ask_leave_site(bool ask);
/* HTML5: get byte size of a dropped file */
-SOKOL_API_DECL uint32_t sapp_html5_get_dropped_file_size(int index);
+SOKOL_APP_API_DECL uint32_t sapp_html5_get_dropped_file_size(int index);
/* HTML5: asynchronously load the content of a dropped file */
-SOKOL_API_DECL void sapp_html5_fetch_dropped_file(const sapp_html5_fetch_request* request);
+SOKOL_APP_API_DECL void sapp_html5_fetch_dropped_file(const sapp_html5_fetch_request* request);
/* Metal: get bridged pointer to Metal device object */
-SOKOL_API_DECL const void* sapp_metal_get_device(void);
+SOKOL_APP_API_DECL const void* sapp_metal_get_device(void);
/* Metal: get bridged pointer to this frame's renderpass descriptor */
-SOKOL_API_DECL const void* sapp_metal_get_renderpass_descriptor(void);
+SOKOL_APP_API_DECL const void* sapp_metal_get_renderpass_descriptor(void);
/* Metal: get bridged pointer to current drawable */
-SOKOL_API_DECL const void* sapp_metal_get_drawable(void);
+SOKOL_APP_API_DECL const void* sapp_metal_get_drawable(void);
/* macOS: get bridged pointer to macOS NSWindow */
-SOKOL_API_DECL const void* sapp_macos_get_window(void);
+SOKOL_APP_API_DECL const void* sapp_macos_get_window(void);
/* iOS: get bridged pointer to iOS UIWindow */
-SOKOL_API_DECL const void* sapp_ios_get_window(void);
+SOKOL_APP_API_DECL const void* sapp_ios_get_window(void);
/* D3D11: get pointer to ID3D11Device object */
-SOKOL_API_DECL const void* sapp_d3d11_get_device(void);
+SOKOL_APP_API_DECL const void* sapp_d3d11_get_device(void);
/* D3D11: get pointer to ID3D11DeviceContext object */
-SOKOL_API_DECL const void* sapp_d3d11_get_device_context(void);
+SOKOL_APP_API_DECL const void* sapp_d3d11_get_device_context(void);
/* D3D11: get pointer to ID3D11RenderTargetView object */
-SOKOL_API_DECL const void* sapp_d3d11_get_render_target_view(void);
+SOKOL_APP_API_DECL const void* sapp_d3d11_get_render_target_view(void);
/* D3D11: get pointer to ID3D11DepthStencilView */
-SOKOL_API_DECL const void* sapp_d3d11_get_depth_stencil_view(void);
+SOKOL_APP_API_DECL const void* sapp_d3d11_get_depth_stencil_view(void);
/* Win32: get the HWND window handle */
-SOKOL_API_DECL const void* sapp_win32_get_hwnd(void);
+SOKOL_APP_API_DECL const void* sapp_win32_get_hwnd(void);
/* WebGPU: get WGPUDevice handle */
-SOKOL_API_DECL const void* sapp_wgpu_get_device(void);
+SOKOL_APP_API_DECL const void* sapp_wgpu_get_device(void);
/* WebGPU: get swapchain's WGPUTextureView handle for rendering */
-SOKOL_API_DECL const void* sapp_wgpu_get_render_view(void);
+SOKOL_APP_API_DECL const void* sapp_wgpu_get_render_view(void);
/* WebGPU: get swapchain's MSAA-resolve WGPUTextureView (may return null) */
-SOKOL_API_DECL const void* sapp_wgpu_get_resolve_view(void);
+SOKOL_APP_API_DECL const void* sapp_wgpu_get_resolve_view(void);
/* WebGPU: get swapchain's WGPUTextureView for the depth-stencil surface */
-SOKOL_API_DECL const void* sapp_wgpu_get_depth_stencil_view(void);
+SOKOL_APP_API_DECL const void* sapp_wgpu_get_depth_stencil_view(void);
/* Android: get native activity handle */
-SOKOL_API_DECL const void* sapp_android_get_native_activity(void);
+SOKOL_APP_API_DECL const void* sapp_android_get_native_activity(void);
#ifdef __cplusplus
} /* extern "C" */
@@ -1268,7 +1276,7 @@ inline int sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#endif // SOKOL_APP_INCLUDED
/*-- IMPLEMENTATION ----------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_APP_IMPL
#define SOKOL_APP_IMPL_INCLUDED (1)
#include <string.h> /* memset */
@@ -10207,11 +10215,11 @@ SOKOL_API_IMPL bool sapp_keyboard_shown(void) {
return _sapp.onscreen_keyboard_shown;
}
-SOKOL_API_DECL bool sapp_is_fullscreen(void) {
+SOKOL_APP_API_DECL bool sapp_is_fullscreen(void) {
return _sapp.fullscreen;
}
-SOKOL_API_DECL void sapp_toggle_fullscreen(void) {
+SOKOL_APP_API_DECL void sapp_toggle_fullscreen(void) {
#if defined(_SAPP_MACOS)
_sapp_macos_toggle_fullscreen();
#elif defined(_SAPP_WIN32)
@@ -10568,4 +10576,4 @@ SOKOL_API_IMPL void sapp_html5_ask_leave_site(bool ask) {
_sapp.html5_ask_leave_site = ask;
}
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_APP_IMPL */
diff --git a/sokol_args.h b/sokol_args.h
index 40ee6908..994ba593 100644
--- a/sokol_args.h
+++ b/sokol_args.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_ARGS_IMPL)
+#define SOKOL_ARGS_IMPL
+#endif
#ifndef SOKOL_ARGS_INCLUDED
/*
sokol_args.h -- cross-platform key/value arg-parsing for web and native
@@ -5,7 +8,8 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_ARGS_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -15,7 +19,8 @@
SOKOL_LOG(msg) - your own logging functions (default: puts(msg))
SOKOL_CALLOC(n,s) - your own calloc() implementation (default: calloc(n,s))
SOKOL_FREE(p) - your own free() implementation (default: free(p))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_ARGS_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_ARGS_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_args.h is compiled as a DLL, define the following before
@@ -23,7 +28,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_ARGS_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
OVERVIEW
@@ -247,13 +252,16 @@
#include <stdint.h>
#include <stdbool.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_ARGS_API_DECL)
+#define SOKOL_ARGS_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_ARGS_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_ARGS_IMPL)
+#define SOKOL_ARGS_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_ARGS_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_ARGS_API_DECL extern
#endif
#endif
@@ -269,29 +277,29 @@ typedef struct sargs_desc {
} sargs_desc;
/* setup sokol-args */
-SOKOL_API_DECL void sargs_setup(const sargs_desc* desc);
+SOKOL_ARGS_API_DECL void sargs_setup(const sargs_desc* desc);
/* shutdown sokol-args */
-SOKOL_API_DECL void sargs_shutdown(void);
+SOKOL_ARGS_API_DECL void sargs_shutdown(void);
/* true between sargs_setup() and sargs_shutdown() */
-SOKOL_API_DECL bool sargs_isvalid(void);
+SOKOL_ARGS_API_DECL bool sargs_isvalid(void);
/* test if an argument exists by key name */
-SOKOL_API_DECL bool sargs_exists(const char* key);
+SOKOL_ARGS_API_DECL bool sargs_exists(const char* key);
/* get value by key name, return empty string if key doesn't exist */
-SOKOL_API_DECL const char* sargs_value(const char* key);
+SOKOL_ARGS_API_DECL const char* sargs_value(const char* key);
/* get value by key name, return provided default if key doesn't exist */
-SOKOL_API_DECL const char* sargs_value_def(const char* key, const char* def);
+SOKOL_ARGS_API_DECL const char* sargs_value_def(const char* key, const char* def);
/* return true if val arg matches the value associated with key */
-SOKOL_API_DECL bool sargs_equals(const char* key, const char* val);
+SOKOL_ARGS_API_DECL bool sargs_equals(const char* key, const char* val);
/* return true if key's value is "true", "yes" or "on" */
-SOKOL_API_DECL bool sargs_boolean(const char* key);
+SOKOL_ARGS_API_DECL bool sargs_boolean(const char* key);
/* get index of arg by key name, return -1 if not exists */
-SOKOL_API_DECL int sargs_find(const char* key);
+SOKOL_ARGS_API_DECL int sargs_find(const char* key);
/* get number of parsed arguments */
-SOKOL_API_DECL int sargs_num_args(void);
+SOKOL_ARGS_API_DECL int sargs_num_args(void);
/* get key name of argument at index, or empty string */
-SOKOL_API_DECL const char* sargs_key_at(int index);
+SOKOL_ARGS_API_DECL const char* sargs_key_at(int index);
/* get value string of argument at index, or empty string */
-SOKOL_API_DECL const char* sargs_value_at(int index);
+SOKOL_ARGS_API_DECL const char* sargs_value_at(int index);
#ifdef __cplusplus
} /* extern "C" */
@@ -303,7 +311,7 @@ inline void sargs_setup(const sargs_desc& desc) { return sargs_setup(&desc); }
#endif // SOKOL_ARGS_INCLUDED
/*--- IMPLEMENTATION ---------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_ARGS_IMPL
#define SOKOL_ARGS_IMPL_INCLUDED (1)
#include <string.h> /* memset, strcmp */
@@ -759,4 +767,4 @@ SOKOL_API_IMPL bool sargs_boolean(const char* key) {
(0 == strcmp("on", val));
}
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_ARGS_IMPL */
diff --git a/sokol_audio.h b/sokol_audio.h
index 4227f34d..ed571d32 100644
--- a/sokol_audio.h
+++ b/sokol_audio.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_AUDIO_IMPL)
+#define SOKOL_AUDIO_IMPL
+#endif
#ifndef SOKOL_AUDIO_INCLUDED
/*
sokol_audio.h -- cross-platform audio-streaming API
@@ -5,7 +8,8 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_AUDIO_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -16,7 +20,8 @@
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_MALLOC(s) - your own malloc() implementation (default: malloc(s))
SOKOL_FREE(p) - your own free() implementation (default: free(p))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_AUDIO_API_DECL- public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_AUDIO_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SAUDIO_RING_MAX_SLOTS - max number of slots in the push-audio ring buffer (default 1024)
@@ -26,7 +31,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_AUDIO_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
FEATURE OVERVIEW
@@ -376,13 +381,16 @@
#include <stdint.h>
#include <stdbool.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_AUDIO_API_DECL)
+#define SOKOL_AUDIO_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_AUDIO_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_AUDIO_IMPL)
+#define SOKOL_AUDIO_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_AUDIO_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_AUDIO_API_DECL extern
#endif
#endif
@@ -402,25 +410,25 @@ typedef struct saudio_desc {
} saudio_desc;
/* setup sokol-audio */
-SOKOL_API_DECL void saudio_setup(const saudio_desc* desc);
+SOKOL_AUDIO_API_DECL void saudio_setup(const saudio_desc* desc);
/* shutdown sokol-audio */
-SOKOL_API_DECL void saudio_shutdown(void);
+SOKOL_AUDIO_API_DECL void saudio_shutdown(void);
/* true after setup if audio backend was successfully initialized */
-SOKOL_API_DECL bool saudio_isvalid(void);
+SOKOL_AUDIO_API_DECL bool saudio_isvalid(void);
/* return the saudio_desc.user_data pointer */
-SOKOL_API_DECL void* saudio_userdata(void);
+SOKOL_AUDIO_API_DECL void* saudio_userdata(void);
/* return a copy of the original saudio_desc struct */
-SOKOL_API_DECL saudio_desc saudio_query_desc(void);
+SOKOL_AUDIO_API_DECL saudio_desc saudio_query_desc(void);
/* actual sample rate */
-SOKOL_API_DECL int saudio_sample_rate(void);
+SOKOL_AUDIO_API_DECL int saudio_sample_rate(void);
/* return actual backend buffer size in number of frames */
-SOKOL_API_DECL int saudio_buffer_frames(void);
+SOKOL_AUDIO_API_DECL int saudio_buffer_frames(void);
/* actual number of channels */
-SOKOL_API_DECL int saudio_channels(void);
+SOKOL_AUDIO_API_DECL int saudio_channels(void);
/* get current number of frames to fill packet queue */
-SOKOL_API_DECL int saudio_expect(void);
+SOKOL_AUDIO_API_DECL int saudio_expect(void);
/* push sample frames from main thread, returns number of frames actually pushed */
-SOKOL_API_DECL int saudio_push(const float* frames, int num_frames);
+SOKOL_AUDIO_API_DECL int saudio_push(const float* frames, int num_frames);
#ifdef __cplusplus
} /* extern "C" */
@@ -432,7 +440,7 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
#endif // SOKOL_AUDIO_INCLUDED
/*=== IMPLEMENTATION =========================================================*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_AUDIO_IMPL
#define SOKOL_AUDIO_IMPL_INCLUDED (1)
#include <string.h> /* memset, memcpy */
@@ -1991,4 +1999,4 @@ SOKOL_API_IMPL int saudio_push(const float* frames, int num_frames) {
#pragma warning(pop)
#endif
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_AUDIO_IMPL */
diff --git a/sokol_fetch.h b/sokol_fetch.h
index 6872a4a2..95324729 100644
--- a/sokol_fetch.h
+++ b/sokol_fetch.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_FETCH_IMPL)
+#define SOKOL_FETCH_IMPL
+#endif
#ifndef SOKOL_FETCH_INCLUDED
/*
sokol_fetch.h -- asynchronous data loading/streaming
@@ -5,7 +8,8 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_FETCH_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -16,7 +20,8 @@
SOKOL_FREE(p) - your own free function (default: free(p))
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_FETCH_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_FETCH_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SFETCH_MAX_PATH - max length of UTF-8 filesystem path / URL (default: 1024 bytes)
SFETCH_MAX_USERDATA_UINT64 - max size of embedded userdata in number of uint64_t, userdata
@@ -29,7 +34,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_FETCH_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
NOTE: The following documentation talks a lot about "IO threads". Actual
@@ -829,13 +834,16 @@
#include <stdint.h>
#include <stdbool.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_FETCH_API_DECL)
+#define SOKOL_FETCH_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_FETCH_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_FETCH_IMPL)
+#define SOKOL_FETCH_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_FETCH_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_FETCH_API_DECL extern
#endif
#endif
@@ -904,35 +912,35 @@ typedef struct sfetch_request_t {
} sfetch_request_t;
/* setup sokol-fetch (can be called on multiple threads) */
-SOKOL_API_DECL void sfetch_setup(const sfetch_desc_t* desc);
+SOKOL_FETCH_API_DECL void sfetch_setup(const sfetch_desc_t* desc);
/* discard a sokol-fetch context */
-SOKOL_API_DECL void sfetch_shutdown(void);
+SOKOL_FETCH_API_DECL void sfetch_shutdown(void);
/* return true if sokol-fetch has been setup */
-SOKOL_API_DECL bool sfetch_valid(void);
+SOKOL_FETCH_API_DECL bool sfetch_valid(void);
/* get the desc struct that was passed to sfetch_setup() */
-SOKOL_API_DECL sfetch_desc_t sfetch_desc(void);
+SOKOL_FETCH_API_DECL sfetch_desc_t sfetch_desc(void);
/* return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t)) */
-SOKOL_API_DECL int sfetch_max_userdata_bytes(void);
+SOKOL_FETCH_API_DECL int sfetch_max_userdata_bytes(void);
/* return the value of the SFETCH_MAX_PATH implementation config value */
-SOKOL_API_DECL int sfetch_max_path(void);
+SOKOL_FETCH_API_DECL int sfetch_max_path(void);
/* send a fetch-request, get handle to request back */
-SOKOL_API_DECL sfetch_handle_t sfetch_send(const sfetch_request_t* request);
+SOKOL_FETCH_API_DECL sfetch_handle_t sfetch_send(const sfetch_request_t* request);
/* return true if a handle is valid *and* the request is alive */
-SOKOL_API_DECL bool sfetch_handle_valid(sfetch_handle_t h);
+SOKOL_FETCH_API_DECL bool sfetch_handle_valid(sfetch_handle_t h);
/* do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks */
-SOKOL_API_DECL void sfetch_dowork(void);
+SOKOL_FETCH_API_DECL void sfetch_dowork(void);
/* bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback */
-SOKOL_API_DECL void sfetch_bind_buffer(sfetch_handle_t h, void* buffer_ptr, uint32_t buffer_size);
+SOKOL_FETCH_API_DECL void sfetch_bind_buffer(sfetch_handle_t h, void* buffer_ptr, uint32_t buffer_size);
/* clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback */
-SOKOL_API_DECL void* sfetch_unbind_buffer(sfetch_handle_t h);
+SOKOL_FETCH_API_DECL void* sfetch_unbind_buffer(sfetch_handle_t h);
/* cancel a request that's in flight (will call response callback with .cancelled + .finished) */
-SOKOL_API_DECL void sfetch_cancel(sfetch_handle_t h);
+SOKOL_FETCH_API_DECL void sfetch_cancel(sfetch_handle_t h);
/* pause a request (will call response callback each frame with .paused) */
-SOKOL_API_DECL void sfetch_pause(sfetch_handle_t h);
+SOKOL_FETCH_API_DECL void sfetch_pause(sfetch_handle_t h);
/* continue a paused request */
-SOKOL_API_DECL void sfetch_continue(sfetch_handle_t h);
+SOKOL_FETCH_API_DECL void sfetch_continue(sfetch_handle_t h);
#ifdef __cplusplus
} /* extern "C" */
@@ -945,7 +953,7 @@ inline sfetch_handle_t sfetch_send(const sfetch_request_t& request) { return sfe
#endif // SOKOL_FETCH_INCLUDED
/*--- IMPLEMENTATION ---------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_FETCH_IMPL
#define SOKOL_FETCH_IMPL_INCLUDED (1)
#include <string.h> /* memset, memcpy */
@@ -2505,5 +2513,5 @@ SOKOL_API_IMPL void sfetch_cancel(sfetch_handle_t h) {
}
}
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_FETCH_IMPL */
diff --git a/sokol_gfx.h b/sokol_gfx.h
index 8d423d63..80a514f0 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_GFX_IMPL)
+#define SOKOL_GFX_IMPL
+#endif
#ifndef SOKOL_GFX_INCLUDED
/*
sokol_gfx.h -- simple 3D API wrapper
@@ -5,7 +8,8 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_GFX_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -38,7 +42,8 @@
SOKOL_FREE(p) - your own free function (default: free(p))
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_GFX_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_GFX_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_TRACE_HOOKS - enable trace hook callbacks (search below for TRACE HOOKS)
@@ -47,7 +52,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_GFX_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
If you want to compile without deprecated structs and functions,
@@ -573,13 +578,16 @@
#include <stdint.h>
#include <stdbool.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_GFX_API_DECL)
+#define SOKOL_GFX_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_GFX_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GFX_IMPL)
+#define SOKOL_GFX_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_GFX_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_GFX_API_DECL extern
#endif
#endif
@@ -1953,11 +1961,21 @@ typedef struct sg_trace_hooks {
void (*alloc_shader)(sg_shader result, void* user_data);
void (*alloc_pipeline)(sg_pipeline result, void* user_data);
void (*alloc_pass)(sg_pass result, void* user_data);
+ void (*dealloc_buffer)(sg_buffer buf_id, void* user_data);
+ void (*dealloc_image)(sg_image img_id, void* user_data);
+ void (*dealloc_shader)(sg_shader shd_id, void* user_data);
+ void (*dealloc_pipeline)(sg_pipeline pip_id, void* user_data);
+ void (*dealloc_pass)(sg_pass pass_id, void* user_data);
void (*init_buffer)(sg_buffer buf_id, const sg_buffer_desc* desc, void* user_data);
void (*init_image)(sg_image img_id, const sg_image_desc* desc, void* user_data);
void (*init_shader)(sg_shader shd_id, const sg_shader_desc* desc, void* user_data);
void (*init_pipeline)(sg_pipeline pip_id, const sg_pipeline_desc* desc, void* user_data);
void (*init_pass)(sg_pass pass_id, const sg_pass_desc* desc, void* user_data);
+ void (*uninit_buffer)(sg_buffer buf_id, void* user_data);
+ void (*uninit_image)(sg_image img_id, void* user_data);
+ void (*uninit_shader)(sg_shader shd_id, void* user_data);
+ void (*uninit_pipeline)(sg_pipeline pip_id, void* user_data);
+ void (*uninit_pass)(sg_pass pass_id, void* user_data);
void (*fail_buffer)(sg_buffer buf_id, void* user_data);
void (*fail_image)(sg_image img_id, void* user_data);
void (*fail_shader)(sg_shader shd_id, void* user_data);
@@ -2205,88 +2223,98 @@ typedef struct sg_desc {
} sg_desc;
/* setup and misc functions */
-SOKOL_API_DECL void sg_setup(const sg_desc* desc);
-SOKOL_API_DECL void sg_shutdown(void);
-SOKOL_API_DECL bool sg_isvalid(void);
-SOKOL_API_DECL void sg_reset_state_cache(void);
-SOKOL_API_DECL sg_trace_hooks sg_install_trace_hooks(const sg_trace_hooks* trace_hooks);
-SOKOL_API_DECL void sg_push_debug_group(const char* name);
-SOKOL_API_DECL void sg_pop_debug_group(void);
+SOKOL_GFX_API_DECL void sg_setup(const sg_desc* desc);
+SOKOL_GFX_API_DECL void sg_shutdown(void);
+SOKOL_GFX_API_DECL bool sg_isvalid(void);
+SOKOL_GFX_API_DECL void sg_reset_state_cache(void);
+SOKOL_GFX_API_DECL sg_trace_hooks sg_install_trace_hooks(const sg_trace_hooks* trace_hooks);
+SOKOL_GFX_API_DECL void sg_push_debug_group(const char* name);
+SOKOL_GFX_API_DECL void sg_pop_debug_group(void);
/* resource creation, destruction and updating */
-SOKOL_API_DECL sg_buffer sg_make_buffer(const sg_buffer_desc* desc);
-SOKOL_API_DECL sg_image sg_make_image(const sg_image_desc* desc);
-SOKOL_API_DECL sg_shader sg_make_shader(const sg_shader_desc* desc);
-SOKOL_API_DECL sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc);
-SOKOL_API_DECL sg_pass sg_make_pass(const sg_pass_desc* desc);
-SOKOL_API_DECL void sg_destroy_buffer(sg_buffer buf);
-SOKOL_API_DECL void sg_destroy_image(sg_image img);
-SOKOL_API_DECL void sg_destroy_shader(sg_shader shd);
-SOKOL_API_DECL void sg_destroy_pipeline(sg_pipeline pip);
-SOKOL_API_DECL void sg_destroy_pass(sg_pass pass);
-SOKOL_API_DECL void sg_update_buffer(sg_buffer buf, const void* data_ptr, int data_size);
-SOKOL_API_DECL void sg_update_image(sg_image img, const sg_image_content* data);
-SOKOL_API_DECL int sg_append_buffer(sg_buffer buf, const void* data_ptr, int data_size);
-SOKOL_API_DECL bool sg_query_buffer_overflow(sg_buffer buf);
+SOKOL_GFX_API_DECL sg_buffer sg_make_buffer(const sg_buffer_desc* desc);
+SOKOL_GFX_API_DECL sg_image sg_make_image(const sg_image_desc* desc);
+SOKOL_GFX_API_DECL sg_shader sg_make_shader(const sg_shader_desc* desc);
+SOKOL_GFX_API_DECL sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc);
+SOKOL_GFX_API_DECL sg_pass sg_make_pass(const sg_pass_desc* desc);
+SOKOL_GFX_API_DECL void sg_destroy_buffer(sg_buffer buf);
+SOKOL_GFX_API_DECL void sg_destroy_image(sg_image img);
+SOKOL_GFX_API_DECL void sg_destroy_shader(sg_shader shd);
+SOKOL_GFX_API_DECL void sg_destroy_pipeline(sg_pipeline pip);
+SOKOL_GFX_API_DECL void sg_destroy_pass(sg_pass pass);
+SOKOL_GFX_API_DECL void sg_update_buffer(sg_buffer buf, const void* data_ptr, int data_size);
+SOKOL_GFX_API_DECL void sg_update_image(sg_image img, const sg_image_content* data);
+SOKOL_GFX_API_DECL int sg_append_buffer(sg_buffer buf, const void* data_ptr, int data_size);
+SOKOL_GFX_API_DECL bool sg_query_buffer_overflow(sg_buffer buf);
/* rendering functions */
-SOKOL_API_DECL void sg_begin_default_pass(const sg_pass_action* pass_action, int width, int height);
-SOKOL_API_DECL void sg_begin_pass(sg_pass pass, const sg_pass_action* pass_action);
-SOKOL_API_DECL void sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left);
-SOKOL_API_DECL void sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left);
-SOKOL_API_DECL void sg_apply_pipeline(sg_pipeline pip);
-SOKOL_API_DECL void sg_apply_bindings(const sg_bindings* bindings);
-SOKOL_API_DECL void sg_apply_uniforms(sg_shader_stage stage, int ub_index, const void* data, int num_bytes);
-SOKOL_API_DECL void sg_draw(int base_element, int num_elements, int num_instances);
-SOKOL_API_DECL void sg_end_pass(void);
-SOKOL_API_DECL void sg_commit(void);
+SOKOL_GFX_API_DECL void sg_begin_default_pass(const sg_pass_action* pass_action, int width, int height);
+SOKOL_GFX_API_DECL void sg_begin_pass(sg_pass pass, const sg_pass_action* pass_action);
+SOKOL_GFX_API_DECL void sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left);
+SOKOL_GFX_API_DECL void sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left);
+SOKOL_GFX_API_DECL void sg_apply_pipeline(sg_pipeline pip);
+SOKOL_GFX_API_DECL void sg_apply_bindings(const sg_bindings* bindings);
+SOKOL_GFX_API_DECL void sg_apply_uniforms(sg_shader_stage stage, int ub_index, const void* data, int num_bytes);
+SOKOL_GFX_API_DECL void sg_draw(int base_element, int num_elements, int num_instances);
+SOKOL_GFX_API_DECL void sg_end_pass(void);
+SOKOL_GFX_API_DECL void sg_commit(void);
/* getting information */
-SOKOL_API_DECL sg_desc sg_query_desc(void);
-SOKOL_API_DECL sg_backend sg_query_backend(void);
-SOKOL_API_DECL sg_features sg_query_features(void);
-SOKOL_API_DECL sg_limits sg_query_limits(void);
-SOKOL_API_DECL sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt);
+SOKOL_GFX_API_DECL sg_desc sg_query_desc(void);
+SOKOL_GFX_API_DECL sg_backend sg_query_backend(void);
+SOKOL_GFX_API_DECL sg_features sg_query_features(void);
+SOKOL_GFX_API_DECL sg_limits sg_query_limits(void);
+SOKOL_GFX_API_DECL sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt);
/* get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID) */
-SOKOL_API_DECL sg_resource_state sg_query_buffer_state(sg_buffer buf);
-SOKOL_API_DECL sg_resource_state sg_query_image_state(sg_image img);
-SOKOL_API_DECL sg_resource_state sg_query_shader_state(sg_shader shd);
-SOKOL_API_DECL sg_resource_state sg_query_pipeline_state(sg_pipeline pip);
-SOKOL_API_DECL sg_resource_state sg_query_pass_state(sg_pass pass);
+SOKOL_GFX_API_DECL sg_resource_state sg_query_buffer_state(sg_buffer buf);
+SOKOL_GFX_API_DECL sg_resource_state sg_query_image_state(sg_image img);
+SOKOL_GFX_API_DECL sg_resource_state sg_query_shader_state(sg_shader shd);
+SOKOL_GFX_API_DECL sg_resource_state sg_query_pipeline_state(sg_pipeline pip);
+SOKOL_GFX_API_DECL sg_resource_state sg_query_pass_state(sg_pass pass);
/* get runtime information about a resource */
-SOKOL_API_DECL sg_buffer_info sg_query_buffer_info(sg_buffer buf);
-SOKOL_API_DECL sg_image_info sg_query_image_info(sg_image img);
-SOKOL_API_DECL sg_shader_info sg_query_shader_info(sg_shader shd);
-SOKOL_API_DECL sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip);
-SOKOL_API_DECL sg_pass_info sg_query_pass_info(sg_pass pass);
+SOKOL_GFX_API_DECL sg_buffer_info sg_query_buffer_info(sg_buffer buf);
+SOKOL_GFX_API_DECL sg_image_info sg_query_image_info(sg_image img);
+SOKOL_GFX_API_DECL sg_shader_info sg_query_shader_info(sg_shader shd);
+SOKOL_GFX_API_DECL sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip);
+SOKOL_GFX_API_DECL sg_pass_info sg_query_pass_info(sg_pass pass);
/* get resource creation desc struct with their default values replaced */
-SOKOL_API_DECL sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc);
-SOKOL_API_DECL sg_image_desc sg_query_image_defaults(const sg_image_desc* desc);
-SOKOL_API_DECL sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc);
-SOKOL_API_DECL sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc);
-SOKOL_API_DECL sg_pass_desc sg_query_pass_defaults(const sg_pass_desc* desc);
+SOKOL_GFX_API_DECL sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc);
+SOKOL_GFX_API_DECL sg_image_desc sg_query_image_defaults(const sg_image_desc* desc);
+SOKOL_GFX_API_DECL sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc);
+SOKOL_GFX_API_DECL sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc);
+SOKOL_GFX_API_DECL sg_pass_desc sg_query_pass_defaults(const sg_pass_desc* desc);
/* separate resource allocation and initialization (for async setup) */
-SOKOL_API_DECL sg_buffer sg_alloc_buffer(void);
-SOKOL_API_DECL sg_image sg_alloc_image(void);
-SOKOL_API_DECL sg_shader sg_alloc_shader(void);
-SOKOL_API_DECL sg_pipeline sg_alloc_pipeline(void);
-SOKOL_API_DECL sg_pass sg_alloc_pass(void);
-SOKOL_API_DECL void sg_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc);
-SOKOL_API_DECL void sg_init_image(sg_image img_id, const sg_image_desc* desc);
-SOKOL_API_DECL void sg_init_shader(sg_shader shd_id, const sg_shader_desc* desc);
-SOKOL_API_DECL void sg_init_pipeline(sg_pipeline pip_id, const sg_pipeline_desc* desc);
-SOKOL_API_DECL void sg_init_pass(sg_pass pass_id, const sg_pass_desc* desc);
-SOKOL_API_DECL void sg_fail_buffer(sg_buffer buf_id);
-SOKOL_API_DECL void sg_fail_image(sg_image img_id);
-SOKOL_API_DECL void sg_fail_shader(sg_shader shd_id);
-SOKOL_API_DECL void sg_fail_pipeline(sg_pipeline pip_id);
-SOKOL_API_DECL void sg_fail_pass(sg_pass pass_id);
+SOKOL_GFX_API_DECL sg_buffer sg_alloc_buffer(void);
+SOKOL_GFX_API_DECL sg_image sg_alloc_image(void);
+SOKOL_GFX_API_DECL sg_shader sg_alloc_shader(void);
+SOKOL_GFX_API_DECL sg_pipeline sg_alloc_pipeline(void);
+SOKOL_GFX_API_DECL sg_pass sg_alloc_pass(void);
+SOKOL_GFX_API_DECL void sg_dealloc_buffer(sg_buffer buf_id);
+SOKOL_GFX_API_DECL void sg_dealloc_image(sg_image img_id);
+SOKOL_GFX_API_DECL void sg_dealloc_shader(sg_shader shd_id);
+SOKOL_GFX_API_DECL void sg_dealloc_pipeline(sg_pipeline pip_id);
+SOKOL_GFX_API_DECL void sg_dealloc_pass(sg_pass pass_id);
+SOKOL_GFX_API_DECL void sg_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc);
+SOKOL_GFX_API_DECL void sg_init_image(sg_image img_id, const sg_image_desc* desc);
+SOKOL_GFX_API_DECL void sg_init_shader(sg_shader shd_id, const sg_shader_desc* desc);
+SOKOL_GFX_API_DECL void sg_init_pipeline(sg_pipeline pip_id, const sg_pipeline_desc* desc);
+SOKOL_GFX_API_DECL void sg_init_pass(sg_pass pass_id, const sg_pass_desc* desc);
+SOKOL_GFX_API_DECL bool sg_uninit_buffer(sg_buffer buf_id);
+SOKOL_GFX_API_DECL bool sg_uninit_image(sg_image img_id);
+SOKOL_GFX_API_DECL bool sg_uninit_shader(sg_shader shd_id);
+SOKOL_GFX_API_DECL bool sg_uninit_pipeline(sg_pipeline pip_id);
+SOKOL_GFX_API_DECL bool sg_uninit_pass(sg_pass pass_id);
+SOKOL_GFX_API_DECL void sg_fail_buffer(sg_buffer buf_id);
+SOKOL_GFX_API_DECL void sg_fail_image(sg_image img_id);
+SOKOL_GFX_API_DECL void sg_fail_shader(sg_shader shd_id);
+SOKOL_GFX_API_DECL void sg_fail_pipeline(sg_pipeline pip_id);
+SOKOL_GFX_API_DECL void sg_fail_pass(sg_pass pass_id);
/* rendering contexts (optional) */
-SOKOL_API_DECL sg_context sg_setup_context(void);
-SOKOL_API_DECL void sg_activate_context(sg_context ctx_id);
-SOKOL_API_DECL void sg_discard_context(sg_context ctx_id);
+SOKOL_GFX_API_DECL sg_context sg_setup_context(void);
+SOKOL_GFX_API_DECL void sg_activate_context(sg_context ctx_id);
+SOKOL_GFX_API_DECL void sg_discard_context(sg_context ctx_id);
/* Backend-specific helper functions, these may come in handy for mixing
sokol-gfx rendering with 'native backend' rendering functions.
@@ -2295,13 +2323,13 @@ SOKOL_API_DECL void sg_discard_context(sg_context ctx_id);
*/
/* D3D11: return ID3D11Device */
-SOKOL_API_DECL const void* sg_d3d11_device(void);
+SOKOL_GFX_API_DECL const void* sg_d3d11_device(void);
/* Metal: return __bridge-casted MTLDevice */
-SOKOL_API_DECL const void* sg_mtl_device(void);
+SOKOL_GFX_API_DECL const void* sg_mtl_device(void);
/* Metal: return __bridge-casted MTLRenderCommandEncoder in current pass (or zero if outside pass) */
-SOKOL_API_DECL const void* sg_mtl_render_command_encoder(void);
+SOKOL_GFX_API_DECL const void* sg_mtl_render_command_encoder(void);
#ifdef _MSC_VER
#pragma warning(pop)
@@ -2339,7 +2367,7 @@ inline void sg_init_pass(sg_pass pass_id, const sg_pass_desc& desc) { return sg_
#endif // SOKOL_GFX_INCLUDED
/*--- IMPLEMENTATION ---------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_GFX_IMPL
#define SOKOL_GFX_IMPL_INCLUDED (1)
#if !(defined(SOKOL_GLCORE33)||defined(SOKOL_GLES2)||defined(SOKOL_GLES3)||defined(SOKOL_D3D11)||defined(SOKOL_METAL)||defined(SOKOL_WGPU)||defined(SOKOL_DUMMY_BACKEND))
@@ -12676,34 +12704,57 @@ _SOKOL_PRIVATE void _sg_pool_free_index(_sg_pool_t* pool, int slot_index) {
SOKOL_ASSERT(pool->queue_top <= (pool->size-1));
}
+_SOKOL_PRIVATE void _sg_reset_slot(_sg_slot_t* slot) {
+ SOKOL_ASSERT(slot);
+ memset(slot, 0, sizeof(_sg_slot_t));
+}
+
_SOKOL_PRIVATE void _sg_reset_buffer(_sg_buffer_t* buf) {
SOKOL_ASSERT(buf);
+ _sg_slot_t slot = buf->slot;
memset(buf, 0, sizeof(_sg_buffer_t));
+ buf->slot = slot;
+ buf->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_reset_image(_sg_image_t* img) {
SOKOL_ASSERT(img);
+ _sg_slot_t slot = img->slot;
memset(img, 0, sizeof(_sg_image_t));
+ img->slot = slot;
+ img->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_reset_shader(_sg_shader_t* shd) {
SOKOL_ASSERT(shd);
+ _sg_slot_t slot = shd->slot;
memset(shd, 0, sizeof(_sg_shader_t));
+ shd->slot = slot;
+ shd->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_reset_pipeline(_sg_pipeline_t* pip) {
SOKOL_ASSERT(pip);
+ _sg_slot_t slot = pip->slot;
memset(pip, 0, sizeof(_sg_pipeline_t));
+ pip->slot = slot;
+ pip->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_reset_pass(_sg_pass_t* pass) {
SOKOL_ASSERT(pass);
+ _sg_slot_t slot = pass->slot;
memset(pass, 0, sizeof(_sg_pass_t));
+ pass->slot = slot;
+ pass->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_reset_context(_sg_context_t* ctx) {
SOKOL_ASSERT(ctx);
+ _sg_slot_t slot = ctx->slot;
memset(ctx, 0, sizeof(_sg_context_t));
+ ctx->slot = slot;
+ ctx->slot.state = SG_RESOURCESTATE_ALLOC;
}
_SOKOL_PRIVATE void _sg_setup_pools(_sg_pools_t* p, const sg_desc* desc) {
@@ -13882,6 +13933,46 @@ _SOKOL_PRIVATE sg_pass _sg_alloc_pass(void) {
return res;
}
+_SOKOL_PRIVATE void _sg_dealloc_buffer(sg_buffer buf_id) {
+ SOKOL_ASSERT(buf_id.id != SG_INVALID_ID);
+ _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
+ SOKOL_ASSERT(buf && buf->slot.state == SG_RESOURCESTATE_ALLOC);
+ _sg_reset_slot(&buf->slot);
+ _sg_pool_free_index(&_sg.pools.buffer_pool, _sg_slot_index(buf_id.id));
+}
+
+_SOKOL_PRIVATE void _sg_dealloc_image(sg_image img_id) {
+ SOKOL_ASSERT(img_id.id != SG_INVALID_ID);
+ _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
+ SOKOL_ASSERT(img && img->slot.state == SG_RESOURCESTATE_ALLOC);
+ _sg_reset_slot(&img->slot);
+ _sg_pool_free_index(&_sg.pools.image_pool, _sg_slot_index(img_id.id));
+}
+
+_SOKOL_PRIVATE void _sg_dealloc_shader(sg_shader shd_id) {
+ SOKOL_ASSERT(shd_id.id != SG_INVALID_ID);
+ _sg_shader_t* shd = _sg_lookup_shader(&_sg.pools, shd_id.id);
+ SOKOL_ASSERT(shd && shd->slot.state == SG_RESOURCESTATE_ALLOC);
+ _sg_reset_slot(&shd->slot);
+ _sg_pool_free_index(&_sg.pools.shader_pool, _sg_slot_index(shd_id.id));
+}
+
+_SOKOL_PRIVATE void _sg_dealloc_pipeline(sg_pipeline pip_id) {
+ SOKOL_ASSERT(pip_id.id != SG_INVALID_ID);
+ _sg_pipeline_t* pip = _sg_lookup_pipeline(&_sg.pools, pip_id.id);
+ SOKOL_ASSERT(pip && pip->slot.state == SG_RESOURCESTATE_ALLOC);
+ _sg_reset_slot(&pip->slot);
+ _sg_pool_free_index(&_sg.pools.pipeline_pool, _sg_slot_index(pip_id.id));
+}
+
+_SOKOL_PRIVATE void _sg_dealloc_pass(sg_pass pass_id) {
+ SOKOL_ASSERT(pass_id.id != SG_INVALID_ID);
+ _sg_pass_t* pass = _sg_lookup_pass(&_sg.pools, pass_id.id);
+ SOKOL_ASSERT(pass && pass->slot.state == SG_RESOURCESTATE_ALLOC);
+ _sg_reset_slot(&pass->slot);
+ _sg_pool_free_index(&_sg.pools.pass_pool, _sg_slot_index(pass_id.id));
+}
+
_SOKOL_PRIVATE void _sg_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc) {
SOKOL_ASSERT(buf_id.id != SG_INVALID_ID && desc);
_sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
@@ -13979,6 +14070,86 @@ _SOKOL_PRIVATE void _sg_init_pass(sg_pass pass_id, const sg_pass_desc* desc) {
SOKOL_ASSERT((pass->slot.state == SG_RESOURCESTATE_VALID)||(pass->slot.state == SG_RESOURCESTATE_FAILED));
}
+_SOKOL_PRIVATE bool _sg_uninit_buffer(sg_buffer buf_id) {
+ _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
+ if (buf) {
+ if (buf->slot.ctx_id == _sg.active_context.id) {
+ _sg_destroy_buffer(buf);
+ _sg_reset_buffer(buf);
+ return true;
+ }
+ else {
+ SOKOL_LOG("_sg_uninit_buffer: active context mismatch (must be same as for creation)");
+ _SG_TRACE_NOARGS(err_context_mismatch);
+ }
+ }
+ return false;
+}
+
+_SOKOL_PRIVATE bool _sg_uninit_image(sg_image img_id) {
+ _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
+ if (img) {
+ if (img->slot.ctx_id == _sg.active_context.id) {
+ _sg_destroy_image(img);
+ _sg_reset_image(img);
+ return true;
+ }
+ else {
+ SOKOL_LOG("_sg_uninit_image: active context mismatch (must be same as for creation)");
+ _SG_TRACE_NOARGS(err_context_mismatch);
+ }
+ }
+ return false;
+}
+
+_SOKOL_PRIVATE bool _sg_uninit_shader(sg_shader shd_id) {
+ _sg_shader_t* shd = _sg_lookup_shader(&_sg.pools, shd_id.id);
+ if (shd) {
+ if (shd->slot.ctx_id == _sg.active_context.id) {
+ _sg_destroy_shader(shd);
+ _sg_reset_shader(shd);
+ return true;
+ }
+ else {
+ SOKOL_LOG("_sg_uninit_shader: active context mismatch (must be same as for creation)");
+ _SG_TRACE_NOARGS(err_context_mismatch);
+ }
+ }
+ return false;
+}
+
+_SOKOL_PRIVATE bool _sg_uninit_pipeline(sg_pipeline pip_id) {
+ _sg_pipeline_t* pip = _sg_lookup_pipeline(&_sg.pools, pip_id.id);
+ if (pip) {
+ if (pip->slot.ctx_id == _sg.active_context.id) {
+ _sg_destroy_pipeline(pip);
+ _sg_reset_pipeline(pip);
+ return true;
+ }
+ else {
+ SOKOL_LOG("_sg_uninit_pipeline: active context mismatch (must be same as for creation)");
+ _SG_TRACE_NOARGS(err_context_mismatch);
+ }
+ }
+ return false;
+}
+
+_SOKOL_PRIVATE bool _sg_uninit_pass(sg_pass pass_id) {
+ _sg_pass_t* pass = _sg_lookup_pass(&_sg.pools, pass_id.id);
+ if (pass) {
+ if (pass->slot.ctx_id == _sg.active_context.id) {
+ _sg_destroy_pass(pass);
+ _sg_reset_pass(pass);
+ return true;
+ }
+ else {
+ SOKOL_LOG("_sg_uninit_pass: active context mismatch (must be same as for creation)");
+ _SG_TRACE_NOARGS(err_context_mismatch);
+ }
+ }
+ return false;
+}
+
/*== PUBLIC API FUNCTIONS ====================================================*/
#if defined(SOKOL_METAL)
@@ -14102,6 +14273,7 @@ SOKOL_API_IMPL void sg_discard_context(sg_context ctx_id) {
if (ctx) {
_sg_destroy_context(ctx);
_sg_reset_context(ctx);
+ _sg_reset_slot(&ctx->slot);
_sg_pool_free_index(&_sg.pools.context_pool, _sg_slot_index(ctx_id.id));
}
_sg.active_context.id = SG_INVALID_ID;
@@ -14165,6 +14337,36 @@ SOKOL_API_IMPL sg_pass sg_alloc_pass(void) {
return res;
}
+SOKOL_API_IMPL void sg_dealloc_buffer(sg_buffer buf_id) {
+ SOKOL_ASSERT(_sg.valid);
+ _sg_dealloc_buffer(buf_id);
+ _SG_TRACE_ARGS(dealloc_buffer, buf_id);
+}
+
+SOKOL_API_IMPL void sg_dealloc_image(sg_image img_id) {
+ SOKOL_ASSERT(_sg.valid);
+ _sg_dealloc_image(img_id);
+ _SG_TRACE_ARGS(dealloc_image, img_id);
+}
+
+SOKOL_API_IMPL void sg_dealloc_shader(sg_shader shd_id) {
+ SOKOL_ASSERT(_sg.valid);
+ _sg_dealloc_shader(shd_id);
+ _SG_TRACE_ARGS(dealloc_shader, shd_id);
+}
+
+SOKOL_API_IMPL void sg_dealloc_pipeline(sg_pipeline pip_id) {
+ SOKOL_ASSERT(_sg.valid);
+ _sg_dealloc_pipeline(pip_id);
+ _SG_TRACE_ARGS(dealloc_pipeline, pip_id);
+}
+
+SOKOL_API_IMPL void sg_dealloc_pass(sg_pass pass_id) {
+ SOKOL_ASSERT(_sg.valid);
+ _sg_dealloc_pass(pass_id);
+ _SG_TRACE_ARGS(dealloc_pass, pass_id);
+}
+
SOKOL_API_IMPL void sg_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc) {
SOKOL_ASSERT(_sg.valid);
sg_buffer_desc desc_def = _sg_buffer_desc_defaults(desc);
@@ -14200,6 +14402,41 @@ SOKOL_API_IMPL void sg_init_pass(sg_pass pass_id, const sg_pass_desc* desc) {
_SG_TRACE_ARGS(init_pass, pass_id, &desc_def);
}
+SOKOL_API_IMPL bool sg_uninit_buffer(sg_buffer buf_id) {
+ SOKOL_ASSERT(_sg.valid);
+ bool res = _sg_uninit_buffer(buf_id);
+ _SG_TRACE_ARGS(uninit_buffer, buf_id);
+ return res;
+}
+
+SOKOL_API_IMPL bool sg_uninit_image(sg_image img_id) {
+ SOKOL_ASSERT(_sg.valid);
+ bool res = _sg_uninit_image(img_id);
+ _SG_TRACE_ARGS(uninit_image, img_id);
+ return res;
+}
+
+SOKOL_API_IMPL bool sg_uninit_shader(sg_shader shd_id) {
+ SOKOL_ASSERT(_sg.valid);
+ bool res = _sg_uninit_shader(shd_id);
+ _SG_TRACE_ARGS(uninit_shader, shd_id);
+ return res;
+}
+
+SOKOL_API_IMPL bool sg_uninit_pipeline(sg_pipeline pip_id) {
+ SOKOL_ASSERT(_sg.valid);
+ bool res = _sg_uninit_pipeline(pip_id);
+ _SG_TRACE_ARGS(uninit_pipeline, pip_id);
+ return res;
+}
+
+SOKOL_API_IMPL bool sg_uninit_pass(sg_pass pass_id) {
+ SOKOL_ASSERT(_sg.valid);
+ bool res = _sg_uninit_pass(pass_id);
+ _SG_TRACE_ARGS(uninit_pass, pass_id);
+ return res;
+}
+
/*-- set allocated resource to failed state ----------------------------------*/
SOKOL_API_IMPL void sg_fail_buffer(sg_buffer buf_id) {
SOKOL_ASSERT(_sg.valid);
@@ -14372,85 +14609,40 @@ SOKOL_API_IMPL sg_pass sg_make_pass(const sg_pass_desc* desc) {
SOKOL_API_IMPL void sg_destroy_buffer(sg_buffer buf_id) {
SOKOL_ASSERT(_sg.valid);
_SG_TRACE_ARGS(destroy_buffer, buf_id);
- _sg_buffer_t* buf = _sg_lookup_buffer(&_sg.pools, buf_id.id);
- if (buf) {
- if (buf->slot.ctx_id == _sg.active_context.id) {
- _sg_destroy_buffer(buf);
- _sg_reset_buffer(buf);
- _sg_pool_free_index(&_sg.pools.buffer_pool, _sg_slot_index(buf_id.id));
- }
- else {
- SOKOL_LOG("sg_destroy_buffer: active context mismatch (must be same as for creation)");
- _SG_TRACE_NOARGS(err_context_mismatch);
- }
+ if (_sg_uninit_buffer(buf_id)) {
+ _sg_dealloc_buffer(buf_id);
}
}
SOKOL_API_IMPL void sg_destroy_image(sg_image img_id) {
SOKOL_ASSERT(_sg.valid);
_SG_TRACE_ARGS(destroy_image, img_id);
- _sg_image_t* img = _sg_lookup_image(&_sg.pools, img_id.id);
- if (img) {
- if (img->slot.ctx_id == _sg.active_context.id) {
- _sg_destroy_image(img);
- _sg_reset_image(img);
- _sg_pool_free_index(&_sg.pools.image_pool, _sg_slot_index(img_id.id));
- }
- else {
- SOKOL_LOG("sg_destroy_image: active context mismatch (must be same as for creation)");
- _SG_TRACE_NOARGS(err_context_mismatch);
- }
+ if (_sg_uninit_image(img_id)) {
+ _sg_dealloc_image(img_id);
}
}
SOKOL_API_IMPL void sg_destroy_shader(sg_shader shd_id) {
SOKOL_ASSERT(_sg.valid);
_SG_TRACE_ARGS(destroy_shader, shd_id);
- _sg_shader_t* shd = _sg_lookup_shader(&_sg.pools, shd_id.id);
- if (shd) {
- if (shd->slot.ctx_id == _sg.active_context.id) {
- _sg_destroy_shader(shd);
- _sg_reset_shader(shd);
- _sg_pool_free_index(&_sg.pools.shader_pool, _sg_slot_index(shd_id.id));
- }
- else {
- SOKOL_LOG("sg_destroy_shader: active context mismatch (must be same as for creation)");
- _SG_TRACE_NOARGS(err_context_mismatch);
- }
+ if (_sg_uninit_shader(shd_id)) {
+ _sg_dealloc_shader(shd_id);
}
}
SOKOL_API_IMPL void sg_destroy_pipeline(sg_pipeline pip_id) {
SOKOL_ASSERT(_sg.valid);
_SG_TRACE_ARGS(destroy_pipeline, pip_id);
- _sg_pipeline_t* pip = _sg_lookup_pipeline(&_sg.pools, pip_id.id);
- if (pip) {
- if (pip->slot.ctx_id == _sg.active_context.id) {
- _sg_destroy_pipeline(pip);
- _sg_reset_pipeline(pip);
- _sg_pool_free_index(&_sg.pools.pipeline_pool, _sg_slot_index(pip_id.id));
- }
- else {
- SOKOL_LOG("sg_destroy_pipeline: active context mismatch (must be same as for creation)");
- _SG_TRACE_NOARGS(err_context_mismatch);
- }
+ if (_sg_uninit_pipeline(pip_id)) {
+ _sg_dealloc_pipeline(pip_id);
}
}
SOKOL_API_IMPL void sg_destroy_pass(sg_pass pass_id) {
SOKOL_ASSERT(_sg.valid);
_SG_TRACE_ARGS(destroy_pass, pass_id);
- _sg_pass_t* pass = _sg_lookup_pass(&_sg.pools, pass_id.id);
- if (pass) {
- if (pass->slot.ctx_id == _sg.active_context.id) {
- _sg_destroy_pass(pass);
- _sg_reset_pass(pass);
- _sg_pool_free_index(&_sg.pools.pass_pool, _sg_slot_index(pass_id.id));
- }
- else {
- SOKOL_LOG("sg_destroy_pass: active context mismatch (must be same as for creation)");
- _SG_TRACE_NOARGS(err_context_mismatch);
- }
+ if (_sg_uninit_pass(pass_id)) {
+ _sg_dealloc_pass(pass_id);
}
}
@@ -14912,4 +15104,4 @@ SOKOL_API_IMPL const void* sg_mtl_render_command_encoder(void) {
#pragma warning(pop)
#endif
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_GFX_IMPL */
diff --git a/sokol_glue.h b/sokol_glue.h
index c47892b7..74ecb7c3 100644
--- a/sokol_glue.h
+++ b/sokol_glue.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_GLUE_IMPL)
+#define SOKOL_GLUE_IMPL
+#endif
#ifndef SOKOL_GLUE_INCLUDED
/*
sokol_glue.h -- glue helper functions for sokol headers
@@ -5,14 +8,16 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_GLUE_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
...optionally provide the following macros to override defaults:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_GLUE_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_GLUE_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_glue.h is compiled as a DLL, define the following before
@@ -20,7 +25,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_GLUE_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
OVERVIEW
@@ -71,13 +76,16 @@
*/
#define SOKOL_GLUE_INCLUDED
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_GLUE_API_DECL)
+#define SOKOL_GLUE_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_GLUE_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GLUE_IMPL)
+#define SOKOL_GLUE_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_GLUE_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_GLUE_API_DECL extern
#endif
#endif
@@ -86,7 +94,7 @@ extern "C" {
#endif
#if defined(SOKOL_GFX_INCLUDED) && defined(SOKOL_APP_INCLUDED)
-SOKOL_API_DECL sg_context_desc sapp_sgcontext(void);
+SOKOL_GLUE_API_DECL sg_context_desc sapp_sgcontext(void);
#endif
#ifdef __cplusplus
@@ -95,7 +103,7 @@ SOKOL_API_DECL sg_context_desc sapp_sgcontext(void);
#endif /* SOKOL_GLUE_INCLUDED */
/*-- IMPLEMENTATION ----------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_GLUE_IMPL
#define SOKOL_GLUE_IMPL_INCLUDED (1)
#include <string.h> /* memset */
@@ -126,4 +134,4 @@ SOKOL_API_IMPL sg_context_desc sapp_sgcontext(void) {
}
#endif
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_GLUE_IMPL */
diff --git a/sokol_time.h b/sokol_time.h
index 18bc8a96..29ecdacf 100644
--- a/sokol_time.h
+++ b/sokol_time.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_TIME_IMPL)
+#define SOKOL_TIME_IMPL
+#endif
#ifndef SOKOL_TIME_INCLUDED
/*
sokol_time.h -- simple cross-platform time measurement
@@ -5,13 +8,15 @@
Project URL: https://github.com/floooh/sokol
Do this:
- #define SOKOL_IMPL
+ #define SOKOL_IMPL or
+ #define SOKOL_TIME_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
Optionally provide the following defines with your own implementations:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_TIME_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_TIME_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_time.h is compiled as a DLL, define the following before
@@ -19,7 +24,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_TIME_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
void stm_setup();
@@ -101,13 +106,16 @@
#define SOKOL_TIME_INCLUDED (1)
#include <stdint.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_TIME_API_DECL)
+#define SOKOL_TIME_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_TIME_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_TIME_IMPL)
+#define SOKOL_TIME_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_TIME_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_TIME_API_DECL extern
#endif
#endif
@@ -115,16 +123,16 @@
extern "C" {
#endif
-SOKOL_API_DECL void stm_setup(void);
-SOKOL_API_DECL uint64_t stm_now(void);
-SOKOL_API_DECL uint64_t stm_diff(uint64_t new_ticks, uint64_t old_ticks);
-SOKOL_API_DECL uint64_t stm_since(uint64_t start_ticks);
-SOKOL_API_DECL uint64_t stm_laptime(uint64_t* last_time);
-SOKOL_API_DECL uint64_t stm_round_to_common_refresh_rate(uint64_t frame_ticks);
-SOKOL_API_DECL double stm_sec(uint64_t ticks);
-SOKOL_API_DECL double stm_ms(uint64_t ticks);
-SOKOL_API_DECL double stm_us(uint64_t ticks);
-SOKOL_API_DECL double stm_ns(uint64_t ticks);
+SOKOL_TIME_API_DECL void stm_setup(void);
+SOKOL_TIME_API_DECL uint64_t stm_now(void);
+SOKOL_TIME_API_DECL uint64_t stm_diff(uint64_t new_ticks, uint64_t old_ticks);
+SOKOL_TIME_API_DECL uint64_t stm_since(uint64_t start_ticks);
+SOKOL_TIME_API_DECL uint64_t stm_laptime(uint64_t* last_time);
+SOKOL_TIME_API_DECL uint64_t stm_round_to_common_refresh_rate(uint64_t frame_ticks);
+SOKOL_TIME_API_DECL double stm_sec(uint64_t ticks);
+SOKOL_TIME_API_DECL double stm_ms(uint64_t ticks);
+SOKOL_TIME_API_DECL double stm_us(uint64_t ticks);
+SOKOL_TIME_API_DECL double stm_ns(uint64_t ticks);
#ifdef __cplusplus
} /* extern "C" */
@@ -132,7 +140,7 @@ SOKOL_API_DECL double stm_ns(uint64_t ticks);
#endif // SOKOL_TIME_INCLUDED
/*-- IMPLEMENTATION ----------------------------------------------------------*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_TIME_IMPL
#define SOKOL_TIME_IMPL_INCLUDED (1)
#include <string.h> /* memset */
@@ -311,5 +319,5 @@ SOKOL_API_IMPL double stm_us(uint64_t ticks) {
SOKOL_API_IMPL double stm_ns(uint64_t ticks) {
return (double)ticks;
}
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_TIME_IMPL */
diff --git a/util/sokol_debugtext.h b/util/sokol_debugtext.h
index 90c15cb5..b07bfe39 100644
--- a/util/sokol_debugtext.h
+++ b/util/sokol_debugtext.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_DEBUGTEXT_IMPL)
+#define SOKOL_DEBUGTEXT_IMPL
+#endif
#ifndef SOKOL_DEBUGTEXT_INCLUDED
/*
sokol_debugtext.h - simple ASCII debug text rendering on top of sokol_gfx.h
@@ -5,6 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
+ #define SOKOL_IMPL or
#define SOKOL_DEBUGTEXT_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -26,7 +30,8 @@
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
SOKOL_FREE(p) - your own free function (default: free(p))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_DEBUGTEXT_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_DEBUGTEXT_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
@@ -36,7 +41,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_DEBUGTEXT_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
Include the following headers before including sokol_debugtext.h:
@@ -392,13 +397,16 @@
#error "Please include sokol_gfx.h before sokol_debugtext.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_DEBUGTEXT_API_DECL)
+#define SOKOL_DEBUGTEXT_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_DEBUGTEXT_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_DEBUGTEXT_IMPL)
+#define SOKOL_DEBUGTEXT_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_DEBUGTEXT_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_DEBUGTEXT_API_DECL extern
#endif
#endif
@@ -490,58 +498,58 @@ typedef struct sdtx_desc_t {
} sdtx_desc_t;
/* initialization/shutdown */
-SOKOL_API_DECL void sdtx_setup(const sdtx_desc_t* desc);
-SOKOL_API_DECL void sdtx_shutdown(void);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_setup(const sdtx_desc_t* desc);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_shutdown(void);
/* builtin font data (use to populate sdtx_desc.font[]) */
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_kc853(void);
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_kc854(void);
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_z1013(void);
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_cpc(void);
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_c64(void);
-SOKOL_API_DECL sdtx_font_desc_t sdtx_font_oric(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_kc853(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_kc854(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_z1013(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_cpc(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_c64(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_font_desc_t sdtx_font_oric(void);
/* context functions */
-SOKOL_API_DECL sdtx_context sdtx_make_context(const sdtx_context_desc_t* desc);
-SOKOL_API_DECL void sdtx_destroy_context(sdtx_context ctx);
-SOKOL_API_DECL void sdtx_set_context(sdtx_context ctx);
-SOKOL_API_DECL sdtx_context sdtx_get_context(void);
+SOKOL_DEBUGTEXT_API_DECL sdtx_context sdtx_make_context(const sdtx_context_desc_t* desc);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_destroy_context(sdtx_context ctx);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_set_context(sdtx_context ctx);
+SOKOL_DEBUGTEXT_API_DECL sdtx_context sdtx_get_context(void);
/* draw and rewind the current context */
-SOKOL_API_DECL void sdtx_draw(void);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_draw(void);
/* switch to a different font */
-SOKOL_API_DECL void sdtx_font(int font_index);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_font(int font_index);
/* set a new virtual canvas size in screen pixels */
-SOKOL_API_DECL void sdtx_canvas(float w, float h);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_canvas(float w, float h);
/* set a new origin in character grid coordinates */
-SOKOL_API_DECL void sdtx_origin(float x, float y);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_origin(float x, float y);
/* cursor movement functions (relative to origin in character grid coordinates) */
-SOKOL_API_DECL void sdtx_home(void);
-SOKOL_API_DECL void sdtx_pos(float x, float y);
-SOKOL_API_DECL void sdtx_pos_x(float x);
-SOKOL_API_DECL void sdtx_pos_y(float y);
-SOKOL_API_DECL void sdtx_move(float dx, float dy);
-SOKOL_API_DECL void sdtx_move_x(float dx);
-SOKOL_API_DECL void sdtx_move_y(float dy);
-SOKOL_API_DECL void sdtx_crlf(void);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_home(void);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_pos(float x, float y);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_pos_x(float x);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_pos_y(float y);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_move(float dx, float dy);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_move_x(float dx);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_move_y(float dy);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_crlf(void);
/* set the current text color */
-SOKOL_API_DECL void sdtx_color3b(uint8_t r, uint8_t g, uint8_t b); // RGB 0..255, A=255
-SOKOL_API_DECL void sdtx_color3f(float r, float g, float b); // RGB 0.0f..1.0f, A=1.0f
-SOKOL_API_DECL void sdtx_color4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a); // RGBA 0..255
-SOKOL_API_DECL void sdtx_color4f(float r, float g, float b, float a); // RGBA 0.0f..1.0f
-SOKOL_API_DECL void sdtx_color1i(uint32_t rgba); // ABGR 0xAABBGGRR
+SOKOL_DEBUGTEXT_API_DECL void sdtx_color3b(uint8_t r, uint8_t g, uint8_t b); // RGB 0..255, A=255
+SOKOL_DEBUGTEXT_API_DECL void sdtx_color3f(float r, float g, float b); // RGB 0.0f..1.0f, A=1.0f
+SOKOL_DEBUGTEXT_API_DECL void sdtx_color4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a); // RGBA 0..255
+SOKOL_DEBUGTEXT_API_DECL void sdtx_color4f(float r, float g, float b, float a); // RGBA 0.0f..1.0f
+SOKOL_DEBUGTEXT_API_DECL void sdtx_color1i(uint32_t rgba); // ABGR 0xAABBGGRR
/* text rendering */
-SOKOL_API_DECL void sdtx_putc(char c);
-SOKOL_API_DECL void sdtx_puts(const char* str); // does NOT append newline!
-SOKOL_API_DECL void sdtx_putr(const char* str, int len); // 'put range', also stops at zero-char
-SOKOL_API_DECL int sdtx_printf(const char* fmt, ...) SOKOL_DEBUGTEXT_PRINTF_ATTR;
-SOKOL_API_DECL int sdtx_vprintf(const char* fmt, va_list args);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_putc(char c);
+SOKOL_DEBUGTEXT_API_DECL void sdtx_puts(const char* str); // does NOT append newline!
+SOKOL_DEBUGTEXT_API_DECL void sdtx_putr(const char* str, int len); // 'put range', also stops at zero-char
+SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) SOKOL_DEBUGTEXT_PRINTF_ATTR;
+SOKOL_DEBUGTEXT_API_DECL int sdtx_vprintf(const char* fmt, va_list args);
#ifdef __cplusplus
} /* extern "C" */
@@ -2191,7 +2199,7 @@ static const uint8_t _sdtx_font_oric[2048] = {
frag_color = texture(tex, uv).xxxx * color;
}
@end
-
+
@program debugtext vs fs
*/
#if defined(SOKOL_GLCORE33)
@@ -4089,7 +4097,7 @@ SOKOL_API_IMPL void sdtx_color1i(uint32_t rgba) {
}
}
-SOKOL_API_DECL void sdtx_putc(char chr) {
+SOKOL_DEBUGTEXT_API_DECL void sdtx_putc(char chr) {
SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
_sdtx_context_t* ctx = _sdtx.cur_ctx;
if (ctx) {
@@ -4097,7 +4105,7 @@ SOKOL_API_DECL void sdtx_putc(char chr) {
}
}
-SOKOL_API_DECL void sdtx_puts(const char* str) {
+SOKOL_DEBUGTEXT_API_DECL void sdtx_puts(const char* str) {
SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
_sdtx_context_t* ctx = _sdtx.cur_ctx;
if (ctx) {
@@ -4108,7 +4116,7 @@ SOKOL_API_DECL void sdtx_puts(const char* str) {
}
}
-SOKOL_API_DECL void sdtx_putr(const char* str, int len) {
+SOKOL_DEBUGTEXT_API_DECL void sdtx_putr(const char* str, int len) {
SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
_sdtx_context_t* ctx = _sdtx.cur_ctx;
if (ctx) {
@@ -4122,7 +4130,7 @@ SOKOL_API_DECL void sdtx_putr(const char* str, int len) {
}
}
-SOKOL_API_DECL int sdtx_vprintf(const char* fmt, va_list args) {
+SOKOL_DEBUGTEXT_API_DECL int sdtx_vprintf(const char* fmt, va_list args) {
SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
SOKOL_ASSERT(_sdtx.fmt_buf && (_sdtx.fmt_buf_size >= 2));
int res = SOKOL_VSNPRINTF(_sdtx.fmt_buf, _sdtx.fmt_buf_size, fmt, args);
@@ -4132,7 +4140,7 @@ SOKOL_API_DECL int sdtx_vprintf(const char* fmt, va_list args) {
return res;
}
-SOKOL_API_DECL int sdtx_printf(const char* fmt, ...) {
+SOKOL_DEBUGTEXT_API_DECL int sdtx_printf(const char* fmt, ...) {
SOKOL_ASSERT(_SDTX_INIT_COOKIE == _sdtx.init_cookie);
SOKOL_ASSERT(_sdtx.fmt_buf && (_sdtx.fmt_buf_size >= 2));
va_list args;
diff --git a/util/sokol_fontstash.h b/util/sokol_fontstash.h
index 81b35a97..1db20019 100644
--- a/util/sokol_fontstash.h
+++ b/util/sokol_fontstash.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_FONTSTASH_IMPL)
+#define SOKOL_FONTSTASH_IMPL
+#endif
#ifndef SOKOL_FONTSTASH_INCLUDED
/*
sokol_fontstash.h -- renderer for https://github.com/memononen/fontstash
@@ -6,7 +9,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
-
+ #define SOKOL_IMPL or
#define SOKOL_FONTSTASH_IMPL
before you include this file in *one* C or C++ file to create the
@@ -27,7 +30,8 @@
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
SOKOL_FREE(p) - your own free function (default: free(p))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_FONTSTASH_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_FONTSTASH_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
@@ -159,23 +163,26 @@
#error "Please include sokol_gfx.h before sokol_fontstash.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_FONTSTASH_API_DECL)
+#define SOKOL_FONTSTASH_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_FONTSTASH_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_FONTSTASH_IMPL)
+#define SOKOL_FONTSTASH_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_FONTSTASH_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_FONTSTASH_API_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
-SOKOL_API_DECL FONScontext* sfons_create(int width, int height, int flags);
-SOKOL_API_DECL void sfons_destroy(FONScontext* ctx);
-SOKOL_API_DECL void sfons_flush(FONScontext* ctx);
-SOKOL_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_FONTSTASH_API_DECL FONScontext* sfons_create(int width, int height, int flags);
+SOKOL_FONTSTASH_API_DECL void sfons_destroy(FONScontext* ctx);
+SOKOL_FONTSTASH_API_DECL void sfons_flush(FONScontext* ctx);
+SOKOL_FONTSTASH_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/util/sokol_gfx_imgui.h b/util/sokol_gfx_imgui.h
index e012e33e..67f9bd5c 100644
--- a/util/sokol_gfx_imgui.h
+++ b/util/sokol_gfx_imgui.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_GFX_IMGUI_IMPL)
+#define SOKOL_GFX_IMGUI_IMPL
+#endif
#ifndef SOKOL_GFX_IMGUI_INCLUDED
/*
sokol_gfx_imgui.h -- debug-inspection UI for sokol_gfx.h using Dear ImGui
@@ -5,7 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
-
+ #define SOKOL_IMPL or
#define SOKOL_GFX_IMGUI_IMPL
before you include this file in *one* C or C++ file to create the
@@ -44,7 +47,8 @@
default: SOKOL_ASSERT(false)
SOKOL_MALLOC(s) -- your own memory allocation function, default: malloc(s)
SOKOL_FREE(p) -- your own memory free function, default: free(p)
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_GFX_IMGUI_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_GFX_IMGUI_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_gfx_imgui.h is compiled as a DLL, define the following before
@@ -52,7 +56,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_GFX_IMGUI_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
STEP BY STEP:
@@ -165,13 +169,16 @@
#error "Please include sokol_gfx.h before sokol_gfx_imgui.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_GFX_IMGUI_API_DECL)
+#define SOKOL_GFX_IMGUI_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_GFX_IMGUI_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GFX_IMGUI_IMPL)
+#define SOKOL_GFX_IMGUI_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_GFX_IMGUI_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_GFX_IMGUI_API_DECL extern
#endif
#endif
@@ -296,11 +303,21 @@ typedef enum {
SG_IMGUI_CMD_ALLOC_SHADER,
SG_IMGUI_CMD_ALLOC_PIPELINE,
SG_IMGUI_CMD_ALLOC_PASS,
+ SG_IMGUI_CMD_DEALLOC_BUFFER,
+ SG_IMGUI_CMD_DEALLOC_IMAGE,
+ SG_IMGUI_CMD_DEALLOC_SHADER,
+ SG_IMGUI_CMD_DEALLOC_PIPELINE,
+ SG_IMGUI_CMD_DEALLOC_PASS,
SG_IMGUI_CMD_INIT_BUFFER,
SG_IMGUI_CMD_INIT_IMAGE,
SG_IMGUI_CMD_INIT_SHADER,
SG_IMGUI_CMD_INIT_PIPELINE,
SG_IMGUI_CMD_INIT_PASS,
+ SG_IMGUI_CMD_UNINIT_BUFFER,
+ SG_IMGUI_CMD_UNINIT_IMAGE,
+ SG_IMGUI_CMD_UNINIT_SHADER,
+ SG_IMGUI_CMD_UNINIT_PIPELINE,
+ SG_IMGUI_CMD_UNINIT_PASS,
SG_IMGUI_CMD_FAIL_BUFFER,
SG_IMGUI_CMD_FAIL_IMAGE,
SG_IMGUI_CMD_FAIL_SHADER,
@@ -440,6 +457,26 @@ typedef struct {
typedef struct {
sg_buffer buffer;
+} sg_imgui_args_dealloc_buffer_t;
+
+typedef struct {
+ sg_image image;
+} sg_imgui_args_dealloc_image_t;
+
+typedef struct {
+ sg_shader shader;
+} sg_imgui_args_dealloc_shader_t;
+
+typedef struct {
+ sg_pipeline pipeline;
+} sg_imgui_args_dealloc_pipeline_t;
+
+typedef struct {
+ sg_pass pass;
+} sg_imgui_args_dealloc_pass_t;
+
+typedef struct {
+ sg_buffer buffer;
} sg_imgui_args_init_buffer_t;
typedef struct {
@@ -460,6 +497,26 @@ typedef struct {
typedef struct {
sg_buffer buffer;
+} sg_imgui_args_uninit_buffer_t;
+
+typedef struct {
+ sg_image image;
+} sg_imgui_args_uninit_image_t;
+
+typedef struct {
+ sg_shader shader;
+} sg_imgui_args_uninit_shader_t;
+
+typedef struct {
+ sg_pipeline pipeline;
+} sg_imgui_args_uninit_pipeline_t;
+
+typedef struct {
+ sg_pass pass;
+} sg_imgui_args_uninit_pass_t;
+
+typedef struct {
+ sg_buffer buffer;
} sg_imgui_args_fail_buffer_t;
typedef struct {
@@ -509,11 +566,21 @@ typedef union {
sg_imgui_args_alloc_shader_t alloc_shader;
sg_imgui_args_alloc_pipeline_t alloc_pipeline;
sg_imgui_args_alloc_pass_t alloc_pass;
+ sg_imgui_args_dealloc_buffer_t dealloc_buffer;
+ sg_imgui_args_dealloc_image_t dealloc_image;
+ sg_imgui_args_dealloc_shader_t dealloc_shader;
+ sg_imgui_args_dealloc_pipeline_t dealloc_pipeline;
+ sg_imgui_args_dealloc_pass_t dealloc_pass;
sg_imgui_args_init_buffer_t init_buffer;
sg_imgui_args_init_image_t init_image;
sg_imgui_args_init_shader_t init_shader;
sg_imgui_args_init_pipeline_t init_pipeline;
sg_imgui_args_init_pass_t init_pass;
+ sg_imgui_args_uninit_buffer_t uninit_buffer;
+ sg_imgui_args_uninit_image_t uninit_image;
+ sg_imgui_args_uninit_shader_t uninit_shader;
+ sg_imgui_args_uninit_pipeline_t uninit_pipeline;
+ sg_imgui_args_uninit_pass_t uninit_pass;
sg_imgui_args_fail_buffer_t fail_buffer;
sg_imgui_args_fail_image_t fail_image;
sg_imgui_args_fail_shader_t fail_shader;
@@ -563,25 +630,25 @@ typedef struct {
sg_trace_hooks hooks;
} sg_imgui_t;
-SOKOL_API_DECL void sg_imgui_init(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_discard(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw(sg_imgui_t* ctx);
-
-SOKOL_API_DECL void sg_imgui_draw_buffers_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_images_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_shaders_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_pipelines_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_passes_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_capture_content(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_capabilities_content(sg_imgui_t* ctx);
-
-SOKOL_API_DECL void sg_imgui_draw_buffers_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_images_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_shaders_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_pipelines_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_passes_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_capture_window(sg_imgui_t* ctx);
-SOKOL_API_DECL void sg_imgui_draw_capabilities_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_init(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_discard(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw(sg_imgui_t* ctx);
+
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_buffers_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_images_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_shaders_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_pipelines_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_passes_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capture_content(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capabilities_content(sg_imgui_t* ctx);
+
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_buffers_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_images_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_shaders_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_pipelines_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_passes_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capture_window(sg_imgui_t* ctx);
+SOKOL_GFX_IMGUI_API_DECL void sg_imgui_draw_capabilities_window(sg_imgui_t* ctx);
#if defined(__cplusplus)
} /* extern "C" */
@@ -1650,6 +1717,41 @@ _SOKOL_PRIVATE sg_imgui_str_t _sg_imgui_capture_item_string(sg_imgui_t* ctx, int
}
break;
+ case SG_IMGUI_CMD_DEALLOC_BUFFER:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_buffer_id_string(ctx, item->args.dealloc_buffer.buffer);
+ _sg_imgui_snprintf(&str, "%d: sg_dealloc_buffer() => %s", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_DEALLOC_IMAGE:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_image_id_string(ctx, item->args.dealloc_image.image);
+ _sg_imgui_snprintf(&str, "%d: sg_dealloc_image() => %s", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_DEALLOC_SHADER:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_shader_id_string(ctx, item->args.dealloc_shader.shader);
+ _sg_imgui_snprintf(&str, "%d: sg_dealloc_shader() => %s", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_DEALLOC_PIPELINE:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_pipeline_id_string(ctx, item->args.dealloc_pipeline.pipeline);
+ _sg_imgui_snprintf(&str, "%d: sg_dealloc_pipeline() => %s", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_DEALLOC_PASS:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_pass_id_string(ctx, item->args.dealloc_pass.pass);
+ _sg_imgui_snprintf(&str, "%d: sg_dealloc_pass() => %s", index, res_id.buf);
+ }
+ break;
+
case SG_IMGUI_CMD_INIT_BUFFER:
{
sg_imgui_str_t res_id = _sg_imgui_buffer_id_string(ctx, item->args.init_buffer.buffer);
@@ -1685,6 +1787,41 @@ _SOKOL_PRIVATE sg_imgui_str_t _sg_imgui_capture_item_string(sg_imgui_t* ctx, int
}
break;
+ case SG_IMGUI_CMD_UNINIT_BUFFER:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_buffer_id_string(ctx, item->args.uninit_buffer.buffer);
+ _sg_imgui_snprintf(&str, "%d: sg_uninit_buffer(buf=%s, desc=..)", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_UNINIT_IMAGE:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_image_id_string(ctx, item->args.uninit_image.image);
+ _sg_imgui_snprintf(&str, "%d: sg_uninit_image(img=%s, desc=..)", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_UNINIT_SHADER:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_shader_id_string(ctx, item->args.uninit_shader.shader);
+ _sg_imgui_snprintf(&str, "%d: sg_uninit_shader(shd=%s, desc=..)", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_UNINIT_PIPELINE:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_pipeline_id_string(ctx, item->args.uninit_pipeline.pipeline);
+ _sg_imgui_snprintf(&str, "%d: sg_uninit_pipeline(pip=%s, desc=..)", index, res_id.buf);
+ }
+ break;
+
+ case SG_IMGUI_CMD_UNINIT_PASS:
+ {
+ sg_imgui_str_t res_id = _sg_imgui_pass_id_string(ctx, item->args.uninit_pass.pass);
+ _sg_imgui_snprintf(&str, "%d: sg_uninit_pass(pass=%s, desc=..)", index, res_id.buf);
+ }
+ break;
+
case SG_IMGUI_CMD_FAIL_BUFFER:
{
sg_imgui_str_t res_id = _sg_imgui_buffer_id_string(ctx, item->args.fail_buffer.buffer);
@@ -2234,6 +2371,76 @@ _SOKOL_PRIVATE void _sg_imgui_alloc_pass(sg_pass result, void* user_data) {
}
}
+_SOKOL_PRIVATE void _sg_imgui_dealloc_buffer(sg_buffer buf_id, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_DEALLOC_BUFFER;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.dealloc_buffer.buffer = buf_id;
+ }
+ if (ctx->hooks.dealloc_buffer) {
+ ctx->hooks.dealloc_buffer(buf_id, ctx->hooks.user_data);
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_dealloc_image(sg_image img_id, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_DEALLOC_IMAGE;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.dealloc_image.image = img_id;
+ }
+ if (ctx->hooks.dealloc_image) {
+ ctx->hooks.dealloc_image(img_id, ctx->hooks.user_data);
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_dealloc_shader(sg_shader shd_id, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_DEALLOC_SHADER;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.dealloc_shader.shader = shd_id;
+ }
+ if (ctx->hooks.dealloc_shader) {
+ ctx->hooks.dealloc_shader(shd_id, ctx->hooks.user_data);
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_dealloc_pipeline(sg_pipeline pip_id, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_DEALLOC_PIPELINE;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.dealloc_pipeline.pipeline = pip_id;
+ }
+ if (ctx->hooks.dealloc_pipeline) {
+ ctx->hooks.dealloc_pipeline(pip_id, ctx->hooks.user_data);
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_dealloc_pass(sg_pass pass_id, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_DEALLOC_PASS;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.dealloc_pass.pass = pass_id;
+ }
+ if (ctx->hooks.dealloc_pass) {
+ ctx->hooks.dealloc_pass(pass_id, ctx->hooks.user_data);
+ }
+}
+
_SOKOL_PRIVATE void _sg_imgui_init_buffer(sg_buffer buf_id, const sg_buffer_desc* desc, void* user_data) {
sg_imgui_t* ctx = (sg_imgui_t*) user_data;
SOKOL_ASSERT(ctx);
@@ -2319,6 +2526,91 @@ _SOKOL_PRIVATE void _sg_imgui_init_pass(sg_pass pass_id, const sg_pass_desc* des
}
}
+_SOKOL_PRIVATE void _sg_imgui_uninit_buffer(sg_buffer buf, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_UNINIT_BUFFER;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.uninit_buffer.buffer = buf;
+ }
+ if (ctx->hooks.uninit_buffer) {
+ ctx->hooks.uninit_buffer(buf, ctx->hooks.user_data);
+ }
+ if (buf.id != SG_INVALID_ID) {
+ _sg_imgui_buffer_destroyed(ctx, _sg_imgui_slot_index(buf.id));
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_uninit_image(sg_image img, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_UNINIT_IMAGE;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.uninit_image.image = img;
+ }
+ if (ctx->hooks.uninit_image) {
+ ctx->hooks.uninit_image(img, ctx->hooks.user_data);
+ }
+ if (img.id != SG_INVALID_ID) {
+ _sg_imgui_image_destroyed(ctx, _sg_imgui_slot_index(img.id));
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_uninit_shader(sg_shader shd, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_UNINIT_SHADER;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.uninit_shader.shader = shd;
+ }
+ if (ctx->hooks.uninit_shader) {
+ ctx->hooks.uninit_shader(shd, ctx->hooks.user_data);
+ }
+ if (shd.id != SG_INVALID_ID) {
+ _sg_imgui_shader_destroyed(ctx, _sg_imgui_slot_index(shd.id));
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_uninit_pipeline(sg_pipeline pip, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_UNINIT_PIPELINE;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.uninit_pipeline.pipeline = pip;
+ }
+ if (ctx->hooks.uninit_pipeline) {
+ ctx->hooks.uninit_pipeline(pip, ctx->hooks.user_data);
+ }
+ if (pip.id != SG_INVALID_ID) {
+ _sg_imgui_pipeline_destroyed(ctx, _sg_imgui_slot_index(pip.id));
+ }
+}
+
+_SOKOL_PRIVATE void _sg_imgui_uninit_pass(sg_pass pass, void* user_data) {
+ sg_imgui_t* ctx = (sg_imgui_t*) user_data;
+ SOKOL_ASSERT(ctx);
+ sg_imgui_capture_item_t* item = _sg_imgui_capture_next_write_item(ctx);
+ if (item) {
+ item->cmd = SG_IMGUI_CMD_UNINIT_PIPELINE;
+ item->color = _SG_IMGUI_COLOR_RSRC;
+ item->args.uninit_pass.pass = pass;
+ }
+ if (ctx->hooks.uninit_pass) {
+ ctx->hooks.uninit_pass(pass, ctx->hooks.user_data);
+ }
+ if (pass.id != SG_INVALID_ID) {
+ _sg_imgui_pass_destroyed(ctx, _sg_imgui_slot_index(pass.id));
+ }
+}
+
_SOKOL_PRIVATE void _sg_imgui_fail_buffer(sg_buffer buf_id, void* user_data) {
sg_imgui_t* ctx = (sg_imgui_t*) user_data;
SOKOL_ASSERT(ctx);
@@ -3482,11 +3774,21 @@ SOKOL_API_IMPL void sg_imgui_init(sg_imgui_t* ctx) {
hooks.alloc_shader = _sg_imgui_alloc_shader;
hooks.alloc_pipeline = _sg_imgui_alloc_pipeline;
hooks.alloc_pass = _sg_imgui_alloc_pass;
+ hooks.dealloc_buffer = _sg_imgui_dealloc_buffer;
+ hooks.dealloc_image = _sg_imgui_dealloc_image;
+ hooks.dealloc_shader = _sg_imgui_dealloc_shader;
+ hooks.dealloc_pipeline = _sg_imgui_dealloc_pipeline;
+ hooks.dealloc_pass = _sg_imgui_dealloc_pass;
hooks.init_buffer = _sg_imgui_init_buffer;
hooks.init_image = _sg_imgui_init_image;
hooks.init_shader = _sg_imgui_init_shader;
hooks.init_pipeline = _sg_imgui_init_pipeline;
hooks.init_pass = _sg_imgui_init_pass;
+ hooks.uninit_buffer = _sg_imgui_uninit_buffer;
+ hooks.uninit_image = _sg_imgui_uninit_image;
+ hooks.uninit_shader = _sg_imgui_uninit_shader;
+ hooks.uninit_pipeline = _sg_imgui_uninit_pipeline;
+ hooks.uninit_pass = _sg_imgui_uninit_pass;
hooks.fail_buffer = _sg_imgui_fail_buffer;
hooks.fail_image = _sg_imgui_fail_image;
hooks.fail_shader = _sg_imgui_fail_shader;
diff --git a/util/sokol_gl.h b/util/sokol_gl.h
index e7b7b553..04895170 100644
--- a/util/sokol_gl.h
+++ b/util/sokol_gl.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_GL_IMPL)
+#define SOKOL_GL_IMPL
+#endif
#ifndef SOKOL_GL_INCLUDED
/*
sokol_gl.h -- OpenGL 1.x style rendering on top of sokol_gfx.h
@@ -5,6 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
+ #define SOKOL_IMPL or
#define SOKOL_GL_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -25,7 +29,8 @@
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
SOKOL_FREE(p) - your own free function (default: free(p))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_GL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_GL_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
@@ -35,7 +40,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_GL_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
Include the following headers before including sokol_gl.h:
@@ -445,13 +450,16 @@
#error "Please include sokol_gfx.h before sokol_gl.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_GL_API_DECL)
+#define SOKOL_GL_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_GL_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GL_IMPL)
+#define SOKOL_GL_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_GL_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_GL_API_DECL extern
#endif
#endif
@@ -488,92 +496,92 @@ typedef struct sgl_desc_t {
} sgl_desc_t;
/* setup/shutdown/misc */
-SOKOL_API_DECL void sgl_setup(const sgl_desc_t* desc);
-SOKOL_API_DECL void sgl_shutdown(void);
-SOKOL_API_DECL sgl_error_t sgl_error(void);
-SOKOL_API_DECL void sgl_defaults(void);
-SOKOL_API_DECL float sgl_rad(float deg);
-SOKOL_API_DECL float sgl_deg(float rad);
+SOKOL_GL_API_DECL void sgl_setup(const sgl_desc_t* desc);
+SOKOL_GL_API_DECL void sgl_shutdown(void);
+SOKOL_GL_API_DECL sgl_error_t sgl_error(void);
+SOKOL_GL_API_DECL void sgl_defaults(void);
+SOKOL_GL_API_DECL float sgl_rad(float deg);
+SOKOL_GL_API_DECL float sgl_deg(float rad);
/* create and destroy pipeline objects */
-SOKOL_API_DECL sgl_pipeline sgl_make_pipeline(const sg_pipeline_desc* desc);
-SOKOL_API_DECL void sgl_destroy_pipeline(sgl_pipeline pip);
+SOKOL_GL_API_DECL sgl_pipeline sgl_make_pipeline(const sg_pipeline_desc* desc);
+SOKOL_GL_API_DECL void sgl_destroy_pipeline(sgl_pipeline pip);
/* render state functions */
-SOKOL_API_DECL void sgl_viewport(int x, int y, int w, int h, bool origin_top_left);
-SOKOL_API_DECL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left);
-SOKOL_API_DECL void sgl_enable_texture(void);
-SOKOL_API_DECL void sgl_disable_texture(void);
-SOKOL_API_DECL void sgl_texture(sg_image img);
+SOKOL_GL_API_DECL void sgl_viewport(int x, int y, int w, int h, bool origin_top_left);
+SOKOL_GL_API_DECL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left);
+SOKOL_GL_API_DECL void sgl_enable_texture(void);
+SOKOL_GL_API_DECL void sgl_disable_texture(void);
+SOKOL_GL_API_DECL void sgl_texture(sg_image img);
/* pipeline stack functions */
-SOKOL_API_DECL void sgl_default_pipeline(void);
-SOKOL_API_DECL void sgl_load_pipeline(sgl_pipeline pip);
-SOKOL_API_DECL void sgl_push_pipeline(void);
-SOKOL_API_DECL void sgl_pop_pipeline(void);
+SOKOL_GL_API_DECL void sgl_default_pipeline(void);
+SOKOL_GL_API_DECL void sgl_load_pipeline(sgl_pipeline pip);
+SOKOL_GL_API_DECL void sgl_push_pipeline(void);
+SOKOL_GL_API_DECL void sgl_pop_pipeline(void);
/* matrix stack functions */
-SOKOL_API_DECL void sgl_matrix_mode_modelview(void);
-SOKOL_API_DECL void sgl_matrix_mode_projection(void);
-SOKOL_API_DECL void sgl_matrix_mode_texture(void);
-SOKOL_API_DECL void sgl_load_identity(void);
-SOKOL_API_DECL void sgl_load_matrix(const float m[16]);
-SOKOL_API_DECL void sgl_load_transpose_matrix(const float m[16]);
-SOKOL_API_DECL void sgl_mult_matrix(const float m[16]);
-SOKOL_API_DECL void sgl_mult_transpose_matrix(const float m[16]);
-SOKOL_API_DECL void sgl_rotate(float angle_rad, float x, float y, float z);
-SOKOL_API_DECL void sgl_scale(float x, float y, float z);
-SOKOL_API_DECL void sgl_translate(float x, float y, float z);
-SOKOL_API_DECL void sgl_frustum(float l, float r, float b, float t, float n, float f);
-SOKOL_API_DECL void sgl_ortho(float l, float r, float b, float t, float n, float f);
-SOKOL_API_DECL void sgl_perspective(float fov_y, float aspect, float z_near, float z_far);
-SOKOL_API_DECL void sgl_lookat(float eye_x, float eye_y, float eye_z, float center_x, float center_y, float center_z, float up_x, float up_y, float up_z);
-SOKOL_API_DECL void sgl_push_matrix(void);
-SOKOL_API_DECL void sgl_pop_matrix(void);
+SOKOL_GL_API_DECL void sgl_matrix_mode_modelview(void);
+SOKOL_GL_API_DECL void sgl_matrix_mode_projection(void);
+SOKOL_GL_API_DECL void sgl_matrix_mode_texture(void);
+SOKOL_GL_API_DECL void sgl_load_identity(void);
+SOKOL_GL_API_DECL void sgl_load_matrix(const float m[16]);
+SOKOL_GL_API_DECL void sgl_load_transpose_matrix(const float m[16]);
+SOKOL_GL_API_DECL void sgl_mult_matrix(const float m[16]);
+SOKOL_GL_API_DECL void sgl_mult_transpose_matrix(const float m[16]);
+SOKOL_GL_API_DECL void sgl_rotate(float angle_rad, float x, float y, float z);
+SOKOL_GL_API_DECL void sgl_scale(float x, float y, float z);
+SOKOL_GL_API_DECL void sgl_translate(float x, float y, float z);
+SOKOL_GL_API_DECL void sgl_frustum(float l, float r, float b, float t, float n, float f);
+SOKOL_GL_API_DECL void sgl_ortho(float l, float r, float b, float t, float n, float f);
+SOKOL_GL_API_DECL void sgl_perspective(float fov_y, float aspect, float z_near, float z_far);
+SOKOL_GL_API_DECL void sgl_lookat(float eye_x, float eye_y, float eye_z, float center_x, float center_y, float center_z, float up_x, float up_y, float up_z);
+SOKOL_GL_API_DECL void sgl_push_matrix(void);
+SOKOL_GL_API_DECL void sgl_pop_matrix(void);
/* these functions only set the internal 'current texcoord / color' (valid inside or outside begin/end) */
-SOKOL_API_DECL void sgl_t2f(float u, float v);
-SOKOL_API_DECL void sgl_c3f(float r, float g, float b);
-SOKOL_API_DECL void sgl_c4f(float r, float g, float b, float a);
-SOKOL_API_DECL void sgl_c3b(uint8_t r, uint8_t g, uint8_t b);
-SOKOL_API_DECL void sgl_c4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL void sgl_c1i(uint32_t rgba);
+SOKOL_GL_API_DECL void sgl_t2f(float u, float v);
+SOKOL_GL_API_DECL void sgl_c3f(float r, float g, float b);
+SOKOL_GL_API_DECL void sgl_c4f(float r, float g, float b, float a);
+SOKOL_GL_API_DECL void sgl_c3b(uint8_t r, uint8_t g, uint8_t b);
+SOKOL_GL_API_DECL void sgl_c4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_GL_API_DECL void sgl_c1i(uint32_t rgba);
/* define primitives, each begin/end is one draw command */
-SOKOL_API_DECL void sgl_begin_points(void);
-SOKOL_API_DECL void sgl_begin_lines(void);
-SOKOL_API_DECL void sgl_begin_line_strip(void);
-SOKOL_API_DECL void sgl_begin_triangles(void);
-SOKOL_API_DECL void sgl_begin_triangle_strip(void);
-SOKOL_API_DECL void sgl_begin_quads(void);
-SOKOL_API_DECL void sgl_v2f(float x, float y);
-SOKOL_API_DECL void sgl_v3f(float x, float y, float z);
-SOKOL_API_DECL void sgl_v2f_t2f(float x, float y, float u, float v);
-SOKOL_API_DECL void sgl_v3f_t2f(float x, float y, float z, float u, float v);
-SOKOL_API_DECL void sgl_v2f_c3f(float x, float y, float r, float g, float b);
-SOKOL_API_DECL void sgl_v2f_c3b(float x, float y, uint8_t r, uint8_t g, uint8_t b);
-SOKOL_API_DECL void sgl_v2f_c4f(float x, float y, float r, float g, float b, float a);
-SOKOL_API_DECL void sgl_v2f_c4b(float x, float y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL void sgl_v2f_c1i(float x, float y, uint32_t rgba);
-SOKOL_API_DECL void sgl_v3f_c3f(float x, float y, float z, float r, float g, float b);
-SOKOL_API_DECL void sgl_v3f_c3b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b);
-SOKOL_API_DECL void sgl_v3f_c4f(float x, float y, float z, float r, float g, float b, float a);
-SOKOL_API_DECL void sgl_v3f_c4b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL void sgl_v3f_c1i(float x, float y, float z, uint32_t rgba);
-SOKOL_API_DECL void sgl_v2f_t2f_c3f(float x, float y, float u, float v, float r, float g, float b);
-SOKOL_API_DECL void sgl_v2f_t2f_c3b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b);
-SOKOL_API_DECL void sgl_v2f_t2f_c4f(float x, float y, float u, float v, float r, float g, float b, float a);
-SOKOL_API_DECL void sgl_v2f_t2f_c4b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL void sgl_v2f_t2f_c1i(float x, float y, float u, float v, uint32_t rgba);
-SOKOL_API_DECL void sgl_v3f_t2f_c3f(float x, float y, float z, float u, float v, float r, float g, float b);
-SOKOL_API_DECL void sgl_v3f_t2f_c3b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b);
-SOKOL_API_DECL void sgl_v3f_t2f_c4f(float x, float y, float z, float u, float v, float r, float g, float b, float a);
-SOKOL_API_DECL void sgl_v3f_t2f_c4b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL void sgl_v3f_t2f_c1i(float x, float y, float z, float u, float v, uint32_t rgba);
-SOKOL_API_DECL void sgl_end(void);
+SOKOL_GL_API_DECL void sgl_begin_points(void);
+SOKOL_GL_API_DECL void sgl_begin_lines(void);
+SOKOL_GL_API_DECL void sgl_begin_line_strip(void);
+SOKOL_GL_API_DECL void sgl_begin_triangles(void);
+SOKOL_GL_API_DECL void sgl_begin_triangle_strip(void);
+SOKOL_GL_API_DECL void sgl_begin_quads(void);
+SOKOL_GL_API_DECL void sgl_v2f(float x, float y);
+SOKOL_GL_API_DECL void sgl_v3f(float x, float y, float z);
+SOKOL_GL_API_DECL void sgl_v2f_t2f(float x, float y, float u, float v);
+SOKOL_GL_API_DECL void sgl_v3f_t2f(float x, float y, float z, float u, float v);
+SOKOL_GL_API_DECL void sgl_v2f_c3f(float x, float y, float r, float g, float b);
+SOKOL_GL_API_DECL void sgl_v2f_c3b(float x, float y, uint8_t r, uint8_t g, uint8_t b);
+SOKOL_GL_API_DECL void sgl_v2f_c4f(float x, float y, float r, float g, float b, float a);
+SOKOL_GL_API_DECL void sgl_v2f_c4b(float x, float y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_GL_API_DECL void sgl_v2f_c1i(float x, float y, uint32_t rgba);
+SOKOL_GL_API_DECL void sgl_v3f_c3f(float x, float y, float z, float r, float g, float b);
+SOKOL_GL_API_DECL void sgl_v3f_c3b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b);
+SOKOL_GL_API_DECL void sgl_v3f_c4f(float x, float y, float z, float r, float g, float b, float a);
+SOKOL_GL_API_DECL void sgl_v3f_c4b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_GL_API_DECL void sgl_v3f_c1i(float x, float y, float z, uint32_t rgba);
+SOKOL_GL_API_DECL void sgl_v2f_t2f_c3f(float x, float y, float u, float v, float r, float g, float b);
+SOKOL_GL_API_DECL void sgl_v2f_t2f_c3b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b);
+SOKOL_GL_API_DECL void sgl_v2f_t2f_c4f(float x, float y, float u, float v, float r, float g, float b, float a);
+SOKOL_GL_API_DECL void sgl_v2f_t2f_c4b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_GL_API_DECL void sgl_v2f_t2f_c1i(float x, float y, float u, float v, uint32_t rgba);
+SOKOL_GL_API_DECL void sgl_v3f_t2f_c3f(float x, float y, float z, float u, float v, float r, float g, float b);
+SOKOL_GL_API_DECL void sgl_v3f_t2f_c3b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b);
+SOKOL_GL_API_DECL void sgl_v3f_t2f_c4f(float x, float y, float z, float u, float v, float r, float g, float b, float a);
+SOKOL_GL_API_DECL void sgl_v3f_t2f_c4b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_GL_API_DECL void sgl_v3f_t2f_c1i(float x, float y, float z, float u, float v, uint32_t rgba);
+SOKOL_GL_API_DECL void sgl_end(void);
/* render everything */
-SOKOL_API_DECL void sgl_draw(void);
+SOKOL_GL_API_DECL void sgl_draw(void);
#ifdef __cplusplus
} /* extern "C" */
@@ -3193,7 +3201,7 @@ SOKOL_API_IMPL void sgl_lookat(float eye_x, float eye_y, float eye_z, float cent
_sgl_lookat(_sgl_matrix(), eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z);
}
-SOKOL_API_DECL void sgl_push_matrix(void) {
+SOKOL_GL_API_DECL void sgl_push_matrix(void) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
SOKOL_ASSERT((_sgl.cur_matrix_mode >= 0) && (_sgl.cur_matrix_mode < SGL_NUM_MATRIXMODES));
_sgl.matrix_dirty = true;
@@ -3208,7 +3216,7 @@ SOKOL_API_DECL void sgl_push_matrix(void) {
}
}
-SOKOL_API_DECL void sgl_pop_matrix(void) {
+SOKOL_GL_API_DECL void sgl_pop_matrix(void) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
SOKOL_ASSERT((_sgl.cur_matrix_mode >= 0) && (_sgl.cur_matrix_mode < SGL_NUM_MATRIXMODES));
_sgl.matrix_dirty = true;
diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h
index cd83e9ef..590e5ca8 100644
--- a/util/sokol_imgui.h
+++ b/util/sokol_imgui.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_IMGUI_IMPL)
+#define SOKOL_IMGUI_IMPL
+#endif
#ifndef SOKOL_IMGUI_INCLUDED
/*
sokol_imgui.h -- drop-in Dear ImGui renderer/event-handler for sokol_gfx.h
@@ -5,7 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
-
+ #define SOKOL_IMPL or
#define SOKOL_IMGUI_IMPL
before you include this file in *one* C or C++ file to create the
@@ -39,7 +42,8 @@
to override defaults:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_IMGUI_API_DECL- public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_IMGUI_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_imgui.h is compiled as a DLL, define the following before
@@ -47,7 +51,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_IMGUI_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
Include the following headers before sokol_imgui.h (both before including
@@ -204,13 +208,16 @@
#error "Please include sokol_app.h before sokol_imgui.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_IMGUI_API_DECL)
+#define SOKOL_IMGUI_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_IMGUI_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMGUI_IMPL)
+#define SOKOL_IMGUI_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_IMGUI_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_IMGUI_API_DECL extern
#endif
#endif
@@ -229,13 +236,13 @@ typedef struct simgui_desc_t {
bool disable_hotkeys; /* don't let ImGui handle Ctrl-A,C,V,X,Y,Z */
} simgui_desc_t;
-SOKOL_API_DECL void simgui_setup(const simgui_desc_t* desc);
-SOKOL_API_DECL void simgui_new_frame(int width, int height, double delta_time);
-SOKOL_API_DECL void simgui_render(void);
+SOKOL_IMGUI_API_DECL void simgui_setup(const simgui_desc_t* desc);
+SOKOL_IMGUI_API_DECL void simgui_new_frame(int width, int height, double delta_time);
+SOKOL_IMGUI_API_DECL void simgui_render(void);
#if !defined(SOKOL_IMGUI_NO_SOKOL_APP)
-SOKOL_API_DECL bool simgui_handle_event(const sapp_event* ev);
+SOKOL_IMGUI_API_DECL bool simgui_handle_event(const sapp_event* ev);
#endif
-SOKOL_API_DECL void simgui_shutdown(void);
+SOKOL_IMGUI_API_DECL void simgui_shutdown(void);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/util/sokol_memtrack.h b/util/sokol_memtrack.h
index 1af0dc93..b795e16f 100644
--- a/util/sokol_memtrack.h
+++ b/util/sokol_memtrack.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_MEMTRACK_IMPL)
+#define SOKOL_MEMTRACK_IMPL
+#endif
#ifndef SOKOL_MEMTRACK_INCLUDED
/*
sokol_memtrack.h -- memory allocation wrapper to track memory usage
@@ -16,7 +19,8 @@
Optionally provide the following defines with your own implementations:
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_MEMTRACK_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_MEMTRACK_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_memtrack.h is compiled as a DLL, define the following before
@@ -73,13 +77,16 @@
#include <stddef.h>
#include <stdint.h>
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_MEMTRACK_API_DECL)
+#define SOKOL_MEMTRACK_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_MEMTRACK_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_MEMTRACK_IMPL)
+#define SOKOL_MEMTRACK_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_MEMTRACK_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_MEMTRACK_API_DECL extern
#endif
#endif
@@ -92,7 +99,7 @@ typedef struct smemtrack_info_t {
int num_bytes;
} smemtrack_info_t;
-SOKOL_API_DECL smemtrack_info_t smemtrack_info(void);
+SOKOL_MEMTRACK_API_DECL smemtrack_info_t smemtrack_info(void);
#ifdef __cplusplus
} /* extern "C" */
@@ -100,7 +107,7 @@ SOKOL_API_DECL smemtrack_info_t smemtrack_info(void);
#endif /* SOKOL_MEMTRACK_INCLUDED */
/*=== IMPLEMENTATION =========================================================*/
-#ifdef SOKOL_IMPL
+#ifdef SOKOL_MEMTRACK_IMPL
#define SOKOL_MEMTRACK_IMPL_INCLUDED (1)
#include <stdlib.h> /* malloc, free, calloc */
#include <string.h> /* memset */
@@ -161,4 +168,4 @@ SOKOL_API_IMPL smemtrack_info_t smemtrack_info(void) {
return _smemtrack.state;
}
-#endif /* SOKOL_IMPL */
+#endif /* SOKOL_MEMTRACK_IMPL */
diff --git a/util/sokol_shape.h b/util/sokol_shape.h
index 3317b603..2c54ac53 100644
--- a/util/sokol_shape.h
+++ b/util/sokol_shape.h
@@ -1,3 +1,6 @@
+#if defined(SOKOL_IMPL) && !defined(SOKOL_SHAPE_IMPL)
+#define SOKOL_SHAPE_IMPL
+#endif
#ifndef SOKOL_SHAPE_INCLUDED
/*
sokol_shape.h -- create simple primitive shapes for sokol_gfx.h
@@ -5,6 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
+ #define SOKOL_IMPL or
#define SOKOL_SHAPE_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -16,7 +20,8 @@
...optionally provide the following macros to override defaults:
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
- SOKOL_API_DECL - public function declaration prefix (default: extern)
+ SOKOL_SHAPE_API_DECL- public function declaration prefix (default: extern)
+ SOKOL_API_DECL - same as SOKOL_SHAPE_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
If sokol_shape.h is compiled as a DLL, define the following before
@@ -24,7 +29,7 @@
SOKOL_DLL
- On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
+ On Windows, SOKOL_DLL will define SOKOL_SHAPE_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
FEATURE OVERVIEW
@@ -364,13 +369,16 @@
#error "Please include sokol_gfx.h before sokol_shape.h"
#endif
-#ifndef SOKOL_API_DECL
-#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
-#define SOKOL_API_DECL __declspec(dllexport)
+#if defined(SOKOL_API_DECL) && !defined(SOKOL_SHAPE_API_DECL)
+#define SOKOL_SHAPE_API_DECL SOKOL_API_DECL
+#endif
+#ifndef SOKOL_SHAPE_API_DECL
+#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_SHAPE_IMPL)
+#define SOKOL_SHAPE_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
-#define SOKOL_API_DECL __declspec(dllimport)
+#define SOKOL_SHAPE_API_DECL __declspec(dllimport)
#else
-#define SOKOL_API_DECL extern
+#define SOKOL_SHAPE_API_DECL extern
#endif
#endif
@@ -472,38 +480,38 @@ typedef struct sshape_torus_t {
} sshape_torus_t;
/* shape builder functions */
-SOKOL_API_DECL sshape_buffer_t sshape_build_plane(const sshape_buffer_t* buf, const sshape_plane_t* params);
-SOKOL_API_DECL sshape_buffer_t sshape_build_box(const sshape_buffer_t* buf, const sshape_box_t* params);
-SOKOL_API_DECL sshape_buffer_t sshape_build_sphere(const sshape_buffer_t* buf, const sshape_sphere_t* params);
-SOKOL_API_DECL sshape_buffer_t sshape_build_cylinder(const sshape_buffer_t* buf, const sshape_cylinder_t* params);
-SOKOL_API_DECL sshape_buffer_t sshape_build_torus(const sshape_buffer_t* buf, const sshape_torus_t* params);
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_plane(const sshape_buffer_t* buf, const sshape_plane_t* params);
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_box(const sshape_buffer_t* buf, const sshape_box_t* params);
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_sphere(const sshape_buffer_t* buf, const sshape_sphere_t* params);
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_cylinder(const sshape_buffer_t* buf, const sshape_cylinder_t* params);
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_torus(const sshape_buffer_t* buf, const sshape_torus_t* params);
/* query required vertex- and index-buffer sizes in bytes */
-SOKOL_API_DECL sshape_sizes_t sshape_plane_sizes(uint32_t tiles);
-SOKOL_API_DECL sshape_sizes_t sshape_box_sizes(uint32_t tiles);
-SOKOL_API_DECL sshape_sizes_t sshape_sphere_sizes(uint32_t slices, uint32_t stacks);
-SOKOL_API_DECL sshape_sizes_t sshape_cylinder_sizes(uint32_t slices, uint32_t stacks);
-SOKOL_API_DECL sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t rings);
+SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_plane_sizes(uint32_t tiles);
+SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_box_sizes(uint32_t tiles);
+SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_sphere_sizes(uint32_t slices, uint32_t stacks);
+SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_cylinder_sizes(uint32_t slices, uint32_t stacks);
+SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t rings);
/* extract sokol-gfx desc structs and primitive ranges from build state */
-SOKOL_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf);
-SOKOL_API_DECL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf);
-SOKOL_API_DECL sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf);
-SOKOL_API_DECL sg_buffer_layout_desc sshape_buffer_layout_desc(void);
-SOKOL_API_DECL sg_vertex_attr_desc sshape_position_attr_desc(void);
-SOKOL_API_DECL sg_vertex_attr_desc sshape_normal_attr_desc(void);
-SOKOL_API_DECL sg_vertex_attr_desc sshape_texcoord_attr_desc(void);
-SOKOL_API_DECL sg_vertex_attr_desc sshape_color_attr_desc(void);
+SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf);
+SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_buffer_t* buf);
+SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* buf);
+SOKOL_SHAPE_API_DECL sg_buffer_layout_desc sshape_buffer_layout_desc(void);
+SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_position_attr_desc(void);
+SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_normal_attr_desc(void);
+SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_texcoord_attr_desc(void);
+SOKOL_SHAPE_API_DECL sg_vertex_attr_desc sshape_color_attr_desc(void);
/* helper functions to build packed color value from floats or bytes */
-SOKOL_API_DECL uint32_t sshape_color_4f(float r, float g, float b, float a);
-SOKOL_API_DECL uint32_t sshape_color_3f(float r, float g, float b);
-SOKOL_API_DECL uint32_t sshape_color_4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-SOKOL_API_DECL uint32_t sshape_color_3b(uint8_t r, uint8_t g, uint8_t b);
+SOKOL_SHAPE_API_DECL uint32_t sshape_color_4f(float r, float g, float b, float a);
+SOKOL_SHAPE_API_DECL uint32_t sshape_color_3f(float r, float g, float b);
+SOKOL_SHAPE_API_DECL uint32_t sshape_color_4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
+SOKOL_SHAPE_API_DECL uint32_t sshape_color_3b(uint8_t r, uint8_t g, uint8_t b);
/* adapter function for filling matrix struct from generic float[16] array */
-SOKOL_API_DECL sshape_mat4_t sshape_mat4(const float m[16]);
-SOKOL_API_DECL sshape_mat4_t sshape_mat4_transpose(const float m[16]);
+SOKOL_SHAPE_API_DECL sshape_mat4_t sshape_mat4(const float m[16]);
+SOKOL_SHAPE_API_DECL sshape_mat4_t sshape_mat4_transpose(const float m[16]);
#ifdef __cplusplus
} // extern "C"
@@ -1169,7 +1177,7 @@ static void _sshape_build_cylinder_cap_ring(sshape_buffer_t* buf, const sshape_c
}
}
-SOKOL_API_DECL sshape_buffer_t sshape_build_cylinder(const sshape_buffer_t* in_buf, const sshape_cylinder_t* in_params) {
+SOKOL_SHAPE_API_DECL sshape_buffer_t sshape_build_cylinder(const sshape_buffer_t* in_buf, const sshape_cylinder_t* in_params) {
SOKOL_ASSERT(in_buf && in_params);
const sshape_cylinder_t params = _sshape_cylinder_defaults(in_params);
const uint32_t num_vertices = _sshape_cylinder_num_vertices(params.slices, params.stacks);
@@ -1350,7 +1358,7 @@ SOKOL_API_IMPL sg_buffer_desc sshape_index_buffer_desc(const sshape_buffer_t* bu
return desc;
}
-SOKOL_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf) {
+SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_buffer_t* buf) {
SOKOL_ASSERT(buf && buf->valid);
SOKOL_ASSERT(buf->indices.shape_offset < buf->indices.data_size);
SOKOL_ASSERT(0 == (buf->indices.shape_offset & (sizeof(uint16_t) - 1)));