v/vlib/sokol/gfx/gfx.c.v

272 lines
5.2 KiB
V
Raw Normal View History

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