Skip to content

Commit

Permalink
Merge branch 'master' into storage-buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Apr 21, 2024
2 parents 7e1035c + 4534e02 commit 4fac1bb
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 63 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/gen_bindings.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down
49 changes: 41 additions & 8 deletions 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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions README.md
@@ -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)
Expand All @@ -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))

Expand Down
Binary file added assets/logo_full_large.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_full_small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_s_large.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_s_small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 47 additions & 23 deletions bindgen/gen_odin.py
Expand Up @@ -8,7 +8,7 @@
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 = {
Expand Down Expand Up @@ -337,45 +337,65 @@ 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')
macos_metal_libs = get_system_libs(prefix, 'macos', 'metal')
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":
Expand All @@ -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'])
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4fac1bb

Please sign in to comment.