0030076: Visualization, TKV3d - API to update certain vertex attribute(s) without...
[occt.git] / tests / bugs / vis / bug23226
1 puts "============"
2 puts "OCC23226"
3 puts "============"
4 puts ""
5 #######################################################################
6 # Extend OpenGl_Context to store map of shared GPU resources
7 #######################################################################
8
9 set BugNumber OCC23226
10
11 #
12 # This test is modified test cdl/934/C2
13 #
14
15 # this test performs automatical test of primitives array objects by pixel checking
16 # this test ALSO DUMPS two result images (the primitives on the images should have
17 # same contours, WIREFRAME OBJECTS ARE IN YELLOW-RED COLORS, SHADED OBJECTS ARE
18 # BLUE-GREEN COLORS)
19
20 set BUGNUMBER OCC22583
21 set status 0
22 set ImageName1 "occ22583-image1.png"
23 set ImageName2 "occ22583-image2.png"
24
25 # set window width and height, this values should correspond to a 
26 # view window sizes to pass the test
27 set view_width  405
28 set view_height 405
29
30 # colors used for tests
31 # yellow
32 set colorY_R 1
33 set colorY_G 1
34 set colorY_B 0
35
36 # red
37 set colorR_R 1
38 set colorR_G 0
39 set colorR_B 0
40
41 # blue
42 set colorB_R 0
43 set colorB_G 1
44 set colorB_B 1
45
46 # green
47 set colorG_R 0
48 set colorG_G 1
49 set colorG_B 0
50
51 # limit of range where the pixels are tested (sets number of iterations)
52 # 30 pixels in width and in height will be enough to test all primitives
53 set limit_x 3
54 set limit_y 3
55
56 # this procedure is internal and will be removed at the end of the script
57 # generate points for primitive
58 proc generate_points {x y z r g b} {
59   # define top plane points
60   global pts01 pts02 pts03 pts04 pts05 pts06
61   set pts01 "v [expr "$x-5"] [expr "$y+5"] [expr "$z"]  n 0 0 -1 c $r $g $b"
62   set pts02 "v [expr "$x  "] [expr "$y+5"] [expr "$z"]  n 0 0 -1 c $r $g $b"
63   set pts03 "v [expr "$x  "] [expr "$y "] [expr "$z"]  n 0 0 -1 c $r $g $b"
64   set pts04 "v [expr "$x+5"] [expr "$y "] [expr "$z"]  n 0 0 -1 c $r $g $b"
65   set pts05 "v [expr "$x-5"] [expr "$y-5"] [expr "$z"]  n 0 0 -1 c $r $g $b"
66   set pts06 "v [expr "$x  "] [expr "$y-5"] [expr "$z"]  n 0 0 -1 c $r $g $b"
67 }
68
69 # this procedure is internal and will be removed at the end of the script
70 # check pixels of primitive
71 proc check_primitive {name1 r g b args} {
72   global limit_x limit_y view_width view_height
73   # show only primitive that we interested in to test
74   vdonly $name1 $args
75   vtop
76   vfit
77
78   # move cursor not to select shape
79   vmoveto 0 0
80   vmoveto 0 0
81
82   # test pixels in a top left corner
83   set TestPassed 0
84   set HasPixel 0
85   for {set i 0} {$i < $limit_x} {incr i} {
86     for {set j 0} {$j < $limit_y} {incr j} {
87       if { "[vreadpixel $i $j rgb]" == "$r $g $b" } {
88         set HasPixel 1
89       }
90     }
91   }
92   if { $HasPixel == 1 } {
93     set TestPassed [expr $TestPassed + 1]
94   } else {
95     set TestPassed 0
96   }
97
98   # test pixels in bottom left corner
99   set HasPixel 1
100   for {set i 0} {$i < $limit_x} {incr i} {
101     for {set j 0} {$j < $limit_y} {incr j} {
102       set coord_y [expr $view_height-$j]
103       if { "[vreadpixel $i $coord_y rgb]" == "$r $g $b" } {
104         set HasPixel 1
105       }
106     }
107   }
108   if { $HasPixel == 1 } {
109     set TestPassed [expr $TestPassed + 1]
110   } else {
111     set TestPassed 0
112   }
113
114   # test pixels in center right corner
115   set HasPixel 1
116   for {set i 0} {$i < $limit_x} {incr i} {
117     for {set j 0} {$j < $limit_y} {incr j} {
118       set coord_x [expr ($view_width-$limit_y) + $i]
119       set coord_y [expr ($view_height-$limit_y)/2 + $j]
120       if { "[vreadpixel $coord_x $coord_y rgb]" == "$r $g $b" } {
121         set HasPixel 1
122       }
123     }
124   }
125   if { $HasPixel == 1 } {
126     set TestPassed [expr $TestPassed + 1]
127   } else {
128     set TestPassed 0
129   }
130
131   # test pixels in center left corner (shouldn't be anything)
132   set HasPixel 0
133   for {set i 0} {$i < $limit_x} {incr i} {
134     for {set j 0} {$j < $limit_y} {incr j} {
135       set coord_x [expr $view_width/4 + $i]
136       set coord_y [expr ($view_height-$limit_y)/2 + $j]
137       if { "[vreadpixel $coord_x $coord_y rgb]" == "$r $g $b" } {
138         set HasPixel 1
139       }
140     }
141   }
142   if { $HasPixel == 1 } {
143     set TestPassed 0
144   } else {
145     set TestPassed [expr $TestPassed + 1]
146   }
147
148   # show all primitives
149   vdisplayall
150   vtop
151   vfit
152
153   # return a result
154   if { ${TestPassed} == 4 } {
155       return 1
156   } else {
157       return 0
158   }
159 }
160
161 vclose ALL
162
163 # ### THIS IS THE HEAD LOOP OF THE TEST ####################
164 # During this test primitives are created and displayed
165 # with commands vdrawparray, and verified for consistency
166 # with check_primitive procedure. In spite of the fact that there
167 # a lot of code below, it's similar and divided on the similar
168 # blocks of code.
169 # The iteration loop is intended to check primitives with
170 # "vertex buffer objects" turned off (vbo_enable = 0) and
171 # turned on (vbo_enable = 1)
172 for {set vbo_enable 0} {$vbo_enable < 2} {incr vbo_enable} {
173   for {set isNonInterleaved 0} {$isNonInterleaved < 2} {incr isNonInterleaved} {
174     vclear
175     vinit View1
176     vtop
177     vvbo $vbo_enable
178     if { $vbo_enable == 0 } {
179       puts "TEST WITH VBO is OFF"
180     } else {
181       puts "TEST WITH VBO is ON"
182     }
183     set aParams ""
184     if { $isNonInterleaved == 1 } { set aParams "-deinterleaved" }
185
186     # this points are only to simplify visiual check of dumped image
187     vpoint point1   65 0 0
188     vpoint point2 -145 0 0
189
190     # ****************************** Graphic3d_ArrayOfPoints ****************************** #
191     puts "Graphic3d_ArrayOfPoints: TEST"
192     generate_points 60 0 0   $colorY_R $colorY_G $colorY_B
193     eval vdrawparray pt01 points {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06
194
195     # ****************************** Graphic3d_ArrayOfSegments ****************************** #
196     puts "Graphic3d_ArrayOfSegments: TEST"
197
198     # 1: no indexes
199     generate_points 50 0 0   $colorY_R $colorY_G $colorY_B
200     eval vdrawparray seg01 segments {*}$aParams $pts02 $pts01 $pts01 $pts03 $pts03 $pts05 $pts05 $pts06 $pts06 $pts04 $pts04 $pts02
201
202     # 2: indexes
203     generate_points 40 0 0   $colorR_R $colorR_G $colorR_B
204     eval vdrawparray seg02 segments {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 e 1 e 2 e 2 e 4 e 4 e 6 e 6 e 5 e 5 e 3 e 3 e 1
205
206     # ****************************** Graphic3d_ArrayOfPolylines ****************************** #
207     puts "Graphic3d_ArrayOfPolylines: TEST"
208
209     # 1: no indexes
210     generate_points 30 0 0   $colorY_R $colorY_G $colorY_B
211     eval vdrawparray pline01 polylines {*}$aParams $pts02 $pts01 $pts03 $pts05 $pts06 $pts04 $pts02
212
213     # 2: indexes
214     generate_points 20 0 0   $colorR_R $colorR_G $colorR_B
215     eval vdrawparray pline02 polylines {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 e 2 e 4 e 6 e 5 e 3 e 1 e 2
216
217     # 3: bounds
218     generate_points 10 0 0   $colorY_R $colorY_G $colorY_B
219     eval vdrawparray pline03 polylines {*}$aParams ( b 3 ( $pts02 $pts01 $pts03 )), ( b 4 ( $pts03 $pts05 $pts06 $pts04 )), ( b 2 ( $pts04 $pts02 ))
220
221     # 4: bounds and indexes
222     generate_points 0 0 0   $colorR_R $colorR_G $colorR_B
223     eval vdrawparray pline04 polylines {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 ( b 4 ( e 2 e 1 e 3 e 5 )), ( b 4 ( e 5 e 6 e 4 e 2 ))
224
225     # ****************************** Graphic3d_ArrayOfTriangles ****************************** #
226     puts "Graphic3d_ArrayOfTriangles: TEST"
227
228     # 1: no indexes
229     generate_points -10 0 0   $colorB_R $colorB_G $colorB_B
230     eval vdrawparray t01 triangles {*}$aParams ( $pts03 $pts02 $pts01 ) , ( $pts03 $pts04 $pts02 ) , ( $pts04 $pts03 $pts06 ) , ( $pts06 $pts03 $pts05 )
231
232     # 2: indexes
233     generate_points -20 0 0   $colorG_R $colorG_G $colorG_B
234     eval vdrawparray t02 triangles {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 e 6 e 3 e 5 e 6 e 4 e 3 e 1 e 3 e 2 e 2 e 3 e 4
235
236     # ****************************** Graphic3d_ArrayOfTriangleFans ****************************** #
237     puts "Graphic3d_ArrayOfTriangleFans: TEST"
238
239     # 1: no bounds
240     generate_points -30 0 0    $colorB_R $colorB_G $colorB_B
241     eval vdrawparray tfan01 trianglefans {*}$aParams ( $pts02 $pts01 $pts03 $pts04 )
242     eval vdrawparray tfan02 trianglefans {*}$aParams ( $pts03 $pts05 $pts06 $pts04 )
243
244     # 2: bounds
245     generate_points -40 0 0   $colorG_R $colorG_G $colorG_B
246     eval vdrawparray tfan03 trianglefans {*}$aParams ( b 4 ( $pts02 $pts01 $pts03 $pts04 )), ( b 4 ( $pts03 $pts05 $pts06 $pts04 ))
247
248     # ****************************** Graphic3d_ArrayOfTriangleStrips ****************************** #
249     puts "Graphic3d_ArrayOfTriangleStrips: TEST"
250
251     # 1: no bounds
252     generate_points -50 0 0    $colorB_R $colorB_G $colorB_B
253     eval vdrawparray tstrip01 trianglestrips {*}$aParams ( $pts06 $pts04 $pts03 $pts02 $pts01 )
254     eval vdrawparray tstrip02 trianglestrips {*}$aParams ( $pts03 $pts05 $pts06 )
255
256     # 2: bounds
257     generate_points -60 0 0    $colorG_R $colorG_G $colorG_B
258     eval vdrawparray tstrip03 trianglestrips {*}$aParams ( b 5 ( $pts06 $pts04 $pts03 $pts02 $pts01 )) , ( b 3 ( $pts03 $pts05 $pts06 ))
259
260     # ****************************** Graphic3d_ArrayOfQuadrangles ****************************** #
261     puts "Graphic3d_ArrayOfQuadrangles: TEST"
262
263     # 1: no indexes
264     generate_points -70 0 0    $colorB_R $colorB_G $colorB_B
265     eval vdrawparray q01 quads {*}$aParams ( $pts01 $pts03 $pts04 $pts02 )
266     eval vdrawparray q02 quads {*}$aParams ( $pts03 $pts05 $pts06 $pts04 )
267
268     # 2: indexes
269     generate_points -80 0 0    $colorG_R $colorG_G $colorG_B
270     eval vdrawparray q03 quads {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 e 1 e 3 e 4 e 2 e 3 e 5 e 6 e 4
271
272     # ****************************** Graphic3d_ArrayOfQuadrangleStrips ****************************** #
273     puts "Graphic3d_ArrayOfQuadrangleStrips: TEST"
274
275     # 1: no bounds
276     generate_points -90 0 0    $colorB_R $colorB_G $colorB_B
277     eval vdrawparray qstrips01 quadstrips {*}$aParams ( $pts02 $pts01 $pts04 $pts03 $pts06 $pts05 )
278
279     # 2: bounds
280     generate_points -100 0 0    $colorG_R $colorG_G $colorG_B
281     eval vdrawparray qstrips02 quadstrips {*}$aParams ( b 4 ( $pts02 $pts01 $pts04 $pts03 )) , ( b 4 ( $pts04 $pts03 $pts06 $pts05 ))
282
283     # ****************************** Graphic3d_ArrayOfPolygons ****************************** #
284     puts "Graphic3d_ArrayOfPolygons: TEST"
285
286     # 1: no indexes
287     generate_points -110 0 0    $colorB_R $colorB_G $colorB_B
288     eval vdrawparray poly01 polygons {*}$aParams ( $pts04 $pts02 $pts01 $pts03 $pts05 $pts06 )
289
290     # 2: bounds
291     generate_points -120 0 0   $colorG_R $colorG_G $colorG_B
292     eval vdrawparray poly02 polygons {*}$aParams ( b 5 ( $pts04 $pts02 $pts01 $pts03 $pts06 )) , ( b 3 ( $pts06 $pts03 $pts05 ))
293
294     # 3: indexes
295     generate_points -130 0 0   $colorB_R $colorB_G $colorB_B
296     eval vdrawparray poly03 polygons {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 e 4 e 2 e 1 e 3 e 5 e 6
297
298     # 4: bounds and indexes
299     generate_points -140 0 0   $colorG_R $colorG_G $colorG_B
300     eval vdrawparray poly04 polygons {*}$aParams $pts01 $pts02 $pts03 $pts04 $pts05 $pts06 ( b 5 ( e 4 e 2 e 1 e 3 e 6 )), ( b 3 ( e 6 e 3 e 5 ))
301
302     # dump resulted image
303     set anImgName "${casename}"
304     if { $vbo_enable == 0 } { set anImgName "${anImgName}_vbooff" }
305     if { $vbo_enable == 1 } { set anImgName "${anImgName}_vboon" }
306     if { $isNonInterleaved == 1 } { set anImgName "${anImgName}_noninter" }
307     vfit
308     vdump ${imagedir}/${anImgName}.png
309   }
310 }
311
312 # delete internal procedures
313 rename generate_points ""
314 rename check_primitive ""
315
316 checkcolor 200 200 $colorG_R $colorG_G $colorG_B
317 checkcolor 220 200 $colorB_R $colorB_G $colorB_B
318 if { $stat == 1 } {
319   puts "BUG OK ${BUGNUMBER}"
320 } else {
321   puts "BUG FAULTY ${BUGNUMBER}"
322 }