Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kassane/sokol-d into imgui-support
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Mar 21, 2024
2 parents 4d1d659 + bbc45ed commit 74d43ca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
11 changes: 8 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,13 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
try cmds.append(b.fmt("-mtriple={s}", .{mtriple}));

// cpu model (e.g. "baseline")
if (options.target.query.isNative())
try cmds.append(b.fmt("-mcpu={s}", .{builtin.cpu.model.name}));
if (options.target.query.isNative()) {
const cpu_model = if (options.target.result.isDarwin())
builtin.cpu.model.llvm_name orelse "generic"
else
builtin.cpu.model.name;
try cmds.append(b.fmt("-mcpu={s}", .{cpu_model}));
}

const outputDir = switch (options.kind) {
.lib => "lib",
Expand Down Expand Up @@ -609,7 +614,7 @@ pub const DCompileStep = struct {
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode = .Debug,
kind: CompileStep.Kind = .exe,
linkage: CompileStep.Linkage = .static,
linkage: std.builtin.LinkMode = .static,
betterC: bool = false,
sources: []const []const u8,
dflags: []const []const u8,
Expand Down
2 changes: 2 additions & 0 deletions src/sokol/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ struct Desc {
bool html5_bubble_wheel_events = false;
bool html5_bubble_key_events = false;
bool html5_bubble_char_events = false;
bool html5_use_emsc_set_main_loop = false;
bool html5_emsc_set_main_loop_simulate_infinite_loop = false;
bool ios_keyboard_resizes_canvas = false;
}
enum Html5FetchError {
Expand Down
28 changes: 20 additions & 8 deletions src/sokol/c/sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ typedef struct sapp_desc {
bool html5_bubble_wheel_events; // same for wheel events
bool html5_bubble_key_events; // if true, bubble up *all* key events to browser, not just key events that represent characters
bool html5_bubble_char_events; // if true, bubble up character events to browser
bool html5_use_emsc_set_main_loop; // if true, use emscripten_set_main_loop() instead of emscripten_request_animation_frame_loop()
bool html5_emsc_set_main_loop_simulate_infinite_loop; // this will be passed as the simulate_infinite_loop arg to emscripten_set_main_loop()
bool ios_keyboard_resizes_canvas; // if true, showing the iOS keyboard shrinks the canvas
} sapp_desc;

Expand Down Expand Up @@ -2594,7 +2596,7 @@ typedef struct {
PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB;
PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB;
// special case glGetIntegerv
void (*GetIntegerv)(uint32_t pname, int32_t* data);
void (WINAPI *GetIntegerv)(uint32_t pname, int32_t* data);
bool ext_swap_control;
bool arb_multisample;
bool arb_pixel_format;
Expand Down Expand Up @@ -4751,7 +4753,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) {
#if defined(_SAPP_EMSCRIPTEN)

#if defined(EM_JS_DEPS)
EM_JS_DEPS(sokol_app, "$withStackSave,$allocateUTF8OnStack");
EM_JS_DEPS(sokol_app, "$withStackSave,$stringToUTF8OnStack");
#endif

#ifdef __cplusplus
Expand Down Expand Up @@ -4868,7 +4870,7 @@ EM_JS(void, sapp_js_add_clipboard_listener, (void), {
Module.sokol_paste = (event) => {
const pasted_str = event.clipboardData.getData('text');
withStackSave(() => {
const cstr = allocateUTF8OnStack(pasted_str);
const cstr = stringToUTF8OnStack(pasted_str);
__sapp_emsc_onpaste(cstr);
});
};
Expand Down Expand Up @@ -4925,7 +4927,7 @@ EM_JS(void, sapp_js_add_dragndrop_listeners, (const char* canvas_name_cstr), {
__sapp_emsc_begin_drop(files.length);
for (let i = 0; i < files.length; i++) {
withStackSave(() => {
const cstr = allocateUTF8OnStack(files[i].name);
const cstr = stringToUTF8OnStack(files[i].name);
__sapp_emsc_drop(i, cstr);
});
}
Expand Down Expand Up @@ -5854,7 +5856,7 @@ _SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers(void) {
#endif
}

_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) {
_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame_animation_loop(double time, void* userData) {
_SOKOL_UNUSED(userData);
_sapp_timing_external(&_sapp.timing, time / 1000.0);

Expand All @@ -5881,6 +5883,13 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) {
return EM_TRUE;
}

_SOKOL_PRIVATE void _sapp_emsc_frame_main_loop(void) {
const double time = emscripten_performance_now();
if (!_sapp_emsc_frame_animation_loop(time, 0)) {
emscripten_cancel_main_loop();
}
}

_SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) {
_sapp_init_state(desc);
sapp_js_init(&_sapp.html5_canvas_selector[1]);
Expand Down Expand Up @@ -5911,8 +5920,11 @@ _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) {
sapp_set_icon(&desc->icon);

// start the frame loop
emscripten_request_animation_frame_loop(_sapp_emsc_frame, 0);

if (_sapp.desc.html5_use_emsc_set_main_loop) {
emscripten_set_main_loop(_sapp_emsc_frame_main_loop, 0, _sapp.desc.html5_emsc_set_main_loop_simulate_infinite_loop);
} else {
emscripten_request_animation_frame_loop(_sapp_emsc_frame_animation_loop, 0);
}
// NOT A BUG: do not call _sapp_discard_state() here, instead this is
// called in _sapp_emsc_frame() when the application is ordered to quit
}
Expand Down Expand Up @@ -6601,7 +6613,7 @@ _SOKOL_PRIVATE void _sapp_wgl_init(void) {
SOKOL_ASSERT(_sapp.wgl.GetCurrentDC);
_sapp.wgl.MakeCurrent = (PFN_wglMakeCurrent)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglMakeCurrent");
SOKOL_ASSERT(_sapp.wgl.MakeCurrent);
_sapp.wgl.GetIntegerv = (void(*)(uint32_t, int32_t*)) GetProcAddress(_sapp.wgl.opengl32, "glGetIntegerv");
_sapp.wgl.GetIntegerv = (void(WINAPI*)(uint32_t, int32_t*)) GetProcAddress(_sapp.wgl.opengl32, "glGetIntegerv");
SOKOL_ASSERT(_sapp.wgl.GetIntegerv);

_sapp.wgl.msg_hwnd = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
Expand Down
19 changes: 11 additions & 8 deletions src/sokol/c/sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -2432,7 +2432,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
Expand Down Expand Up @@ -3566,7 +3566,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") \
Expand Down Expand Up @@ -4166,7 +4166,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); }
Expand Down Expand Up @@ -12526,12 +12526,14 @@ _SOKOL_PRIVATE void _sg_mtl_begin_pass(const sg_pass* pass) {
SOKOL_ASSERT(ds_tex != nil);
pass_desc.depthAttachment.texture = ds_tex;
pass_desc.depthAttachment.storeAction = MTLStoreActionDontCare;
pass_desc.stencilAttachment.texture = ds_tex;
pass_desc.stencilAttachment.storeAction = MTLStoreActionDontCare;
pass_desc.depthAttachment.loadAction = _sg_mtl_load_action(action->depth.load_action);
pass_desc.depthAttachment.clearDepth = action->depth.clear_value;
pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action);
pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value;
if (_sg_is_depth_stencil_format(swapchain->depth_format)) {
pass_desc.stencilAttachment.texture = ds_tex;
pass_desc.stencilAttachment.storeAction = MTLStoreActionDontCare;
pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action);
pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value;
}
}
}

Expand Down Expand Up @@ -14475,6 +14477,7 @@ _SOKOL_PRIVATE _sg_image_t* _sg_wgpu_attachments_ds_image(const _sg_attachments_
}

_SOKOL_PRIVATE void _sg_wgpu_init_color_att(WGPURenderPassColorAttachment* wgpu_att, const sg_color_attachment_action* action, WGPUTextureView color_view, WGPUTextureView resolve_view) {
wgpu_att->depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
wgpu_att->view = color_view;
wgpu_att->resolveTarget = resolve_view;
wgpu_att->loadOp = _sg_wgpu_load_op(color_view, action->load_action);
Expand Down
2 changes: 1 addition & 1 deletion src/sokol/c/sokol_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
functions. Use this in the sg_setup() call like this:
sg_setup(&(sg_desc){
.environment = sglue_enviornment(),
.environment = sglue_environment(),
...
});
Expand Down

0 comments on commit 74d43ca

Please sign in to comment.