Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into some_limits_override
Browse files Browse the repository at this point in the history
  • Loading branch information
allcreater committed Jan 24, 2023
2 parents f81d63b + f1e1bba commit eda6ecb
Show file tree
Hide file tree
Showing 11 changed files with 705 additions and 287 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
## Updates

- **23-Jan-2023**: A couple more sokol_audio.h updates:
- an AAudio backend has been added for Android, and made the default. This
means you now need to link with ```aaudio``` instead of ```OpenSLES``` when
using sokol_audio.h on Android. The OpenSLES backend code still exists (for
now), but must be explicitly selected by compiling the sokol_audio.h
implementation with the define ```SAUDIO_ANDROID_SLES``` (e.g. there is
no runtime fallback from AAudio to OpenSLES). AAudio is fully supported
since Android 8.1. Many thanks to @oviano for the initial AAudio PR
(https://github.com/floooh/sokol/pull/484)
- in the WebAudio backend, WebAudio is now properly activated on the first
input action again on Chrome for Android (at some point activating WebAudio
via a ```touchstart``` event stopped working and had to be moved to the
```touchend``` event, see https://github.com/floooh/sokol/issues/701)
- audio backend initialization on iOS and macOS is now a bit more fault-tolerant,
errors during initialization now properly set sokol_audio.h to 'silent mode'
instead of asserting (or in release mode ignoring the error)
- ...and some minor general code cleanup things in sokol_audio.h: backend-specific
functions now generally have a matching prefix (like ```_saudio_alsa_...()```)
for better searchability

- **16-Jan-2023**:
- sokol_audio.h android: https://github.com/floooh/sokol/pull/747 has been merged
which adds a couple more error checks at OpenSLES startup.
- sokol_gfx.h: support for half-float vertex formats has been added via
PR https://github.com/floooh/sokol/pull/745
- sokol_imgui.h: fixes for Dear ImGui 1.89 deprecations (via PR https://github.com/floooh/sokol/pull/761)

- **15-Jan-2023**: two bugfixes in sokol_app.h and sokol_gfx.h:
- sokol_app.h x11: Mouse button events now always return valid mouse
coordinates, also when no mouse movement happened yet
(fixes https://github.com/floooh/sokol/issues/770)
- sokol_gfx.h gl: The GL context is now configured with
GL_UNPACK_ALIGNMENT = 1, this should bring texture creation and updating
behaviour in line with the other backends for tightly packed texture
data that doesn't have a row-pitch with a multiple of 4
(fixes https://github.com/floooh/sokol/issues/767)

- **14-Jan-2023**: sokol_app.h x11: a drag'n'drop related bugfix, the
XdndFinished reply event was sent with the wrong window handle which
confused some apps where the drag operation originated
(see https://github.com/floooh/sokol/pull/765#issuecomment-1382750611)

- **16-Dec-2022**: In the sokol_gfx.h Metal backend: A fix for a Metal
validation layer error which I just discovered yesterday (seems to be new in
macOS 13). When the validation layer is active, and the application window
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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) (**16-Dec-2022** sokol_gfx.h metal: a lifetime management fix for swapchain resources, **15-Dec-2022** sokol_imgui.h: fix touch input on mobile devices)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**23-Jan-2023** sokol_audio.h: new AAudio backend for Android, activation fix for WebAudio on Chrome for Android.

[![Build](/../../actions/workflows/main.yml/badge.svg)](/../../actions/workflows/main.yml) [![Bindings](/../../actions/workflows/gen_bindings.yml/badge.svg)](/../../actions/workflows/gen_bindings.yml) [![build](https://github.com/floooh/sokol-zig/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-zig/actions/workflows/main.yml) [![build](https://github.com/floooh/sokol-nim/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-nim/actions/workflows/main.yml) [![Odin](https://github.com/floooh/sokol-odin/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-odin/actions/workflows/main.yml)

Expand Down
8 changes: 2 additions & 6 deletions bindgen/gen_zig.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def gen_struct(decl, prefix):
elif is_const_prim_ptr(field_type):
l(f" {field_name}: ?[*]const {as_zig_prim_type(util.extract_ptr_type(field_type))} = null,")
elif util.is_func_ptr(field_type):
l(f" {field_name}: ?meta.FnPtr(fn({funcptr_args_c(field_type, prefix)}) callconv(.C) {funcptr_result_c(field_type)}) = null,")
l(f" {field_name}: ?*const fn({funcptr_args_c(field_type, prefix)}) callconv(.C) {funcptr_result_c(field_type)} = null,")
elif util.is_1d_array_type(field_type):
array_type = util.extract_array_type(field_type)
array_sizes = util.extract_array_sizes(field_type)
Expand Down Expand Up @@ -433,7 +433,6 @@ def pre_parse(inp):

def gen_imports(inp, dep_prefixes):
l('const builtin = @import("builtin");')
l('const meta = @import("std").meta;')
for dep_prefix in dep_prefixes:
dep_module_name = module_names[dep_prefix]
l(f'const {dep_prefix[:-1]} = @import("{dep_module_name}.zig");')
Expand All @@ -457,10 +456,7 @@ def gen_helpers(inp):
l(' }')
l(' },')
l(' .Struct, .Array => {')
l(' switch (builtin.zig_backend) {')
l(' .stage1 => return .{ .ptr = &val, .size = @sizeOf(@TypeOf(val)) },')
l(' else => @compileError("Structs and arrays must be passed as pointers to asRange"),')
l(' }')
l(' @compileError("Structs and arrays must be passed as pointers to asRange");')
l(' },')
l(' else => {')
l(' @compileError("Cannot convert to range!");')
Expand Down
96 changes: 60 additions & 36 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3505,13 +3505,13 @@ _SOKOL_PRIVATE void _sapp_macos_update_window_title(void) {
[_sapp.macos.window setTitle: [NSString stringWithUTF8String:_sapp.window_title]];
}

_SOKOL_PRIVATE void _sapp_macos_update_mouse(NSEvent* event) {
_SOKOL_PRIVATE void _sapp_macos_mouse_update(NSEvent* event) {
if (!_sapp.mouse.locked) {
const NSPoint mouse_pos = event.locationInWindow;
float new_x = mouse_pos.x * _sapp.dpi_scale;
float new_y = _sapp.framebuffer_height - (mouse_pos.y * _sapp.dpi_scale) - 1;
/* don't update dx/dy in the very first update */
if (_sapp.mouse.pos_valid) {
// don't update dx/dy in the very first update
_sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y;
}
Expand Down Expand Up @@ -3975,7 +3975,7 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
[super updateTrackingAreas];
}
- (void)mouseEntered:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
/* don't send mouse enter/leave while dragging (so that it behaves the same as
on Windows while SetCapture is active
*/
Expand All @@ -3984,47 +3984,47 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
}
}
- (void)mouseExited:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (0 == _sapp.macos.mouse_buttons) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event));
}
}
- (void)mouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_LEFT);
}
- (void)mouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_LEFT);
}
- (void)rightMouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_RIGHT);
}
- (void)rightMouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_RIGHT);
}
- (void)otherMouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_MIDDLE);
}
}
- (void)otherMouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mods(event));
_sapp.macos.mouse_buttons &= (1<<SAPP_MOUSEBUTTON_MIDDLE);
}
}
- (void)otherMouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (2 == event.buttonNumber) {
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
Expand All @@ -4034,31 +4034,31 @@ _SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
}
}
- (void)mouseMoved:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event));
}
- (void)mouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mods(event));
}
- (void)rightMouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mods(event));
}
- (void)scrollWheel:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_update(event);
if (_sapp_events_enabled()) {
float dx = (float) event.scrollingDeltaX;
float dy = (float) event.scrollingDeltaY;
Expand Down Expand Up @@ -6807,6 +6807,21 @@ _SOKOL_PRIVATE uint32_t _sapp_win32_mods(void) {
return mods;
}

_SOKOL_PRIVATE void _sapp_win32_mouse_update(LPARAM lParam) {
if (!_sapp.mouse.locked) {
const float new_x = (float)GET_X_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale;
const float new_y = (float)GET_Y_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale;
if (_sapp.mouse.pos_valid) {
// don't update dx/dy in the very first event
_sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y;
}
_sapp.mouse.x = new_x;
_sapp.mouse.y = new_y;
_sapp.mouse.pos_valid = true;
}
}

_SOKOL_PRIVATE void _sapp_win32_mouse_event(sapp_event_type type, sapp_mousebutton btn) {
if (_sapp_events_enabled()) {
_sapp_init_event(type);
Expand Down Expand Up @@ -7017,41 +7032,38 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM
break;
}
case WM_LBUTTONDOWN:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT);
_sapp_win32_capture_mouse(1<<SAPP_MOUSEBUTTON_LEFT);
break;
case WM_RBUTTONDOWN:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_RIGHT);
_sapp_win32_capture_mouse(1<<SAPP_MOUSEBUTTON_RIGHT);
break;
case WM_MBUTTONDOWN:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_MIDDLE);
_sapp_win32_capture_mouse(1<<SAPP_MOUSEBUTTON_MIDDLE);
break;
case WM_LBUTTONUP:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_LEFT);
_sapp_win32_release_mouse(1<<SAPP_MOUSEBUTTON_LEFT);
break;
case WM_RBUTTONUP:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_RIGHT);
_sapp_win32_release_mouse(1<<SAPP_MOUSEBUTTON_RIGHT);
break;
case WM_MBUTTONUP:
_sapp_win32_mouse_update(lParam);
_sapp_win32_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_MIDDLE);
_sapp_win32_release_mouse(1<<SAPP_MOUSEBUTTON_MIDDLE);
break;
case WM_MOUSEMOVE:
if (!_sapp.mouse.locked) {
const float new_x = (float)GET_X_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale;
const float new_y = (float)GET_Y_LPARAM(lParam) * _sapp.win32.dpi.mouse_scale;
/* don't update dx/dy in the very first event */
if (_sapp.mouse.pos_valid) {
_sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y;
}
_sapp.mouse.x = new_x;
_sapp.mouse.y = new_y;
_sapp.mouse.pos_valid = true;
_sapp_win32_mouse_update(lParam);
if (!_sapp.win32.mouse_tracked) {
_sapp.win32.mouse_tracked = true;
TRACKMOUSEEVENT tme;
Expand Down Expand Up @@ -7108,9 +7120,11 @@ _SOKOL_PRIVATE LRESULT CALLBACK _sapp_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM
}
break;
case WM_MOUSEWHEEL:
_sapp_win32_mouse_update(lParam);
_sapp_win32_scroll_event(0.0f, (float)((SHORT)HIWORD(wParam)));
break;
case WM_MOUSEHWHEEL:
_sapp_win32_mouse_update(lParam);
_sapp_win32_scroll_event((float)((SHORT)HIWORD(wParam)), 0.0f);
break;
case WM_CHAR:
Expand Down Expand Up @@ -10995,6 +11009,20 @@ _SOKOL_PRIVATE sapp_mousebutton _sapp_x11_translate_button(const XEvent* event)
}
}

