1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sokol: type alias all gfx structs (#13014)

This commit is contained in:
Larpon
2022-01-02 19:36:01 +01:00
committed by GitHub
parent 41e763f79c
commit 4d4398fa8a
25 changed files with 531 additions and 431 deletions

View File

@@ -9,7 +9,7 @@ pub const (
// setup and misc functions
[inline]
pub fn setup(desc &C.sg_desc) {
pub fn setup(desc &Desc) {
C.sg_setup(desc)
}
@@ -30,83 +30,83 @@ pub fn reset_state_cache() {
// resource creation, destruction and updating
[inline]
pub fn make_buffer(desc &C.sg_buffer_desc) C.sg_buffer {
pub fn make_buffer(desc &BufferDesc) Buffer {
return C.sg_make_buffer(desc)
}
[inline]
pub fn make_image(desc &C.sg_image_desc) C.sg_image {
pub fn make_image(desc &ImageDesc) Image {
return C.sg_make_image(desc)
}
[inline]
pub fn make_shader(desc &C.sg_shader_desc) C.sg_shader {
pub fn make_shader(desc &ShaderDesc) Shader {
return C.sg_make_shader(desc)
}
[inline]
pub fn make_pipeline(desc &C.sg_pipeline_desc) C.sg_pipeline {
pub fn make_pipeline(desc &PipelineDesc) Pipeline {
return C.sg_make_pipeline(desc)
}
[inline]
pub fn make_pass(desc &C.sg_pass_desc) C.sg_pass {
pub fn make_pass(desc &PassDesc) Pass {
return C.sg_make_pass(desc)
}
[inline]
pub fn destroy_buffer(buf C.sg_buffer) {
pub fn destroy_buffer(buf Buffer) {
C.sg_destroy_buffer(buf)
}
[inline]
pub fn destroy_image(img C.sg_image) {
pub fn destroy_image(img Image) {
C.sg_destroy_image(img)
}
[inline]
pub fn destroy_shader(shd C.sg_shader) {
pub fn destroy_shader(shd Shader) {
C.sg_destroy_shader(shd)
}
[inline]
pub fn destroy_pipeline(pip C.sg_pipeline) {
pub fn destroy_pipeline(pip Pipeline) {
C.sg_destroy_pipeline(pip)
}
[inline]
pub fn destroy_pass(pass C.sg_pass) {
pub fn destroy_pass(pass Pass) {
C.sg_destroy_pass(pass)
}
[inline]
pub fn update_buffer(buf C.sg_buffer, data &C.sg_range) {
pub fn update_buffer(buf Buffer, data &Range) {
C.sg_update_buffer(buf, data)
}
[inline]
pub fn update_image(img C.sg_image, data &C.sg_image_data) {
pub fn update_image(img Image, data &ImageData) {
C.sg_update_image(img, data)
}
[inline]
pub fn append_buffer(buf C.sg_buffer, data &C.sg_range) int {
pub fn append_buffer(buf Buffer, data &Range) int {
return C.sg_append_buffer(buf, data)
}
[inline]
pub fn query_buffer_overflow(buf C.sg_buffer) bool {
pub fn query_buffer_overflow(buf 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) {
pub fn begin_default_pass(actions &PassAction, width int, height int) {
C.sg_begin_default_pass(actions, width, height)
}
[inline]
pub fn begin_pass(pass C.sg_pass, actions &C.sg_pass_action) {
pub fn begin_pass(pass Pass, actions &PassAction) {
C.sg_begin_pass(pass, actions)
}
@@ -121,17 +121,17 @@ pub fn apply_scissor_rect(x int, y int, width int, height int, origin_top_left b
}
[inline]
pub fn apply_pipeline(pip C.sg_pipeline) {
pub fn apply_pipeline(pip Pipeline) {
C.sg_apply_pipeline(pip)
}
[inline]
pub fn apply_bindings(bindings &C.sg_bindings) {
pub fn apply_bindings(bindings &Bindings) {
C.sg_apply_bindings(bindings)
}
[inline]
pub fn apply_uniforms(stage int, ub_index int, data &C.sg_range) {
pub fn apply_uniforms(stage int, ub_index int, data &Range) {
C.sg_apply_uniforms(stage, ub_index, data)
}
@@ -152,120 +152,120 @@ pub fn commit() {
// getting information
[inline]
pub fn query_desc() C.sg_desc {
pub fn query_desc() Desc {
return C.sg_query_desc()
}
[inline]
pub fn query_backend() Backend {
return Backend(C.sg_query_backend())
return C.sg_query_backend()
}
[inline]
pub fn query_features() C.sg_features {
pub fn query_features() Features {
return C.sg_query_features()
}
[inline]
pub fn query_limits() C.sg_limits {
pub fn query_limits() Limits {
return C.sg_query_limits()
}
[inline]
pub fn query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info {
pub fn query_pixelformat(fmt PixelFormat) PixelFormatInfo {
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 C.sg_query_buffer_state(buf)
pub fn query_buffer_state(buf Buffer) ResourceState {
return ResourceState(C.sg_query_buffer_state(buf))
}
[inline]
pub fn query_image_state(img C.sg_image) C.sg_resource_state {
return C.sg_query_image_state(img)
pub fn query_image_state(img Image) ResourceState {
return ResourceState(C.sg_query_image_state(img))
}
[inline]
pub fn query_shader_state(shd C.sg_shader) C.sg_resource_state {
return C.sg_query_shader_state(shd)
pub fn query_shader_state(shd Shader) ResourceState {
return ResourceState(C.sg_query_shader_state(shd))
}
[inline]
pub fn query_pipeline_state(pip C.sg_pipeline) C.sg_resource_state {
return C.sg_query_pipeline_state(pip)
pub fn query_pipeline_state(pip Pipeline) ResourceState {
return ResourceState(C.sg_query_pipeline_state(pip))
}
[inline]
pub fn query_pass_state(pass C.sg_pass) C.sg_resource_state {
return C.sg_query_pass_state(pass)
pub fn query_pass_state(pass Pass) ResourceState {
return ResourceState(C.sg_query_pass_state(pass))
}
// get runtime information about a resource
[inline]
pub fn query_buffer_info(buf C.sg_buffer) C.sg_buffer_info {
pub fn query_buffer_info(buf Buffer) BufferInfo {
return C.sg_query_buffer_info(buf)
}
[inline]
pub fn query_image_info(img C.sg_image) C.sg_image_info {
pub fn query_image_info(img Image) ImageInfo {
return C.sg_query_image_info(img)
}
[inline]
pub fn query_shader_info(shd C.sg_shader) C.sg_shader_info {
pub fn query_shader_info(shd Shader) ShaderInfo {
return C.sg_query_shader_info(shd)
}
[inline]
pub fn query_pipeline_info(pip C.sg_pipeline) C.sg_pipeline_info {
pub fn query_pipeline_info(pip Pipeline) PipelineInfo {
return C.sg_query_pipeline_info(pip)
}
[inline]
pub fn query_pass_info(pass C.sg_pass) C.sg_pass_info {
pub fn query_pass_info(pass Pass) PassInfo {
return C.sg_query_pass_info(pass)
}
// get resource creation desc struct with their default values replaced
[inline]
pub fn query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc {
return C.sg_query_buffer_defaults(unsafe { &C.sg_buffer_desc(desc) })
pub fn query_buffer_defaults(desc &Buffer) BufferDesc {
return C.sg_query_buffer_defaults(unsafe { &BufferDesc(voidptr(desc)) })
}
[inline]
pub fn query_image_defaults(desc &C.sg_image) C.sg_image_desc {
return C.sg_query_image_defaults(unsafe { &C.sg_image_desc(desc) })
pub fn query_image_defaults(desc &Image) ImageDesc {
return C.sg_query_image_defaults(unsafe { &ImageDesc(voidptr(desc)) })
}
[inline]
pub fn query_shader_defaults(desc &C.sg_shader) C.sg_shader_desc {
return C.sg_query_shader_defaults(unsafe { &C.sg_shader_desc(desc) })
pub fn query_shader_defaults(desc &Shader) ShaderDesc {
return C.sg_query_shader_defaults(unsafe { &ShaderDesc(voidptr(desc)) })
}
[inline]
pub fn query_pipeline_defaults(desc &C.sg_pipeline) C.sg_pipeline_desc {
return C.sg_query_pipeline_defaults(unsafe { &C.sg_pipeline_desc(desc) })
pub fn query_pipeline_defaults(desc &Pipeline) PipelineDesc {
return C.sg_query_pipeline_defaults(unsafe { &PipelineDesc(voidptr(desc)) })
}
[inline]
pub fn query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc {
return C.sg_query_pass_defaults(unsafe { &C.sg_pass_desc(desc) })
pub fn query_pass_defaults(desc &Pass) PassDesc {
return C.sg_query_pass_defaults(unsafe { &PassDesc(voidptr(desc)) })
}
// rendering contexts (optional)
[inline]
pub fn setup_context() C.sg_context {
pub fn setup_context() Context {
return C.sg_setup_context()
}
[inline]
pub fn activate_context(ctx_id C.sg_context) {
pub fn activate_context(ctx_id Context) {
C.sg_activate_context(ctx_id)
}
[inline]
pub fn discard_context(ctx_id C.sg_context) {
pub fn discard_context(ctx_id Context) {
C.sg_discard_context(ctx_id)
}

View File

@@ -1,6 +1,6 @@
module gfx
pub struct C.sg_desc {
struct C.sg_desc {
_start_canary u32
buffer_pool_size int
image_pool_size int
@@ -8,7 +8,7 @@ pub struct C.sg_desc {
pipeline_pool_size int
pass_pool_size int
context_pool_size int
context C.sg_context_desc
context ContextDesc
/*
// GL specific
gl_force_gles2 bool
@@ -27,7 +27,9 @@ pub struct C.sg_desc {
_end_canary u32
}
pub struct C.sg_context_desc {
pub type Desc = C.sg_desc
struct C.sg_context_desc {
/*
sg_pixel_format color_format;
sg_pixel_format depth_format;
@@ -35,115 +37,133 @@ pub struct C.sg_context_desc {
sg_wgpu_context_desc wgpu;
*/
sample_count int
gl C.sg_gl_context_desc
metal C.sg_metal_context_desc
d3d11 C.sg_d3d11_context_desc
gl GLContextDesc
metal MetalContextDesc
d3d11 D3D11ContextDesc
color_format PixelFormat
depth_format PixelFormat
}
pub struct C.sg_gl_context_desc {
pub type ContextDesc = C.sg_context_desc
struct C.sg_gl_context_desc {
force_gles2 bool
}
pub struct C.sg_metal_context_desc {
pub type GLContextDesc = C.sg_gl_context_desc
struct C.sg_metal_context_desc {
device voidptr
renderpass_descriptor_cb fn () voidptr
drawable_cb fn () voidptr
}
pub struct C.sg_d3d11_context_desc {
pub type MetalContextDesc = C.sg_metal_context_desc
struct C.sg_d3d11_context_desc {
device voidptr
device_context voidptr
render_target_view_cb fn () voidptr
depth_stencil_view_cb fn () voidptr
}
pub struct C.sg_color_state {
pub type D3D11ContextDesc = C.sg_d3d11_context_desc
struct C.sg_color_state {
pub mut:
pixel_format PixelFormat
write_mask ColorMask
blend C.sg_blend_state
blend BlendState
}
pub struct C.sg_pipeline_desc {
pub type ColorState = C.sg_color_state
struct C.sg_pipeline_desc {
pub mut:
_start_canary u32
shader C.sg_shader
layout C.sg_layout_desc
depth C.sg_depth_state
stencil C.sg_stencil_state
shader Shader
layout LayoutDesc
depth DepthState
stencil StencilState
color_count int
colors [4]C.sg_color_state // C.SG_MAX_COLOR_ATTACHMENTS
colors [4]ColorState // C.SG_MAX_COLOR_ATTACHMENTS
primitive_type PrimitiveType
index_type IndexType
cull_mode CullMode
face_winding FaceWinding
sample_count int
blend_color C.sg_color
blend_color Color
alpha_to_coverage_enabled bool
label &char = &char(0)
_end_canary u32
}
pub struct C.sg_pipeline_info {
pub type PipelineDesc = C.sg_pipeline_desc
struct C.sg_pipeline_info {
}
pub struct C.sg_pipeline {
pub type PipelineInfo = C.sg_pipeline_info
struct C.sg_pipeline {
pub:
id u32
}
pub type Pipeline = C.sg_pipeline
pub fn (mut p C.sg_pipeline) free() {
C.sg_destroy_pipeline(*p)
}
pub struct C.sg_bindings {
struct C.sg_bindings {
pub mut:
_start_canary u32
vertex_buffers [8]C.sg_buffer
vertex_buffers [8]Buffer
vertex_buffer_offsets [8]int
index_buffer C.sg_buffer
index_buffer Buffer
index_buffer_offset int
vs_images [8]C.sg_image
fs_images [8]C.sg_image
vs_images [8]Image
fs_images [8]Image
_end_canary u32
}
pub fn (mut b C.sg_bindings) set_vert_image(index int, img C.sg_image) {
pub type Bindings = C.sg_bindings
pub fn (mut b Bindings) set_vert_image(index int, img Image) {
b.vs_images[index] = img
}
pub fn (mut b C.sg_bindings) set_frag_image(index int, img C.sg_image) {
pub fn (mut b Bindings) set_frag_image(index int, img Image) {
b.fs_images[index] = img
}
pub fn (b &C.sg_bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
range := C.sg_range{
pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) {
range := Range{
ptr: data
size: usize(element_size * element_count)
}
C.sg_update_buffer(b.vertex_buffers[index], &range)
}
pub fn (b &C.sg_bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int {
range := C.sg_range{
pub fn (b &Bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int {
range := Range{
ptr: data
size: usize(element_size * element_count)
}
return C.sg_append_buffer(b.vertex_buffers[index], &range)
}
pub fn (b &C.sg_bindings) update_index_buffer(data voidptr, element_size int, element_count int) {
range := C.sg_range{
pub fn (b &Bindings) update_index_buffer(data voidptr, element_size int, element_count int) {
range := Range{
ptr: data
size: usize(element_size * element_count)
}
C.sg_update_buffer(b.index_buffer, &range)
}
pub fn (b &C.sg_bindings) append_index_buffer(data voidptr, element_size int, element_count int) int {
range := C.sg_range{
pub fn (b &Bindings) append_index_buffer(data voidptr, element_size int, element_count int) int {
range := Range{
ptr: data
size: usize(element_size * element_count)
}
@@ -151,119 +171,137 @@ pub fn (b &C.sg_bindings) append_index_buffer(data voidptr, element_size int, el
}
[heap]
pub struct C.sg_shader_desc {
struct C.sg_shader_desc {
pub mut:
_start_canary u32
attrs [16]C.sg_shader_attr_desc
vs C.sg_shader_stage_desc
fs C.sg_shader_stage_desc
attrs [16]ShaderAttrDesc
vs ShaderStageDesc
fs ShaderStageDesc
label &char
_end_canary u32
}
pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &C.sg_shader_desc {
pub type ShaderDesc = C.sg_shader_desc
pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &ShaderDesc {
desc.vs.source = &char(src.str)
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &ShaderDesc {
desc.fs.source = &char(src.str)
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &ShaderDesc {
desc.vs.images[index].name = &char(name.str)
desc.vs.images[index].image_type = ._2d
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &ShaderDesc {
desc.fs.images[index].name = &char(name.str)
desc.fs.images[index].image_type = ._2d
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size usize) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size usize) &ShaderDesc {
desc.vs.uniform_blocks[block_index].size = size
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size usize) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size usize) &ShaderDesc {
desc.fs.uniform_blocks[block_index].size = size
return desc
}
pub fn (mut desc C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
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 {
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str)
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
}
pub fn (mut desc C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
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 {
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str)
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
}
pub fn (desc &C.sg_shader_desc) make_shader() C.sg_shader {
pub fn (desc &ShaderDesc) make_shader() Shader {
return C.sg_make_shader(desc)
}
pub struct C.sg_shader_attr_desc {
struct C.sg_shader_attr_desc {
pub mut:
name &char // GLSL vertex attribute name (only required for GLES2)
sem_name &char // HLSL semantic name
sem_index int // HLSL semantic index
}
pub struct C.sg_shader_stage_desc {
pub type ShaderAttrDesc = C.sg_shader_attr_desc
struct C.sg_shader_stage_desc {
pub mut:
source &char
bytecode C.sg_range
bytecode Range
entry &char
uniform_blocks [4]C.sg_shader_uniform_block_desc
images [12]C.sg_shader_image_desc
uniform_blocks [4]ShaderUniformBlockDesc
images [12]ShaderImageDesc
}
pub fn (mut desc C.sg_shader_stage_desc) set_image(index int, name string) C.sg_shader_stage_desc {
pub type ShaderStageDesc = C.sg_shader_stage_desc
pub fn (mut desc ShaderStageDesc) set_image(index int, name string) ShaderStageDesc {
desc.images[index].name = &char(name.str)
desc.images[index].image_type = ._2d
return *desc
}
pub struct C.sg_shader_uniform_block_desc {
struct C.sg_shader_uniform_block_desc {
pub mut:
size usize
uniforms [16]C.sg_shader_uniform_desc
uniforms [16]ShaderUniformDesc
}
pub struct C.sg_shader_uniform_desc {
pub type ShaderUniformBlockDesc = C.sg_shader_uniform_block_desc
struct C.sg_shader_uniform_desc {
pub mut:
name &char
@type UniformType
array_count int
}
pub struct C.sg_shader_image_desc {
pub type ShaderUniformDesc = C.sg_shader_uniform_desc
struct C.sg_shader_image_desc {
pub mut:
name &char
image_type ImageType
}
pub struct C.sg_shader_info {
pub type ShaderImageDesc = C.sg_shader_image_desc
struct C.sg_shader_info {
}
pub struct C.sg_context {
pub type ShaderInfo = C.sg_shader_info
struct C.sg_context {
id u32
}
pub struct C.sg_range {
pub type Context = C.sg_context
struct C.sg_range {
pub mut:
ptr voidptr
size usize
}
pub struct C.sg_color {
pub type Range = C.sg_range
struct C.sg_color {
pub mut:
r f32
g f32
@@ -271,52 +309,64 @@ pub mut:
a f32
}
pub struct C.sg_shader {
pub type Color = C.sg_color
struct C.sg_shader {
pub:
id u32
}
pub fn (mut s C.sg_shader) free() {
pub type Shader = C.sg_shader
pub fn (mut s Shader) free() {
C.sg_destroy_shader(*s)
}
pub struct C.sg_pass_desc {
struct C.sg_pass_desc {
pub mut:
_start_canary u32
color_attachments [4]C.sg_pass_attachment_desc
depth_stencil_attachment C.sg_pass_attachment_desc
color_attachments [4]PassAttachmentDesc
depth_stencil_attachment PassAttachmentDesc
label &char
_end_canary u32
}
pub struct C.sg_pass_info {
info C.sg_slot_info
pub type PassDesc = C.sg_pass_desc
struct C.sg_pass_info {
info SlotInfo
}
pub struct C.sg_pass_action {
pub type PassInfo = C.sg_pass_info
struct C.sg_pass_action {
pub mut:
_start_canary u32
colors [4]C.sg_color_attachment_action
depth C.sg_depth_attachment_action
stencil C.sg_stencil_attachment_action
colors [4]ColorAttachmentAction
depth DepthAttachmentAction
stencil StencilAttachmentAction
_end_canary u32
}
pub struct C.sg_pass {
pub type PassAction = C.sg_pass_action
struct C.sg_pass {
id u32
}
pub fn (mut p C.sg_pass) free() {
pub type Pass = C.sg_pass
pub fn (mut p Pass) free() {
C.sg_destroy_pass(*p)
}
pub struct C.sg_buffer_desc {
struct C.sg_buffer_desc {
pub mut:
_start_canary u32
size usize
@type BufferType
usage Usage
data C.sg_range
data Range
label &char
// GL specific
gl_buffers [2]u32
@@ -327,23 +377,32 @@ pub mut:
_end_canary u32
}
pub struct C.sg_buffer_info {
pub type BufferDesc = C.sg_buffer_desc
struct C.sg_slot_info {
state ResourceState
res_id u32
ctx_id u32
}
pub struct C.sg_buffer {
pub type SlotInfo = C.sg_slot_info
struct C.sg_buffer_info {
}
pub type BufferInfo = C.sg_buffer_info
struct C.sg_buffer {
id u32
}
pub fn (mut b C.sg_buffer) free() {
pub type Buffer = C.sg_buffer
pub fn (mut b Buffer) free() {
C.sg_destroy_buffer(*b)
}
pub struct DepthLayers {
depth int
layers int
}
pub struct C.sg_image_desc {
struct C.sg_image_desc {
pub mut:
_start_canary u32
@type ImageType
@@ -364,7 +423,7 @@ pub mut:
max_anisotropy u32
min_lod f32
max_lod f32
data C.sg_image_data
data ImageData
label &char
// GL specific
gl_textures [2]u32
@@ -379,20 +438,26 @@ pub mut:
_end_canary u32
}
pub struct C.sg_image_info {
pub type ImageDesc = C.sg_image_desc
struct C.sg_image_info {
pub mut:
slot C.sg_slot_info // 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
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
}
pub struct C.sg_image {
pub type ImageInfo = C.sg_image_info
struct C.sg_image {
pub:
id u32
}
pub fn (mut i C.sg_image) free() {
pub type Image = C.sg_image
pub fn (mut i Image) free() {
C.sg_destroy_image(*i)
}
@@ -400,12 +465,14 @@ pub const sg_cubeface_num = 6
pub const sg_max_mipmaps = 16
pub struct C.sg_image_data {
struct C.sg_image_data {
pub mut:
subimage [sg_cubeface_num][sg_max_mipmaps]C.sg_range
subimage [sg_cubeface_num][sg_max_mipmaps]Range
}
pub struct C.sg_features {
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
@@ -418,7 +485,9 @@ pub:
mrt_independent_write_mask bool // multiple-render-target rendering can use per-render-target color write masks
}
pub struct C.sg_limits {
pub type Features = C.sg_features
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
@@ -428,36 +497,46 @@ pub:
max_vertex_attrs u32 // <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls)
}
pub struct C.sg_layout_desc {
pub type Limits = C.sg_limits
struct C.sg_layout_desc {
pub mut:
buffers [8]C.sg_buffer_layout_desc
attrs [16]C.sg_vertex_attr_desc
buffers [8]BufferLayoutDesc
attrs [16]VertexAttrDesc
}
pub struct C.sg_buffer_layout_desc {
pub type LayoutDesc = C.sg_layout_desc
struct C.sg_buffer_layout_desc {
pub mut:
stride int
step_func VertexStep
step_rate int
}
pub struct C.sg_vertex_attr_desc {
pub type BufferLayoutDesc = C.sg_buffer_layout_desc
struct C.sg_vertex_attr_desc {
pub mut:
buffer_index int
offset int
format VertexFormat
}
pub struct C.sg_stencil_state {
pub type VertexAttrDesc = C.sg_vertex_attr_desc
struct C.sg_stencil_state {
enabled bool
front C.sg_stencil_face_state
back C.sg_stencil_face_state
front StencilFaceState
back StencilFaceState
read_mask byte
write_mask byte
ref byte
}
pub struct C.sg_depth_state {
pub type StencilState = C.sg_stencil_state
struct C.sg_depth_state {
pixel_format PixelFormat
compare CompareFunc
write_enabled bool
@@ -466,14 +545,18 @@ pub struct C.sg_depth_state {
bias_clamp f32
}
pub struct C.sg_stencil_face_state {
pub type DepthState = C.sg_depth_state
struct C.sg_stencil_face_state {
fail_op StencilOp
depth_fail_op StencilOp
pass_op StencilOp
compare_func CompareFunc
}
pub struct C.sg_blend_state {
pub type StencilFaceState = C.sg_stencil_face_state
struct C.sg_blend_state {
pub mut:
enabled bool
src_factor_rgb BlendFactor
@@ -484,12 +567,16 @@ pub mut:
op_alpha BlendOp
}
pub struct C.sg_color_attachment_action {
pub type BlendState = C.sg_blend_state
struct C.sg_color_attachment_action {
pub mut:
action Action
value C.sg_color
value Color
}
pub type ColorAttachmentAction = C.sg_color_attachment_action
/*
pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32) {
action.val[0] = r
@@ -498,19 +585,23 @@ pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32
action.val[3] = a
}
*/
pub struct C.sg_depth_attachment_action {
struct C.sg_depth_attachment_action {
pub mut:
action Action
value f32
}
pub struct C.sg_stencil_attachment_action {
pub type DepthAttachmentAction = C.sg_depth_attachment_action
struct C.sg_stencil_attachment_action {
pub mut:
action Action
value byte
}
pub struct C.sg_pixelformat_info {
pub type StencilAttachmentAction = C.sg_stencil_attachment_action
struct C.sg_pixelformat_info {
pub:
sample bool // pixel format can be sampled in shaders
filter bool // pixel format can be sampled with filtering
@@ -520,9 +611,11 @@ pub:
depth bool // pixel format is a depth format
}
pub struct C.sg_pass_attachment_desc {
pub type PixelFormatInfo = C.sg_pixelformat_info
struct C.sg_pass_attachment_desc {
pub mut:
image C.sg_image
image Image
mip_level int
face int
// image sg_image
@@ -533,3 +626,5 @@ pub mut:
// slice int
// }
}
pub type PassAttachmentDesc = C.sg_pass_attachment_desc

View File

@@ -1,9 +1,9 @@
module gfx
pub fn create_clear_pass(r f32, g f32, b f32, a f32) C.sg_pass_action {
mut color_action := C.sg_color_attachment_action{
pub fn create_clear_pass(r f32, g f32, b f32, a f32) PassAction {
mut color_action := ColorAttachmentAction{
action: Action(C.SG_ACTION_CLEAR)
value: C.sg_color{
value: Color{
r: r
g: g
b: b
@@ -11,7 +11,7 @@ pub fn create_clear_pass(r f32, g f32, b f32, a f32) C.sg_pass_action {
}
}
// color_action.set_color_values(r, g, b, a)
mut pass_action := C.sg_pass_action{}
mut pass_action := PassAction{}
pass_action.colors[0] = color_action
return pass_action
}