diff options
| author | Andre Weissflog <floooh@gmail.com> | 2024-04-21 16:20:42 +0200 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2024-04-21 16:20:42 +0200 |
| commit | 4fac1bb845c011ed91446f511d86c7ce50e15e42 (patch) | |
| tree | 1d3d6fc599265add468ec3cbf135fef6bff30270 | |
| parent | 7e1035cb0dff181ca5ded241914ae128318e7d46 (diff) | |
| parent | 4534e02d6c83e23fa212ac29c1fd90d8a22f5419 (diff) | |
Merge branch 'master' into storage-buffers
| -rw-r--r-- | .github/workflows/gen_bindings.yml | 31 | ||||
| -rw-r--r-- | CHANGELOG.md | 49 | ||||
| -rw-r--r-- | README.md | 16 | ||||
| -rw-r--r-- | assets/logo_full_large.png | bin | 0 -> 2466 bytes | |||
| -rw-r--r-- | assets/logo_full_small.png | bin | 0 -> 1237 bytes | |||
| -rw-r--r-- | assets/logo_s_large.png | bin | 0 -> 1027 bytes | |||
| -rw-r--r-- | assets/logo_s_small.png | bin | 0 -> 414 bytes | |||
| -rw-r--r-- | bindgen/gen_odin.py | 70 | ||||
| -rw-r--r-- | bindgen/gen_rust.py | 12 | ||||
| -rw-r--r-- | sokol_app.h | 2 | ||||
| -rw-r--r-- | sokol_gfx.h | 54 | ||||
| -rw-r--r-- | sokol_glue.h | 2 | ||||
| -rw-r--r-- | tests/ext/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | util/sokol_debugtext.h | 4 | ||||
| -rw-r--r-- | util/sokol_gfx_imgui.h | 2 | ||||
| -rw-r--r-- | util/sokol_imgui.h | 12 |
16 files changed, 193 insertions, 63 deletions
diff --git a/.github/workflows/gen_bindings.yml b/.github/workflows/gen_bindings.yml index c1b52b7e..52a3bbe4 100644 --- a/.github/workflows/gen_bindings.yml +++ b/.github/workflows/gen_bindings.yml @@ -148,9 +148,7 @@ jobs: strategy: fail-fast: false matrix: - # FIXME: macOS Odin vs Homebrew LLVM currently seems broken - # os: [ubuntu-latest, macos-latest, windows-latest] - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 @@ -165,26 +163,43 @@ jobs: name: prepare-linux run: | sudo apt-get update - sudo apt-get install libglu1-mesa-dev mesa-common-dev xorg-dev libasound-dev llvm-14 - curl -L https://github.com/odin-lang/Odin/releases/download/dev-2023-08/odin-ubuntu-amd64-dev-2023-08.zip --output odin.zip + sudo apt-get install libglu1-mesa-dev mesa-common-dev xorg-dev libasound-dev + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + echo "/usr/lib/llvm-17/bin" >> $GITHUB_PATH + curl -L https://github.com/odin-lang/Odin/releases/download/dev-2024-04/odin-ubuntu-amd64-dev-2024-04.zip --output odin.zip unzip odin.zip + unzip dist.zip + rm -r ./dist/examples + mv ./dist/* ./ chmod a+x ./odin + cd sokol + chmod a+x ./build_clibs_linux.sh ./build_clibs_linux.sh + cd .. - if: runner.os == 'macOS' name: prepare-macos run: | - brew install llvm@14 - curl -L https://github.com/odin-lang/Odin/releases/download/dev-2023-08/odin-macos-amd64-dev-2023-08.zip --output odin.zip + brew install llvm@17 + curl -L https://github.com/odin-lang/Odin/releases/download/dev-2024-04/odin-macos-amd64-dev-2024-04.zip --output odin.zip unzip odin.zip + unzip dist.zip + rm -r ./dist/examples + mv ./dist/* ./ chmod a+x ./odin + cd sokol + chmod a+x ./build_clibs_macos.sh ./build_clibs_macos.sh + cd .. - if: runner.os == 'Windows' name: prepare-windows shell: cmd run: | - curl -L https://github.com/odin-lang/Odin/releases/download/dev-2023-08/odin-windows-amd64-dev-2023-08.zip --output odin.zip + curl -L https://github.com/odin-lang/Odin/releases/download/dev-2024-04/odin-windows-amd64-dev-2024-04.zip --output odin.zip unzip odin.zip + cd sokol build_clibs_windows.cmd + cd .. - name: build run: | ./odin build examples/clear -debug diff --git a/CHANGELOG.md b/CHANGELOG.md index fb43b716..ff5f17da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,38 @@ ## Updates +### 13-Apr-2024: + +- sokol_gfx.h d3d11: resource label strings are now communicated to D3D11 resource objects, + making it easier to identify those resources in tools like the Visual Studio Graphics Debugger + or RenderDoc. See PR https://github.com/floooh/sokol/pull/1025 for details. Many thanks to + @jakubtomsu for the PR! +- Odin bindings: merged https://github.com/floooh/sokol/pull/1023 (and related PR + https://github.com/floooh/sokol-odin/pull/11 in the actual bindings repo). This changes + the directory structure of the bindings to make them a bit friendlier to integrate + with Odin projects, and also adds a couple of smaller improvements and fixes. + Many thanks to @jakubtomsu for the PRs! +- Also a couple of smaller 'drive-by PRs' I merged over the last couple of days but didn't mention + yet in the changelog: + - https://github.com/floooh/sokol/pull/1029: exclude NUM enum items in Odin bindings, many thanks to @jakubtomsu + - https://github.com/floooh/sokol/pull/1028: in sokol_gfx.h fix GCC warnings in the d3d11 backend (when compiling + via mingw on Windows), many thanks @edubart + - https://github.com/floooh/sokol/pull/1026: in sokol_gfx.h increase the internal `_SG_STRING_SIZE` from + 16 to 32, by @jakubtomsu + - https://github.com/floooh/sokol/pull/1021, https://github.com/floooh/sokol-odin/pull/10: re-enable Odin CI builds + for macOS (by linking against LLVM 17), also by @jakubtomsu + +### 21-Mar-2024: + +- sokol_imgui.h: merged PR https://github.com/floooh/sokol/pull/1010, this will automatically + re-create the sokol-gfx font texture resources in the `simgui_new_frame()` call + when the Dear ImGui texture atlas has changed. This is an alternative to calling the + functions `simgui_create_fonts_texture()` and `simgui_destroy_fonts_texture()` manually. + One important reason why you'd want to call those functions manually is to create the fonts texture + with custom texture sampler attributes (the new implicit re-creation inside `simgui_new_frame()` + calls `sg_make_sampler()` with default attributes). + + Many thanks to @elloramir for the PR! + ### 02-Mar-2024: - sokol_app.h emscripten: two new flags in `sapp_desc` to configure the Emscripten main loop: @@ -164,7 +197,7 @@ Plus 2 minor drive-by fixes: - sokol_app.h android: Touch event coordinates are now using AMotionEvent_getX/Y() instead of AMotionEvent_getRawX/Y(). The raw functions don't work well in multi-window scenarios. See PR https://github.com/floooh/sokol/pull/974 for details. - Many thanks to Github user @Comanx! + Many thanks to GitHub user @Comanx! #### 19-Jan-2024 @@ -1092,7 +1125,7 @@ GLES2/WebGL1 support has been removed from the sokol headers (now that buffer with retained references). - **15-Dec-2022**: A small but important update in sokol_imgui.h which fixes - touch input handling on mobile devices. Many thanks to github user @Xadiant + touch input handling on mobile devices. Many thanks to GitHub user @Xadiant for the bug investigation and [PR](https://github.com/floooh/sokol/pull/760). - **25-Nov-2022**: Some code cleanup around resource creation and destruction in sokol_gfx.h: @@ -1168,7 +1201,7 @@ GLES2/WebGL1 support has been removed from the sokol headers (now that - **03-Nov-2022** The language bindings generation has been updated for Zig 0.10.0, and clang-14 (there was a minor change in the JSON ast-dump format). - Many thanks to github user @kcbanner for the Zig PR! + Many thanks to GitHub user @kcbanner for the Zig PR! - **02-Nov-2022** A new header sokol_spine.h (in the util dir), this is a renderer and 'handle wrapper' around the spine-c runtime (Spine is a popular 2D @@ -1181,14 +1214,14 @@ GLES2/WebGL1 support has been removed from the sokol headers (now that - **22-Oct-2022** All sokol headers now allow to override logging with a callback function (installed in the setup call) instead of defining a SOKOL_LOG macro. Overriding SOKOL_LOG still works as default fallback, but this is no - longer documented, consider this deprecated. Many thanks to github user + longer documented, consider this deprecated. Many thanks to GitHub user @Manuzor for the PR (see https://github.com/floooh/sokol/pull/721 for details) - **21-Oct-2022** RGB9E5 pixel format support in sokol_gfx.h and a GLES2 related bugfix in the sokol_app.h Android backend: - sokol_gfx.h now supports RGB9E5 textures (3*9 bit RGB + 5 bit shared exponent), this works in all backends except GLES2 and WebGL1 (use ```sg_query_pixelformat()``` - to check for runtime support). Many thanks to github user @allcreater for the PR! + to check for runtime support). Many thanks to GitHub user @allcreater for the PR! - a bugfix in the sokol_app.h Android backend: when forcing a GLES2 context via sapp_desc.gl_force_gles2, the Android backend correctly created a GLES2 context, but then didn't communicate this through the function ```sapp_gles2()``` (which @@ -1291,7 +1324,7 @@ work. - **29-May-2022**: The code generation scripts for the [sokol-nim](https://github.com/floooh/sokol-nim) language bindings have been revised and updated, many thanks to Gustav Olsson for the PR! (I'm planning to -spend a few more days integrating the bindings generation with Github Actions, +spend a few more days integrating the bindings generation with GitHub Actions, so that it's easier to publish new bindings after updates to the sokol headers). - **26-May-2022**: The GL backend in sokol_app.h now allows to override the GL @@ -1304,7 +1337,7 @@ so that it's easier to publish new bindings after updates to the sokol headers). (Android, iOS, web). Furthermore, on macOS only the GL versions 3.2 and 4.1 are available (plus the special config major=1 minor=0 creates an NSOpenGLProfileVersionLegacy context). In general: use at your risk :) Many - thanks to Github user @pplux for the PR! + thanks to GitHub user @pplux for the PR! - **15-May-2022**: The way internal memory allocation can be overridden with your own functions has been changed from global macros to callbacks @@ -1542,7 +1575,7 @@ so that it's easier to publish new bindings after updates to the sokol headers). - **19-Dec-2021**: some sokol_audio.h changes: - on Windows, sokol_audio.h no longer converts audio samples from float to int16_t, but instead configures WASAPI to directly accept - float samples. Many thanks to github user iOrange for the PR! + float samples. Many thanks to GitHub user iOrange for the PR! - sokol_audio.h has a new public function ```saudio_suspended()``` which returns true if the audio device/context is currently in suspended mode. On all backends except WebAudio this always returns false. This allows @@ -1,8 +1,10 @@ -# Sokol +<p align="center"> + <img src="assets/logo_full_large.png" style="width: 60%" /><br/><br/>Simple + <a href="https://github.com/nothings/stb/blob/master/docs/stb_howto.txt">STB-style</a> + cross-platform libraries for C and C++, written in C.<br/><br/> +</p> -Simple -[STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt) -cross-platform libraries for C and C++, written in C. +# Sokol [**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**29-Feb-2024**: **BREAKING CHANGES** 'unified render pass' cleanup in sokol_gfx.h) @@ -27,10 +29,16 @@ cleanup in sokol_gfx.h) - A 'single-file' [Pacman clone in C99](https://github.com/floooh/pacman.c/), also available in [Zig](https://github.com/floooh/pacman.zig/) +- [Solar Storm](https://store.steampowered.com/app/2754920/Solar_Storm/), a turn-based scifi artillery game built with Odin and Sokol, released on Steam. + - [MEG-4](https://bztsrc.gitlab.io/meg4) a virtual fantasy console emulator in C89, ported to sokol - A [Minigolf game](https://mgerdes.github.io/minigolf.html) ([source](https://github.com/mgerdes/minigolf)). +- [hIghQube](https://github.com/RuiVarela/hIghQube) A game demo that used sokol rendering extensively + +- [Senos](https://github.com/RuiVarela/Senos) A music app that uses sokol as backend + - ['Dealer's Dungeon'](https://dealers-dungeon.com/demo/) ([lower graphics quality](https://dealers-dungeon.com/demo/?q=3), [source](https://github.com/bqqbarbhg/spear)) diff --git a/assets/logo_full_large.png b/assets/logo_full_large.png Binary files differnew file mode 100644 index 00000000..cd3c48a8 --- /dev/null +++ b/assets/logo_full_large.png diff --git a/assets/logo_full_small.png b/assets/logo_full_small.png Binary files differnew file mode 100644 index 00000000..865b9601 --- /dev/null +++ b/assets/logo_full_small.png diff --git a/assets/logo_s_large.png b/assets/logo_s_large.png Binary files differnew file mode 100644 index 00000000..091229b4 --- /dev/null +++ b/assets/logo_s_large.png diff --git a/assets/logo_s_small.png b/assets/logo_s_small.png Binary files differnew file mode 100644 index 00000000..c5d098c2 --- /dev/null +++ b/assets/logo_s_small.png diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py index 6ba84f3a..dc1a2c37 100644 --- a/bindgen/gen_odin.py +++ b/bindgen/gen_odin.py @@ -8,7 +8,7 @@ import gen_util as util import os, shutil, sys bindings_root = 'sokol-odin' -c_root = f'{bindings_root}/c' +c_root = f'{bindings_root}/sokol/c' module_root = f'{bindings_root}/sokol' module_names = { @@ -337,7 +337,8 @@ def get_system_libs(module, platform, backend): return '' def gen_c_imports(inp, c_prefix, prefix): - clib_prefix = f'sokol_{inp["module"]}' + module_name = inp["module"] + clib_prefix = f'sokol_{module_name}' clib_import = f'{clib_prefix}_clib' windows_d3d11_libs = get_system_libs(prefix, 'windows', 'd3d11') windows_gl_libs = get_system_libs(prefix, 'windows', 'gl') @@ -345,37 +346,56 @@ def gen_c_imports(inp, c_prefix, prefix): macos_gl_libs = get_system_libs(prefix, 'macos', 'gl') linux_gl_libs = get_system_libs(prefix, 'linux', 'gl') l( 'import "core:c"') + l( '') + l( 'SOKOL_DEBUG :: #config(SOKOL_DEBUG, ODIN_DEBUG)') + l( '') + l(f'DEBUG :: #config(SOKOL_{module_name.upper()}_DEBUG, SOKOL_DEBUG)') + l( 'USE_GL :: #config(SOKOL_USE_GL, false)') + l( 'USE_DLL :: #config(SOKOL_DLL, false)') + l( '') l( 'when ODIN_OS == .Windows {') - l( ' when #config(SOKOL_USE_GL,false) {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_release.lib"{windows_gl_libs} }} }}') + l( ' when USE_DLL {') + l( ' when USE_GL {') + l(f' when DEBUG {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_gl_release.lib"{windows_gl_libs} }} }}') + l( ' } else {') + l(f' when DEBUG {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "../sokol_dll_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}') + l( ' }') l( ' } else {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}') + l( ' when USE_GL {') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_debug.lib"{windows_gl_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_gl_release.lib"{windows_gl_libs} }} }}') + l( ' } else {') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_debug.lib"{windows_d3d11_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_windows_x64_d3d11_release.lib"{windows_d3d11_libs} }} }}') + l( ' }') l( ' }') l( '} else when ODIN_OS == .Darwin {') - l( ' when #config(SOKOL_USE_GL,false) {') + l( ' when USE_GL {') l( ' when ODIN_ARCH == .arm64 {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_debug.a"{macos_gl_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_release.a"{macos_gl_libs} }} }}') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_debug.a"{macos_gl_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_gl_release.a"{macos_gl_libs} }} }}') l( ' } else {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_debug.a"{macos_gl_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_release.a"{macos_gl_libs} }} }}') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_debug.a"{macos_gl_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_gl_release.a"{macos_gl_libs} }} }}') l( ' }') l( ' } else {') l( ' when ODIN_ARCH == .arm64 {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_debug.a"{macos_metal_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_release.a"{macos_metal_libs} }} }}') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_debug.a"{macos_metal_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_arm64_metal_release.a"{macos_metal_libs} }} }}') l( ' } else {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_debug.a"{macos_metal_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_release.a"{macos_metal_libs} }} }}') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_debug.a"{macos_metal_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_macos_x64_metal_release.a"{macos_metal_libs} }} }}') l( ' }') l( ' }') + l( '} else when ODIN_OS == .Linux {') + l(f' when DEBUG {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.a"{linux_gl_libs} }} }}') + l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.a"{linux_gl_libs} }} }}') + l( '} else {') + l( ' #panic("This OS is currently not supported")') l( '}') - l( 'else {') - l(f' when ODIN_DEBUG == true {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_debug.a"{linux_gl_libs} }} }}') - l(f' else {{ foreign import {clib_import} {{ "{clib_prefix}_linux_x64_gl_release.a"{linux_gl_libs} }} }}') - l( '}') + l( '') # Need to special case sapp_sg to avoid Odin's context keyword if c_prefix == "sapp_sg": @@ -396,11 +416,13 @@ def gen_c_imports(inp, c_prefix, prefix): else: l(f" {as_snake_case(decl['name'], c_prefix)} :: proc({args}) {res_str} ---") l('}') + l('') def gen_consts(decl, prefix): for item in decl['items']: item_name = check_override(item['name']) l(f"{as_snake_case(item_name, prefix)} :: {item['value']}") + l('') def gen_struct(decl, prefix): c_struct_name = check_override(decl['name']) @@ -415,18 +437,20 @@ def gen_struct(decl, prefix): else: l(f' {field_name} : {field_type},') l('}') + l('') def gen_enum(decl, prefix): enum_name = check_override(decl['name']) l(f'{as_struct_or_enum_type(enum_name, prefix)} :: enum i32 {{') for item in decl['items']: item_name = as_enum_item_name(check_override(item['name'])) - if item_name != 'FORCE_U32': + if item_name != 'FORCE_U32' and item_name != 'NUM': if 'value' in item: l(f" {item_name} = {item['value']},") else: l(f" {item_name},") l('}') + l('') def gen_imports(dep_prefixes): for dep_prefix in dep_prefixes: @@ -479,10 +503,10 @@ def pre_parse(inp): def prepare(): print('=== Generating Odin bindings:') - if not os.path.isdir(c_root): - os.makedirs(c_root) if not os.path.isdir(module_root): os.makedirs(module_root) + if not os.path.isdir(c_root): + os.makedirs(c_root) def gen(c_header_path, c_prefix, dep_c_prefixes): if not c_prefix in module_names: diff --git a/bindgen/gen_rust.py b/bindgen/gen_rust.py index 0984d14a..59a2b672 100644 --- a/bindgen/gen_rust.py +++ b/bindgen/gen_rust.py @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------------- -# Generate rust bindings. +# Generate Rust bindings. # -# rust coding style: +# Rust coding style: # - types are PascalCase # - otherwise snake_case # ------------------------------------------------------------------------------- @@ -50,7 +50,7 @@ ignores = [ range_struct_name = "Range" -# functions that need to be exposed as 'raw' C callbacks without a rust wrapper function +# functions that need to be exposed as 'raw' C callbacks without a Rust wrapper function c_callbacks = ["slog_func"] # NOTE: syntax for function results: "func_name.RESULT" @@ -753,7 +753,7 @@ def gen_imports(inp, dep_prefixes): def gen_helpers(inp): - l("/// Helper function to convert a C string to a rust string slice") + l("/// Helper function to convert a C string to a Rust string slice") l("#[inline]") l("fn c_char_ptr_to_rust_str(c_char_ptr: *const core::ffi::c_char) -> &'static str {") l(" let c_str = unsafe { core::ffi::CStr::from_ptr(c_char_ptr) };") @@ -762,11 +762,11 @@ def gen_helpers(inp): l("") if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_', 'sapp_']: - l("/// Helper function to cast a rust slice into a sokol Range") + l("/// Helper function to cast a Rust slice into a sokol Range") l(f"pub fn slice_as_range<T>(data: &[T]) -> {range_struct_name} {{") l(f" {range_struct_name} {{ size: std::mem::size_of_val(data), ptr: data.as_ptr() as *const _ }}") l("}") - l("/// Helper function to cast a rust reference into a sokol Range") + l("/// Helper function to cast a Rust reference into a sokol Range") l(f"pub fn value_as_range<T>(value: &T) -> {range_struct_name} {{") l(f" {range_struct_name} {{ size: std::mem::size_of::<T>(), ptr: value as *const T as *const _ }}") l("}") diff --git a/sokol_app.h b/sokol_app.h index c59a47cc..649796c0 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -353,7 +353,7 @@ sapp_consume_event() from inside the event handler (NOTE that this behaviour is currently only implemented for some HTML5 events, support for other platforms and event types will - be added as needed, please open a github ticket and/or provide + be added as needed, please open a GitHub ticket and/or provide a PR if needed). NOTE: Do *not* call any 3D API rendering functions in the event diff --git a/sokol_gfx.h b/sokol_gfx.h index 14928034..45612990 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -141,7 +141,7 @@ object handle is required instead of an sg_swapchain struct. An offscreen pass is started like this (assuming attachments is an sg_attachments handle): - sg_begin_pass(&(sg_pass){ .action = { ... }, .attachments = attachemnts }); + sg_begin_pass(&(sg_pass){ .action = { ... }, .attachments = attachments }); --- set the render pipeline state for the next draw call with: @@ -1854,7 +1854,7 @@ typedef enum sg_image_type { is compatible with what the shader expects. Apart from the sokol-gfx validation layer, WebGPU is the only backend API which actually requires matching texture and sampler type to be provided upfront for validation - (after 3D APIs treat texture/sampler type mismatches as undefined behaviour). + (other 3D APIs treat texture/sampler type mismatches as undefined behaviour). NOTE that the following texture pixel formats require the use of SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT, combined with a sampler @@ -2435,7 +2435,7 @@ typedef struct sg_pass_action { as 'type erased' void pointers: GL: on all GL backends, a GL framebuffer object must be provided. This - can be zero for the defaul framebuffer. + can be zero for the default framebuffer. D3D11: - an ID3D11RenderTargetView for the rendering surface, without @@ -3587,7 +3587,7 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_ATTACHMENTSDESC_DEPTH_IMAGE_SAMPLE_COUNT, "pass depth attachment sample count must match color attachment sample count") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_CANARY, "sg_begin_pass: pass struct not initialized") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_EXISTS, "sg_begin_pass: attachments object no longer alive") \ - _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_VALID, "sg_begin_pass: attachemnts object not in resource state VALID") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_VALID, "sg_begin_pass: attachments object not in resource state VALID") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLOR_ATTACHMENT_IMAGE, "sg_begin_pass: one or more color attachment images are not valid") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVE_ATTACHMENT_IMAGE, "sg_begin_pass: one or more resolve attachment images are not valid") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCIL_ATTACHMENT_IMAGE, "sg_begin_pass: one or more depth-stencil attachment images are not valid") \ @@ -4201,7 +4201,7 @@ inline sg_image sg_make_image(const sg_image_desc& desc) { return sg_make_image( inline sg_sampler sg_make_sampler(const sg_sampler_desc& desc) { return sg_make_sampler(&desc); } inline sg_shader sg_make_shader(const sg_shader_desc& desc) { return sg_make_shader(&desc); } inline sg_pipeline sg_make_pipeline(const sg_pipeline_desc& desc) { return sg_make_pipeline(&desc); } -inline sg_attachments sg_make_attchments(const sg_attachments_desc& desc) { return sg_make_attachments(&desc); } +inline sg_attachments sg_make_attachments(const sg_attachments_desc& desc) { return sg_make_attachments(&desc); } inline void sg_update_image(sg_image img, const sg_image_data& data) { return sg_update_image(img, &data); } inline void sg_begin_pass(const sg_pass& pass) { return sg_begin_pass(&pass); } @@ -4797,7 +4797,7 @@ _SOKOL_PRIVATE int _sg_slot_index(uint32_t id); // constants enum { - _SG_STRING_SIZE = 16, + _SG_STRING_SIZE = 32, _SG_SLOT_SHIFT = 16, _SG_SLOT_MASK = (1<<_SG_SLOT_SHIFT)-1, _SG_MAX_POOL_SIZE = (1<<_SG_SLOT_SHIFT), @@ -9394,6 +9394,29 @@ _SOKOL_PRIVATE void _sg_gl_update_image(_sg_image_t* img, const sg_image_data* d #define _sg_d3d11_Release(self) (self)->lpVtbl->Release(self) #endif +// NOTE: This needs to be a macro since we can't use the polymorphism in C. It's called on many kinds of resources. +// NOTE: Based on microsoft docs, it's fine to call this with pData=NULL if DataSize is also zero. +#if defined(__cplusplus) +#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->SetPrivateData(guid, DataSize, pData) +#else +#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->lpVtbl->SetPrivateData(self, guid, DataSize, pData) +#endif + +#if defined(__cplusplus) +#define _sg_win32_refguid(guid) guid +#else +#define _sg_win32_refguid(guid) &guid +#endif + +static const GUID _sg_d3d11_WKPDID_D3DDebugObjectName = { 0x429b8c22,0x9188,0x4b0c, {0x87,0x42,0xac,0xb0,0xbf,0x85,0xc2,0x00} }; + +#if defined(SOKOL_DEBUG) +#define _sg_d3d11_setlabel(self, label) _sg_d3d11_SetPrivateData(self, _sg_win32_refguid(_sg_d3d11_WKPDID_D3DDebugObjectName), label ? (UINT)strlen(label) : 0, label) +#else +#define _sg_d3d11_setlabel(self, label) +#endif + + //-- D3D11 C/C++ wrappers ------------------------------------------------------ static inline HRESULT _sg_d3d11_CheckFormatSupport(ID3D11Device* self, DXGI_FORMAT Format, UINT* pFormatSupport) { #if defined(__cplusplus) @@ -10213,6 +10236,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_buffer(_sg_buffer_t* buf, cons return SG_RESOURCESTATE_FAILED; } } + _sg_d3d11_setlabel(buf->d3d11.buf, desc->label); } return SG_RESOURCESTATE_VALID; } @@ -10322,6 +10346,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const _SG_ERROR(D3D11_CREATE_2D_TEXTURE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(img->d3d11.tex2d, desc->label); // create shader-resource-view for 2D texture // FIXME: currently we don't support setting MSAA texture as shader resource @@ -10351,6 +10376,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const _SG_ERROR(D3D11_CREATE_2D_SRV_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(img->d3d11.srv, desc->label); } } SOKOL_ASSERT(img->d3d11.tex2d); @@ -10392,6 +10418,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const _SG_ERROR(D3D11_CREATE_3D_TEXTURE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(img->d3d11.tex3d, desc->label); // create shader-resource-view for 3D texture if (!msaa) { @@ -10405,6 +10432,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const _SG_ERROR(D3D11_CREATE_3D_SRV_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(img->d3d11.srv, desc->label); } } SOKOL_ASSERT(img->d3d11.tex3d); @@ -10468,6 +10496,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_sampler(_sg_sampler_t* smp, co _SG_ERROR(D3D11_CREATE_SAMPLER_STATE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(smp->d3d11.smp, desc->label); } return SG_RESOURCESTATE_VALID; } @@ -10562,6 +10591,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_shader(_sg_shader_t* shd, cons _SG_ERROR(D3D11_CREATE_CONSTANT_BUFFER_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(d3d11_stage->cbufs[ub_index], desc->label); } } @@ -10600,6 +10630,8 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_shader(_sg_shader_t* shd, cons SOKOL_ASSERT(shd->d3d11.vs_blob); memcpy(shd->d3d11.vs_blob, vs_ptr, vs_length); result = SG_RESOURCESTATE_VALID; + _sg_d3d11_setlabel(shd->d3d11.vs, desc->label); + _sg_d3d11_setlabel(shd->d3d11.fs, desc->label); } } if (vs_blob) { @@ -10693,6 +10725,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, return SG_RESOURCESTATE_FAILED; } } + _sg_d3d11_setlabel(pip->d3d11.il, desc->label); // create rasterizer state D3D11_RASTERIZER_DESC rs_desc; @@ -10712,6 +10745,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, _SG_ERROR(D3D11_CREATE_RASTERIZER_STATE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(pip->d3d11.rs, desc->label); // create depth-stencil state D3D11_DEPTH_STENCIL_DESC dss_desc; @@ -10737,6 +10771,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, _SG_ERROR(D3D11_CREATE_DEPTH_STENCIL_STATE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(pip->d3d11.dss, desc->label); // create blend state D3D11_BLEND_DESC bs_desc; @@ -10771,6 +10806,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip, _SG_ERROR(D3D11_CREATE_BLEND_STATE_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(pip->d3d11.bs, desc->label); return SG_RESOURCESTATE_VALID; } @@ -10866,6 +10902,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_attachments(_sg_attachments_t* _SG_ERROR(D3D11_CREATE_RTV_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(atts->d3d11.colors[i].view.rtv, desc->label); } SOKOL_ASSERT(0 == atts->d3d11.depth_stencil.view.dsv); if (ds_desc->image.id != SG_INVALID_ID) { @@ -10900,6 +10937,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_attachments(_sg_attachments_t* _SG_ERROR(D3D11_CREATE_DSV_FAILED); return SG_RESOURCESTATE_FAILED; } + _sg_d3d11_setlabel(atts->d3d11.depth_stencil.view.dsv, desc->label); } return SG_RESOURCESTATE_VALID; } @@ -10982,7 +11020,7 @@ _SOKOL_PRIVATE void _sg_d3d11_begin_pass(const sg_pass* pass) { // perform clear action for (int i = 0; i < num_rtvs; i++) { if (action->colors[i].load_action == SG_LOADACTION_CLEAR) { - _sg_d3d11_ClearRenderTargetView(_sg.d3d11.ctx, rtvs[i], &action->colors[i].clear_value.r); + _sg_d3d11_ClearRenderTargetView(_sg.d3d11.ctx, rtvs[i], (float*)&action->colors[i].clear_value); _sg_stats_add(d3d11.pass.num_clear_render_target_view, 1); } } @@ -11099,7 +11137,7 @@ _SOKOL_PRIVATE void _sg_d3d11_apply_pipeline(_sg_pipeline_t* pip) { _sg_d3d11_RSSetState(_sg.d3d11.ctx, pip->d3d11.rs); _sg_d3d11_OMSetDepthStencilState(_sg.d3d11.ctx, pip->d3d11.dss, pip->d3d11.stencil_ref); - _sg_d3d11_OMSetBlendState(_sg.d3d11.ctx, pip->d3d11.bs, &pip->cmn.blend_color.r, 0xFFFFFFFF); + _sg_d3d11_OMSetBlendState(_sg.d3d11.ctx, pip->d3d11.bs, (float*)&pip->cmn.blend_color, 0xFFFFFFFF); _sg_d3d11_IASetPrimitiveTopology(_sg.d3d11.ctx, pip->d3d11.topology); _sg_d3d11_IASetInputLayout(_sg.d3d11.ctx, pip->d3d11.il); _sg_d3d11_VSSetShader(_sg.d3d11.ctx, pip->shader->d3d11.vs, NULL, 0); diff --git a/sokol_glue.h b/sokol_glue.h index 901eb65a..c0294952 100644 --- a/sokol_glue.h +++ b/sokol_glue.h @@ -43,7 +43,7 @@ functions. Use this in the sg_setup() call like this: sg_setup(&(sg_desc){ - .environment = sglue_enviornment(), + .environment = sglue_environment(), ... }); diff --git a/tests/ext/CMakeLists.txt b/tests/ext/CMakeLists.txt index 4ded7c41..6fa78cbd 100644 --- a/tests/ext/CMakeLists.txt +++ b/tests/ext/CMakeLists.txt @@ -14,7 +14,7 @@ if (IS_DIRECTORY ${spineruntimes_dir}) message("### ${spineruntimes_dir} exists...") else() message("### Fetching spine runtimes to ${spineruntimes_dir} (this may take a while...)") - execute_process(COMMAND git clone --depth=1 --recursive https://github.com/EsotericSoftware/spine-runtimes ${spineruntimes_dir}) + execute_process(COMMAND git clone --depth=1 --branch 4.1 --recursive https://github.com/EsotericSoftware/spine-runtimes ${spineruntimes_dir}) endif() add_library(cimgui diff --git a/util/sokol_debugtext.h b/util/sokol_debugtext.h index 7cc3fd5b..12ca7a64 100644 --- a/util/sokol_debugtext.h +++ b/util/sokol_debugtext.h @@ -3855,8 +3855,8 @@ static void _sdtx_init_context(sdtx_context ctx_id, const sdtx_context_desc_t* i pip_desc.colors[0].blend.enabled = true; pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA; pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; - pip_desc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ZERO; - pip_desc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE; + pip_desc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; + pip_desc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ZERO; pip_desc.label = "sdtx-pipeline"; ctx->pip = sg_make_pipeline(&pip_desc); SOKOL_ASSERT(SG_INVALID_ID != ctx->pip.id); diff --git a/util/sokol_gfx_imgui.h b/util/sokol_gfx_imgui.h index b13ce211..217f74f1 100644 --- a/util/sokol_gfx_imgui.h +++ b/util/sokol_gfx_imgui.h @@ -2156,7 +2156,7 @@ _SOKOL_PRIVATE sgimgui_str_t _sgimgui_capture_item_string(sgimgui_t* ctx, int in case SGIMGUI_CMD_UNINIT_ATTACHMENTS: { sgimgui_str_t res_id = _sgimgui_attachments_id_string(ctx, item->args.uninit_attachments.attachments); - _sgimgui_snprintf(&str, "%d: sg_uninit_attachemnts(atts=%s)", index, res_id.buf); + _sgimgui_snprintf(&str, "%d: sg_uninit_attachments(atts=%s)", index, res_id.buf); } break; diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h index e533ad34..810890c0 100644 --- a/util/sokol_imgui.h +++ b/util/sokol_imgui.h @@ -2385,6 +2385,9 @@ SOKOL_API_IMPL void simgui_setup(const simgui_desc_t* desc) { SOKOL_API_IMPL void simgui_create_fonts_texture(const simgui_font_tex_desc_t* desc) { SOKOL_ASSERT(desc); + SOKOL_ASSERT(SG_INVALID_ID == _simgui.font_smp.id); + SOKOL_ASSERT(SG_INVALID_ID == _simgui.font_img.id); + SOKOL_ASSERT(SIMGUI_INVALID_ID == _simgui.default_font.id); #if defined(__cplusplus) ImGuiIO* io = &ImGui::GetIO(); @@ -2434,6 +2437,9 @@ SOKOL_API_IMPL void simgui_destroy_fonts_texture(void) { sg_destroy_sampler(_simgui.font_smp); sg_destroy_image(_simgui.font_img); simgui_destroy_image(_simgui.default_font); + _simgui.font_smp.id = SG_INVALID_ID; + _simgui.font_img.id = SG_INVALID_ID; + _simgui.default_font.id = SIMGUI_INVALID_ID; } SOKOL_API_IMPL void simgui_shutdown(void) { @@ -2519,6 +2525,12 @@ SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) { #else ImGuiIO* io = igGetIO(); #endif + if (!io->Fonts->TexReady) { + simgui_destroy_fonts_texture(); + simgui_font_tex_desc_t simgui_font_smp_desc; + _simgui_clear(&simgui_font_smp_desc, sizeof(simgui_font_smp_desc)); + simgui_create_fonts_texture(&simgui_font_smp_desc); + } io->DisplaySize.x = ((float)desc->width) / _simgui.cur_dpi_scale; io->DisplaySize.y = ((float)desc->height) / _simgui.cur_dpi_scale; io->DeltaTime = (float)desc->delta_time; |