From 0ffc33a5c9cf45653dba16290f7c9ebbdd116159 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 6 Mar 2025 19:53:18 +0200 Subject: [PATCH] examples, gg, gg.m4: fix `VFLAGS='-no-skip-unused -cstrict -cc clang-18' v should-compile-all examples/sokol/` too --- examples/sokol/01_cubes/cube.v | 2 +- examples/sokol/02_cubes_glsl/cube_glsl.v | 6 +- .../sokol/03_march_tracing_glsl/rt_glsl.v | 6 +- examples/sokol/04_multi_shader_glsl/rt_glsl.v | 4 +- examples/sokol/05_instancing_glsl/rt_glsl.v | 6 +- .../sokol/06_obj_viewer/modules/obj/rend.v | 10 +- examples/sokol/08_sdf/sdf.v | 2 +- vlib/gg/gg.c.v | 7 +- vlib/gg/m4/matrix.v | 106 +++++++++--------- 9 files changed, 73 insertions(+), 76 deletions(-) diff --git a/examples/sokol/01_cubes/cube.v b/examples/sokol/01_cubes/cube.v index 774421848b..7b166327bd 100644 --- a/examples/sokol/01_cubes/cube.v +++ b/examples/sokol/01_cubes/cube.v @@ -37,7 +37,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { height: h num_mipmaps: 0 // usage: .dynamic - label: &u8(0) + label: &char(0) d3d11_texture: 0 } // comment, if .dynamic is enabled diff --git a/examples/sokol/02_cubes_glsl/cube_glsl.v b/examples/sokol/02_cubes_glsl/cube_glsl.v index c386fc7acf..2602e4d9c7 100644 --- a/examples/sokol/02_cubes_glsl/cube_glsl.v +++ b/examples/sokol/02_cubes_glsl/cube_glsl.v @@ -60,7 +60,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { height: h num_mipmaps: 0 // usage: .dynamic - label: &u8(0) + label: &char(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -339,7 +339,7 @@ fn init_cube_glsl(mut app App) { ibuf := gfx.make_buffer(&index_buffer_desc) // create shader - shader := gfx.make_shader(C.cube_shader_desc(C.sg_query_backend())) + shader := gfx.make_shader(voidptr(C.cube_shader_desc(C.sg_query_backend()))) mut pipdesc := gfx.PipelineDesc{} unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) } @@ -360,7 +360,7 @@ fn init_cube_glsl(mut app App) { } pipdesc.cull_mode = .back - pipdesc.label = 'glsl_shader pipeline'.str + pipdesc.label = c'glsl_shader pipeline' app.cube_bind.vertex_buffers[0] = vbuf app.cube_bind.index_buffer = ibuf diff --git a/examples/sokol/03_march_tracing_glsl/rt_glsl.v b/examples/sokol/03_march_tracing_glsl/rt_glsl.v index 3bfd4b8901..3e1f5adf89 100644 --- a/examples/sokol/03_march_tracing_glsl/rt_glsl.v +++ b/examples/sokol/03_march_tracing_glsl/rt_glsl.v @@ -63,7 +63,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // usage: .dynamic // wrap_u: .clamp_to_edge // wrap_v: .clamp_to_edge - label: &u8(0) + label: &char(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -205,7 +205,7 @@ fn init_cube_glsl(mut app App) { ibuf := gfx.make_buffer(&index_buffer_desc) // create shader - shader := gfx.make_shader(C.rt_shader_desc(C.sg_query_backend())) + shader := gfx.make_shader(voidptr(C.rt_shader_desc(C.sg_query_backend()))) mut pipdesc := gfx.PipelineDesc{} unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) } @@ -226,7 +226,7 @@ fn init_cube_glsl(mut app App) { } pipdesc.cull_mode = .back - pipdesc.label = 'glsl_shader pipeline'.str + pipdesc.label = c'glsl_shader pipeline' app.cube_bind.vertex_buffers[0] = vbuf app.cube_bind.index_buffer = ibuf diff --git a/examples/sokol/04_multi_shader_glsl/rt_glsl.v b/examples/sokol/04_multi_shader_glsl/rt_glsl.v index 6164ac5fcc..00674cdf83 100644 --- a/examples/sokol/04_multi_shader_glsl/rt_glsl.v +++ b/examples/sokol/04_multi_shader_glsl/rt_glsl.v @@ -285,12 +285,12 @@ fn (mut app App) on_init() { app.texture, app.sampler = create_texture(w, h, tmp_txt) // vfmt off - app.init_glsl_shader('march', C.rt_march_shader_desc(C.sg_query_backend()), [ + app.init_glsl_shader('march', voidptr(C.rt_march_shader_desc(C.sg_query_backend())), [ u16(0), 1, 2, 0, 2, 3, 6, 5, 4, 7, 6, 4, 8, 9, 10, 8, 10, 11, ]) - app.init_glsl_shader('puppy', C.rt_puppy_shader_desc(C.sg_query_backend()), [ + app.init_glsl_shader('puppy', voidptr(C.rt_puppy_shader_desc(C.sg_query_backend())), [ u16(14), 13, 12, 15, 14, 12, 16, 17, 18, 16, 18, 19, 22, 21, 20, 23, 22, 20, diff --git a/examples/sokol/05_instancing_glsl/rt_glsl.v b/examples/sokol/05_instancing_glsl/rt_glsl.v index 9033f7a2c1..0ef53aaf6c 100644 --- a/examples/sokol/05_instancing_glsl/rt_glsl.v +++ b/examples/sokol/05_instancing_glsl/rt_glsl.v @@ -74,7 +74,7 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) { //usage: .dynamic // wrap_u: .clamp_to_edge // wrap_v: .clamp_to_edge - label: &u8(0) + label: &char(0) d3d11_texture: 0 } // vfmt on @@ -225,7 +225,7 @@ fn init_cube_glsl_i(mut app App) { ibuf := gfx.make_buffer(&index_buffer_desc) // create shader - shader := gfx.make_shader(C.instancing_shader_desc(C.sg_query_backend())) + shader := gfx.make_shader(voidptr(C.instancing_shader_desc(C.sg_query_backend()))) mut pipdesc := gfx.PipelineDesc{} unsafe { vmemset(&pipdesc, 0, int(sizeof(pipdesc))) } @@ -257,7 +257,7 @@ fn init_cube_glsl_i(mut app App) { } pipdesc.cull_mode = .back - pipdesc.label = 'glsl_shader pipeline'.str + pipdesc.label = c'glsl_shader pipeline' mut bind := gfx.Bindings{} unsafe { vmemset(&bind, 0, int(sizeof(bind))) } diff --git a/examples/sokol/06_obj_viewer/modules/obj/rend.v b/examples/sokol/06_obj_viewer/modules/obj/rend.v index 140576c57c..81217af919 100644 --- a/examples/sokol/06_obj_viewer/modules/obj/rend.v +++ b/examples/sokol/06_obj_viewer/modules/obj/rend.v @@ -29,7 +29,7 @@ pub fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) { // usage: .dynamic // wrap_u: .clamp_to_edge // wrap_v: .clamp_to_edge - label: &u8(0) + label: &char(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -87,7 +87,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, } vert_buffer_desc.type = .vertexbuffer - vert_buffer_desc.label = 'vertbuf_part_${in_part:03}'.str + vert_buffer_desc.label = &char('vertbuf_part_${in_part:03}'.str) vbuf := gfx.make_buffer(&vert_buffer_desc) // index buffer @@ -101,7 +101,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, } index_buffer_desc.type = .indexbuffer - index_buffer_desc.label = 'indbuf_part_${in_part:03}'.str + index_buffer_desc.label = &char('indbuf_part_${in_part:03}'.str) ibuf := gfx.make_buffer(&index_buffer_desc) mut pipdesc := gfx.PipelineDesc{} @@ -131,7 +131,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, } pipdesc.cull_mode = .front - pipdesc.label = 'pip_part_${in_part:03}'.str + pipdesc.label = &char('pip_part_${in_part:03}'.str) // shader pipdesc.shader = shader @@ -153,7 +153,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader, pub fn (mut obj_part ObjPart) init_render_data(texture gfx.Image, sampler gfx.Sampler) { // create shader // One shader for all the model - shader := gfx.make_shader(C.gouraud_shader_desc(gfx.query_backend())) + shader := gfx.make_shader(voidptr(C.gouraud_shader_desc(gfx.query_backend()))) mut part_dict := map[string][]int{} for i, p in obj_part.part { diff --git a/examples/sokol/08_sdf/sdf.v b/examples/sokol/08_sdf/sdf.v index 19fa823c02..bc6cbb4de3 100644 --- a/examples/sokol/08_sdf/sdf.v +++ b/examples/sokol/08_sdf/sdf.v @@ -33,7 +33,7 @@ fn init(mut state State) { mut pipeline := gfx.PipelineDesc{} pipeline.layout.attrs[C.ATTR_vs_position].format = .float2 - pipeline.shader = gfx.make_shader(C.sdf_shader_desc(gfx.query_backend())) + pipeline.shader = gfx.make_shader(voidptr(C.sdf_shader_desc(gfx.query_backend()))) state.pip = gfx.make_pipeline(&pipeline) // No need to clear the window, since the shader will overwrite the whole framebuffer diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 7162da0165..6086c400b7 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -799,16 +799,17 @@ pub fn screen_size() Size { if output_info == unsafe { nil } { return Size{} } - defer { C.XRRFreeOutputInfo(output_info) } crtc_info := C.XRRGetCrtcInfo(display, resources, output_info.crtc) + C.XRRFreeOutputInfo(output_info) if crtc_info == unsafe { nil } { return Size{} } - defer { C.XRRFreeCrtcInfo(crtc_info) } - return Size{ + res := Size{ width: unsafe { int(crtc_info.width) } height: unsafe { int(crtc_info.height) } } + C.XRRFreeCrtcInfo(crtc_info) + return res } } } diff --git a/vlib/gg/m4/matrix.v b/vlib/gg/m4/matrix.v index f5820705ac..5f1e720d8e 100644 --- a/vlib/gg/m4/matrix.v +++ b/vlib/gg/m4/matrix.v @@ -29,15 +29,14 @@ pub const precision = f32(10e-7) *********************************************************************/ // String representation of the matrix pub fn (x Mat4) str() string { - unsafe { - // vfmt off - return - '|${x.e[0]: -6.3},${x.e[1]: -6.3},${x.e[2]: -6.3},${x.e[3]: -6.3}|\n' + - '|${x.e[4]: -6.3},${x.e[5]: -6.3},${x.e[6]: -6.3},${x.e[7]: -6.3}|\n' + - '|${x.e[8]: -6.3},${x.e[9]: -6.3},${x.e[10]:-6.3},${x.e[11]:-6.3}|\n' + - '|${x.e[12]:-6.3},${x.e[13]:-6.3},${x.e[14]:-6.3},${x.e[15]:-6.3}|' - // vfmt on + // vfmt off + return unsafe { + '|${x.e[0]: -6.3},${x.e[1]: -6.3},${x.e[2]: -6.3},${x.e[3]: -6.3}|\n' + + '|${x.e[4]: -6.3},${x.e[5]: -6.3},${x.e[6]: -6.3},${x.e[7]: -6.3}|\n' + + '|${x.e[8]: -6.3},${x.e[9]: -6.3},${x.e[10]:-6.3},${x.e[11]:-6.3}|\n' + + '|${x.e[12]:-6.3},${x.e[13]:-6.3},${x.e[14]:-6.3},${x.e[15]:-6.3}|' } + // vfmt on } // Remove all the raw zeros @@ -54,6 +53,7 @@ pub fn (a Mat4) clean() Mat4 { } return x } + return zero_m4() // workaround -cstrict } // Sum all the elements of the matrix @@ -254,30 +254,30 @@ pub fn (mut x Mat4) swap_row(row1 int, row2 int) { //------------------------------------- // Transpose the matrix pub fn (x Mat4) transpose() Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ x.e[0 ], x.e[4 ], x.e[8 ], x.e[12], x.e[1 ], x.e[5 ], x.e[9 ], x.e[13], x.e[2 ], x.e[6 ], x.e[10], x.e[14], x.e[3 ], x.e[7 ], x.e[11], x.e[15], ]!} - // vfmt on } + // vfmt on } // Multiply the all the elements of the matrix by a scalar pub fn (x Mat4) mul_scalar(s f32) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ x.e[0 ] * s, x.e[1 ] * s, x.e[2 ] * s, x.e[3 ] * s, x.e[4 ] * s, x.e[5 ] * s, x.e[6 ] * s, x.e[7 ] * s, x.e[8 ] * s, x.e[9 ] * s, x.e[10] * s, x.e[11] * s, x.e[12] * s, x.e[13] * s, x.e[14] * s, x.e[15] * s, ]!} - // vfmt on } + // vfmt on } /********************************************************************* @@ -329,37 +329,37 @@ pub fn set_m4(value f32) Mat4 { // Sum of matrix, operator + pub fn (a Mat4) + (b Mat4) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ a.e[0 ] + b.e[0 ], a.e[1 ] + b.e[1 ], a.e[2 ] + b.e[2 ], a.e[3 ] + b.e[3 ], a.e[4 ] + b.e[4 ], a.e[5 ] + b.e[5 ], a.e[6 ] + b.e[6 ], a.e[7 ] + b.e[7 ], a.e[8 ] + b.e[8 ], a.e[9 ] + b.e[9 ], a.e[10] + b.e[10], a.e[11] + b.e[11], a.e[12] + b.e[12], a.e[13] + b.e[13], a.e[14] + b.e[14], a.e[15] + b.e[15], ]!} - // vfmt on } + // vfmt on } // Subtraction of matrix, operator - pub fn (a Mat4) - (b Mat4) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ a.e[0 ] - b.e[0 ], a.e[1 ] - b.e[1 ], a.e[2 ] - b.e[2 ], a.e[3 ] - b.e[3 ], a.e[4 ] - b.e[4 ], a.e[5 ] - b.e[5 ], a.e[6 ] - b.e[6 ], a.e[7 ] - b.e[7 ], a.e[8 ] - b.e[8 ], a.e[9 ] - b.e[9 ], a.e[10] - b.e[10], a.e[11] - b.e[11], a.e[12] - b.e[12], a.e[13] - b.e[13], a.e[14] - b.e[14], a.e[15] - b.e[15], ]!} - // vfmt on } + // vfmt on } // Multiplication of matrix, operator * pub fn (a Mat4) * (b Mat4) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ a.f[0][0] * b.f[0][0] + a.f[0][1] * b.f[1][0] + a.f[0][2] * b.f[2][0] + a.f[0][3] * b.f[3][0], // [0][0] a.f[0][0] * b.f[0][1] + a.f[0][1] * b.f[1][1] + a.f[0][2] * b.f[2][1] + a.f[0][3] * b.f[3][1], // [0][1] a.f[0][0] * b.f[0][2] + a.f[0][1] * b.f[1][2] + a.f[0][2] * b.f[2][2] + a.f[0][3] * b.f[3][2], // [0][2] @@ -380,43 +380,37 @@ pub fn (a Mat4) * (b Mat4) Mat4 { a.f[3][0] * b.f[0][2] + a.f[3][1] * b.f[1][2] + a.f[3][2] * b.f[2][2] + a.f[3][3] * b.f[3][2], // [3][2] a.f[3][0] * b.f[0][3] + a.f[3][1] * b.f[1][3] + a.f[3][2] * b.f[2][3] + a.f[3][3] * b.f[3][3], // [3][3] ]!} - // vfmt on } + // vfmt on } // Sum of matrix function pub fn add(a Mat4, b Mat4) Mat4 { - unsafe { - return a + b - } + return a + b } // Subtraction of matrix function pub fn sub(a Mat4, b Mat4) Mat4 { - unsafe { - return a - b - } + return a - b } // Multiplication of matrix function pub fn mul(a Mat4, b Mat4) Mat4 { - unsafe { - return a * b - } + return a * b } // Multiply a Matrix by a vector pub fn mul_vec(a Mat4, v Vec4) Vec4 { - unsafe { - // vfmt off - return Vec4{ e: [ + // vfmt off + return unsafe { + Vec4{ e: [ a.e[0 ] * v.e[0] + a.e[1 ] * v.e[1] + a.e[2 ] * v.e[2] + a.e[3 ] * v.e[3], a.e[4 ] * v.e[0] + a.e[5 ] * v.e[1] + a.e[6 ] * v.e[2] + a.e[7 ] * v.e[3], a.e[8 ] * v.e[0] + a.e[9 ] * v.e[1] + a.e[10] * v.e[2] + a.e[11] * v.e[3], a.e[12] * v.e[0] + a.e[13] * v.e[1] + a.e[14] * v.e[2] + a.e[15] * v.e[3], ]!} - // vfmt on } + // vfmt on } // Calculate the determinant of the Matrix @@ -446,15 +440,15 @@ pub fn det(x Mat4) f32 { t[3] = x02 * x33 - x03 * x32 t[4] = x02 * x23 - x03 * x22 t[5] = x02 * x13 - x03 * x12 - // vfmt off - return - x00 * (x11 * t[0] - x21 * t[1] + x31 * t[2]) - - x10 * (x01 * t[0] - x21 * t[3] + x31 * t[4]) + - x20 * (x01 * t[1] - x11 * t[3] + x31 * t[5]) - - x30 * (x01 * t[2] - x11 * t[4] + x21 * t[5]) + return + x00 * (x11 * t[0] - x21 * t[1] + x31 * t[2]) - + x10 * (x01 * t[0] - x21 * t[3] + x31 * t[4]) + + x20 * (x01 * t[1] - x11 * t[3] + x31 * t[5]) - + x30 * (x01 * t[2] - x11 * t[4] + x21 * t[5]) // vfmt on } + return 0 // workaround -cstrict } // Calculate the inverse of the Matrix @@ -530,6 +524,7 @@ pub fn (x Mat4) inverse() Mat4 { } return dest.mul_scalar(det) } + return zero_m4() } /********************************************************************* @@ -558,6 +553,7 @@ pub fn rotate(angle f32, w Vec4) Mat4 { ]!} // vfmt on } + return zero_m4() } /********************************************************************* @@ -567,28 +563,28 @@ pub fn rotate(angle f32, w Vec4) Mat4 { *********************************************************************/ // Get a matrix translated by a vector w pub fn (x Mat4) translate(w Vec4) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ x.e[0], x.e[1], x.e[2 ], x.e[3 ], x.e[4], x.e[5], x.e[6 ], x.e[7 ], x.e[8], x.e[9], x.e[10], x.e[11], x.e[12] + w.e[0], x.e[13] + w.e[1], x.e[14] + w.e[2], x.e[15], ]!} - // vfmt on } + // vfmt on } // Get a scale matrix, the scale vector is w, only xyz are evaluated. pub fn scale(w Vec4) Mat4 { - unsafe { - // vfmt off - return Mat4{ e: [ + // vfmt off + return unsafe { + Mat4{ e: [ w.e[0], 0, 0, 0, 0, w.e[1], 0, 0, 0, 0, w.e[2], 0, 0, 0, 0, 1, ]!} - // vfmt on } + // vfmt on }