From 53aa4eba0db1cc39d62ac89aa4be858336943dab Mon Sep 17 00:00:00 2001 From: Larpon Date: Thu, 7 Oct 2021 09:41:57 +0200 Subject: [PATCH] sokol: add sg_isvalid wrapper to gfx (#12081) --- vlib/gg/image.c.v | 6 ++---- vlib/sokol/gfx/gfx.c.v | 5 +++++ vlib/sokol/gfx/gfx_funcs.c.v | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index a98a5fd409..eb3248e457 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -6,8 +6,6 @@ import os import stbi import sokol.gfx -fn C.sg_isvalid() bool - // TODO return ?Image pub fn (mut ctx Context) create_image(file string) Image { // println('\ncreate_image("$file")') @@ -25,7 +23,7 @@ pub fn (mut ctx Context) create_image(file string) Image { return img } } - if !C.sg_isvalid() { + if !gfx.is_valid() { // Sokol is not initialized yet, add stbi object to a queue/cache // ctx.image_queue << file stb_img := stbi.load(file) or { return Image{} } @@ -145,7 +143,7 @@ pub fn (mut img Image) update_pixel_data(buf &byte) { // TODO copypasta pub fn (mut ctx Context) create_image_with_size(file string, width int, height int) Image { - if !C.sg_isvalid() { + if !gfx.is_valid() { // Sokol is not initialized yet, add stbi object to a queue/cache // ctx.image_queue << file stb_img := stbi.load(file) or { return Image{} } diff --git a/vlib/sokol/gfx/gfx.c.v b/vlib/sokol/gfx/gfx.c.v index 9480173766..2760b18e33 100644 --- a/vlib/sokol/gfx/gfx.c.v +++ b/vlib/sokol/gfx/gfx.c.v @@ -18,6 +18,11 @@ pub fn shutdown() { C.sg_shutdown() } +[inline] +pub fn is_valid() bool { + return C.sg_isvalid() +} + [inline] pub fn reset_state_cache() { C.sg_reset_state_cache() diff --git a/vlib/sokol/gfx/gfx_funcs.c.v b/vlib/sokol/gfx/gfx_funcs.c.v index eb4e99b395..b8e85a1975 100644 --- a/vlib/sokol/gfx/gfx_funcs.c.v +++ b/vlib/sokol/gfx/gfx_funcs.c.v @@ -3,6 +3,7 @@ module gfx // setup and misc functions fn C.sg_setup(desc &C.sg_desc) fn C.sg_shutdown() +fn C.sg_isvalid() bool fn C.sg_reset_state_cache() // resource creation, destruction and updating