Skip to content

Commit

Permalink
Merge remote-tracking branch 'floooh/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miscvariables committed Feb 11, 2021
2 parents 8ba9630 + 29bbcd8 commit f7c1558
Show file tree
Hide file tree
Showing 18 changed files with 2,008 additions and 1,618 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

> NOTE: this list will usually only be updated with changes that affect the public APIs
- **10-Feb-2021**: The breaking API-update has been merged (mainly sokol_gfx.h).
Please see [this blogpost](https://floooh.github.io/2021/02/07/sokol-api-overhaul.html)
and the updates [sokol samples](https://floooh.github.io/sokol-html5/) for details.
I also created a git tag named 'pre-feb2021-api-changes' which captures the previous
state in all related projects. Please also update the [sokol-tools-bin](https://github.com/floooh/sokol-tools-bin) if you're using the sokol-shdc shader compiler.

- **07-Feb-2021**: A PSA about upcoming breaking changes in (mainly) sokol_gfx.h: https://floooh.github.io/2021/02/07/sokol-api-overhaul.html

- **20-Dec-2020**: A couple of minor breaking changes in the sokol_gfx.h and
sokol_app.h APIs as preparation for the upcoming automatic language binding
generation:
Expand Down
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Simple
[STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)
cross-platform libraries for C and C++, written in C.

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**20-Dec-2020**: minor but breaking API changes in sokol_gfx.h/sokol_app.h)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**10-Feb-2021**: big API-breaking update, see the changelog for details)

## Examples and Related Projects

Expand Down Expand Up @@ -86,7 +86,7 @@ int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* w = glfwCreateWindow(640, 480, "Sokol Triangle GLFW", 0, 0);
glfwMakeContextCurrent(w);
Expand All @@ -104,8 +104,7 @@ int main() {
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f
};
sg_buffer vbuf = sg_make_buffer(&(sg_buffer_desc){
.size = sizeof(vertices),
.content = vertices,
.data = SG_RANGE(vertices)
});

/* a shader */
Expand Down Expand Up @@ -140,7 +139,7 @@ int main() {
});

/* resource bindings */
sg_bindings binds = {
sg_bindings bind = {
.vertex_buffers[0] = vbuf
};

Expand All @@ -153,7 +152,7 @@ int main() {
glfwGetFramebufferSize(w, &cur_width, &cur_height);
sg_begin_default_pass(&pass_action, cur_width, cur_height);
sg_apply_pipeline(pip);
sg_apply_bindings(&binds);
sg_apply_bindings(&bind);
sg_draw(0, 3, 1);
sg_end_pass();
sg_commit();
Expand Down Expand Up @@ -183,9 +182,9 @@ A simple clear-loop sample using sokol_app.h and sokol_gfx.h (does not include
separate sokol.c/.m implementation file which is necessary
to split the Objective-C code from the C code of the sample):

```cpp
#include "sokol_app.h"
```c
#include "sokol_gfx.h"
#include "sokol_app.h"
#include "sokol_glue.h"

sg_pass_action pass_action;
Expand All @@ -195,13 +194,13 @@ void init(void) {
.context = sapp_sgcontext()
});
pass_action = (sg_pass_action) {
.colors[0] = { .action=SG_ACTION_CLEAR, .val={1.0f, 0.0f, 0.0f, 1.0f} }
.colors[0] = { .action=SG_ACTION_CLEAR, .value={1.0f, 0.0f, 0.0f, 1.0f} }
};
}

