v2 / vlib / gg / streaming_image_gl_test.v
49 lines · 47 sloc · 1.76 KB · 29fd92cca22f935f02622b415594361727a6c9f2
Raw
1// vtest build: macos && !sanitized_job?
2import os
3import stbi
4
5@[direct_array_access]
6fn png_has_non_black_pixels(path string) !bool {
7 img := stbi.load(path)!
8 defer {
9 img.free()
10 }
11 for i in 0 .. img.width * img.height {
12 unsafe {
13 if img.data[i * 4] != 0 || img.data[i * 4 + 1] != 0 || img.data[i * 4 + 2] != 0 {
14 return true
15 }
16 }
17 }
18 return false
19}
20
21fn test_streaming_r8_zero_buffer_stays_black_on_gl_backend() {
22 vexe := @VEXE
23 vroot := os.dir(vexe)
24 sample_path := os.join_path(vroot, 'vlib/gg/testdata/streaming_r8_zero_buffer_issue_10989.vv')
25 temp_dir := os.join_path(os.temp_dir(), 'v_gg_issue_10989_${os.getpid()}')
26 os.mkdir_all(temp_dir) or { panic(err) }
27 defer {
28 os.rmdir_all(temp_dir) or {}
29 }
30 exe_path := os.join_path(temp_dir, 'issue10989_repro')
31 // Force the GL backend so this exercises the packed texture upload path from issue #10989.
32 compile_cmd := '${os.quoted_path(vexe)} -d gg_record -d darwin_sokol_glcore33 -o ${os.quoted_path(exe_path)} ${os.quoted_path(sample_path)}'
33 compile_res := os.execute(compile_cmd)
34 assert compile_res.exit_code == 0, compile_res.output
35 run_cmd := 'VGG_STOP_AT_FRAME=2 VGG_SCREENSHOT_FRAMES=2 VGG_SCREENSHOT_FOLDER=${os.quoted_path(temp_dir)} ${os.quoted_path(exe_path)}'
36 run_res := os.execute(run_cmd)
37 if run_res.exit_code != 0 {
38 if run_res.output.contains('glpixelformat') || run_res.exit_code == 134 {
39 // OpenGL context creation failed (e.g. headless CI runners without GPU).
40 // Skip the test rather than failing.
41 eprintln('skipping: GL context creation failed on this system')
42 return
43 }
44 assert run_res.exit_code == 0, run_res.output
45 }
46 screenshot_path := os.join_path(temp_dir, 'issue10989_repro_2.png')
47 assert os.exists(screenshot_path)
48 assert png_has_non_black_pixels(screenshot_path)! == false
49}
50