• 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,clear,WEBGL2_FRAGMENT_SHADER_DEMO} from './WebGL2';
20
21
22export default function webgl2_texture() {
23
24	describe('webgl2_texture', function () {
25        let gl = global.gl2;
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        // All levels of two-dimensional texture storage are specified. This function acts like tex Image 2D, but it does not initialize the texture image data.
50        function texStorage2D(callback, finish) {
51            let p = createProgram(gl, `#version 300 es
52                in vec4 a_position;
53                in vec2 a_texcoord;
54                out vec2 v_texcoord;
55                void main(){
56                    gl_Position = a_position;
57                    v_texcoord = a_texcoord;
58                }
59            `, `#version 300 es
60                precision mediump float;
61                precision highp sampler2D;
62                in vec2 v_texcoord;
63                out vec4 color;
64                uniform sampler2D u_sampler;
65                void main(){
66                    color = texture(u_sampler, v_texcoord);
67                }
68            `);
69            let source = new Float32Array([
70                -1.0, -1.0, 0.0, 0.0,
71                1.0, -1.0, 1.0, 0.0,
72                -1.0, 1.0, 0.0, 1.0,
73                1.0, 1.0, 1.0, 1.0,
74            ]);
75            let num = 4;
76            let FSIZE = source.BYTES_PER_ELEMENT;
77            let buffer = gl.createBuffer();
78            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
79            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_READ, 0, 16);
80            let a_position = gl.getAttribLocation(p.program, 'a_position');
81            gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 4 * FSIZE, 0);
82            gl.enableVertexAttribArray(a_position);
83            let a_texcoord = gl.getAttribLocation(p.program, 'a_texcoord');
84            gl.vertexAttribPointer(a_texcoord, 2, gl.FLOAT, false, 4 * FSIZE, 2 * FSIZE);
85            gl.enableVertexAttribArray(a_texcoord);
86            let u_sampler = gl.getUniformLocation(p.program, 'u_sampler');
87            let texture = gl.createTexture();
88            gl.activeTexture(gl.TEXTURE0);
89            gl.bindTexture(gl.TEXTURE_2D, texture);
90            gl.uniform1i(u_sampler, 0);
91            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
92            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
93            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
94            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
95            callback();
96            gl.clearColor(1, 1, 0, 1.0);
97            gl.clear(gl.COLOR_BUFFER_BIT);
98            gl.drawArrays(gl.TRIANGLE_STRIP, 0, num);
99            finish();
100            gl.disableVertexAttribArray(a_position);
101            gl.disableVertexAttribArray(a_texcoord);
102            gl.deleteTexture(texture);
103            gl.deleteBuffer(buffer);
104            gl.deleteShader(p.vertexShader);
105            gl.deleteShader(p.fragmentShader);
106            gl.deleteProgram(p.program);
107        }
108        /**
109         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0001
110         * @tc.name webgl2_test_texStorage2D
111         * @tc.desc Test texStorage2D.
112         */
113        it('webgl2_test_texStorage2D', 0, async function (done) {
114            console.info("webgl2test [webgl2_test_texStorage2D] texStorage2D");
115            texStorage2D(() => {
116                gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, 120, 120);
117                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
118                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
119                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
120            }, () => {
121                let result = new Uint8Array(2 * 2 * 4);
122                gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, result);
123                console.info("webgltest ", result);
124                expect(result[0]).assertEqual(255);
125                expect(result[1]).assertEqual(0);
126                expect(result[2]).assertEqual(0);
127                expect(result[3]).assertEqual(255);
128                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
129            });
130            done();
131        });
132        /**
133         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0002
134         * @tc.name webgl2_test_texStorage2D_1
135         * @tc.desc Test texStorage2D.
136         */
137        it('webgl2_test_texStorage2D_1', 0, async function (done) {
138            console.info("webgl2test [webgl2_test_texStorage2D_1] texStorage2D");
139            texStorage2D(() => {
140                gl.texStorage2D(gl.TEXTURE_CUBE_MAP, 1, gl.RGBA8, 120, 120);
141                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
142                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
143                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
144            }, () => {
145                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
146            });
147            done();
148        });
149        /**
150         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0003
151         * @tc.name webgl2_test_texStorage2D_2
152         * @tc.desc Test texStorage2D.
153         */
154        it('webgl2_test_texStorage2D_2', 0, async function (done) {
155            console.info("webgl2test [webgl2_test_texStorage2D_2] texStorage2D");
156            texStorage2D(() => {
157                gl.texStorage2D(gl.TEXTURE_CUBE_MAP, 1, gl.R16F, 120, 120);
158                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
159                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
160                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
161            }, () => {
162                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
163            });
164            done();
165        });
166        /**
167         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0004
168         * @tc.name webgl2_test_texStorage2D_3
169         * @tc.desc Test texStorage2D.
170         */
171        it('webgl2_test_texStorage2D_3', 0, async function (done) {
172            console.info("webgl2test [webgl2_test_texStorage2D_3] texStorage2D");
173            texStorage2D(() => {
174                gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R8UI, 120, 120);
175                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
176                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
177                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
178            }, () => {
179                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
180            });
181            done();
182        });
183        /**
184         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0005
185         * @tc.name webgl2_test_texStorage2D_4
186         * @tc.desc Test texStorage2D.
187         */
188        it('webgl2_test_texStorage2D_4', 0, async function (done) {
189            console.info("webgl2test [webgl2_test_texStorage2D_4] texStorage2D");
190            texStorage2D(() => {
191                gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RG16F, 120, 120);
192                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
193                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
194                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
195            }, () => {
196                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
197            });
198            done();
199        });
200        /**
201         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0006
202         * @tc.name webgl2_test_texStorage2D_5
203         * @tc.desc Test texStorage2D.
204         */
205        it('webgl2_test_texStorage2D_5', 0, async function (done) {
206            console.info("webgl2test [webgl2_test_texStorage2D_2] texStorage2D");
207            texStorage2D(() => {
208                gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R11F_G11F_B10F, 120, 120);
209                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
210                let image = getColorUint8Array(120, 120, 255, 0, 0, 255);
211                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 120, 120, gl.RGBA, gl.UNSIGNED_BYTE, image);
212            }, () => {
213                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
214            });
215            done();
216        });
217        function texStorage3D(callback, finish) {
218            const data = new Uint8Array(128 * 1280 * 4); // four bytes represent the rgba value of a pixel
219            let colors = [
220                [255, 0, 0, 255],
221                [0, 255, 0, 255],
222                [0, 0, 255, 255],
223                [255, 255, 0, 255],
224                [255, 0, 255, 255],
225                [0, 255, 255, 255],
226                [255, 255, 255, 255],
227                [128, 128, 128, 255],
228                [0, 0, 0, 255],
229                [255, 255, 255, 255],
230            ];
231            for (let i = 0; i < 10; i++) {
232                let arr = getColorUint8Array(128, 128, colors[i][0], colors[i][1], colors[i][2], 255);
233                data.set(arr, 128 * 128 * 4 * i);
234            }
235            let p = createProgram(gl, `#version 300 es
236                layout(location=0) in vec4 a_position;
237                layout(location=1) in vec2 a_texCoord;
238                layout(location=2) in float a_depth;
239                out vec2 v_texcoord;
240                out float v_depth;
241                void main(){
242                    gl_Position = a_position;
243                    v_texcoord = a_texCoord;
244                    v_depth = a_depth;
245                }
246            `, `#version 300 es
247                precision mediump float;
248                uniform mediump sampler2DArray u_sampler;
249                in vec2 v_texcoord;
250                in float v_depth;
251                out vec4 color;
252                void main(){
253                    color = texture(u_sampler, vec3(v_texcoord,v_depth));
254                }
255            `);
256            let source = new Float32Array([
257                -1, -1, 0, 1,
258                1, 1, 1, 0,
259                -1, 1, 0, 0,
260                -1, -1, 0, 1,
261                1, -1, 1, 1,
262                1, 1, 1, 0,
263            ]);
264            let depth = 0;
265            let texture = gl.createTexture();
266            gl.activeTexture(gl.TEXTURE0);
267            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
268            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
269            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
270            callback(data);
271            gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, 128, 128, 10, gl.RGBA, gl.UNSIGNED_BYTE, data);
272            let buffer = gl.createBuffer();
273            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
274            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_DRAW);
275            gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 4 * 4, 0);
276            gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 4 * 4, 2 * 4);
277            gl.vertexAttrib1f(2, 2);
278            gl.enableVertexAttribArray(0);
279            gl.enableVertexAttribArray(1);
280            gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
281            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, 0);
282            gl.clearColor(1.0, 1.0, 0.0, 1.0);
283            gl.clear(gl.COLOR_BUFFER_BIT);
284            gl.drawArrays(gl.TRIANGLES, 0, 6);
285            let res = new Uint8Array(128 * 128 * 4);
286            gl.readPixels(0, 0, 128, 128, gl.RGBA, gl.UNSIGNED_BYTE, res);
287            finish(res);
288            gl.disableVertexAttribArray(0);
289            gl.disableVertexAttribArray(1);
290            gl.deleteBuffer(buffer);
291            gl.deleteTexture(texture);
292            gl.deleteShader(p.vertexShader);
293            gl.deleteShader(p.fragmentShader);
294            gl.deleteProgram(p.program);
295            gl.flush();
296        }
297        /**
298         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0007
299         * @tc.name webgl2_test_texStorage3D
300         * @tc.desc Test texStorage3D.
301         */
302        it('webgl2_test_texStorage3D', 0, async function (done) {
303            console.info("webgl2test [webgl2_test_texStorage3D] texStorage3D");
304            texStorage3D((data) => {
305                gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, 128, 128, 10);
306            }, (res) => {
307                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
308                expect(res[0]).assertEqual(0);
309                expect(res[1]).assertEqual(0);
310                expect(res[2]).assertEqual(255);
311                expect(res[3]).assertEqual(255);
312                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
313            });
314            done();
315        });
316        /**
317         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0008
318         * @tc.name webgl2_test_texStorage3D_1
319         * @tc.desc Test texStorage3D.
320         */
321        it('webgl2_test_texStorage3D_1', 0, async function (done) {
322            console.info("webgl2test [webgl2_test_texStorage3D_1] texStorage3D");
323            texStorage3D((data) => {
324                gl.texStorage3D(gl.TEXTURE_3D, 1, gl.RGBA8, 128, 128, 10);
325            }, (res) => {
326                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
327            });
328            done();
329        });
330        /**
331         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0009
332         * @tc.name webgl2_test_texStorage3D_2
333         * @tc.desc Test texStorage3D.
334         */
335        it('webgl2_test_texStorage3D_2', 0, async function (done) {
336            console.info("webgl2test [webgl2_test_texStorage3D_2] texStorage3D");
337            texStorage3D((data) => {
338                gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.R16F, 128, 128, 10);
339            }, (res) => {
340                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
341            });
342            done();
343        });
344        /**
345         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0010
346         * @tc.name webgl2_test_texStorage3D_3
347         * @tc.desc Test texStorage3D.
348         */
349        it('webgl2_test_texStorage3D_3', 0, async function (done) {
350            console.info("webgl2test [webgl2_test_texStorage3D_3] texStorage3D");
351            texStorage3D((data) => {
352                gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RG16F, 128, 128, 10);
353            }, (res) => {
354                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
355            });
356            done();
357        });
358        /**
359         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0011
360         * @tc.name webgl2_test_texStorage3D_4
361         * @tc.desc Test texStorage3D.
362         */
363        it('webgl2_test_texStorage3D_4', 0, async function (done) {
364            console.info("webgl2test [webgl2_test_texStorage3D_4] texStorage3D");
365            texStorage3D((data) => {
366                gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.SRGB8, 128, 128, 10);
367            }, (res) => {
368                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
369            });
370            done();
371        });
372        /**
373         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0012
374         * @tc.name webgl2_test_texStorage3D_5
375         * @tc.desc Test texStorage3D.
376         */
377        it('webgl2_test_texStorage3D_5', 0, async function (done) {
378            console.info("webgl2test [webgl2_test_texStorage3D_5] texStorage3D");
379            texStorage3D((data) => {
380                gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.R11F_G11F_B10F, 128, 128, 10);
381            }, (res) => {
382                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
383            });
384            done();
385        });
386        function texImage3D(callback, finish) {
387            const width = 8;
388            const height = 8;
389            let depth = 3;
390            const data = new Uint8Array(width * height * depth * 4); // four bytes represent the rgba value of a pixel
391            let colors = [
392                [255, 0, 0, 255],
393                [0, 255, 0, 255],
394                [0, 0, 255, 255],
395            ];
396            for (let i = 0; i < depth; i++) {
397                let arr = getColorUint8Array(width, height, colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
398                data.set(arr, width * height * 4 * i);
399            }
400            let p = createProgram(gl, `#version 300 es
401                layout(location=0) in vec4 a_position;
402                layout(location=1) in vec2 a_texCoord;
403                layout(location=2) in float a_depth;
404                out vec2 v_texcoord;
405                out float v_depth;
406                void main(){
407                    gl_Position = a_position;
408                    v_texcoord = a_texCoord;
409                    v_depth = a_depth;
410                }
411            `, `#version 300 es
412                precision mediump float;
413                uniform mediump sampler2DArray u_sampler;
414                in vec2 v_texcoord;
415                in float v_depth;
416                out vec4 color;
417                void main(){
418                    color = texture(u_sampler, vec3(v_texcoord,v_depth));
419                }
420            `);
421            let source = new Float32Array([
422                -1, -1, 0, 1,
423                1, 1, 1, 0,
424                -1, 1, 0, 0,
425                -1, -1, 0, 1,
426                1, -1, 1, 1,
427                1, 1, 1, 0,
428            ]);
429            let texture = gl.createTexture();
430            gl.activeTexture(gl.TEXTURE0);
431            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
432            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
433            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
434            depth = callback(width, height, depth, data);
435            let buffer = gl.createBuffer();
436            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
437            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_DRAW);
438            let FSIZE = source.BYTES_PER_ELEMENT;
439            let u_sampler = gl.getUniformLocation(p.program, 'u_sampler');
440            gl.uniform1i(u_sampler, 0);
441            gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 4 * FSIZE, 0);
442            gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 4 * FSIZE, 2 * FSIZE);
443            gl.vertexAttrib1f(2, depth);
444            gl.enableVertexAttribArray(0);
445            gl.enableVertexAttribArray(1);
446            gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
447            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, 0);
448            gl.clearColor(1.0, 1.0, 0.0, 1.0);
449            gl.clear(gl.COLOR_BUFFER_BIT);
450            gl.drawArrays(gl.TRIANGLES, 0, 6);
451            let res = new Uint8Array(width * height * 4);
452            gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, res);
453            finish(res);
454            gl.disableVertexAttribArray(0);
455            gl.disableVertexAttribArray(1);
456            gl.deleteBuffer(buffer);
457            gl.deleteTexture(texture);
458            gl.deleteShader(p.vertexShader);
459            gl.deleteShader(p.fragmentShader);
460            gl.deleteProgram(p.program);
461        }
462        /**
463         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0013
464         * @tc.name webgl2_test_texImage3D
465         * @tc.desc Test texImage3D.
466         */
467        it('webgl2_test_texImage3D', 0, async function (done) {
468            console.info("webgl2test [webgl2_test_texImage3D] texImage3D");
469            texImage3D((width, height, depth, data) => {
470                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
471                return 2;
472            }, (res) => {
473                expect(res[0]).assertEqual(0);
474                expect(res[1]).assertEqual(0);
475                expect(res[2]).assertEqual(255);
476                expect(res[3]).assertEqual(255);
477                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
478            });
479            done();
480        });
481        /**
482         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0014
483         * @tc.name webgl2_test_texImage3D_1
484         * @tc.desc Test texImage3D.
485         */
486        it('webgl2_test_texImage3D_1', 0, async function (done) {
487            console.info("webgl2test [webgl2_test_texImage3D_1] texImage3D");
488            texImage3D((width, height, depth, data) => {
489                gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
490                return 2;
491            }, (res) => {
492                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
493            });
494            done();
495        });
496        /**
497         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0015
498         * @tc.name webgl2_test_texImage3D_2
499         * @tc.desc Test texImage3D.
500         */
501        it('webgl2_test_texImage3D_2', 0, async function (done) {
502            console.info("webgl2test [webgl2_test_texImage3D_2] texImage3D");
503            texImage3D((width, height, depth, data) => {
504                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 1, gl.ALPHA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
505                return 2;
506            }, (res) => {
507                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
508            });
509            done();
510        });
511        /**
512         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0016
513         * @tc.name webgl2_test_texImage3D_3
514         * @tc.desc Test texImage3D.
515         */
516        it('webgl2_test_texImage3D_3', 0, async function (done) {
517            console.info("webgl2test [webgl2_test_texImage3D_3] texImage3D");
518            texImage3D((width, height, depth, data) => {
519                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 1, gl.LUMINANCE, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
520                return 2;
521            }, (res) => {
522                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
523            });
524            done();
525        });
526        /**
527         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0017
528         * @tc.name webgl2_test_texImage3D_4
529         * @tc.desc Test texImage3D.
530         */
531        it('webgl2_test_texImage3D_4', 0, async function (done) {
532            console.info("webgl2test [webgl2_test_texImage3D_4] texImage3D");
533            texImage3D((width, height, depth, data) => {
534                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 1, gl.R8UI, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
535                return 2;
536            }, (res) => {
537                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
538            });
539            done();
540        });
541        /**
542         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0018
543         * @tc.name webgl2_test_texImage3D_5
544         * @tc.desc Test texImage3D.
545         */
546        it('webgl2_test_texImage3D_5', 0, async function (done) {
547            console.info("webgl2test [webgl2_test_texImage3D_5] texImage3D");
548            texImage3D((width, height, depth, data) => {
549                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 1, gl.R11F_G11F_B10F, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
550                return 2;
551            }, (res) => {
552                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
553            });
554            done();
555        });
556        function texSubImage3D(callback, finish) {
557            const width = 8;
558            const height = 8;
559            let depth = 3;
560            const data = new Uint8Array(width * height * depth * 4); // four bytes represent the rgba value of a pixel
561            const data1 = new Uint8Array(width * height * depth * 4); // four bytes represent the rgba value of a pixel
562            let colors = [
563                [255, 0, 0, 255],
564                [0, 255, 0, 255],
565                [0, 0, 255, 255],
566            ];
567            let colors1 = [
568                [0, 0, 255, 255],
569                [0, 255, 0, 255],
570                [255, 0, 0, 255],
571            ];
572            for (let i = 0; i < depth; i++) {
573                let arr = getColorUint8Array(width, height, colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
574                data.set(arr, width * height * 4 * i);
575            }
576            for (let i = 0; i < depth; i++) {
577                let arr = getColorUint8Array(width, height, colors1[i][0], colors1[i][1], colors1[i][2], colors1[i][3]);
578                data1.set(arr, width * height * 4 * i);
579            }
580            let p = createProgram(gl, `#version 300 es
581                layout(location=0) in vec4 a_position;
582                layout(location=1) in vec2 a_texCoord;
583                layout(location=2) in float a_depth;
584                out vec2 v_texcoord;
585                out float v_depth;
586                void main(){
587                    gl_Position = a_position;
588                    v_texcoord = a_texCoord;
589                    v_depth = a_depth;
590                }
591            `, `#version 300 es
592                precision mediump float;
593                uniform mediump sampler2DArray u_sampler;
594                in vec2 v_texcoord;
595                in float v_depth;
596                out vec4 color;
597                void main(){
598                    color = texture(u_sampler, vec3(v_texcoord,v_depth));
599                }
600            `);
601            let source = new Float32Array([
602                -1, -1, 0, 1,
603                1, 1, 1, 0,
604                -1, 1, 0, 0,
605                -1, -1, 0, 1,
606                1, -1, 1, 1,
607                1, 1, 1, 0,
608            ]);
609            let texture = gl.createTexture();
610            gl.activeTexture(gl.TEXTURE0);
611            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
612            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
613            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
614            depth = callback(width, height, depth, data, data1);
615            let buffer = gl.createBuffer();
616            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
617            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_DRAW);
618            let FSIZE = source.BYTES_PER_ELEMENT;
619            let u_sampler = gl.getUniformLocation(p.program, 'u_sampler');
620            gl.uniform1i(u_sampler, 0);
621            gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 4 * FSIZE, 0);
622            gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 4 * FSIZE, 2 * FSIZE);
623            gl.vertexAttrib1f(2, depth);
624            gl.enableVertexAttribArray(0);
625            gl.enableVertexAttribArray(1);
626            gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
627            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, 0);
628            gl.clearColor(1.0, 1.0, 0.0, 1.0);
629            gl.clear(gl.COLOR_BUFFER_BIT);
630            gl.drawArrays(gl.TRIANGLES, 0, 6);
631            let res = new Uint8Array(width * height * 4);
632            gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, res);
633            finish(res);
634            gl.disableVertexAttribArray(0);
635            gl.disableVertexAttribArray(1);
636            gl.deleteBuffer(buffer);
637            gl.deleteTexture(texture);
638            gl.deleteShader(p.vertexShader);
639            gl.deleteShader(p.fragmentShader);
640            gl.deleteProgram(p.program);
641        }
642        /**
643         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0019
644         * @tc.name webgl2_test_texSubImage3D
645         * @tc.desc Test texSubImage3D.
646         */
647        it('webgl2_test_texSubImage3D', 0, async function (done) {
648            console.info("webgl2test [webgl2_test_texSubImage3D] texSubImage3D");
649            texSubImage3D((width, height, depth, data, data1) => {
650                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
651                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.UNSIGNED_BYTE, data1);
652                return 0;
653            }, (res) => {
654                expect(res[0]).assertEqual(255);
655                expect(res[1]).assertEqual(0);
656                expect(res[2]).assertEqual(0);
657                expect(res[3]).assertEqual(255);
658                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
659            });
660            done();
661        });
662        /**
663         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0020
664         * @tc.name webgl2_test_texSubImage3D_1
665         * @tc.desc Test texSubImage3D.
666         */
667        it('webgl2_test_texSubImage3D_1', 0, async function (done) {
668            console.info("webgl2test [webgl2_test_texSubImage3D_1] texSubImage3D");
669            texSubImage3D((width, height, depth, data, data1) => {
670                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_SHORT_5_6_5, data);
671                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.UNSIGNED_SHORT_5_6_5, data1);
672                return 0;
673            }, (res) => {
674                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
675            });
676            done();
677        });
678        /**
679         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0021
680         * @tc.name webgl2_test_texSubImage3D_2
681         * @tc.desc Test texSubImage3D.
682         */
683        it('webgl2_test_texSubImage3D_2', 0, async function (done) {
684            console.info("webgl2test [webgl2_test_texSubImage3D_2] texSubImage3D");
685            texSubImage3D((width, height, depth, data, data1) => {
686                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, data);
687                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, data1);
688                return 0;
689            }, (res) => {
690                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
691            });
692            done();
693        });
694        /**
695         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0022
696         * @tc.name webgl2_test_texSubImage3D_3
697         * @tc.desc Test texSubImage3D.
698         */
699        it('webgl2_test_texSubImage3D_3', 0, async function (done) {
700            console.info("webgl2test [webgl2_test_texSubImage3D_3] texSubImage3D");
701            texSubImage3D((width, height, depth, data, data1) => {
702                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_INT, data);
703                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.UNSIGNED_INT, data1);
704                return 0;
705            }, (res) => {
706                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
707            });
708            done();
709        });
710        /**
711         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0023
712         * @tc.name webgl2_test_texSubImage3D_4
713         * @tc.desc Test texSubImage3D.
714         */
715        it('webgl2_test_texSubImage3D_4', 0, async function (done) {
716            console.info("webgl2test [webgl2_test_texSubImage3D_4] texSubImage3D");
717            texSubImage3D((width, height, depth, data, data1) => {
718                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.HALF_FLOAT, data);
719                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.HALF_FLOAT, data1);
720                return 0;
721            }, (res) => {
722                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
723            });
724            done();
725        });
726        /**
727         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0024
728         * @tc.name webgl2_test_texSubImage3D_5
729         * @tc.desc Test texSubImage3D.
730         */
731        it('webgl2_test_texSubImage3D_5', 0, async function (done) {
732            console.info("webgl2test [webgl2_test_texSubImage3D_5] texSubImage3D");
733            texSubImage3D((width, height, depth, data, data1) => {
734                gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_INT_2_10_10_10_REV, data);
735                gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, width / 2, width / 2, 0, width - width / 2, height - height / 2, depth, gl.RGBA, gl.UNSIGNED_INT_2_10_10_10_REV, data1);
736                return 0;
737            }, (res) => {
738                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
739            });
740            done();
741        });
742        function copyTexSubImage3D(callback, finish) {
743            let srcViewPort = gl.getParameter(gl.VIEWPORT);
744            let width = 8;
745            let height = 8;
746            let depth = 3;
747            let data = new Uint8Array(width * height * depth * 4); // four bytes represent the rgba value of a pixel
748            let colors = [
749                [255, 0, 0, 255],
750                [0, 255, 0, 255],
751                [0, 0, 255, 255],
752            ];
753            for (let i = 0; i < depth; i++) {
754                let arr = getColorUint8Array(width, height, colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
755                data.set(arr, width * height * 4 * i);
756            }
757            let vCode = `#version 300 es
758                layout(location=0) in vec4 a_position;
759                layout(location=1) in vec2 a_texCoord;
760                layout(location=2) in float a_depth;
761                out vec2 v_texcoord;
762                out float v_depth;
763                void main(){
764                    gl_Position = a_position;
765                    v_texcoord = a_texCoord;
766                    v_depth = a_depth;
767                }
768            `;
769            let fCode = `#version 300 es
770                precision mediump float;
771                uniform mediump sampler2DArray u_sampler;
772                in vec2 v_texcoord;
773                in float v_depth;
774                out vec4 color;
775                void main(){
776                    color = texture(u_sampler, vec3(v_texcoord,v_depth));
777                }
778            `;
779            let source = [
780                -1, -1, 0, 1,
781                1, 1, 1, 0,
782                -1, 1, 0, 0,
783                -1, -1, 0, 1,
784                1, -1, 1, 1,
785                1, 1, 1, 0,
786            ];
787            let p1 = createProgram(gl, vCode, fCode);
788            gl.useProgram(p1.program);
789            // texture
790            gl.activeTexture(gl.TEXTURE0);
791            let texture = gl.createTexture();
792            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
793            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
794            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
795            gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
796            let renderTexture = gl.createTexture();
797            gl.bindTexture(gl.TEXTURE_2D_ARRAY, renderTexture);
798            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
799            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
800            gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
801            // framebuffer
802            let framebuffer = gl.createFramebuffer();
803            gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
804            let renderbuffer = gl.createRenderbuffer();
805            gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
806            gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
807            gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, renderTexture, 0, 0);
808            gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, renderTexture, 0, 1);
809            gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT2, renderTexture, 0, 2);
810            gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
811            gl.viewport(0, 0, width, height);
812            // draw
813            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
814            let buffer = gl.createBuffer();
815            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
816            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(source), gl.STATIC_DRAW);
817            let FSIZE = 4;
818            let a_position = gl.getAttribLocation(p1.program, 'a_position');
819            let a_texCoord = gl.getAttribLocation(p1.program, 'a_texCoord');
820            let a_depth = gl.getAttribLocation(p1.program, 'a_depth');
821            gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 4 * FSIZE, 0);
822            gl.vertexAttribPointer(a_texCoord, 2, gl.FLOAT, false, 4 * FSIZE, 2 * FSIZE);
823            gl.vertexAttrib1f(a_depth, 0);
824            gl.enableVertexAttribArray(a_position);
825            gl.enableVertexAttribArray(a_texCoord);
826            gl.clearColor(0.0, 0.0, 0.0, 1.0);
827            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
828            gl.drawArrays(gl.TRIANGLES, 0, 6);
829            gl.flush();
830            // copyTexImage3D
831            let newTexture = gl.createTexture();
832            gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
833            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
834            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
835            gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
836            callback(width, height, depth, texture, newTexture);
837            gl.bindFramebuffer(gl.FRAMEBUFFER, null);
838            // draw
839            gl.viewport(srcViewPort[0], srcViewPort[1], srcViewPort[2], srcViewPort[3]);
840            let p2 = createProgram(gl, vCode, fCode);
841            gl.useProgram(p2.program);
842            let buffer2 = gl.createBuffer();
843            gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
844            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(source), gl.STATIC_DRAW);
845            gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 4 * FSIZE, 0);
846            gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 4 * FSIZE, 2 * FSIZE);
847            gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
848            gl.vertexAttrib1f(2, 2);
849            gl.enableVertexAttribArray(0);
850            gl.enableVertexAttribArray(1);
851            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
852            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
853            let u_sampler = gl.getUniformLocation(p2.program, 'u_sampler');
854            gl.uniform1i(u_sampler, 0);
855            gl.clearColor(0.0, 0.0, 0.0, 1.0);
856            gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
857            gl.drawArrays(gl.TRIANGLES, 0, 6);
858            let res = new Uint8Array(width * height * 4);
859            gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, res);
860            finish(res);
861            gl.disableVertexAttribArray(0);
862            gl.disableVertexAttribArray(1);
863            gl.deleteBuffer(buffer);
864            gl.deleteBuffer(buffer2);
865            gl.deleteTexture(texture);
866            gl.deleteTexture(renderTexture);
867            gl.deleteTexture(newTexture);
868            gl.deleteRenderbuffer(renderbuffer);
869            gl.deleteFramebuffer(framebuffer);
870            gl.deleteShader(p1.vertexShader);
871            gl.deleteShader(p1.fragmentShader);
872            gl.deleteProgram(p1.program);
873            gl.deleteShader(p2.vertexShader);
874            gl.deleteShader(p2.fragmentShader);
875            gl.deleteProgram(p2.program);
876            gl.flush();
877            checkError(gl);
878        }
879        /**
880         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0025
881         * @tc.name webgl2_test_copyTexSubImage3D
882         * @tc.desc Test copyTexSubImage3D.
883         */
884        it('webgl2_test_copyTexSubImage3D', 0, async function (done) {
885            console.info("webgl2test [webgl2_test_copyTexSubImage3D] copyTexSubImage3D");
886            copyTexSubImage3D((width, height, depth, texture, newTexture) => {
887                for (let i = 0; i < depth; i++) {
888                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
889                    gl.vertexAttrib1f(2, i);
890                    gl.clearColor(0.0, 0.0, 0.0, 1.0);
891                    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
892                    gl.drawArrays(gl.TRIANGLES, 0, 6);
893                    gl.flush();
894                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
895                    gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, i, 0, 0, width, height);
896                }
897            }, (res) => {
898                expect(res[0]).assertEqual(0);
899                expect(res[1]).assertEqual(0);
900                expect(res[2]).assertEqual(255);
901                expect(res[3]).assertEqual(255);
902            });
903            done();
904        });
905        /**
906         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0026
907         * @tc.name webgl2_test_copyTexSubImage3D_1
908         * @tc.desc Test copyTexSubImage3D.
909         */
910        it('webgl2_test_copyTexSubImage3D_1', 0, async function (done) {
911            console.info("webgl2test [webgl2_test_copyTexSubImage3D_1] copyTexSubImage3D");
912            copyTexSubImage3D((width, height, depth, texture, newTexture) => {
913                for (let i = 0; i < depth; i++) {
914                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
915                    gl.vertexAttrib1f(2, i);
916                    gl.clearColor(0.0, 0.0, 0.0, 1.0);
917                    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
918                    gl.drawArrays(gl.TRIANGLES, 0, 6);
919                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
920                    gl.copyTexSubImage3D(gl.TEXTURE_3D, 0, 0, 0, i, 0, 0, width, height);
921                }
922            }, (res) => {
923                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
924            });
925            done();
926        });
927        /**
928         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0027
929         * @tc.name webgl2_test_copyTexSubImage3D_2
930         * @tc.desc Test copyTexSubImage3D.
931         */
932        it('webgl2_test_copyTexSubImage3D_2', 0, async function (done) {
933            console.info("webgl2test [webgl2_test_copyTexSubImage3D_2] copyTexSubImage3D");
934            copyTexSubImage3D((width, height, depth, texture, newTexture) => {
935                for (let i = 0; i < depth; i++) {
936                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
937                    gl.vertexAttrib1f(2, i);
938                    gl.clearColor(0.0, 0.0, 0.0, 1.0);
939                    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
940                    gl.drawArrays(gl.TRIANGLES, 0, 6);
941                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
942                    gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, 1, 1, 10, i, 10, 10, width, height);
943                }
944            }, (res) => {
945                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
946            });
947            done();
948        });
949        /**
950         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0028
951         * @tc.name webgl2_test_copyTexSubImage3D_3
952         * @tc.desc Test copyTexSubImage3D.
953         */
954        it('webgl2_test_copyTexSubImage3D_3', 0, async function (done) {
955            console.info("webgl2test [webgl2_test_copyTexSubImage3D_3] copyTexSubImage3D");
956            copyTexSubImage3D((width, height, depth, texture, newTexture) => {
957                for (let i = 0; i < depth; i++) {
958                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
959                    gl.vertexAttrib1f(2, i);
960                    gl.clearColor(0.0, 0.0, 0.0, 1.0);
961                    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
962                    gl.drawArrays(gl.TRIANGLES, 0, 6);
963                    gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture);
964                    gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, -1, 0, 0, i, 0, 0, width, height);
965                }
966            }, (res) => {
967                expect(checkError(gl)).assertEqual(gl.INVALID_VALUE);
968            });
969            done();
970        });
971        function compressedTexImage3D(callback, finish) {
972            let texture = gl.createTexture();
973            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
974            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
975            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
976            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
977            callback();
978            finish();
979            gl.deleteTexture(texture);
980        }
981        /**
982         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0029
983         * @tc.name webgl2_test_compressedTexImage3D
984         * @tc.desc Test compressedTexImage3D.
985         */
986        it('webgl2_test_compressedTexImage3D', 0, async function (done) {
987            console.info("webgl2test [webgl2_test_compressedTexImage3D] compressedTexImage3D");
988            let texture = gl.createTexture();
989            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
990            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
991            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
992            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
993            gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4));
994            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
995            gl.deleteTexture(texture);
996            done();
997        });
998        /**
999         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0030
1000         * @tc.name webgl2_test_compressedTexImage3D_1
1001         * @tc.desc Test compressedTexImage3D.
1002         */
1003        it('webgl2_test_compressedTexImage3D_1', 0, async function (done) {
1004            compressedTexImage3D(() => {
1005                gl.compressedTexImage3D(gl.TEXTURE_3D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4));
1006            }, () => {
1007                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1008            });
1009            done();
1010        });
1011        /**
1012         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0031
1013         * @tc.name webgl2_test_compressedTexImage3D_2
1014         * @tc.desc Test compressedTexImage3D.
1015         */
1016        it('webgl2_test_compressedTexImage3D_2', 0, async function (done) {
1017            compressedTexImage3D(() => {
1018                gl.compressedTexImage3D(gl.TEXTURE_3D, 1, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4));
1019            }, () => {
1020                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1021            });
1022            done();
1023        });
1024        /**
1025         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0032
1026         * @tc.name webgl2_test_compressedTexImage3D_3
1027         * @tc.desc Test compressedTexImage3D.
1028         */
1029        it('webgl2_test_compressedTexImage3D_3', 0, async function (done) {
1030            compressedTexImage3D(() => {
1031                gl.compressedTexImage3D(gl.TEXTURE_3D, -1, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4));
1032            }, () => {
1033                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1034            });
1035            done();
1036        });
1037        function compressedTexSubImage3D(callback, finish) {
1038            let texture = gl.createTexture();
1039            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
1040            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1041            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
1042            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
1043            gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(4));
1044            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1045            callback();
1046            finish();
1047            gl.deleteTexture(texture);
1048        }
1049        /**
1050         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0033
1051         * @tc.name webgl2_test_compressedTexSubImage3D
1052         * @tc.desc Test compressedTexSubImage3D.
1053         */
1054        it('webgl2_test_compressedTexSubImage3D', 0, async function (done) {
1055            console.info("webgl2test [webgl2_test_compressedTexSubImage3D] compressedTexSubImage3D");
1056            let texture = gl.createTexture();
1057            gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
1058            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1059            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
1060            gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
1061            gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(4));
1062            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1063            gl.deleteTexture(texture);
1064            done();
1065        });
1066        /**
1067         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0034
1068         * @tc.name webgl2_test_compressedTexSubImage3D_1
1069         * @tc.desc Test compressedTexSubImage3D.
1070         */
1071        it('webgl2_test_compressedTexSubImage3D_1', 0, async function (done) {
1072            console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D");
1073            compressedTexSubImage3D(() => {
1074                gl.compressedTexSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4));
1075            }, () => {
1076                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1077            });
1078            done();
1079        });
1080        /**
1081         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0035
1082         * @tc.name webgl2_test_compressedTexSubImage3D_2
1083         * @tc.desc Test compressedTexSubImage3D.
1084         */
1085        it('webgl2_test_compressedTexSubImage3D_2', 0, async function (done) {
1086            console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D");
1087            compressedTexSubImage3D(() => {
1088                gl.compressedTexSubImage3D(gl.TEXTURE_3D, 1, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4));
1089            }, () => {
1090                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1091            });
1092            done();
1093        });
1094        /**
1095         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0036
1096         * @tc.name webgl2_test_compressedTexSubImage3D_3
1097         * @tc.desc Test compressedTexSubImage3D.
1098         */
1099        it('webgl2_test_compressedTexSubImage3D_3', 0, async function (done) {
1100            console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D");
1101            compressedTexSubImage3D(() => {
1102                gl.compressedTexSubImage3D(gl.TEXTURE_3D, -1, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4));
1103            }, () => {
1104                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1105            });
1106            done();
1107        });
1108        function texImage2D(callback, finish) {
1109            let image = new Uint8Array(8 * 8 * 4); // four bytes represent the rgba value of a pixel
1110            for (let i = 0; i < image.length; i += 4) {
1111                if (i < image.length / 2) {
1112                    image[i] = 0;
1113                    image[i + 1] = 0;
1114                    image[i + 2] = 255;
1115                    image[i + 3] = 255;
1116                }
1117                else {
1118                    image[i] = 255;
1119                    image[i + 1] = 0;
1120                    image[i + 2] = 0;
1121                    image[i + 3] = 255;
1122                }
1123            }
1124            let { program, vertexShader, fragmentShader } = createProgram(gl, `#version 300 es
1125                in vec4 a_Position;
1126                in vec2 a_TexCoord;
1127                out vec2 v_TexCoord;
1128                void main(){
1129                    gl_Position = a_Position;
1130                    v_TexCoord = a_TexCoord;
1131                }
1132            `, `#version 300 es
1133                precision mediump float;
1134                precision highp sampler2D;
1135                uniform sampler2D u_Sampler;
1136                in vec2 v_TexCoord;
1137                out vec4 color;
1138                void main(){
1139                    color = texture(u_Sampler, v_TexCoord);
1140                }
1141            `);
1142            let arr = new Float32Array([
1143                -1.0, 1.0, 0.0, 1.0,
1144                -1.0, -1.0, 0.0, 0.0,
1145                1.0, 1.0, 1.0, 1.0,
1146                1.0, -1.0, 1.0, 0.0,
1147            ]);
1148            let FSIZE = arr.BYTES_PER_ELEMENT;
1149            let buffer = gl.createBuffer(); // create buffer
1150            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // bound buffer
1151            gl.bufferData(gl.ARRAY_BUFFER, arr.buffer, gl.STATIC_DRAW); // writes data to a buffer object
1152            let a_Position = gl.getAttribLocation(program, 'a_Position'); // gets the address of the attribute variable
1153            gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 4, 0); // assign the buffer object to an attribute variable
1154            gl.enableVertexAttribArray(a_Position); // Open the attribute variable (connect a Position variable to the buffer object assigned to it)
1155            let a_TexCoord = gl.getAttribLocation(program, 'a_TexCoord'); // gets the address of the attribute variable
1156            gl.vertexAttribPointer(a_TexCoord, 2, gl.FLOAT, false, FSIZE * 4, FSIZE * 2); // assign the buffer object to an attribute variable
1157            gl.enableVertexAttribArray(a_TexCoord); // Open the attribute variable (connect a Position variable to the buffer object assigned to it)
1158            let u_Sampler = gl.getUniformLocation(program, 'u_Sampler');
1159            let texture = gl.createTexture();
1160            gl.activeTexture(gl.TEXTURE0); // open texture unit 0
1161            gl.bindTexture(gl.TEXTURE_2D, texture); // bind the texture object to target
1162            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // configure texture parameters
1163            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // configure texture parameters
1164            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // configure texture parameters
1165            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // configure texture parameters
1166            callback(image);
1167            gl.uniform1i(u_Sampler, 0); // pass texture 0 to the shader
1168            gl.clearColor(0.92, 0.92, 0.92, 1);
1169            gl.clear(gl.COLOR_BUFFER_BIT);
1170            gl.drawArrays(gl.TRIANGLE_STRIP, 0, arr.length / 4);
1171            let res = new Uint8Array(8 * 8 * 4);
1172            gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, res);
1173            finish(res);
1174            gl.flush();
1175            gl.disableVertexAttribArray(a_Position);
1176            gl.disableVertexAttribArray(a_TexCoord);
1177            gl.bindTexture(gl.TEXTURE_2D, null);
1178            gl.bindBuffer(gl.ARRAY_BUFFER, null);
1179            gl.deleteBuffer(buffer);
1180            gl.deleteTexture(texture);
1181            gl.deleteShader(vertexShader);
1182            gl.deleteShader(fragmentShader);
1183            gl.deleteProgram(program);
1184        }
1185        /**
1186         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0037
1187         * @tc.name webgl2_test_texImage2D
1188         * @tc.desc Test texImage2D.
1189         */
1190        it('webgl2_test_texImage2D', 0, async function (done) {
1191            console.info("webgl2test [webgl2_test_texImage2D] texImage2D");
1192            texImage2D((image) => {
1193                gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1194            }, (res) => {
1195                expect(res[0]).assertEqual(0);
1196                expect(res[1]).assertEqual(0);
1197                expect(res[2]).assertEqual(255);
1198                expect(res[3]).assertEqual(255);
1199                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1200            });
1201            done();
1202        });
1203        /**
1204         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0038
1205         * @tc.name webgl2_test_texImage2D_1
1206         * @tc.desc Test texImage2D.
1207         */
1208        it('webgl2_test_texImage2D_1', 0, async function (done) {
1209            console.info("webgl2test [webgl2_test_texImage2D_1] texImage2D");
1210            texImage2D((image) => {
1211                gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1212            }, (res) => {
1213                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1214            });
1215            done();
1216        });
1217        /**
1218         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0039
1219         * @tc.name webgl2_test_texImage2D_2
1220         * @tc.desc Test texImage2D.
1221         */
1222        it('webgl2_test_texImage2D_2', 0, async function (done) {
1223            console.info("webgl2test [webgl2_test_texImage2D_2] texImage2D");
1224            texImage2D((image) => {
1225                gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1226            }, (res) => {
1227                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1228            });
1229            done();
1230        });
1231        /**
1232         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0040
1233         * @tc.name webgl2_test_texImage2D_3
1234         * @tc.desc Test texImage2D.
1235         */
1236        it('webgl2_test_texImage2D_3', 0, async function (done) {
1237            console.info("webgl2test [webgl2_test_texImage2D_3] texImage2D");
1238            texImage2D((image) => {
1239                gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1240            }, (res) => {
1241                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1242            });
1243            done();
1244        });
1245        /**
1246         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0041
1247         * @tc.name webgl2_test_texImage2D_4
1248         * @tc.desc Test texImage2D.
1249         */
1250        it('webgl2_test_texImage2D_4', 0, async function (done) {
1251            console.info("webgl2test [webgl2_test_texImage2D_4] texImage2D");
1252            texImage2D((image) => {
1253                gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); //  configure texture images
1254            }, (res) => {
1255                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1256            });
1257            done();
1258        });
1259        /**
1260         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0042
1261         * @tc.name webgl2_test_texImage2D_5
1262         * @tc.desc Test texImage2D.
1263         */
1264        it('webgl2_test_texImage2D_5', 0, async function (done) {
1265            console.info("webgl2test [webgl2_test_texImage2D_5] texImage2D");
1266            texImage2D((image) => {
1267                gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1268            }, (res) => {
1269                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1270            });
1271            done();
1272        });
1273        /**
1274         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0043
1275         * @tc.name webgl2_test_texImage2D_6
1276         * @tc.desc Test texImage2D.
1277         */
1278        it('webgl2_test_texImage2D_6', 0, async function (done) {
1279            console.info("webgl2test [webgl2_test_texImage2D_6] texImage2D");
1280            texImage2D((image) => {
1281                gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images
1282            }, (res) => {
1283                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1284            });
1285            done();
1286        });
1287        function texSubImage2D(callback, finish) {
1288            let image = new Uint8Array(8 * 8 * 4); // four bytes represent the rgba value of a pixel
1289            for (let i = 0; i < image.length; i += 4) {
1290                if (i < image.length / 2) {
1291                    image[i] = 0;
1292                    image[i + 1] = 0;
1293                    image[i + 2] = 255;
1294                    image[i + 3] = 255;
1295                }
1296                else {
1297                    image[i] = 255;
1298                    image[i + 1] = 0;
1299                    image[i + 2] = 0;
1300                    image[i + 3] = 255;
1301                }
1302            }
1303            let { program, vertexShader, fragmentShader } = createProgram(gl, `#version 300 es
1304                in vec4 a_Position;
1305                in vec2 a_TexCoord;
1306                out vec2 v_TexCoord;
1307                void main(){
1308                    gl_Position = a_Position;
1309                    v_TexCoord = a_TexCoord;
1310                }
1311            `, `#version 300 es
1312                precision mediump float;
1313                precision highp sampler2D;
1314                uniform sampler2D u_Sampler;
1315                in vec2 v_TexCoord;
1316                out vec4 color;
1317                void main(){
1318                    color = texture(u_Sampler, v_TexCoord);
1319                }
1320            `);
1321            let arr = new Float32Array([
1322                -1.0, 1.0, 0.0, 1.0,
1323                -1.0, -1.0, 0.0, 0.0,
1324                1.0, 1.0, 1.0, 1.0,
1325                1.0, -1.0, 1.0, 0.0,
1326            ]);
1327            let FSIZE = arr.BYTES_PER_ELEMENT;
1328            let buffer = gl.createBuffer(); // create buffer
1329            gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // bound buffer
1330            gl.bufferData(gl.ARRAY_BUFFER, arr.buffer, gl.STATIC_DRAW); // writes data to a buffer object
1331            let a_Position = gl.getAttribLocation(program, 'a_Position'); // gets the address of the attribute variable
1332            gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 4, 0); // assign the buffer object to an attribute variable
1333            gl.enableVertexAttribArray(a_Position); // Open the attribute variable (connect a Position variable to the buffer object assigned to it)
1334            let a_TexCoord = gl.getAttribLocation(program, 'a_TexCoord'); // gets the address of the attribute variable
1335            gl.vertexAttribPointer(a_TexCoord, 2, gl.FLOAT, false, FSIZE * 4, FSIZE * 2); // assign the buffer object to an attribute variable
1336            gl.enableVertexAttribArray(a_TexCoord); // Open the attribute variable (connect a Position variable to the buffer object assigned to it)
1337            let u_Sampler = gl.getUniformLocation(program, 'u_Sampler');
1338            let texture = gl.createTexture();
1339            gl.activeTexture(gl.TEXTURE0); // open texture unit 0
1340            gl.bindTexture(gl.TEXTURE_2D, texture); // bind the texture object to target
1341            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // configure texture parameters
1342            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // configure texture parameters
1343            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // configure texture parameters
1344            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // configure texture parameters
1345            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 8, 8, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 0); // configure texture images
1346            callback(image);
1347            gl.uniform1i(u_Sampler, 0); // pass texture 0 to the shader
1348            gl.clearColor(0.92, 0.92, 0.92, 1);
1349            gl.clear(gl.COLOR_BUFFER_BIT);
1350            gl.drawArrays(gl.TRIANGLE_STRIP, 0, arr.length / 4);
1351            let res = new Uint8Array(8 * 8 * 4);
1352            gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, res);
1353            finish(res);
1354            gl.flush();
1355            gl.disableVertexAttribArray(a_Position);
1356            gl.disableVertexAttribArray(a_TexCoord);
1357            gl.bindTexture(gl.TEXTURE_2D, null);
1358            gl.bindBuffer(gl.ARRAY_BUFFER, null);
1359            gl.deleteBuffer(buffer);
1360            gl.deleteTexture(texture);
1361            gl.deleteShader(vertexShader);
1362            gl.deleteShader(fragmentShader);
1363            gl.deleteProgram(program);
1364        }
1365        /**
1366         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0044
1367         * @tc.name webgl2_test_texSubImage2D
1368         * @tc.desc Test texSubImage2D.
1369         */
1370        it('webgl2_test_texSubImage2D', 0, async function (done) {
1371            console.info("webgl2test [webgl2_test_texSubImage2D] texSubImage2D");
1372            texSubImage2D((image) => {
1373                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1374                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1375            }, (res) => {
1376                expect(res[0]).assertEqual(255);
1377                expect(res[1]).assertEqual(255);
1378                expect(res[2]).assertEqual(0);
1379                expect(res[3]).assertEqual(255);
1380                expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1381            });
1382            done();
1383        });
1384        /**
1385         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0045
1386         * @tc.name webgl2_test_texSubImage2D_1
1387         * @tc.desc Test texSubImage2D.
1388         */
1389        it('webgl2_test_texSubImage2D_1', 0, async function (done) {
1390            console.info("webgl2test [webgl2_test_texSubImage2D_1] texSubImage2D");
1391            texSubImage2D((image) => {
1392                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1393                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1394            }, (res) => {
1395                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1396            });
1397            done();
1398        });
1399        /**
1400         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0046
1401         * @tc.name webgl2_test_texSubImage2D_2
1402         * @tc.desc Test texSubImage2D.
1403         */
1404        it('webgl2_test_texSubImage2D_2', 0, async function (done) {
1405            console.info("webgl2test [webgl2_test_texSubImage2D_2] texSubImage2D");
1406            texSubImage2D((image) => {
1407                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1408                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1409            }, (res) => {
1410                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1411            });
1412            done();
1413        });
1414        /**
1415         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0047
1416         * @tc.name webgl2_test_texSubImage2D_3
1417         * @tc.desc Test texSubImage2D.
1418         */
1419        it('webgl2_test_texSubImage2D_3', 0, async function (done) {
1420            console.info("webgl2test [webgl2_test_texSubImage2D_3] texSubImage2D");
1421            texSubImage2D((image) => {
1422                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1423                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1424            }, (res) => {
1425                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1426            });
1427            done();
1428        });
1429        /**
1430         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0048
1431         * @tc.name webgl2_test_texSubImage2D_4
1432         * @tc.desc Test texSubImage2D.
1433         */
1434        it('webgl2_test_texSubImage2D_4', 0, async function (done) {
1435            console.info("webgl2test [webgl2_test_texSubImage2D_4] texSubImage2D");
1436            texSubImage2D((image) => {
1437                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1438                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1439            }, (res) => {
1440                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1441            });
1442            done();
1443        });
1444        /**
1445         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0049
1446         * @tc.name webgl2_test_texSubImage2D_5
1447         * @tc.desc Test texSubImage2D.
1448         */
1449        it('webgl2_test_texSubImage2D_5', 0, async function (done) {
1450            console.info("webgl2test [webgl2_test_texSubImage2D_5] texSubImage2D");
1451            texSubImage2D((image) => {
1452                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1453                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1454            }, (res) => {
1455                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1456            });
1457            done();
1458        });
1459        /**
1460         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0050
1461         * @tc.name webgl2_test_texSubImage2D_6
1462         * @tc.desc Test texSubImage2D.
1463         */
1464        it('webgl2_test_texSubImage2D_6', 0, async function (done) {
1465            console.info("webgl2test [webgl2_test_texSubImage2D_6] texSubImage2D");
1466            texSubImage2D((image) => {
1467                let newData = getColorUint8Array(4, 4, 255, 255, 0, 255);
1468                gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8);
1469            }, (res) => {
1470                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1471            });
1472            done();
1473        });
1474        function compressedTexImage2D(callback, finish) {
1475            let texture = gl.createTexture();
1476            gl.bindTexture(gl.TEXTURE_2D, texture);
1477            console.log(gl.getSupportedExtensions());
1478            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1479            callback();
1480            finish();
1481            gl.deleteTexture(texture);
1482        }
1483        /**
1484         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0051
1485         * @tc.name webgl2_test_compressedTexImage2D
1486         * @tc.desc Test compressedTexImage2D.
1487         */
1488        it('webgl2_test_compressedTexImage2D', 0, async function (done) {
1489            console.info("webgl2test [webgl2_test_compressedTexImage2D] compressedTexImage2D");
1490            let texture = gl.createTexture();
1491            gl.bindTexture(gl.TEXTURE_2D, texture);
1492            console.log(gl.getSupportedExtensions());
1493            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1494            gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1495            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1496            gl.deleteTexture(texture);
1497            done();
1498        });
1499        /**
1500         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0052
1501         * @tc.name webgl2_test_compressedTexImage2D_1
1502         * @tc.desc Test compressedTexImage2D.
1503         */
1504        it('webgl2_test_compressedTexImage2D_1', 0, async function (done) {
1505            console.info("webgl2test [webgl2_test_compressedTexImage2D_1] compressedTexImage2D");
1506            compressedTexImage2D(() => {
1507                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1508            }, () => {
1509                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1510            });
1511            done();
1512        });
1513        /**
1514         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0053
1515         * @tc.name webgl2_test_compressedTexImage2D_2
1516         * @tc.desc Test compressedTexImage2D.
1517         */
1518        it('webgl2_test_compressedTexImage2D_2', 0, async function (done) {
1519            console.info("webgl2test [webgl2_test_compressedTexImage2D_2] compressedTexImage2D");
1520            compressedTexImage2D(() => {
1521                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1522            }, () => {
1523                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1524            });
1525            done();
1526        });
1527        /**
1528         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0054
1529         * @tc.name webgl2_test_compressedTexImage2D_3
1530         * @tc.desc Test compressedTexImage2D.
1531         */
1532        it('webgl2_test_compressedTexImage2D_3', 0, async function (done) {
1533            console.info("webgl2test [webgl2_test_compressedTexImage2D_3] compressedTexImage2D");
1534            compressedTexImage2D(() => {
1535                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1536            }, () => {
1537                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1538            });
1539            done();
1540        });
1541        /**
1542         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0055
1543         * @tc.name webgl2_test_compressedTexImage2D_4
1544         * @tc.desc Test compressedTexImage2D.
1545         */
1546        it('webgl2_test_compressedTexImage2D_4', 0, async function (done) {
1547            console.info("webgl2test [webgl2_test_compressedTexImage2D_4] compressedTexImage2D");
1548            compressedTexImage2D(() => {
1549                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1550            }, () => {
1551                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1552            });
1553            done();
1554        });
1555        /**
1556         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0056
1557         * @tc.name webgl2_test_compressedTexImage2D_5
1558         * @tc.desc Test compressedTexImage2D.
1559         */
1560        it('webgl2_test_compressedTexImage2D_5', 0, async function (done) {
1561            console.info("webgl2test [webgl2_test_compressedTexImage2D_5] compressedTexImage2D");
1562            compressedTexImage2D(() => {
1563                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1564            }, () => {
1565                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1566            });
1567            done();
1568        });
1569        /**
1570         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0057
1571         * @tc.name webgl2_test_compressedTexImage2D_6
1572         * @tc.desc Test compressedTexImage2D.
1573         */
1574        it('webgl2_test_compressedTexImage2D_6', 0, async function (done) {
1575            console.info("webgl2test [webgl2_test_compressedTexImage2D_6] compressedTexImage2D");
1576            compressedTexImage2D(() => {
1577                gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1578            }, () => {
1579                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1580            });
1581            done();
1582        });
1583        function compressedTexSubImage2D(callback, finish) {
1584            let texture = gl.createTexture();
1585            gl.bindTexture(gl.TEXTURE_2D, texture);
1586            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1587            gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1588            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1589            callback();
1590            finish();
1591            gl.deleteTexture(texture);
1592        }
1593        /**
1594         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0058
1595         * @tc.name webgl2_test_compressedTexSubImage2D
1596         * @tc.desc Test compressedTexSubImage2D.
1597         */
1598        it('webgl2_test_compressedTexSubImage2D', 0, async function (done) {
1599            console.info("webgl2test [webgl2_test_compressedTexSubImage2D] compressedTexSubImage2D");
1600            let texture = gl.createTexture();
1601            gl.bindTexture(gl.TEXTURE_2D, texture);
1602            console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS));
1603            gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4));
1604            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1605            gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1606            expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1607            gl.deleteTexture(texture);
1608            done();
1609        });
1610        /**
1611         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0059
1612         * @tc.name webgl2_test_compressedTexSubImage2D_1
1613         * @tc.desc Test compressedTexSubImage2D.
1614         */
1615        it('webgl2_test_compressedTexSubImage2D_1', 0, async function (done) {
1616            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_1] compressedTexSubImage2D");
1617            compressedTexSubImage2D(() => {
1618                gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1619            }, () => {
1620                expect(checkError(gl)).assertEqual(gl.INVALID_ENUM);
1621            });
1622            done();
1623        });
1624        /**
1625         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0060
1626         * @tc.name webgl2_test_compressedTexSubImage2D_2
1627         * @tc.desc Test compressedTexSubImage2D.
1628         */
1629        it('webgl2_test_compressedTexSubImage2D_2', 0, async function (done) {
1630            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_2] compressedTexSubImage2D");
1631            compressedTexSubImage2D(() => {
1632                gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1633            }, () => {
1634                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1635            });
1636            done();
1637        });
1638        /**
1639         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0061
1640         * @tc.name webgl2_test_compressedTexSubImage2D_3
1641         * @tc.desc Test compressedTexSubImage2D.
1642         */
1643        it('webgl2_test_compressedTexSubImage2D_3', 0, async function (done) {
1644            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_3] compressedTexSubImage2D");
1645            compressedTexSubImage2D(() => {
1646                gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1647            }, () => {
1648                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1649            });
1650            done();
1651        });
1652        /**
1653         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0062
1654         * @tc.name webgl2_test_compressedTexSubImage2D_4
1655         * @tc.desc Test compressedTexSubImage2D.
1656         */
1657        it('webgl2_test_compressedTexSubImage2D_4', 0, async function (done) {
1658            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_4] compressedTexSubImage2D");
1659            compressedTexSubImage2D(() => {
1660                gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1661            }, () => {
1662                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1663            });
1664            done();
1665        });
1666        /**
1667         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0063
1668         * @tc.name webgl2_test_compressedTexSubImage2D_5
1669         * @tc.desc Test compressedTexSubImage2D.
1670         */
1671        it('webgl2_test_compressedTexSubImage2D_5', 0, async function (done) {
1672            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_5] compressedTexSubImage2D");
1673            compressedTexSubImage2D(() => {
1674                gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1675            }, () => {
1676                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1677            });
1678            done();
1679        });
1680        /**
1681         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0064
1682         * @tc.name webgl2_test_compressedTexSubImage2D_6
1683         * @tc.desc Test compressedTexSubImage2D.
1684         */
1685        it('webgl2_test_compressedTexSubImage2D_6', 0, async function (done) {
1686            console.info("webgl2test [webgl2_test_compressedTexSubImage2D_6] compressedTexSubImage2D");
1687            compressedTexSubImage2D(() => {
1688                gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1);
1689            }, () => {
1690                expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION);
1691            });
1692            done();
1693        });
1694        /**
1695         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0065
1696         * @tc.name webgl2_test_readPixels
1697         * @tc.desc Test readPixels.
1698         */
1699        it('webgl2_test_readPixels', 0, async function (done) {
1700            console.info("webgl2test [webgl2_test_readPixels] readPixels");
1701            let srcViewport = gl.getParameter(gl.VIEWPORT);
1702            let p = createProgram(gl, `#version 300 es
1703                in vec4 a_position;
1704                in vec3 a_color;
1705                out vec3 v_color;
1706                void main(){
1707                    gl_Position = a_position;
1708                    gl_PointSize = 1.0;
1709                    v_color = a_color;
1710                }
1711            `, `#version 300 es
1712                precision mediump float;
1713                in vec3 v_color;
1714                out vec4 color;
1715                void main(){
1716                    color = vec4(v_color,1.0);
1717                }
1718            `);
1719            let source = new Float32Array([
1720                -0.5, -0.5, 1.0, 0.0, 0.0,
1721                0.5, -0.5, 0.0, 0.0, 0.0,
1722                -0.5, 0.5, 0.0, 1.0, 0.0,
1723                0.5, 0.5, 0.0, 0.0, 1.0,
1724            ]);
1725            let num = 4;
1726            let FSIZE = source.BYTES_PER_ELEMENT;
1727            let buffer = gl.createBuffer();
1728            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
1729            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_READ, 0, 20);
1730            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1731            let a_position = gl.getAttribLocation(p.program, 'a_position');
1732            gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 5 * FSIZE, 0);
1733            gl.enableVertexAttribArray(a_position);
1734            let a_color = gl.getAttribLocation(p.program, 'a_color');
1735            gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 5 * FSIZE, 2 * FSIZE);
1736            gl.enableVertexAttribArray(a_color);
1737            gl.clearColor(0, 0, 0, 1.0);
1738            gl.clear(gl.COLOR_BUFFER_BIT);
1739            gl.viewport(0, 0, 2, 2);
1740            gl.drawArrays(gl.POINTS, 0, 4);
1741            let result = new Uint8Array(2 * 2 * 4 + 4);
1742            gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, result, 4);
1743            console.info("webgltest ", result);
1744            expect(result[0]).assertEqual(0);
1745            expect(result[1]).assertEqual(0);
1746            expect(result[2]).assertEqual(0);
1747            expect(result[3]).assertEqual(0);
1748            expect(result[4]).assertEqual(255);
1749            expect(result[5]).assertEqual(0);
1750            expect(result[6]).assertEqual(0);
1751            expect(result[7]).assertEqual(255);
1752            gl.deleteBuffer(buffer);
1753            gl.deleteShader(p.vertexShader);
1754            gl.deleteShader(p.fragmentShader);
1755            gl.deleteProgram(p.program);
1756            gl.disableVertexAttribArray(a_color);
1757            gl.disableVertexAttribArray(a_position);
1758            gl.viewport(srcViewport[0], srcViewport[1], srcViewport[2], srcViewport[3]);
1759            checkError(gl);
1760            done();
1761        });
1762        /**
1763         * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0066
1764         * @tc.name webgl2_test_readPixels_2
1765         * @tc.desc Test readPixels.
1766         */
1767        it('webgl2_test_readPixels_2', 0, async function (done) {
1768            console.info("webgl2test [webgl2_test_readPixels_2] readPixels");
1769            let srcViewport = gl.getParameter(gl.VIEWPORT);
1770            let p = createProgram(gl, `#version 300 es
1771                in vec4 a_position;
1772                in vec3 a_color;
1773                out vec3 v_color;
1774                void main(){
1775                    gl_Position = a_position;
1776                    gl_PointSize = 1.0;
1777                    v_color = a_color;
1778                }
1779            `, `#version 300 es
1780                precision mediump float;
1781                in vec3 v_color;
1782                out vec4 color;
1783                void main(){
1784                    color = vec4(v_color,1.0);
1785                }
1786            `);
1787            let source = new Float32Array([
1788                -0.5, -0.5, 1.0, 0.0, 0.0,
1789                0.5, -0.5, 0.0, 0.0, 0.0,
1790                -0.5, 0.5, 0.0, 1.0, 0.0,
1791                0.5, 0.5, 0.0, 0.0, 1.0,
1792            ]);
1793            let num = 4;
1794            let FSIZE = source.BYTES_PER_ELEMENT;
1795            let buffer = gl.createBuffer();
1796            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
1797            gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_READ, 0, 20);
1798            expect(checkError(gl)).assertEqual(gl.NO_ERROR);
1799            let a_position = gl.getAttribLocation(p.program, 'a_position');
1800            gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 5 * FSIZE, 0);
1801            gl.enableVertexAttribArray(a_position);
1802            let a_color = gl.getAttribLocation(p.program, 'a_color');
1803            gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 5 * FSIZE, 2 * FSIZE);
1804            gl.enableVertexAttribArray(a_color);
1805            gl.clearColor(0, 0, 0, 1.0);
1806            gl.clear(gl.COLOR_BUFFER_BIT);
1807            gl.viewport(0, 0, 2, 2);
1808            gl.drawArrays(gl.POINTS, 0, 4);
1809            let result = new Uint8Array(2 * 2 * 4);
1810            gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, result);
1811            console.info("webgltest ", result);
1812            expect(result[0]).assertEqual(255);
1813            expect(result[1]).assertEqual(0);
1814            expect(result[2]).assertEqual(0);
1815            expect(result[3]).assertEqual(255);
1816            expect(result[4]).assertEqual(0);
1817            expect(result[5]).assertEqual(0);
1818            expect(result[6]).assertEqual(0);
1819            expect(result[7]).assertEqual(255);
1820            gl.deleteBuffer(buffer);
1821            gl.deleteShader(p.vertexShader);
1822            gl.deleteShader(p.fragmentShader);
1823            gl.deleteProgram(p.program);
1824            gl.disableVertexAttribArray(a_color);
1825            gl.disableVertexAttribArray(a_position);
1826            gl.viewport(srcViewport[0], srcViewport[1], srcViewport[2], srcViewport[3]);
1827            checkError(gl);
1828            done();
1829        });
1830    })
1831}
1832