From 3c0b73c2d6a303fdce08c2d6902c9c61f3035424 Mon Sep 17 00:00:00 2001 From: lydiandy <56576373+lydiandy@users.noreply.github.com> Date: Tue, 25 Feb 2020 01:02:22 +0800 Subject: [PATCH] sokol: fixes --- vlib/sokol/gfx/enums.v | 2 +- vlib/sokol/gfx/gfx.v | 97 ++++++++++++++++++++++++---------- vlib/sokol/gfx/gfx_funcs.v | 27 +++++++--- vlib/sokol/gfx/gfx_structs.v | 18 +++---- vlib/sokol/sapp/enums.v | 7 +++ vlib/sokol/sapp/sapp.v | 5 ++ vlib/sokol/sapp/sapp_funcs.v | 2 + vlib/sokol/sapp/sapp_structs.v | 4 +- 8 files changed, 114 insertions(+), 48 deletions(-) diff --git a/vlib/sokol/gfx/enums.v b/vlib/sokol/gfx/enums.v index 5fea066fdb..d4aef911af 100644 --- a/vlib/sokol/gfx/enums.v +++ b/vlib/sokol/gfx/enums.v @@ -82,7 +82,7 @@ pub enum PixelFormat { etc2_rg11 etc2_rg11sn - num + _num } pub enum ResourceState { diff --git a/vlib/sokol/gfx/gfx.v b/vlib/sokol/gfx/gfx.v index 4fe5aa3710..586e72b403 100644 --- a/vlib/sokol/gfx/gfx.v +++ b/vlib/sokol/gfx/gfx.v @@ -82,6 +82,11 @@ pub fn append_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) int { return C.sg_append_buffer(buf, ptr, num_bytes) } +[inline] +pub fn query_buffer_overflow(buf C.sg_buffer) bool { + return C.sg_query_buffer_overflow(buf) +} + // rendering functions [inline] pub fn begin_default_pass(actions &C.sg_pass_action, width int, height int) { @@ -133,9 +138,56 @@ pub fn commit() { C.sg_commit() } +// getting information [inline] -pub fn query_buffer_overflow(buf C.sg_buffer) bool { - return C.sg_query_buffer_overflow(buf) +pub fn query_desc() C.sg_desc { + return C.sg_query_desc() +} + +[inline] +pub fn query_backend() Backend { + return C.sg_query_backend() +} + +[inline] +pub fn query_features() C.sg_features { + return C.sg_query_features() +} + +[inline] +pub fn query_limits() C.sg_limits { + return C.sg_query_limits() +} + +[inline] +pub fn query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info { + return C.sg_query_pixelformat(fmt) +} + +/* get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID) */ +[inline] +pub fn query_buffer_state(buf C.sg_buffer) C.sg_resource_state { + return sg_query_buffer_state(buf) +} + +[inline] +pub fn query_image_state(img C.sg_image) C.sg_resource_state { + return sg_query_image_state(img) +} + +[inline] +pub fn query_shader_state(shd C.sg_shader) C.sg_resource_state { + return sg_query_shader_state(shd) +} + +[inline] +pub fn query_pipeline_state(pip C.sg_pipeline) C.sg_resource_state { + return sg_query_pipeline_state(pip) +} + +[inline] +pub fn query_pass_state(pass C.sg_pass) C.sg_resource_state { + return sg_query_pass_state(pass) } // get runtime information about a resource @@ -164,32 +216,6 @@ pub fn query_pass_info(pass C.sg_pass) C.sg_pass_info { return C.sg_query_pass_info(pass) } -// getting information -[inline] -pub fn query_desc() C.sg_desc { - return C.sg_query_desc() -} - -[inline] -pub fn query_backend() Backend { - return C.sg_query_backend() -} - -[inline] -pub fn query_features() C.sg_features { - return C.sg_query_features() -} - -[inline] -pub fn query_limits() C.sg_limits { - return C.sg_query_limits() -} - -[inline] -pub fn query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info { - return C.sg_query_pixelformat(fmt) -} - // get resource creation desc struct with their default values replaced [inline] pub fn query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc { @@ -216,3 +242,18 @@ pub fn query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc { return C.sg_query_pass_defaults(desc) } +/* rendering contexts (optional) */ +[inline] +pub fn setup_context() C.sg_context { + return C.sg_setup_context() +} + +[inline] +pub fn activate_context(ctx_id C.sg_context) { + C.sg_activate_context(ctx_id) +} + +[inline] +pub fn discard_context(ctx_id C.sg_context) { + C.sg_discard_context(ctx_id) +} \ No newline at end of file diff --git a/vlib/sokol/gfx/gfx_funcs.v b/vlib/sokol/gfx/gfx_funcs.v index 25459ef700..8a3a8b37c5 100644 --- a/vlib/sokol/gfx/gfx_funcs.v +++ b/vlib/sokol/gfx/gfx_funcs.v @@ -19,6 +19,7 @@ fn C.sg_destroy_pass(pass C.sg_pass) fn C.sg_update_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) fn C.sg_update_image(img C.sg_image, content &C.sg_image_content) fn C.sg_append_buffer(buf C.sg_buffer, ptr voidptr, num_bytes int) int +fn C.sg_query_buffer_overflow(buf C.sg_buffer) bool // rendering functions fn C.sg_begin_default_pass(actions &C.sg_pass_action, width int, height int) @@ -32,7 +33,19 @@ fn C.sg_draw(base_element int, num_elements int, num_instances int) fn C.sg_end_pass() fn C.sg_commit() -fn C.sg_query_buffer_overflow(buf C.sg_buffer) bool +// getting information +fn C.sg_query_desc() C.sg_desc +fn C.sg_query_backend() Backend +fn C.sg_query_features() C.sg_features +fn C.sg_query_limits() C.sg_limits +fn C.sg_query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info + +/* get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID) */ +fn C.sg_query_buffer_state(buf C.sg_buffer) C.sg_resource_state +fn C.sg_query_image_state(img C.sg_image) C.sg_resource_state +fn C.sg_query_shader_state(shd C.sg_shader) C.sg_resource_state +fn C.sg_query_pipeline_state(pip C.sg_pipeline) C.sg_resource_state +fn C.sg_query_pass_state(pass C.sg_pass) C.sg_resource_state // get runtime information about a resource fn C.sg_query_buffer_info(buf C.sg_buffer) C.sg_buffer_info @@ -41,16 +54,14 @@ fn C.sg_query_shader_info(shd C.sg_shader) C.sg_shader_info fn C.sg_query_pipeline_info(pip C.sg_pipeline) C.sg_pipeline_info fn C.sg_query_pass_info(pass C.sg_pass) C.sg_pass_info -// getting information -fn C.sg_query_desc() C.sg_desc -fn C.sg_query_backend() Backend -fn C.sg_query_features() C.sg_features -fn C.sg_query_limits() C.sg_limits -fn C.sg_query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info - // get resource creation desc struct with their default values replaced fn C.sg_query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc fn C.sg_query_image_defaults(desc &C.sg_image) C.sg_image_desc fn C.sg_query_shader_defaults(desc &C.sg_shader) C.sg_shader_desc fn C.sg_query_pipeline_defaults(desc &C.sg_pipeline) C.sg_pipeline_desc fn C.sg_query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc + +/* rendering contexts (optional) */ +fn C.sg_setup_context() C.sg_context +fn C.sg_activate_context(ctx_id C.sg_context) +fn C.sg_discard_context(ctx_id C.sg_context) \ No newline at end of file diff --git a/vlib/sokol/gfx/gfx_structs.v b/vlib/sokol/gfx/gfx_structs.v index ad061cf1ce..25c9fbf778 100644 --- a/vlib/sokol/gfx/gfx_structs.v +++ b/vlib/sokol/gfx/gfx_structs.v @@ -325,13 +325,13 @@ pub mut: pub struct C.sg_features { pub: - instancing bool - origin_top_left bool - multiple_render_targets bool - msaa_render_targets bool - imagetype_3d bool /* creation of SG_IMAGETYPE_3D images is supported */ - imagetype_array bool /* creation of SG_IMAGETYPE_ARRAY images is supported */ - image_clamp_to_border bool /* border color and clamp-to-border UV-wrap mode is supported */ + instancing bool /* hardware instancing supported */ + origin_top_left bool /* framebuffer and texture origin is in top left corner */ + multiple_render_targets bool /* offscreen render passes can have multiple render targets attached */ + msaa_render_targets bool /* offscreen render passes support MSAA antialiasing */ + imagetype_3d bool /* creation of SG_IMAGETYPE_3D images is supported */ + imagetype_array bool /* creation of SG_IMAGETYPE_ARRAY images is supported */ + image_clamp_to_border bool /* border color and clamp-to-border UV-wrap mode is supported */ } pub struct C.sg_limits { @@ -339,8 +339,8 @@ pub: max_image_size_2d u32 /* max width/height of SG_IMAGETYPE_2D images */ max_image_size_cube u32 /* max width/height of SG_IMAGETYPE_CUBE images */ max_image_size_3d u32 /* max width/height/depth of SG_IMAGETYPE_3D images */ - max_image_size_array u32 - max_image_array_layers u32 + max_image_size_array u32 /* max width/height pf SG_IMAGETYPE_ARRAY images */ + max_image_array_layers u32 /* max number of layers in SG_IMAGETYPE_ARRAY images */ max_vertex_attrs u32 /* <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) */ } diff --git a/vlib/sokol/sapp/enums.v b/vlib/sokol/sapp/enums.v index 8644b67f51..3cb20b9ff8 100644 --- a/vlib/sokol/sapp/enums.v +++ b/vlib/sokol/sapp/enums.v @@ -33,6 +33,13 @@ pub enum MouseButton { middle = 2 } +pub enum Modifier { + shift = 1 //(1<<0) + ctrl = 2 //(1<<1) + alt = 4 //(1<<2) + super = 8 //(1<<3) +} + pub enum KeyCode { invalid = 0 space = 32 diff --git a/vlib/sokol/sapp/sapp.v b/vlib/sokol/sapp/sapp.v index 332a7228e2..a204117e16 100644 --- a/vlib/sokol/sapp/sapp.v +++ b/vlib/sokol/sapp/sapp.v @@ -186,3 +186,8 @@ pub fn win32_get_hwnd() voidptr { return C.sapp_win32_get_hwnd() } +/* Android: get native activity handle */ +[inline] +pub fn android_get_native_activity() voidptr { + return C.sapp_android_get_native_activity() +} diff --git a/vlib/sokol/sapp/sapp_funcs.v b/vlib/sokol/sapp/sapp_funcs.v index 6427f339d5..12d6615fd3 100644 --- a/vlib/sokol/sapp/sapp_funcs.v +++ b/vlib/sokol/sapp/sapp_funcs.v @@ -67,3 +67,5 @@ fn C.sapp_d3d11_get_render_target_view() voidptr fn C.sapp_d3d11_get_depth_stencil_view() voidptr /* Win32: get the HWND window handle */ fn C.sapp_win32_get_hwnd() voidptr +/* Android: get native activity handle */ +fn C.sapp_android_get_native_activity() voidptr \ No newline at end of file diff --git a/vlib/sokol/sapp/sapp_structs.v b/vlib/sokol/sapp/sapp_structs.v index e6ed0882da..d0fdcaa9bb 100644 --- a/vlib/sokol/sapp/sapp_structs.v +++ b/vlib/sokol/sapp/sapp_structs.v @@ -5,7 +5,7 @@ pub: init_cb fn() /* these are the user-provided callbacks without user data */ frame_cb fn() cleanup_cb fn() - event_cb fn( voidptr) //&sapp_event) + event_cb fn(&C.sapp_event) //&sapp_event) fail_cb fn(byteptr) user_data voidptr /* these are the user-provided callbacks with user data */ @@ -13,7 +13,7 @@ pub: frame_userdata_cb fn(voidptr) cleanup_userdata_cb fn(voidptr) event_userdata_cb fn(&C.sapp_event, voidptr) - fail_userdata_cb fn(voidptr) + fail_userdata_cb fn(byteptr,voidptr) width int /* the preferred width of the window / canvas */ height int /* the preferred height of the window / canvas */