2020-01-16 22:45:47 +03:00
|
|
|
module gfx
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_desc {
|
2022-01-27 22:16:00 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_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
|
2022-01-02 21:36:01 +03:00
|
|
|
context ContextDesc
|
2020-10-18 09:48:13 +03:00
|
|
|
/*
|
|
|
|
// GL specific
|
2020-01-16 22:45:47 +03:00
|
|
|
gl_force_gles2 bool
|
2020-08-23 08:25:30 +03:00
|
|
|
// Metal-specific
|
2020-01-16 22:45:47 +03:00
|
|
|
mtl_device voidptr
|
|
|
|
mtl_renderpass_descriptor_cb fn() voidptr
|
|
|
|
mtl_drawable_cb fn() voidptr
|
|
|
|
mtl_global_uniform_buffer_size int
|
|
|
|
mtl_sampler_cache_size int
|
2020-08-23 08:25:30 +03:00
|
|
|
// D3D11-specific
|
2020-01-16 22:45:47 +03:00
|
|
|
d3d11_device voidptr
|
|
|
|
d3d11_device_context voidptr
|
|
|
|
d3d11_render_target_view_cb fn() voidptr
|
|
|
|
d3d11_depth_stencil_view_cb fn() voidptr
|
2020-10-18 09:48:13 +03:00
|
|
|
*/
|
2021-04-27 08:18:48 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Desc = C.sg_desc
|
|
|
|
|
|
|
|
struct C.sg_context_desc {
|
2022-01-27 22:16:00 +03:00
|
|
|
pub mut:
|
|
|
|
color_format PixelFormat
|
|
|
|
depth_format PixelFormat
|
2020-10-18 09:48:13 +03:00
|
|
|
sample_count int
|
2022-01-02 21:36:01 +03:00
|
|
|
gl GLContextDesc
|
|
|
|
metal MetalContextDesc
|
|
|
|
d3d11 D3D11ContextDesc
|
2022-01-27 22:16:00 +03:00
|
|
|
// TODO C.sg_wgpu_context_desc wgpu;
|
2020-08-23 08:25:30 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ContextDesc = C.sg_context_desc
|
|
|
|
|
|
|
|
struct C.sg_gl_context_desc {
|
2021-04-27 08:18:48 +03:00
|
|
|
force_gles2 bool
|
2020-08-23 08:25:30 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type GLContextDesc = C.sg_gl_context_desc
|
|
|
|
|
|
|
|
struct C.sg_metal_context_desc {
|
2020-10-18 09:48:13 +03:00
|
|
|
device voidptr
|
|
|
|
renderpass_descriptor_cb fn () voidptr
|
|
|
|
drawable_cb fn () voidptr
|
2020-08-23 08:25:30 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type MetalContextDesc = C.sg_metal_context_desc
|
|
|
|
|
|
|
|
struct C.sg_d3d11_context_desc {
|
2020-10-18 09:48:13 +03:00
|
|
|
device voidptr
|
|
|
|
device_context voidptr
|
|
|
|
render_target_view_cb fn () voidptr
|
|
|
|
depth_stencil_view_cb fn () voidptr
|
2020-08-23 08:25:30 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type D3D11ContextDesc = C.sg_d3d11_context_desc
|
|
|
|
|
|
|
|
struct C.sg_color_state {
|
2021-04-07 21:39:23 +03:00
|
|
|
pub mut:
|
|
|
|
pixel_format PixelFormat
|
|
|
|
write_mask ColorMask
|
2022-01-02 21:36:01 +03:00
|
|
|
blend BlendState
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ColorState = C.sg_color_state
|
|
|
|
|
|
|
|
struct C.sg_pipeline_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-04-07 21:39:23 +03:00
|
|
|
_start_canary u32
|
2022-01-02 21:36:01 +03:00
|
|
|
shader Shader
|
|
|
|
layout LayoutDesc
|
|
|
|
depth DepthState
|
|
|
|
stencil StencilState
|
2021-04-07 21:39:23 +03:00
|
|
|
color_count int
|
2022-01-02 21:36:01 +03:00
|
|
|
colors [4]ColorState // C.SG_MAX_COLOR_ATTACHMENTS
|
2021-04-07 21:39:23 +03:00
|
|
|
primitive_type PrimitiveType
|
|
|
|
index_type IndexType
|
|
|
|
cull_mode CullMode
|
|
|
|
face_winding FaceWinding
|
|
|
|
sample_count int
|
2022-01-02 21:36:01 +03:00
|
|
|
blend_color Color
|
2021-04-07 21:39:23 +03:00
|
|
|
alpha_to_coverage_enabled bool
|
2021-04-27 08:18:48 +03:00
|
|
|
label &char = &char(0)
|
2021-04-07 21:39:23 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PipelineDesc = C.sg_pipeline_desc
|
|
|
|
|
|
|
|
struct C.sg_pipeline_info {
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PipelineInfo = C.sg_pipeline_info
|
|
|
|
|
|
|
|
struct C.sg_pipeline {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2020-10-18 09:48:13 +03:00
|
|
|
id u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Pipeline = C.sg_pipeline
|
|
|
|
|
2021-09-09 09:15:21 +03:00
|
|
|
pub fn (mut p C.sg_pipeline) free() {
|
|
|
|
C.sg_destroy_pipeline(*p)
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_bindings {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
2022-01-02 21:36:01 +03:00
|
|
|
vertex_buffers [8]Buffer
|
2020-10-18 09:48:13 +03:00
|
|
|
vertex_buffer_offsets [8]int
|
2022-01-02 21:36:01 +03:00
|
|
|
index_buffer Buffer
|
2020-10-18 09:48:13 +03:00
|
|
|
index_buffer_offset int
|
2022-01-02 21:36:01 +03:00
|
|
|
vs_images [8]Image
|
|
|
|
fs_images [8]Image
|
2020-10-18 09:48:13 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Bindings = C.sg_bindings
|
|
|
|
|
|
|
|
pub fn (mut b Bindings) set_vert_image(index int, img Image) {
|
2020-10-18 09:48:13 +03:00
|
|
|
b.vs_images[index] = img
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut b Bindings) set_frag_image(index int, img Image) {
|
2020-10-18 09:48:13 +03:00
|
|
|
b.fs_images[index] = img
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
|
|
|
|
range := Range{
|
2021-04-07 21:39:23 +03:00
|
|
|
ptr: data
|
2021-09-08 13:09:32 +03:00
|
|
|
size: usize(element_size * element_count)
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
C.sg_update_buffer(b.vertex_buffers[index], &range)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (b &Bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int {
|
|
|
|
range := Range{
|
2021-04-07 21:39:23 +03:00
|
|
|
ptr: data
|
2021-09-08 13:09:32 +03:00
|
|
|
size: usize(element_size * element_count)
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
return C.sg_append_buffer(b.vertex_buffers[index], &range)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (b &Bindings) update_index_buffer(data voidptr, element_size int, element_count int) {
|
|
|
|
range := Range{
|
2021-04-07 21:39:23 +03:00
|
|
|
ptr: data
|
2021-09-08 13:09:32 +03:00
|
|
|
size: usize(element_size * element_count)
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
C.sg_update_buffer(b.index_buffer, &range)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (b &Bindings) append_index_buffer(data voidptr, element_size int, element_count int) int {
|
|
|
|
range := Range{
|
2021-04-07 21:39:23 +03:00
|
|
|
ptr: data
|
2021-09-08 13:09:32 +03:00
|
|
|
size: usize(element_size * element_count)
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
return C.sg_append_buffer(b.index_buffer, &range)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-05-07 15:58:48 +03:00
|
|
|
[heap]
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_shader_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
2022-01-02 21:36:01 +03:00
|
|
|
attrs [16]ShaderAttrDesc
|
|
|
|
vs ShaderStageDesc
|
|
|
|
fs ShaderStageDesc
|
2021-04-27 08:18:48 +03:00
|
|
|
label &char
|
2020-10-18 09:48:13 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderDesc = C.sg_shader_desc
|
|
|
|
|
|
|
|
pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.vs.source = &char(src.str)
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.fs.source = &char(src.str)
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.vs.images[index].name = &char(name.str)
|
2021-04-07 21:39:23 +03:00
|
|
|
desc.vs.images[index].image_type = ._2d
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.fs.images[index].name = &char(name.str)
|
2021-04-07 21:39:23 +03:00
|
|
|
desc.fs.images[index].image_type = ._2d
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size usize) &ShaderDesc {
|
2020-10-18 09:48:13 +03:00
|
|
|
desc.vs.uniform_blocks[block_index].size = size
|
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size usize) &ShaderDesc {
|
2020-10-18 09:48:13 +03:00
|
|
|
desc.fs.uniform_blocks[block_index].size = size
|
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str)
|
2020-01-16 22:45:47 +03:00
|
|
|
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (mut desc C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &ShaderDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str)
|
2020-01-16 22:45:47 +03:00
|
|
|
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
|
2020-10-18 09:48:13 +03:00
|
|
|
return desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn (desc &ShaderDesc) make_shader() Shader {
|
2020-10-18 09:48:13 +03:00
|
|
|
return C.sg_make_shader(desc)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_shader_attr_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-04-27 08:18:48 +03:00
|
|
|
name &char // GLSL vertex attribute name (only required for GLES2)
|
|
|
|
sem_name &char // HLSL semantic name
|
|
|
|
sem_index int // HLSL semantic index
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderAttrDesc = C.sg_shader_attr_desc
|
|
|
|
|
|
|
|
struct C.sg_shader_stage_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-04-27 08:18:48 +03:00
|
|
|
source &char
|
2022-01-02 21:36:01 +03:00
|
|
|
bytecode Range
|
2021-04-27 08:18:48 +03:00
|
|
|
entry &char
|
2022-01-02 21:36:01 +03:00
|
|
|
uniform_blocks [4]ShaderUniformBlockDesc
|
|
|
|
images [12]ShaderImageDesc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderStageDesc = C.sg_shader_stage_desc
|
|
|
|
|
|
|
|
pub fn (mut desc ShaderStageDesc) set_image(index int, name string) ShaderStageDesc {
|
2021-04-19 15:38:48 +03:00
|
|
|
desc.images[index].name = &char(name.str)
|
2021-04-07 21:39:23 +03:00
|
|
|
desc.images[index].image_type = ._2d
|
2020-10-18 09:48:13 +03:00
|
|
|
return *desc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_shader_uniform_block_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-09-08 13:09:32 +03:00
|
|
|
size usize
|
2022-01-08 21:29:29 +03:00
|
|
|
layout UniformLayout
|
2022-01-02 21:36:01 +03:00
|
|
|
uniforms [16]ShaderUniformDesc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderUniformBlockDesc = C.sg_shader_uniform_block_desc
|
|
|
|
|
|
|
|
struct C.sg_shader_uniform_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-04-27 08:18:48 +03:00
|
|
|
name &char
|
2020-10-18 09:48:13 +03:00
|
|
|
@type UniformType
|
|
|
|
array_count int
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderUniformDesc = C.sg_shader_uniform_desc
|
|
|
|
|
|
|
|
struct C.sg_shader_image_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2021-04-27 08:18:48 +03:00
|
|
|
name &char
|
2021-04-07 21:39:23 +03:00
|
|
|
image_type ImageType
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderImageDesc = C.sg_shader_image_desc
|
|
|
|
|
|
|
|
struct C.sg_shader_info {
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ShaderInfo = C.sg_shader_info
|
|
|
|
|
|
|
|
struct C.sg_context {
|
2020-10-18 09:48:13 +03:00
|
|
|
id u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Context = C.sg_context
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_range {
|
2021-04-07 21:39:23 +03:00
|
|
|
pub mut:
|
|
|
|
ptr voidptr
|
2021-09-08 13:09:32 +03:00
|
|
|
size usize
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Range = C.sg_range
|
|
|
|
|
|
|
|
struct C.sg_color {
|
2021-04-07 21:39:23 +03:00
|
|
|
pub mut:
|
|
|
|
r f32
|
|
|
|
g f32
|
|
|
|
b f32
|
|
|
|
a f32
|
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Color = C.sg_color
|
|
|
|
|
|
|
|
struct C.sg_shader {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2020-10-18 09:48:13 +03:00
|
|
|
id u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Shader = C.sg_shader
|
|
|
|
|
|
|
|
pub fn (mut s Shader) free() {
|
2021-09-09 09:15:21 +03:00
|
|
|
C.sg_destroy_shader(*s)
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_pass_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
2022-01-02 21:36:01 +03:00
|
|
|
color_attachments [4]PassAttachmentDesc
|
|
|
|
depth_stencil_attachment PassAttachmentDesc
|
2021-04-27 08:18:48 +03:00
|
|
|
label &char
|
2020-10-18 09:48:13 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PassDesc = C.sg_pass_desc
|
|
|
|
|
|
|
|
struct C.sg_pass_info {
|
|
|
|
info SlotInfo
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PassInfo = C.sg_pass_info
|
|
|
|
|
|
|
|
struct C.sg_pass_action {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
2022-01-02 21:36:01 +03:00
|
|
|
colors [4]ColorAttachmentAction
|
|
|
|
depth DepthAttachmentAction
|
|
|
|
stencil StencilAttachmentAction
|
2020-10-18 09:48:13 +03:00
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PassAction = C.sg_pass_action
|
|
|
|
|
|
|
|
struct C.sg_pass {
|
2020-10-18 09:48:13 +03:00
|
|
|
id u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Pass = C.sg_pass
|
|
|
|
|
|
|
|
pub fn (mut p Pass) free() {
|
2021-09-09 09:15:21 +03:00
|
|
|
C.sg_destroy_pass(*p)
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
struct C.sg_buffer_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
2021-09-08 13:09:32 +03:00
|
|
|
size usize
|
2020-10-18 09:48:13 +03:00
|
|
|
@type BufferType
|
|
|
|
usage Usage
|
2022-01-02 21:36:01 +03:00
|
|
|
data Range
|
2021-04-27 08:18:48 +03:00
|
|
|
label &char
|
2020-10-18 09:48:13 +03:00
|
|
|
// GL specific
|
2021-04-27 08:18:48 +03:00
|
|
|
gl_buffers [2]u32
|
2020-10-18 09:48:13 +03:00
|
|
|
// Metal specific
|
2021-04-27 08:18:48 +03:00
|
|
|
mtl_buffers [2]voidptr
|
2020-10-18 09:48:13 +03:00
|
|
|
// D3D11 specific
|
2021-04-27 08:18:48 +03:00
|
|
|
d3d11_buffer voidptr
|
|
|
|
_end_canary u32
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type BufferDesc = C.sg_buffer_desc
|
|
|
|
|
|
|
|
struct C.sg_slot_info {
|
|
|
|
state ResourceState
|
|
|
|
res_id u32
|
|
|
|
ctx_id u32
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type SlotInfo = C.sg_slot_info
|
|
|
|
|
|
|
|
struct C.sg_buffer_info {
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type BufferInfo = C.sg_buffer_info
|
|
|
|
|
|
|
|
struct C.sg_buffer {
|
|
|
|
id u32
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Buffer = C.sg_buffer
|
|
|
|
|
|
|
|
pub fn (mut b Buffer) free() {
|
|
|
|
C.sg_destroy_buffer(*b)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_image_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
_start_canary u32
|
|
|
|
@type ImageType
|
|
|
|
render_target bool
|
|
|
|
width int
|
|
|
|
height int
|
2021-04-07 21:39:23 +03:00
|
|
|
num_slices int
|
2020-10-18 09:48:13 +03:00
|
|
|
num_mipmaps int
|
|
|
|
usage Usage
|
|
|
|
pixel_format PixelFormat
|
|
|
|
sample_count int
|
|
|
|
min_filter Filter
|
|
|
|
mag_filter Filter
|
|
|
|
wrap_u Wrap
|
|
|
|
wrap_v Wrap
|
|
|
|
wrap_w Wrap
|
|
|
|
border_color BorderColor
|
|
|
|
max_anisotropy u32
|
|
|
|
min_lod f32
|
|
|
|
max_lod f32
|
2022-01-02 21:36:01 +03:00
|
|
|
data ImageData
|
2021-04-27 08:18:48 +03:00
|
|
|
label &char
|
2020-10-18 09:48:13 +03:00
|
|
|
// GL specific
|
2021-04-27 08:18:48 +03:00
|
|
|
gl_textures [2]u32
|
2021-04-07 21:39:23 +03:00
|
|
|
gl_texture_target u32
|
2020-10-18 09:48:13 +03:00
|
|
|
// Metal specific
|
2021-04-27 08:18:48 +03:00
|
|
|
mtl_textures [2]voidptr
|
2020-10-18 09:48:13 +03:00
|
|
|
// D3D11 specific
|
2021-04-27 08:18:48 +03:00
|
|
|
d3d11_texture voidptr
|
2021-04-07 21:39:23 +03:00
|
|
|
d3d11_shader_resource_view voidptr
|
|
|
|
// WebGPU specific
|
2021-04-27 08:18:48 +03:00
|
|
|
wgpu_texture voidptr
|
|
|
|
_end_canary u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ImageDesc = C.sg_image_desc
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_image_info {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2022-01-02 21:36:01 +03:00
|
|
|
slot SlotInfo // resource pool slot info
|
|
|
|
upd_frame_index u32 // frame index of last sg_update_image()
|
|
|
|
num_slots int // number of renaming-slots for dynamically updated images
|
|
|
|
active_slot int // currently active write-slot for dynamically updated images
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ImageInfo = C.sg_image_info
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_image {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2020-10-18 09:48:13 +03:00
|
|
|
id u32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Image = C.sg_image
|
|
|
|
|
|
|
|
pub fn (mut i Image) free() {
|
2021-09-09 09:15:21 +03:00
|
|
|
C.sg_destroy_image(*i)
|
2020-10-18 09:48:13 +03:00
|
|
|
}
|
2020-01-16 22:45:47 +03:00
|
|
|
|
2021-06-24 17:45:14 +03:00
|
|
|
pub const sg_cubeface_num = 6
|
|
|
|
|
|
|
|
pub const sg_max_mipmaps = 16
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_image_data {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2022-01-02 21:36:01 +03:00
|
|
|
subimage [sg_cubeface_num][sg_max_mipmaps]Range
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ImageData = C.sg_image_data
|
|
|
|
|
|
|
|
struct C.sg_features {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2021-04-07 21:39:23 +03:00
|
|
|
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
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Features = C.sg_features
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_limits {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2020-10-18 09:48:13 +03:00
|
|
|
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)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type Limits = C.sg_limits
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_layout_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2022-01-02 21:36:01 +03:00
|
|
|
buffers [8]BufferLayoutDesc
|
|
|
|
attrs [16]VertexAttrDesc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type LayoutDesc = C.sg_layout_desc
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_buffer_layout_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
stride int
|
|
|
|
step_func VertexStep
|
|
|
|
step_rate int
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type BufferLayoutDesc = C.sg_buffer_layout_desc
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_vertex_attr_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
buffer_index int
|
|
|
|
offset int
|
|
|
|
format VertexFormat
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type VertexAttrDesc = C.sg_vertex_attr_desc
|
|
|
|
|
|
|
|
struct C.sg_stencil_state {
|
2021-04-27 08:18:48 +03:00
|
|
|
enabled bool
|
2022-01-02 21:36:01 +03:00
|
|
|
front StencilFaceState
|
|
|
|
back StencilFaceState
|
2022-04-15 18:25:45 +03:00
|
|
|
read_mask u8
|
|
|
|
write_mask u8
|
|
|
|
ref u8
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type StencilState = C.sg_stencil_state
|
|
|
|
|
|
|
|
struct C.sg_depth_state {
|
2021-04-27 08:18:48 +03:00
|
|
|
pixel_format PixelFormat
|
|
|
|
compare CompareFunc
|
|
|
|
write_enabled bool
|
|
|
|
bias f32
|
2021-04-07 21:39:23 +03:00
|
|
|
bias_slope_scale f32
|
2021-04-27 08:18:48 +03:00
|
|
|
bias_clamp f32
|
2021-04-07 21:39:23 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type DepthState = C.sg_depth_state
|
|
|
|
|
|
|
|
struct C.sg_stencil_face_state {
|
2020-10-18 09:48:13 +03:00
|
|
|
fail_op StencilOp
|
|
|
|
depth_fail_op StencilOp
|
|
|
|
pass_op StencilOp
|
|
|
|
compare_func CompareFunc
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type StencilFaceState = C.sg_stencil_face_state
|
|
|
|
|
|
|
|
struct C.sg_blend_state {
|
2020-08-03 00:30:08 +03:00
|
|
|
pub mut:
|
2021-04-27 08:18:48 +03:00
|
|
|
enabled bool
|
|
|
|
src_factor_rgb BlendFactor
|
|
|
|
dst_factor_rgb BlendFactor
|
|
|
|
op_rgb BlendOp
|
|
|
|
src_factor_alpha BlendFactor
|
|
|
|
dst_factor_alpha BlendFactor
|
|
|
|
op_alpha BlendOp
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type BlendState = C.sg_blend_state
|
|
|
|
|
|
|
|
struct C.sg_color_attachment_action {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
action Action
|
2022-01-02 21:36:01 +03:00
|
|
|
value Color
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type ColorAttachmentAction = C.sg_color_attachment_action
|
|
|
|
|
2020-05-15 19:55:29 +03:00
|
|
|
/*
|
2020-05-17 14:51:18 +03:00
|
|
|
pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
action.val[0] = r
|
|
|
|
action.val[1] = g
|
|
|
|
action.val[2] = b
|
|
|
|
action.val[3] = a
|
|
|
|
}
|
2020-05-15 19:55:29 +03:00
|
|
|
*/
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_depth_attachment_action {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
action Action
|
2021-04-07 21:39:23 +03:00
|
|
|
value f32
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type DepthAttachmentAction = C.sg_depth_attachment_action
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_stencil_attachment_action {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2020-10-18 09:48:13 +03:00
|
|
|
action Action
|
2022-04-15 18:25:45 +03:00
|
|
|
value u8
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type StencilAttachmentAction = C.sg_stencil_attachment_action
|
|
|
|
|
2022-06-19 19:47:41 +03:00
|
|
|
pub struct C.sg_pixelformat_info {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub:
|
2020-10-18 09:48:13 +03:00
|
|
|
sample bool // pixel format can be sampled in shaders
|
|
|
|
filter bool // pixel format can be sampled with filtering
|
|
|
|
render bool // pixel format can be used as render target
|
|
|
|
blend bool // alpha-blending is supported
|
|
|
|
msaa bool // pixel format can be used as MSAA render target
|
|
|
|
depth bool // pixel format is a depth format
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 21:36:01 +03:00
|
|
|
pub type PixelFormatInfo = C.sg_pixelformat_info
|
|
|
|
|
|
|
|
struct C.sg_pass_attachment_desc {
|
2020-01-16 22:45:47 +03:00
|
|
|
pub mut:
|
2022-01-02 21:36:01 +03:00
|
|
|
image Image
|
2020-10-18 09:48:13 +03:00
|
|
|
mip_level int
|
|
|
|
face int
|
|
|
|
// image sg_image
|
|
|
|
// mip_level int
|
|
|
|
// union {
|
|
|
|
// face int
|
|
|
|
// layer int
|
|
|
|
// slice int
|
|
|
|
// }
|
2020-01-22 23:34:38 +03:00
|
|
|
}
|
2022-01-02 21:36:01 +03:00
|
|
|
|
|
|
|
pub type PassAttachmentDesc = C.sg_pass_attachment_desc
|