From 8e7cd6f3ac7e8aff6c7acd405aece45832850000 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 6 Oct 2023 09:27:11 +0300 Subject: [PATCH] sokol.gfx: update the V bindings for the new functionality in the Sokol GFX library --- vlib/sokol/gfx/enums.v | 145 +++++++++++++++------ vlib/sokol/gfx/gfx.c.v | 2 +- vlib/sokol/gfx/gfx_funcs.c.v | 77 +++++++++-- vlib/sokol/gfx/gfx_structs.c.v | 213 +++++++++++++++++++------------ vlib/sokol/gfx/gfx_utils.c.v | 2 +- vlib/sokol/sapp/sapp_structs.c.v | 1 + 6 files changed, 303 insertions(+), 137 deletions(-) diff --git a/vlib/sokol/gfx/enums.v b/vlib/sokol/gfx/enums.v index baaeacb9d8881b..85931e0068b3a3 100644 --- a/vlib/sokol/gfx/enums.v +++ b/vlib/sokol/gfx/enums.v @@ -12,13 +12,15 @@ pub enum Backend { } // PixelFormat is C.sg_pixel_format -pub enum PixelFormat { +pub enum PixelFormat as u32 { _default // value 0 reserved for default-init @none + // r8 r8sn r8ui r8si + // r16 r16sn r16ui @@ -28,6 +30,7 @@ pub enum PixelFormat { rg8sn rg8ui rg8si + // r32ui r32si r32f @@ -44,6 +47,7 @@ pub enum PixelFormat { bgra8 rgb10a2 rg11b10f + // rg32ui rg32si rg32f @@ -52,11 +56,14 @@ pub enum PixelFormat { rgba16ui rgba16si rgba16f + // rgba32ui rgba32si rgba32f + // depth depth_stencil + // bc1_rgba bc2_rgba bc3_rgba @@ -76,47 +83,74 @@ pub enum PixelFormat { etc2_rgba8 etc2_rg11 etc2_rg11sn + // + rgb9e5 + // _num + _force_u32 = 0x7FFFFFFF } -pub enum ResourceState { +pub enum ResourceState as u32 { initial alloc valid failed invalid + _force_u32 = 0x7FFFFFFF } -pub enum Usage { +pub enum Usage as u32 { _default // value 0 reserved for default-init immutable dynamic stream _num + _force_u32 = 0x7FFFFFFF } -pub enum BufferType { +pub enum BufferType as u32 { _default // value 0 reserved for default-init vertexbuffer indexbuffer _num + _force_u32 = 0x7FFFFFFF } -pub enum IndexType { +pub enum IndexType as u32 { _default // value 0 reserved for default-init @none uint16 uint32 _num + _force_u32 = 0x7FFFFFFF } -pub enum ImageType { +pub enum ImageType as u32 { _default // value 0 reserved for default-init _2d cube _3d array _num + _force_u32 = 0x7FFFFFFF +} + +pub enum ImageSampleType as u32 { + _default // value 0 reserved for default-init + float + depth + sint + uint + _num + _force_u32 = 0x7FFFFFFF +} + +pub enum SamplerType as u32 { + _default + sample + compare + _num + _force_u32 = 0x7FFFFFFF } pub enum CubeFace as u32 { @@ -130,12 +164,13 @@ pub enum CubeFace as u32 { _force_u32 = 0x7fffffff } -pub enum ShaderStage { +pub enum ShaderStage as u32 { vs fs + _force_u32 = 0x7FFFFFFF } -pub enum PrimitiveType { +pub enum PrimitiveType as u32 { _default // value 0 reserved for default-init points lines @@ -143,37 +178,38 @@ pub enum PrimitiveType { triangles triangle_strip _num + _force_u32 = 0x7FFFFFFF } -pub enum Filter { +pub enum Filter as u32 { _default // value 0 reserved for default-init + @none nearest linear - nearest_mipmap_nearest - nearest_mipmap_linear - linear_mipmap_nearest - linear_mipmap_linear _num + _force_u32 = 0x7fffffff } -pub enum Wrap { +pub enum Wrap as u32 { _default // value 0 reserved for default-init - repeat + repeat // The default wrap mode. clamp_to_edge - clamp_to_border + clamp_to_border // not supported on all backends and platforms. To check for support, call sg_query_features(), and check the "clamp_to_border" boolean in the returned sg_features struct. Platforms which don't support SG_WRAP_CLAMP_TO_BORDER will silently fall back to clamp_to_edge without a validation error. mirrored_repeat _num + _force_u32 = 0x7FFFFFFF } -pub enum BorderColor { +pub enum BorderColor as u32 { _default // value 0 reserved for default-init transparent_black opaque_black opaque_white _num + _force_u32 = 0x7FFFFFFF } -pub enum VertexFormat { +pub enum VertexFormat as u32 { invalid float float2 @@ -190,43 +226,54 @@ pub enum VertexFormat { short4n ushort4n uint10_n2 + half2 + half4 _num + _force_u32 = 0x7FFFFFFF } -pub enum VertexStep { +pub enum VertexStep as u32 { _default // value 0 reserved for default-init per_vertex per_instance _num + _force_u32 = 0x7FFFFFFF } -pub enum UniformType { +pub enum UniformType as u32 { invalid float float2 float3 float4 + int + int2 + int3 + int4 mat4 _num + _force_u32 = 0x7FFFFFFF } -pub enum CullMode { +pub enum CullMode as u32 { _default // value 0 reserved for default-init @none front back _num + _force_u32 = 0x7FFFFFFF } // FaceWindin is C.sg_face_winding -pub enum FaceWinding { +pub enum FaceWinding as u32 { _facewinding_default // value 0 reserved for default-init facewinding_ccw facewinding_cw _facewinding_num + _force_u32 = 0x7FFFFFFF } -pub enum CompareFunc { +pub enum CompareFunc as u32 { _default // value 0 reserved for default-init never less @@ -237,9 +284,10 @@ pub enum CompareFunc { greater_equal always _num + _force_u32 = 0x7FFFFFFF } -pub enum StencilOp { +pub enum StencilOp as u32 { _default // value 0 reserved for default-init keep zero @@ -250,9 +298,10 @@ pub enum StencilOp { incr_wrap decr_wrap _num + _force_u32 = 0x7FFFFFFF } -pub enum BlendFactor { +pub enum BlendFactor as u32 { _default // value 0 reserved for default-init zero one @@ -270,38 +319,58 @@ pub enum BlendFactor { blend_alpha one_minus_blend_alpha _num + _force_u32 = 0x7FFFFFFF } -pub enum BlendOp { +pub enum BlendOp as u32 { _default // value 0 reserved for default-init add subtract reverse_subtract _num + _force_u32 = 0x7FFFFFFF } -pub enum ColorMask { - _default = 0 // value 0 reserved for default-init - @none = 0x10 // special value for 'all channels disabled - r = 1 - g = 2 - b = 4 - a = 8 - rgb = 0x7 - rgba = 0xF +pub enum ColorMask as u32 { + _default = 0 // value 0 reserved for default-init + @none = 0x10 // special value for 'all channels disabled + r = 1 + g = 2 + rg = 3 + b = 4 + rb = 5 + gb = 6 + rgb = 7 + a = 8 + ra = 9 + ga = 0xa + rga = 0xb + ba = 0xc + rba = 0xd + gba = 0xe + rgba = 0xf + _force_u32 = 0x7FFFFFFF } -pub enum Action { +pub enum LoadAction as u32 { _default clear load dontcare - _num + _force_u32 = 0x7FFFFFFF +} + +pub enum StoreAction as u32 { + _default + store + dontcare + _force_u32 = 0x7FFFFFFF } -pub enum UniformLayout { +pub enum UniformLayout as u32 { uniformlayout_default = 0 // value 0 reserved for default-init uniformlayout_native // default: layout depends on currently active backend uniformlayout_std140 // std140: memory layout according to std140 _num + _force_u32 = 0x7FFFFFFF } diff --git a/vlib/sokol/gfx/gfx.c.v b/vlib/sokol/gfx/gfx.c.v index 3e23a6b3a91683..9324f57e640fb4 100644 --- a/vlib/sokol/gfx/gfx.c.v +++ b/vlib/sokol/gfx/gfx.c.v @@ -143,7 +143,7 @@ pub fn apply_bindings(bindings &Bindings) { [inline] pub fn apply_uniforms(stage ShaderStage, ub_index int, data &Range) { - C.sg_apply_uniforms(int(stage), ub_index, data) + C.sg_apply_uniforms(stage, ub_index, data) } [inline] diff --git a/vlib/sokol/gfx/gfx_funcs.c.v b/vlib/sokol/gfx/gfx_funcs.c.v index b8e85a1975bef3..f0d90f88980d96 100644 --- a/vlib/sokol/gfx/gfx_funcs.c.v +++ b/vlib/sokol/gfx/gfx_funcs.c.v @@ -1,19 +1,26 @@ module gfx // setup and misc functions -fn C.sg_setup(desc &C.sg_desc) +fn C.sg_setup(const_desc &C.sg_desc) fn C.sg_shutdown() fn C.sg_isvalid() bool fn C.sg_reset_state_cache() +fn C.sg_install_trace_hooks(const_trace_hooks &C.sg_trace_hooks) C.sg_trace_hooks +fn C.sg_push_debug_group(const_name &char) +fn C.sg_pop_debug_group() +fn C.sg_add_commit_listener(listener C.sg_commit_listener) bool +fn C.sg_remove_commit_listener(listener C.sg_commit_listener) bool // resource creation, destruction and updating -fn C.sg_make_buffer(desc &C.sg_buffer_desc) C.sg_buffer -fn C.sg_make_image(desc &C.sg_image_desc) C.sg_image -fn C.sg_make_shader(desc &C.sg_shader_desc) C.sg_shader -fn C.sg_make_pipeline(desc &C.sg_pipeline_desc) C.sg_pipeline -fn C.sg_make_pass(desc &C.sg_pass_desc) C.sg_pass +fn C.sg_make_buffer(const_desc &C.sg_buffer_desc) C.sg_buffer +fn C.sg_make_image(const_desc &C.sg_image_desc) C.sg_image +fn C.sg_make_sampler(const_desc &C.sg_sampler_desc) C.sg_sampler +fn C.sg_make_shader(const_desc &C.sg_shader_desc) C.sg_shader +fn C.sg_make_pipeline(const_desc &C.sg_pipeline_desc) C.sg_pipeline +fn C.sg_make_pass(const_desc &C.sg_pass_desc) C.sg_pass fn C.sg_destroy_buffer(buf C.sg_buffer) fn C.sg_destroy_image(img C.sg_image) +fn C.sg_destroy_sampler(smp C.sg_sampler) fn C.sg_destroy_shader(shd C.sg_shader) fn C.sg_destroy_pipeline(pip C.sg_pipeline) fn C.sg_destroy_pass(pass C.sg_pass) @@ -21,6 +28,7 @@ fn C.sg_update_buffer(buf C.sg_buffer, data &C.sg_range) fn C.sg_update_image(img C.sg_image, data &C.sg_image_data) fn C.sg_append_buffer(buf C.sg_buffer, data &C.sg_range) int fn C.sg_query_buffer_overflow(buf C.sg_buffer) bool +fn C.sg_query_buffer_will_overflow(buf C.sg_buffer, size usize) bool // rendering functions fn C.sg_begin_default_pass(actions &C.sg_pass_action, width int, height int) @@ -31,9 +39,7 @@ fn C.sg_apply_scissor_rect(x int, y int, width int, height int, origin_top_left fn C.sg_apply_scissor_rectf(x f32, y f32, width f32, height f32, origin_top_left bool) fn C.sg_apply_pipeline(pip C.sg_pipeline) fn C.sg_apply_bindings(bindings &C.sg_bindings) - -// stage == sg_shader_stage -fn C.sg_apply_uniforms(stage int, ub_index int, data &C.sg_range) +fn C.sg_apply_uniforms(stage ShaderStage, ub_index int, const_data &C.sg_range) fn C.sg_draw(base_element int, num_elements int, num_instances int) fn C.sg_end_pass() fn C.sg_commit() @@ -48,6 +54,7 @@ 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_sampler_state(smp C.sg_sampler) C.sg_sampler_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 @@ -55,16 +62,58 @@ 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 fn C.sg_query_image_info(img C.sg_image) C.sg_image_info +fn C.sg_query_sampler_info(smp C.sg_sampler) C.sg_sampler_info 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 +// get desc structs matching a specific resource (NOTE that not all creation attributes may be provided) +fn C.sg_query_buffer_desc(buf C.sg_buffer) C.sg_buffer_desc +fn C.sg_query_image_desc(img C.sg_image) C.sg_image_desc +fn C.sg_query_sampler_desc(smp C.sg_sampler) C.sg_sampler_desc +fn C.sg_query_shader_desc(shd C.sg_shader) C.sg_shader_desc +fn C.sg_query_pipeline_desc(pip C.sg_pipeline) C.sg_pipeline_desc +fn C.sg_query_pass_desc(pass C.sg_pass) C.sg_pass_desc + // get resource creation desc struct with their default values replaced -fn C.sg_query_buffer_defaults(desc &C.sg_buffer_desc) C.sg_buffer_desc -fn C.sg_query_image_defaults(desc &C.sg_image_desc) C.sg_image_desc -fn C.sg_query_shader_defaults(desc &C.sg_shader_desc) C.sg_shader_desc -fn C.sg_query_pipeline_defaults(desc &C.sg_pipeline_desc) C.sg_pipeline_desc -fn C.sg_query_pass_defaults(desc &C.sg_pass_desc) C.sg_pass_desc +fn C.sg_query_buffer_defaults(const_desc &C.sg_buffer_desc) C.sg_buffer_desc +fn C.sg_query_image_defaults(const_desc &C.sg_image_desc) C.sg_image_desc +fn C.sg_query_sampler_defaults(const_desc &C.sg_sampler_desc) C.sg_sampler_desc +fn C.sg_query_shader_defaults(const_desc &C.sg_shader_desc) C.sg_shader_desc +fn C.sg_query_pipeline_defaults(const_desc &C.sg_pipeline_desc) C.sg_pipeline_desc +fn C.sg_query_pass_defaults(const_desc &C.sg_pass_desc) C.sg_pass_desc + +// separate resource allocation and initialization (for async setup) +fn C.sg_alloc_buffer() C.sg_buffer +fn C.sg_alloc_image() C.sg_image +fn C.sg_alloc_sampler() C.sg_sampler +fn C.sg_alloc_shader() C.sg_shader +fn C.sg_alloc_pipeline() C.sg_pipeline +fn C.sg_alloc_pass() C.sg_pass +fn C.sg_dealloc_buffer(buf C.sg_buffer) +fn C.sg_dealloc_image(img C.sg_image) +fn C.sg_dealloc_sampler(smp C.sg_sampler) +fn C.sg_dealloc_shader(shd C.sg_shader) +fn C.sg_dealloc_pipeline(pip C.sg_pipeline) +fn C.sg_dealloc_pass(pass C.sg_pass) +fn C.sg_init_buffer(buf C.sg_buffer, const_desc &C.sg_buffer_desc) +fn C.sg_init_image(img C.sg_image, const_desc &C.sg_buffer_desc) +fn C.sg_init_sampler(smg C.sg_sampler, const_desc &C.sg_sampler_desc) +fn C.sg_init_shader(shd C.sg_shader, const_desc &C.sg_shader_desc) +fn C.sg_init_pipeline(pip C.sg_pipeline, const_desc &C.sg_pipeline_desc) +fn C.sg_init_pass(pass C.sg_pass, const_desc &C.sg_pass_desc) +fn C.sg_uninit_buffer(buf C.sg_buffer) +fn C.sg_uninit_image(img C.sg_image) +fn C.sg_uninit_sampler(smp C.sg_sampler) +fn C.sg_uninit_shader(shd C.sg_shader) +fn C.sg_uninit_pipeline(pip C.sg_pipeline) +fn C.sg_uninit_pass(pass C.sg_pass) +fn C.sg_fail_buffer(buf C.sg_buffer) +fn C.sg_fail_image(img C.sg_image) +fn C.sg_fail_sampler(smp C.sg_sampler) +fn C.sg_fail_shader(shd C.sg_shader) +fn C.sg_fail_pipeline(pip C.sg_pipeline) +fn C.sg_fail_pass(pass C.sg_pass) // rendering contexts (optional) fn C.sg_setup_context() C.sg_context diff --git a/vlib/sokol/gfx/gfx_structs.c.v b/vlib/sokol/gfx/gfx_structs.c.v index 442271fb178ac1..3c44bcb0814e80 100644 --- a/vlib/sokol/gfx/gfx_structs.c.v +++ b/vlib/sokol/gfx/gfx_structs.c.v @@ -3,24 +3,23 @@ module gfx // C.sg_desc describes pub struct C.sg_desc { pub mut: - _start_canary u32 - buffer_pool_size int - image_pool_size int - shader_pool_size int - pipeline_pool_size int - pass_pool_size int - context_pool_size int - uniform_buffer_size int - staging_buffer_size int - sampler_pool_size int - max_commit_listeners int - disable_validation bool // disable validation layer even in debug mode, useful for tests + buffer_pool_size int + image_pool_size int + sampler_pool_size int + shader_pool_size int + pipeline_pool_size int + pass_pool_size int + context_pool_size int + uniform_buffer_size int + staging_buffer_size int + max_commit_listeners int + disable_validation bool // disable validation layer even in debug mode, useful for tests + mtl_force_managed_storage_mode bool // for debugging: use Metal managed storage mode for resources even with UMA // allocator C.sg_allocator logger C.sg_logger // - context ContextDesc - _end_canary u32 + context C.sg_context_desc } pub type Desc = C.sg_desc @@ -72,7 +71,6 @@ pub type ColorState = C.sg_color_target_state pub struct C.sg_pipeline_desc { pub mut: - _start_canary u32 shader Shader layout LayoutDesc depth DepthState @@ -87,12 +85,13 @@ pub mut: blend_color Color alpha_to_coverage_enabled bool label &char = &char(0) - _end_canary u32 } pub type PipelineDesc = C.sg_pipeline_desc -struct C.sg_pipeline_info { +pub struct C.sg_pipeline_info { +pub: + slot SlotInfo } pub type PipelineInfo = C.sg_pipeline_info @@ -110,7 +109,6 @@ pub fn (mut p C.sg_pipeline) free() { struct C.sg_bindings { pub mut: - _start_canary u32 vertex_buffers [8]Buffer vertex_buffer_offsets [8]int index_buffer Buffer @@ -119,12 +117,12 @@ pub mut: fs C.sg_stage_bindings // vs_images [8]Image // old // fs_images [8]Image // old - _end_canary u32 } pub struct C.sg_stage_bindings { pub mut: - images [12]Image + images [12]Image + samplers [8]Sampler } pub type Bindings = C.sg_bindings @@ -172,12 +170,10 @@ pub fn (b &Bindings) append_index_buffer(data voidptr, element_size int, element [heap] struct C.sg_shader_desc { pub mut: - _start_canary u32 - attrs [16]ShaderAttrDesc - vs ShaderStageDesc - fs ShaderStageDesc - label &char - _end_canary u32 + attrs [16]ShaderAttrDesc + vs ShaderStageDesc + fs ShaderStageDesc + label &char } pub type ShaderDesc = C.sg_shader_desc @@ -241,11 +237,14 @@ pub type ShaderAttrDesc = C.sg_shader_attr_desc struct C.sg_shader_stage_desc { pub mut: - source &char - bytecode Range - entry &char - uniform_blocks [4]ShaderUniformBlockDesc - images [12]ShaderImageDesc + source &char + bytecode Range + entry &char + d3d11_target &char + uniform_blocks [4]ShaderUniformBlockDesc + images [12]ShaderImageDesc + samplers [8]ShaderSamplerDesc + image_sampler_pairs [12]ShaderImageSamplerPairDesc } pub type ShaderStageDesc = C.sg_shader_stage_desc @@ -279,17 +278,39 @@ pub mut: used bool multisampled bool // name &char - image_type ImageType + image_type ImageType + sample_type ImageSampleType } pub type ShaderImageDesc = C.sg_shader_image_desc -struct C.sg_shader_info { +pub struct C.sg_shader_sampler_desc { +pub mut: + used bool + sampler_type SamplerType +} + +pub type ShaderSamplerDesc = C.sg_shader_sampler_desc + +pub struct C.sg_shader_image_sampler_pair_desc { +pub mut: + used bool + image_slot int + sampler_slot int + glsl_name &char +} + +pub type ShaderImageSamplerPairDesc = C.sg_shader_image_sampler_pair_desc + +pub struct C.sg_shader_info { +pub: + slot SlotInfo } pub type ShaderInfo = C.sg_shader_info -struct C.sg_context { +pub struct C.sg_context { +pub: id u32 } @@ -326,11 +347,9 @@ pub fn (mut s Shader) free() { struct C.sg_pass_desc { pub mut: - _start_canary u32 color_attachments [4]PassAttachmentDesc depth_stencil_attachment PassAttachmentDesc label &char - _end_canary u32 } pub type PassDesc = C.sg_pass_desc @@ -343,11 +362,9 @@ pub type PassInfo = C.sg_pass_info pub struct C.sg_pass_action { pub mut: - _start_canary u32 - colors [4]ColorAttachmentAction - depth DepthAttachmentAction - stencil StencilAttachmentAction - _end_canary u32 + colors [4]ColorAttachmentAction + depth DepthAttachmentAction + stencil StencilAttachmentAction } pub type PassAction = C.sg_pass_action @@ -364,19 +381,16 @@ pub fn (mut p Pass) free() { struct C.sg_buffer_desc { pub mut: - _start_canary u32 - size usize - @type BufferType - usage Usage - data Range - label &char - // GL specific - gl_buffers [2]u32 - // Metal specific - mtl_buffers [2]voidptr - // D3D11 specific + size usize + @type BufferType + usage Usage + data Range + label &char + // backend-specific resources + gl_buffers [2]u32 + mtl_buffers [2]voidptr d3d11_buffer voidptr - _end_canary u32 + wgpu_buffer voidptr } pub type BufferDesc = C.sg_buffer_desc @@ -389,7 +403,15 @@ struct C.sg_slot_info { pub type SlotInfo = C.sg_slot_info -struct C.sg_buffer_info { +pub struct C.sg_buffer_info { +pub: + slot SlotInfo + update_frame_index u32 + append_frame_index u32 + append_pos int + append_overflow bool + num_slots int + active_slot int } pub type BufferInfo = C.sg_buffer_info @@ -406,7 +428,6 @@ pub fn (mut b Buffer) free() { pub struct C.sg_image_desc { pub mut: - _start_canary u32 @type ImageType render_target bool width int @@ -427,17 +448,13 @@ pub mut: // max_lod f32 data ImageData label &char - // GL specific - gl_textures [2]u32 - gl_texture_target u32 - // Metal specific - mtl_textures [2]voidptr - // D3D11 specific + // backend-specific resources + gl_textures [2]u32 + gl_texture_target u32 + mtl_textures [2]voidptr d3d11_texture voidptr d3d11_shader_resource_view voidptr - // WebGPU specific - wgpu_texture voidptr - _end_canary u32 + wgpu_texture voidptr } pub type ImageDesc = C.sg_image_desc @@ -445,13 +462,21 @@ pub type ImageDesc = C.sg_image_desc pub struct C.sg_sampler_desc { min_filter Filter mag_filter Filter + mipmap_filter Filter wrap_u Wrap wrap_v Wrap wrap_w Wrap min_lod f32 max_lod f32 border_color BorderColor + compare CompareFunc max_anisotropy u32 + label &char + // backend-specific resources + gl_sampler u32 + mtl_sampler voidptr + d3d11_sampler voidptr + wgpu_sampler voidptr } pub struct C.sg_image_info { @@ -475,7 +500,12 @@ pub fn (mut i Image) free() { C.sg_destroy_image(*i) } -pub struct C.sg_sampler {} +pub struct C.sg_sampler { +pub: + id u32 +} + +pub type Sampler = C.sg_sampler pub const sg_cubeface_num = 6 @@ -490,27 +520,29 @@ pub type ImageData = C.sg_image_data struct C.sg_features { pub: - 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 mrt_independent_blend_state bool // multiple-render-target rendering can use per-render-target blend state mrt_independent_write_mask bool // multiple-render-target rendering can use per-render-target color write masks + // instancing bool // hardware instancing supported + // 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 } pub type Features = C.sg_features pub struct C.sg_limits { 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 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) + max_image_size_2d int // max width/height of SG_IMAGETYPE_2D images + max_image_size_cube int // max width/height of SG_IMAGETYPE_CUBE images + max_image_size_3d int // max width/height/depth of SG_IMAGETYPE_3D images + max_image_size_array int // max width/height pf SG_IMAGETYPE_ARRAY images + max_image_array_layers int // max number of layers in SG_IMAGETYPE_ARRAY images + max_vertex_attrs int // <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) + gl_max_vertex_uniform_vectors int // <= GL_MAX_VERTEX_UNIFORM_VECTORS (only on GL backends) + gl_max_combined_texture_image_units int // <= GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (only on GL backends) } pub type Limits = C.sg_limits @@ -564,10 +596,10 @@ struct C.sg_depth_state { pub type DepthState = C.sg_depth_state struct C.sg_stencil_face_state { + compare CompareFunc fail_op StencilOp depth_fail_op StencilOp pass_op StencilOp - compare_func CompareFunc } pub type StencilFaceState = C.sg_stencil_face_state @@ -587,8 +619,9 @@ pub type BlendState = C.sg_blend_state struct C.sg_color_attachment_action { pub mut: - load_action Action - clear_value Color + load_action LoadAction + store_action StoreAction + clear_value Color } pub type ColorAttachmentAction = C.sg_color_attachment_action @@ -603,16 +636,18 @@ pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32 */ pub struct C.sg_depth_attachment_action { pub mut: - load_action Action - clear_value f32 + load_action LoadAction + store_action StoreAction + clear_value f32 } pub type DepthAttachmentAction = C.sg_depth_attachment_action pub struct C.sg_stencil_attachment_action { pub mut: - load_action Action - clear_value u8 + load_action LoadAction + store_action StoreAction + clear_value u8 } pub type StencilAttachmentAction = C.sg_stencil_attachment_action @@ -644,3 +679,15 @@ pub mut: } pub type PassAttachmentDesc = C.sg_pass_attachment_desc + +// C.sg_commit_listener is used with sg_add_commit_listener, to add a callback, +// which will be called in sg_commit(). This is useful for libraries building +// on top of sokol-gfx to be notified about when a frame ends (instead of having +// to guess, or add a manual 'new-frame' function). +pub struct C.sg_commit_listener { +pub: + func fn (user_data voidptr) + user_data voidptr +} + +pub type CommitListener = C.sg_commit_listener diff --git a/vlib/sokol/gfx/gfx_utils.c.v b/vlib/sokol/gfx/gfx_utils.c.v index dc6b9eda47933d..01cbc2ffaa29c8 100644 --- a/vlib/sokol/gfx/gfx_utils.c.v +++ b/vlib/sokol/gfx/gfx_utils.c.v @@ -2,7 +2,7 @@ module gfx pub fn create_clear_pass(r f32, g f32, b f32, a f32) PassAction { mut color_action := ColorAttachmentAction{ - load_action: Action.clear // unsafe { Action(C.SG_ACTION_CLEAR) } + load_action: .clear // unsafe { Action(C.SG_ACTION_CLEAR) } clear_value: Color{ r: r g: g diff --git a/vlib/sokol/sapp/sapp_structs.c.v b/vlib/sokol/sapp/sapp_structs.c.v index 55d695d4cf54d5..5c13a2a54c2cff 100644 --- a/vlib/sokol/sapp/sapp_structs.c.v +++ b/vlib/sokol/sapp/sapp_structs.c.v @@ -7,6 +7,7 @@ const ( max_iconimages = 8 ) +// sapp_range is a general pointer/size-pair struct for passing binary blobs into sokol_app.h [typedef] pub struct C.sapp_range { pub: