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, TestType, Level, Size } 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 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', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 911 async function (done) { 912 console.info("webgl2test [webgl2_test_copyTexSubImage3D_1] copyTexSubImage3D"); 913 copyTexSubImage3D((width, height, depth, texture, newTexture) => { 914 for (let i = 0; i < depth; i++) { 915 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 916 gl.vertexAttrib1f(2, i); 917 gl.clearColor(0.0, 0.0, 0.0, 1.0); 918 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 919 gl.drawArrays(gl.TRIANGLES, 0, 6); 920 gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture); 921 gl.copyTexSubImage3D(gl.TEXTURE_3D, 0, 0, 0, i, 0, 0, width, height); 922 } 923 }, (res) => { 924 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 925 }); 926 done(); 927 }); 928 /** 929 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0027 930 * @tc.name webgl2_test_copyTexSubImage3D_2 931 * @tc.desc Test copyTexSubImage3D. 932 */ 933 it('webgl2_test_copyTexSubImage3D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 934 async function (done) { 935 console.info("webgl2test [webgl2_test_copyTexSubImage3D_2] copyTexSubImage3D"); 936 copyTexSubImage3D((width, height, depth, texture, newTexture) => { 937 for (let i = 0; i < depth; i++) { 938 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 939 gl.vertexAttrib1f(2, i); 940 gl.clearColor(0.0, 0.0, 0.0, 1.0); 941 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 942 gl.drawArrays(gl.TRIANGLES, 0, 6); 943 gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture); 944 gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, 1, 1, 10, i, 10, 10, width, height); 945 } 946 }, (res) => { 947 expect(checkError(gl)).assertEqual(gl.INVALID_VALUE); 948 }); 949 done(); 950 }); 951 /** 952 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0028 953 * @tc.name webgl2_test_copyTexSubImage3D_3 954 * @tc.desc Test copyTexSubImage3D. 955 */ 956 it('webgl2_test_copyTexSubImage3D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 957 async function (done) { 958 console.info("webgl2test [webgl2_test_copyTexSubImage3D_3] copyTexSubImage3D"); 959 copyTexSubImage3D((width, height, depth, texture, newTexture) => { 960 for (let i = 0; i < depth; i++) { 961 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 962 gl.vertexAttrib1f(2, i); 963 gl.clearColor(0.0, 0.0, 0.0, 1.0); 964 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 965 gl.drawArrays(gl.TRIANGLES, 0, 6); 966 gl.bindTexture(gl.TEXTURE_2D_ARRAY, newTexture); 967 gl.copyTexSubImage3D(gl.TEXTURE_2D_ARRAY, -1, 0, 0, i, 0, 0, width, height); 968 } 969 }, (res) => { 970 expect(checkError(gl)).assertEqual(gl.INVALID_VALUE); 971 }); 972 done(); 973 }); 974 function compressedTexImage3D(callback, finish) { 975 let texture = gl.createTexture(); 976 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 977 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 978 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 979 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 980 callback(); 981 finish(); 982 gl.deleteTexture(texture); 983 } 984 /** 985 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0029 986 * @tc.name webgl2_test_compressedTexImage3D 987 * @tc.desc Test compressedTexImage3D. 988 */ 989 it('webgl2_test_compressedTexImage3D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 990 async function (done) { 991 console.info("webgl2test [webgl2_test_compressedTexImage3D] compressedTexImage3D"); 992 let texture = gl.createTexture(); 993 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 994 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 995 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 996 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 997 gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4)); 998 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 999 gl.deleteTexture(texture); 1000 done(); 1001 }); 1002 /** 1003 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0030 1004 * @tc.name webgl2_test_compressedTexImage3D_1 1005 * @tc.desc Test compressedTexImage3D. 1006 */ 1007 it('webgl2_test_compressedTexImage3D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1008 async function (done) { 1009 compressedTexImage3D(() => { 1010 gl.compressedTexImage3D(gl.TEXTURE_3D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4)); 1011 }, () => { 1012 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1013 }); 1014 done(); 1015 }); 1016 /** 1017 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0031 1018 * @tc.name webgl2_test_compressedTexImage3D_2 1019 * @tc.desc Test compressedTexImage3D. 1020 */ 1021 it('webgl2_test_compressedTexImage3D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1022 async function (done) { 1023 compressedTexImage3D(() => { 1024 gl.compressedTexImage3D(gl.TEXTURE_3D, 1, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4)); 1025 }, () => { 1026 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1027 }); 1028 done(); 1029 }); 1030 /** 1031 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0032 1032 * @tc.name webgl2_test_compressedTexImage3D_3 1033 * @tc.desc Test compressedTexImage3D. 1034 */ 1035 it('webgl2_test_compressedTexImage3D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1036 async function (done) { 1037 compressedTexImage3D(() => { 1038 gl.compressedTexImage3D(gl.TEXTURE_3D, -1, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(1 * 1 * 1 * 4)); 1039 }, () => { 1040 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1041 }); 1042 done(); 1043 }); 1044 function compressedTexSubImage3D(callback, finish) { 1045 let texture = gl.createTexture(); 1046 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 1047 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1048 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1049 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 1050 gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(4)); 1051 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1052 callback(); 1053 finish(); 1054 gl.deleteTexture(texture); 1055 } 1056 /** 1057 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0033 1058 * @tc.name webgl2_test_compressedTexSubImage3D 1059 * @tc.desc Test compressedTexSubImage3D. 1060 */ 1061 it('webgl2_test_compressedTexSubImage3D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1062 async function (done) { 1063 console.info("webgl2test [webgl2_test_compressedTexSubImage3D] compressedTexSubImage3D"); 1064 let texture = gl.createTexture(); 1065 gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture); 1066 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1067 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1068 gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 1069 gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 1, 0, new Float32Array(4)); 1070 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1071 gl.deleteTexture(texture); 1072 done(); 1073 }); 1074 /** 1075 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0034 1076 * @tc.name webgl2_test_compressedTexSubImage3D_1 1077 * @tc.desc Test compressedTexSubImage3D. 1078 */ 1079 it('webgl2_test_compressedTexSubImage3D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1080 async function (done) { 1081 console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D"); 1082 compressedTexSubImage3D(() => { 1083 gl.compressedTexSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4)); 1084 }, () => { 1085 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1086 }); 1087 done(); 1088 }); 1089 /** 1090 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0035 1091 * @tc.name webgl2_test_compressedTexSubImage3D_2 1092 * @tc.desc Test compressedTexSubImage3D. 1093 */ 1094 it('webgl2_test_compressedTexSubImage3D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1095 async function (done) { 1096 console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D"); 1097 compressedTexSubImage3D(() => { 1098 gl.compressedTexSubImage3D(gl.TEXTURE_3D, 1, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4)); 1099 }, () => { 1100 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1101 }); 1102 done(); 1103 }); 1104 /** 1105 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0036 1106 * @tc.name webgl2_test_compressedTexSubImage3D_3 1107 * @tc.desc Test compressedTexSubImage3D. 1108 */ 1109 it('webgl2_test_compressedTexSubImage3D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1110 async function (done) { 1111 console.info("webgl2test [webgl2_test_compressedTexSubImage3D_1] compressedTexSubImage3D"); 1112 compressedTexSubImage3D(() => { 1113 gl.compressedTexSubImage3D(gl.TEXTURE_3D, -1, 0, 0, 0, 1, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4)); 1114 }, () => { 1115 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1116 }); 1117 done(); 1118 }); 1119 function texImage2D(callback, finish) { 1120 let image = new Uint8Array(8 * 8 * 4); // four bytes represent the rgba value of a pixel 1121 for (let i = 0; i < image.length; i += 4) { 1122 if (i < image.length / 2) { 1123 image[i] = 0; 1124 image[i + 1] = 0; 1125 image[i + 2] = 255; 1126 image[i + 3] = 255; 1127 } 1128 else { 1129 image[i] = 255; 1130 image[i + 1] = 0; 1131 image[i + 2] = 0; 1132 image[i + 3] = 255; 1133 } 1134 } 1135 let { program, vertexShader, fragmentShader } = createProgram(gl, `#version 300 es 1136 in vec4 a_Position; 1137 in vec2 a_TexCoord; 1138 out vec2 v_TexCoord; 1139 void main(){ 1140 gl_Position = a_Position; 1141 v_TexCoord = a_TexCoord; 1142 } 1143 `, `#version 300 es 1144 precision mediump float; 1145 precision highp sampler2D; 1146 uniform sampler2D u_Sampler; 1147 in vec2 v_TexCoord; 1148 out vec4 color; 1149 void main(){ 1150 color = texture(u_Sampler, v_TexCoord); 1151 } 1152 `); 1153 let arr = new Float32Array([ 1154 -1.0, 1.0, 0.0, 1.0, 1155 -1.0, -1.0, 0.0, 0.0, 1156 1.0, 1.0, 1.0, 1.0, 1157 1.0, -1.0, 1.0, 0.0, 1158 ]); 1159 let FSIZE = arr.BYTES_PER_ELEMENT; 1160 let buffer = gl.createBuffer(); // create buffer 1161 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // bound buffer 1162 gl.bufferData(gl.ARRAY_BUFFER, arr.buffer, gl.STATIC_DRAW); // writes data to a buffer object 1163 let a_Position = gl.getAttribLocation(program, 'a_Position'); // gets the address of the attribute variable 1164 gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 4, 0); // assign the buffer object to an attribute variable 1165 gl.enableVertexAttribArray(a_Position); // Open the attribute variable (connect a Position variable to the buffer object assigned to it) 1166 let a_TexCoord = gl.getAttribLocation(program, 'a_TexCoord'); // gets the address of the attribute variable 1167 gl.vertexAttribPointer(a_TexCoord, 2, gl.FLOAT, false, FSIZE * 4, FSIZE * 2); // assign the buffer object to an attribute variable 1168 gl.enableVertexAttribArray(a_TexCoord); // Open the attribute variable (connect a Position variable to the buffer object assigned to it) 1169 let u_Sampler = gl.getUniformLocation(program, 'u_Sampler'); 1170 let texture = gl.createTexture(); 1171 gl.activeTexture(gl.TEXTURE0); // open texture unit 0 1172 gl.bindTexture(gl.TEXTURE_2D, texture); // bind the texture object to target 1173 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // configure texture parameters 1174 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // configure texture parameters 1175 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // configure texture parameters 1176 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // configure texture parameters 1177 callback(image); 1178 gl.uniform1i(u_Sampler, 0); // pass texture 0 to the shader 1179 gl.clearColor(0.92, 0.92, 0.92, 1); 1180 gl.clear(gl.COLOR_BUFFER_BIT); 1181 gl.drawArrays(gl.TRIANGLE_STRIP, 0, arr.length / 4); 1182 let res = new Uint8Array(8 * 8 * 4); 1183 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, res); 1184 finish(res); 1185 gl.flush(); 1186 gl.disableVertexAttribArray(a_Position); 1187 gl.disableVertexAttribArray(a_TexCoord); 1188 gl.bindTexture(gl.TEXTURE_2D, null); 1189 gl.bindBuffer(gl.ARRAY_BUFFER, null); 1190 gl.deleteBuffer(buffer); 1191 gl.deleteTexture(texture); 1192 gl.deleteShader(vertexShader); 1193 gl.deleteShader(fragmentShader); 1194 gl.deleteProgram(program); 1195 } 1196 /** 1197 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0037 1198 * @tc.name webgl2_test_texImage2D 1199 * @tc.desc Test texImage2D. 1200 */ 1201 it('webgl2_test_texImage2D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1202 console.info("webgl2test [webgl2_test_texImage2D] texImage2D"); 1203 texImage2D((image) => { 1204 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1205 }, (res) => { 1206 expect(res[0]).assertEqual(0); 1207 expect(res[1]).assertEqual(0); 1208 expect(res[2]).assertEqual(255); 1209 expect(res[3]).assertEqual(255); 1210 expect(checkError(gl)).assertEqual(gl.NO_ERROR); 1211 }); 1212 done(); 1213 }); 1214 /** 1215 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0038 1216 * @tc.name webgl2_test_texImage2D_1 1217 * @tc.desc Test texImage2D. 1218 */ 1219 it('webgl2_test_texImage2D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1220 console.info("webgl2test [webgl2_test_texImage2D_1] texImage2D"); 1221 texImage2D((image) => { 1222 gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1223 }, (res) => { 1224 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1225 }); 1226 done(); 1227 }); 1228 /** 1229 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0039 1230 * @tc.name webgl2_test_texImage2D_2 1231 * @tc.desc Test texImage2D. 1232 */ 1233 it('webgl2_test_texImage2D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1234 console.info("webgl2test [webgl2_test_texImage2D_2] texImage2D"); 1235 texImage2D((image) => { 1236 gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1237 }, (res) => { 1238 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1239 }); 1240 done(); 1241 }); 1242 /** 1243 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0040 1244 * @tc.name webgl2_test_texImage2D_3 1245 * @tc.desc Test texImage2D. 1246 */ 1247 it('webgl2_test_texImage2D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1248 console.info("webgl2test [webgl2_test_texImage2D_3] texImage2D"); 1249 texImage2D((image) => { 1250 gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1251 }, (res) => { 1252 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1253 }); 1254 done(); 1255 }); 1256 /** 1257 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0041 1258 * @tc.name webgl2_test_texImage2D_4 1259 * @tc.desc Test texImage2D. 1260 */ 1261 it('webgl2_test_texImage2D_4', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1262 console.info("webgl2test [webgl2_test_texImage2D_4] texImage2D"); 1263 texImage2D((image) => { 1264 gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1265 }, (res) => { 1266 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1267 }); 1268 done(); 1269 }); 1270 /** 1271 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0042 1272 * @tc.name webgl2_test_texImage2D_5 1273 * @tc.desc Test texImage2D. 1274 */ 1275 it('webgl2_test_texImage2D_5', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1276 console.info("webgl2test [webgl2_test_texImage2D_5] texImage2D"); 1277 texImage2D((image) => { 1278 gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1279 }, (res) => { 1280 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1281 }); 1282 done(); 1283 }); 1284 /** 1285 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0043 1286 * @tc.name webgl2_test_texImage2D_6 1287 * @tc.desc Test texImage2D. 1288 */ 1289 it('webgl2_test_texImage2D_6', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1290 console.info("webgl2test [webgl2_test_texImage2D_6] texImage2D"); 1291 texImage2D((image) => { 1292 gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, 8, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 32); // configure texture images 1293 }, (res) => { 1294 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1295 }); 1296 done(); 1297 }); 1298 function texSubImage2D(callback, finish) { 1299 let image = new Uint8Array(8 * 8 * 4); // four bytes represent the rgba value of a pixel 1300 for (let i = 0; i < image.length; i += 4) { 1301 if (i < image.length / 2) { 1302 image[i] = 0; 1303 image[i + 1] = 0; 1304 image[i + 2] = 255; 1305 image[i + 3] = 255; 1306 } 1307 else { 1308 image[i] = 255; 1309 image[i + 1] = 0; 1310 image[i + 2] = 0; 1311 image[i + 3] = 255; 1312 } 1313 } 1314 let { program, vertexShader, fragmentShader } = createProgram(gl, `#version 300 es 1315 in vec4 a_Position; 1316 in vec2 a_TexCoord; 1317 out vec2 v_TexCoord; 1318 void main(){ 1319 gl_Position = a_Position; 1320 v_TexCoord = a_TexCoord; 1321 } 1322 `, `#version 300 es 1323 precision mediump float; 1324 precision highp sampler2D; 1325 uniform sampler2D u_Sampler; 1326 in vec2 v_TexCoord; 1327 out vec4 color; 1328 void main(){ 1329 color = texture(u_Sampler, v_TexCoord); 1330 } 1331 `); 1332 let arr = new Float32Array([ 1333 -1.0, 1.0, 0.0, 1.0, 1334 -1.0, -1.0, 0.0, 0.0, 1335 1.0, 1.0, 1.0, 1.0, 1336 1.0, -1.0, 1.0, 0.0, 1337 ]); 1338 let FSIZE = arr.BYTES_PER_ELEMENT; 1339 let buffer = gl.createBuffer(); // create buffer 1340 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // bound buffer 1341 gl.bufferData(gl.ARRAY_BUFFER, arr.buffer, gl.STATIC_DRAW); // writes data to a buffer object 1342 let a_Position = gl.getAttribLocation(program, 'a_Position'); // gets the address of the attribute variable 1343 gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, FSIZE * 4, 0); // assign the buffer object to an attribute variable 1344 gl.enableVertexAttribArray(a_Position); // Open the attribute variable (connect a Position variable to the buffer object assigned to it) 1345 let a_TexCoord = gl.getAttribLocation(program, 'a_TexCoord'); // gets the address of the attribute variable 1346 gl.vertexAttribPointer(a_TexCoord, 2, gl.FLOAT, false, FSIZE * 4, FSIZE * 2); // assign the buffer object to an attribute variable 1347 gl.enableVertexAttribArray(a_TexCoord); // Open the attribute variable (connect a Position variable to the buffer object assigned to it) 1348 let u_Sampler = gl.getUniformLocation(program, 'u_Sampler'); 1349 let texture = gl.createTexture(); 1350 gl.activeTexture(gl.TEXTURE0); // open texture unit 0 1351 gl.bindTexture(gl.TEXTURE_2D, texture); // bind the texture object to target 1352 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // configure texture parameters 1353 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // configure texture parameters 1354 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // configure texture parameters 1355 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // configure texture parameters 1356 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 8, 8, 0, gl.RGBA, gl.UNSIGNED_BYTE, image, 0); // configure texture images 1357 callback(image); 1358 gl.uniform1i(u_Sampler, 0); // pass texture 0 to the shader 1359 gl.clearColor(0.92, 0.92, 0.92, 1); 1360 gl.clear(gl.COLOR_BUFFER_BIT); 1361 gl.drawArrays(gl.TRIANGLE_STRIP, 0, arr.length / 4); 1362 let res = new Uint8Array(8 * 8 * 4); 1363 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, res); 1364 finish(res); 1365 gl.flush(); 1366 gl.disableVertexAttribArray(a_Position); 1367 gl.disableVertexAttribArray(a_TexCoord); 1368 gl.bindTexture(gl.TEXTURE_2D, null); 1369 gl.bindBuffer(gl.ARRAY_BUFFER, null); 1370 gl.deleteBuffer(buffer); 1371 gl.deleteTexture(texture); 1372 gl.deleteShader(vertexShader); 1373 gl.deleteShader(fragmentShader); 1374 gl.deleteProgram(program); 1375 } 1376 /** 1377 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0044 1378 * @tc.name webgl2_test_texSubImage2D 1379 * @tc.desc Test texSubImage2D. 1380 */ 1381 it('webgl2_test_texSubImage2D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1382 console.info("webgl2test [webgl2_test_texSubImage2D] texSubImage2D"); 1383 texSubImage2D((image) => { 1384 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1385 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1386 }, (res) => { 1387 expect(res[0]).assertEqual(255); 1388 expect(res[1]).assertEqual(255); 1389 expect(res[2]).assertEqual(0); 1390 expect(res[3]).assertEqual(255); 1391 expect(checkError(gl)).assertEqual(gl.NO_ERROR); 1392 }); 1393 done(); 1394 }); 1395 /** 1396 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0045 1397 * @tc.name webgl2_test_texSubImage2D_1 1398 * @tc.desc Test texSubImage2D. 1399 */ 1400 it('webgl2_test_texSubImage2D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1401 console.info("webgl2test [webgl2_test_texSubImage2D_1] texSubImage2D"); 1402 texSubImage2D((image) => { 1403 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1404 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1405 }, (res) => { 1406 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1407 }); 1408 done(); 1409 }); 1410 /** 1411 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0046 1412 * @tc.name webgl2_test_texSubImage2D_2 1413 * @tc.desc Test texSubImage2D. 1414 */ 1415 it('webgl2_test_texSubImage2D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1416 console.info("webgl2test [webgl2_test_texSubImage2D_2] texSubImage2D"); 1417 texSubImage2D((image) => { 1418 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1419 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1420 }, (res) => { 1421 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1422 }); 1423 done(); 1424 }); 1425 /** 1426 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0047 1427 * @tc.name webgl2_test_texSubImage2D_3 1428 * @tc.desc Test texSubImage2D. 1429 */ 1430 it('webgl2_test_texSubImage2D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1431 console.info("webgl2test [webgl2_test_texSubImage2D_3] texSubImage2D"); 1432 texSubImage2D((image) => { 1433 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1434 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1435 }, (res) => { 1436 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1437 }); 1438 done(); 1439 }); 1440 /** 1441 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0048 1442 * @tc.name webgl2_test_texSubImage2D_4 1443 * @tc.desc Test texSubImage2D. 1444 */ 1445 it('webgl2_test_texSubImage2D_4', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1446 console.info("webgl2test [webgl2_test_texSubImage2D_4] texSubImage2D"); 1447 texSubImage2D((image) => { 1448 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1449 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1450 }, (res) => { 1451 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1452 }); 1453 done(); 1454 }); 1455 /** 1456 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0049 1457 * @tc.name webgl2_test_texSubImage2D_5 1458 * @tc.desc Test texSubImage2D. 1459 */ 1460 it('webgl2_test_texSubImage2D_5', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1461 console.info("webgl2test [webgl2_test_texSubImage2D_5] texSubImage2D"); 1462 texSubImage2D((image) => { 1463 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1464 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1465 }, (res) => { 1466 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1467 }); 1468 done(); 1469 }); 1470 /** 1471 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0050 1472 * @tc.name webgl2_test_texSubImage2D_6 1473 * @tc.desc Test texSubImage2D. 1474 */ 1475 it('webgl2_test_texSubImage2D_6', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1476 console.info("webgl2test [webgl2_test_texSubImage2D_6] texSubImage2D"); 1477 texSubImage2D((image) => { 1478 let newData = getColorUint8Array(4, 4, 255, 255, 0, 255); 1479 gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 0, 0, 4, 2, gl.RGBA, gl.UNSIGNED_BYTE, newData, 8); 1480 }, (res) => { 1481 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1482 }); 1483 done(); 1484 }); 1485 function compressedTexImage2D(callback, finish) { 1486 let texture = gl.createTexture(); 1487 gl.bindTexture(gl.TEXTURE_2D, texture); 1488 console.log(gl.getSupportedExtensions()); 1489 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1490 callback(); 1491 finish(); 1492 gl.deleteTexture(texture); 1493 } 1494 /** 1495 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0051 1496 * @tc.name webgl2_test_compressedTexImage2D 1497 * @tc.desc Test compressedTexImage2D. 1498 */ 1499 it('webgl2_test_compressedTexImage2D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1500 async function (done) { 1501 console.info("webgl2test [webgl2_test_compressedTexImage2D] compressedTexImage2D"); 1502 let texture = gl.createTexture(); 1503 gl.bindTexture(gl.TEXTURE_2D, texture); 1504 console.log(gl.getSupportedExtensions()); 1505 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1506 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1507 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1508 gl.deleteTexture(texture); 1509 done(); 1510 }); 1511 /** 1512 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0052 1513 * @tc.name webgl2_test_compressedTexImage2D_1 1514 * @tc.desc Test compressedTexImage2D. 1515 */ 1516 it('webgl2_test_compressedTexImage2D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1517 async function (done) { 1518 console.info("webgl2test [webgl2_test_compressedTexImage2D_1] compressedTexImage2D"); 1519 compressedTexImage2D(() => { 1520 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1521 }, () => { 1522 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1523 }); 1524 done(); 1525 }); 1526 /** 1527 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0053 1528 * @tc.name webgl2_test_compressedTexImage2D_2 1529 * @tc.desc Test compressedTexImage2D. 1530 */ 1531 it('webgl2_test_compressedTexImage2D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1532 async function (done) { 1533 console.info("webgl2test [webgl2_test_compressedTexImage2D_2] compressedTexImage2D"); 1534 compressedTexImage2D(() => { 1535 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 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_0054 1543 * @tc.name webgl2_test_compressedTexImage2D_3 1544 * @tc.desc Test compressedTexImage2D. 1545 */ 1546 it('webgl2_test_compressedTexImage2D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1547 async function (done) { 1548 console.info("webgl2test [webgl2_test_compressedTexImage2D_3] compressedTexImage2D"); 1549 compressedTexImage2D(() => { 1550 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1551 }, () => { 1552 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1553 }); 1554 done(); 1555 }); 1556 /** 1557 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0055 1558 * @tc.name webgl2_test_compressedTexImage2D_4 1559 * @tc.desc Test compressedTexImage2D. 1560 */ 1561 it('webgl2_test_compressedTexImage2D_4', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1562 async function (done) { 1563 console.info("webgl2test [webgl2_test_compressedTexImage2D_4] compressedTexImage2D"); 1564 compressedTexImage2D(() => { 1565 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1566 }, () => { 1567 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1568 }); 1569 done(); 1570 }); 1571 /** 1572 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0056 1573 * @tc.name webgl2_test_compressedTexImage2D_5 1574 * @tc.desc Test compressedTexImage2D. 1575 */ 1576 it('webgl2_test_compressedTexImage2D_5', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1577 async function (done) { 1578 console.info("webgl2test [webgl2_test_compressedTexImage2D_5] compressedTexImage2D"); 1579 compressedTexImage2D(() => { 1580 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1581 }, () => { 1582 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1583 }); 1584 done(); 1585 }); 1586 /** 1587 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0057 1588 * @tc.name webgl2_test_compressedTexImage2D_6 1589 * @tc.desc Test compressedTexImage2D. 1590 */ 1591 it('webgl2_test_compressedTexImage2D_6', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1592 async function (done) { 1593 console.info("webgl2test [webgl2_test_compressedTexImage2D_6] compressedTexImage2D"); 1594 compressedTexImage2D(() => { 1595 gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1596 }, () => { 1597 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1598 }); 1599 done(); 1600 }); 1601 function compressedTexSubImage2D(callback, finish) { 1602 let texture = gl.createTexture(); 1603 gl.bindTexture(gl.TEXTURE_2D, texture); 1604 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1605 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1606 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1607 callback(); 1608 finish(); 1609 gl.deleteTexture(texture); 1610 } 1611 /** 1612 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0058 1613 * @tc.name webgl2_test_compressedTexSubImage2D 1614 * @tc.desc Test compressedTexSubImage2D. 1615 */ 1616 it('webgl2_test_compressedTexSubImage2D', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1617 async function (done) { 1618 console.info("webgl2test [webgl2_test_compressedTexSubImage2D] compressedTexSubImage2D"); 1619 let texture = gl.createTexture(); 1620 gl.bindTexture(gl.TEXTURE_2D, texture); 1621 console.log(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS)); 1622 gl.compressedTexImage2D(gl.TEXTURE_2D, 0, gl.COMPRESSED_TEXTURE_FORMATS, 1, 1, 0, new Float32Array(1 * 1 * 4)); 1623 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1624 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1625 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1626 gl.deleteTexture(texture); 1627 done(); 1628 }); 1629 /** 1630 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0059 1631 * @tc.name webgl2_test_compressedTexSubImage2D_1 1632 * @tc.desc Test compressedTexSubImage2D. 1633 */ 1634 it('webgl2_test_compressedTexSubImage2D_1', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1635 async function (done) { 1636 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_1] compressedTexSubImage2D"); 1637 compressedTexSubImage2D(() => { 1638 gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1639 }, () => { 1640 expect(checkError(gl)).assertEqual(gl.INVALID_ENUM); 1641 }); 1642 done(); 1643 }); 1644 /** 1645 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0060 1646 * @tc.name webgl2_test_compressedTexSubImage2D_2 1647 * @tc.desc Test compressedTexSubImage2D. 1648 */ 1649 it('webgl2_test_compressedTexSubImage2D_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1650 async function (done) { 1651 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_2] compressedTexSubImage2D"); 1652 compressedTexSubImage2D(() => { 1653 gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1654 }, () => { 1655 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1656 }); 1657 done(); 1658 }); 1659 /** 1660 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0061 1661 * @tc.name webgl2_test_compressedTexSubImage2D_3 1662 * @tc.desc Test compressedTexSubImage2D. 1663 */ 1664 it('webgl2_test_compressedTexSubImage2D_3', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1665 async function (done) { 1666 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_3] compressedTexSubImage2D"); 1667 compressedTexSubImage2D(() => { 1668 gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1669 }, () => { 1670 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1671 }); 1672 done(); 1673 }); 1674 /** 1675 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0062 1676 * @tc.name webgl2_test_compressedTexSubImage2D_4 1677 * @tc.desc Test compressedTexSubImage2D. 1678 */ 1679 it('webgl2_test_compressedTexSubImage2D_4', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1680 async function (done) { 1681 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_4] compressedTexSubImage2D"); 1682 compressedTexSubImage2D(() => { 1683 gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1684 }, () => { 1685 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1686 }); 1687 done(); 1688 }); 1689 /** 1690 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0063 1691 * @tc.name webgl2_test_compressedTexSubImage2D_5 1692 * @tc.desc Test compressedTexSubImage2D. 1693 */ 1694 it('webgl2_test_compressedTexSubImage2D_5', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1695 async function (done) { 1696 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_5] compressedTexSubImage2D"); 1697 compressedTexSubImage2D(() => { 1698 gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1699 }, () => { 1700 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1701 }); 1702 done(); 1703 }); 1704 /** 1705 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0064 1706 * @tc.name webgl2_test_compressedTexSubImage2D_6 1707 * @tc.desc Test compressedTexSubImage2D. 1708 */ 1709 it('webgl2_test_compressedTexSubImage2D_6', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, 1710 async function (done) { 1711 console.info("webgl2test [webgl2_test_compressedTexSubImage2D_6] compressedTexSubImage2D"); 1712 compressedTexSubImage2D(() => { 1713 gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 0, 0, 1, 1, gl.COMPRESSED_TEXTURE_FORMATS, new Float32Array(4), 0, 1); 1714 }, () => { 1715 expect(checkError(gl)).assertEqual(gl.INVALID_OPERATION); 1716 }); 1717 done(); 1718 }); 1719 /** 1720 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0065 1721 * @tc.name webgl2_test_readPixels 1722 * @tc.desc Test readPixels. 1723 */ 1724 it('webgl2_test_readPixels', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1725 console.info("webgl2test [webgl2_test_readPixels] readPixels"); 1726 let srcViewport = gl.getParameter(gl.VIEWPORT); 1727 let p = createProgram(gl, `#version 300 es 1728 in vec4 a_position; 1729 in vec3 a_color; 1730 out vec3 v_color; 1731 void main(){ 1732 gl_Position = a_position; 1733 gl_PointSize = 1.0; 1734 v_color = a_color; 1735 } 1736 `, `#version 300 es 1737 precision mediump float; 1738 in vec3 v_color; 1739 out vec4 color; 1740 void main(){ 1741 color = vec4(v_color,1.0); 1742 } 1743 `); 1744 let source = new Float32Array([ 1745 -0.5, -0.5, 1.0, 0.0, 0.0, 1746 0.5, -0.5, 0.0, 0.0, 0.0, 1747 -0.5, 0.5, 0.0, 1.0, 0.0, 1748 0.5, 0.5, 0.0, 0.0, 1.0, 1749 ]); 1750 let num = 4; 1751 let FSIZE = source.BYTES_PER_ELEMENT; 1752 let buffer = gl.createBuffer(); 1753 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1754 gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_READ, 0, 20); 1755 expect(checkError(gl)).assertEqual(gl.NO_ERROR); 1756 let a_position = gl.getAttribLocation(p.program, 'a_position'); 1757 gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 5 * FSIZE, 0); 1758 gl.enableVertexAttribArray(a_position); 1759 let a_color = gl.getAttribLocation(p.program, 'a_color'); 1760 gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 5 * FSIZE, 2 * FSIZE); 1761 gl.enableVertexAttribArray(a_color); 1762 gl.clearColor(0, 0, 0, 1.0); 1763 gl.clear(gl.COLOR_BUFFER_BIT); 1764 gl.viewport(0, 0, 2, 2); 1765 gl.drawArrays(gl.POINTS, 0, 4); 1766 let result = new Uint8Array(2 * 2 * 4 + 4); 1767 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, result, 4); 1768 console.info("webgltest ", result); 1769 expect(result[0]).assertEqual(0); 1770 expect(result[1]).assertEqual(0); 1771 expect(result[2]).assertEqual(0); 1772 expect(result[3]).assertEqual(0); 1773 expect(result[4]).assertEqual(255); 1774 expect(result[5]).assertEqual(0); 1775 expect(result[6]).assertEqual(0); 1776 expect(result[7]).assertEqual(255); 1777 gl.deleteBuffer(buffer); 1778 gl.deleteShader(p.vertexShader); 1779 gl.deleteShader(p.fragmentShader); 1780 gl.deleteProgram(p.program); 1781 gl.disableVertexAttribArray(a_color); 1782 gl.disableVertexAttribArray(a_position); 1783 gl.viewport(srcViewport[0], srcViewport[1], srcViewport[2], srcViewport[3]); 1784 checkError(gl); 1785 done(); 1786 }); 1787 /** 1788 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TEXTURE_0066 1789 * @tc.name webgl2_test_readPixels_2 1790 * @tc.desc Test readPixels. 1791 */ 1792 it('webgl2_test_readPixels_2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 1793 console.info("webgl2test [webgl2_test_readPixels_2] readPixels"); 1794 let srcViewport = gl.getParameter(gl.VIEWPORT); 1795 let p = createProgram(gl, `#version 300 es 1796 in vec4 a_position; 1797 in vec3 a_color; 1798 out vec3 v_color; 1799 void main(){ 1800 gl_Position = a_position; 1801 gl_PointSize = 1.0; 1802 v_color = a_color; 1803 } 1804 `, `#version 300 es 1805 precision mediump float; 1806 in vec3 v_color; 1807 out vec4 color; 1808 void main(){ 1809 color = vec4(v_color,1.0); 1810 } 1811 `); 1812 let source = new Float32Array([ 1813 -0.5, -0.5, 1.0, 0.0, 0.0, 1814 0.5, -0.5, 0.0, 0.0, 0.0, 1815 -0.5, 0.5, 0.0, 1.0, 0.0, 1816 0.5, 0.5, 0.0, 0.0, 1.0, 1817 ]); 1818 let num = 4; 1819 let FSIZE = source.BYTES_PER_ELEMENT; 1820 let buffer = gl.createBuffer(); 1821 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1822 gl.bufferData(gl.ARRAY_BUFFER, source, gl.STATIC_READ, 0, 20); 1823 expect(checkError(gl)).assertEqual(gl.NO_ERROR); 1824 let a_position = gl.getAttribLocation(p.program, 'a_position'); 1825 gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 5 * FSIZE, 0); 1826 gl.enableVertexAttribArray(a_position); 1827 let a_color = gl.getAttribLocation(p.program, 'a_color'); 1828 gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 5 * FSIZE, 2 * FSIZE); 1829 gl.enableVertexAttribArray(a_color); 1830 gl.clearColor(0, 0, 0, 1.0); 1831 gl.clear(gl.COLOR_BUFFER_BIT); 1832 gl.viewport(0, 0, 2, 2); 1833 gl.drawArrays(gl.POINTS, 0, 4); 1834 let result = new Uint8Array(2 * 2 * 4); 1835 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, result); 1836 console.info("webgltest ", result); 1837 expect(result[0]).assertEqual(255); 1838 expect(result[1]).assertEqual(0); 1839 expect(result[2]).assertEqual(0); 1840 expect(result[3]).assertEqual(255); 1841 expect(result[4]).assertEqual(0); 1842 expect(result[5]).assertEqual(0); 1843 expect(result[6]).assertEqual(0); 1844 expect(result[7]).assertEqual(255); 1845 gl.deleteBuffer(buffer); 1846 gl.deleteShader(p.vertexShader); 1847 gl.deleteShader(p.fragmentShader); 1848 gl.deleteProgram(p.program); 1849 gl.disableVertexAttribArray(a_color); 1850 gl.disableVertexAttribArray(a_position); 1851 gl.viewport(srcViewport[0], srcViewport[1], srcViewport[2], srcViewport[3]); 1852 checkError(gl); 1853 done(); 1854 }); 1855 }) 1856} 1857