WebGL.test14.js 32.2 KB
Newer Older
M
muppets 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import app from '@system.app'
import Context from '@ohos.napi_context'

import {
	describe,
	beforeAll,
	beforeEach,
	afterEach,
	afterAll,
	it,
	expect
} from 'deccjsunit/index'

describe('webgl1Test', function() {
	console.info('webgltest start');
	var gl;
	var gl2;

	var indices = new Uint16Array([0, 1, 2, 1, 3, 4]);
	var vertices = new Uint16Array([
		-0.5, 0.5, 0.0,
		0.0, 0.5, 0.0,
		-0.25, 0.25, 0.0,
		0.5, 0.5, 0.0,
		0.25, 0.25, 0.0,
	])

	//顶点着色器程序
	var VSHADER_SOURCE =
		"attribute vec4 a_Position;" +
		"void main() {" +
		//设置坐标
		"gl_Position = a_Position; " +
		//    "gl_PointSize = 10.0;" +
		"} ";

	//片元着色器
	var FSHADER_SOURCE =
		"void main() {" +
		//设置颜色
		"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);" +
		"}";

	function globalFunction() {
		const vertexShader = gl.createShader(gl.VERTEX_SHADER);
		gl.shaderSource(vertexShader, VSHADER_SOURCE);
		gl.compileShader(vertexShader);
		const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
		gl.shaderSource(fragmentShader, FSHADER_SOURCE);
		gl.compileShader(fragmentShader);
		const programObj = gl.createProgram();
		console.info("testUseProgram has failed for " + programObj)
		const useProgramError1 = gl.getError();
		console.info("useProgramError: " + useProgramError1);
		const renderBufferValue1 = gl.getParameter(gl.CURRENT_PROGRAM);
		console.info("testUseProgram has failed for " + renderBufferValue1)
		gl.attachShader(programObj, vertexShader);
		gl.attachShader(programObj, fragmentShader);
		gl.linkProgram(programObj);
		gl.useProgram(programObj);
		return programObj;
	}


	function createProgram(gl) {
		//顶点着色器程序
		var VSHADER_SOURCE =
			'attribute vec4 a_Position;\n' +
			'void main() {\n' +
			'  gl_Position = a_Position;\n' +
			'}\n';

		// 片元着色器程序
		var FSHADER_SOURCE =
			'precision mediump float;\n' +
			'uniform vec4 u_FragColor;\n' +
			'void main() {\n' +
			'  gl_FragColor = u_FragColor;\n' +
			'}\n';
		var vertexShader = gl.createShader(gl.VERTEX_SHADER);
		gl.shaderSource(vertexShader, VSHADER_SOURCE);
		gl.compileShader(vertexShader);
		var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
		gl.shaderSource(fragmentShader, FSHADER_SOURCE);
		gl.compileShader(fragmentShader);
		const programObj = gl.createProgram();
		console.log("testUseProgram has failed for " + programObj)
		const useProgramError1 = gl.getError();
		console.info("useProgramError: " + useProgramError1);
		const renderBufferValue1 = gl.getParameter(gl.CURRENT_PROGRAM);
		console.log("testUseProgram has failed for " + renderBufferValue1)
		gl.attachShader(programObj, vertexShader);
		gl.attachShader(programObj, fragmentShader);
		gl.linkProgram(programObj);
		gl.useProgram(programObj);
		return programObj;
	}

	function initShaders(gl, vshader, fshader) {
		var program = createProgramExternal(gl, vshader, fshader);
		console.log("======createProgram program: " + JSON.stringify(program));

		if (!program) {
			console.log('Failed to create program');
			return false;
		}

		gl.useProgram(program);
		gl.program = program;

		return true;
	}

	function createProgramExternal(gl, vshader, fshader) {
		// Create shader object
		var vertexShader = loadShader(gl, gl.VERTEX_SHADER, vshader);
		console.log("======vertexShader: " + vertexShader);
		var fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, fshader);
		if (!vertexShader || !fragmentShader) {
			return null;
		}

		// Create a program object
		var program = gl.createProgram();
		console.log("======createProgram program: " + JSON.stringify(program));

		if (!program) {
			return null;
		}

		// Attach the shader objects
		gl.attachShader(program, vertexShader);
		gl.attachShader(program, fragmentShader);

		// Link the program object
		gl.linkProgram(program);

		// Check the result of linking
		var linked = gl.getProgramParameter(program, 0x8B82);
		console.log("======getProgramParameter linked: " + linked);

		const getUniformLocationValue = gl.getUniformLocation(program, "a_Position");
		console.log("======getUniformLocation: " + JSON.stringify(getUniformLocationValue));


		if (!linked) {
			var error = gl.getProgramInfoLog(program);
			console.log('Failed to link program: ' + error);
			gl.deleteProgram(program);
			gl.deleteShader(fragmentShader);
			gl.deleteShader(vertexShader);
			return null;
		}

		return program;
	}

	function loadShader(gl, type, source) {
		console.log("======into loadShader====");
		// Create shader object
		var shader = gl.createShader(type);
		if (shader == null) {
			console.log('unable to create shader');
			return null;
		}

		const isShaderValue = gl.isShader(shader);
		console.log('isShader: ' + isShaderValue);

		// Set the shader program
		gl.shaderSource(shader, source);

		// Compile the shader
		gl.compileShader(shader);

		// Check the result of compilation
		var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
		if (!compiled) {
			var error = gl.getShaderInfoLog(shader);
			console.log('Failed to compile shader: ' + error);
			gl.deleteShader(shader);
			return null;
		}

		var vertex = gl.getShaderParameter(shader, gl.VERTEX_SHADER);
		console.log('getShaderParameter VERTEX_SHADER: ' + vertex);


		return shader;
	}

	function initVertexBuffers(gl) {
		var vertices = new Float32Array([
			0.0, -1.0, -0.5, 0, 0.5, 0
		]);

		var n = 3; // 点的个数

		// 创建缓冲区对象
		var vertexBuffer = gl.createBuffer();
		if (!vertexBuffer) {
			console.log('Failed to create the buffer object');
			return -1;
		}

		// 将缓冲区对象绑定到目标
		gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
		// 向缓冲区对象写入数据
		gl.bufferData(gl.ARRAY_BUFFER, vertices.buffer, gl.STATIC_DRAW);

		var aPosition = gl.getAttribLocation(gl.program, 'a_Position');
		console.info("webgl# getAttribLocation getAttribLocation success:" + JSON.stringify(gl.program));
		console.info("webgl# getAttribLocation getAttribLocation success:" + aPosition);
		if (aPosition < 0) {
			console.log('Failed to get the storage location of a_Position');
			return -1;
		}
		// 将缓冲区对象分配给a_Position变量
		gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);

		// 连接a_Position变量与分配给它的缓冲区对象
		gl.enableVertexAttribArray(aPosition);

		return n;
	}


	var float1 = new Float32Array([1.1, 1.2, 1.3, 1.4]);
	var int1 = new Int8Array([1, 1, 1, 1]);
	var uint1 = new Uint8Array([1, 1, 1, 1]);
	var float2 = [1.1, 1.2, 1.3, 1.4];
	var int2 = [1, 1, 1, 1];
	var uint2 = [1, 1, 1, 1];

	function initContext() {
		console.info('initContext start');
		// 获取canvas元素
		const el = global.el;
		const el2 = global.el2;
		// 获取webgl上下文
		gl = el.getContext('webgl');
		if (!gl) {
			console.log('webgltest Failed to get the rendering context for WebGL');
		}
		gl2 = el2.getContext('webgl2');
		if (!gl) {
			console.log('webgltest Failed to get the rendering context for WebGL2');
		}
		console.info('webgltest initContext finish');
	}

	function deleteContext() {
		if (gl != null) {
			gl = null;
			console.info("webgltest gl has null");
		}
		if (gl2 != null) {
			console.info("webgltest gl2 has null");
			gl2 = null;
		}
	}

	/**
	 * run before testClass
	 */
	beforeAll(async function(done) {
		console.info('webgltest beforeAll called');
		initContext();
		done();
	});

	/**
	 * run after testClass
	 */
	afterAll(async function(done) {
		console.info('webgltest afterEach called');
		deleteContext();
		done();
	})


	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1301
	 * @tc.name testGetFramebufferAttachmentParameter3_11
	 * @tc.desc Test getFramebufferAttachmentParameter.
	 */
	it('testGetFramebufferAttachmentParameter3_11', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getFramebufferAttachmentParameter test start ...' + JSON.stringify(
			gl));
		const renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER,
			renderBuffer);
		const framebuffer = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl
			.DEPTH_STENCIL_ATTACHMENT,
			gl2.FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER);
		console.info('Framebuffer' + framebuffer);
		const errorCode = gl.getError();
		console.info("jsWebGL getFramebufferAttachmentParameter errorCode: " + errorCode);
		expect(errorCode).assertEqual(gl.INVALID_OPERATION);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1302
	 * @tc.name testGetFramebufferAttachmentParameter3_12
	 * @tc.desc Test getFramebufferAttachmentParameter.
	 */
	it('testGetFramebufferAttachmentParameter3_12', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getFramebufferAttachmentParameter test start ...' + JSON.stringify(
			gl));
		const renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER,
			renderBuffer);
		const framebuffer = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl
			.DEPTH_STENCIL_ATTACHMENT,
			gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL);
		console.info('Framebuffer' + framebuffer);
		const errorCode = gl.getError();
		console.info("jsWebGL getFramebufferAttachmentParameter errorCode: " + errorCode);
		expect(errorCode).assertEqual(gl.INVALID_OPERATION);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1303
	 * @tc.name testGetFramebufferAttachmentParameter3_13
	 * @tc.desc Test getFramebufferAttachmentParameter.
	 */
	it('testGetFramebufferAttachmentParameter3_13', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getFramebufferAttachmentParameter test start ...' + JSON.stringify(
			gl));
		const renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER,
			renderBuffer);
		const framebuffer = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl
			.DEPTH_STENCIL_ATTACHMENT,
			gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE);
		console.info('Framebuffer' + framebuffer);
		const errorCode = gl.getError();
		console.info("jsWebGL getFramebufferAttachmentParameter errorCode: " + errorCode);
		expect(errorCode).assertEqual(gl.INVALID_OPERATION);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1304
	 * @tc.name testGetFramebufferAttachmentParameter3_14
	 * @tc.desc Test getFramebufferAttachmentParameter.
	 */
	it('testGetFramebufferAttachmentParameter3_14', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getFramebufferAttachmentParameter test start ...' + JSON.stringify(
			gl));
		const renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER,
			renderBuffer);
		const framebuffer = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl
			.DEPTH_STENCIL_ATTACHMENT,
			gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE);
		console.info('Framebuffer' + framebuffer);
		const errorCode = gl.getError();
		console.info("jsWebGL getFramebufferAttachmentParameter errorCode: " + errorCode);
		expect(errorCode).assertEqual(gl.INVALID_OPERATION);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1306
	 * @tc.name webgl_test_checkFramebufferStatus2_1
	 * @tc.desc Test checkFramebufferStatus.
	 */
	it('webgl_test_checkFramebufferStatus2_1', 0, async function(done) {
		//initContext();
		console.info("webgltest into checkFramebufferStatus");

		var framebuffer = gl.createFramebuffer();
		gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);

		const checkFramebufferStatus = gl.checkFramebufferStatus(gl2
			.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
		console.info("createFramebuffer --> bindFramebuffer --> checkFramebufferStatus: " +
			checkFramebufferStatus);
		expect(checkFramebufferStatus).assertEqual(0);
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1307
	 * @tc.name webgl_test_checkFramebufferStatus2_2
	 * @tc.desc Test checkFramebufferStatus.
	 */
	it('webgl_test_checkFramebufferStatus2_2', 0, async function(done) {
		//initContext();
		console.info("webgltest into checkFramebufferStatus");

		var framebuffer = gl.createFramebuffer();
		gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);

		const checkFramebufferStatus = gl.checkFramebufferStatus(gl
			.FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
		console.info("createFramebuffer --> bindFramebuffer --> checkFramebufferStatus: " +
			checkFramebufferStatus);
		expect(checkFramebufferStatus).assertEqual(0);
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1308
	 * @tc.name webgl_test_checkFramebufferStatus2_3
	 * @tc.desc Test checkFramebufferStatus.
	 */
	it('webgl_test_checkFramebufferStatus2_3', 0, async function(done) {
		//initContext();
		console.info("webgltest into checkFramebufferStatus");

		var framebuffer = gl.createFramebuffer();
		gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);

		const checkFramebufferStatus = gl.checkFramebufferStatus(gl
			.FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
		console.info("createFramebuffer --> bindFramebuffer --> checkFramebufferStatus: " +
			checkFramebufferStatus);
		expect(checkFramebufferStatus).assertEqual(0);
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1309
	 * @tc.name webgl_test_checkFramebufferStatus2_4
	 * @tc.desc Test checkFramebufferStatus.
	 */
	it('webgl_test_checkFramebufferStatus2_4', 0, async function(done) {
		//initContext();
		console.info("webgltest into checkFramebufferStatus");

		var framebuffer = gl.createFramebuffer();
		gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);

		const checkFramebufferStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER_UNSUPPORTED);
		console.info("createFramebuffer --> bindFramebuffer --> checkFramebufferStatus: " +
			checkFramebufferStatus);
		expect(checkFramebufferStatus).assertEqual(0);
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1310
	 * @tc.name testGetVertexAttribFirst_1
	 * @tc.desc Test getVertexAttrib.
	 */
	it('testGetVertexAttribFirst_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getVertexAttrib test start ...' + JSON.stringify(gl));
		const vertexBuffer = gl.createBuffer();
		gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
		const shaderProgram = globalFunction();
		const aVertexPosition = gl.getAttribLocation(shaderProgram, "a_position");

		gl.enableVertexAttribArray(aVertexPosition);
		gl.vertexAttribPointer(aVertexPosition, 3, gl.FLOAT, false, 20, 0);

		gl.drawArrays(gl.TRIANGLES, 0, 8);
		gl.vertexAttrib1f(0, 2.8);
		const type = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
		console.info("getVertexAttrib: type" + type);
		expect(type.toString()).assertEqual([2.799999952316284, 0, 0, 1].toString());
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1311
	 * @tc.name testGetParameter_webgl_1
	 * @tc.desc Test getParameter.
	 */
	it('testGetParameter_webgl_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getParameter test start ...' + JSON.stringify(gl));
		gl.activeTexture(gl.TEXTURE0);
		var textureParameter = gl.getParameter(gl.BLEND_EQUATION);
		// returns "33984" (0x84C0, gl.TEXTURE0 enum value)
		console.info("activeTexture --> getParameter: " + textureParameter);
		let errorCode = gl.getError();
		console.info("webgltest framebufferRenderbuffer getError: " + errorCode);
		expect(errorCode).assertEqual(1281);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1312
	 * @tc.name testGetParameter_webgl_2
	 * @tc.desc Test getParameter.
	 */
	it('testGetParameter_webgl_2', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getParameter test start ...' + JSON.stringify(gl));
		gl.activeTexture(gl.TEXTURE0);
		var textureParameter = gl.getParameter(gl.DEPTH_BITS);
		// returns "33984" (0x84C0, gl.TEXTURE0 enum value)
		console.info("activeTexture --> getParameter: " + textureParameter);
		let errorCode = gl.getError();
		console.info("webgltest framebufferRenderbuffer getError: " + errorCode);
Z
zleoyu 已提交
527 528 529 530
		// The webgl interface transparently transmits opengl.Therefore, only need to verify the interface does not crash.
		const notCrash = true;
		expect(notCrash).assertTrue();
		for(let err; (err = gl.getError()) != gl.NO_ERROR;) {}
M
muppets 已提交
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1313
	 * @tc.name testGetVertexAttribFirst_2
	 * @tc.desc Test getVertexAttrib.
	 */
	it('testGetVertexAttribFirst_2', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getVertexAttrib test start ...' + JSON.stringify(gl));
		const vertexBuffer = gl.createBuffer();
		gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
		const shaderProgram = globalFunction();
		const aVertexPosition = gl.getAttribLocation(shaderProgram, "a_position");

		gl.enableVertexAttribArray(aVertexPosition);
		gl.vertexAttribPointer(aVertexPosition, 3, gl.FLOAT, false, 20, 0);

		gl.drawArrays(gl.TRIANGLES, 0, 8);
		gl.vertexAttrib1f(0, 2.8);
		const type = gl.getVertexAttrib(0, gl2.VERTEX_ATTRIB_ARRAY_INTEGER);
		console.info("getVertexAttrib: type" + type);
		expect(type).assertEqual(false);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1314
	 * @tc.name testGetVertexAttribFirst_3
	 * @tc.desc Test getVertexAttrib.
	 */
	it('testGetVertexAttribFirst_3', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getVertexAttrib test start ...' + JSON.stringify(gl));
		const vertexBuffer = gl.createBuffer();
		gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
		const shaderProgram = globalFunction();
		const aVertexPosition = gl.getAttribLocation(shaderProgram, "a_position");

		gl.enableVertexAttribArray(aVertexPosition);
		gl.vertexAttribPointer(aVertexPosition, 3, gl.FLOAT, false, 20, 0);

		gl.drawArrays(gl.TRIANGLES, 0, 8);
		gl.vertexAttrib1f(0, 2.8);
		const type = gl.getVertexAttrib(0, gl2.VERTEX_ATTRIB_ARRAY_DIVISOR);
		console.info("getVertexAttrib: type" + type);
		expect(type).assertEqual(0);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1315
	 * @tc.name testGetTexParameterFirst_1
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameterFirst_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(gl.NEAREST_MIPMAP_NEAREST);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1316
	 * @tc.name testGetTexParameterFirst_2
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameterFirst_2', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(gl.NEAREST_MIPMAP_LINEAR);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1317
	 * @tc.name testGetTexParameterFirst_3
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameterFirst_3', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(gl.LINEAR_MIPMAP_LINEAR);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1318
	 * @tc.name webgl_test_activeTexture_webgl_1
	 * @tc.desc Test activeTexture.
	 */
	it('webgl_test_activeTexture_webgl_1', 0, async function(done) {
		//initContext();
		console.info("webgltest into activeTexture");
		gl.activeTexture(gl.TEXTURE);
		const activeTextureParameter = gl.getParameter(gl.ACTIVE_TEXTURE);
		console.info("webgltest activeTexture --> getParameter: " + activeTextureParameter);
		expect(activeTextureParameter).assertEqual(33984);
		//deleteContext();
		done();
	});


	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1319
	 * @tc.name testGetUniform_11
	 * @tc.desc Test getUniform.
	 */
	it('testGetUniform_11', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getUniform test start ...' + JSON.stringify(gl));
		const programObj = globalFunction();

		const uniformLocation = gl.getUniformLocation(programObj, "a_Position");
		const uniform = gl.getUniform(programObj, uniformLocation);
		let type = [];
		if ((typeof uniform) === 'boolean') {
			type = [gl.BOOL];
		} else if ((typeof uniform) === 'number') {
			type = [gl.SAMPLER_2D, gl.SAMPLER_CUBE];
		} else {
			type = [gl.FLOAT_VEC2, gl.FLOAT_VEC3, gl.FLOAT_VEC4, gl.INT_VEC2, gl.INT_VEC3, gl
				.INT_VEC4, gl.FLOAT_MAT2,
				gl.FLOAT_MAT3, gl.FLOAT_MAT4, gl.BOOL_VEC2, gl.BOOL_VEC3, gl.BOOL_VEC4
			]
		}
		const typeBool = type.length > 0
		console.info('getUniformLocation uniform' + uniform);
		expect(typeBool).assertEqual(true);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1320
	 * @tc.name testGetTexParameterError_1
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameterError_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_2D, gl2.TEXTURE_IMMUTABLE_FORMAT);
		console.info('texParameterfValue' + texParameterValue);
		const type = (texParameterValue === gl2.TEXTURE_IMMUTABLE_FORMAT);
		expect(type).assertEqual(false);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1321
	 * @tc.name testGetTexParameterError_2
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameterError_2', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_2D, gl2.TEXTURE_IMMUTABLE_LEVELS);
		console.info('texParameterfValue' + texParameterValue);
		const type = (texParameterValue === gl2.TEXTURE_IMMUTABLE_LEVELS);
		expect(type).assertEqual(false);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1322
	 * @tc.name testGetUniform_11_1
	 * @tc.desc Test getUniform.
	 */
	it('testGetUniform_11_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getUniform test start ...' + JSON.stringify(gl));
		const programObj = globalFunction();

		const uniformLocation = gl.getUniformLocation(programObj, "a_Position");
		const uniform = gl.getUniform(programObj, uniformLocation);
		let type = [];
		if ((typeof uniform) === 'number') {
			type = [gl2.SIGNED_NORMALIZED, gl2.UNSIGNED_NORMALIZED, gl2.SAMPLER_3D, gl2
				.SAMPLER_2D_SHADOW,
				gl2.SAMPLER_2D_ARRAY, gl2.SAMPLER_2D_ARRAY_SHADOW, gl2.SAMPLER_CUBE_SHADOW, gl2
				.INT_SAMPLER_2D,
				gl2.INT_SAMPLER_3D, gl2.INT_SAMPLER_CUBE, gl2.INT_SAMPLER_2D_ARRAY, gl2
				.UNSIGNED_INT_SAMPLER_2D,
				gl2.UNSIGNED_INT_SAMPLER_3D, gl2.UNSIGNED_INT_SAMPLER_CUBE, gl2
				.UNSIGNED_INT_SAMPLER_2D_ARRAY
			];
		} else {
			type = [gl2.UNSIGNED_INT_VEC2, gl2.UNSIGNED_INT_VEC3,
				gl2.UNSIGNED_INT_VEC4, gl2.FLOAT_MAT2x3, gl2.FLOAT_MAT2x4, gl2.FLOAT_MAT3x2, gl2
				.FLOAT_MAT3x4,
				gl2.FLOAT_MAT4x2, gl2.FLOAT_MAT4x3, gl.BOOL_VEC2, gl.BOOL_VEC3, gl.BOOL_VEC4
			]
		}
		const typeBool = type.length > 0
		console.info('getUniformLocation uniform' + uniform);
		expect(typeBool).assertEqual(true);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1323
	 * @tc.name testTexImage3D_INT_2_10_10_10_REV
	 * @tc.desc Test testTexImage3D.
	 */
	it('testTexImage3D_INT_2_10_10_10_REV', 0, async function(done) {
		//initContext();
		try {
			console.info('jsWebGL testTexImage3D test start ...66');
			console.info('jsWebGL testTexImage3D test start ...' + JSON.stringify(gl));
			gl2.texImage3D(gl2.TEXTURE_3D, 0, gl2.SRGB8_ALPHA8, 1, 1, 1, 0, gl.RGBA, gl2
				.INT_2_10_10_10_REV, 0);
			const texImage3DError = gl.getError();
			console.info("texImage3DError: " + texImage3DError);
			expect(texImage3DError).assertEqual(gl.INVALID_ENUM);
			//deleteContext();
			done();
		} catch (e) {
			console.log("testTexImage3D has failed for " + e)
			expect(null).assertFail()
		}
	})

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1324
	 * @tc.name testTexImage2D2_1
	 * @tc.desc Test texImage2D.
	 */
	it('testTexImage2D2_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL2 texImage2D test start ...' + JSON.stringify(gl2));
		gl2.texImage2D(gl2.TEXTURE_2D, 0, gl2.SRGB, 512, 512, 0, gl.RGB, gl.UNSIGNED_BYTE, 0);
		const errorCode = gl.getError();
		console.info("webgl2test texImage2D getError: " + errorCode);
		expect(errorCode).assertEqual(gl.NO_ERROR);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1325
	 * @tc.name testGetTexParameter3_1
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameter3_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(gl.REPEAT);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1326
	 * @tc.name testGetTexParameter3_2
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameter3_2', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(10497);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1327
	 * @tc.name testGetTexParameter3_3
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameter3_3', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(10497);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1328
	 * @tc.name webgl_test_clearBufferfv_22
	 * @tc.desc Test clearBufferfv.
	 */
	it('webgl_test_clearBufferfv_22', 0, async function(done) {
		//initContext();
		console.info("webgltest into clearBufferfv");

		gl2.clearBufferfv(gl2.INVALID_INDEX, 0, [0.0, 0.0, 0.0, 0.0]);

		let errorCode = gl.getError();
		console.info("webgltest webgl_test_clearBufferfv getError: " + errorCode);
Z
zleoyu 已提交
835 836
		expect(errorCode).assertLarger(gl.NO_ERROR);
		for(let err; (err = gl.getError()) != gl.NO_ERROR;) {}
M
muppets 已提交
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1329
	 * @tc.name testGetFramebufferAttachmentParameter3_10_1
	 * @tc.desc Test getFramebufferAttachmentParameter.
	 */
	it('testGetFramebufferAttachmentParameter3_10_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getFramebufferAttachmentParameter test start ...' + JSON.stringify(
			gl));
		const renderBuffer = gl.createRenderbuffer();
		gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
		gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER,
			renderBuffer);
		const framebuffer = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl
			.DEPTH_STENCIL_ATTACHMENT,
			gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE);
		console.info('Framebuffer' + framebuffer);
		const errorCode = gl.getError();
		const type = (errorCode === gl.OUT_OF_MEMORY)
		console.info("jsWebGL getFramebufferAttachmentParameter errorCode: " + errorCode);
		expect(type).assertEqual(false);
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1330
	 * @tc.name testGetParameter_20_1
	 * @tc.desc Test getParameter.
	 */
	it('testGetParameter_20_1', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getParameter test start ...' + JSON.stringify(gl));
		gl.activeTexture(gl.TEXTURE0);
		var textureParameter = gl.getParameter(gl.BROWSER_DEFAULT_WEBGL);
		console.info("activeTexture --> getParameter: " + textureParameter);
		let errorCode = gl.getError();
		console.info("webgltest framebufferRenderbuffer getError: " + errorCode);
		expect(errorCode).assertEqual(gl.NO_ERROR);
		done();
	});


	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1331
	 * @tc.name webgl_test_clearBufferfv_22
	 * @tc.desc Test clearBufferfv.
	 */
	it('webgl_test_clearBufferfv_22', 0, async function(done) {
		//initContext();
		console.info("webgltest into clearBufferfv");

		gl2.clearBufferfv(gl2.INVALID_INDEX, 0, [0.0, 0.0, 0.0, 0.0]);

		let errorCode = gl.getError();
		console.info("webgltest webgl_test_clearBufferfv getError: " + errorCode);
Z
zleoyu 已提交
896 897
		expect(errorCode).assertLarger(gl.NO_ERROR);
		for(let err; (err = gl.getError()) != gl.NO_ERROR;) {}
M
muppets 已提交
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
		//deleteContext();
		done();
	});

	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1332
	 * @tc.name testGetTexParameter3_4
	 * @tc.desc Test getTexParameter.
	 */
	it('testGetTexParameter3_4', 0, async function(done) {
		//initContext();
		console.info('jsWebGL getTexParameter test start ...' + JSON.stringify(gl));
		gl.texParameterf(gl.TEXTURE_2D, gl2.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
		const texParameterValue = gl.getTexParameter(gl.TEXTURE_CUBE_MAP, gl2.TEXTURE_COMPARE_MODE);
		console.info('texParameterfValue' + texParameterValue);
		expect(texParameterValue).assertEqual(gl.COMPARE_REF_TO_TEXTURE);
		done();
	});
	
	/**
	 * @tc.number GRAPHIC_FUNCTION_JS_WEBGL_TESTWEBGL_1337
	 * @tc.name testRendingContextBase
	 * @tc.desc Test RendingContextBase.
	 */
	it('testRendingContextBase', 0, async function(done) {
		console.info('jsWebGL testRendingContextBase test start');
		const buffer = gl.createBuffer();
		expect(typeof(buffer)).assertEqual('object');

		var x1 = gl2.COLOR;
		expect(x1).assertEqual(6144);

		var x2 = gl2.STENCIL;
		expect(x2).assertEqual(6146);

		var x3 = gl2.MIN;
		expect(x3).assertEqual(32775);

		var x4 = gl2.MAX;
		expect(x4).assertEqual(32776);

		var x5 = gl2.RG;
		expect(x5).assertEqual(33319);

		var x6 = gl2.SYNC_CONDITION;
		expect(x6).assertEqual(37139);

		var x7 = gl2.SYNC_STATUS;
		expect(x7).assertEqual(37140);

		var x8 = gl2.SYNC_FLAGS;
		expect(x8).assertEqual(37141);

		done();
	});
})