| 1 | module gfx |
| 2 | |
| 3 | // C.sg_desc describes |
| 4 | pub struct C.sg_desc { |
| 5 | pub mut: |
| 6 | _start_canary u32 |
| 7 | buffer_pool_size int |
| 8 | image_pool_size int |
| 9 | sampler_pool_size int |
| 10 | shader_pool_size int |
| 11 | pipeline_pool_size int |
| 12 | attachments_pool_size int |
| 13 | uniform_buffer_size int |
| 14 | max_commit_listeners int |
| 15 | disable_validation bool // disable validation layer even in debug mode, useful for tests |
| 16 | mtl_force_managed_storage_mode bool // for debugging: use Metal managed storage mode for resources even with UMA |
| 17 | mtl_use_command_buffer_with_retained_references bool // Metal: use a managed MTLCommandBuffer which ref-counts used resources |
| 18 | wgpu_disable_bindgroups_cache bool // set to true to disable the WebGPU backend BindGroup cache |
| 19 | wgpu_bindgroups_cache_size int // number of slots in the WebGPU bindgroup cache (must be 2^N) |
| 20 | allocator C.sg_allocator |
| 21 | logger C.sg_logger // optional log function override |
| 22 | environment C.sg_environment |
| 23 | _end_canary u32 |
| 24 | } |
| 25 | |
| 26 | pub type Desc = C.sg_desc |
| 27 | |
| 28 | pub struct C.sg_color_target_state { |
| 29 | pub mut: |
| 30 | pixel_format PixelFormat |
| 31 | write_mask ColorMask |
| 32 | blend BlendState |
| 33 | } |
| 34 | |
| 35 | pub type ColorTargetState = C.sg_color_target_state |
| 36 | |
| 37 | pub struct C.sg_pipeline_desc { |
| 38 | pub mut: |
| 39 | shader Shader |
| 40 | layout VertexLayoutState |
| 41 | depth DepthState |
| 42 | stencil StencilState |
| 43 | color_count int |
| 44 | colors [4]ColorTargetState // C.SG_MAX_COLOR_ATTACHMENTS |
| 45 | primitive_type PrimitiveType |
| 46 | index_type IndexType |
| 47 | cull_mode CullMode |
| 48 | face_winding FaceWinding |
| 49 | sample_count int |
| 50 | blend_color Color |
| 51 | alpha_to_coverage_enabled bool |
| 52 | label &char = &char(unsafe { nil }) |
| 53 | } |
| 54 | |
| 55 | pub type PipelineDesc = C.sg_pipeline_desc |
| 56 | |
| 57 | pub struct C.sg_pipeline_info { |
| 58 | pub: |
| 59 | slot SlotInfo |
| 60 | } |
| 61 | |
| 62 | pub type PipelineInfo = C.sg_pipeline_info |
| 63 | |
| 64 | pub struct C.sg_pipeline { |
| 65 | pub: |
| 66 | id u32 |
| 67 | } |
| 68 | |
| 69 | pub type Pipeline = C.sg_pipeline |
| 70 | |
| 71 | pub fn (mut p C.sg_pipeline) free() { |
| 72 | C.sg_destroy_pipeline(*p) |
| 73 | } |
| 74 | |
| 75 | pub struct C.sg_attachments { |
| 76 | id u32 |
| 77 | } |
| 78 | |
| 79 | // Attachments represents data that can be attached to a render pass. |
| 80 | // See also: documentation at the top of thirdparty/sokol/sokol_gfx.h |
| 81 | pub type Attachments = C.sg_attachments |
| 82 | |
| 83 | // free frees the resources occupied by the struct |
| 84 | pub fn (mut a C.sg_attachments) free() { |
| 85 | C.sg_destroy_attachments(*a) |
| 86 | } |
| 87 | |
| 88 | pub struct C.sg_attachment_desc { |
| 89 | pub mut: |
| 90 | image Image |
| 91 | mip_level int |
| 92 | slice int |
| 93 | } |
| 94 | |
| 95 | pub type AttachmentDesc = C.sg_attachment_desc |
| 96 | |
| 97 | pub struct C.sg_attachments_desc { |
| 98 | pub mut: |
| 99 | _start_canary u32 |
| 100 | colors [4]AttachmentDesc |
| 101 | resolves [4]AttachmentDesc |
| 102 | depth_stencil AttachmentDesc |
| 103 | label &char = unsafe { nil } |
| 104 | _end_canary u32 |
| 105 | } |
| 106 | |
| 107 | pub type AttachmentsDesc = C.sg_attachments_desc |
| 108 | |
| 109 | pub struct C.sg_attachments_info { |
| 110 | pub mut: |
| 111 | slot SlotInfo // resource pool slot info |
| 112 | } |
| 113 | |
| 114 | pub type AttachmentsInfo = C.sg_attachments_info |
| 115 | |
| 116 | pub struct C.sg_bindings { |
| 117 | pub mut: |
| 118 | _start_canary u32 |
| 119 | vertex_buffers [8]Buffer |
| 120 | vertex_buffer_offsets [8]int |
| 121 | index_buffer Buffer |
| 122 | index_buffer_offset int |
| 123 | vs StageBindings |
| 124 | fs StageBindings |
| 125 | _end_canary u32 |
| 126 | // vs_images [8]Image // old |
| 127 | // fs_images [8]Image // old |
| 128 | } |
| 129 | |
| 130 | pub type Bindings = C.sg_bindings |
| 131 | |
| 132 | pub fn (mut b Bindings) set_vert_image(index int, img Image) { |
| 133 | b.vs.images[index] = img |
| 134 | } |
| 135 | |
| 136 | pub fn (mut b Bindings) set_frag_image(index int, img Image) { |
| 137 | b.fs.images[index] = img |
| 138 | } |
| 139 | |
| 140 | pub fn (b &Bindings) update_vert_buffer(index int, data voidptr, element_size int, element_count int) { |
| 141 | range := Range{ |
| 142 | ptr: data |
| 143 | size: usize(element_size * element_count) |
| 144 | } |
| 145 | C.sg_update_buffer(b.vertex_buffers[index], &range) |
| 146 | } |
| 147 | |
| 148 | pub fn (b &Bindings) append_vert_buffer(index int, data voidptr, element_size int, element_count int) int { |
| 149 | range := Range{ |
| 150 | ptr: data |
| 151 | size: usize(element_size * element_count) |
| 152 | } |
| 153 | return C.sg_append_buffer(b.vertex_buffers[index], &range) |
| 154 | } |
| 155 | |
| 156 | pub fn (b &Bindings) update_index_buffer(data voidptr, element_size int, element_count int) { |
| 157 | range := Range{ |
| 158 | ptr: data |
| 159 | size: usize(element_size * element_count) |
| 160 | } |
| 161 | C.sg_update_buffer(b.index_buffer, &range) |
| 162 | } |
| 163 | |
| 164 | pub fn (b &Bindings) append_index_buffer(data voidptr, element_size int, element_count int) int { |
| 165 | range := Range{ |
| 166 | ptr: data |
| 167 | size: usize(element_size * element_count) |
| 168 | } |
| 169 | return C.sg_append_buffer(b.index_buffer, &range) |
| 170 | } |
| 171 | |
| 172 | pub struct C.sg_stage_bindings { |
| 173 | pub mut: |
| 174 | images [12]Image |
| 175 | samplers [8]Sampler |
| 176 | storage_buffers [8]Buffer |
| 177 | } |
| 178 | |
| 179 | pub type StageBindings = C.sg_stage_bindings |
| 180 | |
| 181 | @[heap] |
| 182 | pub struct C.sg_shader_desc { |
| 183 | pub mut: |
| 184 | attrs [16]ShaderAttrDesc |
| 185 | vs ShaderStageDesc |
| 186 | fs ShaderStageDesc |
| 187 | label &char |
| 188 | } |
| 189 | |
| 190 | pub type ShaderDesc = C.sg_shader_desc |
| 191 | |
| 192 | pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &ShaderDesc { |
| 193 | desc.vs.source = &char(src.str) |
| 194 | return desc |
| 195 | } |
| 196 | |
| 197 | pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &ShaderDesc { |
| 198 | desc.fs.source = &char(src.str) |
| 199 | return desc |
| 200 | } |
| 201 | |
| 202 | pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &ShaderDesc { |
| 203 | // desc.vs.images[index].name = &char(name.str) |
| 204 | desc.vs.images[index].image_type = ._2d |
| 205 | return desc |
| 206 | } |
| 207 | |
| 208 | pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &ShaderDesc { |
| 209 | // desc.fs.images[index].name = &char(name.str) |
| 210 | desc.fs.images[index].image_type = ._2d |
| 211 | return desc |
| 212 | } |
| 213 | |
| 214 | pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size usize) &ShaderDesc { |
| 215 | desc.vs.uniform_blocks[block_index].size = size |
| 216 | return desc |
| 217 | } |
| 218 | |
| 219 | pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size usize) &ShaderDesc { |
| 220 | desc.fs.uniform_blocks[block_index].size = size |
| 221 | return desc |
| 222 | } |
| 223 | |
| 224 | pub fn (mut desc C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, typ UniformType, |
| 225 | array_count int) &ShaderDesc { |
| 226 | desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str) |
| 227 | desc.vs.uniform_blocks[block_index].uniforms[uniform_index].type = typ |
| 228 | desc.vs.uniform_blocks[block_index].uniforms[uniform_index].array_count = array_count |
| 229 | return desc |
| 230 | } |
| 231 | |
| 232 | pub fn (mut desc C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, typ UniformType, |
| 233 | array_count int) &ShaderDesc { |
| 234 | desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = &char(name.str) |
| 235 | desc.fs.uniform_blocks[block_index].uniforms[uniform_index].type = typ |
| 236 | desc.fs.uniform_blocks[block_index].uniforms[uniform_index].array_count = array_count |
| 237 | return desc |
| 238 | } |
| 239 | |
| 240 | pub fn (desc &ShaderDesc) make_shader() Shader { |
| 241 | return C.sg_make_shader(desc) |
| 242 | } |
| 243 | |
| 244 | pub struct C.sg_shader_attr_desc { |
| 245 | pub mut: |
| 246 | name &char // GLSL vertex attribute name (only required for GLES2) |
| 247 | sem_name &char // HLSL semantic name |
| 248 | sem_index int // HLSL semantic index |
| 249 | } |
| 250 | |
| 251 | pub type ShaderAttrDesc = C.sg_shader_attr_desc |
| 252 | |
| 253 | pub struct C.sg_shader_stage_desc { |
| 254 | pub mut: |
| 255 | source &char |
| 256 | bytecode Range |
| 257 | entry &char |
| 258 | d3d11_target &char |
| 259 | uniform_blocks [4]ShaderUniformBlockDesc |
| 260 | storage_buffers [8]ShaderStorageBufferDesc |
| 261 | images [12]ShaderImageDesc |
| 262 | samplers [8]ShaderSamplerDesc |
| 263 | image_sampler_pairs [12]ShaderImageSamplerPairDesc |
| 264 | } |
| 265 | |
| 266 | pub type ShaderStageDesc = C.sg_shader_stage_desc |
| 267 | |
| 268 | pub fn (mut desc ShaderStageDesc) set_image(index int, name string) ShaderStageDesc { |
| 269 | // desc.images[index].name = &char(name.str) |
| 270 | desc.images[index].image_type = ._2d |
| 271 | return *desc |
| 272 | } |
| 273 | |
| 274 | pub struct C.sg_shader_uniform_block_desc { |
| 275 | pub mut: |
| 276 | size usize |
| 277 | layout UniformLayout |
| 278 | uniforms [16]ShaderUniformDesc |
| 279 | } |
| 280 | |
| 281 | pub type ShaderUniformBlockDesc = C.sg_shader_uniform_block_desc |
| 282 | |
| 283 | pub struct C.sg_shader_uniform_desc { |
| 284 | pub mut: |
| 285 | name &char |
| 286 | type UniformType |
| 287 | array_count int |
| 288 | } |
| 289 | |
| 290 | pub type ShaderUniformDesc = C.sg_shader_uniform_desc |
| 291 | |
| 292 | pub struct C.sg_shader_image_desc { |
| 293 | pub mut: |
| 294 | used bool |
| 295 | multisampled bool |
| 296 | // name &char |
| 297 | image_type ImageType |
| 298 | sample_type ImageSampleType |
| 299 | } |
| 300 | |
| 301 | pub type ShaderImageDesc = C.sg_shader_image_desc |
| 302 | |
| 303 | pub struct C.sg_shader_storage_buffer_desc { |
| 304 | pub mut: |
| 305 | used bool |
| 306 | readonly bool |
| 307 | } |
| 308 | |
| 309 | pub type ShaderStorageBufferDesc = C.sg_shader_storage_buffer_desc |
| 310 | |
| 311 | pub struct C.sg_shader_sampler_desc { |
| 312 | pub mut: |
| 313 | used bool |
| 314 | sampler_type SamplerType |
| 315 | } |
| 316 | |
| 317 | pub type ShaderSamplerDesc = C.sg_shader_sampler_desc |
| 318 | |
| 319 | pub struct C.sg_shader_image_sampler_pair_desc { |
| 320 | pub mut: |
| 321 | used bool |
| 322 | image_slot int |
| 323 | sampler_slot int |
| 324 | glsl_name &char |
| 325 | } |
| 326 | |
| 327 | pub type ShaderImageSamplerPairDesc = C.sg_shader_image_sampler_pair_desc |
| 328 | |
| 329 | pub struct C.sg_shader_info { |
| 330 | pub: |
| 331 | slot SlotInfo |
| 332 | } |
| 333 | |
| 334 | pub type ShaderInfo = C.sg_shader_info |
| 335 | |
| 336 | pub struct C.sg_range { |
| 337 | pub mut: |
| 338 | ptr voidptr |
| 339 | size usize |
| 340 | } |
| 341 | |
| 342 | pub type Range = C.sg_range |
| 343 | |
| 344 | pub struct C.sg_color { |
| 345 | pub mut: |
| 346 | r f32 |
| 347 | g f32 |
| 348 | b f32 |
| 349 | a f32 |
| 350 | } |
| 351 | |
| 352 | pub type Color = C.sg_color |
| 353 | |
| 354 | pub struct C.sg_shader { |
| 355 | pub: |
| 356 | id u32 |
| 357 | } |
| 358 | |
| 359 | pub type Shader = C.sg_shader |
| 360 | |
| 361 | pub fn (mut s Shader) free() { |
| 362 | C.sg_destroy_shader(*s) |
| 363 | } |
| 364 | |
| 365 | @[typedef] |
| 366 | pub struct C.sg_frame_stats_gl { |
| 367 | num_bind_buffer u32 |
| 368 | num_active_texture u32 |
| 369 | num_bind_texture u32 |
| 370 | num_bind_sampler u32 |
| 371 | num_use_program u32 |
| 372 | num_render_state u32 |
| 373 | num_vertex_attrib_pointer u32 |
| 374 | num_vertex_attrib_divisor u32 |
| 375 | num_enable_vertex_attrib_array u32 |
| 376 | num_disable_vertex_attrib_array u32 |
| 377 | num_uniform u32 |
| 378 | } |
| 379 | |
| 380 | pub type FrameStatsGL = C.sg_frame_stats_gl |
| 381 | |
| 382 | @[typedef] |
| 383 | pub struct C.sg_frame_stats_d3d11_pass { |
| 384 | num_om_set_render_targets u32 |
| 385 | num_clear_render_target_view u32 |
| 386 | num_clear_depth_stencil_view u32 |
| 387 | num_resolve_subresource u32 |
| 388 | } |
| 389 | |
| 390 | pub type FrameStatsD3D11Pass = C.sg_frame_stats_d3d11_pass |
| 391 | |
| 392 | @[typedef] |
| 393 | pub struct C.sg_frame_stats_d3d11_pipeline { |
| 394 | num_rs_set_state u32 |
| 395 | num_om_set_depth_stencil_state u32 |
| 396 | num_om_set_blend_state u32 |
| 397 | num_ia_set_primitive_topology u32 |
| 398 | num_ia_set_input_layout u32 |
| 399 | num_vs_set_shader u32 |
| 400 | num_vs_set_constant_buffers u32 |
| 401 | num_ps_set_shader u32 |
| 402 | num_ps_set_constant_buffers u32 |
| 403 | } |
| 404 | |
| 405 | pub type FrameStatsD3D11Pipeline = C.sg_frame_stats_d3d11_pipeline |
| 406 | |
| 407 | @[typedef] |
| 408 | pub struct C.sg_frame_stats_d3d11_bindings { |
| 409 | num_ia_set_vertex_buffers u32 |
| 410 | num_ia_set_index_buffer u32 |
| 411 | num_vs_set_shader_resources u32 |
| 412 | num_ps_set_shader_resources u32 |
| 413 | num_vs_set_samplers u32 |
| 414 | num_ps_set_samplers u32 |
| 415 | } |
| 416 | |
| 417 | pub type FrameStatsD3D11Bindings = C.sg_frame_stats_d3d11_bindings |
| 418 | |
| 419 | @[typedef] |
| 420 | pub struct C.sg_frame_stats_d3d11_uniforms { |
| 421 | num_update_subresource u32 |
| 422 | } |
| 423 | |
| 424 | pub type FrameStatsD3D11Uniforms = C.sg_frame_stats_d3d11_uniforms |
| 425 | |
| 426 | @[typedef] |
| 427 | pub struct C.sg_frame_stats_d3d11_draw { |
| 428 | num_draw_indexed_instanced u32 |
| 429 | num_draw_indexed u32 |
| 430 | num_draw_instanced u32 |
| 431 | num_draw u32 |
| 432 | } |
| 433 | |
| 434 | pub type FrameStatsD3D11Draw = C.sg_frame_stats_d3d11_draw |
| 435 | |
| 436 | @[typedef] |
| 437 | pub struct C.sg_frame_stats_d3d11 { |
| 438 | pass FrameStatsD3D11Pass |
| 439 | pipeline FrameStatsD3D11Pipeline |
| 440 | bindings FrameStatsD3D11Bindings |
| 441 | uniforms FrameStatsD3D11Uniforms |
| 442 | draw FrameStatsD3D11Draw |
| 443 | num_map u32 |
| 444 | num_unmap u32 |
| 445 | } |
| 446 | |
| 447 | pub type FrameStatsD3D11 = C.sg_frame_stats_d3d11 |
| 448 | |
| 449 | @[typedef] |
| 450 | pub struct C.sg_frame_stats_metal_idpool { |
| 451 | num_added u32 |
| 452 | num_released u32 |
| 453 | num_garbage_collected u32 |
| 454 | } |
| 455 | |
| 456 | pub type FrameStatsMetalIdpool = C.sg_frame_stats_metal_idpool |
| 457 | |
| 458 | @[typedef] |
| 459 | pub struct C.sg_frame_stats_metal_pipeline { |
| 460 | num_set_blend_color u32 |
| 461 | num_set_cull_mode u32 |
| 462 | num_set_front_facing_winding u32 |
| 463 | num_set_stencil_reference_value u32 |
| 464 | num_set_depth_bias u32 |
| 465 | num_set_render_pipeline_state u32 |
| 466 | num_set_depth_stencil_state u32 |
| 467 | } |
| 468 | |
| 469 | pub type FrameStatsMetalPipeline = C.sg_frame_stats_metal_pipeline |
| 470 | |
| 471 | @[typedef] |
| 472 | pub struct C.sg_frame_stats_metal_bindings { |
| 473 | num_set_vertex_buffer u32 |
| 474 | num_set_vertex_texture u32 |
| 475 | num_set_vertex_sampler_state u32 |
| 476 | num_set_fragment_buffer u32 |
| 477 | num_set_fragment_texture u32 |
| 478 | num_set_fragment_sampler_state u32 |
| 479 | } |
| 480 | |
| 481 | pub type FrameStatsMetalBindings = C.sg_frame_stats_metal_bindings |
| 482 | |
| 483 | @[typedef] |
| 484 | pub struct C.sg_frame_stats_metal_uniforms { |
| 485 | num_set_vertex_buffer_offset u32 |
| 486 | num_set_fragment_buffer_offset u32 |
| 487 | } |
| 488 | |
| 489 | pub type FrameStatsMetalUniforms = C.sg_frame_stats_metal_uniforms |
| 490 | |
| 491 | @[typedef] |
| 492 | pub struct C.sg_frame_stats_metal { |
| 493 | idpool FrameStatsMetalIdpool |
| 494 | pipeline FrameStatsMetalPipeline |
| 495 | bindings FrameStatsMetalBindings |
| 496 | uniforms FrameStatsMetalUniforms |
| 497 | } |
| 498 | |
| 499 | pub type FrameStatsMetal = C.sg_frame_stats_metal |
| 500 | |
| 501 | @[typedef] |
| 502 | pub struct C.sg_frame_stats_wgpu_uniforms { |
| 503 | num_set_bindgroup u32 |
| 504 | size_write_buffer u32 |
| 505 | } |
| 506 | |
| 507 | pub type FrameStatsWGPUUniforms = C.sg_frame_stats_wgpu_uniforms |
| 508 | |
| 509 | @[typedef] |
| 510 | pub struct C.sg_frame_stats_wgpu_bindings { |
| 511 | num_set_vertex_buffer u32 |
| 512 | num_skip_redundant_vertex_buffer u32 |
| 513 | num_set_index_buffer u32 |
| 514 | num_skip_redundant_index_buffer u32 |
| 515 | num_create_bindgroup u32 |
| 516 | num_discard_bindgroup u32 |
| 517 | num_set_bindgroup u32 |
| 518 | num_skip_redundant_bindgroup u32 |
| 519 | num_bindgroup_cache_hits u32 |
| 520 | num_bindgroup_cache_misses u32 |
| 521 | num_bindgroup_cache_collisions u32 |
| 522 | num_bindgroup_cache_hash_vs_key_mismatch u32 |
| 523 | } |
| 524 | |
| 525 | pub type FrameStatsWGPUBindings = C.sg_frame_stats_wgpu_bindings |
| 526 | |
| 527 | @[typedef] |
| 528 | pub struct C.sg_frame_stats_wgpu { |
| 529 | uniforms FrameStatsWGPUUniforms |
| 530 | bindings FrameStatsWGPUBindings |
| 531 | } |
| 532 | |
| 533 | pub type FrameStatsWGPU = C.sg_frame_stats_wgpu |
| 534 | |
| 535 | @[typedef] |
| 536 | pub struct C.sg_frame_stats { |
| 537 | frame_index u32 // current frame counter, starts at 0 |
| 538 | |
| 539 | num_passes u32 |
| 540 | num_apply_viewport u32 |
| 541 | num_apply_scissor_rect u32 |
| 542 | num_apply_pipeline u32 |
| 543 | num_apply_bindings u32 |
| 544 | num_apply_uniforms u32 |
| 545 | num_draw u32 |
| 546 | num_update_buffer u32 |
| 547 | num_append_buffer u32 |
| 548 | num_update_image u32 |
| 549 | |
| 550 | size_apply_uniforms u32 |
| 551 | size_update_buffer u32 |
| 552 | size_append_buffer u32 |
| 553 | size_update_image u32 |
| 554 | |
| 555 | gl FrameStatsGL |
| 556 | d3d11 FrameStatsD3D11 |
| 557 | metal FrameStatsMetal |
| 558 | wgpu FrameStatsWGPU |
| 559 | } |
| 560 | |
| 561 | pub type FrameStats = C.sg_frame_stats |
| 562 | |
| 563 | pub struct C.sg_pass_action { |
| 564 | pub mut: |
| 565 | colors [4]ColorAttachmentAction |
| 566 | depth DepthAttachmentAction |
| 567 | stencil StencilAttachmentAction |
| 568 | } |
| 569 | |
| 570 | pub type PassAction = C.sg_pass_action |
| 571 | |
| 572 | @[typedef] |
| 573 | pub struct C.sg_metal_swapchain { |
| 574 | pub mut: |
| 575 | current_drawable voidptr |
| 576 | depth_stencil_texture voidptr // MTLTexture |
| 577 | msaa_color_texture voidptr // MTLTexture |
| 578 | } |
| 579 | |
| 580 | pub type MetalSwapchain = C.sg_metal_swapchain |
| 581 | |
| 582 | @[typedef] |
| 583 | pub struct C.sg_d3d11_swapchain { |
| 584 | pub mut: |
| 585 | render_view voidptr // ID3D11RenderTargetView |
| 586 | resolve_view voidptr // ID3D11RenderTargetView |
| 587 | depth_stencil_view voidptr // ID3D11DepthStencilView |
| 588 | } |
| 589 | |
| 590 | pub type D3d11Swapchain = C.sg_d3d11_swapchain |
| 591 | |
| 592 | @[typedef] |
| 593 | pub struct C.sg_wgpu_swapchain { |
| 594 | pub mut: |
| 595 | render_view voidptr // WGPUTextureView |
| 596 | resolve_view voidptr // WGPUTextureView |
| 597 | depth_stencil_view voidptr // WGPUTextureView |
| 598 | } |
| 599 | |
| 600 | pub type WgpuSwapchain = C.sg_wgpu_swapchain |
| 601 | |
| 602 | @[typedef] |
| 603 | pub struct C.sg_gl_swapchain { |
| 604 | pub mut: |
| 605 | framebuffer u32 |
| 606 | } |
| 607 | |
| 608 | pub type GlSwapchain = C.sg_gl_swapchain |
| 609 | |
| 610 | @[typedef] |
| 611 | pub struct C.sg_swapchain { |
| 612 | pub mut: |
| 613 | width int |
| 614 | height int |
| 615 | sample_count int |
| 616 | color_format PixelFormat |
| 617 | depth_format PixelFormat |
| 618 | metal MetalSwapchain |
| 619 | d3d11 D3d11Swapchain |
| 620 | wgpu WgpuSwapchain |
| 621 | gl GlSwapchain |
| 622 | } |
| 623 | |
| 624 | pub type Swapchain = C.sg_swapchain |
| 625 | |
| 626 | @[typedef] |
| 627 | pub struct C.sg_pass { |
| 628 | pub mut: |
| 629 | _start_canary u32 |
| 630 | action PassAction |
| 631 | attachments Attachments |
| 632 | swapchain Swapchain |
| 633 | label &char = unsafe { nil } |
| 634 | _end_canary u32 |
| 635 | } |
| 636 | |
| 637 | pub type Pass = C.sg_pass |
| 638 | |
| 639 | pub struct C.sg_buffer_desc { |
| 640 | pub mut: |
| 641 | size usize |
| 642 | type BufferType |
| 643 | usage Usage |
| 644 | data Range |
| 645 | label &char |
| 646 | // backend-specific resources |
| 647 | gl_buffers [2]u32 |
| 648 | mtl_buffers [2]voidptr |
| 649 | d3d11_buffer voidptr |
| 650 | wgpu_buffer voidptr |
| 651 | } |
| 652 | |
| 653 | pub type BufferDesc = C.sg_buffer_desc |
| 654 | |
| 655 | pub struct C.sg_slot_info { |
| 656 | state ResourceState |
| 657 | res_id u32 |
| 658 | ctx_id u32 |
| 659 | } |
| 660 | |
| 661 | pub type SlotInfo = C.sg_slot_info |
| 662 | |
| 663 | pub struct C.sg_buffer_info { |
| 664 | pub: |
| 665 | slot SlotInfo |
| 666 | update_frame_index u32 |
| 667 | append_frame_index u32 |
| 668 | append_pos int |
| 669 | append_overflow bool |
| 670 | num_slots int |
| 671 | active_slot int |
| 672 | } |
| 673 | |
| 674 | pub type BufferInfo = C.sg_buffer_info |
| 675 | |
| 676 | pub struct C.sg_buffer { |
| 677 | id u32 |
| 678 | } |
| 679 | |
| 680 | pub type Buffer = C.sg_buffer |
| 681 | |
| 682 | pub fn (mut b Buffer) free() { |
| 683 | C.sg_destroy_buffer(*b) |
| 684 | } |
| 685 | |
| 686 | pub struct C.sg_image_desc { |
| 687 | pub mut: |
| 688 | type ImageType |
| 689 | render_target bool |
| 690 | width int |
| 691 | height int |
| 692 | num_slices int |
| 693 | num_mipmaps int |
| 694 | usage Usage |
| 695 | pixel_format PixelFormat |
| 696 | sample_count int |
| 697 | // min_filter Filter |
| 698 | // mag_filter Filter |
| 699 | // wrap_u Wrap |
| 700 | // wrap_v Wrap |
| 701 | // wrap_w Wrap |
| 702 | // border_color BorderColor |
| 703 | // max_anisotropy u32 |
| 704 | // min_lod f32 |
| 705 | // max_lod f32 |
| 706 | data ImageData |
| 707 | label &char |
| 708 | // backend-specific resources |
| 709 | gl_textures [2]u32 |
| 710 | gl_texture_target u32 |
| 711 | mtl_textures [2]voidptr |
| 712 | d3d11_texture voidptr |
| 713 | d3d11_shader_resource_view voidptr |
| 714 | wgpu_texture voidptr |
| 715 | } |
| 716 | |
| 717 | pub type ImageDesc = C.sg_image_desc |
| 718 | |
| 719 | pub struct C.sg_sampler_desc { |
| 720 | min_filter Filter |
| 721 | mag_filter Filter |
| 722 | mipmap_filter Filter |
| 723 | wrap_u Wrap |
| 724 | wrap_v Wrap |
| 725 | wrap_w Wrap |
| 726 | min_lod f32 |
| 727 | max_lod f32 |
| 728 | border_color BorderColor |
| 729 | compare CompareFunc |
| 730 | max_anisotropy u32 |
| 731 | label &char |
| 732 | // backend-specific resources |
| 733 | gl_sampler u32 |
| 734 | mtl_sampler voidptr |
| 735 | d3d11_sampler voidptr |
| 736 | wgpu_sampler voidptr |
| 737 | } |
| 738 | |
| 739 | pub type SamplerDesc = C.sg_sampler_desc |
| 740 | |
| 741 | pub struct C.sg_image_info { |
| 742 | pub mut: |
| 743 | slot SlotInfo // resource pool slot info |
| 744 | upd_frame_index u32 // frame index of last sg_update_image() |
| 745 | num_slots int // number of renaming-slots for dynamically updated images |
| 746 | active_slot int // currently active write-slot for dynamically updated images |
| 747 | } |
| 748 | |
| 749 | pub type ImageInfo = C.sg_image_info |
| 750 | |
| 751 | pub struct C.sg_image { |
| 752 | pub mut: |
| 753 | id u32 |
| 754 | } |
| 755 | |
| 756 | pub type Image = C.sg_image |
| 757 | |
| 758 | pub fn (mut i Image) free() { |
| 759 | C.sg_destroy_image(*i) |
| 760 | } |
| 761 | |
| 762 | pub struct C.sg_sampler { |
| 763 | pub mut: |
| 764 | id u32 |
| 765 | } |
| 766 | |
| 767 | pub type Sampler = C.sg_sampler |
| 768 | |
| 769 | pub const sg_cubeface_num = 6 |
| 770 | |
| 771 | pub const sg_max_mipmaps = 16 |
| 772 | |
| 773 | pub struct C.sg_image_data { |
| 774 | pub mut: |
| 775 | subimage [sg_cubeface_num][sg_max_mipmaps]Range |
| 776 | } |
| 777 | |
| 778 | pub type ImageData = C.sg_image_data |
| 779 | |
| 780 | pub struct C.sg_features { |
| 781 | pub: |
| 782 | origin_top_left bool // framebuffer and texture origin is in top left corner |
| 783 | image_clamp_to_border bool // border color and clamp-to-border UV-wrap mode is supported |
| 784 | mrt_independent_blend_state bool // multiple-render-target rendering can use per-render-target blend state |
| 785 | mrt_independent_write_mask bool // multiple-render-target rendering can use per-render-target color write masks |
| 786 | storage_buffer bool // storage buffers are supported |
| 787 | } |
| 788 | |
| 789 | pub type Features = C.sg_features |
| 790 | |
| 791 | pub struct C.sg_limits { |
| 792 | pub: |
| 793 | max_image_size_2d int // max width/height of SG_IMAGETYPE_2D images |
| 794 | max_image_size_cube int // max width/height of SG_IMAGETYPE_CUBE images |
| 795 | max_image_size_3d int // max width/height/depth of SG_IMAGETYPE_3D images |
| 796 | max_image_size_array int // max width/height pf SG_IMAGETYPE_ARRAY images |
| 797 | max_image_array_layers int // max number of layers in SG_IMAGETYPE_ARRAY images |
| 798 | max_vertex_attrs int // <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) |
| 799 | gl_max_vertex_uniform_components int // <= GL_MAX_VERTEX_UNIFORM_COMPONENTS (only on GL backends) |
| 800 | gl_max_combined_texture_image_units int // <= GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (only on GL backends) |
| 801 | } |
| 802 | |
| 803 | pub type Limits = C.sg_limits |
| 804 | |
| 805 | pub struct C.sg_vertex_layout_state { |
| 806 | pub mut: |
| 807 | buffers [8]VertexBufferLayoutState |
| 808 | attrs [16]VertexAttrDesc |
| 809 | } |
| 810 | |
| 811 | pub type VertexLayoutState = C.sg_vertex_layout_state |
| 812 | |
| 813 | pub struct C.sg_vertex_buffer_layout_state { |
| 814 | pub mut: |
| 815 | stride int |
| 816 | step_func VertexStep |
| 817 | step_rate int |
| 818 | } |
| 819 | |
| 820 | pub type VertexBufferLayoutState = C.sg_vertex_buffer_layout_state |
| 821 | |
| 822 | pub struct C.sg_vertex_attr_state { |
| 823 | pub mut: |
| 824 | buffer_index int |
| 825 | offset int |
| 826 | format VertexFormat |
| 827 | } |
| 828 | |
| 829 | pub type VertexAttrDesc = C.sg_vertex_attr_state |
| 830 | |
| 831 | pub struct C.sg_stencil_state { |
| 832 | enabled bool |
| 833 | front StencilFaceState |
| 834 | back StencilFaceState |
| 835 | read_mask u8 |
| 836 | write_mask u8 |
| 837 | ref u8 |
| 838 | } |
| 839 | |
| 840 | pub type StencilState = C.sg_stencil_state |
| 841 | |
| 842 | pub struct C.sg_depth_state { |
| 843 | pixel_format PixelFormat |
| 844 | compare CompareFunc |
| 845 | write_enabled bool |
| 846 | bias f32 |
| 847 | bias_slope_scale f32 |
| 848 | bias_clamp f32 |
| 849 | } |
| 850 | |
| 851 | pub type DepthState = C.sg_depth_state |
| 852 | |
| 853 | pub struct C.sg_stencil_face_state { |
| 854 | compare CompareFunc |
| 855 | fail_op StencilOp |
| 856 | depth_fail_op StencilOp |
| 857 | pass_op StencilOp |
| 858 | } |
| 859 | |
| 860 | pub type StencilFaceState = C.sg_stencil_face_state |
| 861 | |
| 862 | pub struct C.sg_blend_state { |
| 863 | pub mut: |
| 864 | enabled bool |
| 865 | src_factor_rgb BlendFactor |
| 866 | dst_factor_rgb BlendFactor |
| 867 | op_rgb BlendOp |
| 868 | src_factor_alpha BlendFactor |
| 869 | dst_factor_alpha BlendFactor |
| 870 | op_alpha BlendOp |
| 871 | } |
| 872 | |
| 873 | pub type BlendState = C.sg_blend_state |
| 874 | |
| 875 | pub struct C.sg_color_attachment_action { |
| 876 | pub mut: |
| 877 | load_action LoadAction |
| 878 | store_action StoreAction |
| 879 | clear_value Color |
| 880 | } |
| 881 | |
| 882 | pub type ColorAttachmentAction = C.sg_color_attachment_action |
| 883 | |
| 884 | /* |
| 885 | pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32) { |
| 886 | action.val[0] = r |
| 887 | action.val[1] = g |
| 888 | action.val[2] = b |
| 889 | action.val[3] = a |
| 890 | } |
| 891 | */ |
| 892 | pub struct C.sg_depth_attachment_action { |
| 893 | pub mut: |
| 894 | load_action LoadAction |
| 895 | store_action StoreAction |
| 896 | clear_value f32 |
| 897 | } |
| 898 | |
| 899 | pub type DepthAttachmentAction = C.sg_depth_attachment_action |
| 900 | |
| 901 | pub struct C.sg_stencil_attachment_action { |
| 902 | pub mut: |
| 903 | load_action LoadAction |
| 904 | store_action StoreAction |
| 905 | clear_value u8 |
| 906 | } |
| 907 | |
| 908 | pub type StencilAttachmentAction = C.sg_stencil_attachment_action |
| 909 | |
| 910 | pub struct C.sg_pixelformat_info { |
| 911 | pub: |
| 912 | sample bool // pixel format can be sampled in shaders |
| 913 | filter bool // pixel format can be sampled with filtering |
| 914 | render bool // pixel format can be used as render target |
| 915 | blend bool // alpha-blending is supported |
| 916 | msaa bool // pixel format can be used as MSAA render target |
| 917 | depth bool // pixel format is a depth format |
| 918 | } |
| 919 | |
| 920 | pub type PixelFormatInfo = C.sg_pixelformat_info |
| 921 | |
| 922 | @[typedef] |
| 923 | pub struct C.sg_environment_defaults { |
| 924 | pub mut: |
| 925 | color_format PixelFormat |
| 926 | depth_format PixelFormat |
| 927 | sample_count int |
| 928 | } |
| 929 | |
| 930 | pub type EnvironmentDefaults = C.sg_environment_defaults |
| 931 | |
| 932 | @[typedef] |
| 933 | pub struct C.sg_metal_environment { |
| 934 | pub mut: |
| 935 | device voidptr |
| 936 | } |
| 937 | |
| 938 | pub type MetalEnvironment = C.sg_metal_environment |
| 939 | |
| 940 | @[typedef] |
| 941 | pub struct C.sg_d3d11_environment { |
| 942 | pub mut: |
| 943 | device voidptr |
| 944 | device_context voidptr |
| 945 | } |
| 946 | |
| 947 | pub type D3d11Environment = C.sg_d3d11_environment |
| 948 | |
| 949 | @[typedef] |
| 950 | pub struct C.sg_wgpu_environment { |
| 951 | pub mut: |
| 952 | device voidptr |
| 953 | } |
| 954 | |
| 955 | pub type WgpuEnvironment = C.sg_wgpu_environment |
| 956 | |
| 957 | @[typedef] |
| 958 | pub struct C.sg_environment { |
| 959 | pub mut: |
| 960 | defaults EnvironmentDefaults |
| 961 | metal MetalEnvironment |
| 962 | d3d11 D3d11Environment |
| 963 | wgpu WgpuEnvironment |
| 964 | } |
| 965 | |
| 966 | pub type Environment = C.sg_environment |
| 967 | |
| 968 | // C.sg_commit_listener is used with sg_add_commit_listener, to add a callback, |
| 969 | // which will be called in sg_commit(). This is useful for libraries building |
| 970 | // on top of sokol-gfx to be notified about when a frame ends (instead of having |
| 971 | // to guess, or add a manual 'new-frame' function). |
| 972 | pub struct C.sg_commit_listener { |
| 973 | pub: |
| 974 | func fn (user_data voidptr) |
| 975 | user_data voidptr |
| 976 | } |
| 977 | |
| 978 | pub type CommitListener = C.sg_commit_listener |
| 979 | |
| 980 | pub struct C.sg_trace_hooks {} |
| 981 | |
| 982 | // pub struct C.sg_resource_state {} enum |
| 983 | pub struct C.sg_sampler_info {} |
| 984 | |