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

examples, tests: small formatting cleanup in cube_glsl.v , remove already fixed skips in v test-cleancode, before // vfmt off and // vfmt on

This commit is contained in:
Delyan Angelov
2022-11-04 10:20:21 +02:00
parent fa7ff09370
commit 7f91db695c
2 changed files with 169 additions and 165 deletions

View File

@@ -39,14 +39,11 @@ const verify_known_failing_exceptions = [
'examples/sokol/03_march_tracing_glsl/rt_glsl.v', 'examples/sokol/03_march_tracing_glsl/rt_glsl.v',
'examples/sokol/04_multi_shader_glsl/rt_glsl.v', 'examples/sokol/04_multi_shader_glsl/rt_glsl.v',
'examples/sokol/05_instancing_glsl/rt_glsl.v', 'examples/sokol/05_instancing_glsl/rt_glsl.v',
'examples/sokol/06_obj_viewer/show_obj.v',
'vlib/v/checker/tests/modules/deprecated_module/main.v' /* adds deprecated_module. module prefix to imports, even though the folder has v.mod */, 'vlib/v/checker/tests/modules/deprecated_module/main.v' /* adds deprecated_module. module prefix to imports, even though the folder has v.mod */,
'vlib/gg/m4/graphic.v', 'vlib/gg/m4/graphic.v',
'vlib/gg/m4/m4_test.v', 'vlib/gg/m4/m4_test.v',
'vlib/gg/m4/matrix.v', 'vlib/gg/m4/matrix.v',
'vlib/builtin/int_test.v' /* special number formatting that should be tested */,
// TODOs and unfixed vfmt bugs // TODOs and unfixed vfmt bugs
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
'vlib/v/tests/inout/string_interpolation_inner_expr_cbr.vv', /* for new string interpolation, prevent resolving to nested interpolation */ 'vlib/v/tests/inout/string_interpolation_inner_expr_cbr.vv', /* for new string interpolation, prevent resolving to nested interpolation */
'vlib/v/tests/string_new_interpolation_test.v', /* new string interpolation */ 'vlib/v/tests/string_new_interpolation_test.v', /* new string interpolation */
] ]

View File

