es3fShaderStateQueryTests.js (86875B)
1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program OpenGL ES Utilities 3 * ------------------------------------------------ 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the 'License'); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an 'AS IS' BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 */ 20 21 'use strict'; 22 goog.provide('functional.gles3.es3fShaderStateQueryTests'); 23 goog.require('framework.common.tcuMatrix'); 24 goog.require('framework.common.tcuTestCase'); 25 goog.require('framework.delibs.debase.deRandom'); 26 goog.require('functional.gles3.es3fApiCase'); 27 goog.require('modules.shared.glsStateQuery'); 28 29 goog.scope(function() { 30 var es3fShaderStateQueryTests = functional.gles3.es3fShaderStateQueryTests; 31 var tcuTestCase = framework.common.tcuTestCase; 32 var glsStateQuery = modules.shared.glsStateQuery; 33 var es3fApiCase = functional.gles3.es3fApiCase; 34 var deRandom = framework.delibs.debase.deRandom; 35 var tcuMatrix = framework.common.tcuMatrix; 36 37 var setParentClass = function(child, parent) { 38 child.prototype = Object.create(parent.prototype); 39 child.prototype.constructor = child; 40 }; 41 42 var commonTestVertSource = '#version 300 es\n' + 43 'void main (void)\n' + 44 '{\n' + 45 ' gl_Position = vec4(0.0);\n' + 46 '}\n'; 47 var commonTestFragSource = '#version 300 es\n' + 48 'layout(location = 0) out mediump vec4 fragColor;\n' + 49 'void main (void)\n' + 50 '{\n' + 51 ' fragColor = vec4(0.0);\n' + 52 '}\n'; 53 54 var brokenShader = '#version 300 es\n' + 55 'broken, this should not compile!\n' + 56 '\n'; 57 58 /** 59 * @constructor 60 * @extends {es3fApiCase.ApiCase} 61 * @param {string} name 62 * @param {string} description 63 */ 64 es3fShaderStateQueryTests.ShaderTypeCase = function(name, description) { 65 es3fApiCase.ApiCase.call(this, name, description, gl); 66 }; 67 68 setParentClass(es3fShaderStateQueryTests.ShaderTypeCase, es3fApiCase.ApiCase); 69 70 es3fShaderStateQueryTests.ShaderTypeCase.prototype.test = function() { 71 var shaderTypes = [gl.VERTEX_SHADER, gl.FRAGMENT_SHADER]; 72 for (var ndx = 0; ndx < shaderTypes.length; ++ndx) { 73 var shader = gl.createShader(shaderTypes[ndx]); 74 var result = glsStateQuery.verifyShader(shader, gl.SHADER_TYPE, shaderTypes[ndx]); 75 this.check(result, 'Incorrect shader type'); 76 gl.deleteShader(shader); 77 } 78 }; 79 80 /** 81 * @constructor 82 * @extends {es3fApiCase.ApiCase} 83 * @param {string} name 84 * @param {string} description 85 */ 86 es3fShaderStateQueryTests.ShaderCompileStatusCase = function(name, description) { 87 es3fApiCase.ApiCase.call(this, name, description, gl); 88 }; 89 90 setParentClass(es3fShaderStateQueryTests.ShaderCompileStatusCase, es3fApiCase.ApiCase); 91 92 es3fShaderStateQueryTests.ShaderCompileStatusCase.prototype.test = function() { 93 var result; 94 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 95 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 96 97 result = glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, false); 98 this.check(result, 'Vertex shader compilation status should be false'); 99 result = glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, false); 100 this.check(result, 'Fragment shader compilation status should be false'); 101 102 gl.shaderSource(shaderVert, commonTestVertSource); 103 gl.shaderSource(shaderFrag, commonTestFragSource); 104 105 gl.compileShader(shaderVert); 106 gl.compileShader(shaderFrag); 107 108 result = glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true); 109 this.check(result, 'Vertex shader compilation status should be true'); 110 result = glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true); 111 this.check(result, 'Fragment shader compilation status should be true'); 112 113 gl.deleteShader(shaderVert); 114 gl.deleteShader(shaderFrag); 115 }; 116 117 /** 118 * @constructor 119 * @extends {es3fApiCase.ApiCase} 120 * @param {string} name 121 * @param {string} description 122 */ 123 es3fShaderStateQueryTests.ShaderInfoLogCase = function(name, description) { 124 es3fApiCase.ApiCase.call(this, name, description, gl); 125 }; 126 127 setParentClass(es3fShaderStateQueryTests.ShaderInfoLogCase, es3fApiCase.ApiCase); 128 129 es3fShaderStateQueryTests.ShaderInfoLogCase.prototype.test = function() { 130 var shader = gl.createShader(gl.VERTEX_SHADER); 131 var log = gl.getShaderInfoLog(shader); 132 this.check(log === ''); 133 134 gl.shaderSource(shader, brokenShader); 135 gl.compileShader(shader); 136 137 log = gl.getShaderInfoLog(shader); 138 this.check(log === null || typeof log === 'string'); 139 140 gl.deleteShader(shader); 141 }; 142 143 /** 144 * @constructor 145 * @extends {es3fApiCase.ApiCase} 146 * @param {string} name 147 * @param {string} description 148 */ 149 es3fShaderStateQueryTests.ShaderSourceCase = function(name, description) { 150 es3fApiCase.ApiCase.call(this, name, description, gl); 151 }; 152 153 setParentClass(es3fShaderStateQueryTests.ShaderSourceCase, es3fApiCase.ApiCase); 154 155 es3fShaderStateQueryTests.ShaderSourceCase.prototype.test = function() { 156 var shader = gl.createShader(gl.VERTEX_SHADER); 157 this.check(gl.getShaderSource(shader) === ''); 158 159 gl.shaderSource(shader, brokenShader); 160 this.check(gl.getShaderSource(shader) === brokenShader); 161 162 gl.deleteShader(shader); 163 }; 164 165 /** 166 * @constructor 167 * @extends {es3fApiCase.ApiCase} 168 * @param {string} name 169 * @param {string} description 170 */ 171 es3fShaderStateQueryTests.DeleteStatusCase = function(name, description) { 172 es3fApiCase.ApiCase.call(this, name, description, gl); 173 }; 174 175 setParentClass(es3fShaderStateQueryTests.DeleteStatusCase, es3fApiCase.ApiCase); 176 177 es3fShaderStateQueryTests.DeleteStatusCase.prototype.test = function() { 178 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 179 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 180 181 gl.shaderSource(shaderVert, commonTestVertSource); 182 gl.shaderSource(shaderFrag, commonTestFragSource); 183 184 gl.compileShader(shaderVert); 185 gl.compileShader(shaderFrag); 186 187 this.check(glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true)); 188 this.check(glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true)); 189 190 var shaderProg = gl.createProgram(); 191 gl.attachShader(shaderProg, shaderVert); 192 gl.attachShader(shaderProg, shaderFrag); 193 gl.linkProgram(shaderProg); 194 195 this.check(glsStateQuery.verifyProgram(shaderProg, gl.LINK_STATUS, true)); 196 197 this.check(glsStateQuery.verifyShader(shaderVert, gl.DELETE_STATUS, false)); 198 this.check(glsStateQuery.verifyShader(shaderFrag, gl.DELETE_STATUS, false)); 199 this.check(glsStateQuery.verifyProgram(shaderProg, gl.DELETE_STATUS, false)); 200 201 gl.useProgram(shaderProg); 202 203 gl.deleteShader(shaderVert); 204 gl.deleteShader(shaderFrag); 205 gl.deleteProgram(shaderProg); 206 207 this.check(glsStateQuery.verifyShader(shaderVert, gl.DELETE_STATUS, true)); 208 this.check(glsStateQuery.verifyShader(shaderFrag, gl.DELETE_STATUS, true)); 209 this.check(glsStateQuery.verifyProgram(shaderProg, gl.DELETE_STATUS, true)); 210 211 gl.useProgram(null); 212 }; 213 214 /** 215 * @constructor 216 * @extends {es3fApiCase.ApiCase} 217 * @param {string} name 218 * @param {string} description 219 */ 220 es3fShaderStateQueryTests.CurrentVertexAttribInitialCase = function(name, description) { 221 es3fApiCase.ApiCase.call(this, name, description, gl); 222 }; 223 224 setParentClass(es3fShaderStateQueryTests.CurrentVertexAttribInitialCase, es3fApiCase.ApiCase); 225 226 es3fShaderStateQueryTests.CurrentVertexAttribInitialCase.prototype.test = function() { 227 var attribute_count = /** @type {number} */ (gl.getParameter(gl.MAX_VERTEX_ATTRIBS)); 228 var initial = new Float32Array([0, 0, 0, 1]); 229 // initial 230 231 for (var index = 0; index < attribute_count; ++index) { 232 var attrib = gl.getVertexAttrib(index, gl.CURRENT_VERTEX_ATTRIB); 233 this.check(glsStateQuery.compare(attrib, initial), 'Initial attrib value should be [0, 0, 0, 1]'); 234 } 235 }; 236 237 /** 238 * @constructor 239 * @extends {es3fApiCase.ApiCase} 240 * @param {string} name 241 * @param {string} description 242 */ 243 es3fShaderStateQueryTests.CurrentVertexAttribFloatCase = function(name, description) { 244 es3fApiCase.ApiCase.call(this, name, description, gl); 245 }; 246 247 setParentClass(es3fShaderStateQueryTests.CurrentVertexAttribFloatCase, es3fApiCase.ApiCase); 248 249 es3fShaderStateQueryTests.CurrentVertexAttribFloatCase.prototype.test = function() { 250 var rnd = new deRandom.Random(0xabcdef); 251 252 var attribute_count = /** @type {number} */ (gl.getParameter(gl.MAX_VERTEX_ATTRIBS)); 253 254 // test write float/read float 255 256 for (var index = 0; index < attribute_count; ++index) { 257 var x = rnd.getFloat(-64000, 64000); 258 var y = rnd.getFloat(-64000, 64000); 259 var z = rnd.getFloat(-64000, 64000); 260 var w = rnd.getFloat(-64000, 64000); 261 262 gl.vertexAttrib4f(index, x, y, z, w); 263 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Float32Array([x, y, z, w]))); 264 } 265 for (var index = 0; index < attribute_count; ++index) { 266 var x = rnd.getFloat(-64000, 64000); 267 var y = rnd.getFloat(-64000, 64000); 268 var z = rnd.getFloat(-64000, 64000); 269 var w = 1.0; 270 271 gl.vertexAttrib3f(index, x, y, z); 272 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Float32Array([x, y, z, w]))); 273 } 274 for (var index = 0; index < attribute_count; ++index) { 275 var x = rnd.getFloat(-64000, 64000); 276 var y = rnd.getFloat(-64000, 64000); 277 var z = 0.0; 278 var w = 1.0; 279 280 gl.vertexAttrib2f(index, x, y); 281 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Float32Array([x, y, z, w]))); 282 } 283 for (var index = 0; index < attribute_count; ++index) { 284 var x = rnd.getFloat(-64000, 64000); 285 var y = 0.0; 286 var z = 0.0; 287 var w = 1.0; 288 289 gl.vertexAttrib1f(index, x); 290 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Float32Array([x, y, z, w]))); 291 } 292 }; 293 294 /** 295 * @constructor 296 * @extends {es3fApiCase.ApiCase} 297 * @param {string} name 298 * @param {string} description 299 */ 300 es3fShaderStateQueryTests.CurrentVertexAttribIntCase = function(name, description) { 301 es3fApiCase.ApiCase.call(this, name, description, gl); 302 }; 303 304 setParentClass(es3fShaderStateQueryTests.CurrentVertexAttribIntCase, es3fApiCase.ApiCase); 305 306 es3fShaderStateQueryTests.CurrentVertexAttribIntCase.prototype.test = function() { 307 var rnd = new deRandom.Random(0xabcdef); 308 309 var attribute_count = /** @type {number} */ (gl.getParameter(gl.MAX_VERTEX_ATTRIBS)); 310 311 // test write float/read float 312 313 for (var index = 0; index < attribute_count; ++index) { 314 var x = rnd.getInt(-64000, 64000); 315 var y = rnd.getInt(-64000, 64000); 316 var z = rnd.getInt(-64000, 64000); 317 var w = rnd.getInt(-64000, 64000); 318 319 gl.vertexAttribI4i(index, x, y, z, w); 320 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Int32Array([x, y, z, w]))); 321 } 322 }; 323 324 /** 325 * @constructor 326 * @extends {es3fApiCase.ApiCase} 327 * @param {string} name 328 * @param {string} description 329 */ 330 es3fShaderStateQueryTests.CurrentVertexAttribUintCase = function(name, description) { 331 es3fApiCase.ApiCase.call(this, name, description, gl); 332 }; 333 334 setParentClass(es3fShaderStateQueryTests.CurrentVertexAttribUintCase, es3fApiCase.ApiCase); 335 336 es3fShaderStateQueryTests.CurrentVertexAttribUintCase.prototype.test = function() { 337 var rnd = new deRandom.Random(0xabcdef); 338 339 var attribute_count = /** @type {number} */ (gl.getParameter(gl.MAX_VERTEX_ATTRIBS)); 340 341 // test write float/read float 342 343 for (var index = 0; index < attribute_count; ++index) { 344 var x = rnd.getInt(0, 64000); 345 var y = rnd.getInt(0, 64000); 346 var z = rnd.getInt(0, 64000); 347 var w = rnd.getInt(0, 64000); 348 349 gl.vertexAttribI4ui(index, x, y, z, w); 350 this.check(glsStateQuery.verifyCurrentVertexAttrib(index, new Uint32Array([x, y, z, w]))); 351 } 352 }; 353 354 /** 355 * @constructor 356 * @extends {es3fApiCase.ApiCase} 357 * @param {string} name 358 * @param {string} description 359 */ 360 es3fShaderStateQueryTests.ProgramInfoLogCase = function(name, description) { 361 es3fApiCase.ApiCase.call(this, name, description, gl); 362 }; 363 364 setParentClass(es3fShaderStateQueryTests.ProgramInfoLogCase, es3fApiCase.ApiCase); 365 366 es3fShaderStateQueryTests.ProgramInfoLogCase.prototype.test = function() { 367 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 368 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 369 370 gl.shaderSource(shaderVert, brokenShader); 371 gl.compileShader(shaderVert); 372 gl.shaderSource(shaderFrag, brokenShader); 373 gl.compileShader(shaderFrag); 374 375 var program = gl.createProgram(); 376 gl.attachShader(program, shaderVert); 377 gl.attachShader(program, shaderFrag); 378 gl.linkProgram(program); 379 380 var log = gl.getProgramInfoLog(program); 381 this.check(log === null || typeof log === 'string'); 382 383 gl.deleteShader(shaderVert); 384 gl.deleteShader(shaderFrag); 385 gl.deleteProgram(program); 386 }; 387 388 /** 389 * @constructor 390 * @extends {es3fApiCase.ApiCase} 391 * @param {string} name 392 * @param {string} description 393 */ 394 es3fShaderStateQueryTests.ProgramValidateStatusCase = function(name, description) { 395 es3fApiCase.ApiCase.call(this, name, description, gl); 396 }; 397 398 setParentClass(es3fShaderStateQueryTests.ProgramValidateStatusCase, es3fApiCase.ApiCase); 399 400 es3fShaderStateQueryTests.ProgramValidateStatusCase.prototype.test = function() { 401 // test validate ok 402 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 403 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 404 405 gl.shaderSource(shaderVert, commonTestVertSource); 406 gl.shaderSource(shaderFrag, commonTestFragSource); 407 408 gl.compileShader(shaderVert); 409 gl.compileShader(shaderFrag); 410 411 var program = gl.createProgram(); 412 gl.attachShader(program, shaderVert); 413 gl.attachShader(program, shaderFrag); 414 gl.linkProgram(program); 415 416 this.check(glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true)); 417 this.check(glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true)); 418 this.check(glsStateQuery.verifyProgram(program, gl.LINK_STATUS, true)); 419 420 gl.validateProgram(program); 421 this.check(glsStateQuery.verifyProgram(program, gl.VALIDATE_STATUS, true)); 422 423 gl.deleteShader(shaderVert); 424 gl.deleteShader(shaderFrag); 425 gl.deleteProgram(program); 426 427 // test with broken shader 428 shaderVert = gl.createShader(gl.VERTEX_SHADER); 429 shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 430 431 gl.shaderSource(shaderVert, commonTestVertSource); 432 gl.shaderSource(shaderFrag, brokenShader); 433 434 gl.compileShader(shaderVert); 435 gl.compileShader(shaderFrag); 436 437 program = gl.createProgram(); 438 gl.attachShader(program, shaderVert); 439 gl.attachShader(program, shaderFrag); 440 gl.linkProgram(program); 441 442 this.check(glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true)); 443 this.check(glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, false)); 444 this.check(glsStateQuery.verifyProgram(program, gl.LINK_STATUS, false)); 445 446 gl.validateProgram(program); 447 this.check(glsStateQuery.verifyProgram(program, gl.VALIDATE_STATUS, false)); 448 449 gl.deleteShader(shaderVert); 450 gl.deleteShader(shaderFrag); 451 gl.deleteProgram(program); 452 }; 453 454 /** 455 * @constructor 456 * @extends {es3fApiCase.ApiCase} 457 * @param {string} name 458 * @param {string} description 459 */ 460 es3fShaderStateQueryTests.ProgramAttachedShadersCase = function(name, description) { 461 es3fApiCase.ApiCase.call(this, name, description, gl); 462 }; 463 464 setParentClass(es3fShaderStateQueryTests.ProgramAttachedShadersCase, es3fApiCase.ApiCase); 465 466 es3fShaderStateQueryTests.ProgramAttachedShadersCase.prototype.test = function() { 467 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 468 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 469 470 gl.shaderSource(shaderVert, commonTestVertSource); 471 gl.shaderSource(shaderFrag, commonTestFragSource); 472 473 gl.compileShader(shaderVert); 474 gl.compileShader(shaderFrag); 475 476 // check ATTACHED_SHADERS 477 478 var program = gl.createProgram(); 479 this.check(glsStateQuery.verifyProgram(program, gl.ATTACHED_SHADERS, 0)); 480 481 gl.attachShader(program, shaderVert); 482 this.check(glsStateQuery.verifyProgram(program, gl.ATTACHED_SHADERS, 1)); 483 484 gl.attachShader(program, shaderFrag); 485 this.check(glsStateQuery.verifyProgram(program, gl.ATTACHED_SHADERS, 2)); 486 487 // check GetAttachedShaders 488 var shaders = gl.getAttachedShaders(program); 489 this.check(glsStateQuery.compare(shaders, [shaderVert, shaderFrag])); 490 491 gl.deleteShader(shaderVert); 492 gl.deleteShader(shaderFrag); 493 gl.deleteProgram(program); 494 }; 495 496 /** 497 * @constructor 498 * @extends {es3fApiCase.ApiCase} 499 * @param {string} name 500 * @param {string} description 501 */ 502 es3fShaderStateQueryTests.ProgramActiveUniformNameCase = function(name, description) { 503 es3fApiCase.ApiCase.call(this, name, description, gl); 504 }; 505 506 setParentClass(es3fShaderStateQueryTests.ProgramActiveUniformNameCase, es3fApiCase.ApiCase); 507 508 es3fShaderStateQueryTests.ProgramActiveUniformNameCase.prototype.test = function() { 509 var testVertSource = 510 '#version 300 es\n' + 511 'uniform highp float uniformNameWithLength23;\n' + 512 'uniform highp vec2 uniformVec2;\n' + 513 'uniform highp mat4 uniformMat4;\n' + 514 'void main (void)\n' + 515 '{\n' + 516 ' gl_Position = vec4(0.0) + vec4(uniformNameWithLength23) + vec4(uniformVec2.x) + vec4(uniformMat4[2][3]);\n' + 517 '}\n'; 518 var testFragSource = 519 '#version 300 es\n' + 520 'layout(location = 0) out mediump vec4 fragColor;' + 521 'void main (void)\n' + 522 '{\n' + 523 ' fragColor = vec4(0.0);\n' + 524 '}\n'; 525 526 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 527 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 528 529 gl.shaderSource(shaderVert, testVertSource); 530 gl.shaderSource(shaderFrag, testFragSource); 531 532 gl.compileShader(shaderVert); 533 gl.compileShader(shaderFrag); 534 535 var program = gl.createProgram(); 536 gl.attachShader(program, shaderVert); 537 gl.attachShader(program, shaderFrag); 538 gl.linkProgram(program); 539 540 this.check(glsStateQuery.verifyProgram(program, gl.ACTIVE_UNIFORMS, 3)); 541 542 var uniformNames = [ 543 'uniformNameWithLength23', 544 'uniformVec2', 545 'uniformMat4' 546 ]; 547 548 var indices = gl.getUniformIndices(program, uniformNames); 549 550 // check names 551 for (var ndx = 0; ndx < uniformNames.length; ++ndx) { 552 var index = indices[ndx]; 553 var uniform = gl.getActiveUniform(program, index); 554 555 this.check(glsStateQuery.compare(uniform.name, uniformNames[ndx])); 556 } 557 558 gl.deleteShader(shaderVert); 559 gl.deleteShader(shaderFrag); 560 gl.deleteProgram(program); 561 562 }; 563 564 /** 565 * @constructor 566 * @extends {es3fApiCase.ApiCase} 567 * @param {string} name 568 * @param {string} description 569 */ 570 es3fShaderStateQueryTests.ProgramUniformCase = function(name, description) { 571 es3fApiCase.ApiCase.call(this, name, description, gl); 572 }; 573 574 setParentClass(es3fShaderStateQueryTests.ProgramUniformCase, es3fApiCase.ApiCase); 575 576 es3fShaderStateQueryTests.ProgramUniformCase.prototype.test = function() { 577 var uniformTypes = [ 578 ['float', '', 'highp', '', 'uniformValue', gl.FLOAT, 1, false], 579 ['float[2]', '', 'highp', '', 'uniformValue[1]', gl.FLOAT, 2, false], 580 ['vec2', '', 'highp', '', 'uniformValue.x', gl.FLOAT_VEC2, 1, false], 581 ['vec3', '', 'highp', '', 'uniformValue.x', gl.FLOAT_VEC3, 1, false], 582 ['vec4', '', 'highp', '', 'uniformValue.x', gl.FLOAT_VEC4, 1, false], 583 ['int', '', 'highp', '', 'float(uniformValue)', gl.INT, 1, false], 584 ['ivec2', '', 'highp', '', 'float(uniformValue.x)', gl.INT_VEC2, 1, false], 585 ['ivec3', '', 'highp', '', 'float(uniformValue.x)', gl.INT_VEC3, 1, false], 586 ['ivec4', '', 'highp', '', 'float(uniformValue.x)', gl.INT_VEC4, 1, false], 587 ['uint', '', 'highp', '', 'float(uniformValue)', gl.UNSIGNED_INT, 1, false], 588 ['uvec2', '', 'highp', '', 'float(uniformValue.x)', gl.UNSIGNED_INT_VEC2, 1, false], 589 ['uvec3', '', 'highp', '', 'float(uniformValue.x)', gl.UNSIGNED_INT_VEC3, 1, false], 590 ['uvec4', '', 'highp', '', 'float(uniformValue.x)', gl.UNSIGNED_INT_VEC4, 1, false], 591 ['bool', '', '', '', 'float(uniformValue)', gl.BOOL, 1, false], 592 ['bvec2', '', '', '', 'float(uniformValue.x)', gl.BOOL_VEC2, 1, false], 593 ['bvec3', '', '', '', 'float(uniformValue.x)', gl.BOOL_VEC3, 1, false], 594 ['bvec4', '', '', '', 'float(uniformValue.x)', gl.BOOL_VEC4, 1, false], 595 ['mat2', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT2, 1, false], 596 ['mat3', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT3, 1, false], 597 ['mat4', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT4, 1, false], 598 ['mat2x3', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT2x3, 1, false], 599 ['mat2x4', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT2x4, 1, false], 600 ['mat3x2', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT3x2, 1, false], 601 ['mat3x4', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT3x4, 1, false], 602 ['mat4x2', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT4x2, 1, false], 603 ['mat4x3', '', 'highp', '', 'float(uniformValue[0][0])', gl.FLOAT_MAT4x3, 1, false], 604 ['sampler2D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_2D, 1, false], 605 ['sampler3D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_3D, 1, false], 606 ['samplerCube', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_CUBE, 1, false], 607 ['sampler2DShadow', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_2D_SHADOW, 1, false], 608 ['sampler2DArray', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_2D_ARRAY, 1, false], 609 ['sampler2DArrayShadow', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_2D_ARRAY_SHADOW, 1, false], 610 ['samplerCubeShadow', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.SAMPLER_CUBE_SHADOW, 1, false], 611 ['isampler2D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.INT_SAMPLER_2D, 1, false], 612 ['isampler3D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.INT_SAMPLER_3D, 1, false], 613 ['isamplerCube', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.INT_SAMPLER_CUBE, 1, false], 614 ['isampler2DArray', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.INT_SAMPLER_2D_ARRAY, 1, false], 615 ['usampler2D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.UNSIGNED_INT_SAMPLER_2D, 1, false], 616 ['usampler3D', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.UNSIGNED_INT_SAMPLER_3D, 1, false], 617 ['usamplerCube', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.UNSIGNED_INT_SAMPLER_CUBE, 1, false], 618 ['usampler2DArray', '', 'highp', '', 'float(textureSize(uniformValue,0).r)', gl.UNSIGNED_INT_SAMPLER_2D_ARRAY, 1, false] 619 ]; 620 621 var vertSource = 622 '#version 300 es\n' + 623 'void main (void)\n' + 624 '{\n' + 625 ' gl_Position = vec4(0.0);\n' + 626 '}\n'; 627 628 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 629 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 630 var program = gl.createProgram(); 631 632 gl.attachShader(program, shaderVert); 633 gl.attachShader(program, shaderFrag); 634 635 gl.shaderSource(shaderVert, vertSource); 636 gl.compileShader(shaderVert); 637 638 for (var ndx = 0; ndx < uniformTypes.length; ++ndx) { 639 var declaration = uniformTypes[ndx][0]; 640 var postDeclaration = uniformTypes[ndx][1]; 641 var precision = uniformTypes[ndx][2]; 642 var layout = uniformTypes[ndx][3]; 643 var getter = uniformTypes[ndx][4]; 644 var type = uniformTypes[ndx][5]; 645 var size = uniformTypes[ndx][6]; 646 var isRowMajor = uniformTypes[ndx][7]; 647 bufferedLogToConsole('Verify type of ' + declaration + ' variable' + postDeclaration); 648 649 // gen fragment shader 650 651 var frag = ''; 652 frag += '#version 300 es\n'; 653 frag += layout + 'uniform ' + precision + ' ' + declaration + ' uniformValue' + postDeclaration + ';\n'; 654 frag += 'layout(location = 0) out mediump vec4 fragColor;\n'; 655 frag += 'void main (void)\n'; 656 frag += '{\n'; 657 frag += ' fragColor = vec4(' + getter + ');\n'; 658 frag += '}\n'; 659 660 gl.shaderSource(shaderFrag, frag); 661 662 // compile & link 663 664 gl.compileShader(shaderFrag); 665 gl.linkProgram(program); 666 667 // test 668 if (this.check(glsStateQuery.verifyProgram(program, gl.LINK_STATUS, true), 'Program link fail' + gl.getProgramInfoLog(program))) { 669 var indices = gl.getUniformIndices(program, ['uniformValue']); 670 var info_type = gl.getActiveUniforms(program, indices, gl.UNIFORM_TYPE)[0]; 671 var info_size = gl.getActiveUniforms(program, indices, gl.UNIFORM_SIZE)[0]; 672 var info_is_row_major = gl.getActiveUniforms(program, indices, gl.UNIFORM_IS_ROW_MAJOR)[0]; 673 this.check(glsStateQuery.compare(info_size, size)); 674 this.check(glsStateQuery.compare(info_type, type)); 675 this.check(glsStateQuery.compare(info_is_row_major, isRowMajor)); 676 } 677 } 678 679 gl.deleteShader(shaderVert); 680 gl.deleteShader(shaderFrag); 681 gl.deleteProgram(program); 682 }; 683 684 /** 685 * @constructor 686 * @extends {es3fApiCase.ApiCase} 687 * @param {string} name 688 * @param {string} description 689 */ 690 es3fShaderStateQueryTests.ProgramActiveUniformBlocksCase = function(name, description) { 691 es3fApiCase.ApiCase.call(this, name, description, gl); 692 }; 693 694 setParentClass(es3fShaderStateQueryTests.ProgramActiveUniformBlocksCase, es3fApiCase.ApiCase); 695 696 es3fShaderStateQueryTests.ProgramActiveUniformBlocksCase.prototype.test = function() { 697 var testVertSource = 698 '#version 300 es\n' + 699 'uniform longlongUniformBlockName {highp vec2 vector2;} longlongUniformInstanceName;\n' + 700 'uniform shortUniformBlockName {highp vec2 vector2;highp vec4 vector4;} shortUniformInstanceName;\n' + 701 'void main (void)\n' + 702 '{\n' + 703 ' gl_Position = shortUniformInstanceName.vector4 + vec4(longlongUniformInstanceName.vector2.x) + vec4(shortUniformInstanceName.vector2.x);\n' + 704 '}\n'; 705 var testFragSource = 706 '#version 300 es\n' + 707 'uniform longlongUniformBlockName {highp vec2 vector2;} longlongUniformInstanceName;\n' + 708 'layout(location = 0) out mediump vec4 fragColor;' + 709 'void main (void)\n' + 710 '{\n' + 711 ' fragColor = vec4(longlongUniformInstanceName.vector2.y);\n' + 712 '}\n'; 713 714 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 715 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 716 717 gl.shaderSource(shaderVert, testVertSource); 718 gl.shaderSource(shaderFrag, testFragSource); 719 720 gl.compileShader(shaderVert); 721 gl.compileShader(shaderFrag); 722 723 var program = gl.createProgram(); 724 gl.attachShader(program, shaderVert); 725 gl.attachShader(program, shaderFrag); 726 gl.linkProgram(program); 727 728 this.check(glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true)); 729 this.check(glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true)); 730 this.check(glsStateQuery.verifyProgram(program, gl.LINK_STATUS, true)); 731 732 this.check(glsStateQuery.verifyProgram(program, gl.ACTIVE_UNIFORM_BLOCKS, 2)); 733 734 var longlongUniformBlockIndex = gl.getUniformBlockIndex(program, 'longlongUniformBlockName'); 735 var shortUniformBlockIndex = gl.getUniformBlockIndex(program, 'shortUniformBlockName'); 736 737 var uniformNames = [ 738 'longlongUniformBlockName.vector2', 739 'shortUniformBlockName.vector2', 740 'shortUniformBlockName.vector4' 741 ]; 742 743 // test UNIFORM_BLOCK_INDEX 744 745 var uniformIndices = gl.getUniformIndices(program, uniformNames); 746 747 var uniformsBlockIndices = gl.getActiveUniforms(program, uniformIndices, gl.UNIFORM_BLOCK_INDEX); 748 this.check(uniformsBlockIndices[0] == longlongUniformBlockIndex && 749 uniformsBlockIndices[1] == shortUniformBlockIndex && 750 uniformsBlockIndices[2] == shortUniformBlockIndex, 751 'Expected [' + longlongUniformBlockIndex + ", " + shortUniformBlockIndex + ", " + shortUniformBlockIndex + ']; got ' + 752 uniformsBlockIndices[0] + ", " + uniformsBlockIndices[1] + ", " + uniformsBlockIndices[2] + "]"); 753 754 // test UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER & UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 755 756 this.check(glsStateQuery.verifyActiveUniformBlock(program, longlongUniformBlockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER, true)); 757 this.check(glsStateQuery.verifyActiveUniformBlock(program, longlongUniformBlockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER, true)); 758 this.check(glsStateQuery.verifyActiveUniformBlock(program, shortUniformBlockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER, true)); 759 this.check(glsStateQuery.verifyActiveUniformBlock(program, shortUniformBlockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER, false)); 760 761 // test UNIFORM_BLOCK_ACTIVE_UNIFORMS 762 763 this.check(glsStateQuery.verifyActiveUniformBlock(program, longlongUniformBlockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS, 1)); 764 this.check(glsStateQuery.verifyActiveUniformBlock(program, shortUniformBlockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS, 2)); 765 766 // test UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 767 768 var shortUniformBlockIndices = gl.getActiveUniformBlockParameter(program, shortUniformBlockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES); 769 this.check(shortUniformBlockIndices.length == 2, 'Expected 2 indices; got ' + shortUniformBlockIndices.length); 770 771 this.check(glsStateQuery.compare(shortUniformBlockIndices, new Uint32Array([uniformIndices[1], uniformIndices[2]])) || 772 glsStateQuery.compare(shortUniformBlockIndices, new Uint32Array([uniformIndices[2], uniformIndices[1]])), 773 'Expected { ' + uniformIndices[1] +', ' + uniformIndices[2] + 774 '}; got {' + shortUniformBlockIndices[0] + ', ' + shortUniformBlockIndices[1] + '}'); 775 776 // check block names 777 778 var name = gl.getActiveUniformBlockName(program, longlongUniformBlockIndex); 779 this.check(name == "longlongUniformBlockName", 'Wrong uniform block name, expected longlongUniformBlockName; got ' + name); 780 name = gl.getActiveUniformBlockName(program, shortUniformBlockIndex) 781 this.check(name == "shortUniformBlockName", 'Wrong uniform block name, expected shortUniformBlockName; got ' + name); 782 783 gl.deleteShader(shaderVert); 784 gl.deleteShader(shaderFrag); 785 gl.deleteProgram(program); 786 }; 787 788 /** 789 * @constructor 790 * @extends {es3fApiCase.ApiCase} 791 * @param {string} name 792 * @param {string} description 793 */ 794 es3fShaderStateQueryTests.TransformFeedbackCase = function(name, description) { 795 es3fApiCase.ApiCase.call(this, name, description, gl); 796 }; 797 798 setParentClass(es3fShaderStateQueryTests.TransformFeedbackCase, es3fApiCase.ApiCase); 799 800 es3fShaderStateQueryTests.TransformFeedbackCase.prototype.test = function() { 801 var transformFeedbackTestVertSource = 802 '#version 300 es\n' + 803 'out highp vec4 tfOutput2withLongName;\n' + 804 'void main (void)\n' + 805 '{\n' + 806 ' gl_Position = vec4(0.0);\n' + 807 ' tfOutput2withLongName = vec4(0.0);\n' + 808 '}\n'; 809 var transformFeedbackTestFragSource = 810 '#version 300 es\n' + 811 'layout(location = 0) out highp vec4 fragColor;\n' + 812 'void main (void)\n' + 813 '{\n' + 814 ' fragColor = vec4(0.0);\n' + 815 '}\n'; 816 817 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 818 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 819 var shaderProg = gl.createProgram(); 820 821 this.check(glsStateQuery.verifyProgram(shaderProg, gl.TRANSFORM_FEEDBACK_BUFFER_MODE, gl.INTERLEAVED_ATTRIBS)); 822 823 gl.shaderSource(shaderVert, transformFeedbackTestVertSource); 824 gl.shaderSource(shaderFrag, transformFeedbackTestFragSource); 825 826 gl.compileShader(shaderVert); 827 gl.compileShader(shaderFrag); 828 829 this.check(glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true)); 830 this.check(glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true)); 831 832 gl.attachShader(shaderProg, shaderVert); 833 gl.attachShader(shaderProg, shaderFrag); 834 835 // check TRANSFORM_FEEDBACK_BUFFER_MODE 836 837 var transform_feedback_outputs = ['gl_Position', 'tfOutput2withLongName']; 838 var bufferModes = [gl.SEPARATE_ATTRIBS, gl.INTERLEAVED_ATTRIBS]; 839 840 for (var ndx = 0; ndx < bufferModes.length; ++ndx) { 841 gl.transformFeedbackVaryings(shaderProg, transform_feedback_outputs, bufferModes[ndx]); 842 gl.linkProgram(shaderProg); 843 844 this.check(glsStateQuery.verifyProgram(shaderProg, gl.LINK_STATUS, true)); 845 this.check(glsStateQuery.verifyProgram(shaderProg, gl.TRANSFORM_FEEDBACK_BUFFER_MODE, bufferModes[ndx])); 846 } 847 848 // check varyings 849 var varyings = /** @type {number} */ (gl.getProgramParameter(shaderProg, gl.TRANSFORM_FEEDBACK_VARYINGS)); 850 this.check(varyings === 2); 851 852 for (var index = 0; index < varyings; ++index) { 853 var info = gl.getTransformFeedbackVarying(shaderProg, index); 854 this.check(glsStateQuery.compare(info.type, gl.FLOAT_VEC4)); 855 this.check(glsStateQuery.compare(info.size, 1)); 856 this.check(glsStateQuery.compare(info.name, transform_feedback_outputs[index])); 857 } 858 859 gl.deleteShader(shaderVert); 860 gl.deleteShader(shaderFrag); 861 gl.deleteProgram(shaderProg); 862 863 // TODO(kbr): this test is failing and leaving an error in the GL 864 // state, causing later tests to fail. Clear the error state for 865 // the time being. 866 while (gl.getError() != gl.NO_ERROR) {} 867 }; 868 869 /** 870 * @constructor 871 * @extends {es3fApiCase.ApiCase} 872 * @param {string} name 873 * @param {string} description 874 */ 875 es3fShaderStateQueryTests.ActiveAttributesCase = function(name, description) { 876 es3fApiCase.ApiCase.call(this, name, description, gl); 877 }; 878 879 setParentClass(es3fShaderStateQueryTests.ActiveAttributesCase, es3fApiCase.ApiCase); 880 881 es3fShaderStateQueryTests.ActiveAttributesCase.prototype.test = function() { 882 var testVertSource = 883 '#version 300 es\n' + 884 'in highp vec2 longInputAttributeName;\n' + 885 'in highp vec2 shortName;\n' + 886 'void main (void)\n' + 887 '{\n' + 888 ' gl_Position = longInputAttributeName.yxxy + shortName.xyxy;\n' + 889 '}\n'; 890 var testFragSource = 891 '#version 300 es\n' + 892 'layout(location = 0) out mediump vec4 fragColor;' + 893 'void main (void)\n' + 894 '{\n' + 895 ' fragColor = vec4(0.0);\n' + 896 '}\n'; 897 898 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 899 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 900 901 gl.shaderSource(shaderVert, testVertSource); 902 gl.shaderSource(shaderFrag, testFragSource); 903 904 gl.compileShader(shaderVert); 905 gl.compileShader(shaderFrag); 906 907 var program = gl.createProgram(); 908 gl.attachShader(program, shaderVert); 909 gl.attachShader(program, shaderFrag); 910 gl.linkProgram(program); 911 912 this.check(glsStateQuery.verifyProgram(program, gl.ACTIVE_ATTRIBUTES, 2)); 913 914 var attribNames = [ 915 'longInputAttributeName', 916 'shortName' 917 ]; 918 // check names 919 for (var attributeNdx = 0; attributeNdx < 2; ++attributeNdx) { 920 var info = gl.getActiveAttrib(program, attributeNdx); 921 this.check(glsStateQuery.compare(info.name, attribNames[0]) || glsStateQuery.compare(info.name, attribNames[1])); 922 } 923 924 gl.deleteShader(shaderVert); 925 gl.deleteShader(shaderFrag); 926 gl.deleteProgram(program); 927 }; 928 929 /** 930 * @constructor 931 * @extends {es3fApiCase.ApiCase} 932 * @param {string} name 933 * @param {string} description 934 */ 935 es3fShaderStateQueryTests.VertexAttributeSizeCase = function(name, description) { 936 es3fApiCase.ApiCase.call(this, name, description, gl); 937 }; 938 939 setParentClass(es3fShaderStateQueryTests.VertexAttributeSizeCase, es3fApiCase.ApiCase); 940 941 es3fShaderStateQueryTests.VertexAttributeSizeCase.prototype.test = function() { 942 var pointers = [ 943 // size test 944 [4, gl.FLOAT, 0, false, 0], 945 [3, gl.FLOAT, 0, false, 0], 946 [2, gl.FLOAT, 0, false, 0], 947 [1, gl.FLOAT, 0, false, 0], 948 [4, gl.INT, 0, false, 0], 949 [3, gl.INT, 0, false, 0], 950 [2, gl.INT, 0, false, 0], 951 [1, gl.INT, 0, false, 0] 952 ]; 953 954 var buf = gl.createBuffer(); 955 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 956 957 // Test with default VAO 958 959 for (var ndx = 0; ndx < pointers.length; ++ndx) { 960 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], pointers[ndx][3], pointers[ndx][2], pointers[ndx][4]); 961 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE, pointers[ndx][0])); 962 } 963 964 // Test with multiple VAOs 965 var vao0 = gl.createVertexArray(); 966 var vao1 = gl.createVertexArray(); 967 968 // initial 969 gl.bindVertexArray(vao0); 970 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE, 4)); 971 972 // set vao 0 to some value 973 gl.vertexAttribPointer(0, pointers[0][0], pointers[0][1], pointers[0][3], pointers[0][2], 0); 974 975 // set vao 1 to some other value 976 gl.bindVertexArray(vao1); 977 gl.vertexAttribPointer(0, pointers[1][0], pointers[1][1], pointers[1][3], pointers[1][2], 0); 978 979 // verify vao 1 state 980 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE, pointers[1][0])); 981 982 // verify vao 0 state 983 gl.bindVertexArray(vao0); 984 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_SIZE, pointers[0][0])); 985 986 gl.deleteVertexArray(vao0); 987 gl.deleteVertexArray(vao1); 988 gl.deleteBuffer(buf); 989 }; 990 991 /** 992 * @constructor 993 * @extends {es3fApiCase.ApiCase} 994 * @param {string} name 995 * @param {string} description 996 */ 997 es3fShaderStateQueryTests.VertexAttributeTypeCase = function(name, description) { 998 es3fApiCase.ApiCase.call(this, name, description, gl); 999 }; 1000 1001 setParentClass(es3fShaderStateQueryTests.VertexAttributeTypeCase, es3fApiCase.ApiCase); 1002 1003 es3fShaderStateQueryTests.VertexAttributeTypeCase.prototype.test = function() { 1004 var pointers = [ 1005 // type test 1006 [1, gl.BYTE, 0, false, 0], 1007 [1, gl.SHORT, 0, false, 0], 1008 [1, gl.INT, 0, false, 0], 1009 [1, gl.FLOAT, 0, false, 0], 1010 [1, gl.HALF_FLOAT, 0, false, 0], 1011 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1012 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1013 [1, gl.UNSIGNED_INT, 0, false, 0], 1014 [4, gl.INT_2_10_10_10_REV, 0, false, 0], 1015 [4, gl.UNSIGNED_INT_2_10_10_10_REV, 0, false, 0] 1016 ]; 1017 1018 var buf = gl.createBuffer(); 1019 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 1020 1021 // Test with default VAO 1022 1023 for (var ndx = 0; ndx < pointers.length; ++ndx) { 1024 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], pointers[ndx][3], pointers[ndx][2], pointers[ndx][4]); 1025 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE, pointers[ndx][1])); 1026 } 1027 1028 var pointersI = [ 1029 [1, gl.BYTE, 0, false, 0], 1030 [1, gl.SHORT, 0, false, 0], 1031 [1, gl.INT, 0, false, 0], 1032 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1033 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1034 [1, gl.UNSIGNED_INT, 0, false, 0] 1035 ]; 1036 1037 for (var ndx = 0; ndx < pointersI.length; ++ndx) { 1038 gl.vertexAttribIPointer(0, pointersI[ndx][0], pointersI[ndx][1], pointersI[ndx][2], pointersI[ndx][4]); 1039 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE, pointersI[ndx][1])); 1040 } 1041 1042 // Test with multiple VAOs 1043 var vao0 = gl.createVertexArray(); 1044 var vao1 = gl.createVertexArray(); 1045 1046 // initial 1047 gl.bindVertexArray(vao0); 1048 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE, gl.FLOAT)); 1049 1050 // set vao 0 to some value 1051 gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0); 1052 1053 // set vao 1 to some other value 1054 gl.bindVertexArray(vao1); 1055 gl.vertexAttribPointer(0, 1, gl.SHORT, false, 0, 0); 1056 1057 // verify vao 1 state 1058 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE, gl.SHORT)); 1059 1060 // verify vao 0 state 1061 gl.bindVertexArray(vao0); 1062 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_TYPE, gl.FLOAT)); 1063 1064 gl.deleteVertexArray(vao0); 1065 gl.deleteVertexArray(vao1); 1066 gl.deleteBuffer(buf); 1067 }; 1068 1069 /** 1070 * @constructor 1071 * @extends {es3fApiCase.ApiCase} 1072 * @param {string} name 1073 * @param {string} description 1074 */ 1075 es3fShaderStateQueryTests.VertexAttributeStrideCase = function(name, description) { 1076 es3fApiCase.ApiCase.call(this, name, description, gl); 1077 }; 1078 1079 setParentClass(es3fShaderStateQueryTests.VertexAttributeStrideCase, es3fApiCase.ApiCase); 1080 1081 es3fShaderStateQueryTests.VertexAttributeStrideCase.prototype.test = function() { 1082 var pointers = [ 1083 [1, gl.FLOAT, 0, 0, gl.NO_ERROR], 1084 [1, gl.FLOAT, 1, 0, gl.INVALID_OPERATION], 1085 [1, gl.FLOAT, 4, 0, gl.NO_ERROR], 1086 [1, gl.HALF_FLOAT, 0, 0, gl.NO_ERROR], 1087 [1, gl.HALF_FLOAT, 1, 0, gl.INVALID_OPERATION], 1088 [1, gl.HALF_FLOAT, 4, 0, gl.NO_ERROR] 1089 ]; 1090 1091 var buf = gl.createBuffer(); 1092 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 1093 1094 // Test with default VAO 1095 1096 for (var ndx = 0; ndx < pointers.length; ++ndx) { 1097 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], false, pointers[ndx][2], pointers[ndx][3]); 1098 this.expectError(pointers[ndx][4]); 1099 if (pointers[ndx][4] == gl.NO_ERROR) { 1100 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE, pointers[ndx][2])); 1101 } 1102 } 1103 1104 var pointersI = [ 1105 [1, gl.INT, 0, 0, gl.NO_ERROR], 1106 [1, gl.INT, 1, 0, gl.INVALID_OPERATION], 1107 [1, gl.INT, 4, 0, gl.NO_ERROR], 1108 [4, gl.UNSIGNED_BYTE, 0, 0, gl.NO_ERROR], 1109 [4, gl.UNSIGNED_BYTE, 1, 0, gl.NO_ERROR], 1110 [4, gl.UNSIGNED_BYTE, 4, 0, gl.NO_ERROR], 1111 [2, gl.SHORT, 0, 0, gl.NO_ERROR], 1112 [2, gl.SHORT, 1, 0, gl.INVALID_OPERATION], 1113 [2, gl.SHORT, 4, 0, gl.NO_ERROR] 1114 ]; 1115 1116 for (var ndx = 0; ndx < pointersI.length; ++ndx) { 1117 gl.vertexAttribIPointer(0, pointersI[ndx][0], pointersI[ndx][1], pointersI[ndx][2], pointersI[ndx][3]); 1118 this.expectError(pointersI[ndx][4]); 1119 if (pointersI[ndx][4] == gl.NO_ERROR) { 1120 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE, pointersI[ndx][2])); 1121 } 1122 } 1123 1124 // Test with multiple VAOs 1125 var vao0 = gl.createVertexArray(); 1126 var vao1 = gl.createVertexArray(); 1127 1128 // initial 1129 gl.bindVertexArray(vao0); 1130 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE, 0)); 1131 1132 // set vao 0 to some value 1133 gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 4, 0); 1134 1135 // set vao 1 to some other value 1136 gl.bindVertexArray(vao1); 1137 gl.vertexAttribPointer(0, 1, gl.SHORT, false, 8, 0); 1138 1139 // verify vao 1 state 1140 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE, 8)); 1141 1142 // verify vao 0 state 1143 gl.bindVertexArray(vao0); 1144 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_STRIDE, 4)); 1145 1146 gl.deleteVertexArray(vao0); 1147 gl.deleteVertexArray(vao1); 1148 gl.deleteBuffer(buf); 1149 }; 1150 1151 /** 1152 * @constructor 1153 * @extends {es3fApiCase.ApiCase} 1154 * @param {string} name 1155 * @param {string} description 1156 */ 1157 es3fShaderStateQueryTests.VertexAttributeNormalizedCase = function(name, description) { 1158 es3fApiCase.ApiCase.call(this, name, description, gl); 1159 }; 1160 1161 setParentClass(es3fShaderStateQueryTests.VertexAttributeNormalizedCase, es3fApiCase.ApiCase); 1162 1163 es3fShaderStateQueryTests.VertexAttributeNormalizedCase.prototype.test = function() { 1164 var pointers = [ 1165 // type test 1166 [1, gl.BYTE, 0, false, 0], 1167 [1, gl.SHORT, 0, false, 0], 1168 [1, gl.INT, 0, false, 0], 1169 [1, gl.FLOAT, 0, false, 0], 1170 [1, gl.HALF_FLOAT, 0, false, 0], 1171 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1172 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1173 [1, gl.UNSIGNED_INT, 0, false, 0], 1174 [4, gl.INT_2_10_10_10_REV, 0, false, 0], 1175 [4, gl.UNSIGNED_INT_2_10_10_10_REV, 0, false, 0], 1176 [1, gl.BYTE, 0, true, 0], 1177 [1, gl.SHORT, 0, true, 0], 1178 [1, gl.INT, 0, true, 0], 1179 [1, gl.FLOAT, 0, true, 0], 1180 [1, gl.HALF_FLOAT, 0, true, 0], 1181 [1, gl.UNSIGNED_BYTE, 0, true, 0], 1182 [1, gl.UNSIGNED_SHORT, 0, true, 0], 1183 [1, gl.UNSIGNED_INT, 0, true, 0], 1184 [4, gl.INT_2_10_10_10_REV, 0, true, 0], 1185 [4, gl.UNSIGNED_INT_2_10_10_10_REV, 0, true, 0] 1186 ]; 1187 1188 var buf = gl.createBuffer(); 1189 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 1190 1191 // Test with default VAO 1192 1193 for (var ndx = 0; ndx < pointers.length; ++ndx) { 1194 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], pointers[ndx][3], pointers[ndx][2], pointers[ndx][4]); 1195 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED, pointers[ndx][3])); 1196 } 1197 1198 var pointersI = [ 1199 [1, gl.BYTE, 0, false, 0], 1200 [1, gl.SHORT, 0, false, 0], 1201 [1, gl.INT, 0, false, 0], 1202 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1203 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1204 [1, gl.UNSIGNED_INT, 0, false, 0] 1205 ]; 1206 1207 for (var ndx = 0; ndx < pointersI.length; ++ndx) { 1208 gl.vertexAttribIPointer(0, pointersI[ndx][0], pointersI[ndx][1], pointersI[ndx][2], pointersI[ndx][4]); 1209 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED, false)); 1210 } 1211 1212 // Test with multiple VAOs 1213 var vao0 = gl.createVertexArray(); 1214 var vao1 = gl.createVertexArray(); 1215 1216 // initial 1217 gl.bindVertexArray(vao0); 1218 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED, false)); 1219 1220 // set vao 0 to some value 1221 gl.vertexAttribPointer(0, 1, gl.INT, true, 0, 0); 1222 1223 // set vao 1 to some other value 1224 gl.bindVertexArray(vao1); 1225 gl.vertexAttribPointer(0, 1, gl.INT, false, 0, 0); 1226 1227 // verify vao 1 state 1228 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED, false)); 1229 1230 // verify vao 0 state 1231 gl.bindVertexArray(vao0); 1232 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED, true)); 1233 1234 gl.deleteVertexArray(vao0); 1235 gl.deleteVertexArray(vao1); 1236 gl.deleteBuffer(buf); 1237 }; 1238 1239 /** 1240 * @constructor 1241 * @extends {es3fApiCase.ApiCase} 1242 * @param {string} name 1243 * @param {string} description 1244 */ 1245 es3fShaderStateQueryTests.VertexAttributeIntegerCase = function(name, description) { 1246 es3fApiCase.ApiCase.call(this, name, description, gl); 1247 }; 1248 1249 setParentClass(es3fShaderStateQueryTests.VertexAttributeIntegerCase, es3fApiCase.ApiCase); 1250 1251 es3fShaderStateQueryTests.VertexAttributeIntegerCase.prototype.test = function() { 1252 var pointers = [ 1253 // type test 1254 [1, gl.BYTE, 0, false, 0], 1255 [1, gl.SHORT, 0, false, 0], 1256 [1, gl.INT, 0, false, 0], 1257 [1, gl.FLOAT, 0, false, 0], 1258 [1, gl.HALF_FLOAT, 0, false, 0], 1259 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1260 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1261 [1, gl.UNSIGNED_INT, 0, false, 0], 1262 [4, gl.INT_2_10_10_10_REV, 0, false, 0], 1263 [4, gl.UNSIGNED_INT_2_10_10_10_REV, 0, false, 0] 1264 ]; 1265 1266 var buf = gl.createBuffer(); 1267 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 1268 1269 // Test with default VAO 1270 1271 for (var ndx = 0; ndx < pointers.length; ++ndx) { 1272 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], pointers[ndx][3], pointers[ndx][2], pointers[ndx][4]); 1273 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_INTEGER, false)); 1274 } 1275 1276 var pointersI = [ 1277 [1, gl.BYTE, 0, false, 0], 1278 [1, gl.SHORT, 0, false, 0], 1279 [1, gl.INT, 0, false, 0], 1280 [1, gl.UNSIGNED_BYTE, 0, false, 0], 1281 [1, gl.UNSIGNED_SHORT, 0, false, 0], 1282 [1, gl.UNSIGNED_INT, 0, false, 0] 1283 ]; 1284 1285 for (var ndx = 0; ndx < pointersI.length; ++ndx) { 1286 gl.vertexAttribIPointer(0, pointersI[ndx][0], pointersI[ndx][1], pointersI[ndx][2], pointersI[ndx][4]); 1287 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_INTEGER, true)); 1288 } 1289 1290 // Test with multiple VAOs 1291 var vao0 = gl.createVertexArray(); 1292 var vao1 = gl.createVertexArray(); 1293 1294 // initial 1295 gl.bindVertexArray(vao0); 1296 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_INTEGER, false)); 1297 1298 // set vao 0 to some value 1299 gl.vertexAttribIPointer(0, 1, gl.INT, 0, 0); 1300 1301 // set vao 1 to some other value 1302 gl.bindVertexArray(vao1); 1303 gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0); 1304 1305 // verify vao 1 state 1306 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_INTEGER, false)); 1307 1308 // verify vao 0 state 1309 gl.bindVertexArray(vao0); 1310 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_INTEGER, true)); 1311 1312 gl.deleteVertexArray(vao0); 1313 gl.deleteVertexArray(vao1); 1314 gl.deleteBuffer(buf); 1315 }; 1316 1317 /** 1318 * @constructor 1319 * @extends {es3fApiCase.ApiCase} 1320 * @param {string} name 1321 * @param {string} description 1322 */ 1323 es3fShaderStateQueryTests.VertexAttributeEnabledCase = function(name, description) { 1324 es3fApiCase.ApiCase.call(this, name, description, gl); 1325 }; 1326 1327 setParentClass(es3fShaderStateQueryTests.VertexAttributeEnabledCase, es3fApiCase.ApiCase); 1328 1329 es3fShaderStateQueryTests.VertexAttributeEnabledCase.prototype.test = function() { 1330 // Test with default VAO 1331 1332 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_ENABLED, false)); 1333 gl.enableVertexAttribArray(0); 1334 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_ENABLED, true)); 1335 gl.disableVertexAttribArray(0); 1336 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_ENABLED, false)); 1337 1338 // Test with multiple VAOs 1339 var vao0 = gl.createVertexArray(); 1340 var vao1 = gl.createVertexArray(); 1341 1342 // initial 1343 gl.bindVertexArray(vao0); 1344 // set vao 0 to some value 1345 gl.enableVertexAttribArray(0); 1346 1347 // set vao 1 to some other value 1348 gl.bindVertexArray(vao1); 1349 gl.disableVertexAttribArray(0); 1350 1351 // verify vao 1 state 1352 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_ENABLED, false)); 1353 1354 // verify vao 0 state 1355 gl.bindVertexArray(vao0); 1356 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_ENABLED, true)); 1357 1358 gl.deleteVertexArray(vao0); 1359 gl.deleteVertexArray(vao1); 1360 }; 1361 1362 /** 1363 * @constructor 1364 * @extends {es3fApiCase.ApiCase} 1365 * @param {string} name 1366 * @param {string} description 1367 */ 1368 es3fShaderStateQueryTests.VertexAttributeDivisorCase = function(name, description) { 1369 es3fApiCase.ApiCase.call(this, name, description, gl); 1370 }; 1371 1372 setParentClass(es3fShaderStateQueryTests.VertexAttributeDivisorCase, es3fApiCase.ApiCase); 1373 1374 es3fShaderStateQueryTests.VertexAttributeDivisorCase.prototype.test = function() { 1375 // Test with default VAO 1376 1377 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR, 0)); 1378 gl.vertexAttribDivisor(0, 1); 1379 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR, 1)); 1380 gl.vertexAttribDivisor(0, 5); 1381 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR, 5)); 1382 1383 // Test with multiple VAOs 1384 var vao0 = gl.createVertexArray(); 1385 var vao1 = gl.createVertexArray(); 1386 1387 // initial 1388 gl.bindVertexArray(vao0); 1389 // set vao 0 to some value 1390 gl.vertexAttribDivisor(0, 1); 1391 1392 // set vao 1 to some other value 1393 gl.bindVertexArray(vao1); 1394 gl.vertexAttribDivisor(0, 5); 1395 1396 // verify vao 1 state 1397 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR, 5)); 1398 1399 // verify vao 0 state 1400 gl.bindVertexArray(vao0); 1401 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR, 1)); 1402 1403 gl.deleteVertexArray(vao0); 1404 gl.deleteVertexArray(vao1); 1405 }; 1406 1407 /** 1408 * @constructor 1409 * @extends {es3fApiCase.ApiCase} 1410 * @param {string} name 1411 * @param {string} description 1412 */ 1413 es3fShaderStateQueryTests.VertexAttributeBufferBindingCase = function(name, description) { 1414 es3fApiCase.ApiCase.call(this, name, description, gl); 1415 }; 1416 1417 setParentClass(es3fShaderStateQueryTests.VertexAttributeBufferBindingCase, es3fApiCase.ApiCase); 1418 1419 es3fShaderStateQueryTests.VertexAttributeBufferBindingCase.prototype.test = function() { 1420 // Test with default VAO 1421 1422 var buffer = gl.createBuffer(); 1423 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1424 1425 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0); 1426 1427 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, buffer)); 1428 1429 gl.deleteBuffer(buffer); 1430 1431 // Test with multiple VAOs 1432 var vao0 = gl.createVertexArray(); 1433 var vao1 = gl.createVertexArray(); 1434 var buffer0 = gl.createBuffer(); 1435 var buffer1 = gl.createBuffer(); 1436 1437 // initial 1438 gl.bindVertexArray(vao0); 1439 // set vao 0 to some value 1440 gl.bindBuffer(gl.ARRAY_BUFFER, buffer0); 1441 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0); 1442 1443 // set vao 1 to some other value 1444 gl.bindVertexArray(vao1); 1445 gl.bindBuffer(gl.ARRAY_BUFFER, buffer1); 1446 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0); 1447 1448 // verify vao 1 state 1449 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, buffer1)); 1450 1451 // verify vao 0 state 1452 gl.bindVertexArray(vao0); 1453 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, buffer0)); 1454 1455 gl.deleteVertexArray(vao0); 1456 gl.deleteVertexArray(vao1); 1457 gl.deleteBuffer(buffer0); 1458 gl.deleteBuffer(buffer1); 1459 }; 1460 1461 /** 1462 * @constructor 1463 * @extends {es3fApiCase.ApiCase} 1464 * @param {string} name 1465 * @param {string} description 1466 */ 1467 es3fShaderStateQueryTests.VertexAttributeOffsetCase = function(name, description) { 1468 es3fApiCase.ApiCase.call(this, name, description, gl); 1469 }; 1470 1471 setParentClass(es3fShaderStateQueryTests.VertexAttributeOffsetCase, es3fApiCase.ApiCase); 1472 1473 es3fShaderStateQueryTests.VertexAttributeOffsetCase.prototype.test = function() { 1474 var pointers = [ 1475 [1, gl.BYTE, 0, false, 2 * 4], 1476 [1, gl.SHORT, 0, false, 1 * 4], 1477 [1, gl.INT, 0, false, 2 * 4], 1478 [1, gl.FLOAT, 0, false, 0 * 4], 1479 [1, gl.FLOAT, 0, false, 3 * 4], 1480 [1, gl.FLOAT, 0, false, 2 * 4], 1481 [1, gl.HALF_FLOAT, 0, false, 0 * 4], 1482 [4, gl.HALF_FLOAT, 0, false, 1 * 4], 1483 [4, gl.HALF_FLOAT, 0, false, 2 * 4] 1484 ]; 1485 1486 var buf = gl.createBuffer(); 1487 gl.bindBuffer(gl.ARRAY_BUFFER, buf); 1488 1489 // Test with default VAO 1490 1491 for (var ndx = 0; ndx < pointers.length; ++ndx) { 1492 gl.vertexAttribPointer(0, pointers[ndx][0], pointers[ndx][1], pointers[ndx][3], pointers[ndx][2], pointers[ndx][4]); 1493 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_POINTER, pointers[ndx][4])); 1494 } 1495 1496 // Test with multiple VAOs 1497 var vao0 = gl.createVertexArray(); 1498 var vao1 = gl.createVertexArray(); 1499 1500 // initial 1501 gl.bindVertexArray(vao0); 1502 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_POINTER, 0)); 1503 1504 // set vao 0 to some value 1505 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 8); 1506 1507 // set vao 1 to some other value 1508 gl.bindVertexArray(vao1); 1509 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 4); 1510 1511 // verify vao 1 state 1512 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_POINTER, 4)); 1513 1514 // verify vao 0 state 1515 gl.bindVertexArray(vao0); 1516 this.check(glsStateQuery.verifyVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_POINTER, 8)); 1517 1518 gl.deleteVertexArray(vao0); 1519 gl.deleteVertexArray(vao1); 1520 gl.deleteBuffer(buf); 1521 }; 1522 1523 /** 1524 * @constructor 1525 * @extends {es3fApiCase.ApiCase} 1526 * @param {string} name 1527 * @param {string} description 1528 */ 1529 es3fShaderStateQueryTests.UniformValueFloatCase = function(name, description) { 1530 es3fApiCase.ApiCase.call(this, name, description, gl); 1531 }; 1532 1533 setParentClass(es3fShaderStateQueryTests.UniformValueFloatCase, es3fApiCase.ApiCase); 1534 1535 es3fShaderStateQueryTests.UniformValueFloatCase.prototype.test = function() { 1536 var testVertSource = 1537 '#version 300 es\n' + 1538 'uniform highp float floatUniform;\n' + 1539 'uniform highp vec2 float2Uniform;\n' + 1540 'uniform highp vec3 float3Uniform;\n' + 1541 'uniform highp vec4 float4Uniform;\n' + 1542 'void main (void)\n' + 1543 '{\n' + 1544 ' gl_Position = vec4(floatUniform + float2Uniform.x + float3Uniform.x + float4Uniform.x);\n' + 1545 '}\n'; 1546 var testFragSource = 1547 '#version 300 es\n' + 1548 'layout(location = 0) out mediump vec4 fragColor;' + 1549 'void main (void)\n' + 1550 '{\n' + 1551 ' fragColor = vec4(0.0);\n' + 1552 '}\n'; 1553 1554 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1555 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1556 1557 gl.shaderSource(shaderVert, testVertSource); 1558 gl.shaderSource(shaderFrag, testFragSource); 1559 1560 gl.compileShader(shaderVert); 1561 gl.compileShader(shaderFrag); 1562 1563 var program = gl.createProgram(); 1564 gl.attachShader(program, shaderVert); 1565 gl.attachShader(program, shaderFrag); 1566 gl.linkProgram(program); 1567 gl.useProgram(program); 1568 1569 var location; 1570 1571 location = gl.getUniformLocation(program, 'floatUniform'); 1572 gl.uniform1f(location, 1); 1573 this.check(glsStateQuery.verifyUniform(program, location, 1)); 1574 1575 location = gl.getUniformLocation(program, 'float2Uniform'); 1576 gl.uniform2f(location, 1, 2); 1577 this.check(glsStateQuery.verifyUniform(program, location, new Float32Array([1, 2]))); 1578 1579 location = gl.getUniformLocation(program, 'float3Uniform'); 1580 gl.uniform3f(location, 1, 2, 3); 1581 this.check(glsStateQuery.verifyUniform(program, location, new Float32Array([1, 2, 3]))); 1582 1583 location = gl.getUniformLocation(program, 'float4Uniform'); 1584 gl.uniform4f(location, 1, 2, 3, 4); 1585 this.check(glsStateQuery.verifyUniform(program, location, new Float32Array([1, 2, 3, 4]))); 1586 1587 gl.useProgram(null); 1588 gl.deleteShader(shaderVert); 1589 gl.deleteShader(shaderFrag); 1590 gl.deleteProgram(program); 1591 }; 1592 1593 /** 1594 * @constructor 1595 * @extends {es3fApiCase.ApiCase} 1596 * @param {string} name 1597 * @param {string} description 1598 */ 1599 es3fShaderStateQueryTests.UniformValueIntCase = function(name, description) { 1600 es3fApiCase.ApiCase.call(this, name, description, gl); 1601 }; 1602 1603 setParentClass(es3fShaderStateQueryTests.UniformValueIntCase, es3fApiCase.ApiCase); 1604 1605 es3fShaderStateQueryTests.UniformValueIntCase.prototype.test = function() { 1606 var testVertSource = 1607 '#version 300 es\n' + 1608 'uniform highp int intUniform;\n' + 1609 'uniform highp ivec2 int2Uniform;\n' + 1610 'uniform highp ivec3 int3Uniform;\n' + 1611 'uniform highp ivec4 int4Uniform;\n' + 1612 'void main (void)\n' + 1613 '{\n' + 1614 ' gl_Position = vec4(float(intUniform + int2Uniform.x + int3Uniform.x + int4Uniform.x));\n' + 1615 '}\n'; 1616 var testFragSource = 1617 '#version 300 es\n' + 1618 'layout(location = 0) out mediump vec4 fragColor;' + 1619 'void main (void)\n' + 1620 '{\n' + 1621 ' fragColor = vec4(0.0);\n' + 1622 '}\n'; 1623 1624 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1625 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1626 1627 gl.shaderSource(shaderVert, testVertSource); 1628 gl.shaderSource(shaderFrag, testFragSource); 1629 1630 gl.compileShader(shaderVert); 1631 gl.compileShader(shaderFrag); 1632 1633 var program = gl.createProgram(); 1634 gl.attachShader(program, shaderVert); 1635 gl.attachShader(program, shaderFrag); 1636 gl.linkProgram(program); 1637 gl.useProgram(program); 1638 1639 var location; 1640 1641 location = gl.getUniformLocation(program, 'intUniform'); 1642 gl.uniform1i(location, 1); 1643 this.check(glsStateQuery.verifyUniform(program, location, 1)); 1644 1645 location = gl.getUniformLocation(program, 'int2Uniform'); 1646 gl.uniform2i(location, 1, 2); 1647 this.check(glsStateQuery.verifyUniform(program, location, new Int32Array([1, 2]))); 1648 1649 location = gl.getUniformLocation(program, 'int3Uniform'); 1650 gl.uniform3i(location, 1, 2, 3); 1651 this.check(glsStateQuery.verifyUniform(program, location, new Int32Array([1, 2, 3]))); 1652 1653 location = gl.getUniformLocation(program, 'int4Uniform'); 1654 gl.uniform4i(location, 1, 2, 3, 4); 1655 this.check(glsStateQuery.verifyUniform(program, location, new Int32Array([1, 2, 3, 4]))); 1656 1657 gl.useProgram(null); 1658 gl.deleteShader(shaderVert); 1659 gl.deleteShader(shaderFrag); 1660 gl.deleteProgram(program); 1661 }; 1662 1663 /** 1664 * @constructor 1665 * @extends {es3fApiCase.ApiCase} 1666 * @param {string} name 1667 * @param {string} description 1668 */ 1669 es3fShaderStateQueryTests.UniformValueUintCase = function(name, description) { 1670 es3fApiCase.ApiCase.call(this, name, description, gl); 1671 }; 1672 1673 setParentClass(es3fShaderStateQueryTests.UniformValueUintCase, es3fApiCase.ApiCase); 1674 1675 es3fShaderStateQueryTests.UniformValueUintCase.prototype.test = function() { 1676 var testVertSource = 1677 '#version 300 es\n' + 1678 'uniform highp uint uintUniform;\n' + 1679 'uniform highp uvec2 uint2Uniform;\n' + 1680 'uniform highp uvec3 uint3Uniform;\n' + 1681 'uniform highp uvec4 uint4Uniform;\n' + 1682 'void main (void)\n' + 1683 '{\n' + 1684 ' gl_Position = vec4(float(uintUniform + uint2Uniform.x + uint3Uniform.x + uint4Uniform.x));\n' + 1685 '}\n'; 1686 var testFragSource = 1687 '#version 300 es\n' + 1688 'layout(location = 0) out mediump vec4 fragColor;' + 1689 'void main (void)\n' + 1690 '{\n' + 1691 ' fragColor = vec4(0.0);\n' + 1692 '}\n'; 1693 1694 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1695 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1696 1697 gl.shaderSource(shaderVert, testVertSource); 1698 gl.shaderSource(shaderFrag, testFragSource); 1699 1700 gl.compileShader(shaderVert); 1701 gl.compileShader(shaderFrag); 1702 1703 var program = gl.createProgram(); 1704 gl.attachShader(program, shaderVert); 1705 gl.attachShader(program, shaderFrag); 1706 gl.linkProgram(program); 1707 gl.useProgram(program); 1708 1709 var location; 1710 1711 location = gl.getUniformLocation(program, 'uintUniform'); 1712 gl.uniform1ui(location, 1); 1713 this.check(glsStateQuery.verifyUniform(program, location, 1)); 1714 1715 location = gl.getUniformLocation(program, 'uint2Uniform'); 1716 gl.uniform2ui(location, 1, 2); 1717 this.check(glsStateQuery.verifyUniform(program, location, new Uint32Array([1, 2]))); 1718 1719 location = gl.getUniformLocation(program, 'uint3Uniform'); 1720 gl.uniform3ui(location, 1, 2, 3); 1721 this.check(glsStateQuery.verifyUniform(program, location, new Uint32Array([1, 2, 3]))); 1722 1723 location = gl.getUniformLocation(program, 'uint4Uniform'); 1724 gl.uniform4ui(location, 1, 2, 3, 4); 1725 this.check(glsStateQuery.verifyUniform(program, location, new Uint32Array([1, 2, 3, 4]))); 1726 1727 gl.useProgram(null); 1728 gl.deleteShader(shaderVert); 1729 gl.deleteShader(shaderFrag); 1730 gl.deleteProgram(program); 1731 }; 1732 1733 /** 1734 * @constructor 1735 * @extends {es3fApiCase.ApiCase} 1736 * @param {string} name 1737 * @param {string} description 1738 */ 1739 es3fShaderStateQueryTests.UniformValueBooleanCase = function(name, description) { 1740 es3fApiCase.ApiCase.call(this, name, description, gl); 1741 }; 1742 1743 setParentClass(es3fShaderStateQueryTests.UniformValueBooleanCase, es3fApiCase.ApiCase); 1744 1745 es3fShaderStateQueryTests.UniformValueBooleanCase.prototype.test = function() { 1746 var testVertSource = 1747 '#version 300 es\n' + 1748 'uniform bool boolUniform;\n' + 1749 'uniform bvec2 bool2Uniform;\n' + 1750 'uniform bvec3 bool3Uniform;\n' + 1751 'uniform bvec4 bool4Uniform;\n' + 1752 'void main (void)\n' + 1753 '{\n' + 1754 ' gl_Position = vec4(float(boolUniform) + float(bool2Uniform.x) + float(bool3Uniform.x) + float(bool4Uniform.x));\n' + 1755 '}\n'; 1756 var testFragSource = 1757 '#version 300 es\n' + 1758 'layout(location = 0) out mediump vec4 fragColor;' + 1759 'void main (void)\n' + 1760 '{\n' + 1761 ' fragColor = vec4(0.0);\n' + 1762 '}\n'; 1763 1764 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1765 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1766 1767 gl.shaderSource(shaderVert, testVertSource); 1768 gl.shaderSource(shaderFrag, testFragSource); 1769 1770 gl.compileShader(shaderVert); 1771 gl.compileShader(shaderFrag); 1772 1773 var program = gl.createProgram(); 1774 gl.attachShader(program, shaderVert); 1775 gl.attachShader(program, shaderFrag); 1776 gl.linkProgram(program); 1777 gl.useProgram(program); 1778 1779 var location; 1780 1781 location = gl.getUniformLocation(program, 'boolUniform'); 1782 gl.uniform1i(location, 1); 1783 this.check(glsStateQuery.verifyUniform(program, location, true)); 1784 1785 location = gl.getUniformLocation(program, 'bool2Uniform'); 1786 gl.uniform2i(location, 1, 0); 1787 this.check(glsStateQuery.verifyUniform(program, location, [true, false])); 1788 1789 location = gl.getUniformLocation(program, 'bool3Uniform'); 1790 gl.uniform3i(location, 1, 0, 1); 1791 this.check(glsStateQuery.verifyUniform(program, location, [true, false, true])); 1792 1793 location = gl.getUniformLocation(program, 'bool4Uniform'); 1794 gl.uniform4i(location, 1, 0, 1, 0); 1795 this.check(glsStateQuery.verifyUniform(program, location, [true, false, true, false])); 1796 1797 gl.useProgram(null); 1798 gl.deleteShader(shaderVert); 1799 gl.deleteShader(shaderFrag); 1800 gl.deleteProgram(program); 1801 }; 1802 1803 /** 1804 * @constructor 1805 * @extends {es3fApiCase.ApiCase} 1806 * @param {string} name 1807 * @param {string} description 1808 */ 1809 es3fShaderStateQueryTests.UniformValueSamplerCase = function(name, description) { 1810 es3fApiCase.ApiCase.call(this, name, description, gl); 1811 }; 1812 1813 setParentClass(es3fShaderStateQueryTests.UniformValueSamplerCase, es3fApiCase.ApiCase); 1814 1815 es3fShaderStateQueryTests.UniformValueSamplerCase.prototype.test = function() { 1816 var testVertSource = 1817 '#version 300 es\n' + 1818 'void main (void)\n' + 1819 '{\n' + 1820 ' gl_Position = vec4(0.0);\n' + 1821 '}\n'; 1822 var testFragSource = 1823 '#version 300 es\n' + 1824 'uniform highp sampler2D uniformSampler;\n' + 1825 'layout(location = 0) out mediump vec4 fragColor;' + 1826 'void main (void)\n' + 1827 '{\n' + 1828 ' fragColor = vec4(textureSize(uniformSampler, 0).x);\n' + 1829 '}\n'; 1830 1831 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1832 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1833 1834 gl.shaderSource(shaderVert, testVertSource); 1835 gl.shaderSource(shaderFrag, testFragSource); 1836 1837 gl.compileShader(shaderVert); 1838 gl.compileShader(shaderFrag); 1839 1840 var program = gl.createProgram(); 1841 gl.attachShader(program, shaderVert); 1842 gl.attachShader(program, shaderFrag); 1843 gl.linkProgram(program); 1844 gl.useProgram(program); 1845 1846 var location; 1847 1848 location = gl.getUniformLocation(program, 'uniformSampler'); 1849 gl.uniform1i(location, 1); 1850 this.check(glsStateQuery.verifyUniform(program, location, 1)); 1851 1852 gl.useProgram(null); 1853 gl.deleteShader(shaderVert); 1854 gl.deleteShader(shaderFrag); 1855 gl.deleteProgram(program); 1856 }; 1857 1858 /** 1859 * @constructor 1860 * @extends {es3fApiCase.ApiCase} 1861 * @param {string} name 1862 * @param {string} description 1863 */ 1864 es3fShaderStateQueryTests.UniformValueArrayCase = function(name, description) { 1865 es3fApiCase.ApiCase.call(this, name, description, gl); 1866 }; 1867 1868 setParentClass(es3fShaderStateQueryTests.UniformValueArrayCase, es3fApiCase.ApiCase); 1869 1870 es3fShaderStateQueryTests.UniformValueArrayCase.prototype.test = function() { 1871 var testVertSource = 1872 '#version 300 es\n' + 1873 'uniform highp float arrayUniform[5];' + 1874 'uniform highp vec2 array2Uniform[5];' + 1875 'uniform highp vec3 array3Uniform[5];' + 1876 'uniform highp vec4 array4Uniform[5];' + 1877 'void main (void)\n' + 1878 '{\n' + 1879 ' gl_Position = \n' + 1880 ' + vec4(arrayUniform[0] + arrayUniform[1] + arrayUniform[2] + arrayUniform[3] + arrayUniform[4])\n' + 1881 ' + vec4(array2Uniform[0].x + array2Uniform[1].x + array2Uniform[2].x + array2Uniform[3].x + array2Uniform[4].x)\n' + 1882 ' + vec4(array3Uniform[0].x + array3Uniform[1].x + array3Uniform[2].x + array3Uniform[3].x + array3Uniform[4].x)\n' + 1883 ' + vec4(array4Uniform[0].x + array4Uniform[1].x + array4Uniform[2].x + array4Uniform[3].x + array4Uniform[4].x);\n' + 1884 '}\n'; 1885 var testFragSource = 1886 '#version 300 es\n' + 1887 'layout(location = 0) out mediump vec4 fragColor;' + 1888 'void main (void)\n' + 1889 '{\n' + 1890 ' fragColor = vec4(0.0);\n' + 1891 '}\n'; 1892 1893 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1894 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 1895 1896 gl.shaderSource(shaderVert, testVertSource); 1897 gl.shaderSource(shaderFrag, testFragSource); 1898 1899 gl.compileShader(shaderVert); 1900 gl.compileShader(shaderFrag); 1901 1902 var program = gl.createProgram(); 1903 gl.attachShader(program, shaderVert); 1904 gl.attachShader(program, shaderFrag); 1905 gl.linkProgram(program); 1906 gl.useProgram(program); 1907 1908 var location; 1909 1910 var uniformValue = [ 1911 -1.0, 0.1, 4.0, 800.0, 1912 13.0, 55.0, 12.0, 91.0, 1913 -55.1, 1.1, 98.0, 19.0, 1914 41.0, 65.0, 4.0, 12.2, 1915 95.0, 77.0, 32.0, 48.0 1916 ]; 1917 1918 location = gl.getUniformLocation(program, 'arrayUniform'); 1919 gl.uniform1fv(location, new Float32Array(uniformValue.slice(0, 5))); 1920 1921 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'arrayUniform[0]'), uniformValue[0])); 1922 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'arrayUniform[1]'), uniformValue[1])); 1923 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'arrayUniform[2]'), uniformValue[2])); 1924 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'arrayUniform[3]'), uniformValue[3])); 1925 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'arrayUniform[4]'), uniformValue[4])); 1926 1927 location = gl.getUniformLocation(program, 'array2Uniform'); 1928 gl.uniform2fv(location, new Float32Array(uniformValue.slice(0, 10))); 1929 1930 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array2Uniform[0]'), new Float32Array([uniformValue[2 * 0], uniformValue[(2 * 0) + 1]]))); 1931 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array2Uniform[1]'), new Float32Array([uniformValue[2 * 1], uniformValue[(2 * 1) + 1]]))); 1932 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array2Uniform[2]'), new Float32Array([uniformValue[2 * 2], uniformValue[(2 * 2) + 1]]))); 1933 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array2Uniform[3]'), new Float32Array([uniformValue[2 * 3], uniformValue[(2 * 3) + 1]]))); 1934 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array2Uniform[4]'), new Float32Array([uniformValue[2 * 4], uniformValue[(2 * 4) + 1]]))); 1935 1936 location = gl.getUniformLocation(program, 'array3Uniform'); 1937 gl.uniform3fv(location, new Float32Array(uniformValue.slice(0, 15))); 1938 1939 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array3Uniform[0]'), new Float32Array([uniformValue[3 * 0], uniformValue[(3 * 0) + 1], uniformValue[(3 * 0) + 2]]))); 1940 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array3Uniform[1]'), new Float32Array([uniformValue[3 * 1], uniformValue[(3 * 1) + 1], uniformValue[(3 * 1) + 2]]))); 1941 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array3Uniform[2]'), new Float32Array([uniformValue[3 * 2], uniformValue[(3 * 2) + 1], uniformValue[(3 * 2) + 2]]))); 1942 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array3Uniform[3]'), new Float32Array([uniformValue[3 * 3], uniformValue[(3 * 3) + 1], uniformValue[(3 * 3) + 2]]))); 1943 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array3Uniform[4]'), new Float32Array([uniformValue[3 * 4], uniformValue[(3 * 4) + 1], uniformValue[(3 * 4) + 2]]))); 1944 1945 location = gl.getUniformLocation(program, 'array4Uniform'); 1946 gl.uniform4fv(location, new Float32Array(uniformValue)); 1947 1948 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array4Uniform[0]'), new Float32Array([uniformValue[4 * 0], uniformValue[(4 * 0) + 1], uniformValue[(4 * 0) + 2], uniformValue[(4 * 0) + 3]]))); 1949 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array4Uniform[1]'), new Float32Array([uniformValue[4 * 1], uniformValue[(4 * 1) + 1], uniformValue[(4 * 1) + 2], uniformValue[(4 * 1) + 3]]))); 1950 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array4Uniform[2]'), new Float32Array([uniformValue[4 * 2], uniformValue[(4 * 2) + 1], uniformValue[(4 * 2) + 2], uniformValue[(4 * 2) + 3]]))); 1951 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array4Uniform[3]'), new Float32Array([uniformValue[4 * 3], uniformValue[(4 * 3) + 1], uniformValue[(4 * 3) + 2], uniformValue[(4 * 3) + 3]]))); 1952 this.check(glsStateQuery.verifyUniform(program, gl.getUniformLocation(program, 'array4Uniform[4]'), new Float32Array([uniformValue[4 * 4], uniformValue[(4 * 4) + 1], uniformValue[(4 * 4) + 2], uniformValue[(4 * 4) + 3]]))); 1953 1954 gl.useProgram(null); 1955 gl.deleteShader(shaderVert); 1956 gl.deleteShader(shaderFrag); 1957 gl.deleteProgram(program); 1958 }; 1959 1960 /** 1961 * @constructor 1962 * @extends {es3fApiCase.ApiCase} 1963 * @param {string} name 1964 * @param {string} description 1965 */ 1966 es3fShaderStateQueryTests.UniformValueMatrixCase = function(name, description) { 1967 es3fApiCase.ApiCase.call(this, name, description, gl); 1968 }; 1969 1970 setParentClass(es3fShaderStateQueryTests.UniformValueMatrixCase, es3fApiCase.ApiCase); 1971 1972 es3fShaderStateQueryTests.UniformValueMatrixCase.prototype.test = function() { 1973 var transpose = function(rows, cols, data) { 1974 var matrix = tcuMatrix.matrixFromDataArray(rows, cols, data); 1975 var result = []; 1976 for (var col = 0; col < cols; col++) 1977 result.push(matrix.getColumn(col)); 1978 return new Float32Array([].concat.apply([], result)); 1979 }; 1980 1981 var testVertSource = 1982 '#version 300 es\n' + 1983 'uniform highp mat2 mat2Uniform;' + 1984 'uniform highp mat3 mat3Uniform;' + 1985 'uniform highp mat4 mat4Uniform;' + 1986 'void main (void)\n' + 1987 '{\n' + 1988 ' gl_Position = vec4(mat2Uniform[0][0] + mat3Uniform[0][0] + mat4Uniform[0][0]);\n' + 1989 '}\n'; 1990 var testFragSource = 1991 '#version 300 es\n' + 1992 'layout(location = 0) out mediump vec4 fragColor;' + 1993 'void main (void)\n' + 1994 '{\n' + 1995 ' fragColor = vec4(0.0);\n' + 1996 '}\n'; 1997 1998 var shaderVert = gl.createShader(gl.VERTEX_SHADER); 1999 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER); 2000 2001 gl.shaderSource(shaderVert, testVertSource); 2002 gl.shaderSource(shaderFrag, testFragSource); 2003 2004 gl.compileShader(shaderVert); 2005 gl.compileShader(shaderFrag); 2006 2007 var program = gl.createProgram(); 2008 gl.attachShader(program, shaderVert); 2009 gl.attachShader(program, shaderFrag); 2010 gl.linkProgram(program); 2011 gl.useProgram(program); 2012 2013 var location; 2014 2015 var matrixValues = [ 2016 -1.0, 0.1, 4.0, 800.0, 2017 13.0, 55.0, 12.0, 91.0, 2018 -55.1, 1.1, 98.0, 19.0, 2019 41.0, 65.0, 4.0, 12.0 2020 ]; 2021 2022 // the values of the matrix are returned in column major order but they can be given in either order 2023 2024 location = gl.getUniformLocation(program, 'mat2Uniform'); 2025 var m2 = new Float32Array(matrixValues.slice(0, 2 * 2)); 2026 gl.uniformMatrix2fv(location, false, m2); 2027 this.check(glsStateQuery.verifyUniform(program, location, m2)); 2028 gl.uniformMatrix2fv(location, true, m2); 2029 this.check(glsStateQuery.verifyUniform(program, location, transpose(2, 2, m2))); 2030 2031 location = gl.getUniformLocation(program, 'mat3Uniform'); 2032 var m3 = new Float32Array(matrixValues.slice(0, 3 * 3)); 2033 gl.uniformMatrix3fv(location, false, m3); 2034 this.check(glsStateQuery.verifyUniform(program, location, m3)); 2035 gl.uniformMatrix3fv(location, true, m3); 2036 this.check(glsStateQuery.verifyUniform(program, location, transpose(3, 3, m3))); 2037 2038 location = gl.getUniformLocation(program, 'mat4Uniform'); 2039 var m4 = new Float32Array(matrixValues.slice(0, 4 * 4)); 2040 gl.uniformMatrix4fv(location, false, m4); 2041 this.check(glsStateQuery.verifyUniform(program, location, m4)); 2042 gl.uniformMatrix4fv(location, true, m4); 2043 this.check(glsStateQuery.verifyUniform(program, location, transpose(4, 4, m4))); 2044 2045 gl.useProgram(null); 2046 gl.deleteShader(shaderVert); 2047 gl.deleteShader(shaderFrag); 2048 gl.deleteProgram(program); 2049 }; 2050 2051 /** 2052 * @constructor 2053 * @extends {es3fApiCase.ApiCase} 2054 * @param {string} name 2055 * @param {string} description 2056 * @param {number} shaderType 2057 * @param {number} precisionType 2058 */ 2059 es3fShaderStateQueryTests.PrecisionFormatCase = function(name, description, shaderType, precisionType) { 2060 es3fApiCase.ApiCase.call(this, name, description, gl); 2061 this.m_shaderType = shaderType; 2062 this.m_precisionType = precisionType; 2063 }; 2064 2065 setParentClass(es3fShaderStateQueryTests.PrecisionFormatCase, es3fApiCase.ApiCase); 2066 2067 es3fShaderStateQueryTests.PrecisionFormatCase.prototype.test = function() { 2068 var requirements = {}; 2069 requirements[gl.LOW_FLOAT] = [0, 0, 8]; 2070 requirements[gl.MEDIUM_FLOAT] = [13, 13, 10]; 2071 requirements[gl.HIGH_FLOAT] = [127, 127, 23]; 2072 requirements[gl.LOW_INT] = [8, 7, 0]; 2073 requirements[gl.MEDIUM_INT] = [15, 14, 0]; 2074 requirements[gl.HIGH_INT] = [31, 30, 0]; 2075 2076 2077 var expected = requirements[this.m_precisionType]; 2078 var result = gl.getShaderPrecisionFormat(this.m_shaderType, this.m_precisionType); 2079 2080 bufferedLogToConsole('Precision:' + 2081 ' range min = ' + result.rangeMin + 2082 ' range max = ' + result.rangeMax + 2083 ' precision = ' + result.precision); 2084 2085 if (this.m_precisionType == gl.HIGH_FLOAT) { 2086 // highp float must be IEEE 754 single 2087 2088 this.check(result.rangeMin == expected[0] || 2089 result.rangeMax == expected[1] || 2090 result.precision == expected[2], 2091 'Invalid precision format, expected:' + 2092 ' range min = ' + expected[0] + 2093 ' range max = ' + expected[1] + 2094 ' precision = ' + expected[2]); 2095 } else{ 2096 this.check(result.rangeMin >= expected[0] || 2097 result.rangeMax >= expected[1] || 2098 result.precision >= expected[2], 2099 'Invalid precision format, expected:' + 2100 ' range min >= ' + expected[0] + 2101 ' range max >= ' + expected[1] + 2102 ' precision >= ' + expected[2]); 2103 } 2104 }; 2105 2106 /** 2107 * @constructor 2108 * @extends {tcuTestCase.DeqpTest} 2109 */ 2110 es3fShaderStateQueryTests.ShaderStateQueryTests = function() { 2111 tcuTestCase.DeqpTest.call(this, 'shader', 'Shader State Query tests'); 2112 }; 2113 2114 es3fShaderStateQueryTests.ShaderStateQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype); 2115 es3fShaderStateQueryTests.ShaderStateQueryTests.prototype.constructor = es3fShaderStateQueryTests.ShaderStateQueryTests; 2116 2117 es3fShaderStateQueryTests.ShaderStateQueryTests.prototype.init = function() { 2118 // shader 2119 this.addChild(new es3fShaderStateQueryTests.ShaderTypeCase('shader_type', 'SHADER_TYPE')); 2120 this.addChild(new es3fShaderStateQueryTests.ShaderCompileStatusCase('shader_compile_status', 'COMPILE_STATUS')); 2121 this.addChild(new es3fShaderStateQueryTests.ShaderInfoLogCase('shader_info_log', 'INFO_LOG')); 2122 this.addChild(new es3fShaderStateQueryTests.ShaderSourceCase('shader_source', 'SHADER_SOURCE')); 2123 2124 // shader and program 2125 this.addChild(new es3fShaderStateQueryTests.DeleteStatusCase('delete_status', 'DELETE_STATUS')); 2126 2127 // // vertex-attrib 2128 this.addChild(new es3fShaderStateQueryTests.CurrentVertexAttribInitialCase('current_vertex_attrib_initial', 'CURRENT_VERTEX_ATTRIB')); 2129 this.addChild(new es3fShaderStateQueryTests.CurrentVertexAttribFloatCase('current_vertex_attrib_float', 'CURRENT_VERTEX_ATTRIB')); 2130 this.addChild(new es3fShaderStateQueryTests.CurrentVertexAttribIntCase('current_vertex_attrib_int', 'CURRENT_VERTEX_ATTRIB')); 2131 this.addChild(new es3fShaderStateQueryTests.CurrentVertexAttribUintCase('current_vertex_attrib_uint', 'CURRENT_VERTEX_ATTRIB')); 2132 2133 // // program 2134 this.addChild(new es3fShaderStateQueryTests.ProgramInfoLogCase('program_info_log', 'INFO_LOG')); 2135 this.addChild(new es3fShaderStateQueryTests.ProgramValidateStatusCase('program_validate_status', 'VALIDATE_STATUS')); 2136 this.addChild(new es3fShaderStateQueryTests.ProgramAttachedShadersCase('program_attached_shaders', 'ATTACHED_SHADERS')); 2137 2138 this.addChild(new es3fShaderStateQueryTests.ProgramActiveUniformNameCase('program_active_uniform_name', 'ACTIVE_UNIFORMS')); 2139 this.addChild(new es3fShaderStateQueryTests.ProgramUniformCase('program_active_uniform_types', 'UNIFORM_TYPE, UNIFORM_SIZE, and UNIFORM_IS_ROW_MAJOR')); 2140 this.addChild(new es3fShaderStateQueryTests.ProgramActiveUniformBlocksCase ("program_active_uniform_blocks", "ACTIVE_UNIFORM_BLOCK_x")); 2141 2142 // transform feedback 2143 this.addChild(new es3fShaderStateQueryTests.TransformFeedbackCase('transform_feedback', 'TRANSFORM_FEEDBACK_BUFFER_MODE, TRANSFORM_FEEDBACK_VARYINGS, TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH')); 2144 2145 // attribute related 2146 this.addChild(new es3fShaderStateQueryTests.ActiveAttributesCase('active_attributes', 'ACTIVE_ATTRIBUTES and ACTIVE_ATTRIBUTE_MAX_LENGTH')); 2147 this.addChild(new es3fShaderStateQueryTests.VertexAttributeSizeCase('vertex_attrib_size', 'VERTEX_ATTRIB_ARRAY_SIZE')); 2148 this.addChild(new es3fShaderStateQueryTests.VertexAttributeTypeCase('vertex_attrib_type', 'VERTEX_ATTRIB_ARRAY_TYPE')); 2149 this.addChild(new es3fShaderStateQueryTests.VertexAttributeStrideCase('vertex_attrib_stride', 'VERTEX_ATTRIB_ARRAY_STRIDE')); 2150 this.addChild(new es3fShaderStateQueryTests.VertexAttributeNormalizedCase('vertex_attrib_normalized', 'VERTEX_ATTRIB_ARRAY_NORMALIZED')); 2151 this.addChild(new es3fShaderStateQueryTests.VertexAttributeIntegerCase('vertex_attrib_integer', 'VERTEX_ATTRIB_ARRAY_INTEGER')); 2152 this.addChild(new es3fShaderStateQueryTests.VertexAttributeEnabledCase('vertex_attrib_array_enabled', 'VERTEX_ATTRIB_ARRAY_ENABLED')); 2153 this.addChild(new es3fShaderStateQueryTests.VertexAttributeDivisorCase('vertex_attrib_array_divisor', 'VERTEX_ATTRIB_ARRAY_DIVISOR')); 2154 this.addChild(new es3fShaderStateQueryTests.VertexAttributeBufferBindingCase('vertex_attrib_array_buffer_binding', 'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING')); 2155 this.addChild(new es3fShaderStateQueryTests.VertexAttributeOffsetCase('vertex_attrib_offset', 'VERTEX_ATTRIB_ARRAY_POINTER')); 2156 2157 // uniform values 2158 this.addChild(new es3fShaderStateQueryTests.UniformValueFloatCase('uniform_value_float', 'GetUniform*')); 2159 this.addChild(new es3fShaderStateQueryTests.UniformValueIntCase('uniform_value_int', 'GetUniform*')); 2160 this.addChild(new es3fShaderStateQueryTests.UniformValueUintCase('uniform_value_uint', 'GetUniform*')); 2161 this.addChild(new es3fShaderStateQueryTests.UniformValueBooleanCase('uniform_value_boolean', 'GetUniform*')); 2162 this.addChild(new es3fShaderStateQueryTests.UniformValueSamplerCase('uniform_value_sampler', 'GetUniform*')); 2163 this.addChild(new es3fShaderStateQueryTests.UniformValueArrayCase('uniform_value_array', 'GetUniform*')); 2164 this.addChild(new es3fShaderStateQueryTests.UniformValueMatrixCase('uniform_value_matrix', 'GetUniform*')); 2165 2166 // precision format query 2167 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_lowp_float', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.LOW_FLOAT)); 2168 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_mediump_float', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.MEDIUM_FLOAT)); 2169 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_highp_float', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.HIGH_FLOAT)); 2170 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_lowp_int', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.LOW_INT)); 2171 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_mediump_int', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.MEDIUM_INT)); 2172 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_vertex_highp_int', 'GetShaderPrecisionFormat', gl.VERTEX_SHADER, gl.HIGH_INT)); 2173 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_lowp_float', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.LOW_FLOAT)); 2174 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_mediump_float', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT)); 2175 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_highp_float', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.HIGH_FLOAT)); 2176 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_lowp_int', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.LOW_INT)); 2177 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_mediump_int', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.MEDIUM_INT)); 2178 this.addChild(new es3fShaderStateQueryTests.PrecisionFormatCase('precision_fragment_highp_int', 'GetShaderPrecisionFormat', gl.FRAGMENT_SHADER, gl.HIGH_INT)); 2179 }; 2180 2181 /** 2182 * Run test 2183 * @param {WebGL2RenderingContext} context 2184 */ 2185 es3fShaderStateQueryTests.run = function(context) { 2186 gl = context; 2187 //Set up Test Root parameters 2188 var state = tcuTestCase.runner; 2189 state.setRoot(new es3fShaderStateQueryTests.ShaderStateQueryTests()); 2190 2191 //Set up name and description of this test series. 2192 setCurrentTestName(state.testCases.fullName()); 2193 description(state.testCases.getDescription()); 2194 2195 try { 2196 //Run test cases 2197 tcuTestCase.runTestCases(); 2198 } 2199 catch (err) { 2200 testFailedOptions('Failed to es3fShaderStateQueryTests.run tests', false); 2201 tcuTestCase.runner.terminate(); 2202 } 2203 }; 2204 2205 });