1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sokol: type alias all gfx structs (#13014)

This commit is contained in:
Larpon
2022-01-02 19:36:01 +01:00
committed by GitHub
parent 41e763f79c
commit 4d4398fa8a
25 changed files with 531 additions and 431 deletions

View File

@@ -109,7 +109,7 @@ pub mut:
// will get set to 2.0 for retina, will remain 1.0 for normal
width int
height int
clear_pass C.sg_pass_action
clear_pass gfx.PassAction
window sapp.Desc
timage_pip C.sgl_pipeline
config Config
@@ -139,7 +139,7 @@ fn gg_init_sokol_window(user_data voidptr) {
mut g := unsafe { &Context(user_data) }
desc := sapp.create_desc()
/*
desc := C.sg_desc{
desc := gfx.Desc{
mtl_device: sapp.metal_get_device()
mtl_renderpass_descriptor_cb: sapp.metal_get_renderpass_descriptor
mtl_drawable_cb: sapp.metal_get_drawable
@@ -196,16 +196,16 @@ fn gg_init_sokol_window(user_data voidptr) {
}
}
//
mut pipdesc := C.sg_pipeline_desc{
mut pipdesc := gfx.PipelineDesc{
label: c'alpha_image'
}
unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) }
color_state := C.sg_color_state{
blend: C.sg_blend_state{
color_state := gfx.ColorState{
blend: gfx.BlendState{
enabled: true
src_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_SRC_ALPHA)
dst_factor_rgb: gfx.BlendFactor(C.SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA)
src_factor_rgb: .src_alpha
dst_factor_rgb: .one_minus_src_alpha
}
}
pipdesc.colors[0] = color_state

View File

@@ -18,7 +18,7 @@ pub mut:
data voidptr
ext string
simg_ok bool
simg C.sg_image
simg gfx.Image
path string
}
@@ -64,7 +64,7 @@ pub fn (mut ctx Context) create_image(file string) Image {
pub fn (mut img Image) init_sokol_image() &Image {
// println('\n init sokol image $img.path ok=$img.simg_ok')
mut img_desc := C.sg_image_desc{
mut img_desc := gfx.ImageDesc{
width: img.width
height: img.height
num_mipmaps: 0
@@ -73,11 +73,11 @@ pub fn (mut img Image) init_sokol_image() &Image {
label: img.path.str
d3d11_texture: 0
}
img_desc.data.subimage[0][0] = C.sg_range{
img_desc.data.subimage[0][0] = gfx.Range{
ptr: img.data
size: usize(img.nr_channels * img.width * img.height)
}
img.simg = C.sg_make_image(&img_desc)
img.simg = gfx.make_image(&img_desc)
img.simg_ok = true
img.ok = true
return img
@@ -118,7 +118,7 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S
img.width = w
img.height = h
img.nr_channels = channels // 4 bytes per pixel for .rgba8, see pixel_format
mut img_desc := C.sg_image_desc{
mut img_desc := gfx.ImageDesc{
width: img.width
height: img.height
pixel_format: sicfg.pixel_format
@@ -132,11 +132,11 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S
label: img.path.str
}
// Sokol requires that streamed images have NO .ptr/.size initially:
img_desc.data.subimage[0][0] = C.sg_range{
img_desc.data.subimage[0][0] = gfx.Range{
ptr: 0
size: usize(0)
}
img.simg = C.sg_make_image(&img_desc)
img.simg = gfx.make_image(&img_desc)
img.simg_ok = true
img.ok = true
img_idx := ctx.cache_image(img)
@@ -151,7 +151,7 @@ pub fn (mut ctx Context) update_pixel_data(cached_image_idx int, buf &byte) {
}
pub fn (mut img Image) update_pixel_data(buf &byte) {
mut data := C.sg_image_data{}
mut data := gfx.ImageData{}
data.subimage[0][0].ptr = buf
data.subimage[0][0].size = usize(img.width * img.height * img.nr_channels)
gfx.update_image(img.simg, &data)