_SOKOL_PRIVATE void _sapp_x11_mouse_update(int x, int y) {
if (!_sapp.mouse.locked) {
const float new_x = (float) x;
const float new_y = (float) y;
if (_sapp.mouse.pos_valid) {
_sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y;
}
_sapp.mouse.x = new_x;
_sapp.mouse.y = new_y;
_sapp.mouse.pos_valid = true;
}
}

_SOKOL_PRIVATE void _sapp_x11_mouse_event(sapp_event_type type, sapp_mousebutton btn, uint32_t mods) {
if (_sapp_events_enabled()) {
_sapp_init_event(type);
Expand Down Expand Up @@ -11374,6 +11402,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
break;
case ButtonPress:
{
_sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y);
const sapp_mousebutton btn = _sapp_x11_translate_button(event);
uint32_t mods = _sapp_x11_mods(event->xbutton.state);
// X11 doesn't set modifier bit on button down, so emulate that
Expand All @@ -11395,6 +11424,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
break;
case ButtonRelease:
{
_sapp_x11_mouse_update(event->xbutton.x, event->xbutton.y);
const sapp_mousebutton btn = _sapp_x11_translate_button(event);
if (btn != SAPP_MOUSEBUTTON_INVALID) {
uint32_t mods = _sapp_x11_mods(event->xbutton.state);
Expand All @@ -11408,25 +11438,19 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
case EnterNotify:
/* don't send enter/leave events while mouse button held down */
if (0 == _sapp.x11.mouse_buttons) {
_sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_ENTER, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state));
}
break;
case LeaveNotify:
if (0 == _sapp.x11.mouse_buttons) {
_sapp_x11_mouse_update(event->xcrossing.x, event->xcrossing.y);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xcrossing.state));
}
break;
case MotionNotify:
if (!_sapp.mouse.locked) {
const float new_x = (float) event->xmotion.x;
const float new_y = (float) event->xmotion.y;
if (_sapp.mouse.pos_valid) {
_sapp.mouse.dx = new_x - _sapp.mouse.x;
_sapp.mouse.dy = new_y - _sapp.mouse.y;
}
_sapp.mouse.x = new_x;
_sapp.mouse.y = new_y;
_sapp.mouse.pos_valid = true;
_sapp_x11_mouse_update(event->xmotion.x, event->xmotion.y);
_sapp_x11_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_x11_mods(event->xmotion.state));
}
break;
Expand Down Expand Up @@ -11512,7 +11536,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
XEvent reply;
_sapp_clear(&reply, sizeof(reply));
reply.type = ClientMessage;
reply.xclient.window = _sapp.x11.window;
reply.xclient.window = _sapp.x11.xdnd.source;
reply.xclient.message_type = _sapp.x11.xdnd.XdndFinished;
reply.xclient.format = 32;
reply.xclient.data.l[0] = (long)_sapp.x11.window;
Expand Down Expand Up @@ -11567,7 +11591,7 @@ _SOKOL_PRIVATE void _sapp_x11_process_event(XEvent* event) {
XEvent reply;
_sapp_clear(&reply, sizeof(reply));
reply.type = ClientMessage;
reply.xclient.window = _sapp.x11.window;
reply.xclient.window = _sapp.x11.xdnd.source;
reply.xclient.message_type = _sapp.x11.xdnd.XdndFinished;
reply.xclient.format = 32;
reply.xclient.data.l[0] = (long)_sapp.x11.window;
Expand Down
Loading

0 comments on commit eda6ecb

Please sign in to comment.