void frame(void) {
float g = pass_action.colors[0].val[1] + 0.01f;
pass_action.colors[0].val[1] = (g > 1.0f) ? 0.0f : g;
float g = pass_action.colors[0].value.g + 0.01f;
pass_action.colors[0].value.g = (g > 1.0f) ? 0.0f : g;
sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
sg_end_pass();
sg_commit();
Expand All @@ -218,7 +217,7 @@ sapp_desc sokol_main(int argc, char* argv[]) {
.cleanup_cb = cleanup,
.width = 400,
.height = 300,
.window_title = "Clear (sokol app)",
.window_title = "Clear Sample",
};
}
```
Expand All @@ -240,7 +239,7 @@ A minimal audio-streaming API:
A simple mono square-wave generator using the callback model:
```cpp
```c
// the sample callback, running in audio thread
static void stream_cb(float* buffer, int num_frames, int num_channels) {
assert(1 == num_channels);
Expand All @@ -266,7 +265,7 @@ int main() {

The same code using the push-model

```cpp
```c
#define BUF_SIZE (32)
int main() {
// init sokol-audio with default params, no callback
Expand Down
22 changes: 11 additions & 11 deletions bindgen/gen_all.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import gen_ir, gen_zig
import os, gen_zig

tasks = [
[ '../sokol_gfx.h', 'sg_', 'gfx' ],
[ '../sokol_app.h', 'sapp_', 'app' ],
[ '../sokol_time.h', 'stm_', 'time' ],
[ '../sokol_audio.h', 'saudio_', 'audio' ]
[ '../sokol_gfx.h', 'sg_', [] ],
[ '../sokol_app.h', 'sapp_', [] ],
[ '../sokol_time.h', 'stm_', [] ],
[ '../sokol_audio.h', 'saudio_', [] ],
[ '../util/sokol_gl.h', 'sgl_', ['sg_'] ],
[ '../util/sokol_debugtext.h', 'sdtx_', ['sg_'] ],
[ '../util/sokol_shape.h', 'sshape_', ['sg_'] ],
]

# Zig
print('> generating Zig bindings...')
gen_zig.prepare()
for task in tasks:
c_header_path = task[0]
c_prefix = task[1]
module_name = task[2]
print(f' {c_header_path} => {module_name}.zig')
ir = gen_ir.gen(c_header_path, module_name, c_prefix, ["-DSOKOL_ZIG_BINDINGS"])
gen_zig.gen(c_header_path, ir)
main_prefix = task[1]
dep_prefixes = task[2]
gen_zig.gen(c_header_path, main_prefix, dep_prefixes)
34 changes: 25 additions & 9 deletions bindgen/gen_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ def is_api_decl(decl, prefix):
else:
return False

def is_dep_decl(decl, dep_prefixes):
for prefix in dep_prefixes:
if is_api_decl(decl, prefix):
return True
return False

def dep_prefix(decl, dep_prefixes):
for prefix in dep_prefixes:
if is_api_decl(decl, prefix):
return prefix
return None

def filter_types(str):
return str.replace('_Bool', 'bool')

Expand Down Expand Up @@ -67,7 +79,8 @@ def parse_func(decl):
if 'inner' in decl:
for param in decl['inner']:
if param['kind'] != 'ParmVarDecl':
sys.exit(f"ERROR: func param kind must be 'ParmVarDecl' ({decl['name']})")
print(f"warning: ignoring func {decl['name']} (unsupported parameter type)")
return None
outp_param = {}
outp_param['name'] = param['name']
outp_param['type'] = filter_types(param['type']['qualType'])
Expand All @@ -85,22 +98,25 @@ def parse_decl(decl):
else:
return None

def clang(header_path, additional_options):
cmd = ['clang', '-Xclang', '-ast-dump=json' ]
cmd.extend(additional_options)
cmd.append(header_path)
def clang(csrc_path):
cmd = ['clang', '-Xclang', '-ast-dump=json', '-c' ]
cmd.append(csrc_path)
return subprocess.check_output(cmd)

def gen(header_path, module, prefix, clang_options):
ast = clang(header_path, clang_options)
def gen(header_path, source_path, module, main_prefix, dep_prefixes):
ast = clang(source_path)
inp = json.loads(ast)
outp = {}
outp['module'] = module
outp['prefix'] = prefix
outp['prefix'] = main_prefix
outp['dep_prefixes'] = dep_prefixes
outp['decls'] = []
for decl in inp['inner']:
if is_api_decl(decl, prefix):
is_dep = is_dep_decl(decl, dep_prefixes)
if is_api_decl(decl, main_prefix) or is_dep:
outp_decl = parse_decl(decl)
if outp_decl is not None:
outp_decl['is_dep'] = is_dep
outp_decl['dep_prefix'] = dep_prefix(decl, dep_prefixes)
outp['decls'].append(outp_decl)
return outp
Loading

0 comments on commit f7c1558

Please sign in to comment.