2020-01-16 22:45:47 +03:00
|
|
|
module gfx
|
|
|
|
|
2020-12-07 08:16:21 +03:00
|
|
|
import sokol.c
|
|
|
|
|
2020-06-11 21:16:12 +03:00
|
|
|
pub const (
|
2021-05-08 13:32:29 +03:00
|
|
|
version = 1
|
2020-12-07 08:16:21 +03:00
|
|
|
used_import = c.used_import
|
2020-06-11 21:16:12 +03:00
|
|
|
)
|
|
|
|
|
2020-01-16 22:45:47 +03:00
|
|
|
// setup and misc functions
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn setup(desc &Desc) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_setup(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn shutdown() {
|
|
|
|
C.sg_shutdown()
|
|
|
|
}
|
|
|
|
|
2021-10-07 10:41:57 +03:00
|
|
|
[inline]
|
|
|
|
pub fn is_valid() bool {
|
|
|
|
return C.sg_isvalid()
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
|
|
|
pub fn reset_state_cache() {
|
|
|
|
C.sg_reset_state_cache()
|
|
|
|
}
|
|
|
|
|
|
|
|
// resource creation, destruction and updating
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn make_buffer(desc &BufferDesc) Buffer {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sg_make_buffer(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn make_image(desc &ImageDesc) Image {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sg_make_image(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn make_shader(desc &ShaderDesc) Shader {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sg_make_shader(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn make_pipeline(desc &PipelineDesc) Pipeline {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sg_make_pipeline(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn make_pass(desc &PassDesc) Pass {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.sg_make_pass(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn destroy_buffer(buf Buffer) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_destroy_buffer(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn destroy_image(img Image) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_destroy_image(img)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn destroy_shader(shd Shader) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_destroy_shader(shd)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn destroy_pipeline(pip Pipeline) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_destroy_pipeline(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn destroy_pass(pass Pass) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_destroy_pass(pass)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn update_buffer(buf Buffer, data &Range) {
|
2021-04-07 21:39:23 +03:00
|
|
|
C.sg_update_buffer(buf, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn update_image(img Image, data &ImageData) {
|
2021-04-07 21:39:23 +03:00
|
|
|
C.sg_update_image(img, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn append_buffer(buf Buffer, data &Range) int {
|
2021-04-07 21:39:23 +03:00
|
|
|
return C.sg_append_buffer(buf, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 20:02:22 +03:00
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_buffer_overflow(buf Buffer) bool {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_buffer_overflow(buf)
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:45:47 +03:00
|
|
|
// rendering functions
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn begin_default_pass(actions &PassAction, width int, height int) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_begin_default_pass(actions, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn begin_pass(pass Pass, actions &PassAction) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_begin_pass(pass, actions)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn apply_viewport(x int, y int, width int, height int, origin_top_left bool) {
|
|
|
|
C.sg_apply_viewport(x, y, width, height, origin_top_left)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn apply_scissor_rect(x int, y int, width int, height int, origin_top_left bool) {
|
|
|
|
C.sg_apply_scissor_rect(x, y, width, height, origin_top_left)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn apply_pipeline(pip Pipeline) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_apply_pipeline(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn apply_bindings(bindings &Bindings) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.sg_apply_bindings(bindings)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-07 20:52:44 +03:00
|
|
|
pub fn apply_uniforms(stage ShaderStage, ub_index int, data &Range) {
|
|
|
|
C.sg_apply_uniforms(int(stage), ub_index, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn draw(base_element int, num_elements int, num_instances int) {
|
|
|
|
C.sg_draw(base_element, num_elements, num_instances)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn end_pass() {
|
|
|
|
C.sg_end_pass()
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn commit() {
|
|
|
|
C.sg_commit()
|
|
|
|
}
|
|
|
|
|
2020-02-24 20:02:22 +03:00
|
|
|
// getting information
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_desc() Desc {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_desc()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_backend() Backend {
|
2022-01-02 21:36:01 +03:00
|
|
|
return C.sg_query_backend()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_features() Features {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_features()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_limits() Limits {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_limits()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pixelformat(fmt PixelFormat) PixelFormatInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_pixelformat(fmt)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-05-08 13:32:29 +03:00
|
|
|
// get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID)
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_buffer_state(buf Buffer) ResourceState {
|
|
|
|
return ResourceState(C.sg_query_buffer_state(buf))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_image_state(img Image) ResourceState {
|
|
|
|
return ResourceState(C.sg_query_image_state(img))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_shader_state(shd Shader) ResourceState {
|
|
|
|
return ResourceState(C.sg_query_shader_state(shd))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pipeline_state(pip Pipeline) ResourceState {
|
|
|
|
return ResourceState(C.sg_query_pipeline_state(pip))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pass_state(pass Pass) ResourceState {
|
|
|
|
return ResourceState(C.sg_query_pass_state(pass))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 20:02:22 +03:00
|
|
|
// get runtime information about a resource
|
2020-01-16 22:45:47 +03:00
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_buffer_info(buf Buffer) BufferInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_buffer_info(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_image_info(img Image) ImageInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_image_info(img)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_shader_info(shd Shader) ShaderInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_shader_info(shd)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pipeline_info(pip Pipeline) PipelineInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_pipeline_info(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pass_info(pass Pass) PassInfo {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_query_pass_info(pass)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get resource creation desc struct with their default values replaced
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_buffer_defaults(desc &Buffer) BufferDesc {
|
|
|
|
return C.sg_query_buffer_defaults(unsafe { &BufferDesc(voidptr(desc)) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_image_defaults(desc &Image) ImageDesc {
|
|
|
|
return C.sg_query_image_defaults(unsafe { &ImageDesc(voidptr(desc)) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_shader_defaults(desc &Shader) ShaderDesc {
|
|
|
|
return C.sg_query_shader_defaults(unsafe { &ShaderDesc(voidptr(desc)) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pipeline_defaults(desc &Pipeline) PipelineDesc {
|
|
|
|
return C.sg_query_pipeline_defaults(unsafe { &PipelineDesc(voidptr(desc)) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn query_pass_defaults(desc &Pass) PassDesc {
|
|
|
|
return C.sg_query_pass_defaults(unsafe { &PassDesc(voidptr(desc)) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2021-05-08 13:32:29 +03:00
|
|
|
// rendering contexts (optional)
|
2020-02-24 20:02:22 +03:00
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn setup_context() Context {
|
2020-02-24 20:02:22 +03:00
|
|
|
return C.sg_setup_context()
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn activate_context(ctx_id Context) {
|
2020-02-24 20:02:22 +03:00
|
|
|
C.sg_activate_context(ctx_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2022-01-02 21:36:01 +03:00
|
|
|
pub fn discard_context(ctx_id Context) {
|
2020-02-24 20:02:22 +03:00
|
|
|
C.sg_discard_context(ctx_id)
|
2020-03-27 20:01:46 +03:00
|
|
|
}
|