Skip to content

Commit

Permalink
Merge branch 'floooh:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopolimeni authored Apr 27, 2022
2 parents a8a97bd + 9a6237f commit f5058f2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
22 changes: 12 additions & 10 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ typedef struct {
#if defined(_SAPP_MACOS) || defined(_SAPP_IOS)
// this is ARC compatible
#if defined(__cplusplus)
#define _SAPP_CLEAR(type, item) { item = (type) { }; }
#define _SAPP_CLEAR(type, item) { item = { }; }
#else
#define _SAPP_CLEAR(type, item) { item = (type) { 0 }; }
#endif
Expand Down Expand Up @@ -3954,6 +3954,11 @@ _SOKOL_PRIVATE void _sapp_ios_update_dimensions(void) {
(_sapp.framebuffer_height != cur_fb_height);
if (dim_changed) {
#if defined(SOKOL_METAL)
// NOTE: explicitely resize the drawable here again, despite MTKView using
// autoResizeDrawable, this seems to be the only way so that the MTKView's
// contentScaleFactor is honored, but also the correct screen size being
// reported when device rotations happen
// (see: https://github.com/floooh/sokol-samples/issues/101)
const CGSize drawable_size = { (CGFloat) _sapp.framebuffer_width, (CGFloat) _sapp.framebuffer_height };
_sapp.ios.view.drawableSize = drawable_size;
#else
Expand Down Expand Up @@ -4027,11 +4032,6 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) {
_sapp.ios.view.colorPixelFormat = MTLPixelFormatBGRA8Unorm;
_sapp.ios.view.depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
_sapp.ios.view.sampleCount = (NSUInteger)_sapp.sample_count;
/* NOTE: iOS MTKView seems to ignore thew view's contentScaleFactor
and automatically renders at Retina resolution. We'll disable
autoResize and instead do the resizing in _sapp_ios_update_dimensions()
*/
_sapp.ios.view.autoResizeDrawable = false;
_sapp.ios.view.userInteractionEnabled = YES;
_sapp.ios.view.multipleTouchEnabled = YES;
_sapp.ios.view_ctrl = [[UIViewController alloc] init];
Expand Down Expand Up @@ -6254,14 +6254,16 @@ _SOKOL_PRIVATE void _sapp_win32_set_fullscreen(bool fullscreen, UINT swp_flags)
else {
GetWindowRect(_sapp.win32.hwnd, &_sapp.win32.stored_window_rect);
win_style = WS_POPUP | WS_SYSMENU | WS_VISIBLE;
rect.right = monitor_w;
rect.bottom = monitor_h;
rect.left = mr.left;
rect.top = mr.top;
rect.right = rect.left + monitor_w;
rect.bottom = rect.top + monitor_h;
AdjustWindowRectEx(&rect, win_style, FALSE, win_ex_style);
}
const int win_w = rect.right - rect.left;
const int win_h = rect.bottom - rect.top;
const int win_x = mr.left + rect.left;
const int win_y = mr.top + rect.top;
const int win_x = rect.left;
const int win_y = rect.top;
SetWindowLongPtr(_sapp.win32.hwnd, GWL_STYLE, win_style);
SetWindowPos(_sapp.win32.hwnd, HWND_TOP, win_x, win_y, win_w, win_h, swp_flags | SWP_FRAMECHANGED);
}
Expand Down
6 changes: 3 additions & 3 deletions sokol_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1223,14 +1223,14 @@ _SOKOL_PRIVATE bool _saudio_backend_init(void) {
fmt.mBytesPerPacket = fmt.mBytesPerFrame;
fmt.mBitsPerChannel = 32;
_saudio_OSStatus res = AudioQueueNewOutput(&fmt, _saudio_coreaudio_callback, 0, NULL, NULL, 0, &_saudio.backend.ca_audio_queue);
SOKOL_ASSERT((res == 0) && _saudio.backend.ca_audio_queue);
SOKOL_ASSERT((res == 0) && _saudio.backend.ca_audio_queue); (void)res;

/* create 2 audio buffers */
for (int i = 0; i < 2; i++) {
_saudio_AudioQueueBufferRef buf = NULL;
const uint32_t buf_byte_size = (uint32_t)_saudio.buffer_frames * fmt.mBytesPerFrame;
res = AudioQueueAllocateBuffer(_saudio.backend.ca_audio_queue, buf_byte_size, &buf);
SOKOL_ASSERT((res == 0) && buf);
SOKOL_ASSERT((res == 0) && buf); (void)res;
buf->mAudioDataByteSize = buf_byte_size;
memset(buf->mAudioData, 0, buf->mAudioDataByteSize);
AudioQueueEnqueueBuffer(_saudio.backend.ca_audio_queue, buf, 0, NULL);
Expand All @@ -1241,7 +1241,7 @@ _SOKOL_PRIVATE bool _saudio_backend_init(void) {

/* ...and start playback */
res = AudioQueueStart(_saudio.backend.ca_audio_queue, NULL);
SOKOL_ASSERT(0 == res);
SOKOL_ASSERT(0 == res); (void)res;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15096,7 +15096,7 @@ _SOKOL_PRIVATE bool _sg_uninit_pass(sg_pass pass_id) {
#if defined(SOKOL_METAL)
// this is ARC compatible
#if defined(__cplusplus)
#define _SG_CLEAR(type, item) { item = (type) { }; }
#define _SG_CLEAR(type, item) { item = { }; }
#else
#define _SG_CLEAR(type, item) { item = (type) { 0 }; }
#endif
Expand Down
8 changes: 4 additions & 4 deletions util/sokol_fontstash.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@
--- finally on application shutdown, call:
sfons_shutdown()
sfons_destroy(FONScontext* ctx)
before sgl_shutdown() and sg_shutdown()
WHAT HAPPENS UNDER THE HOOD:
============================
sfons_create():
FONScontext* sfons_create(int width, int height, int flags):
- creates a sokol-gfx shader compatible with sokol-gl
- creates an sgl_pipeline object with alpha-blending using
this shader
Expand All @@ -122,12 +122,12 @@
all calls to fonsDrawText() will be merged into a single draw call
as long as all calls use the same FONScontext
sfons_flush():
sfons_flush(FONScontext* ctx):
- this will call sg_update_image() on the font atlas texture
if fontstash.h has added any rasterized glyphs since the last
frame
sfons_shutdown():
sfons_destroy(FONScontext* ctx):
- destroy the font atlas texture, sgl_pipeline and sg_shader objects
LICENSE
Expand Down
9 changes: 8 additions & 1 deletion util/sokol_nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -1941,8 +1941,15 @@ SOKOL_API_IMPL void snk_render(int width, int height) {
int idx_offset = 0;
nk_draw_foreach(cmd, &_snuklear.ctx, &cmds) {
if (cmd->elem_count > 0) {
sg_image img;
if (cmd->texture.id != 0) {
img = (sg_image){ .id = (uint32_t) cmd->texture.id };
}
else {
img = _snuklear.img;
}
sg_apply_bindings(&(sg_bindings){
.fs_images[0] = _snuklear.img,
.fs_images[0] = img,
.vertex_buffers[0] = _snuklear.vbuf,
.index_buffer = _snuklear.ibuf,
.vertex_buffer_offsets[0] = 0,
Expand Down

0 comments on commit f5058f2

Please sign in to comment.