• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import hilog from '@ohos.hilog';
17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
18
19import {checkError, createProgram, getColorUint8Array} from './WebGL1';
20
21
22export default function webgl1_attribute() {
23
24	describe('webgl1_attribute', function () {
25        let gl = global.gl;
26        // Defines a test suite. Two parameters are supported: test suite name and test suite function.
27        beforeAll(function () {
28            hilog.info(0x0000, 'testTag', '%{public}s', 'webgl1_test_01 start');
29            // Presets an action, which is performed only once before all test cases of the test suite start.
30            // This API supports only one parameter: preset action function.
31        })
32        beforeEach(function () {
33            // Presets an action, which is performed before each unit test case starts.
34            // The number of execution times is the same as the number of test cases defined by **it**.
35            // This API supports only one parameter: preset action function.
36            checkError(gl);
37        })
38        afterEach(function () {
39            // Presets a clear action, which is performed after each unit test case ends.
40            // The number of execution times is the same as the number of test cases defined by **it**.
41            // This API supports only one parameter: clear action function.
42            checkError(gl);
43        })
44        afterAll(function () {
45            // Presets a clear action, which is performed after all test cases of the test suite end.
46            // This API supports only one parameter: clear action function.
47            hilog.info(0x0000, 'testTag', '%{public}s', 'webgl1_test_01 end');
48        })
49
50        let getVertexAttribDesc = (attrib) => {
51            // 返回当前绑定的 WebGLBuffer。
52            let bufferBinding = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
53            // 返回一个 GLint,指示顶点数组元素的大小。
54            let size = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_SIZE);
55            // 返回一个 GLboolean,如果在此索引处启用了顶点属性,则该 GLboolean 为 true。 否则为假。
56            let enable = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
57            // 返回一个 GLint,指示数组中连续元素之间的字节数。 0 表示元素是连续的。
58            let stride = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_STRIDE);
59            // 返回表示数组类型的 GLenum。 其中之一 gl.BYTE  gl.UNSIGNED_BYTE gl.SHORT,gl.UNSIGNED_SHORT gl.FLOAT
60            let type = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_TYPE);
61            // 返回一个 GLboolean,如果对给定索引处的顶点属性数组规范化定点数据类型,则该 GLboolean 为 true。
62            let normalized = gl.getVertexAttrib(attrib, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)
63            // 返回一个 Float32Array(包含 4 个元素),表示给定索引处顶点属性的当前值。
64            let vertex = gl.getVertexAttrib(attrib, gl.CURRENT_VERTEX_ATTRIB);
65            return {bufferBinding, size, enable, stride, type, normalized, vertex}
66        }
67
68        function getAttribLocationTemp(callback, finish) {
69            let vSource = `
70            attribute vec4 a_Position;
71            attribute float a_PointSize;
72            void main(){
73                gl_Position = a_Position;
74                gl_PointSize = a_PointSize;
75            }
76        `;
77            let fSource = `
78            precision mediump float;
79            uniform vec4 u_FragColor;
80            void main(){
81                gl_FragColor = u_FragColor;
82            }
83        `
84            let p = createProgram(gl, vSource, fSource);
85            callback(p);
86            gl.deleteShader(p.vertexShader);
87            gl.deleteShader(p.fragmentShader);
88            gl.deleteProgram(p.program);
89            if (finish) finish();
90        }
91
92        /**
93         * 验证此方法是否返回了给定WebGLProgram对象中某属性的下标指向位置
94         */
95
96        /**
97         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0001
98         * @tc.name webgl_test_getAttribLocation
99         * @tc.desc Test getAttribLocation.
100         */
101        it('webgl_test_getAttribLocation', 0, async function (done) {
102            console.info("webgltest [webgl_test_getAttribLocation] getAttribLocation");
103            let vSource = `
104            attribute vec4 a_Position;
105            attribute float a_PointSize;
106            void main(){
107                gl_Position = a_Position;
108                gl_PointSize = a_PointSize;
109            }
110        `;
111            let fSource = `
112            precision mediump float;
113            uniform vec4 u_FragColor;
114            void main(){
115                gl_FragColor = u_FragColor;
116            }
117        `
118            let p = createProgram(gl, vSource, fSource);
119            let a_Position = gl.getAttribLocation(p.program, "a_Position");
120            console.info("webgltest vertexShader source :", vSource);
121            console.info("webgltest attribute a_Position:", a_Position);
122            expect(a_Position >= 0).assertTrue();
123            let a_PositionErr = gl.getAttribLocation(p.program, "a_Position_Err");
124            console.info("webgltest attribute a_PositionErr:", a_PositionErr);
125            expect(a_PositionErr).assertEqual(-1);
126            gl.deleteShader(p.vertexShader);
127            gl.deleteShader(p.fragmentShader);
128            gl.deleteProgram(p.program);
129            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
130            done();
131        })
132
133        /**
134         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0002
135         * @tc.name webgl_test_getAttribLocation_1
136         * @tc.desc Test getAttribLocation.
137         */
138        it('webgl_test_getAttribLocation_1', 0, async function (done) {
139            console.info("webgltest [webgl_test_getAttribLocation_1] getAttribLocation");
140            getAttribLocationTemp((p) => {
141                let attr = gl.getAttribLocation(p.program, 0);
142                console.info("webgltest ", attr);
143                expect(attr).assertEqual(-1);
144                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
145            });
146            done();
147        })
148
149        /**
150         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0003
151         * @tc.name webgl_test_getAttribLocation_2
152         * @tc.desc Test getAttribLocation.
153         */
154        it('webgl_test_getAttribLocation_2', 0, async function (done) {
155            console.info("webgltest [webgl_test_getAttribLocation_1] getAttribLocation");
156            getAttribLocationTemp((p) => {
157                let attr = gl.getAttribLocation(p.program, undefined);
158                console.info("webgltest ", attr);
159                expect(attr).assertEqual(-1);
160                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
161            });
162            done();
163        })
164
165        /**
166         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0004
167         * @tc.name webgl_test_getAttribLocation_3
168         * @tc.desc Test getAttribLocation.
169         */
170        it('webgl_test_getAttribLocation_3', 0, async function (done) {
171            console.info("webgltest [webgl_test_getAttribLocation_1] getAttribLocation");
172            getAttribLocationTemp((p) => {
173                let attr = gl.getAttribLocation(p.program, null);
174                console.info("webgltest ", attr);
175                expect(attr).assertEqual(-1);
176                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
177            });
178            done();
179        })
180
181        /**
182         * 验证getActiveAttrib方法是否返回一个WebGLActiveInfo对象,并包含在WebGLProgram中给到位置的一个顶点属性的尺寸、类型和名称。
183         */
184        function getActiveAttrib(callback, finish) {
185            let vSource = `
186            attribute vec4 a_Position;
187            void main(){
188                gl_Position = a_Position;
189                gl_PointSize = 10.0;
190            }
191        `;
192            let fSource = `
193            precision mediump float;
194            uniform vec4 u_FragColor;
195            void main(){
196                gl_FragColor = u_FragColor;
197            }
198        `
199            let p = createProgram(gl, vSource, fSource);
200            callback(p);
201            gl.deleteShader(p.vertexShader);
202            gl.deleteShader(p.fragmentShader);
203            gl.deleteProgram(p.program);
204            if (finish) finish();
205        }
206
207
208        /**
209         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0005
210         * @tc.name webgl_test_getActiveAttrib
211         * @tc.desc Test getActiveAttrib.
212         */
213        it('webgl_test_getActiveAttrib', 0, async function (done) {
214            console.info("webgltest [webgl_test_getActiveAttrib] getActiveAttrib");
215            let vSource = `
216            attribute vec4 a_Position;
217            void main(){
218                gl_Position = a_Position;
219                gl_PointSize = 10.0;
220            }
221        `;
222            let fSource = `
223            precision mediump float;
224            uniform vec4 u_FragColor;
225            void main(){
226                gl_FragColor = u_FragColor;
227            }
228        `
229            let p = createProgram(gl, vSource, fSource);
230
231            console.info("webgltest vertex shader source:", vSource);
232            let attribCount = gl.getProgramParameter(p.program, gl.ACTIVE_ATTRIBUTES);
233            console.info("webgltest attribCount:", attribCount);
234            let activeAttrib = gl.getActiveAttrib(p.program, 0);
235            console.info("webgltest ", activeAttrib);
236            expect(activeAttrib.name).assertEqual("a_Position");
237            expect(activeAttrib.type).assertEqual(gl.FLOAT_VEC4);
238            gl.deleteShader(p.vertexShader);
239            gl.deleteShader(p.fragmentShader);
240            gl.deleteProgram(p.program);
241            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
242            done();
243        })
244
245        /**
246         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0006
247         * @tc.name webgl_test_getActiveAttrib_1
248         * @tc.desc Test getActiveAttrib.
249         */
250        it('webgl_test_getActiveAttrib_1', 0, async function (done) {
251            console.info("webgltest [webgl_test_getActiveAttrib_1] getActiveAttrib");
252            getActiveAttrib((p) => {
253                let activeAttrib = gl.getActiveAttrib(p.program, 10);
254                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
255                console.info("webgltest ", activeAttrib);
256                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
257            });
258            done();
259        })
260
261
262        /**
263         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0007
264         * @tc.name webgl_test_getActiveAttrib_2
265         * @tc.desc Test getActiveAttrib.
266         */
267        it('webgl_test_getActiveAttrib_2', 0, async function (done) {
268            console.info("webgltest [webgl_test_getActiveAttrib_2] getActiveAttrib");
269            getActiveAttrib((p) => {
270                let activeAttrib = gl.getActiveAttrib(p.program, null);
271                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
272                console.info("webgltest ", activeAttrib);
273                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
274            });
275            done();
276        })
277
278
279        /**
280         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0008
281         * @tc.name webgl_test_getActiveAttrib_3
282         * @tc.desc Test getActiveAttrib.
283         */
284        it('webgl_test_getActiveAttrib_3', 0, async function (done) {
285            console.info("webgltest [webgl_test_getActiveAttrib_3] getActiveAttrib");
286            getActiveAttrib((p) => {
287                let activeAttrib = gl.getActiveAttrib(p.program, -1);
288                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
289                console.info("webgltest ", activeAttrib);
290                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
291            });
292            done();
293        })
294
295        /**
296         * 验证vertexAttrib1f方法是否可以给顶点 attibute 变量的1个分量赋值
297         */
298        function vertexAttrib1f(callback, finish) {
299            let vSource = `
300            attribute float a_PointSize;
301            void main(){
302                gl_Position = vec4(0.5, 0.5, 1, 1.0);
303                gl_PointSize = a_PointSize;
304            }
305        `;
306            let fSource = `
307            precision mediump float;
308            uniform vec4 u_FragColor;
309            void main(){
310                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
311            }
312        `
313            let p = createProgram(gl, vSource, fSource);
314            callback(p);
315            gl.deleteShader(p.vertexShader);
316            gl.deleteShader(p.fragmentShader);
317            gl.deleteProgram(p.program);
318            if (finish) finish();
319        }
320
321
322        /**
323         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0009
324         * @tc.name webgl_test_vertexAttrib1f
325         * @tc.desc Test vertexAttrib1f.
326         */
327        it('webgl_test_vertexAttrib1f', 0, async function (done) {
328            console.info("webgltest [webgl_test_vertexAttrib1f] vertexAttrib1f");
329            let vSource = `
330            attribute float a_PointSize;
331            void main(){
332                gl_Position = vec4(0.5, 0.5, 1, 1.0);
333                gl_PointSize = a_PointSize;
334            }
335        `;
336            let fSource = `
337            precision mediump float;
338            uniform vec4 u_FragColor;
339            void main(){
340                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
341            }
342        `
343            let p = createProgram(gl, vSource, fSource);
344            console.info("webgltest vertex shader source:", vSource);
345            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
346            console.info("webgltest vertexAttrib1f( 100.0) ");
347            gl.vertexAttrib1f(a_PointSize, 100.0);
348            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
349            console.log(vertexAttrib);
350            console.info("webgltest a_PointSize value: ", vertexAttrib[0]);
351            expect(vertexAttrib[0]).assertEqual(100);
352            gl.deleteShader(p.vertexShader);
353            gl.deleteShader(p.fragmentShader);
354            gl.deleteProgram(p.program);
355            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
356            done();
357        })
358
359
360        /**
361         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0010
362         * @tc.name webgl_test_vertexAttrib1f_1
363         * @tc.desc Test vertexAttrib1f.
364         */
365        it('webgl_test_vertexAttrib1f_1', 0, async function (done) {
366            console.info("webgltest [webgl_test_vertexAttrib1f_1] vertexAttrib1f");
367            vertexAttrib1f((p) => {
368                let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
369                gl.vertexAttrib1f(a_PointSize, 100);
370                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
371            })
372            done();
373        })
374
375
376        /**
377         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0011
378         * @tc.name webgl_test_vertexAttrib1f_2
379         * @tc.desc Test vertexAttrib1f.
380         */
381        it('webgl_test_vertexAttrib1f_2', 0, async function (done) {
382            console.info("webgltest [webgl_test_vertexAttrib1f_1] vertexAttrib1f");
383            vertexAttrib1f((p) => {
384                let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
385                gl.vertexAttrib1f(a_PointSize, null);
386                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
387            })
388            done();
389        })
390
391
392        /**
393         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0012
394         * @tc.name webgl_test_vertexAttrib1f_3
395         * @tc.desc Test vertexAttrib1f.
396         */
397        it('webgl_test_vertexAttrib1f_3', 0, async function (done) {
398            console.info("webgltest [webgl_test_vertexAttrib1f_1] vertexAttrib1f");
399            vertexAttrib1f((p) => {
400                let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
401                gl.vertexAttrib1f(a_PointSize, -100);
402                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
403            })
404            done();
405        })
406
407
408        /**
409         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0013
410         * @tc.name webgl_test_vertexAttrib1f_4
411         * @tc.desc Test vertexAttrib1f.
412         */
413        it('webgl_test_vertexAttrib1f_4', 0, async function (done) {
414            console.info("webgltest [webgl_test_vertexAttrib1f_4] vertexAttrib1f");
415            vertexAttrib1f((p) => {
416                let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
417                gl.vertexAttrib1f(null, null);
418                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
419            })
420            done();
421        })
422
423        /**
424         * 验证vertexAttrib2f方法是否可以给顶点 attibute 变量的2个分量赋值
425         */
426        function vertexAttrib2f(callback, verify) {
427            let vSource = `
428            attribute float a_PointSize;
429            void main(){
430                gl_Position = vec4(0.5, 0.5, 1, 1.0);
431                gl_PointSize = a_PointSize;
432            }
433        `;
434            let fSource = `
435            precision mediump float;
436            uniform vec4 u_FragColor;
437            void main(){
438                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
439            }
440        `
441            let p = createProgram(gl, vSource, fSource);
442            console.info("webgltest vertex shader source:", vSource);
443            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
444            callback(a_PointSize);
445            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
446            console.info("webgltest a_PointSize value: ", vertexAttrib);
447            verify(vertexAttrib);
448            gl.deleteShader(p.vertexShader);
449            gl.deleteShader(p.fragmentShader);
450            gl.deleteProgram(p.program);
451        }
452
453
454        /**
455         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0014
456         * @tc.name webgl_test_vertexAttrib2f
457         * @tc.desc Test vertexAttrib2f.
458         */
459        it('webgl_test_vertexAttrib2f', 0, async function (done) {
460            console.info("webgltest [webgl_test_vertexAttrib2f] vertexAttrib2f");
461            let vSource = `
462            attribute float a_PointSize;
463            void main(){
464                gl_Position = vec4(0.5, 0.5, 1, 1.0);
465                gl_PointSize = a_PointSize;
466            }
467        `;
468            let fSource = `
469            precision mediump float;
470            uniform vec4 u_FragColor;
471            void main(){
472                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
473            }
474        `
475            let p = createProgram(gl, vSource, fSource);
476            console.info("webgltest vertex shader source:", vSource);
477            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
478            console.info("webgltest vertexAttrib2f( 100.0, 100.0) ");
479            gl.vertexAttrib2f(a_PointSize, 100.0, 100);
480            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
481            console.info("webgltest a_PointSize value: ", vertexAttrib);
482            expect(vertexAttrib[0]).assertEqual(100);
483            expect(vertexAttrib[1]).assertEqual(100);
484            gl.deleteShader(p.vertexShader);
485            gl.deleteShader(p.fragmentShader);
486            gl.deleteProgram(p.program);
487            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
488            done();
489        })
490
491
492        /**
493         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0015
494         * @tc.name webgl_test_vertexAttrib2f_1
495         * @tc.desc Test vertexAttrib2f.
496         */
497        it('webgl_test_vertexAttrib2f_1', 0, async function (done) {
498            console.info("webgltest [webgl_test_vertexAttrib2f_1] vertexAttrib2f");
499            vertexAttrib2f((attrib) => {
500                gl.vertexAttrib2f(attrib, null, null);
501            }, (attrib) => {
502                expect(attrib[0]).assertEqual(0);
503                expect(attrib[1]).assertEqual(0);
504                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
505            });
506            done();
507        })
508
509
510        /**
511         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0016
512         * @tc.name webgl_test_vertexAttrib2f_2
513         * @tc.desc Test vertexAttrib2f.
514         */
515        it('webgl_test_vertexAttrib2f_2', 0, async function (done) {
516            console.info("webgltest [webgl_test_vertexAttrib2f_2] vertexAttrib2f");
517            vertexAttrib2f((attrib) => {
518                gl.vertexAttrib2f(attrib, -100, -100);
519            }, (attrib) => {
520                expect(attrib[0]).assertEqual(-100);
521                expect(attrib[1]).assertEqual(-100);
522                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
523            });
524            done();
525        })
526
527
528        /**
529         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0017
530         * @tc.name webgl_test_vertexAttrib2f_3
531         * @tc.desc Test vertexAttrib2f.
532         */
533        it('webgl_test_vertexAttrib2f_3', 0, async function (done) {
534            console.info("webgltest [webgl_test_vertexAttrib2f_3] vertexAttrib2f");
535            vertexAttrib2f((attrib) => {
536                gl.vertexAttrib2f(-1, -200, -100);
537                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
538            }, (attrib) => {
539                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
540            });
541            done();
542        })
543
544        /**
545         * 验证vertexAttrib3f方法是否可以给顶点 attibute 变量的3个分量赋值
546         */
547        function vertexAttrib3f(callback, finish) {
548            let vSource = `
549            attribute float a_PointSize;
550            void main(){
551                gl_Position = vec4(0.5, 0.5, 1, 1.0);
552                gl_PointSize = a_PointSize;
553            }
554        `;
555            let fSource = `
556            precision mediump float;
557            uniform vec4 u_FragColor;
558            void main(){
559                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
560            }
561        `
562            let p = createProgram(gl, vSource, fSource);
563            console.info("webgltest vertex shader source:", vSource);
564            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
565            callback(a_PointSize);
566            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
567            finish(vertexAttrib);
568            gl.deleteShader(p.vertexShader);
569            gl.deleteShader(p.fragmentShader);
570            gl.deleteProgram(p.program);
571        }
572
573
574        /**
575         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0018
576         * @tc.name webgl_test_vertexAttrib3f
577         * @tc.desc Test vertexAttrib3f.
578         */
579        it('webgl_test_vertexAttrib3f', 0, async function (done) {
580            console.info("webgltest [webgl_test_vertexAttrib3f] vertexAttrib3f");
581            let vSource = `
582            attribute float a_PointSize;
583            void main(){
584                gl_Position = vec4(0.5, 0.5, 1, 1.0);
585                gl_PointSize = a_PointSize;
586            }
587        `;
588            let fSource = `
589            precision mediump float;
590            uniform vec4 u_FragColor;
591            void main(){
592                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
593            }
594        `
595            let p = createProgram(gl, vSource, fSource);
596            console.info("webgltest vertex shader source:", vSource);
597            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
598            console.info("webgltest vertexAttrib3f( 100.0, 100.0, 100.0) ");
599            gl.vertexAttrib3f(a_PointSize, 100.0, 100.0, 100.0);
600            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
601            console.info("webgltest a_PointSize value: ", vertexAttrib);
602            expect(vertexAttrib[0]).assertEqual(100);
603            expect(vertexAttrib[1]).assertEqual(100);
604            expect(vertexAttrib[2]).assertEqual(100);
605            gl.deleteShader(p.vertexShader);
606            gl.deleteShader(p.fragmentShader);
607            gl.deleteProgram(p.program);
608            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
609            done();
610        })
611
612
613        /**
614         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0019
615         * @tc.name webgl_test_vertexAttrib3f_1
616         * @tc.desc Test vertexAttrib3f.
617         */
618        it('webgl_test_vertexAttrib3f_1', 0, async function (done) {
619            console.info("webgltest [webgl_test_vertexAttrib3f_1] vertexAttrib3f");
620            vertexAttrib3f((attrib) => {
621                gl.vertexAttrib3f(attrib, null, null, null);
622                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
623            }, (attrib) => {
624                expect(attrib[0]).assertEqual(0);
625                expect(attrib[1]).assertEqual(0);
626                expect(attrib[2]).assertEqual(0);
627                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
628            })
629            done();
630        })
631
632
633        /**
634         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0020
635         * @tc.name webgl_test_vertexAttrib3f_2
636         * @tc.desc Test vertexAttrib3f.
637         */
638        it('webgl_test_vertexAttrib3f_2', 0, async function (done) {
639            console.info("webgltest [webgl_test_vertexAttrib3f_2] vertexAttrib3f");
640            vertexAttrib3f((attrib) => {
641                gl.vertexAttrib3f(attrib, -1, -1, -1);
642                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
643            }, (attrib) => {
644                expect(attrib[0]).assertEqual(-1);
645                expect(attrib[1]).assertEqual(-1);
646                expect(attrib[2]).assertEqual(-1);
647                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
648            })
649            done();
650        })
651
652
653        /**
654         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0021
655         * @tc.name webgl_test_vertexAttrib3f_3
656         * @tc.desc Test vertexAttrib3f.
657         */
658        it('webgl_test_vertexAttrib3f_3', 0, async function (done) {
659            console.info("webgltest [webgl_test_vertexAttrib3f_3] vertexAttrib3f");
660            vertexAttrib3f((attrib) => {
661                gl.vertexAttrib3f(attrib, undefined, undefined, undefined);
662                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
663            }, (attrib) => {
664                expect(attrib[0].toString()).assertEqual("NaN");
665                expect(attrib[1].toString()).assertEqual("NaN");
666                expect(attrib[2].toString()).assertEqual("NaN");
667                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
668            })
669            done();
670        })
671
672
673        /**
674         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0022
675         * @tc.name webgl_test_vertexAttrib3f_4
676         * @tc.desc Test vertexAttrib3f.
677         */
678        it('webgl_test_vertexAttrib3f_4', 0, async function (done) {
679            console.info("webgltest [webgl_test_vertexAttrib3f_4] vertexAttrib3f");
680            vertexAttrib3f((attrib) => {
681                gl.vertexAttrib3f(-1, null, null, null);
682                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
683            }, (attrib) => {
684                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
685            })
686            done();
687        })
688
689        /**
690         * 验证vertexAttrib4f方法是否可以给顶点 attibute 变量的4个分量赋值
691         */
692        function vertexAttrib4f(callback, finish) {
693            let vSource = `
694            attribute float a_PointSize;
695            void main(){
696                gl_Position = vec4(0.5, 0.5, 1, 1.0);
697                gl_PointSize = a_PointSize;
698            }
699        `;
700            let fSource = `
701            precision mediump float;
702            uniform vec4 u_FragColor;
703            void main(){
704                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
705            }
706        `
707            let p = createProgram(gl, vSource, fSource);
708            console.info("webgltest vertex shader source:", vSource);
709            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
710            callback(a_PointSize);
711            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
712            finish(vertexAttrib);
713            gl.deleteShader(p.vertexShader);
714            gl.deleteShader(p.fragmentShader);
715            gl.deleteProgram(p.program);
716        }
717
718
719        /**
720         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0023
721         * @tc.name webgl_test_vertexAttrib4f
722         * @tc.desc Test vertexAttrib4f.
723         */
724        it('webgl_test_vertexAttrib4f', 0, async function (done) {
725            console.info("webgltest [webgl_test_vertexAttrib4f] vertexAttrib4f");
726            let vSource = `
727            attribute float a_PointSize;
728            void main(){
729                gl_Position = vec4(0.5, 0.5, 1, 1.0);
730                gl_PointSize = a_PointSize;
731            }
732        `;
733            let fSource = `
734            precision mediump float;
735            uniform vec4 u_FragColor;
736            void main(){
737                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
738            }
739        `
740            let p = createProgram(gl, vSource, fSource);
741            console.info("webgltest vertex shader source:", vSource);
742            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
743            console.info("webgltest vertexAttrib4f( 100.0, 100.0, 100.0,100.0) ");
744            gl.vertexAttrib4f(a_PointSize, 100.0, 100.0, 100.0, 100.0);
745            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
746            console.info("webgltest a_PointSize value: ", vertexAttrib);
747            expect(vertexAttrib[0]).assertEqual(100);
748            expect(vertexAttrib[1]).assertEqual(100);
749            expect(vertexAttrib[2]).assertEqual(100);
750            expect(vertexAttrib[3]).assertEqual(100);
751            gl.deleteShader(p.vertexShader);
752            gl.deleteShader(p.fragmentShader);
753            gl.deleteProgram(p.program);
754            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
755            done();
756        })
757
758
759        /**
760         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0024
761         * @tc.name webgl_test_vertexAttrib4f_1
762         * @tc.desc Test vertexAttrib4f.
763         */
764        it('webgl_test_vertexAttrib4f_1', 0, async function (done) {
765            console.info("webgltest [webgl_test_vertexAttrib4f_1] vertexAttrib4f");
766            vertexAttrib4f((attrib) => {
767                gl.vertexAttrib4f(attrib, null, null, null, null);
768                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
769            }, (attrib) => {
770                expect(attrib[0]).assertEqual(0);
771                expect(attrib[1]).assertEqual(0);
772                expect(attrib[2]).assertEqual(0);
773                expect(attrib[3]).assertEqual(0);
774                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
775            })
776            done();
777        })
778
779
780        /**
781         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0025
782         * @tc.name webgl_test_vertexAttrib4f_2
783         * @tc.desc Test vertexAttrib4f.
784         */
785        it('webgl_test_vertexAttrib4f_2', 0, async function (done) {
786            console.info("webgltest [webgl_test_vertexAttrib4f_2] vertexAttrib4f");
787            vertexAttrib4f((attrib) => {
788                gl.vertexAttrib4f(attrib, -1, -1, -1, -1);
789                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
790            }, (attrib) => {
791                expect(attrib[0]).assertEqual(-1);
792                expect(attrib[1]).assertEqual(-1);
793                expect(attrib[2]).assertEqual(-1);
794                expect(attrib[3]).assertEqual(-1);
795                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
796            })
797            done();
798        })
799
800
801        /**
802         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0026
803         * @tc.name webgl_test_vertexAttrib4f_3
804         * @tc.desc Test vertexAttrib4f.
805         */
806        it('webgl_test_vertexAttrib4f_3', 0, async function (done) {
807            console.info("webgltest [webgl_test_vertexAttrib4f_3] vertexAttrib4f");
808            vertexAttrib4f((attrib) => {
809                gl.vertexAttrib4f(attrib, undefined, undefined, undefined, undefined);
810                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
811            }, (attrib) => {
812                expect(attrib[0].toString()).assertEqual("NaN");
813                expect(attrib[1].toString()).assertEqual("NaN");
814                expect(attrib[2].toString()).assertEqual("NaN");
815                expect(attrib[3].toString()).assertEqual("NaN");
816                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
817            })
818            done();
819        })
820
821
822        /**
823         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0027
824         * @tc.name webgl_test_vertexAttrib4f_4
825         * @tc.desc Test vertexAttrib4f.
826         */
827        it('webgl_test_vertexAttrib4f_4', 0, async function (done) {
828            console.info("webgltest [webgl_test_vertexAttrib4f_4] vertexAttrib4f");
829            vertexAttrib4f((attrib) => {
830                gl.vertexAttrib4f(-1, 0, 0, 0, 0);
831                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
832            }, (attrib) => {
833                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
834            })
835            done();
836        })
837
838        /**
839         * 验证vertexAttrib1fv方法是否可以给顶点 attibute 变量的第一个向量值
840         */
841        function vertexAttrib1fv(callback, finish) {
842            let vSource = `
843            attribute float a_PointSize;
844            void main(){
845                gl_Position = vec4(0.5, 0.5, 1, 1.0);
846                gl_PointSize = a_PointSize;
847            }
848        `;
849            let fSource = `
850            precision mediump float;
851            uniform vec4 u_FragColor;
852            void main(){
853                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
854            }
855        `
856            let p = createProgram(gl, vSource, fSource);
857            console.info("webgltest vertex shader source:", vSource);
858            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
859            callback(a_PointSize);
860            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
861            finish(vertexAttrib);
862            gl.deleteShader(p.vertexShader);
863            gl.deleteShader(p.fragmentShader);
864            gl.deleteProgram(p.program);
865        }
866
867
868        /**
869         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0028
870         * @tc.name webgl_test_vertexAttrib1fv
871         * @tc.desc Test vertexAttrib1fv.
872         */
873        it('webgl_test_vertexAttrib1fv', 0, async function (done) {
874            console.info("webgltest [webgl_test_vertexAttrib1fv] vertexAttrib1fv");
875            let vSource = `
876            attribute float a_PointSize;
877            void main(){
878                gl_Position = vec4(0.5, 0.5, 1, 1.0);
879                gl_PointSize = a_PointSize;
880            }
881        `;
882            let fSource = `
883            precision mediump float;
884            uniform vec4 u_FragColor;
885            void main(){
886                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
887            }
888        `
889            let p = createProgram(gl, vSource, fSource);
890            console.info("webgltest vertex shader source:", vSource);
891            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
892            console.info("webgltest vertexAttrib1fv(a_PointSize,new Float32Array([100.0, 100.0, 100.0, 100.0])) ");
893            gl.vertexAttrib1fv(a_PointSize, new Float32Array([100.0, 100.0, 100.0, 100.0]));
894            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
895            console.info("webgltest a_PointSize value: ", vertexAttrib);
896            expect(vertexAttrib[0]).assertEqual(100);
897            expect(vertexAttrib[1] != 100).assertTrue();
898            expect(vertexAttrib[2] != 100).assertTrue();
899            expect(vertexAttrib[3] != 100).assertTrue();
900            gl.deleteShader(p.vertexShader);
901            gl.deleteShader(p.fragmentShader);
902            gl.deleteProgram(p.program);
903            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
904            done();
905        })
906
907
908        /**
909         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0029
910         * @tc.name webgl_test_vertexAttrib1fv_1
911         * @tc.desc Test vertexAttrib1fv.
912         */
913        it('webgl_test_vertexAttrib1fv_1', 0, async function (done) {
914            console.info("webgltest [webgl_test_vertexAttrib1fv_1] vertexAttrib1fv");
915            vertexAttrib1fv((attrib) => {
916                gl.vertexAttrib1fv(attrib, new Float32Array([-100.0]));
917                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
918            }, (attrib) => {
919                expect(attrib[0]).assertEqual(-100);
920                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
921            })
922            done();
923        })
924
925        /**
926         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0030
927         * @tc.name webgl_test_vertexAttrib1fv_2
928         * @tc.desc Test vertexAttrib1fv.
929         */
930        it('webgl_test_vertexAttrib1fv_2', 0, async function (done) {
931            console.info("webgltest [webgl_test_vertexAttrib1fv_2] vertexAttrib1fv");
932            vertexAttrib1fv((attrib) => {
933                gl.vertexAttrib1fv(attrib, new Float32Array([undefined]));
934                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
935            }, (attrib) => {
936                expect(attrib[0].toString()).assertEqual("NaN");
937                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
938            })
939            done();
940        })
941
942        /**
943         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0031
944         * @tc.name webgl_test_vertexAttrib1fv_3
945         * @tc.desc Test vertexAttrib1fv.
946         */
947        it('webgl_test_vertexAttrib1fv_3', 0, async function (done) {
948            console.info("webgltest [webgl_test_vertexAttrib1fv_3] vertexAttrib1fv");
949            vertexAttrib1fv((attrib) => {
950                gl.vertexAttrib1fv(attrib, new Float32Array([null]));
951                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
952            }, (attrib) => {
953                expect(attrib[0]).assertEqual(0);
954                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
955            })
956            done();
957        })
958
959
960        /**
961         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0032
962         * @tc.name webgl_test_vertexAttrib1fv_4
963         * @tc.desc Test vertexAttrib1fv.
964         */
965        it('webgl_test_vertexAttrib1fv_4', 0, async function (done) {
966            console.info("webgltest [webgl_test_vertexAttrib1fv_4] vertexAttrib1fv");
967            vertexAttrib1fv((attrib) => {
968                gl.vertexAttrib1fv(attrib, new Float32Array([-100]));
969                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
970            }, (attrib) => {
971                expect(attrib[0]).assertEqual(-100);
972                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
973            })
974            done();
975        })
976
977        /**
978         * 验证vertexAttrib2fv方法是否可以给顶点 attibute 变量的第2个向量值
979         */
980        function vertexAttrib2fv(callback, finish) {
981            let vSource = `
982            attribute float a_PointSize;
983            void main(){
984                gl_Position = vec4(0.5, 0.5, 1, 1.0);
985                gl_PointSize = a_PointSize;
986            }
987        `;
988            let fSource = `
989            precision mediump float;
990            uniform vec4 u_FragColor;
991            void main(){
992                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
993            }
994        `
995            let p = createProgram(gl, vSource, fSource);
996            console.info("webgltest vertex shader source:", vSource);
997            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
998            callback(a_PointSize);
999            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1000            finish(vertexAttrib);
1001            gl.deleteShader(p.vertexShader);
1002            gl.deleteShader(p.fragmentShader);
1003            gl.deleteProgram(p.program);
1004        }
1005
1006
1007        /**
1008         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0033
1009         * @tc.name webgl_test_vertexAttrib2fv
1010         * @tc.desc Test vertexAttrib2fv.
1011         */
1012        it('webgl_test_vertexAttrib2fv', 0, async function (done) {
1013            console.info("webgltest [webgl_test_vertexAttrib2fv] vertexAttrib2fv");
1014            let vSource = `
1015            attribute float a_PointSize;
1016            void main(){
1017                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1018                gl_PointSize = a_PointSize;
1019            }
1020        `;
1021            let fSource = `
1022            precision mediump float;
1023            uniform vec4 u_FragColor;
1024            void main(){
1025                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1026            }
1027        `
1028            let p = createProgram(gl, vSource, fSource);
1029            console.info("webgltest vertex shader source:", vSource);
1030            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1031            console.info("webgltest vertexAttrib2fv(a_PointSize,new Float32Array([100.0, 100.0, 100.0, 100.0])) ");
1032            gl.vertexAttrib2fv(a_PointSize, new Float32Array([100.0, 100.0, 100.0, 100.0]));
1033            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1034            console.info("webgltest a_PointSize value: ", vertexAttrib);
1035            expect(vertexAttrib[0]).assertEqual(100);
1036            expect(vertexAttrib[1]).assertEqual(100);
1037            expect(vertexAttrib[2] != 100).assertTrue();
1038            expect(vertexAttrib[3] != 100).assertTrue();
1039            gl.deleteShader(p.vertexShader);
1040            gl.deleteShader(p.fragmentShader);
1041            gl.deleteProgram(p.program);
1042            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1043            done();
1044        })
1045
1046        /**
1047         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0034
1048         * @tc.name webgl_test_vertexAttrib2fv_1
1049         * @tc.desc Test vertexAttrib2fv.
1050         */
1051        it('webgl_test_vertexAttrib2fv_1', 0, async function (done) {
1052            console.info("webgltest [webgl_test_vertexAttrib2fv_1] vertexAttrib2fv");
1053            vertexAttrib2fv((attrib) => {
1054                gl.vertexAttrib2fv(attrib, new Float32Array([-100.0, -100.0]));
1055                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1056            }, (attrib) => {
1057                expect(attrib[0]).assertEqual(-100);
1058                expect(attrib[1]).assertEqual(-100);
1059                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1060            })
1061            done();
1062        })
1063
1064        /**
1065         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0035
1066         * @tc.name webgl_test_vertexAttrib2fv_2
1067         * @tc.desc Test vertexAttrib2fv.
1068         */
1069        it('webgl_test_vertexAttrib2fv_2', 0, async function (done) {
1070            console.info("webgltest [webgl_test_vertexAttrib2fv_2] vertexAttrib2fv");
1071            vertexAttrib2fv((attrib) => {
1072                gl.vertexAttrib2fv(attrib, new Float32Array([undefined, undefined]));
1073                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1074            }, (attrib) => {
1075                expect(attrib[0].toString()).assertEqual("NaN");
1076                expect(attrib[1].toString()).assertEqual("NaN");
1077                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1078            })
1079            done();
1080        })
1081
1082
1083        /**
1084         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0036
1085         * @tc.name webgl_test_vertexAttrib2fv_3
1086         * @tc.desc Test vertexAttrib2fv.
1087         */
1088        it('webgl_test_vertexAttrib2fv_3', 0, async function (done) {
1089            console.info("webgltest [webgl_test_vertexAttrib2fv_3] vertexAttrib2fv");
1090            vertexAttrib2fv((attrib) => {
1091                gl.vertexAttrib2fv(attrib, new Float32Array([null, null]));
1092                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1093            }, (attrib) => {
1094                expect(attrib[0]).assertEqual(0);
1095                expect(attrib[1]).assertEqual(0);
1096                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1097            })
1098            done();
1099        })
1100
1101
1102        /**
1103         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0037
1104         * @tc.name webgl_test_vertexAttrib2fv_4
1105         * @tc.desc Test vertexAttrib2fv.
1106         */
1107        it('webgl_test_vertexAttrib2fv_4', 0, async function (done) {
1108            console.info("webgltest [webgl_test_vertexAttrib2fv_4] vertexAttrib2fv");
1109            vertexAttrib2fv((attrib) => {
1110                gl.vertexAttrib2fv(attrib, new Float32Array([-100, 100]));
1111                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1112            }, (attrib) => {
1113                expect(attrib[0]).assertEqual(-100);
1114                expect(attrib[1]).assertEqual(100);
1115                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1116            })
1117            done();
1118        })
1119
1120        /**
1121         * 验证vertexAttrib3fv方法是否可以给顶点 attibute 变量的第3个向量值
1122         */
1123        function vertexAttrib3fv(callback, finish) {
1124            let vSource = `
1125            attribute float a_PointSize;
1126            void main(){
1127                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1128                gl_PointSize = a_PointSize;
1129            }
1130        `;
1131            let fSource = `
1132            precision mediump float;
1133            uniform vec4 u_FragColor;
1134            void main(){
1135                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1136            }
1137        `
1138            let p = createProgram(gl, vSource, fSource);
1139            console.info("webgltest vertex shader source:", vSource);
1140            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1141            callback(a_PointSize);
1142            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1143            finish(vertexAttrib);
1144            gl.deleteShader(p.vertexShader);
1145            gl.deleteShader(p.fragmentShader);
1146            gl.deleteProgram(p.program);
1147        }
1148
1149
1150        /**
1151         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0038
1152         * @tc.name webgl_test_vertexAttrib3fv
1153         * @tc.desc Test vertexAttrib3fv.
1154         */
1155        it('webgl_test_vertexAttrib3fv', 0, async function (done) {
1156            console.info("webgltest [webgl_test_vertexAttrib3fv] vertexAttrib3fv");
1157            let vSource = `
1158            attribute float a_PointSize;
1159            void main(){
1160                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1161                gl_PointSize = a_PointSize;
1162            }
1163        `;
1164            let fSource = `
1165            precision mediump float;
1166            uniform vec4 u_FragColor;
1167            void main(){
1168                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1169            }
1170        `
1171            let p = createProgram(gl, vSource, fSource);
1172            console.info("webgltest vertex shader source:", vSource);
1173            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1174            console.info("webgltest vertexAttrib3fv(a_PointSize,new Float32Array([100.0, 100.0, 100.0, 100.0])) ");
1175            gl.vertexAttrib3fv(a_PointSize, new Float32Array([100.0, 100.0, 100.0, 100.0]));
1176            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1177            console.info("webgltest a_PointSize value: ", vertexAttrib);
1178            expect(vertexAttrib[0]).assertEqual(100);
1179            expect(vertexAttrib[1]).assertEqual(100);
1180            expect(vertexAttrib[2]).assertEqual(100);
1181            expect(vertexAttrib[3] != 100).assertTrue();
1182            gl.deleteShader(p.vertexShader);
1183            gl.deleteShader(p.fragmentShader);
1184            gl.deleteProgram(p.program);
1185            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1186            done();
1187        })
1188
1189
1190        /**
1191         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0039
1192         * @tc.name webgl_test_vertexAttrib3fv_1
1193         * @tc.desc Test vertexAttrib3fv.
1194         */
1195        it('webgl_test_vertexAttrib3fv_1', 0, async function (done) {
1196            console.info("webgltest [webgl_test_vertexAttrib3fv_1] vertexAttrib3fv");
1197            vertexAttrib3fv((attrib) => {
1198                gl.vertexAttrib3fv(attrib, new Float32Array([-100.0, -100.0, -100.0]));
1199                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1200            }, (attrib) => {
1201                expect(attrib[0]).assertEqual(-100);
1202                expect(attrib[1]).assertEqual(-100);
1203                expect(attrib[2]).assertEqual(-100);
1204                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1205            })
1206            done();
1207        })
1208
1209
1210        /**
1211         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0040
1212         * @tc.name webgl_test_vertexAttrib3fv_2
1213         * @tc.desc Test vertexAttrib3fv.
1214         */
1215        it('webgl_test_vertexAttrib3fv_2', 0, async function (done) {
1216            console.info("webgltest [webgl_test_vertexAttrib3fv_2] vertexAttrib3fv");
1217            vertexAttrib3fv((attrib) => {
1218                gl.vertexAttrib3fv(attrib, new Float32Array([undefined, undefined, undefined]));
1219                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1220            }, (attrib) => {
1221                expect(attrib[0].toString()).assertEqual("NaN");
1222                expect(attrib[1].toString()).assertEqual("NaN");
1223                expect(attrib[2].toString()).assertEqual("NaN");
1224                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1225            })
1226            done();
1227        })
1228
1229
1230        /**
1231         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0041
1232         * @tc.name webgl_test_vertexAttrib3fv_3
1233         * @tc.desc Test vertexAttrib3fv.
1234         */
1235        it('webgl_test_vertexAttrib3fv_3', 0, async function (done) {
1236            console.info("webgltest [webgl_test_vertexAttrib3fv_3] vertexAttrib3fv");
1237            vertexAttrib3fv((attrib) => {
1238                gl.vertexAttrib3fv(attrib, new Float32Array([null, null, null]));
1239                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1240            }, (attrib) => {
1241                expect(attrib[0]).assertEqual(0);
1242                expect(attrib[1]).assertEqual(0);
1243                expect(attrib[2]).assertEqual(0);
1244                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1245            })
1246            done();
1247        })
1248
1249
1250        /**
1251         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0042
1252         * @tc.name webgl_test_vertexAttrib3fv_4
1253         * @tc.desc Test vertexAttrib3fv.
1254         */
1255        it('webgl_test_vertexAttrib3fv_4', 0, async function (done) {
1256            console.info("webgltest [webgl_test_vertexAttrib3fv_4] vertexAttrib3fv");
1257            vertexAttrib3fv((attrib) => {
1258                gl.vertexAttrib3fv(-1, new Float32Array([-100, 100, 100]));
1259                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
1260            }, (attrib) => {
1261                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1262            })
1263            done();
1264        })
1265
1266        /**
1267         * 验证vertexAttrib4fv方法是否可以给顶点 attibute 变量的第4个向量值
1268         */
1269        function vertexAttrib4fv(callback, finish) {
1270            let vSource = `
1271            attribute float a_PointSize;
1272            void main(){
1273                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1274                gl_PointSize = a_PointSize;
1275            }
1276        `;
1277            let fSource = `
1278            precision mediump float;
1279            uniform vec4 u_FragColor;
1280            void main(){
1281                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1282            }
1283        `
1284            let p = createProgram(gl, vSource, fSource);
1285            console.info("webgltest vertex shader source:", vSource);
1286            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1287            callback(a_PointSize);
1288            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1289            finish(vertexAttrib);
1290            gl.deleteShader(p.vertexShader);
1291            gl.deleteShader(p.fragmentShader);
1292            gl.deleteProgram(p.program);
1293        }
1294
1295
1296        /**
1297         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0043
1298         * @tc.name webgl_test_vertexAttrib4fv
1299         * @tc.desc Test vertexAttrib4fv.
1300         */
1301        it('webgl_test_vertexAttrib4fv', 0, async function (done) {
1302            console.info("webgltest [webgl_test_vertexAttrib4fv] vertexAttrib4fv");
1303            let vSource = `
1304            attribute float a_PointSize;
1305            void main(){
1306                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1307                gl_PointSize = a_PointSize;
1308            }
1309        `;
1310            let fSource = `
1311            precision mediump float;
1312            uniform vec4 u_FragColor;
1313            void main(){
1314                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1315            }
1316        `
1317            let p = createProgram(gl, vSource, fSource);
1318            console.info("webgltest vertex shader source:", vSource);
1319            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1320            console.info("webgltest vertexAttrib4fv(a_PointSize,new Float32Array([100.0, 100.0, 100.0, 100.0])) ");
1321            gl.vertexAttrib4fv(a_PointSize, new Float32Array([100.0, 100.0, 100.0, 100.0]));
1322            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1323            console.info("webgltest a_PointSize value: ", vertexAttrib);
1324            expect(vertexAttrib[0]).assertEqual(100);
1325            expect(vertexAttrib[1]).assertEqual(100);
1326            expect(vertexAttrib[2]).assertEqual(100);
1327            expect(vertexAttrib[3]).assertEqual(100);
1328            gl.deleteShader(p.vertexShader);
1329            gl.deleteShader(p.fragmentShader);
1330            gl.deleteProgram(p.program);
1331            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1332            done();
1333        })
1334
1335
1336        /**
1337         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0044
1338         * @tc.name webgl_test_vertexAttrib4fv_1
1339         * @tc.desc Test vertexAttrib4fv.
1340         */
1341        it('webgl_test_vertexAttrib4fv_1', 0, async function (done) {
1342            console.info("webgltest [webgl_test_vertexAttrib4fv_1] vertexAttrib4fv");
1343            vertexAttrib4fv((attrib) => {
1344                gl.vertexAttrib4fv(attrib, new Float32Array([-100.0, -100.0, -100.0, -100.0]));
1345                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1346            }, (attrib) => {
1347                expect(attrib[0]).assertEqual(-100);
1348                expect(attrib[1]).assertEqual(-100);
1349                expect(attrib[2]).assertEqual(-100);
1350                expect(attrib[3]).assertEqual(-100);
1351                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1352            })
1353            done();
1354        })
1355
1356
1357        /**
1358         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0045
1359         * @tc.name webgl_test_vertexAttrib4fv_2
1360         * @tc.desc Test vertexAttrib4fv.
1361         */
1362        it('webgl_test_vertexAttrib4fv_2', 0, async function (done) {
1363            console.info("webgltest [webgl_test_vertexAttrib4fv_2] vertexAttrib4fv");
1364            vertexAttrib4fv((attrib) => {
1365                gl.vertexAttrib4fv(attrib, new Float32Array([undefined, undefined, undefined, undefined]));
1366                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1367            }, (attrib) => {
1368                expect(attrib[0].toString()).assertEqual("NaN");
1369                expect(attrib[1].toString()).assertEqual("NaN");
1370                expect(attrib[2].toString()).assertEqual("NaN");
1371                expect(attrib[3].toString()).assertEqual("NaN");
1372                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1373            })
1374            done();
1375        })
1376
1377
1378        /**
1379         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0046
1380         * @tc.name webgl_test_vertexAttrib4fv_3
1381         * @tc.desc Test vertexAttrib4fv.
1382         */
1383        it('webgl_test_vertexAttrib4fv_3', 0, async function (done) {
1384            console.info("webgltest [webgl_test_vertexAttrib4fv_3] vertexAttrib4fv");
1385            vertexAttrib4fv((attrib) => {
1386                gl.vertexAttrib4fv(attrib, new Float32Array([null, null, null, null]));
1387                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1388            }, (attrib) => {
1389                expect(attrib[0]).assertEqual(0);
1390                expect(attrib[1]).assertEqual(0);
1391                expect(attrib[2]).assertEqual(0);
1392                expect(attrib[3]).assertEqual(0);
1393                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1394            })
1395            done();
1396        })
1397
1398
1399        /**
1400         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0047
1401         * @tc.name webgl_test_vertexAttrib4fv_4
1402         * @tc.desc Test vertexAttrib4fv.
1403         */
1404        it('webgl_test_vertexAttrib4fv_4', 0, async function (done) {
1405            console.info("webgltest [webgl_test_vertexAttrib4fv_4] vertexAttrib4fv");
1406            vertexAttrib4fv((attrib) => {
1407                gl.vertexAttrib4fv(-1, new Float32Array([-100, 100, 100, 100]));
1408                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
1409            }, (attrib) => {
1410                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1411            })
1412            done();
1413        })
1414
1415        /**
1416         * 验证getVertexAttrib方法 是否能够返回关于给定位置顶点属性的信息。
1417         */
1418        function getVertexAttrib(callback, finish) {
1419            let vSource = `
1420            attribute float a_PointSize;
1421            void main(){
1422                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1423                gl_PointSize = a_PointSize;
1424            }
1425        `;
1426            let fSource = `
1427            precision mediump float;
1428            uniform vec4 u_FragColor;
1429            void main(){
1430                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1431            }
1432        `
1433            let p = createProgram(gl, vSource, fSource);
1434            console.info("webgltest vertex shader source:", vSource);
1435            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1436            callback(a_PointSize);
1437            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1438            finish(vertexAttrib);
1439            gl.deleteShader(p.vertexShader);
1440            gl.deleteShader(p.fragmentShader);
1441            gl.deleteProgram(p.program);
1442        }
1443
1444
1445        /**
1446         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0048
1447         * @tc.name webgl_test_getVertexAttrib
1448         * @tc.desc Test getVertexAttrib.
1449         */
1450        it('webgl_test_getVertexAttrib', 0, async function (done) {
1451            console.info("webgltest [webgl_test_getVertexAttrib] getVertexAttrib");
1452            let vSource = `
1453            attribute float a_PointSize;
1454            void main(){
1455                gl_Position = vec4(0.5, 0.5, 1, 1.0);
1456                gl_PointSize = a_PointSize;
1457            }
1458        `;
1459            let fSource = `
1460            precision mediump float;
1461            uniform vec4 u_FragColor;
1462            void main(){
1463                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
1464            }
1465        `
1466            let p = createProgram(gl, vSource, fSource);
1467            console.info("webgltest vertex shader source:", vSource);
1468            let a_PointSize = gl.getAttribLocation(p.program, "a_PointSize");
1469            console.info("webgltest vertexAttrib4fv(a_PointSize,new Float32Array([100.0, 100.0, 100.0, 100.0]));");
1470            gl.vertexAttrib4fv(a_PointSize, new Float32Array([100.0, 100.0, 100.0, 100.0]));
1471            console.info("webgltest gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);");
1472            let vertexAttrib = gl.getVertexAttrib(a_PointSize, gl.CURRENT_VERTEX_ATTRIB);
1473            console.info("webgltest a_PointSize value: ", vertexAttrib);
1474            expect(vertexAttrib[0]).assertEqual(100);
1475            expect(vertexAttrib[1]).assertEqual(100);
1476            expect(vertexAttrib[2]).assertEqual(100);
1477            expect(vertexAttrib[3]).assertEqual(100);
1478            gl.deleteShader(p.vertexShader);
1479            gl.deleteShader(p.fragmentShader);
1480            gl.deleteProgram(p.program);
1481            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1482            done();
1483        })
1484
1485
1486        /**
1487         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0049
1488         * @tc.name webgl_test_getVertexAttrib_1
1489         * @tc.desc Test getVertexAttrib.
1490         */
1491        it('webgl_test_getVertexAttrib_1', 0, async function (done) {
1492            console.info("webgltest [webgl_test_getVertexAttrib_1] getVertexAttrib");
1493            getVertexAttrib((attrib) => {
1494                gl.vertexAttrib4fv(attrib, new Float32Array([-100.0, -100.0, -100.0, -100.0]));
1495                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1496            }, (attrib) => {
1497                expect(attrib[0]).assertEqual(-100);
1498                expect(attrib[1]).assertEqual(-100);
1499                expect(attrib[2]).assertEqual(-100);
1500                expect(attrib[3]).assertEqual(-100);
1501                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1502            })
1503            done();
1504        });
1505
1506
1507        /**
1508         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0050
1509         * @tc.name webgl_test_getVertexAttrib_2
1510         * @tc.desc Test getVertexAttrib.
1511         */
1512        it('webgl_test_getVertexAttrib_2', 0, async function (done) {
1513            console.info("webgltest [webgl_test_getVertexAttrib_2] getVertexAttrib");
1514            getVertexAttrib((attrib) => {
1515                gl.vertexAttrib4fv(attrib, new Float32Array([undefined, undefined, undefined, undefined]));
1516                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1517            }, (attrib) => {
1518                expect(attrib[0].toString()).assertEqual("NaN");
1519                expect(attrib[1].toString()).assertEqual("NaN");
1520                expect(attrib[2].toString()).assertEqual("NaN");
1521                expect(attrib[3].toString()).assertEqual("NaN");
1522                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1523            })
1524            done();
1525        })
1526
1527
1528        /**
1529         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0051
1530         * @tc.name webgl_test_getVertexAttrib_3
1531         * @tc.desc Test getVertexAttrib.
1532         */
1533        it('webgl_test_getVertexAttrib_3', 0, async function (done) {
1534            console.info("webgltest [webgl_test_getVertexAttrib_3] getVertexAttrib");
1535            getVertexAttrib((attrib) => {
1536                gl.vertexAttrib4fv(attrib, new Float32Array([null, null, null, null]));
1537                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1538            }, (attrib) => {
1539                expect(attrib[0]).assertEqual(0);
1540                expect(attrib[1]).assertEqual(0);
1541                expect(attrib[2]).assertEqual(0);
1542                expect(attrib[3]).assertEqual(0);
1543                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1544            })
1545            done();
1546        })
1547
1548
1549        /**
1550         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0052
1551         * @tc.name webgl_test_getVertexAttrib_4
1552         * @tc.desc Test getVertexAttrib.
1553         */
1554        it('webgl_test_getVertexAttrib_4', 0, async function (done) {
1555            console.info("webgltest [webgl_test_getVertexAttrib_4] getVertexAttrib");
1556            getVertexAttrib((attrib) => {
1557                gl.vertexAttrib4fv(-1, new Float32Array([-100, 100, 100, 100]));
1558                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
1559            }, (attrib) => {
1560                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1561            })
1562            done();
1563        })
1564
1565        /**
1566         * WebGL API 的 WebGLRenderingContext.vertexAttribPointer()
1567         * 方法绑定了当前绑定到 gl 的缓冲区。
1568         * ARRAY_BUFFER到当前顶点缓冲区对象的通用顶点属性并指定其布局。
1569         */
1570        function vertexAttribPointer(callback, finish) {
1571            let vSource = `
1572            attribute vec4 a_Position;
1573            attribute vec4 a_Color;
1574            uniform mat4 u_ModelViewMatrix;
1575            varying vec4 v_Color;
1576            void main() {
1577                gl_Position = u_ModelViewMatrix * a_Position;
1578                v_Color = a_Color;
1579            }
1580        `;
1581            let fSource = `
1582            precision mediump float;
1583            varying vec4 v_Color;
1584            void main() {
1585                gl_FragColor = v_Color;
1586            }
1587        `
1588            let p = createProgram(gl, vSource, fSource);
1589            console.info("webgltest vertex shader source:", vSource);
1590
1591            let arr = new Float32Array([
1592                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
1593                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
1594                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
1595
1596                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
1597                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
1598                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
1599
1600                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
1601                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
1602                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
1603            ]);
1604            let FSIZE = arr.BYTES_PER_ELEMENT;
1605            let buffer = gl.createBuffer(); // 创建缓冲区
1606            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
1607            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
1608            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
1609            let info = getVertexAttribDesc(a_Position);
1610            callback(a_Position);
1611            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
1612            info = getVertexAttribDesc(a_Position);
1613            finish(info);
1614            gl.disableVertexAttribArray(a_Position);
1615            gl.deleteBuffer(buffer);
1616            gl.deleteShader(p.vertexShader);
1617            gl.deleteShader(p.fragmentShader);
1618            gl.deleteProgram(p.program);
1619        }
1620
1621
1622        /**
1623         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0053
1624         * @tc.name webgl_test_vertexAttribPointer
1625         * @tc.desc Test vertexAttribPointer.
1626         */
1627        it('webgl_test_vertexAttribPointer', 0, async function (done) {
1628            console.info("webgltest [webgl_test_vertexAttribPointer] vertexAttribPointer");
1629            let vSource = `
1630            attribute vec4 a_Position;
1631            attribute vec4 a_Color;
1632            uniform mat4 u_ModelViewMatrix;
1633            varying vec4 v_Color;
1634            void main() {
1635                gl_Position = u_ModelViewMatrix * a_Position;
1636                v_Color = a_Color;
1637            }
1638        `;
1639            let fSource = `
1640            precision mediump float;
1641            varying vec4 v_Color;
1642            void main() {
1643                gl_FragColor = v_Color;
1644            }
1645        `
1646            let p = createProgram(gl, vSource, fSource);
1647            console.info("webgltest vertex shader source:", vSource);
1648
1649            let arr = new Float32Array([
1650                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
1651                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
1652                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
1653
1654                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
1655                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
1656                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
1657
1658                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
1659                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
1660                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
1661            ]);
1662            let FSIZE = arr.BYTES_PER_ELEMENT;
1663            let buffer = gl.createBuffer(); // 创建缓冲区
1664            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
1665            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
1666
1667            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
1668            let info = getVertexAttribDesc(a_Position);
1669            console.info("webgltest ", JSON.stringify(info));
1670            expect(info.bufferBinding).assertEqual(null);
1671            console.info("webgltest gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); ");
1672            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
1673            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
1674            info = getVertexAttribDesc(a_Position);
1675            console.info("webgltest ", JSON.stringify(info));
1676            expect(info.bufferBinding).assertEqual(buffer);
1677            expect(info.size).assertEqual(3);
1678            expect(info.type).assertEqual(gl.FLOAT);
1679            expect(info.normalized).assertEqual(false);
1680            expect(info.stride).assertEqual(FSIZE * 6);
1681            gl.disableVertexAttribArray(a_Position);
1682            gl.deleteBuffer(buffer);
1683            gl.deleteShader(p.vertexShader);
1684            gl.deleteShader(p.fragmentShader);
1685            gl.deleteProgram(p.program);
1686            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1687            done();
1688        })
1689
1690
1691        /**
1692         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0054
1693         * @tc.name webgl_test_vertexAttribPointer_1
1694         * @tc.desc Test vertexAttribPointer.
1695         */
1696        it('webgl_test_vertexAttribPointer_1', 0, async function (done) {
1697            console.info("webgltest [webgl_test_vertexAttribPointer_1] vertexAttribPointer");
1698            vertexAttribPointer((attrib) => {
1699                gl.vertexAttribPointer(attrib, 2, gl.FLOAT, false, 0, 0);
1700                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1701            }, (info) => {
1702                expect(info.size).assertEqual(2);
1703                expect(info.type).assertEqual(gl.FLOAT);
1704                expect(info.normalized).assertEqual(false);
1705                expect(info.stride).assertEqual(0);
1706                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1707            })
1708            done();
1709        })
1710
1711
1712        /**
1713         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0055
1714         * @tc.name webgl_test_vertexAttribPointer_2
1715         * @tc.desc Test vertexAttribPointer.
1716         */
1717        it('webgl_test_vertexAttribPointer_2', 0, async function (done) {
1718            console.info("webgltest [webgl_test_vertexAttribPointer_2] vertexAttribPointer");
1719            vertexAttribPointer((attrib) => {
1720                gl.vertexAttribPointer(-1, 2, gl.FLOAT, false, 0, 0);
1721                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
1722            }, (info) => {
1723                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1724            })
1725            done();
1726        })
1727
1728
1729        /**
1730         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0056
1731         * @tc.name webgl_test_vertexAttribPointer_3
1732         * @tc.desc Test vertexAttribPointer.
1733         */
1734        it('webgl_test_vertexAttribPointer_3', 0, async function (done) {
1735            console.info("webgltest [webgl_test_vertexAttribPointer_3] vertexAttribPointer");
1736            vertexAttribPointer((attrib) => {
1737                gl.vertexAttribPointer(attrib, 2, gl.BYTE, false, 0, 0);
1738                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1739            }, (info) => {
1740                expect(info.size).assertEqual(2);
1741                expect(info.type).assertEqual(gl.BYTE);
1742                expect(info.normalized).assertEqual(false);
1743                expect(info.stride).assertEqual(0);
1744                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1745            })
1746            done();
1747        })
1748
1749
1750        /**
1751         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0057
1752         * @tc.name webgl_test_vertexAttribPointer_4
1753         * @tc.desc Test vertexAttribPointer.
1754         */
1755        it('webgl_test_vertexAttribPointer_4', 0, async function (done) {
1756            console.info("webgltest [webgl_test_vertexAttribPointer_4] vertexAttribPointer");
1757            vertexAttribPointer((attrib) => {
1758                gl.vertexAttribPointer(attrib, 3, gl.SHORT, false, 0, 0);
1759                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1760            }, (info) => {
1761                expect(info.size).assertEqual(3);
1762                expect(info.type).assertEqual(gl.SHORT);
1763                expect(info.normalized).assertEqual(false);
1764                expect(info.stride).assertEqual(0);
1765                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1766            })
1767            done();
1768        })
1769
1770
1771        /**
1772         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0058
1773         * @tc.name webgl_test_vertexAttribPointer_5
1774         * @tc.desc Test vertexAttribPointer.
1775         */
1776        it('webgl_test_vertexAttribPointer_5', 0, async function (done) {
1777            console.info("webgltest [webgl_test_vertexAttribPointer_5] vertexAttribPointer");
1778            vertexAttribPointer((attrib) => {
1779                gl.vertexAttribPointer(attrib, 3, gl.UNSIGNED_BYTE, false, 0, 0);
1780                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1781            }, (info) => {
1782                expect(info.size).assertEqual(3);
1783                expect(info.type).assertEqual(gl.UNSIGNED_BYTE);
1784                expect(info.normalized).assertEqual(false);
1785                expect(info.stride).assertEqual(0);
1786                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1787            })
1788            done();
1789        })
1790
1791
1792        /**
1793         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0059
1794         * @tc.name webgl_test_vertexAttribPointer_6
1795         * @tc.desc Test vertexAttribPointer.
1796         */
1797        it('webgl_test_vertexAttribPointer_6', 0, async function (done) {
1798            console.info("webgltest [webgl_test_vertexAttribPointer_6] vertexAttribPointer");
1799            vertexAttribPointer((attrib) => {
1800                gl.vertexAttribPointer(attrib, 3, gl.UNSIGNED_SHORT, false, 0, 0);
1801                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1802            }, (info) => {
1803                expect(info.size).assertEqual(3);
1804                expect(info.type).assertEqual(gl.UNSIGNED_SHORT);
1805                expect(info.normalized).assertEqual(false);
1806                expect(info.stride).assertEqual(0);
1807                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1808            })
1809            done();
1810        })
1811
1812
1813        /**
1814         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0060
1815         * @tc.name webgl_test_vertexAttribPointer_7
1816         * @tc.desc Test vertexAttribPointer.
1817         */
1818        it('webgl_test_vertexAttribPointer_7', 0, async function (done) {
1819            console.info("webgltest [webgl_test_vertexAttribPointer_7] vertexAttribPointer");
1820            vertexAttribPointer((attrib) => {
1821                gl.vertexAttribPointer(attrib, 3, gl.UNSIGNED_SHORT, true, 0, 0);
1822                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1823            }, (info) => {
1824                expect(info.size).assertEqual(3);
1825                expect(info.type).assertEqual(gl.UNSIGNED_SHORT);
1826                expect(info.normalized).assertEqual(true);
1827                expect(info.stride).assertEqual(0);
1828                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1829            })
1830            done();
1831        })
1832
1833
1834        /**
1835         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0061
1836         * @tc.name webgl_test_vertexAttribPointer_8
1837         * @tc.desc Test vertexAttribPointer.
1838         */
1839        it('webgl_test_vertexAttribPointer_8', 0, async function (done) {
1840            console.info("webgltest [webgl_test_vertexAttribPointer_8] vertexAttribPointer");
1841            vertexAttribPointer((attrib) => {
1842                gl.vertexAttribPointer(attrib, 3, gl.UNSIGNED_SHORT, true, 2, 0);
1843                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1844            }, (info) => {
1845                console.log(info);
1846                expect(info.size).assertEqual(3);
1847                expect(info.type).assertEqual(gl.UNSIGNED_SHORT);
1848                expect(info.normalized).assertEqual(true);
1849                expect(info.stride).assertEqual(2);
1850                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1851            })
1852            done();
1853        })
1854
1855        /**
1856         * enableVertexAttribArray方法再给定的索引位置打开通用顶点数组。
1857         */
1858        function enableVertexAttribArray(callback, finish) {
1859            let vSource = `
1860            attribute vec4 a_Position;
1861            attribute vec4 a_Color;
1862            uniform mat4 u_ModelViewMatrix;
1863            varying vec4 v_Color;
1864            void main() {
1865                gl_Position = u_ModelViewMatrix * a_Position;
1866                v_Color = a_Color;
1867            }
1868        `;
1869            let fSource = `
1870            precision mediump float;
1871            varying vec4 v_Color;
1872            void main() {
1873                gl_FragColor = v_Color;
1874            }
1875        `
1876            let p = createProgram(gl, vSource, fSource);
1877            console.info("webgltest vertex shader source:", vSource);
1878
1879            let arr = new Float32Array([
1880                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
1881                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
1882                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
1883
1884                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
1885                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
1886                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
1887
1888                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
1889                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
1890                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
1891            ]);
1892            let FSIZE = arr.BYTES_PER_ELEMENT;
1893            let buffer = gl.createBuffer(); // 创建缓冲区
1894            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
1895            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
1896            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
1897            let info = getVertexAttribDesc(a_Position);
1898            console.info("webgltest enable:", info.enable);
1899            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
1900            callback(a_Position);
1901            info = getVertexAttribDesc(a_Position);
1902            finish(info);
1903            gl.disableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
1904            gl.deleteBuffer(buffer);
1905            gl.deleteShader(p.vertexShader);
1906            gl.deleteShader(p.fragmentShader);
1907            gl.deleteProgram(p.program);
1908        }
1909
1910
1911        /**
1912         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0062
1913         * @tc.name webgl_test_enableVertexAttribArray
1914         * @tc.desc Test enableVertexAttribArray.
1915         */
1916        it('webgl_test_enableVertexAttribArray', 0, async function (done) {
1917            console.info("webgltest [webgl_test_enableVertexAttribArray] enableVertexAttribArray");
1918            let vSource = `
1919            attribute vec4 a_Position;
1920            attribute vec4 a_Color;
1921            uniform mat4 u_ModelViewMatrix;
1922            varying vec4 v_Color;
1923            void main() {
1924                gl_Position = u_ModelViewMatrix * a_Position;
1925                v_Color = a_Color;
1926            }
1927        `;
1928            let fSource = `
1929            precision mediump float;
1930            varying vec4 v_Color;
1931            void main() {
1932                gl_FragColor = v_Color;
1933            }
1934        `
1935            let p = createProgram(gl, vSource, fSource);
1936            console.info("webgltest vertex shader source:", vSource);
1937
1938            let arr = new Float32Array([
1939                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
1940                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
1941                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
1942
1943                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
1944                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
1945                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
1946
1947                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
1948                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
1949                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
1950            ]);
1951            let FSIZE = arr.BYTES_PER_ELEMENT;
1952            let buffer = gl.createBuffer();
1953            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
1954            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW);
1955
1956            let a_Position = gl.getAttribLocation(p.program, 'a_Position');
1957            let info = getVertexAttribDesc(a_Position);
1958            console.info("webgltest enable:", info.enable);
1959            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0);
1960            expect(info.enable).assertEqual(false);
1961            console.info("webgltest gl.enableVertexAttribArray(a_Position);");
1962            gl.enableVertexAttribArray(a_Position);
1963            info = getVertexAttribDesc(a_Position);
1964            console.info("webgltest enable:", info.enable);
1965            expect(info.enable).assertEqual(true);
1966            gl.disableVertexAttribArray(a_Position);
1967            gl.deleteBuffer(buffer);
1968            gl.deleteShader(p.vertexShader);
1969            gl.deleteShader(p.fragmentShader);
1970            gl.deleteProgram(p.program);
1971            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1972            done();
1973        })
1974
1975
1976        /**
1977         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0063
1978         * @tc.name webgl_test_enableVertexAttribArray_1
1979         * @tc.desc Test enableVertexAttribArray.
1980         */
1981        it('webgl_test_enableVertexAttribArray_1', 0, async function (done) {
1982            console.info("webgltest [webgl_test_enableVertexAttribArray_1] enableVertexAttribArray");
1983            enableVertexAttribArray((attrib) => {
1984                gl.enableVertexAttribArray(attrib);
1985                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1986            }, (info) => {
1987                expect(info.enable).assertEqual(true);
1988                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1989            })
1990            done();
1991        })
1992
1993
1994        /**
1995         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0064
1996         * @tc.name webgl_test_enableVertexAttribArray_2
1997         * @tc.desc Test enableVertexAttribArray.
1998         */
1999        it('webgl_test_enableVertexAttribArray_2', 0, async function (done) {
2000            console.info("webgltest [webgl_test_enableVertexAttribArray_2] enableVertexAttribArray");
2001            enableVertexAttribArray((attrib) => {
2002                gl.enableVertexAttribArray(-1);
2003                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2004            }, (info) => {
2005                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2006            })
2007            done();
2008        })
2009
2010        /**
2011         * enableVertexAttribArray方法再给定的索引位置关闭通用顶点数组。
2012         */
2013
2014        function disableVertexAttribArray(callback, finish) {
2015            let vSource = `
2016            attribute vec4 a_Position;
2017            attribute vec4 a_Color;
2018            uniform mat4 u_ModelViewMatrix;
2019            varying vec4 v_Color;
2020            void main() {
2021                gl_Position = u_ModelViewMatrix * a_Position;
2022                v_Color = a_Color;
2023            }
2024        `;
2025            let fSource = `
2026            precision mediump float;
2027            varying vec4 v_Color;
2028            void main() {
2029                gl_FragColor = v_Color;
2030            }
2031        `
2032            let p = createProgram(gl, vSource, fSource);
2033            console.info("webgltest vertex shader source:", vSource);
2034
2035            let arr = new Float32Array([
2036                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
2037                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
2038                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
2039
2040                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
2041                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
2042                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
2043
2044                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
2045                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
2046                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
2047            ]);
2048
2049            let FSIZE = arr.BYTES_PER_ELEMENT;
2050            let buffer = gl.createBuffer();
2051            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
2052            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW);
2053
2054            let a_Position = gl.getAttribLocation(p.program, 'a_Position');
2055            let info = getVertexAttribDesc(a_Position);
2056            console.info("webgltest enable:", info.enable);
2057            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0);
2058            gl.enableVertexAttribArray(a_Position);
2059            info = getVertexAttribDesc(a_Position);
2060            callback(a_Position);
2061            info = getVertexAttribDesc(a_Position);
2062            finish(info);
2063            gl.deleteBuffer(buffer);
2064            gl.deleteShader(p.vertexShader);
2065            gl.deleteShader(p.fragmentShader);
2066            gl.deleteProgram(p.program);
2067        }
2068
2069
2070        /**
2071         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0065
2072         * @tc.name webgl_test_disableVertexAttribArray
2073         * @tc.desc Test disableVertexAttribArray.
2074         */
2075        it('webgl_test_disableVertexAttribArray', 0, async function (done) {
2076            console.info("webgltest [webgl_test_disableVertexAttribArray] disableVertexAttribArray");
2077            let vSource = `
2078            attribute vec4 a_Position;
2079            attribute vec4 a_Color;
2080            uniform mat4 u_ModelViewMatrix;
2081            varying vec4 v_Color;
2082            void main() {
2083                gl_Position = u_ModelViewMatrix * a_Position;
2084                v_Color = a_Color;
2085            }
2086        `;
2087            let fSource = `
2088            precision mediump float;
2089            varying vec4 v_Color;
2090            void main() {
2091                gl_FragColor = v_Color;
2092            }
2093        `
2094            let p = createProgram(gl, vSource, fSource);
2095            console.info("webgltest vertex shader source:", vSource);
2096
2097            let arr = new Float32Array([
2098                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
2099                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
2100                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
2101
2102                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
2103                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
2104                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
2105
2106                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
2107                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
2108                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
2109            ]);
2110
2111            let FSIZE = arr.BYTES_PER_ELEMENT;
2112            let buffer = gl.createBuffer(); // 创建缓冲区
2113            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2114            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2115
2116            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
2117            let info = getVertexAttribDesc(a_Position);
2118            console.info("webgltest enable:", info.enable);
2119            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2120            expect(info.enable).assertEqual(false);
2121            console.info("webgltest gl.enableVertexAttribArray(a_Position);");
2122            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2123            info = getVertexAttribDesc(a_Position);
2124            console.info("webgltest enable:", info.enable);
2125            expect(info.enable).assertEqual(true);
2126            console.info("webgltest gl.disableVertexAttribArray(a_Position);");
2127            gl.disableVertexAttribArray(a_Position);
2128            info = getVertexAttribDesc(a_Position);
2129            console.info("webgltest enable:", info.enable);
2130            expect(info.enable).assertEqual(false);
2131            gl.deleteBuffer(buffer);
2132            gl.deleteShader(p.vertexShader);
2133            gl.deleteShader(p.fragmentShader);
2134            gl.deleteProgram(p.program);
2135            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2136            done();
2137        })
2138
2139
2140        /**
2141         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0066
2142         * @tc.name webgl_test_disableVertexAttribArray_1
2143         * @tc.desc Test disableVertexAttribArray.
2144         */
2145        it('webgl_test_disableVertexAttribArray_1', 0, async function (done) {
2146            console.info("webgltest [webgl_test_disableVertexAttribArray_1] disableVertexAttribArray");
2147            disableVertexAttribArray((attrib) => {
2148                gl.disableVertexAttribArray(attrib);
2149                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2150            }, (info) => {
2151                expect(info.enable).assertEqual(false);
2152                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2153            })
2154            done();
2155        })
2156
2157
2158        /**
2159         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0067
2160         * @tc.name webgl_test_disableVertexAttribArray_2
2161         * @tc.desc Test disableVertexAttribArray.
2162         */
2163        it('webgl_test_disableVertexAttribArray_2', 0, async function (done) {
2164            console.info("webgltest [webgl_test_disableVertexAttribArray_2] disableVertexAttribArray");
2165            disableVertexAttribArray((attrib) => {
2166                gl.disableVertexAttribArray(-1);
2167                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2168                gl.disableVertexAttribArray(attrib);
2169            }, (info) => {
2170                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2171            })
2172            done();
2173        })
2174
2175
2176        /**
2177         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0068
2178         * @tc.name webgl_test_disableVertexAttribArray_3
2179         * @tc.desc Test disableVertexAttribArray.
2180         */
2181        it('webgl_test_disableVertexAttribArray_3', 0, async function (done) {
2182            console.info("webgltest [webgl_test_disableVertexAttribArray_3] disableVertexAttribArray");
2183            disableVertexAttribArray((attrib) => {
2184                gl.disableVertexAttribArray(null);
2185                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2186                gl.disableVertexAttribArray(attrib);
2187            }, (info) => {
2188                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2189            })
2190            done();
2191        })
2192
2193        /**
2194         * bindAttribLocation方法将通用顶点索引绑定到属性变量
2195         */
2196        function bindAttribLocation(callback, finish) {
2197            let vSource = `
2198            attribute vec4 a_Position;
2199            attribute vec4 a_Color;
2200            varying vec4 v_Color;
2201            void main() {
2202                gl_Position = a_Position;
2203                v_Color = a_Color;
2204            }
2205        `;
2206            let fSource = `
2207            precision mediump float;
2208            varying vec4 v_Color;
2209            void main() {
2210                gl_FragColor = v_Color;
2211            }
2212        `
2213            let p = createProgram(gl, vSource, fSource, (it) => {
2214                gl.bindAttribLocation(it, 11, "a_Position");
2215            });
2216            let a_Position = gl.getAttribLocation(p.program, "a_Position");
2217            callback(p.program, a_Position);
2218            gl.linkProgram(p.program);
2219            a_Position = gl.getAttribLocation(p.program, "a_Position");
2220            finish(a_Position)
2221            gl.bindAttribLocation(p.program, 0, "a_Position");
2222            gl.deleteShader(p.vertexShader);
2223            gl.deleteShader(p.fragmentShader);
2224            gl.deleteProgram(p.program);
2225        }
2226
2227        /**
2228         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0069
2229         * @tc.name webgl_test_bindAttribLocation
2230         * @tc.desc Test bindAttribLocation.
2231         */
2232        it('webgl_test_bindAttribLocation', 0, async function (done) {
2233            console.info("webgltest [webgl_test_bindAttribLocation] bindAttribLocation");
2234            let vSource = `
2235            attribute vec4 a_Position;
2236            attribute vec4 a_Color;
2237            varying vec4 v_Color;
2238            void main() {
2239                gl_Position = a_Position;
2240                v_Color = a_Color;
2241            }
2242        `;
2243            let fSource = `
2244            precision mediump float;
2245            varying vec4 v_Color;
2246            void main() {
2247                gl_FragColor = v_Color;
2248            }
2249        `
2250            let p = createProgram(gl, vSource, fSource, (it) => {
2251                console.info("webgltest gl.bindAttribLocation(it, 11, 'a_Position');");
2252                gl.bindAttribLocation(it, 11, "a_Position");
2253            });
2254            let a_Position = gl.getAttribLocation(p.program, "a_Position");
2255            console.info("webgltest a_Position:", a_Position);
2256            expect(a_Position).assertEqual(11);
2257            console.info("webgltest gl.bindAttribLocation(p.program, 12, 'a_Position');");
2258            gl.bindAttribLocation(p.program, 12, "a_Position");
2259            console.info("webgltest gl.linkProgram(p.program);");
2260            gl.linkProgram(p.program);
2261            a_Position = gl.getAttribLocation(p.program, "a_Position");
2262            console.info("webgltest a_Position:", a_Position);
2263            expect(a_Position).assertEqual(12);
2264            gl.bindAttribLocation(p.program, 0, "a_Position");
2265            gl.deleteShader(p.vertexShader);
2266            gl.deleteShader(p.fragmentShader);
2267            gl.deleteProgram(p.program);
2268            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2269            done();
2270        })
2271
2272
2273        /**
2274         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0070
2275         * @tc.name webgl_test_bindAttribLocation_1
2276         * @tc.desc Test bindAttribLocation.
2277         */
2278        it('webgl_test_bindAttribLocation_1', 0, async function (done) {
2279            console.info("webgltest [webgl_test_bindAttribLocation_1] bindAttribLocation");
2280            bindAttribLocation((program, attrib) => {
2281                gl.bindAttribLocation(program, 12, "a_Position");
2282                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2283            }, (attrib) => {
2284                expect(attrib).assertEqual(12);
2285                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2286            })
2287            done();
2288        })
2289
2290
2291        /**
2292         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0071
2293         * @tc.name webgl_test_bindAttribLocation_2
2294         * @tc.desc Test bindAttribLocation.
2295         */
2296        it('webgl_test_bindAttribLocation_2', 0, async function (done) {
2297            console.info("webgltest [webgl_test_bindAttribLocation_2] bindAttribLocation");
2298            bindAttribLocation((program, attrib) => {
2299                gl.bindAttribLocation(program, 12, "a");
2300                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2301            }, (attrib) => {
2302                expect(attrib).assertEqual(11);
2303                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2304            })
2305            done();
2306        })
2307
2308
2309        /**
2310         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0072
2311         * @tc.name webgl_test_bindAttribLocation_3
2312         * @tc.desc Test bindAttribLocation.
2313         */
2314        it('webgl_test_bindAttribLocation_3', 0, async function (done) {
2315            console.info("webgltest [webgl_test_bindAttribLocation_3] bindAttribLocation");
2316            bindAttribLocation((program, attrib) => {
2317                gl.bindAttribLocation(program, null, null);
2318                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2319            }, (attrib) => {
2320                expect(attrib).assertEqual(11);
2321                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2322            })
2323            done();
2324        })
2325
2326
2327        /**
2328         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0073
2329         * @tc.name webgl_test_bindAttribLocation_4
2330         * @tc.desc Test bindAttribLocation.
2331         */
2332        it('webgl_test_bindAttribLocation_4', 0, async function (done) {
2333            console.info("webgltest [webgl_test_bindAttribLocation_4] bindAttribLocation");
2334            bindAttribLocation((program, attrib) => {
2335                gl.bindAttribLocation(program, -1, attrib);
2336                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2337            }, (attrib) => {
2338                expect(attrib).assertEqual(11);
2339                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2340            })
2341            done();
2342        })
2343
2344        /**
2345         * 返回指定顶点属性的地址
2346         */
2347        function getVertexAttribOffset(callback, finish) {
2348            let vSource = `
2349            attribute vec4 a_Position;
2350            attribute vec4 a_Color;
2351            uniform mat4 u_ModelViewMatrix;
2352            varying vec4 v_Color;
2353            void main() {
2354                gl_Position = u_ModelViewMatrix * a_Position;
2355                v_Color = a_Color;
2356            }
2357        `;
2358            let fSource = `
2359            precision mediump float;
2360            varying vec4 v_Color;
2361            void main() {
2362                gl_FragColor = v_Color;
2363            }
2364        `
2365            let p = createProgram(gl, vSource, fSource);
2366            console.info("webgltest vertex shader source:", vSource);
2367            let arr = new Float32Array([
2368                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
2369                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
2370                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
2371
2372                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
2373                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
2374                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
2375
2376                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
2377                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
2378                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
2379            ]);
2380
2381            let FSIZE = arr.BYTES_PER_ELEMENT;
2382            let buffer = gl.createBuffer(); // 创建缓冲区
2383            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2384            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2385            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
2386            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2387            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2388            let positionOffset = gl.getVertexAttribOffset(a_Position, gl.VERTEX_ATTRIB_ARRAY_POINTER);
2389            let a_Color = gl.getAttribLocation(gl.program, 'a_Color'); // 获取attribute变量地址
2390            callback(a_Color, FSIZE);
2391            let colorOffset = gl.getVertexAttribOffset(a_Color, gl.VERTEX_ATTRIB_ARRAY_POINTER);
2392            finish(colorOffset, FSIZE);
2393            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2394            gl.disableVertexAttribArray(a_Position);
2395            gl.disableVertexAttribArray(a_Color);
2396            gl.deleteBuffer(buffer)
2397            gl.deleteShader(p.vertexShader);
2398            gl.deleteShader(p.fragmentShader);
2399            gl.deleteProgram(p.program);
2400        }
2401
2402        /**
2403         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0074
2404         * @tc.name webgl_test_getVertexAttribOffset
2405         * @tc.desc Test getVertexAttribOffset.
2406         */
2407        it('webgl_test_getVertexAttribOffset', 0, async function (done) {
2408            console.info("webgltest [webgl_test_getVertexAttribOffset] getVertexAttribOffset");
2409            let vSource = `
2410            attribute vec4 a_Position;
2411            attribute vec4 a_Color;
2412            uniform mat4 u_ModelViewMatrix;
2413            varying vec4 v_Color;
2414            void main() {
2415                gl_Position = u_ModelViewMatrix * a_Position;
2416                v_Color = a_Color;
2417            }
2418        `;
2419            let fSource = `
2420            precision mediump float;
2421            varying vec4 v_Color;
2422            void main() {
2423                gl_FragColor = v_Color;
2424            }
2425        `
2426            let p = createProgram(gl, vSource, fSource);
2427            console.info("webgltest vertex shader source:", vSource);
2428
2429            let arr = new Float32Array([
2430                0.0, 0.5, -0.4, 0.4, 1.0, 0.4,
2431                -0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
2432                0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
2433
2434                0.5, 0.4, -0.2, 1.0, 0.4, 0.4,
2435                -0.5, 0.4, -0.2, 1.0, 1.0, 0.4,
2436                0.0, -0.6, -0.2, 1.0, 1.0, 0.4,
2437
2438                0.0, 0.5, 0.0, 0.4, 0.4, 1.0,
2439                -0.5, -0.5, 0.0, 0.4, 0.4, 1.0,
2440                0.5, -0.5, 0.0, 1.0, 0.4, 0.4,
2441            ]);
2442
2443            let FSIZE = arr.BYTES_PER_ELEMENT;
2444            let buffer = gl.createBuffer(); // 创建缓冲区
2445            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2446            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2447
2448            let a_Position = gl.getAttribLocation(p.program, 'a_Position'); // 获取attribute变量地址
2449            console.info("webgltest gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0);");
2450            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2451            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2452            let positionOffset = gl.getVertexAttribOffset(a_Position, gl.VERTEX_ATTRIB_ARRAY_POINTER);
2453            console.info("webgltest positionOffset:", positionOffset);
2454            let a_Color = gl.getAttribLocation(gl.program, 'a_Color'); // 获取attribute变量地址
2455            console.info("webgltest gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3);");
2456            gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3); // 将缓冲区对象分配给一个attribute变量
2457            let colorOffset = gl.getVertexAttribOffset(a_Color, gl.VERTEX_ATTRIB_ARRAY_POINTER);
2458            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2459            console.info("webgltest colorOffset:", colorOffset);
2460            console.info("webgltest FSIZE:", FSIZE);
2461            expect(positionOffset).assertEqual(0);
2462            expect(colorOffset).assertEqual(FSIZE * 3);
2463            gl.disableVertexAttribArray(a_Position);
2464            gl.disableVertexAttribArray(a_Color);
2465            gl.deleteBuffer(buffer)
2466            gl.deleteShader(p.vertexShader);
2467            gl.deleteShader(p.fragmentShader);
2468            gl.deleteProgram(p.program);
2469            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2470            done();
2471        })
2472
2473
2474        /**
2475         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0075
2476         * @tc.name webgl_test_getVertexAttribOffset_1
2477         * @tc.desc Test getVertexAttribOffset.
2478         */
2479        it('webgl_test_getVertexAttribOffset_1', 0, async function (done) {
2480            console.info("webgltest [webgl_test_getVertexAttribOffset_1] getVertexAttribOffset");
2481            getVertexAttribOffset((val, FSIZE) => {
2482                gl.vertexAttribPointer(val, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3);
2483                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2484            }, (val, FSIZE) => {
2485                expect(val).assertEqual(FSIZE * 3);
2486                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2487            })
2488            done();
2489        })
2490
2491
2492        /**
2493         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0076
2494         * @tc.name webgl_test_getVertexAttribOffset_2
2495         * @tc.desc Test getVertexAttribOffset.
2496         */
2497        it('webgl_test_getVertexAttribOffset_2', 0, async function (done) {
2498            console.info("webgltest [webgl_test_getVertexAttribOffset_2] getVertexAttribOffset");
2499            getVertexAttribOffset((val, FSIZE) => {
2500                gl.vertexAttribPointer(val, 3, gl.FLOAT, false, FSIZE * 6, -FSIZE * 3);
2501                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2502            }, (val, FSIZE) => {
2503                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2504            })
2505            done();
2506        })
2507
2508
2509        /**
2510         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0077
2511         * @tc.name webgl_test_getVertexAttribOffset_3
2512         * @tc.desc Test getVertexAttribOffset.
2513         */
2514        it('webgl_test_getVertexAttribOffset_3', 0, async function (done) {
2515            console.info("webgltest [webgl_test_getVertexAttribOffset_3] getVertexAttribOffset");
2516            getVertexAttribOffset((val, FSIZE) => {
2517                gl.vertexAttribPointer(val, 3, gl.FLOAT, false, FSIZE * 6, null);
2518                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2519            }, (val, FSIZE) => {
2520                expect(val).assertEqual(0);
2521                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2522            })
2523            done();
2524        })
2525
2526
2527        /**
2528         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0078
2529         * @tc.name webgl_test_getVertexAttribOffset_4
2530         * @tc.desc Test getVertexAttribOffset.
2531         */
2532        it('webgl_test_getVertexAttribOffset_4', 0, async function (done) {
2533            console.info("webgltest [webgl_test_getVertexAttribOffset_4] getVertexAttribOffset");
2534            getVertexAttribOffset((val, FSIZE) => {
2535                gl.vertexAttribPointer(val, 3, gl.FLOAT, false, FSIZE * 6, undefined);
2536                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2537            }, (val, FSIZE) => {
2538                expect(val).assertEqual(0);
2539                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2540            })
2541            done();
2542        })
2543
2544        /**
2545         * drawArrays 用于从向量数组中绘制图元
2546         */
2547        function drawArrays(callback, finish) {
2548            let srcViewport = gl.getParameter(gl.VIEWPORT);
2549            let {program, vertexShader, fragmentShader} = createProgram(gl, `
2550                attribute vec4 a_Position;
2551                attribute float a_PointSize;
2552                attribute vec4 a_Color;
2553                varying vec4 v_Color;
2554                void main(){
2555                    gl_Position = a_Position;
2556                    gl_PointSize = a_PointSize;
2557                    v_Color = a_Color;
2558                }
2559            `, `
2560                precision mediump float;
2561                varying vec4 v_Color;
2562                void main(){
2563                    gl_FragColor = v_Color;
2564                }
2565            `);
2566            gl.clearColor(0.92, 0.92, 0.92, 1);
2567            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
2568            let arr = new Float32Array([
2569                0.0, 0.5, 20.0, 1.0, 0.0, 0.0,
2570                -0.5, -0.5, 40.0, 0.0, 1.0, 0.0,
2571                0.5, -0.5, 60.0, 0.0, 0.0, 1.0,
2572            ]);
2573            let FSIZE = arr.BYTES_PER_ELEMENT;
2574            let buffer = gl.createBuffer(); // 创建缓冲区
2575            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2576            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2577
2578            let a_Position = gl.getAttribLocation(gl.program, 'a_Position'); // 获取attribute变量地址
2579            gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2580            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2581
2582            let a_PointSize = gl.getAttribLocation(gl.program, 'a_PointSize');
2583            gl.vertexAttribPointer(a_PointSize, 1, gl.FLOAT, false, FSIZE * 6, FSIZE * 2);
2584            gl.enableVertexAttribArray(a_PointSize); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2585
2586            let a_Color = gl.getAttribLocation(gl.program, 'a_Color');
2587            gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3);
2588            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2589
2590            let n = arr.length / 6;
2591            gl.viewport(0, 0, 800, 800);
2592            callback(n)
2593            finish()
2594            gl.viewport(srcViewport[0],srcViewport[1],srcViewport[2],srcViewport[3]);
2595            gl.disableVertexAttribArray(a_Position);
2596            gl.disableVertexAttribArray(a_PointSize);
2597            gl.disableVertexAttribArray(a_Color);
2598            gl.deleteBuffer(buffer);
2599            gl.detachShader(program, vertexShader);
2600            gl.deleteShader(vertexShader);
2601            gl.detachShader(program, fragmentShader);
2602            gl.deleteShader(fragmentShader);
2603            gl.deleteProgram(program);
2604            gl.flush();
2605        }
2606
2607        /**
2608         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0079
2609         * @tc.name webgl_test_drawArrays
2610         * @tc.desc Test drawArrays.
2611         */
2612        it('webgl_test_drawArrays', 0, async function (done) {
2613            console.info("webgltest [webgl_test_drawArrays] drawArrays");
2614            let srcViewport = gl.getParameter(gl.VIEWPORT);
2615            let {program, vertexShader, fragmentShader} = createProgram(gl, `
2616                attribute vec4 a_Position;
2617                attribute float a_PointSize;
2618                attribute vec4 a_Color;
2619                varying vec4 v_Color;
2620                void main(){
2621                    gl_Position = a_Position;
2622                    gl_PointSize = a_PointSize;
2623                    v_Color = a_Color;
2624                }
2625            `, `
2626                precision mediump float;
2627                varying vec4 v_Color;
2628                void main(){
2629                    gl_FragColor = v_Color;
2630                }
2631            `);
2632            gl.clearColor(0.92, 0.92, 0.92, 1);
2633            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
2634            let arr = new Float32Array([
2635                0.0, 0.5, 20.0, 1.0, 0.0, 0.0,
2636                -0.5, -0.5, 40.0, 0.0, 1.0, 0.0,
2637                0.5, -0.5, 60.0, 0.0, 0.0, 1.0,
2638            ]);
2639            let FSIZE = arr.BYTES_PER_ELEMENT;
2640            let buffer = gl.createBuffer(); // 创建缓冲区
2641            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2642            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2643
2644            let a_Position = gl.getAttribLocation(gl.program, 'a_Position'); // 获取attribute变量地址
2645            gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2646            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2647
2648            let a_PointSize = gl.getAttribLocation(gl.program, 'a_PointSize');
2649            gl.vertexAttribPointer(a_PointSize, 1, gl.FLOAT, false, FSIZE * 6, FSIZE * 2);
2650            gl.enableVertexAttribArray(a_PointSize); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2651
2652            let a_Color = gl.getAttribLocation(gl.program, 'a_Color');
2653            gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3);
2654            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2655
2656            let n = arr.length / 6;
2657            gl.viewport(0, 0, 800, 800);
2658            gl.drawArrays(gl.TRIANGLES, 0, n);
2659            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2660            gl.disableVertexAttribArray(a_Position);
2661            gl.disableVertexAttribArray(a_PointSize);
2662            gl.disableVertexAttribArray(a_Color);
2663            gl.deleteBuffer(buffer);
2664            gl.detachShader(program, vertexShader);
2665            gl.deleteShader(vertexShader);
2666            gl.detachShader(program, fragmentShader);
2667            gl.deleteShader(fragmentShader);
2668            gl.deleteProgram(program);
2669            gl.flush();
2670            gl.viewport(srcViewport[0],srcViewport[1],srcViewport[2],srcViewport[3]);
2671            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2672            done();
2673        })
2674
2675
2676        /**
2677         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0080
2678         * @tc.name webgl_test_drawArrays_1
2679         * @tc.desc Test drawArrays.
2680         */
2681        it('webgl_test_drawArrays_1', 0, async function (done) {
2682            console.info("webgltest [webgl_test_drawArrays_1] drawArrays");
2683            drawArrays((n) => {
2684                gl.drawArrays(gl.TRIANGLES, 0, -1);
2685                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2686            }, () => {
2687                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2688            })
2689            done();
2690        })
2691
2692
2693        /**
2694         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0081
2695         * @tc.name webgl_test_drawArrays_2
2696         * @tc.desc Test drawArrays.
2697         */
2698        it('webgl_test_drawArrays_2', 0, async function (done) {
2699            console.info("webgltest [webgl_test_drawArrays_2] drawArrays");
2700            drawArrays((n) => {
2701                gl.drawArrays(gl.TRIANGLES, 0, null);
2702                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2703            }, () => {
2704                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2705            })
2706            done();
2707        })
2708
2709
2710        /**
2711         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0082
2712         * @tc.name webgl_test_drawArrays_3
2713         * @tc.desc Test drawArrays.
2714         */
2715        it('webgl_test_drawArrays_3', 0, async function (done) {
2716            console.info("webgltest [webgl_test_drawArrays_3] drawArrays");
2717            drawArrays((n) => {
2718                gl.drawArrays(gl.TRIANGLES, -1, null);
2719                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
2720            }, () => {
2721                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2722            })
2723            done();
2724        })
2725
2726
2727        /**
2728         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0083
2729         * @tc.name webgl_test_drawArrays_4
2730         * @tc.desc Test drawArrays.
2731         */
2732        it('webgl_test_drawArrays_4', 0, async function (done) {
2733            console.info("webgltest [webgl_test_drawArrays_4] drawArrays");
2734            drawArrays((n) => {
2735                gl.drawArrays(gl.POINTS, 0, n);
2736                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2737            }, () => {
2738                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2739            })
2740            done();
2741        })
2742
2743
2744        /**
2745         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0084
2746         * @tc.name webgl_test_drawArrays_5
2747         * @tc.desc Test drawArrays.
2748         */
2749        it('webgl_test_drawArrays_5', 0, async function (done) {
2750            console.info("webgltest [webgl_test_drawArrays_5] drawArrays");
2751            drawArrays((n) => {
2752                gl.drawArrays(gl.LINE_STRIP, 0, n);
2753                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2754            }, () => {
2755                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2756            })
2757            done();
2758        })
2759
2760
2761        /**
2762         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0085
2763         * @tc.name webgl_test_drawArrays_6
2764         * @tc.desc Test drawArrays.
2765         */
2766        it('webgl_test_drawArrays_6', 0, async function (done) {
2767            console.info("webgltest [webgl_test_drawArrays_6] drawArrays");
2768            drawArrays((n) => {
2769                gl.drawArrays(gl.LINE_LOOP, 0, n);
2770                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2771            }, () => {
2772                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2773            })
2774            done();
2775        })
2776
2777
2778        /**
2779         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0086
2780         * @tc.name webgl_test_drawArrays_7
2781         * @tc.desc Test drawArrays.
2782         */
2783        it('webgl_test_drawArrays_7', 0, async function (done) {
2784            console.info("webgltest [webgl_test_drawArrays_7] drawArrays");
2785            drawArrays((n) => {
2786                gl.drawArrays(gl.LINES, 0, n);
2787                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2788            }, () => {
2789                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2790            })
2791            done();
2792        })
2793
2794
2795        /**
2796         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0087
2797         * @tc.name webgl_test_drawArrays_8
2798         * @tc.desc Test drawArrays.
2799         */
2800        it('webgl_test_drawArrays_8', 0, async function (done) {
2801            console.info("webgltest [webgl_test_drawArrays_8] drawArrays");
2802            drawArrays((n) => {
2803                gl.drawArrays(gl.TRIANGLE_STRIP, 0, n);
2804                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2805            }, () => {
2806                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2807            })
2808            done();
2809        })
2810
2811
2812        /**
2813         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0088
2814         * @tc.name webgl_test_drawArrays_9
2815         * @tc.desc Test drawArrays.
2816         */
2817        it('webgl_test_drawArrays_9', 0, async function (done) {
2818            console.info("webgltest [webgl_test_drawArrays_9] drawArrays");
2819            drawArrays((n) => {
2820                gl.drawArrays(gl.TRIANGLE_FAN, 0, n);
2821                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2822            }, () => {
2823                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2824            })
2825            done();
2826        })
2827
2828        /**
2829         * drawElements 从数组数据渲染图元
2830         */
2831        function drawElements(callback, finish) {
2832            let srcViewport = gl.getParameter(gl.VIEWPORT);
2833            let {program, vertexShader, fragmentShader} = createProgram(gl, `
2834                attribute vec4 a_Position;
2835                attribute vec4 a_Color;
2836                uniform mat4 u_MvpMatrix;
2837                varying vec4 v_Color;
2838                void main() {
2839                    gl_Position = u_MvpMatrix * a_Position;
2840                    v_Color = a_Color;
2841                }
2842            `, `
2843                precision mediump float;
2844                varying vec4 v_Color;
2845                void main() {
2846                    gl_FragColor = v_Color;
2847                }
2848            `);
2849            let arr = new Float32Array([
2850                1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
2851                -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
2852                -1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
2853                1.0, -1.0, 1.0, 1.0, 1.0, 0.0,
2854
2855                1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
2856                1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
2857                -1.0, 1.0, -1.0, 0.0, 0.0, 1.0,
2858                -1.0, -1.0, -1.0, 0.0, 0.0, 0.0,
2859            ]);
2860            let indices = new Uint8Array([
2861                0, 1, 2, 0, 2, 3,
2862                0, 3, 4, 0, 4, 5,
2863                0, 5, 6, 0, 6, 1,
2864                1, 6, 7, 1, 7, 2,
2865                7, 4, 3, 7, 3, 2,
2866                4, 7, 6, 4, 6, 5,
2867            ]);
2868            let FSIZE = arr.BYTES_PER_ELEMENT;
2869            let buffer = gl.createBuffer(); // 创建缓冲区
2870            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2871            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2872
2873            let a_Position = gl.getAttribLocation(gl.program, 'a_Position'); // 获取attribute变量地址
2874            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2875            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2876
2877            let a_Color = gl.getAttribLocation(gl.program, 'a_Color'); // 获取attribute变量地址
2878            gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3); // 将缓冲区对象分配给一个attribute变量
2879            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2880
2881            let indexBuffer = gl.createBuffer();
2882            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
2883            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
2884
2885            let u_MvpMatrix = gl.getUniformLocation(gl.program, 'u_MvpMatrix');
2886            gl.clearColor(0.92, 0.92, 0.92, 1);
2887            gl.clear(gl.COLOR_BUFFER_BIT);
2888            let srcEnable = gl.isEnabled(gl.DEPTH_TEST);
2889            gl.enable(gl.DEPTH_TEST);
2890            gl.enable(gl.POLYGON_OFFSET_FILL);
2891            gl.polygonOffset(1.0, 1.0);
2892            gl.uniformMatrix4fv(u_MvpMatrix, false, new Float32Array([
2893                3.4, -0.5, -0.3, -0.3,
2894                0, 3.4, -0.3, -0.3,
2895                -1.4, -1.2, -0.8, -0.8,
2896                -0.4, -0.5, 6.3, 8.1,
2897            ]));
2898            gl.viewport(0, 0, 800, 800);
2899            callback(indices.length);
2900            finish();
2901            gl.viewport(srcViewport[0],srcViewport[1],srcViewport[2],srcViewport[3]);
2902            gl.disableVertexAttribArray(a_Position);
2903            gl.disableVertexAttribArray(a_Color);
2904            gl.bindBuffer(gl.ARRAY_BUFFER, null);
2905            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
2906            gl.deleteBuffer(buffer);
2907            gl.deleteBuffer(indexBuffer);
2908            gl.deleteShader(vertexShader);
2909            gl.deleteShader(fragmentShader);
2910            gl.deleteProgram(program);
2911            if (srcEnable) {
2912                gl.enable(gl.DEPTH_TEST);
2913            } else {
2914                gl.disable(gl.DEPTH_TEST);
2915            }
2916            gl.disable(gl.POLYGON_OFFSET_FILL);
2917            gl.flush();
2918        }
2919
2920        /**
2921         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0089
2922         * @tc.name webgl_test_drawElements
2923         * @tc.desc Test drawElements.
2924         */
2925        it('webgl_test_drawElements', 0, async function (done) {
2926            console.info("webgltest [webgl_test_drawElements] drawElements");
2927            let srcViewport = gl.getParameter(gl.VIEWPORT);
2928            let {program, vertexShader, fragmentShader} = createProgram(gl, `
2929                attribute vec4 a_Position;
2930                attribute vec4 a_Color;
2931                uniform mat4 u_MvpMatrix;
2932                varying vec4 v_Color;
2933                void main() {
2934                    gl_Position = u_MvpMatrix * a_Position;
2935                    v_Color = a_Color;
2936                }
2937            `, `
2938                precision mediump float;
2939                varying vec4 v_Color;
2940                void main() {
2941                    gl_FragColor = v_Color;
2942                }
2943            `);
2944            let arr = new Float32Array([
2945                1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
2946                -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
2947                -1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
2948                1.0, -1.0, 1.0, 1.0, 1.0, 0.0,
2949
2950                1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
2951                1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
2952                -1.0, 1.0, -1.0, 0.0, 0.0, 1.0,
2953                -1.0, -1.0, -1.0, 0.0, 0.0, 0.0,
2954            ]);
2955            let indices = new Uint8Array([
2956                0, 1, 2, 0, 2, 3,
2957                0, 3, 4, 0, 4, 5,
2958                0, 5, 6, 0, 6, 1,
2959                1, 6, 7, 1, 7, 2,
2960                7, 4, 3, 7, 3, 2,
2961                4, 7, 6, 4, 6, 5,
2962            ]);
2963            let FSIZE = arr.BYTES_PER_ELEMENT;
2964            let buffer = gl.createBuffer(); // 创建缓冲区
2965            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // 绑定缓冲区
2966            gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW); // 将数据写入缓冲区对象
2967
2968            let a_Position = gl.getAttribLocation(gl.program, 'a_Position'); // 获取attribute变量地址
2969            gl.vertexAttribPointer(a_Position, 3, gl.FLOAT, false, FSIZE * 6, 0); // 将缓冲区对象分配给一个attribute变量
2970            gl.enableVertexAttribArray(a_Position); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2971
2972            let a_Color = gl.getAttribLocation(gl.program, 'a_Color'); // 获取attribute变量地址
2973            gl.vertexAttribPointer(a_Color, 3, gl.FLOAT, false, FSIZE * 6, FSIZE * 3); // 将缓冲区对象分配给一个attribute变量
2974            gl.enableVertexAttribArray(a_Color); // 开启attribute变量(连接a_Position变量与分配给它的缓冲区对象)
2975
2976            let indexBuffer = gl.createBuffer();
2977            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
2978            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
2979
2980            let u_MvpMatrix = gl.getUniformLocation(gl.program, 'u_MvpMatrix');
2981
2982            gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
2983            gl.clearColor(0.92, 0.92, 0.92, 1);
2984            gl.clear(gl.COLOR_BUFFER_BIT);
2985            let srcEnable = gl.isEnabled(gl.DEPTH_TEST);
2986            gl.enable(gl.DEPTH_TEST);
2987            gl.enable(gl.POLYGON_OFFSET_FILL);
2988            gl.polygonOffset(1.0, 1.0);
2989            gl.uniformMatrix4fv(u_MvpMatrix, false, new Float32Array([
2990                3.4, -0.5, -0.3, -0.3,
2991                0, 3.4, -0.3, -0.3,
2992                -1.4, -1.2, -0.8, -0.8,
2993                -0.4, -0.5, 6.3, 8.1,
2994            ]));
2995            gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_BYTE, 0);
2996            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
2997            gl.viewport(srcViewport[0],srcViewport[1],srcViewport[2],srcViewport[3]);
2998            gl.disableVertexAttribArray(a_Position);
2999            gl.disableVertexAttribArray(a_Color);
3000            gl.bindBuffer(gl.ARRAY_BUFFER, null);
3001            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
3002            gl.deleteBuffer(buffer);
3003            gl.deleteBuffer(indexBuffer);
3004            gl.deleteShader(vertexShader);
3005            gl.deleteShader(fragmentShader);
3006            gl.deleteProgram(program);
3007            if (srcEnable) {
3008                gl.enable(gl.DEPTH_TEST);
3009            } else {
3010                gl.disable(gl.DEPTH_TEST);
3011            }
3012            gl.disable(gl.POLYGON_OFFSET_FILL);
3013            gl.flush();
3014            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3015            done();
3016        })
3017
3018
3019        /**
3020         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0090
3021         * @tc.name webgl_test_drawElements_1
3022         * @tc.desc Test drawElements.
3023         */
3024        it('webgl_test_drawElements_1', 0, async function (done) {
3025            console.info("webgltest [webgl_test_drawElements_1] drawElements");
3026            drawElements((n) => {
3027                gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_BYTE, 0);
3028                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3029            }, () => {
3030                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3031            })
3032            done();
3033        })
3034
3035
3036        /**
3037         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0091
3038         * @tc.name webgl_test_drawElements_2
3039         * @tc.desc Test drawElements.
3040         */
3041        it('webgl_test_drawElements_2', 0, async function (done) {
3042            console.info("webgltest [webgl_test_drawElements_2] drawElements");
3043            drawElements((n) => {
3044                gl.drawElements(gl.POINTS, n, gl.UNSIGNED_BYTE, 0);
3045                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3046            }, () => {
3047                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3048            })
3049            done();
3050        })
3051
3052
3053        /**
3054         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0092
3055         * @tc.name webgl_test_drawElements_3
3056         * @tc.desc Test drawElements.
3057         */
3058        it('webgl_test_drawElements_3', 0, async function (done) {
3059            console.info("webgltest [webgl_test_drawElements_3] drawElements");
3060            drawElements((n) => {
3061                gl.drawElements(gl.LINE_STRIP, n, gl.UNSIGNED_BYTE, 0);
3062                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3063            }, () => {
3064                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3065            })
3066            done();
3067        })
3068
3069
3070        /**
3071         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0093
3072         * @tc.name webgl_test_drawElements_4
3073         * @tc.desc Test drawElements.
3074         */
3075        it('webgl_test_drawElements_4', 0, async function (done) {
3076            console.info("webgltest [webgl_test_drawElements_4] drawElements");
3077            drawElements((n) => {
3078                gl.drawElements(gl.LINE_LOOP, n, gl.UNSIGNED_BYTE, 0);
3079                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3080            }, () => {
3081                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3082            })
3083            done();
3084        })
3085
3086
3087        /**
3088         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0094
3089         * @tc.name webgl_test_drawElements_5
3090         * @tc.desc Test drawElements.
3091         */
3092        it('webgl_test_drawElements_5', 0, async function (done) {
3093            console.info("webgltest [webgl_test_drawElements_5] drawElements");
3094            drawElements((n) => {
3095                gl.drawElements(gl.LINES, n, gl.UNSIGNED_BYTE, 0);
3096                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3097            }, () => {
3098                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3099            })
3100            done();
3101        })
3102
3103
3104        /**
3105         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0095
3106         * @tc.name webgl_test_drawElements_6
3107         * @tc.desc Test drawElements.
3108         */
3109        it('webgl_test_drawElements_6', 0, async function (done) {
3110            console.info("webgltest [webgl_test_drawElements_6] drawElements");
3111            drawElements((n) => {
3112                gl.drawElements(gl.TRIANGLE_STRIP, n, gl.UNSIGNED_BYTE, 0);
3113                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3114            }, () => {
3115                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3116            })
3117            done();
3118        })
3119
3120
3121        /**
3122         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0096
3123         * @tc.name webgl_test_drawElements_7
3124         * @tc.desc Test drawElements.
3125         */
3126        it('webgl_test_drawElements_7', 0, async function (done) {
3127            console.info("webgltest [webgl_test_drawElements_7] drawElements");
3128            drawElements((n) => {
3129                gl.drawElements(gl.TRIANGLE_FAN, n, gl.UNSIGNED_BYTE, 0);
3130                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3131            }, () => {
3132                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3133            })
3134            done();
3135        })
3136
3137
3138        /**
3139         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0097
3140         * @tc.name webgl_test_drawElements_8
3141         * @tc.desc Test drawElements.
3142         */
3143        it('webgl_test_drawElements_8', 0, async function (done) {
3144            console.info("webgltest [webgl_test_drawElements_8] drawElements");
3145            drawElements((n) => {
3146                gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_SHORT, 0);
3147                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
3148            }, () => {
3149                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3150            })
3151            done();
3152        })
3153
3154
3155        /**
3156         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0098
3157         * @tc.name webgl_test_drawElements_9
3158         * @tc.desc Test drawElements.
3159         */
3160        it('webgl_test_drawElements_9', 0, async function (done) {
3161            console.info("webgltest [webgl_test_drawElements_9] drawElements");
3162            drawElements((n) => {
3163                gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_INT, 0);
3164                expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
3165            }, () => {
3166                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3167            })
3168            done();
3169        })
3170
3171
3172        /**
3173         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0099
3174         * @tc.name webgl_test_drawElements_10
3175         * @tc.desc Test drawElements.
3176         */
3177        it('webgl_test_drawElements_10', 0, async function (done) {
3178            console.info("webgltest [webgl_test_drawElements_10] drawElements");
3179            drawElements((n) => {
3180                gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_BYTE, -1);
3181                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
3182            }, () => {
3183                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3184            })
3185            done();
3186        })
3187
3188
3189        /**
3190         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_ATTRIBUTE_0100
3191         * @tc.name webgl_test_drawElements_11
3192         * @tc.desc Test drawElements.
3193         */
3194        it('webgl_test_drawElements_11', 0, async function (done) {
3195            console.info("webgltest [webgl_test_drawElements_11] drawElements");
3196            drawElements((n) => {
3197                gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_BYTE, null);
3198                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3199            }, () => {
3200                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
3201            })
3202            done();
3203        })
3204    })
3205}
3206