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]
|
|
|
|
pub fn setup(desc &C.sg_desc) {
|
|
|
|
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]
|
|
|
|
pub fn make_buffer(desc &C.sg_buffer_desc) C.sg_buffer {
|
|
|
|
return C.sg_make_buffer(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn make_image(desc &C.sg_image_desc) C.sg_image {
|
|
|
|
return C.sg_make_image(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn make_shader(desc &C.sg_shader_desc) C.sg_shader {
|
|
|
|
return C.sg_make_shader(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn make_pipeline(desc &C.sg_pipeline_desc) C.sg_pipeline {
|
|
|
|
return C.sg_make_pipeline(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn make_pass(desc &C.sg_pass_desc) C.sg_pass {
|
|
|
|
return C.sg_make_pass(desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn destroy_buffer(buf C.sg_buffer) {
|
|
|
|
C.sg_destroy_buffer(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn destroy_image(img C.sg_image) {
|
|
|
|
C.sg_destroy_image(img)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn destroy_shader(shd C.sg_shader) {
|
|
|
|
C.sg_destroy_shader(shd)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn destroy_pipeline(pip C.sg_pipeline) {
|
|
|
|
C.sg_destroy_pipeline(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn destroy_pass(pass C.sg_pass) {
|
|
|
|
C.sg_destroy_pass(pass)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-04-07 21:39:23 +03:00
|
|
|
pub fn update_buffer(buf C.sg_buffer, data &C.sg_range) {
|
|
|
|
C.sg_update_buffer(buf, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-04-07 21:39:23 +03:00
|
|
|
pub fn update_image(img C.sg_image, data &C.sg_image_data) {
|
|
|
|
C.sg_update_image(img, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-04-07 21:39:23 +03:00
|
|
|
pub fn append_buffer(buf C.sg_buffer, data &C.sg_range) int {
|
|
|
|
return C.sg_append_buffer(buf, data)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 20:02:22 +03:00
|
|
|
[inline]
|
|
|
|
pub fn query_buffer_overflow(buf C.sg_buffer) bool {
|
|
|
|
return C.sg_query_buffer_overflow(buf)
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:45:47 +03:00
|
|
|
// rendering functions
|
|
|
|
[inline]
|
|
|
|
pub fn begin_default_pass(actions &C.sg_pass_action, 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) {
|
|
|
|
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]
|
|
|
|
pub fn apply_pipeline(pip C.sg_pipeline) {
|
|
|
|
C.sg_apply_pipeline(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn apply_bindings(bindings &C.sg_bindings) {
|
|
|
|
C.sg_apply_bindings(bindings)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-04-07 21:39:23 +03:00
|
|
|
pub fn apply_uniforms(stage int, ub_index int, data &C.sg_range) {
|
|
|
|
C.sg_apply_uniforms(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]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_desc() C.sg_desc {
|
|
|
|
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 {
|
2021-04-19 15:38:48 +03:00
|
|
|
return Backend(C.sg_query_backend())
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_features() C.sg_features {
|
|
|
|
return C.sg_query_features()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_limits() C.sg_limits {
|
|
|
|
return C.sg_query_limits()
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_pixelformat(fmt PixelFormat) C.sg_pixelformat_info {
|
|
|
|
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]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_buffer_state(buf C.sg_buffer) C.sg_resource_state {
|
2020-04-16 16:53:34 +03:00
|
|
|
return C.sg_query_buffer_state(buf)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_image_state(img C.sg_image) C.sg_resource_state {
|
2020-04-16 16:53:34 +03:00
|
|
|
return C.sg_query_image_state(img)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_shader_state(shd C.sg_shader) C.sg_resource_state {
|
2020-04-16 16:53:34 +03:00
|
|
|
return C.sg_query_shader_state(shd)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_pipeline_state(pip C.sg_pipeline) C.sg_resource_state {
|
2020-04-16 16:53:34 +03:00
|
|
|
return C.sg_query_pipeline_state(pip)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_pass_state(pass C.sg_pass) C.sg_resource_state {
|
2020-04-16 16:53:34 +03:00
|
|
|
return 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]
|
2020-02-24 20:02:22 +03:00
|
|
|
pub fn query_buffer_info(buf C.sg_buffer) C.sg_buffer_info {
|
|
|
|
return C.sg_query_buffer_info(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_image_info(img C.sg_image) C.sg_image_info {
|
|
|
|
return C.sg_query_image_info(img)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_shader_info(shd C.sg_shader) C.sg_shader_info {
|
|
|
|
return C.sg_query_shader_info(shd)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_pipeline_info(pip C.sg_pipeline) C.sg_pipeline_info {
|
|
|
|
return C.sg_query_pipeline_info(pip)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_pass_info(pass C.sg_pass) C.sg_pass_info {
|
|
|
|
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]
|
|
|
|
pub fn query_buffer_defaults(desc &C.sg_buffer) C.sg_buffer_desc {
|
2021-04-19 15:38:48 +03:00
|
|
|
return C.sg_query_buffer_defaults(unsafe { &C.sg_buffer_desc(desc) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_image_defaults(desc &C.sg_image) C.sg_image_desc {
|
2021-04-19 15:38:48 +03:00
|
|
|
return C.sg_query_image_defaults(unsafe { &C.sg_image_desc(desc) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_shader_defaults(desc &C.sg_shader) C.sg_shader_desc {
|
2021-04-19 15:38:48 +03:00
|
|
|
return C.sg_query_shader_defaults(unsafe { &C.sg_shader_desc(desc) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_pipeline_defaults(desc &C.sg_pipeline) C.sg_pipeline_desc {
|
2021-04-19 15:38:48 +03:00
|
|
|
return C.sg_query_pipeline_defaults(unsafe { &C.sg_pipeline_desc(desc) })
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn query_pass_defaults(desc &C.sg_pass) C.sg_pass_desc {
|
2021-04-19 15:38:48 +03:00
|
|
|
return C.sg_query_pass_defaults(unsafe { &C.sg_pass_desc(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]
|
|
|
|
pub fn setup_context() C.sg_context {
|
|
|
|
return C.sg_setup_context()
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn activate_context(ctx_id C.sg_context) {
|
|
|
|
C.sg_activate_context(ctx_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn discard_context(ctx_id C.sg_context) {
|
|
|
|
C.sg_discard_context(ctx_id)
|
2020-03-27 20:01:46 +03:00
|
|
|
}
|