@@ -102,15 +102,18 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
fn draw_triangle() { fn draw_triangle() {
sgl.defaults() sgl.defaults()
sgl.begin_triangles() sgl.begin_triangles()
{
sgl.v2f_c3b( 0.0, 0.5, 255, 0 , 0 ) sgl.v2f_c3b( 0.0, 0.5, 255, 0 , 0 )
sgl.v2f_c3b(-0.5, -0.5, 0, 0 , 255) sgl.v2f_c3b(-0.5, -0.5, 0, 0 , 255)
sgl.v2f_c3b( 0.5, -0.5, 0, 255, 0 ) sgl.v2f_c3b( 0.5, -0.5, 0, 255, 0 )
}
sgl.end() sgl.end()
} }
// vertex specification for a cube with colored sides and texture coords // vertex specification for a cube with colored sides and texture coords
fn cube() { fn cube() {
sgl.begin_quads() sgl.begin_quads()
{
// edge color // edge color
sgl.c3f(1.0, 0.0, 0.0) sgl.c3f(1.0, 0.0, 0.0)
// edge coord // edge coord
@@ -144,6 +147,7 @@ fn cube() {
sgl.v3f_t2f(-1.0, 1.0, 1.0, 1.0, 1.0) sgl.v3f_t2f(-1.0, 1.0, 1.0, 1.0, 1.0)
sgl.v3f_t2f( 1.0, 1.0, 1.0, 1.0, -1.0) sgl.v3f_t2f( 1.0, 1.0, 1.0, 1.0, -1.0)
sgl.v3f_t2f( 1.0, 1.0, -1.0, -1.0, -1.0) sgl.v3f_t2f( 1.0, 1.0, -1.0, -1.0, -1.0)
}
sgl.end() sgl.end()
} }
@@ -163,23 +167,28 @@ fn draw_cubes(app App) {
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0) sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
cube() cube()
sgl.push_matrix() sgl.push_matrix()
{
sgl.translate(0.0, 0.0, 3.0) sgl.translate(0.0, 0.0, 3.0)
sgl.scale(0.5, 0.5, 0.5) sgl.scale(0.5, 0.5, 0.5)
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0) sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0) sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
cube() cube()
sgl.push_matrix() sgl.push_matrix()
{
sgl.translate(0.0, 0.0, 3.0) sgl.translate(0.0, 0.0, 3.0)
sgl.scale(0.5, 0.5, 0.5) sgl.scale(0.5, 0.5, 0.5)
sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0) sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0)
sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0) sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0)
cube() cube()
}
sgl.pop_matrix() sgl.pop_matrix()
}
sgl.pop_matrix() sgl.pop_matrix()
} }
fn cube_texture(r f32, g f32, b f32) { fn cube_texture(r f32, g f32, b f32) {
sgl.begin_quads() sgl.begin_quads()
{
// edge color // edge color
sgl.c3f(r, g, b) sgl.c3f(r, g, b)
// edge coord // edge coord
@@ -213,6 +222,7 @@ fn cube_texture(r f32, g f32, b f32) {
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.25, 0.25) sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.25, 0.25)
sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 ) sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 )
sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.0 , 0.0 ) sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.0 , 0.0 )
}
sgl.end() sgl.end()
} }
@@ -289,7 +299,7 @@ fn init_cube_glsl(mut app App) {
// vert_buffer_desc.usage = .immutable // vert_buffer_desc.usage = .immutable
vbuf := gfx.make_buffer(&vert_buffer_desc) vbuf := gfx.make_buffer(&vert_buffer_desc)
/* create an index buffer for the cube */ // create an index buffer for the cube
indices := [ indices := [
u16(0), 1, 2, 0, 2, 3, u16(0), 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4, 6, 5, 4, 7, 6, 4,
@@ -299,7 +309,9 @@ fn init_cube_glsl(mut app App) {
22, 21, 20, 23, 22, 20 22, 21, 20, 23, 22, 20
] ]
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'} mut index_buffer_desc := gfx.BufferDesc{
label: c'cube-indices'
}
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) } unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
index_buffer_desc.size = usize(indices.len * int(sizeof(u16))) index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
@@ -347,9 +359,22 @@ fn draw_cube_glsl(app App) {
return return
} }
rot := [f32(app.mouse_y), f32(app.mouse_x)] // clear
ws := gg.window_size_real_pixels() ws := gg.window_size_real_pixels()
mut color_action := gfx.ColorAttachmentAction{
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0
a: 1.0
}
}
mut pass_action := gfx.PassAction{}
pass_action.colors[0] = color_action
gfx.begin_default_pass(&pass_action, ws.width, ws.height)
{
rot := [f32(app.mouse_y), f32(app.mouse_x)]
// ratio := f32(ws.width)/ws.height // ratio := f32(ws.width)/ws.height
dw := f32(ws.width / 2) dw := f32(ws.width / 2)
dh := f32(ws.height / 2) dh := f32(ws.height / 2)
@@ -361,9 +386,7 @@ fn draw_cube_glsl(app App) {
gfx.apply_pipeline(app.cube_pip_glsl) gfx.apply_pipeline(app.cube_pip_glsl)
gfx.apply_bindings(app.cube_bind) gfx.apply_bindings(app.cube_bind)
//*************** // Uniforms:
// Uniforms
//***************
// passing the view matrix as uniform // passing the view matrix as uniform
// res is a 4x4 matrix of f32 thus: 4*16 byte of size // res is a 4x4 matrix of f32 thus: 4*16 byte of size
vs_uniforms_range := gfx.Range{ vs_uniforms_range := gfx.Range{
@@ -387,6 +410,7 @@ fn draw_cube_glsl(app App) {
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range) gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
gfx.draw(0, (3 * 2) * 6, 1) gfx.draw(0, (3 * 2) * 6, 1)
}
gfx.end_pass() gfx.end_pass()
gfx.commit() gfx.commit()
} }
@@ -407,19 +431,24 @@ fn draw_texture_cubes(app App) {
sgl.rotate(sgl.rad(rot[0]), 1.0, 0.0, 0.0) sgl.rotate(sgl.rad(rot[0]), 1.0, 0.0, 0.0)
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0) sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
cube_texture(1, 1, 1) cube_texture(1, 1, 1)
sgl.push_matrix() sgl.push_matrix()
{
sgl.translate(0.0, 0.0, 3.0) sgl.translate(0.0, 0.0, 3.0)
sgl.scale(0.5, 0.5, 0.5) sgl.scale(0.5, 0.5, 0.5)
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0) sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0) sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
cube_texture(1, 1, 1) cube_texture(1, 1, 1)
sgl.push_matrix() sgl.push_matrix()
{
sgl.translate(0.0, 0.0, 3.0) sgl.translate(0.0, 0.0, 3.0)
sgl.scale(0.5, 0.5, 0.5) sgl.scale(0.5, 0.5, 0.5)
sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0) sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0)
sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0) sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0)
cube_texture(1, 1, 1) cube_texture(1, 1, 1)
}
sgl.pop_matrix() sgl.pop_matrix()
}
sgl.pop_matrix() sgl.pop_matrix()
sgl.disable_texture() sgl.disable_texture()
@@ -440,6 +469,7 @@ fn frame(mut app App) {
// app.gg.begin() // app.gg.begin()
app.gg.begin() app.gg.begin()
{
sgl.defaults() sgl.defaults()
// 2d triangle // 2d triangle
@@ -453,23 +483,9 @@ fn frame(mut app App) {
// textured cubed with viewport // textured cubed with viewport
sgl.viewport(0, int(dh / 5), dw, int(dh * ratio), true) sgl.viewport(0, int(dh / 5), dw, int(dh * ratio), true)
draw_texture_cubes(app) draw_texture_cubes(app)
}
app.gg.end() app.gg.end()
// clear
mut color_action := gfx.ColorAttachmentAction{
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0
a: 1.0
}
}
mut pass_action := gfx.PassAction{}
pass_action.colors[0] = color_action
gfx.begin_default_pass(&pass_action, ws.width, ws.height)
// glsl cube // glsl cube
draw_cube_glsl(app) draw_cube_glsl(app)
@@ -477,9 +493,7 @@ fn frame(mut app App) {
} }
/****************************************************************************** /******************************************************************************
*
* Init / Cleanup * Init / Cleanup
*
******************************************************************************/ ******************************************************************************/
fn my_init(mut app App) { fn my_init(mut app App) {
// set max vertices, // set max vertices,
@@ -554,9 +568,7 @@ fn my_init(mut app App) {
} }
/****************************************************************************** /******************************************************************************
*
* event * event
*
******************************************************************************/ ******************************************************************************/
fn my_event_manager(mut ev gg.Event, mut app App) { fn my_event_manager(mut ev gg.Event, mut app App) {
if ev.typ == .mouse_move { if ev.typ == .mouse_move {
@@ -572,11 +584,6 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
} }
} }
/******************************************************************************
*
* Main
*
******************************************************************************/
fn main() { fn main() {
// App init // App init
mut app := &App{ mut app := &App{