Merge branch 'main' into fix_win32_time_init

This commit is contained in:
MartinFouilleul 2023-08-25 13:38:49 +00:00
commit b0e025616c
16 changed files with 580 additions and 451 deletions

View File

@ -19,6 +19,9 @@ f32 minf(f32 a, f32 b);
ORCA_EXPORT void oc_on_init(void) ORCA_EXPORT void oc_on_init(void)
{ {
oc_runtime_window_set_title(OC_STR8("clock"));
oc_runtime_window_set_size((oc_vec2){ .x = 400, .y = 400 });
surface = oc_surface_canvas(); surface = oc_surface_canvas();
canvas = oc_canvas_create(); canvas = oc_canvas_create();

View File

@ -615,6 +615,8 @@ ORCA_EXPORT void oc_on_init()
{ {
oc_log_info("Hello, world (from C)"); oc_log_info("Hello, world (from C)");
oc_runtime_window_set_title(OC_STR8("fluid"));
surface = oc_surface_gles(); surface = oc_surface_gles();
oc_surface_select(surface); oc_surface_select(surface);

View File

@ -37,6 +37,8 @@ void compile_shader(GLuint shader, const char* source)
ORCA_EXPORT void oc_on_init(void) ORCA_EXPORT void oc_on_init(void)
{ {
oc_runtime_window_set_title(OC_STR8("triangle"));
surface = oc_surface_gles(); surface = oc_surface_gles();
oc_surface_select(surface); oc_surface_select(surface);

View File

@ -69,6 +69,8 @@ oc_str8 loadFile(oc_arena* arena, oc_str8 filename)
ORCA_EXPORT void oc_on_init(void) ORCA_EXPORT void oc_on_init(void)
{ {
oc_runtime_window_set_title(OC_STR8("pong"));
surface = oc_surface_canvas(); surface = oc_surface_canvas();
canvas = oc_canvas_create(); canvas = oc_canvas_create();

View File

@ -10,6 +10,8 @@ oc_arena textArena = { 0 };
ORCA_EXPORT void oc_on_init(void) ORCA_EXPORT void oc_on_init(void)
{ {
oc_runtime_window_set_title(OC_STR8("ui"));
surface = oc_surface_canvas(); surface = oc_surface_canvas();
canvas = oc_canvas_create(); canvas = oc_canvas_create();
oc_ui_init(&ui); oc_ui_init(&ui);

View File

@ -397,6 +397,7 @@ def gen_all_bindings():
) )
bindgen("core", "src/wasmbind/core_api.json", bindgen("core", "src/wasmbind/core_api.json",
guest_stubs="src/wasmbind/core_api_stubs.c",
wasm3_bindings="src/wasmbind/core_api_bind_gen.c", wasm3_bindings="src/wasmbind/core_api_bind_gen.c",
) )

View File

@ -15,31 +15,30 @@
#include "util/utf8.h" #include "util/utf8.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Typedefs, enums and constants // Typedefs, enums and constants
//-------------------------------------------------------------------- //--------------------------------------------------------------------
typedef struct oc_window typedef struct oc_window
{ {
u64 h; u64 h;
} oc_window; } oc_window;
typedef enum typedef enum
{ {
OC_MOUSE_CURSOR_ARROW, OC_MOUSE_CURSOR_ARROW,
OC_MOUSE_CURSOR_RESIZE_0, OC_MOUSE_CURSOR_RESIZE_0,
OC_MOUSE_CURSOR_RESIZE_90, OC_MOUSE_CURSOR_RESIZE_90,
OC_MOUSE_CURSOR_RESIZE_45, OC_MOUSE_CURSOR_RESIZE_45,
OC_MOUSE_CURSOR_RESIZE_135, OC_MOUSE_CURSOR_RESIZE_135,
OC_MOUSE_CURSOR_TEXT OC_MOUSE_CURSOR_TEXT
} oc_mouse_cursor; } oc_mouse_cursor;
typedef i32 oc_window_style; typedef i32 oc_window_style;
static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0, static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0,
OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1, OC_WINDOW_STYLE_FIXED_SIZE = 0x01 << 1,
OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2, OC_WINDOW_STYLE_NO_CLOSE = 0x01 << 2,
OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3, OC_WINDOW_STYLE_NO_MINIFY = 0x01 << 3,
@ -48,8 +47,8 @@ extern "C"
OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6, OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6,
OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7; OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7;
typedef enum typedef enum
{ {
OC_EVENT_NONE, OC_EVENT_NONE,
OC_EVENT_KEYBOARD_MODS, //TODO: remove, keep only key? OC_EVENT_KEYBOARD_MODS, //TODO: remove, keep only key?
OC_EVENT_KEYBOARD_KEY, OC_EVENT_KEYBOARD_KEY,
@ -69,18 +68,18 @@ extern "C"
OC_EVENT_PATHDROP, OC_EVENT_PATHDROP,
OC_EVENT_FRAME, OC_EVENT_FRAME,
OC_EVENT_QUIT OC_EVENT_QUIT
} oc_event_type; } oc_event_type;
typedef enum typedef enum
{ {
OC_KEY_NO_ACTION, OC_KEY_NO_ACTION,
OC_KEY_PRESS, OC_KEY_PRESS,
OC_KEY_RELEASE, OC_KEY_RELEASE,
OC_KEY_REPEAT OC_KEY_REPEAT
} oc_key_action; } oc_key_action;
typedef enum typedef enum
{ {
OC_KEY_UNKNOWN = 0, OC_KEY_UNKNOWN = 0,
OC_KEY_SPACE = 32, OC_KEY_SPACE = 32,
OC_KEY_APOSTROPHE = 39, /* ' */ OC_KEY_APOSTROPHE = 39, /* ' */
@ -203,62 +202,62 @@ extern "C"
OC_KEY_RIGHT_SUPER = 347, OC_KEY_RIGHT_SUPER = 347,
OC_KEY_MENU = 348, OC_KEY_MENU = 348,
OC_KEY_COUNT OC_KEY_COUNT
} oc_key_code; } oc_key_code;
typedef enum typedef enum
{ {
OC_KEYMOD_NONE = 0x00, OC_KEYMOD_NONE = 0x00,
OC_KEYMOD_ALT = 0x01, OC_KEYMOD_ALT = 0x01,
OC_KEYMOD_SHIFT = 0x02, OC_KEYMOD_SHIFT = 0x02,
OC_KEYMOD_CTRL = 0x04, OC_KEYMOD_CTRL = 0x04,
OC_KEYMOD_CMD = 0x08, OC_KEYMOD_CMD = 0x08,
OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */ OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */
} oc_keymod_flags; } oc_keymod_flags;
typedef enum typedef enum
{ {
OC_MOUSE_LEFT = 0x00, OC_MOUSE_LEFT = 0x00,
OC_MOUSE_RIGHT = 0x01, OC_MOUSE_RIGHT = 0x01,
OC_MOUSE_MIDDLE = 0x02, OC_MOUSE_MIDDLE = 0x02,
OC_MOUSE_EXT1 = 0x03, OC_MOUSE_EXT1 = 0x03,
OC_MOUSE_EXT2 = 0x04, OC_MOUSE_EXT2 = 0x04,
OC_MOUSE_BUTTON_COUNT OC_MOUSE_BUTTON_COUNT
} oc_mouse_button; } oc_mouse_button;
typedef struct oc_key_event // keyboard and mouse buttons input typedef struct oc_key_event // keyboard and mouse buttons input
{ {
oc_key_action action; oc_key_action action;
i32 code; i32 code;
oc_keymod_flags mods; oc_keymod_flags mods;
char label[8]; char label[8];
u8 labelLen; u8 labelLen;
int clickCount; int clickCount;
} oc_key_event; } oc_key_event;
typedef struct oc_char_event // character input typedef struct oc_char_event // character input
{ {
oc_utf32 codepoint; oc_utf32 codepoint;
char sequence[8]; char sequence[8];
u8 seqLen; u8 seqLen;
} oc_char_event; } oc_char_event;
typedef struct oc_mouse_event // mouse move/scroll typedef struct oc_mouse_event // mouse move/scroll
{ {
f32 x; f32 x;
f32 y; f32 y;
f32 deltaX; f32 deltaX;
f32 deltaY; f32 deltaY;
oc_keymod_flags mods; oc_keymod_flags mods;
} oc_mouse_event; } oc_mouse_event;
typedef struct oc_move_event // window resize / move typedef struct oc_move_event // window resize / move
{ {
oc_rect frame; oc_rect frame;
oc_rect content; oc_rect content;
} oc_move_event; } oc_move_event;
typedef struct oc_event typedef struct oc_event
{ {
//TODO clipboard and path drop //TODO clipboard and path drop
oc_window window; oc_window window;
oc_event_type type; oc_event_type type;
@ -272,135 +271,143 @@ extern "C"
oc_str8_list paths; oc_str8_list paths;
}; };
} oc_event; } oc_event;
//NOTE: these APIs are not directly available to Orca apps //NOTE: these APIs are not directly available to Orca apps
#if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) #if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// app management // app management
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API void oc_init(void); ORCA_API void oc_init(void);
ORCA_API void oc_terminate(void); ORCA_API void oc_terminate(void);
ORCA_API bool oc_should_quit(void); ORCA_API bool oc_should_quit(void);
ORCA_API void oc_cancel_quit(void); ORCA_API void oc_cancel_quit(void);
ORCA_API void oc_request_quit(void); ORCA_API void oc_request_quit(void);
ORCA_API void oc_set_cursor(oc_mouse_cursor cursor); ORCA_API void oc_set_cursor(oc_mouse_cursor cursor);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Main loop and events handling // Main loop and events handling
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/*NOTE: /*NOTE:
oc_pump_events() pumps system events into the event queue. A timeout of 0 polls for events, oc_pump_events() pumps system events into the event queue. A timeout of 0 polls for events,
while a timeout of -1 blocks for events. A timeout > 0 blocks until new events are available while a timeout of -1 blocks for events. A timeout > 0 blocks until new events are available
or the timeout elapses. or the timeout elapses.
oc_next_event() get the next event from the event queue, allocating from the passed arena oc_next_event() get the next event from the event queue, allocating from the passed arena
*/ */
ORCA_API void oc_pump_events(f64 timeout); ORCA_API void oc_pump_events(f64 timeout);
ORCA_API oc_event* oc_next_event(oc_arena* arena); ORCA_API oc_event* oc_next_event(oc_arena* arena);
typedef void (*oc_live_resize_callback)(oc_event event, void* data); typedef void (*oc_live_resize_callback)(oc_event event, void* data);
ORCA_API void oc_set_live_resize_callback(oc_live_resize_callback callback, void* data); ORCA_API void oc_set_live_resize_callback(oc_live_resize_callback callback, void* data);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// window management // window management
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API bool oc_window_handle_is_null(oc_window window); ORCA_API bool oc_window_handle_is_null(oc_window window);
ORCA_API oc_window oc_window_null_handle(void); ORCA_API oc_window oc_window_null_handle(void);
ORCA_API oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style style); ORCA_API oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style style);
ORCA_API void oc_window_destroy(oc_window window); ORCA_API void oc_window_destroy(oc_window window);
ORCA_API void* oc_window_native_pointer(oc_window window); ORCA_API void* oc_window_native_pointer(oc_window window);
ORCA_API bool oc_window_should_close(oc_window window); ORCA_API bool oc_window_should_close(oc_window window);
ORCA_API void oc_window_request_close(oc_window window); ORCA_API void oc_window_request_close(oc_window window);
ORCA_API void oc_window_cancel_close(oc_window window); ORCA_API void oc_window_cancel_close(oc_window window);
ORCA_API bool oc_window_is_hidden(oc_window window); ORCA_API bool oc_window_is_hidden(oc_window window);
ORCA_API void oc_window_hide(oc_window window); ORCA_API void oc_window_hide(oc_window window);
ORCA_API void oc_window_show(oc_window window); ORCA_API void oc_window_show(oc_window window);
ORCA_API bool oc_window_is_minimized(oc_window window); ORCA_API void oc_window_set_title(oc_window window, oc_str8 title);
ORCA_API void oc_window_minimize(oc_window window);
ORCA_API void oc_window_restore(oc_window window);
ORCA_API bool oc_window_has_focus(oc_window window); ORCA_API bool oc_window_is_minimized(oc_window window);
ORCA_API void oc_window_focus(oc_window window); ORCA_API bool oc_window_is_maximized(oc_window window);
ORCA_API void oc_window_unfocus(oc_window window); ORCA_API void oc_window_minimize(oc_window window);
ORCA_API void oc_window_maximize(oc_window window);
ORCA_API void oc_window_restore(oc_window window);
ORCA_API void oc_window_send_to_back(oc_window window); ORCA_API bool oc_window_has_focus(oc_window window);
ORCA_API void oc_window_bring_to_front(oc_window window); ORCA_API void oc_window_focus(oc_window window);
ORCA_API void oc_window_unfocus(oc_window window);
ORCA_API oc_rect oc_window_get_frame_rect(oc_window window); ORCA_API void oc_window_send_to_back(oc_window window);
ORCA_API void oc_window_set_frame_rect(oc_window window, oc_rect rect); ORCA_API void oc_window_bring_to_front(oc_window window);
ORCA_API void oc_window_set_frame_position(oc_window window, oc_vec2 position);
ORCA_API void oc_window_set_frame_size(oc_window window, oc_vec2 size);
ORCA_API oc_rect oc_window_get_content_rect(oc_window window); ORCA_API oc_rect oc_window_get_frame_rect(oc_window window);
ORCA_API void oc_window_set_content_rect(oc_window window, oc_rect rect); ORCA_API void oc_window_set_frame_rect(oc_window window, oc_rect rect);
ORCA_API void oc_window_set_content_position(oc_window window, oc_vec2 position); ORCA_API void oc_window_set_frame_position(oc_window window, oc_vec2 position);
ORCA_API void oc_window_set_content_size(oc_window window, oc_vec2 size); ORCA_API void oc_window_set_frame_size(oc_window window, oc_vec2 size);
ORCA_API void oc_window_center(oc_window window); ORCA_API oc_rect oc_window_get_content_rect(oc_window window);
ORCA_API void oc_window_set_content_rect(oc_window window, oc_rect rect);
ORCA_API void oc_window_set_content_position(oc_window window, oc_vec2 position);
ORCA_API void oc_window_set_content_size(oc_window window, oc_vec2 size);
ORCA_API oc_rect oc_window_content_rect_for_frame_rect(oc_rect frameRect, oc_window_style style); ORCA_API void oc_window_center(oc_window window);
ORCA_API oc_rect oc_window_frame_rect_for_content_rect(oc_rect contentRect, oc_window_style style);
//--------------------------------------------------------------- ORCA_API oc_rect oc_window_content_rect_for_frame_rect(oc_rect frameRect, oc_window_style style);
// Dispatching stuff to the main thread ORCA_API oc_rect oc_window_frame_rect_for_content_rect(oc_rect contentRect, oc_window_style style);
//---------------------------------------------------------------
typedef i32 (*oc_dispatch_proc)(void* user); //---------------------------------------------------------------
// Dispatching stuff to the main thread
//---------------------------------------------------------------
ORCA_API i32 oc_dispatch_on_main_thread_sync(oc_window main_window, oc_dispatch_proc proc, void* user); typedef i32 (*oc_dispatch_proc)(void* user);
//-------------------------------------------------------------------- ORCA_API i32 oc_dispatch_on_main_thread_sync(oc_window main_window, oc_dispatch_proc proc, void* user);
// Clipboard
//--------------------------------------------------------------------
ORCA_API void oc_clipboard_clear(void);
ORCA_API void oc_clipboard_set_string(oc_str8 string); //--------------------------------------------------------------------
ORCA_API oc_str8 oc_clipboard_get_string(oc_arena* arena); // Clipboard
ORCA_API oc_str8 oc_clipboard_copy_string(oc_str8 backing); //--------------------------------------------------------------------
ORCA_API void oc_clipboard_clear(void);
ORCA_API bool oc_clipboard_has_tag(const char* tag); ORCA_API void oc_clipboard_set_string(oc_str8 string);
ORCA_API void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 data); ORCA_API oc_str8 oc_clipboard_get_string(oc_arena* arena);
ORCA_API oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag); ORCA_API oc_str8 oc_clipboard_copy_string(oc_str8 backing);
//-------------------------------------------------------------------- ORCA_API bool oc_clipboard_has_tag(const char* tag);
// native open/save/alert windows ORCA_API void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 data);
//-------------------------------------------------------------------- ORCA_API oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag);
ORCA_API oc_str8 oc_open_dialog(oc_arena* arena, //--------------------------------------------------------------------
// native open/save/alert windows
//--------------------------------------------------------------------
ORCA_API oc_str8 oc_open_dialog(oc_arena* arena,
oc_str8 title, oc_str8 title,
oc_str8 defaultPath, oc_str8 defaultPath,
oc_str8_list filters, oc_str8_list filters,
bool directory); bool directory);
ORCA_API oc_str8 oc_save_dialog(oc_arena* arena, ORCA_API oc_str8 oc_save_dialog(oc_arena* arena,
oc_str8 title, oc_str8 title,
oc_str8 defaultPath, oc_str8 defaultPath,
oc_str8_list filters); oc_str8_list filters);
ORCA_API int oc_alert_popup(oc_str8 title, ORCA_API int oc_alert_popup(oc_str8 title,
oc_str8 message, oc_str8 message,
oc_str8_list options); oc_str8_list options);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// file system stuff... //TODO: move elsewhere // file system stuff... //TODO: move elsewhere
//-------------------------------------------------------------------- //--------------------------------------------------------------------
ORCA_API int oc_file_move(oc_str8 from, oc_str8 to); ORCA_API int oc_file_move(oc_str8 from, oc_str8 to);
ORCA_API int oc_file_remove(oc_str8 path); ORCA_API int oc_file_remove(oc_str8 path);
ORCA_API int oc_directory_create(oc_str8 path); ORCA_API int oc_directory_create(oc_str8 path);
#else #else
void ORCA_IMPORT(oc_request_quit)(void); void ORCA_IMPORT(oc_request_quit)(void);
void ORCA_IMPORT(oc_runtime_window_set_title)(oc_str8 title);
void ORCA_IMPORT(oc_runtime_window_set_size)(oc_vec2 size);
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) #endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)

View File

@ -1471,6 +1471,29 @@ bool oc_window_is_focused(oc_window window)
} }
} }
void oc_window_set_title(oc_window window, oc_str8 title)
{
dispatch_block_t block = ^{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
windowData->osx.nsWindow.title = [[NSString alloc] initWithBytes:title.ptr length:title.len encoding:NSUTF8StringEncoding];
}
}
};
if([NSThread isMainThread])
{
block();
}
else
{
dispatch_sync(dispatch_get_main_queue(), block);
}
}
bool oc_window_is_minimized(oc_window window) bool oc_window_is_minimized(oc_window window)
{ {
@autoreleasepool @autoreleasepool
@ -1634,9 +1657,9 @@ oc_rect oc_window_get_content_rect(oc_window window)
void oc_window_set_content_rect(oc_window window, oc_rect rect) void oc_window_set_content_rect(oc_window window, oc_rect rect)
{ {
dispatch_block_t block = ^{
@autoreleasepool @autoreleasepool
{ {
oc_window_data* windowData = oc_window_ptr_from_handle(window); oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData) if(windowData)
{ {
@ -1652,6 +1675,16 @@ void oc_window_set_content_rect(oc_window window, oc_rect rect)
[windowData->osx.nsWindow setFrame:frameRect display:YES]; [windowData->osx.nsWindow setFrame:frameRect display:YES];
} }
} }
};
if([NSThread isMainThread])
{
block();
}
else
{
dispatch_sync(dispatch_get_main_queue(), block);
}
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------

View File

@ -791,6 +791,20 @@ void oc_window_show(oc_window window)
} }
} }
void oc_window_set_title(oc_window window, oc_str8 title)
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
oc_arena_scope scratch = oc_scratch_begin();
const char* titleCString = oc_str8_to_cstring(scratch.arena, title);
SetWindowText(windowData->win32.hWnd, titleCString);
oc_scratch_end(scratch);
}
}
bool oc_window_is_minimized(oc_window window) bool oc_window_is_minimized(oc_window window)
{ {
oc_window_data* windowData = oc_window_ptr_from_handle(window); oc_window_data* windowData = oc_window_ptr_from_handle(window);

View File

@ -1448,6 +1448,7 @@ void oc_rectangle_stroke(f32 x, f32 y, f32 w, f32 h)
void oc_rounded_rectangle_path(f32 x, f32 y, f32 w, f32 h, f32 r) void oc_rounded_rectangle_path(f32 x, f32 y, f32 w, f32 h, f32 r)
{ {
r = oc_min(r, oc_min(w / 2, h / 2));
f32 c = r * 4 * (sqrt(2) - 1) / 3; f32 c = r * 4 * (sqrt(2) - 1) / 3;
oc_move_to(x + r, y); oc_move_to(x + r, y);

View File

@ -984,6 +984,8 @@ void oc_mtl_render_batch(oc_mtl_canvas_backend* backend,
[blitEncoder endEncoding]; [blitEncoder endEncoding];
//NOTE: path setup pass //NOTE: path setup pass
if(pathCount > 0)
{
id<MTLComputeCommandEncoder> pathEncoder = [surface->commandBuffer computeCommandEncoder]; id<MTLComputeCommandEncoder> pathEncoder = [surface->commandBuffer computeCommandEncoder];
pathEncoder.label = @"path pass"; pathEncoder.label = @"path pass";
[pathEncoder setComputePipelineState:backend->pathPipeline]; [pathEncoder setComputePipelineState:backend->pathPipeline];
@ -1004,15 +1006,18 @@ void oc_mtl_render_batch(oc_mtl_canvas_backend* backend,
[pathEncoder dispatchThreads:pathGridSize threadsPerThreadgroup:pathGroupSize]; [pathEncoder dispatchThreads:pathGridSize threadsPerThreadgroup:pathGroupSize];
[pathEncoder endEncoding]; [pathEncoder endEncoding];
}
//NOTE: segment setup pass
id<MTLComputeCommandEncoder> segmentEncoder = [surface->commandBuffer computeCommandEncoder];
segmentEncoder.label = @"segment pass";
[segmentEncoder setComputePipelineState:backend->segmentPipeline];
int tileOpMax = [backend->tileOpBuffer length] / sizeof(oc_mtl_tile_op); int tileOpMax = [backend->tileOpBuffer length] / sizeof(oc_mtl_tile_op);
int segmentMax = [backend->segmentBuffer length] / sizeof(oc_mtl_segment); int segmentMax = [backend->segmentBuffer length] / sizeof(oc_mtl_segment);
//NOTE: segment setup pass
if(eltCount > 0)
{
id<MTLComputeCommandEncoder> segmentEncoder = [surface->commandBuffer computeCommandEncoder];
segmentEncoder.label = @"segment pass";
[segmentEncoder setComputePipelineState:backend->segmentPipeline];
[segmentEncoder setBytes:&eltCount length:sizeof(int) atIndex:0]; [segmentEncoder setBytes:&eltCount length:sizeof(int) atIndex:0];
[segmentEncoder setBuffer:backend->elementBuffer[backend->bufferIndex] offset:elementBufferOffset atIndex:1]; [segmentEncoder setBuffer:backend->elementBuffer[backend->bufferIndex] offset:elementBufferOffset atIndex:1];
[segmentEncoder setBuffer:backend->segmentCountBuffer offset:0 atIndex:2]; [segmentEncoder setBuffer:backend->segmentCountBuffer offset:0 atIndex:2];
@ -1033,8 +1038,11 @@ void oc_mtl_render_batch(oc_mtl_canvas_backend* backend,
[segmentEncoder dispatchThreads:segmentGridSize threadsPerThreadgroup:segmentGroupSize]; [segmentEncoder dispatchThreads:segmentGridSize threadsPerThreadgroup:segmentGroupSize];
[segmentEncoder endEncoding]; [segmentEncoder endEncoding];
}
//NOTE: backprop pass //NOTE: backprop pass
if(pathCount > 0)
{
id<MTLComputeCommandEncoder> backpropEncoder = [surface->commandBuffer computeCommandEncoder]; id<MTLComputeCommandEncoder> backpropEncoder = [surface->commandBuffer computeCommandEncoder];
backpropEncoder.label = @"backprop pass"; backpropEncoder.label = @"backprop pass";
[backpropEncoder setComputePipelineState:backend->backpropPipeline]; [backpropEncoder setComputePipelineState:backend->backpropPipeline];
@ -1049,8 +1057,11 @@ void oc_mtl_render_batch(oc_mtl_canvas_backend* backend,
[backpropEncoder dispatchThreads:backpropGridSize threadsPerThreadgroup:backpropGroupSize]; [backpropEncoder dispatchThreads:backpropGridSize threadsPerThreadgroup:backpropGroupSize];
[backpropEncoder endEncoding]; [backpropEncoder endEncoding];
}
//NOTE: merge pass //NOTE: merge pass
if(pathCount > 0)
{
id<MTLComputeCommandEncoder> mergeEncoder = [surface->commandBuffer computeCommandEncoder]; id<MTLComputeCommandEncoder> mergeEncoder = [surface->commandBuffer computeCommandEncoder];
mergeEncoder.label = @"merge pass"; mergeEncoder.label = @"merge pass";
[mergeEncoder setComputePipelineState:backend->mergePipeline]; [mergeEncoder setComputePipelineState:backend->mergePipeline];
@ -1074,6 +1085,7 @@ void oc_mtl_render_batch(oc_mtl_canvas_backend* backend,
[mergeEncoder dispatchThreads:mergeGridSize threadsPerThreadgroup:mergeGroupSize]; [mergeEncoder dispatchThreads:mergeGridSize threadsPerThreadgroup:mergeGroupSize];
[mergeEncoder endEncoding]; [mergeEncoder endEncoding];
}
//NOTE: raster pass //NOTE: raster pass
id<MTLComputeCommandEncoder> rasterEncoder = [surface->commandBuffer computeCommandEncoder]; id<MTLComputeCommandEncoder> rasterEncoder = [surface->commandBuffer computeCommandEncoder];

View File

@ -96,6 +96,7 @@
//NOTE: macos application layer and graphics backends are defined in orca.m //NOTE: macos application layer and graphics backends are defined in orca.m
#elif OC_PLATFORM_ORCA #elif OC_PLATFORM_ORCA
#include "app/orca_app.c" #include "app/orca_app.c"
#include "wasmbind/core_api_stubs.c"
#include "graphics/graphics_common.c" #include "graphics/graphics_common.c"
#include "graphics/orca_surface_stubs.c" #include "graphics/orca_surface_stubs.c"
#else #else

View File

@ -66,6 +66,37 @@ oc_runtime_env* oc_runtime_env_get()
return (&__orcaApp.runtime); return (&__orcaApp.runtime);
} }
void* oc_runtime_ptr_to_native(oc_runtime* orca, void* wasmPtr, u32 length)
{
// We can't use the runtime's memory pointer directly because wasm3 embeds a
// header at the beginning of the block we give it.
u64 bufferIndex = (u64)wasmPtr & 0xffffffff;
u32 memSize = 0;
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
if(bufferIndex + length < memSize)
{
char* nativePtr = memory + bufferIndex;
return nativePtr;
}
return NULL;
}
void oc_runtime_window_set_title(oc_str8 title)
{
title.ptr = oc_runtime_ptr_to_native(oc_runtime_get(), title.ptr, title.len);
if(title.ptr)
{
oc_window_set_title(__orcaApp.window, title);
}
}
void oc_runtime_window_set_size(oc_vec2 size)
{
oc_window_set_content_size(__orcaApp.window, size);
}
void oc_runtime_log(oc_log_level level, void oc_runtime_log(oc_log_level level,
int fileLen, int fileLen,
char* file, char* file,

View File

@ -125,4 +125,6 @@ typedef struct oc_runtime
oc_runtime* oc_runtime_get(); oc_runtime* oc_runtime_get();
oc_runtime_env* oc_runtime_env_get(); oc_runtime_env* oc_runtime_env_get();
void* oc_runtime_ptr_to_native(oc_runtime* runtime, void* wasmPtr, u32 length);
#endif //__RUNTIME_H_ #endif //__RUNTIME_H_

View File

@ -14,19 +14,12 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
oc_io_cmp cmp = { 0 }; oc_io_cmp cmp = { 0 };
oc_io_req req = *wasmReq; oc_io_req req = *wasmReq;
//NOTE: convert the req->buffer wasm pointer to a native pointer
// for some reason, wasm3 memory doesn't start at the beginning of the block we give it.
u64 bufferIndex = (u64)req.buffer & 0xffffffff;
u32 memSize = 0;
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
if(bufferIndex + req.size > memSize) void* buffer = oc_runtime_ptr_to_native(orca, req.buffer, req.size);
if(buffer)
{ {
cmp.error = OC_IO_ERR_ARG; req.buffer = buffer;
}
else
{
req.buffer = memory + bufferIndex;
if(req.op == OC_IO_OPEN_AT) if(req.op == OC_IO_OPEN_AT)
{ {
@ -39,5 +32,10 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
} }
cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable); cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable);
} }
else
{
cmp.error = OC_IO_ERR_ARG;
}
return (cmp); return (cmp);
} }

View File

@ -69,5 +69,23 @@
"cname": "oc_request_quit", "cname": "oc_request_quit",
"ret": {"name": "void", "tag": "v"}, "ret": {"name": "void", "tag": "v"},
"args": [] "args": []
},
{
"name": "oc_runtime_window_set_title",
"cname": "oc_runtime_window_set_title",
"ret": {"name": "void", "tag": "v"},
"args": [
{ "name": "title",
"type": {"name": "oc_str8", "tag": "S"}}
]
},
{
"name": "oc_runtime_window_set_size",
"cname": "oc_runtime_window_set_size",
"ret": {"name": "void", "tag": "v"},
"args": [
{ "name": "size",
"type": {"name": "oc_vec2", "tag": "S"}}
]
} }
] ]