Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / deqp / modules / shared / glsVertexArrayTests.js
blob99dc79f35e8822f0bbfe441c1be18fe3ca3eff8e
1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 'use strict';
22 goog.provide('modules.shared.glsVertexArrayTests');
23 goog.require('framework.common.tcuFloat');
24 goog.require('framework.common.tcuImageCompare');
25 goog.require('framework.common.tcuLogImage');
26 goog.require('framework.common.tcuPixelFormat');
27 goog.require('framework.common.tcuRGBA');
28 goog.require('framework.common.tcuSurface');
29 goog.require('framework.common.tcuTestCase');
30 goog.require('framework.delibs.debase.deMath');
31 goog.require('framework.delibs.debase.deRandom');
32 goog.require('framework.opengl.gluShaderUtil');
33 goog.require('framework.opengl.simplereference.sglrGLContext');
34 goog.require('framework.opengl.simplereference.sglrReferenceContext');
35 goog.require('framework.opengl.simplereference.sglrShaderProgram');
36 goog.require('framework.referencerenderer.rrFragmentOperations');
37 goog.require('framework.referencerenderer.rrGenericVector');
38 goog.require('framework.referencerenderer.rrShadingContext');
39 goog.require('framework.referencerenderer.rrVertexAttrib');
40 goog.require('framework.referencerenderer.rrVertexPacket');
42 goog.scope(function() {
44 var glsVertexArrayTests = modules.shared.glsVertexArrayTests;
45 var tcuTestCase = framework.common.tcuTestCase;
46 var tcuRGBA = framework.common.tcuRGBA;
47 var tcuFloat = framework.common.tcuFloat;
48 var tcuPixelFormat = framework.common.tcuPixelFormat;
49 var tcuSurface = framework.common.tcuSurface;
50 var tcuImageCompare = framework.common.tcuImageCompare;
51 var tcuLogImage = framework.common.tcuLogImage;
52 var gluShaderUtil = framework.opengl.gluShaderUtil;
53 var sglrGLContext = framework.opengl.simplereference.sglrGLContext;
54 var sglrReferenceContext = framework.opengl.simplereference.sglrReferenceContext;
55 var sglrShaderProgram = framework.opengl.simplereference.sglrShaderProgram;
56 var deMath = framework.delibs.debase.deMath;
57 var deRandom = framework.delibs.debase.deRandom;
58 var rrFragmentOperations = framework.referencerenderer.rrFragmentOperations;
59 var rrGenericVector = framework.referencerenderer.rrGenericVector;
60 var rrShadingContext = framework.referencerenderer.rrShadingContext;
61 var rrVertexAttrib = framework.referencerenderer.rrVertexAttrib;
62 var rrVertexPacket = framework.referencerenderer.rrVertexPacket;
64 var DE_ASSERT = function(x) {
65 if (!x)
66 throw new Error('Assert failed');
69 /**
70 * @interface
72 glsVertexArrayTests.deArray = function() {};
74 /**
75 * glsVertexArrayTests.deArray.Target enum
76 * @enum
78 glsVertexArrayTests.deArray.Target = {
79 ELEMENT_ARRAY: 0,
80 ARRAY: 1
83 /**
84 * glsVertexArrayTests.deArray.InputType enum
85 * @enum
87 glsVertexArrayTests.deArray.InputType = {
88 FLOAT: 0,
89 /*FIXED: 1,
90 DOUBLE: 2,*/
92 BYTE: 1,
93 SHORT: 2,
95 UNSIGNED_BYTE: 3,
96 UNSIGNED_SHORT: 4,
98 INT: 5,
99 UNSIGNED_INT: 6,
100 HALF: 7,
101 UNSIGNED_INT_2_10_10_10: 8,
102 INT_2_10_10_10: 9
106 * glsVertexArrayTests.deArray.OutputType enum
107 * @enum
109 glsVertexArrayTests.deArray.OutputType = {
110 FLOAT: 0,
111 VEC2: 1,
112 VEC3: 2,
113 VEC4: 3,
115 INT: 4,
116 UINT: 5,
118 IVEC2: 6,
119 IVEC3: 7,
120 IVEC4: 8,
122 UVEC2: 9,
123 UVEC3: 10,
124 UVEC4: 11
128 * glsVertexArrayTests.deArray.Usage enum
129 * @enum
131 glsVertexArrayTests.deArray.Usage = {
132 DYNAMIC_DRAW: 0,
133 STATIC_DRAW: 1,
134 STREAM_DRAW: 2,
136 STREAM_READ: 3,
137 STREAM_COPY: 4,
139 STATIC_READ: 5,
140 STATIC_COPY: 6,
142 DYNAMIC_READ: 7,
143 DYNAMIC_COPY: 8
147 * glsVertexArrayTests.deArray.Storage enum
148 * @enum
150 glsVertexArrayTests.deArray.Storage = {
151 USER: 0,
152 BUFFER: 1
156 * glsVertexArrayTests.deArray.Primitive enum
157 * @enum
159 glsVertexArrayTests.deArray.Primitive = {
160 POINTS: 0,
161 TRIANGLES: 1,
162 TRIANGLE_FAN: 2,
163 TRIANGLE_STRIP: 3
166 //glsVertexArrayTests.deArray static functions
169 * @param {glsVertexArrayTests.deArray.Target} target
170 * @return {string}
172 glsVertexArrayTests.deArray.targetToString = function(target) {
173 DE_ASSERT(target < Object.keys(glsVertexArrayTests.deArray.Target).length);
175 /** @type {Array<string>} */ var targets =
177 'element_array', // glsVertexArrayTests.deArray.Target.ELEMENT_ARRAY
178 'array' // glsVertexArrayTests.deArray.Target.ARRAY
180 DE_ASSERT(targets.length == Object.keys(glsVertexArrayTests.deArray.Target).length);
182 return targets[target];
186 * @param {glsVertexArrayTests.deArray.InputType} type
187 * @return {string}
189 glsVertexArrayTests.deArray.inputTypeToString = function(type) {
190 DE_ASSERT(type < Object.keys(glsVertexArrayTests.deArray.InputType).length);
192 /** @type {Array<string>} */ var types =
194 'float', // glsVertexArrayTests.deArray.InputType.FLOAT
196 'byte', // glsVertexArrayTests.deArray.InputType.BYTE
197 'short', // glsVertexArrayTests.deArray.InputType.SHORT
199 'unsigned_byte', // glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE
200 'unsigned_short', // glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT
202 'int', // glsVertexArrayTests.deArray.InputType.INT
203 'unsigned_int', // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT
204 'half', // glsVertexArrayTests.deArray.InputType.HALF
205 'unsigned_int2_10_10_10', // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10
206 'int2_10_10_10' // glsVertexArrayTests.deArray.InputType.INT_2_10_10_10
208 DE_ASSERT(types.length == Object.keys(glsVertexArrayTests.deArray.InputType).length);
210 return types[type];
214 * @param {glsVertexArrayTests.deArray.OutputType} type
215 * @return {string}
217 glsVertexArrayTests.deArray.outputTypeToString = function(type) {
218 DE_ASSERT(type < Object.keys(glsVertexArrayTests.deArray.OutputType).length);
220 /** @type {Array<string>} */ var types =
222 'float', // glsVertexArrayTests.deArray.OutputType.FLOAT
223 'vec2', // glsVertexArrayTests.deArray.OutputType.VEC2
224 'vec3', // glsVertexArrayTests.deArray.OutputType.VEC3
225 'vec4', // glsVertexArrayTests.deArray.OutputType.VEC4
227 'int', // glsVertexArrayTests.deArray.OutputType.INT
228 'uint', // glsVertexArrayTests.deArray.OutputType.UINT
230 'ivec2', // glsVertexArrayTests.deArray.OutputType.IVEC2
231 'ivec3', // glsVertexArrayTests.deArray.OutputType.IVEC3
232 'ivec4', // glsVertexArrayTests.deArray.OutputType.IVEC4
234 'uvec2', // glsVertexArrayTests.deArray.OutputType.UVEC2
235 'uvec3', // glsVertexArrayTests.deArray.OutputType.UVEC3
236 'uvec4' // glsVertexArrayTests.deArray.OutputType.UVEC4
238 DE_ASSERT(types.length == Object.keys(glsVertexArrayTests.deArray.OutputType).length);
240 return types[type];
244 * @param {glsVertexArrayTests.deArray.Usage} usage
245 * @return {string}
247 glsVertexArrayTests.deArray.usageTypeToString = function(usage) {
248 DE_ASSERT(usage < Object.keys(glsVertexArrayTests.deArray.Usage).length);
250 /** @type {Array<string>} */ var usages =
252 'dynamic_draw', // glsVertexArrayTests.deArray.Usage.DYNAMIC_DRAW
253 'static_draw', // glsVertexArrayTests.deArray.Usage.STATIC_DRAW
254 'stream_draw', // glsVertexArrayTests.deArray.Usage.STREAM_DRAW
256 'stream_read', // glsVertexArrayTests.deArray.Usage.STREAM_READ
257 'stream_copy', // glsVertexArrayTests.deArray.Usage.STREAM_COPY
259 'static_read', // glsVertexArrayTests.deArray.Usage.STATIC_READ
260 'static_copy', // glsVertexArrayTests.deArray.Usage.STATIC_COPY
262 'dynamic_read', // glsVertexArrayTests.deArray.Usage.DYNAMIC_READ
263 'dynamic_copy' // glsVertexArrayTests.deArray.Usage.DYNAMIC_COPY
265 DE_ASSERT(usages.length == Object.keys(glsVertexArrayTests.deArray.Usage).length);
267 return usages[usage];
271 * @param {glsVertexArrayTests.deArray.Storage} storage
272 * @return {string}
274 glsVertexArrayTests.deArray.storageToString = function(storage) {
275 DE_ASSERT(storage < Object.keys(glsVertexArrayTests.deArray.Storage).length);
277 /** @type {Array<string>} */ var storages =
279 'user_ptr', // glsVertexArrayTests.deArray.Storage.USER
280 'buffer' // glsVertexArrayTests.deArray.Storage.BUFFER
282 DE_ASSERT(storages.length == Object.keys(glsVertexArrayTests.deArray.Storage).length);
284 return storages[storage];
288 * @param {glsVertexArrayTests.deArray.Primitive} primitive
289 * @return {string}
291 glsVertexArrayTests.deArray.primitiveToString = function(primitive) {
292 DE_ASSERT(primitive < Object.keys(glsVertexArrayTests.deArray.Primitive).length);
294 /** @type {Array<string>} */ var primitives =
296 'points', // glsVertexArrayTests.deArray.Primitive.POINTS
297 'triangles', // glsVertexArrayTests.deArray.Primitive.TRIANGLES
298 'triangle_fan', // glsVertexArrayTests.deArray.Primitive.TRIANGLE_FAN
299 'triangle_strip' // glsVertexArrayTests.deArray.Primitive.TRIANGLE_STRIP
301 DE_ASSERT(primitives.length == Object.keys(glsVertexArrayTests.deArray.Primitive).length);
303 return primitives[primitive];
307 * @param {glsVertexArrayTests.deArray.InputType} type
308 * @return {number}
310 glsVertexArrayTests.deArray.inputTypeSize = function(type) {
311 DE_ASSERT(type < Object.keys(glsVertexArrayTests.deArray.InputType).length);
313 /** @type {Array<number>} */ var size = [
314 4, // glsVertexArrayTests.deArray.InputType.FLOAT
316 1, // glsVertexArrayTests.deArray.InputType.BYTE
317 2, // glsVertexArrayTests.deArray.InputType.SHORT
319 1, // glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE
320 2, // glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT
322 4, // glsVertexArrayTests.deArray.InputType.INT
323 4, // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT
324 2, // glsVertexArrayTests.deArray.InputType.HALF
325 4 / 4, // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10
326 4 / 4 // glsVertexArrayTests.deArray.InputType.INT_2_10_10_10
328 DE_ASSERT(size.length == Object.keys(glsVertexArrayTests.deArray.InputType).length);
330 return size[type];
334 * @param {glsVertexArrayTests.deArray.InputType} type
335 * @return {boolean}
337 glsVertexArrayTests.inputTypeIsFloatType = function(type) {
338 if (type == glsVertexArrayTests.deArray.InputType.FLOAT)
339 return true;
340 /*if (type == glsVertexArrayTests.deArray.InputType.FIXED)
341 return true;
342 if (type == glsVertexArrayTests.deArray.InputType.DOUBLE)
343 return true;*/
344 if (type == glsVertexArrayTests.deArray.InputType.HALF)
345 return true;
346 return false;
350 * @param {glsVertexArrayTests.deArray.OutputType} type
351 * @return {boolean}
353 glsVertexArrayTests.outputTypeIsFloatType = function(type) {
354 if (type == glsVertexArrayTests.deArray.OutputType.FLOAT ||
355 type == glsVertexArrayTests.deArray.OutputType.VEC2 ||
356 type == glsVertexArrayTests.deArray.OutputType.VEC3 ||
357 type == glsVertexArrayTests.deArray.OutputType.VEC4)
358 return true;
360 return false;
363 //glsVertexArrayTests.deArray member functions (all virtual, since this is an interface)
366 * @param {glsVertexArrayTests.deArray.Target} target
367 * @param {number} size
368 * @param {Uint8Array} data
369 * @param {glsVertexArrayTests.deArray.Usage} usage
371 glsVertexArrayTests.deArray.prototype.data = function(target, size, data, usage) {};
374 * @param {glsVertexArrayTests.deArray.Target} target
375 * @param {number} offset
376 * @param {number} size
377 * @param {Uint8Array} data
379 glsVertexArrayTests.deArray.prototype.subdata = function(target, offset, size, data) {};
382 * @param {number} attribNdx
383 * @param {number} offset
384 * @param {number} size
385 * @param {glsVertexArrayTests.deArray.InputType} inType
386 * @param {glsVertexArrayTests.deArray.OutputType} outType
387 * @param {boolean} normalized
388 * @param {number} stride
390 glsVertexArrayTests.deArray.prototype.bind = function(attribNdx, offset, size, inType, outType, normalized, stride) {};
393 * unBind
395 glsVertexArrayTests.deArray.prototype.unBind = function() {};
398 * @return {boolean}
400 glsVertexArrayTests.deArray.prototype.isBound = function() {};
403 * @return {number}
405 glsVertexArrayTests.deArray.prototype.getComponentCount = function() {};
408 * @return {glsVertexArrayTests.deArray.Target}
410 glsVertexArrayTests.deArray.prototype.getTarget = function() {};
413 * @return {glsVertexArrayTests.deArray.InputType}
415 glsVertexArrayTests.deArray.prototype.getInputType = function() {};
418 * @return {glsVertexArrayTests.deArray.OutputType}
420 glsVertexArrayTests.deArray.prototype.getOutputType = function() {};
423 * @return {glsVertexArrayTests.deArray.Storage}
425 glsVertexArrayTests.deArray.prototype.getStorageType = function() {};
428 * @return {boolean}
430 glsVertexArrayTests.deArray.prototype.getNormalized = function() {};
433 * @return {number}
435 glsVertexArrayTests.deArray.prototype.getStride = function() {};
438 * @return {number}
440 glsVertexArrayTests.deArray.prototype.getAttribNdx = function() {};
443 * @param {number} attribNdx
445 glsVertexArrayTests.deArray.prototype.setAttribNdx = function(attribNdx) {};
447 //glsVertexArrayTests.ContextArray class, implements glsVertexArrayTests.deArray interface
450 * @constructor
451 * @implements {glsVertexArrayTests.deArray}
452 * @param {glsVertexArrayTests.deArray.Storage} storage
453 * @param {sglrGLContext.GLContext | sglrReferenceContext.ReferenceContext} context
455 glsVertexArrayTests.ContextArray = function(storage, context) {
456 /** @type {glsVertexArrayTests.deArray.Storage} */ this.m_storage = storage;
457 /** @type {sglrGLContext.GLContext | sglrReferenceContext.ReferenceContext} */ this.m_ctx = context;
458 /** @type {WebGLBuffer|sglrReferenceContext.DataBuffer|null} */ this.m_glBuffer = null;
460 /** @type {boolean} */ this.m_bound = false;
461 /** @type {number} */ this.m_attribNdx = 0;
462 /** @type {number} */ this.m_size = 0;
463 /** @type {Uint8Array} */ this.m_data = null;
464 /** @type {number} */ this.m_componentCount = 1;
465 /** @type {glsVertexArrayTests.deArray.Target} */ this.m_target = glsVertexArrayTests.deArray.Target.ARRAY;
466 /** @type {glsVertexArrayTests.deArray.InputType} */ this.m_inputType = glsVertexArrayTests.deArray.InputType.FLOAT;
467 /** @type {glsVertexArrayTests.deArray.OutputType} */ this.m_outputType = glsVertexArrayTests.deArray.OutputType.FLOAT;
468 /** @type {boolean} */ this.m_normalize = false;
469 /** @type {number} */ this.m_stride = 0;
470 /** @type {number} */ this.m_offset = 0;
472 if (this.m_storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
473 this.m_glBuffer = this.m_ctx.createBuffer();
477 // glsVertexArrayTests.ContextArray member functions
480 * unBind
482 glsVertexArrayTests.ContextArray.prototype.unBind = function() { this.m_bound = false; };
485 * @return {boolean}
487 glsVertexArrayTests.ContextArray.prototype.isBound = function() { return this.m_bound; };
490 * @return {number}
492 glsVertexArrayTests.ContextArray.prototype.getComponentCount = function() { return this.m_componentCount; };
495 * @return {glsVertexArrayTests.deArray.Target}
497 glsVertexArrayTests.ContextArray.prototype.getTarget = function() { return this.m_target; };
500 * @return {glsVertexArrayTests.deArray.InputType}
502 glsVertexArrayTests.ContextArray.prototype.getInputType = function() { return this.m_inputType; };
505 * @return {glsVertexArrayTests.deArray.OutputType}
507 glsVertexArrayTests.ContextArray.prototype.getOutputType = function() { return this.m_outputType; };
510 * @return {glsVertexArrayTests.deArray.Storage}
512 glsVertexArrayTests.ContextArray.prototype.getStorageType = function() { return this.m_storage; };
515 * @return {boolean}
517 glsVertexArrayTests.ContextArray.prototype.getNormalized = function() { return this.m_normalize; };
520 * @return {number}
522 glsVertexArrayTests.ContextArray.prototype.getStride = function() { return this.m_stride; };
525 * @return {number}
527 glsVertexArrayTests.ContextArray.prototype.getAttribNdx = function() { return this.m_attribNdx; };
530 * @param {number} attribNdx
532 glsVertexArrayTests.ContextArray.prototype.setAttribNdx = function(attribNdx) { this.m_attribNdx = attribNdx; };
535 * @param {glsVertexArrayTests.deArray.Target} target
536 * @param {number} size
537 * @param {Uint8Array} ptr
538 * @param {glsVertexArrayTests.deArray.Usage} usage
540 glsVertexArrayTests.ContextArray.prototype.data = function(target, size, ptr, usage) {
541 this.m_size = size;
542 this.m_target = target;
544 if (this.m_storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
545 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(target), this.m_glBuffer);
547 //No need for size param here, as opposed to GL ES.
548 this.m_ctx.bufferData(glsVertexArrayTests.ContextArray.targetToGL(target), ptr, glsVertexArrayTests.ContextArray.usageToGL(usage));
549 } else if (this.m_storage == glsVertexArrayTests.deArray.Storage.USER) {
550 this.m_data = new Uint8Array(size);
551 for (var i = 0; i < size; i++)
552 this.m_data[i] = ptr[i];
553 } else
554 throw new Error('glsVertexArrayTests.ContextArray.prototype.data - Invalid storage type specified');
558 * @param {glsVertexArrayTests.deArray.Target} target
559 * @param {number} offset
560 * @param {number} size
561 * @param {Uint8Array} ptr
563 glsVertexArrayTests.ContextArray.prototype.subdata = function(target, offset, size, ptr) {
564 this.m_target = target;
566 if (this.m_storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
567 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(target), this.m_glBuffer);
569 this.m_ctx.bufferSubData(glsVertexArrayTests.ContextArray.targetToGL(target), offset, ptr);
570 } else if (this.m_storage == glsVertexArrayTests.deArray.Storage.USER)
571 for (var i = offset; i < size; i++)
572 this.m_data[i] = ptr[i];
573 else
574 throw new Error('glsVertexArrayTests.ContextArray.prototype.subdata - Invalid storage type specified');
578 * @param {number} attribNdx
579 * @param {number} offset
580 * @param {number} size
581 * @param {glsVertexArrayTests.deArray.InputType} inType
582 * @param {glsVertexArrayTests.deArray.OutputType} outType
583 * @param {boolean} normalized
584 * @param {number} stride
586 glsVertexArrayTests.ContextArray.prototype.bind = function(attribNdx, offset, size, inType, outType, normalized, stride) {
587 this.m_attribNdx = attribNdx;
588 this.m_bound = true;
589 this.m_componentCount = size;
590 this.m_inputType = inType;
591 this.m_outputType = outType;
592 this.m_normalize = normalized;
593 this.m_stride = stride;
594 this.m_offset = offset;
598 * @param {glsVertexArrayTests.deArray.Target} target
600 glsVertexArrayTests.ContextArray.prototype.bindIndexArray = function(target) {
601 if (this.m_storage == glsVertexArrayTests.deArray.Storage.USER) {
602 } else if (this.m_storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
603 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(target), this.m_glBuffer);
608 * @param {number} loc
610 glsVertexArrayTests.ContextArray.prototype.glBind = function(loc) {
611 if (this.m_storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
612 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(this.m_target), this.m_glBuffer);
614 if (!glsVertexArrayTests.inputTypeIsFloatType(this.m_inputType)) {
615 // Input is not float type
617 if (glsVertexArrayTests.outputTypeIsFloatType(this.m_outputType)) {
618 // Output type is float type
619 this.m_ctx.vertexAttribPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_normalize, this.m_stride, this.m_offset);
620 } else {
621 // Output type is int type
622 this.m_ctx.vertexAttribIPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_stride, this.m_offset);
624 } else {
625 // Input type is float type
626 // Output type must be float type
627 DE_ASSERT(this.m_outputType == glsVertexArrayTests.deArray.OutputType.FLOAT || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC2 || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC3 || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC4);
629 this.m_ctx.vertexAttribPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_normalize, this.m_stride, this.m_offset);
632 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(this.m_target), null);
633 } else if (this.m_storage == glsVertexArrayTests.deArray.Storage.USER) {
634 this.m_ctx.bindBuffer(glsVertexArrayTests.ContextArray.targetToGL(this.m_target), null);
636 if (!glsVertexArrayTests.inputTypeIsFloatType(this.m_inputType)) {
637 // Input is not float type
639 if (glsVertexArrayTests.outputTypeIsFloatType(this.m_outputType)) {
640 // Output type is float type
641 this.m_ctx.vertexAttribPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_normalize, this.m_stride, this.m_data.subarray(this.m_offset));
642 } else {
643 // Output type is int type
644 this.m_ctx.vertexAttribIPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_stride, this.m_data.subarray(this.m_offset));
646 } else {
647 // Input type is float type
649 // Output type must be float type
650 DE_ASSERT(this.m_outputType == glsVertexArrayTests.deArray.OutputType.FLOAT || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC2 || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC3 || this.m_outputType == glsVertexArrayTests.deArray.OutputType.VEC4);
652 this.m_ctx.vertexAttribPointer(loc, this.m_componentCount, glsVertexArrayTests.ContextArray.inputTypeToGL(this.m_inputType), this.m_normalize, this.m_stride, this.m_data.subarray(this.m_offset));
654 } else
655 throw new Error('glsVertexArrayTests.ContextArray.prototype.glBind - Invalid storage type specified');
658 //glsVertexArrayTests.ContextArray static functions
661 * @param {glsVertexArrayTests.deArray.Target} target
662 * @return {number}
664 glsVertexArrayTests.ContextArray.targetToGL = function(target) {
665 DE_ASSERT(target < Object.keys(glsVertexArrayTests.deArray.Target).length);
667 /** @type {Array<number>} */ var targets =
669 gl.ELEMENT_ARRAY_BUFFER, // glsVertexArrayTests.deArray.Target.ELEMENT_ARRAY
670 gl.ARRAY_BUFFER // glsVertexArrayTests.deArray.Target.ARRAY
673 return targets[target];
677 * @param {glsVertexArrayTests.deArray.Usage} usage
678 * @return {number}
680 glsVertexArrayTests.ContextArray.usageToGL = function(usage) {
681 DE_ASSERT(usage < Object.keys(glsVertexArrayTests.deArray.Usage).length);
683 /** @type {Array<number>} */ var usages =
685 gl.DYNAMIC_DRAW, // glsVertexArrayTests.deArray.Usage.DYNAMIC_DRAW
686 gl.STATIC_DRAW, // glsVertexArrayTests.deArray.Usage.STATIC_DRAW
687 gl.STREAM_DRAW, // glsVertexArrayTests.deArray.Usage.STREAM_DRAW
689 gl.STREAM_READ, // glsVertexArrayTests.deArray.Usage.STREAM_READ
690 gl.STREAM_COPY, // glsVertexArrayTests.deArray.Usage.STREAM_COPY
692 gl.STATIC_READ, // glsVertexArrayTests.deArray.Usage.STATIC_READ
693 gl.STATIC_COPY, // glsVertexArrayTests.deArray.Usage.STATIC_COPY
695 gl.DYNAMIC_READ, // glsVertexArrayTests.deArray.Usage.DYNAMIC_READ
696 gl.DYNAMIC_COPY // glsVertexArrayTests.deArray.Usage.DYNAMIC_COPY
698 DE_ASSERT(usages.length == Object.keys(glsVertexArrayTests.deArray.Usage).length);
700 return usages[usage];
704 * @param {glsVertexArrayTests.deArray.InputType} type
705 * @return {number}
707 glsVertexArrayTests.ContextArray.inputTypeToGL = function(type) {
708 DE_ASSERT(type < Object.keys(glsVertexArrayTests.deArray.InputType).length);
710 /** @type {Array<number>} */ var types =
712 gl.FLOAT, // glsVertexArrayTests.deArray.InputType.FLOAT
714 gl.BYTE, // glsVertexArrayTests.deArray.InputType.BYTE
715 gl.SHORT, // glsVertexArrayTests.deArray.InputType.SHORT
716 gl.UNSIGNED_BYTE, // glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE
717 gl.UNSIGNED_SHORT, // glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT
719 gl.INT, // glsVertexArrayTests.deArray.InputType.INT
720 gl.UNSIGNED_INT, // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT
721 gl.HALF_FLOAT, // glsVertexArrayTests.deArray.InputType.HALF
722 gl.UNSIGNED_INT_2_10_10_10_REV, // glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10
723 gl.INT_2_10_10_10_REV // glsVertexArrayTests.deArray.InputType.INT_2_10_10_10
725 DE_ASSERT(types.length == Object.keys(glsVertexArrayTests.deArray.InputType).length);
727 return types[type];
731 * @param {glsVertexArrayTests.deArray.OutputType} type
732 * @return {string}
734 glsVertexArrayTests.ContextArray.outputTypeToGLType = function(type) {
735 DE_ASSERT(type < Object.keys(glsVertexArrayTests.deArray.OutputType).length);
737 /** @type {Array<string>} */ var types =
739 'float', // glsVertexArrayTests.deArray.OutputType.FLOAT
740 'vec2', // glsVertexArrayTests.deArray.OutputType.VEC2
741 'vec3', // glsVertexArrayTests.deArray.OutputType.VEC3
742 'vec4', // glsVertexArrayTests.deArray.OutputType.VEC4
744 'int', // glsVertexArrayTests.deArray.OutputType.INT
745 'uint', // glsVertexArrayTests.deArray.OutputType.UINT
747 'ivec2', // glsVertexArrayTests.deArray.OutputType.IVEC2
748 'ivec3', // glsVertexArrayTests.deArray.OutputType.IVEC3
749 'ivec4', // glsVertexArrayTests.deArray.OutputType.IVEC4
751 'uvec2', // glsVertexArrayTests.deArray.OutputType.UVEC2
752 'uvec3', // glsVertexArrayTests.deArray.OutputType.UVEC3
753 'uvec4' // glsVertexArrayTests.deArray.OutputType.UVEC4
755 DE_ASSERT(types.length == Object.keys(glsVertexArrayTests.deArray.OutputType).length);
757 return types[type];
761 * @param {glsVertexArrayTests.deArray.Primitive} primitive
762 * @return {number}
764 glsVertexArrayTests.ContextArray.primitiveToGL = function(primitive) {
765 /** @type {Array<number>} */ var primitives =
767 gl.POINTS, // glsVertexArrayTests.deArray.Primitive.POINTS
768 gl.TRIANGLES, // glsVertexArrayTests.deArray.Primitive.TRIANGLES
769 gl.TRIANGLE_FAN, // glsVertexArrayTests.deArray.Primitive.TRIANGLE_FAN
770 gl.TRIANGLE_STRIP // glsVertexArrayTests.deArray.Primitive.TRIANGLE_STRIP
772 DE_ASSERT(primitives.length == Object.keys(glsVertexArrayTests.deArray.Primitive).length);
774 return primitives[primitive];
778 * @constructor
779 * @param {sglrGLContext.GLContext | sglrReferenceContext.ReferenceContext} drawContext
781 glsVertexArrayTests.ContextArrayPack = function(drawContext) {
782 /** @type {WebGLRenderingContextBase} */ this.m_renderCtx = gl;
783 //TODO: Reference rasterizer implementation.
784 /** @type {sglrGLContext.GLContext | sglrReferenceContext.ReferenceContext} */ this.m_ctx = drawContext;
786 /** @type {Array<glsVertexArrayTests.ContextArray>} */ this.m_arrays = [];
787 /** @type {sglrShaderProgram.ShaderProgram} */ this.m_program;
788 /** @type {tcuSurface.Surface} */ this.m_screen = new tcuSurface.Surface(
789 Math.min(512, canvas.width),
790 Math.min(512, canvas.height)
795 * @return {number}
797 glsVertexArrayTests.ContextArrayPack.prototype.getArrayCount = function() {
798 return this.m_arrays.length;
802 * @param {glsVertexArrayTests.deArray.Storage} storage
804 glsVertexArrayTests.ContextArrayPack.prototype.newArray = function(storage) {
805 this.m_arrays.push(new glsVertexArrayTests.ContextArray(storage, this.m_ctx));
809 * @param {number} i
810 * @return {glsVertexArrayTests.ContextArray}
812 glsVertexArrayTests.ContextArrayPack.prototype.getArray = function(i) {
813 return this.m_arrays[i];
817 * updateProgram
819 glsVertexArrayTests.ContextArrayPack.prototype.updateProgram = function() {
820 this.m_program = new glsVertexArrayTests.ContextShaderProgram(this.m_renderCtx, this.m_arrays);
824 * @param {glsVertexArrayTests.deArray.Primitive} primitive
825 * @param {number} firstVertex
826 * @param {number} vertexCount
827 * @param {boolean} useVao
828 * @param {number} coordScale
829 * @param {number} colorScale
831 glsVertexArrayTests.ContextArrayPack.prototype.render = function(primitive, firstVertex, vertexCount, useVao, coordScale, colorScale) {
832 var program;
833 /** @type {(WebGLVertexArrayObject|sglrReferenceContext.VertexArray|null)} */ var vaoID = null;
835 this.updateProgram();
837 this.m_ctx.viewport(0, 0, this.m_screen.getWidth(), this.m_screen.getHeight());
838 this.m_ctx.clearColor(0.0, 0.0, 0.0, 1.0);
839 this.m_ctx.clear(gl.COLOR_BUFFER_BIT);
841 program = this.m_ctx.createProgram(this.m_program);
843 this.m_ctx.useProgram(program);
845 this.m_ctx.uniform1f(this.m_ctx.getUniformLocation(program, 'u_coordScale'), coordScale);
846 this.m_ctx.uniform1f(this.m_ctx.getUniformLocation(program, 'u_colorScale'), colorScale);
848 if (useVao) {
849 vaoID = this.m_ctx.createVertexArray();
850 this.m_ctx.bindVertexArray(vaoID);
853 /** @type {string} */ var attribName;
854 /** @type {number} */ var loc;
855 for (var arrayNdx = 0; arrayNdx < this.m_arrays.length; arrayNdx++) {
856 if (this.m_arrays[arrayNdx].isBound()) {
857 attribName = 'a_' + this.m_arrays[arrayNdx].getAttribNdx();
858 loc = this.m_ctx.getAttribLocation(program, attribName);
859 this.m_ctx.enableVertexAttribArray(loc);
861 this.m_arrays[arrayNdx].glBind(loc);
865 DE_ASSERT((firstVertex % 6) == 0);
866 //this.m_ctx.drawArrays(glsVertexArrayTests.ContextArray.primitiveToGL(primitive), firstVertex, vertexCount - firstVertex);
867 this.m_ctx.drawQuads(gl.TRIANGLES, firstVertex, vertexCount - firstVertex);
869 for (var arrayNdx = 0; arrayNdx < this.m_arrays.length; arrayNdx++) {
870 if (this.m_arrays[arrayNdx].isBound()) {
871 attribName = 'a_' + this.m_arrays[arrayNdx].getAttribNdx();
872 loc = this.m_ctx.getAttribLocation(program, attribName);
874 this.m_ctx.disableVertexAttribArray(loc);
878 if (useVao)
879 vaoID = this.m_ctx.deleteVertexArray(vaoID);
881 this.m_ctx.deleteProgram(program);
882 this.m_ctx.useProgram(null);
883 this.m_ctx.readPixels(0, 0, this.m_screen.getWidth(), this.m_screen.getHeight(), gl.RGBA, gl.UNSIGNED_BYTE, this.m_screen.getAccess().getDataPtr());
887 * @return {tcuSurface.Surface}
889 glsVertexArrayTests.ContextArrayPack.prototype.getSurface = function() { return this.m_screen; };
892 * glsVertexArrayTests.ContextShaderProgram class
893 * @constructor
894 * @extends {sglrShaderProgram.ShaderProgram}
895 * @param {WebGLRenderingContextBase | sglrReferenceContext.ReferenceContext} ctx
896 * @param {Array<glsVertexArrayTests.ContextArray>} arrays
898 glsVertexArrayTests.ContextShaderProgram = function(ctx, arrays) {
899 sglrShaderProgram.ShaderProgram.call(this, this.createProgramDeclaration(ctx, arrays));
900 this.m_componentCount = new Array(arrays.length);
901 /** @type {Array<rrGenericVector.GenericVecType>} */ this.m_attrType = new Array(arrays.length);
903 for (var arrayNdx = 0; arrayNdx < arrays.length; arrayNdx++) {
904 this.m_componentCount[arrayNdx] = this.getComponentCount(arrays[arrayNdx].getOutputType());
905 this.m_attrType[arrayNdx] = this.mapOutputType(arrays[arrayNdx].getOutputType());
909 glsVertexArrayTests.ContextShaderProgram.prototype = Object.create(sglrShaderProgram.ShaderProgram.prototype);
910 glsVertexArrayTests.ContextShaderProgram.prototype.constructor = glsVertexArrayTests.ContextShaderProgram;
913 * glsVertexArrayTests.calcShaderColorCoord function
914 * @param {Array<number>} coord (2 elements)
915 * @param {Array<number>} color (3 elements)
916 * @param {goog.NumberArray} attribValue (4 elements)
917 * @param {boolean} isCoordinate
918 * @param {number} numComponents
920 glsVertexArrayTests.calcShaderColorCoord = function(coord, color, attribValue, isCoordinate, numComponents) {
921 if (isCoordinate)
922 switch (numComponents) {
923 case 1:
924 coord[0] = attribValue[0];
925 coord[1] = attribValue[0];
926 break;
927 case 2:
928 coord[0] = attribValue[0];
929 coord[1] = attribValue[1];
930 break;
931 case 3:
932 coord[0] = attribValue[0] + attribValue[2];
933 coord[1] = attribValue[1];
934 break;
935 case 4:
936 coord[0] = attribValue[0] + attribValue[2];
937 coord[1] = attribValue[1] + attribValue[3];
938 break;
939 default:
940 throw new Error('glsVertexArrayTests.calcShaderColorCoord - Invalid number of components');
941 } else {
942 switch (numComponents) {
943 case 1:
944 color[0] = color[0] * attribValue[0];
945 break;
946 case 2:
947 color[0] = color[0] * attribValue[0];
948 color[1] = color[1] * attribValue[1];
949 break;
950 case 3:
951 color[0] = color[0] * attribValue[0];
952 color[1] = color[1] * attribValue[1];
953 color[2] = color[2] * attribValue[2];
954 break;
955 case 4:
956 color[0] = color[0] * attribValue[0] * attribValue[3];
957 color[1] = color[1] * attribValue[1] * attribValue[3];
958 color[2] = color[2] * attribValue[2] * attribValue[3];
959 break;
960 default:
961 throw new Error('glsVertexArrayTests.calcShaderColorCoord - Invalid number of components');
967 * glsVertexArrayTests.ContextShaderProgram.shadeVertices
968 * @param {Array<rrVertexAttrib.VertexAttrib>} inputs
969 * @param {Array<rrVertexPacket.VertexPacket>} packets
970 * @param {number} numPackets
972 glsVertexArrayTests.ContextShaderProgram.prototype.shadeVertices = function(inputs, packets, numPackets) {
973 /** @type {number} */ var u_coordScale = this.getUniformByName('u_coordScale').value[0];
974 /** @type {number} */ var u_colorScale = this.getUniformByName('u_colorScale').value[0];
976 for (var packetNdx = 0; packetNdx < numPackets; ++packetNdx) {
977 /** @type {number} */ var varyingLocColor = 0;
979 /** @type {rrVertexPacket.VertexPacket} */ var packet = packets[packetNdx];
981 // Calc output color
982 /** @type {Array<number>} */ var coord = [1.0, 1.0];
983 /** @type {Array<number>} */ var color = [1.0, 1.0, 1.0];
985 for (var attribNdx = 0; attribNdx < this.m_attrType.length; attribNdx++) {
986 /** @type {number} */ var numComponents = this.m_componentCount[attribNdx];
988 glsVertexArrayTests.calcShaderColorCoord(coord, color, rrVertexAttrib.readVertexAttrib(inputs[attribNdx], packet.instanceNdx, packet.vertexNdx, this.m_attrType[attribNdx]), attribNdx == 0, numComponents);
991 // Transform position
992 packet.position = [u_coordScale * coord[0], u_coordScale * coord[1], 1.0, 1.0];
994 // Pass color to FS
995 packet.outputs[varyingLocColor] = [u_colorScale * color[0], u_colorScale * color[1], u_colorScale * color[2], 1.0];
1000 * @param {Array<rrFragmentOperations.Fragment>} packets
1001 * @param {rrShadingContext.FragmentShadingContext} context
1003 glsVertexArrayTests.ContextShaderProgram.prototype.shadeFragments = function(packets, context) {
1004 var varyingLocColor = 0;
1006 // Normal shading
1007 for (var packetNdx = 0; packetNdx < packets.length; ++packetNdx)
1008 packets[packetNdx].value = rrShadingContext.readTriangleVarying(packets[packetNdx], context, varyingLocColor);
1012 * @param {Array<glsVertexArrayTests.ContextArray>} arrays
1013 * @return string
1015 glsVertexArrayTests.ContextShaderProgram.prototype.genVertexSource = function(arrays) {
1016 var vertexShaderSrc = '';
1017 var params = [];
1019 params['VTX_IN'] = 'in';
1020 params['VTX_OUT'] = 'out';
1021 params['FRAG_IN'] = 'in';
1022 params['FRAG_COLOR'] = 'dEQP_FragColor';
1023 params['VTX_HDR'] = '#version 300 es\n';
1024 params['FRAG_HDR'] = '#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n';
1026 vertexShaderSrc += params['VTX_HDR'];
1028 for (var arrayNdx = 0; arrayNdx < arrays.length; arrayNdx++) {
1029 vertexShaderSrc += params['VTX_IN'] + ' highp ' + glsVertexArrayTests.ContextArray.outputTypeToGLType(arrays[arrayNdx].getOutputType()) + ' a_' + arrays[arrayNdx].getAttribNdx() + ';\n';
1032 vertexShaderSrc +=
1033 'uniform highp float u_coordScale;\n' +
1034 'uniform highp float u_colorScale;\n' +
1035 params['VTX_OUT'] + ' mediump vec4 v_color;\n' +
1036 'void main(void)\n' +
1037 ' {\n' +
1038 '\tgl_PointSize = 1.0;\n' +
1039 '\thighp vec2 coord = vec2(1.0, 1.0);\n' +
1040 '\thighp vec3 color = vec3(1.0, 1.0, 1.0);\n';
1042 for (var arrayNdx = 0; arrayNdx < arrays.length; arrayNdx++) {
1043 if (arrays[arrayNdx].getAttribNdx() == 0) {
1044 switch (arrays[arrayNdx].getOutputType()) {
1045 case (glsVertexArrayTests.deArray.OutputType.FLOAT):
1046 vertexShaderSrc +=
1047 '\tcoord = vec2(a_0);\n';
1048 break;
1050 case (glsVertexArrayTests.deArray.OutputType.VEC2):
1051 vertexShaderSrc +=
1052 '\tcoord = a_0.xy;\n';
1053 break;
1055 case (glsVertexArrayTests.deArray.OutputType.VEC3):
1056 vertexShaderSrc +=
1057 '\tcoord = a_0.xy;\n' +
1058 '\tcoord.x = coord.x + a_0.z;\n';
1059 break;
1061 case (glsVertexArrayTests.deArray.OutputType.VEC4):
1062 vertexShaderSrc +=
1063 '\tcoord = a_0.xy;\n' +
1064 '\tcoord += a_0.zw;\n';
1065 break;
1067 case (glsVertexArrayTests.deArray.OutputType.IVEC2):
1068 case (glsVertexArrayTests.deArray.OutputType.UVEC2):
1069 vertexShaderSrc +=
1070 '\tcoord = vec2(a_0.xy);\n';
1071 break;
1073 case (glsVertexArrayTests.deArray.OutputType.IVEC3):
1074 case (glsVertexArrayTests.deArray.OutputType.UVEC3):
1075 vertexShaderSrc +=
1076 '\tcoord = vec2(a_0.xy);\n' +
1077 '\tcoord.x = coord.x + float(a_0.z);\n';
1078 break;
1080 case (glsVertexArrayTests.deArray.OutputType.IVEC4):
1081 case (glsVertexArrayTests.deArray.OutputType.UVEC4):
1082 vertexShaderSrc +=
1083 '\tcoord = vec2(a_0.xy);\n' +
1084 '\tcoord += vec2(a_0.zw);\n';
1085 break;
1087 default:
1088 throw new Error('Invalid output type');
1089 break;
1091 continue;
1094 switch (arrays[arrayNdx].getOutputType()) {
1095 case (glsVertexArrayTests.deArray.OutputType.FLOAT):
1096 vertexShaderSrc +=
1097 '\tcolor = color * a_' + arrays[arrayNdx].getAttribNdx() + ';\n';
1098 break;
1100 case (glsVertexArrayTests.deArray.OutputType.VEC2):
1101 vertexShaderSrc +=
1102 '\tcolor.rg = color.rg * a_' + arrays[arrayNdx].getAttribNdx() + '.xy;\n';
1103 break;
1105 case (glsVertexArrayTests.deArray.OutputType.VEC3):
1106 vertexShaderSrc +=
1107 '\tcolor = color.rgb * a_' + arrays[arrayNdx].getAttribNdx() + '.xyz;\n';
1108 break;
1110 case (glsVertexArrayTests.deArray.OutputType.VEC4):
1111 vertexShaderSrc +=
1112 '\tcolor = color.rgb * a_' + arrays[arrayNdx].getAttribNdx() + '.xyz * a_' + arrays[arrayNdx].getAttribNdx() + '.w;\n';
1113 break;
1115 default:
1116 throw new Error('Invalid output type');
1117 break;
1121 vertexShaderSrc +=
1122 '\tv_color = vec4(u_colorScale * color, 1.0);\n' +
1123 '\tgl_Position = vec4(u_coordScale * coord, 1.0, 1.0);\n' +
1124 '}\n';
1126 return vertexShaderSrc;
1130 * @return {string}
1132 glsVertexArrayTests.ContextShaderProgram.prototype.genFragmentSource = function() {
1133 var params = [];
1135 params['VTX_IN'] = 'in';
1136 params['VTX_OUT'] = 'out';
1137 params['FRAG_IN'] = 'in';
1138 params['FRAG_COLOR'] = 'dEQP_FragColor';
1139 params['VTX_HDR'] = '#version 300 es\n';
1140 params['FRAG_HDR'] = '#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n';
1142 /* TODO: Check if glsl supported version check function is needed.*/
1144 var fragmentShaderSrc = params['FRAG_HDR'] +
1145 params['FRAG_IN'] + ' mediump vec4 v_color;\n' +
1146 'void main(void)\n' +
1147 ' {\n' +
1148 '\t' + params['FRAG_COLOR'] + ' = v_color;\n' +
1149 '}\n';
1151 return fragmentShaderSrc;
1155 * @param {glsVertexArrayTests.deArray.OutputType} type
1156 * @return {rrGenericVector.GenericVecType}
1158 glsVertexArrayTests.ContextShaderProgram.prototype.mapOutputType = function(type) {
1159 switch (type) {
1160 case (glsVertexArrayTests.deArray.OutputType.FLOAT):
1161 case (glsVertexArrayTests.deArray.OutputType.VEC2):
1162 case (glsVertexArrayTests.deArray.OutputType.VEC3):
1163 case (glsVertexArrayTests.deArray.OutputType.VEC4):
1164 return rrGenericVector.GenericVecType.FLOAT;
1166 case (glsVertexArrayTests.deArray.OutputType.INT):
1167 case (glsVertexArrayTests.deArray.OutputType.IVEC2):
1168 case (glsVertexArrayTests.deArray.OutputType.IVEC3):
1169 case (glsVertexArrayTests.deArray.OutputType.IVEC4):
1170 return rrGenericVector.GenericVecType.INT32;
1172 case (glsVertexArrayTests.deArray.OutputType.UINT):
1173 case (glsVertexArrayTests.deArray.OutputType.UVEC2):
1174 case (glsVertexArrayTests.deArray.OutputType.UVEC3):
1175 case (glsVertexArrayTests.deArray.OutputType.UVEC4):
1176 return rrGenericVector.GenericVecType.UINT32;
1178 default:
1179 throw new Error('Invalid output type');
1184 * @param {glsVertexArrayTests.deArray.OutputType} type
1185 * @return {number}
1187 glsVertexArrayTests.ContextShaderProgram.prototype.getComponentCount = function(type) {
1188 switch (type) {
1189 case (glsVertexArrayTests.deArray.OutputType.FLOAT):
1190 case (glsVertexArrayTests.deArray.OutputType.INT):
1191 case (glsVertexArrayTests.deArray.OutputType.UINT):
1192 return 1;
1194 case (glsVertexArrayTests.deArray.OutputType.VEC2):
1195 case (glsVertexArrayTests.deArray.OutputType.IVEC2):
1196 case (glsVertexArrayTests.deArray.OutputType.UVEC2):
1197 return 2;
1199 case (glsVertexArrayTests.deArray.OutputType.VEC3):
1200 case (glsVertexArrayTests.deArray.OutputType.IVEC3):
1201 case (glsVertexArrayTests.deArray.OutputType.UVEC3):
1202 return 3;
1204 case (glsVertexArrayTests.deArray.OutputType.VEC4):
1205 case (glsVertexArrayTests.deArray.OutputType.IVEC4):
1206 case (glsVertexArrayTests.deArray.OutputType.UVEC4):
1207 return 4;
1209 default:
1210 throw new Error('Invalid output type');
1215 * @param {WebGLRenderingContextBase | sglrReferenceContext.ReferenceContext} ctx
1216 * @param {Array<glsVertexArrayTests.ContextArray>} arrays
1217 * @return {sglrShaderProgram.ShaderProgramDeclaration}
1219 glsVertexArrayTests.ContextShaderProgram.prototype.createProgramDeclaration = function(ctx, arrays) {
1220 /** @type {sglrShaderProgram.ShaderProgramDeclaration} */ var decl = new sglrShaderProgram.ShaderProgramDeclaration();
1222 for (var arrayNdx = 0; arrayNdx < arrays.length; arrayNdx++)
1223 decl.pushVertexAttribute(new sglrShaderProgram.VertexAttribute('a_' + arrayNdx, this.mapOutputType(arrays[arrayNdx].getOutputType())));
1225 decl.pushVertexToFragmentVarying(new sglrShaderProgram.VertexToFragmentVarying(rrGenericVector.GenericVecType.FLOAT));
1226 decl.pushFragmentOutput(new sglrShaderProgram.FragmentOutput(rrGenericVector.GenericVecType.FLOAT));
1228 decl.pushVertexSource(new sglrShaderProgram.VertexSource(this.genVertexSource(/*ctx,*/ arrays))); //TODO: Check if we need to review the support of a given GLSL version (we'd need the ctx)
1229 decl.pushFragmentSource(new sglrShaderProgram.FragmentSource(this.genFragmentSource(/*ctx*/)));
1231 decl.pushUniform(new sglrShaderProgram.Uniform('u_coordScale', gluShaderUtil.DataType.FLOAT));
1232 decl.pushUniform(new sglrShaderProgram.Uniform('u_colorScale', gluShaderUtil.DataType.FLOAT));
1234 return decl;
1238 * glsVertexArrayTests.GLValue class
1239 * @constructor
1241 glsVertexArrayTests.GLValue = function() {
1242 /** @type {goog.NumberArray} */ this.m_value = [0];
1243 /** @type {glsVertexArrayTests.deArray.InputType} */ this.m_type;
1247 * @param {Uint8Array} dst
1248 * @param {glsVertexArrayTests.GLValue} val
1250 glsVertexArrayTests.copyGLValueToArray = function(dst, val) {
1251 /** @type {Uint8Array} */ var val8 = new Uint8Array(val.m_value.buffer); // TODO: Fix encapsulation issue
1252 dst.set(val8);
1256 * @param {Uint8Array} dst
1257 * @param {goog.NumberArray} src
1259 glsVertexArrayTests.copyArray = function(dst, src) {
1260 /** @type {Uint8Array} */ var src8 = new Uint8Array(src.buffer).subarray(src.byteOffset, src.byteOffset + src.byteLength); // TODO: Fix encapsulation issue
1261 dst.set(src8);
1265 * typeToTypedArray function. Determines which type of array will store the value, and stores it.
1266 * @param {number} value
1267 * @param {glsVertexArrayTests.deArray.InputType} type
1269 glsVertexArrayTests.GLValue.typeToTypedArray = function(value, type) {
1270 var array;
1272 switch (type) {
1273 case glsVertexArrayTests.deArray.InputType.FLOAT:
1274 array = new Float32Array(1);
1275 break;
1276 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1277 array = new Int32Array(1);
1278 break;
1279 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1280 array = new Float32Array(1); // 64-bit?
1281 break;*/
1283 case glsVertexArrayTests.deArray.InputType.BYTE:
1284 array = new Int8Array(1);
1285 break;
1286 case glsVertexArrayTests.deArray.InputType.SHORT:
1287 array = new Int16Array(1);
1288 break;
1290 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1291 array = new Uint8Array(1);
1292 break;
1293 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1294 array = new Uint16Array(1);
1295 break;
1297 case glsVertexArrayTests.deArray.InputType.INT:
1298 array = new Int32Array(1);
1299 break;
1300 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1301 array = new Uint32Array(1);
1302 break;
1303 case glsVertexArrayTests.deArray.InputType.HALF:
1304 array = new Uint16Array(1);
1305 value = glsVertexArrayTests.GLValue.floatToHalf(value);
1306 break;
1307 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10:
1308 array = new Uint32Array(1);
1309 break;
1310 case glsVertexArrayTests.deArray.InputType.INT_2_10_10_10:
1311 array = new Int32Array(1);
1312 break;
1313 default:
1314 throw new Error('glsVertexArrayTests.GLValue.typeToTypedArray - Invalid InputType');
1317 array[0] = value;
1318 return array;
1322 * glsVertexArrayTests.GLValue.create
1323 * @param {number} value
1324 * @param {glsVertexArrayTests.deArray.InputType} type
1326 glsVertexArrayTests.GLValue.create = function(value, type) {
1327 var v = new glsVertexArrayTests.GLValue();
1328 v.m_value = glsVertexArrayTests.GLValue.typeToTypedArray(value, type);
1329 v.m_type = type;
1330 return v;
1334 * glsVertexArrayTests.GLValue.halfToFloat
1335 * @param {number} value
1336 * @return {number}
1338 glsVertexArrayTests.GLValue.halfToFloat = function(value) {
1339 return tcuFloat.halfFloatToNumberNoDenorm(value);
1343 * @param {number} f
1344 * @return {number}
1346 glsVertexArrayTests.GLValue.floatToHalf = function(f) {
1347 // No denorm support.
1348 return tcuFloat.numberToHalfFloatNoDenorm(f);
1352 * glsVertexArrayTests.GLValue.getMaxValue
1353 * @param {glsVertexArrayTests.deArray.InputType} type
1354 * @return {glsVertexArrayTests.GLValue}
1356 glsVertexArrayTests.GLValue.getMaxValue = function(type) {
1357 var value;
1359 switch (type) {
1360 case glsVertexArrayTests.deArray.InputType.FLOAT:
1361 value = 127;
1362 break;
1363 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1364 value = 32760;
1365 break;
1366 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1367 value = 127;
1368 break;*/
1369 case glsVertexArrayTests.deArray.InputType.BYTE:
1370 value = 127;
1371 break;
1372 case glsVertexArrayTests.deArray.InputType.SHORT:
1373 value = 32760;
1374 break;
1375 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1376 value = 255;
1377 break;
1378 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1379 value = 65530;
1380 break;
1381 case glsVertexArrayTests.deArray.InputType.INT:
1382 value = 2147483647;
1383 break;
1384 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1385 value = 4294967295;
1386 break;
1387 case glsVertexArrayTests.deArray.InputType.HALF:
1388 value = 256;
1389 break;
1390 default: //Original code returns garbage-filled GLValues
1391 return new glsVertexArrayTests.GLValue();
1394 return glsVertexArrayTests.GLValue.create(value, type);
1398 * glsVertexArrayTests.GLValue.getMinValue
1399 * @param {glsVertexArrayTests.deArray.InputType} type
1400 * @return {glsVertexArrayTests.GLValue}
1402 glsVertexArrayTests.GLValue.getMinValue = function(type) {
1403 var value;
1405 switch (type) {
1406 case glsVertexArrayTests.deArray.InputType.FLOAT:
1407 value = -127;
1408 break;
1409 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1410 value = -32760;
1411 break;
1412 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1413 value = -127;
1414 break;*/
1415 case glsVertexArrayTests.deArray.InputType.BYTE:
1416 value = -127;
1417 break;
1418 case glsVertexArrayTests.deArray.InputType.SHORT:
1419 value = -32760;
1420 break;
1421 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1422 value = 0;
1423 break;
1424 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1425 value = 0;
1426 break;
1427 case glsVertexArrayTests.deArray.InputType.INT:
1428 value = -2147483647;
1429 break;
1430 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1431 value = 0;
1432 break;
1433 case glsVertexArrayTests.deArray.InputType.HALF:
1434 value = -256;
1435 break;
1437 default: //Original code returns garbage-filled GLValues
1438 return new glsVertexArrayTests.GLValue();
1441 return glsVertexArrayTests.GLValue.create(value, type);
1445 * glsVertexArrayTests.GLValue.getRandom
1446 * @param {deRandom.Random} rnd
1447 * @param {glsVertexArrayTests.GLValue} min
1448 * @param {glsVertexArrayTests.GLValue} max
1449 * @return {glsVertexArrayTests.GLValue}
1451 glsVertexArrayTests.GLValue.getRandom = function(rnd, min, max) {
1452 DE_ASSERT(min.getType() == max.getType());
1454 var minv = min.interpret();
1455 var maxv = max.interpret();
1456 var type = min.getType();
1457 var value;
1459 if (maxv < minv)
1460 return min;
1462 switch (type) {
1463 case glsVertexArrayTests.deArray.InputType.FLOAT:
1464 //case glsVertexArrayTests.deArray.InputType.DOUBLE:
1465 case glsVertexArrayTests.deArray.InputType.HALF: {
1466 return glsVertexArrayTests.GLValue.create(minv + rnd.getFloat() * (maxv - minv), type);
1467 break;
1470 /*case glsVertexArrayTests.deArray.InputType.FIXED: {
1471 return minv == maxv ? min : glsVertexArrayTests.GLValue.create(minv + rnd.getInt() % (maxv - minv), type);
1472 break;
1475 case glsVertexArrayTests.deArray.InputType.SHORT:
1476 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1477 case glsVertexArrayTests.deArray.InputType.BYTE:
1478 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1479 case glsVertexArrayTests.deArray.InputType.INT:
1480 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT: {
1481 return glsVertexArrayTests.GLValue.create(minv + rnd.getInt() % (maxv - minv), type);
1482 break;
1485 default:
1486 throw new Error('glsVertexArrayTests.GLValue.getRandom - Invalid input type');
1487 break;
1491 // Minimum difference required between coordinates
1494 * @param {glsVertexArrayTests.deArray.InputType} type
1495 * @return {glsVertexArrayTests.GLValue}
1497 glsVertexArrayTests.GLValue.minValue = function(type) {
1498 switch (type) {
1499 case glsVertexArrayTests.deArray.InputType.FLOAT:
1500 case glsVertexArrayTests.deArray.InputType.BYTE:
1501 case glsVertexArrayTests.deArray.InputType.HALF:
1502 //case glsVertexArrayTests.deArray.InputType.DOUBLE:
1503 return glsVertexArrayTests.GLValue.create(4, type);
1504 case glsVertexArrayTests.deArray.InputType.SHORT:
1505 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1506 return glsVertexArrayTests.GLValue.create(4 * 256, type);
1507 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1508 return glsVertexArrayTests.GLValue.create(4 * 2, type);
1509 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1510 return glsVertexArrayTests.GLValue.create(4 * 512, type);*/
1511 case glsVertexArrayTests.deArray.InputType.INT:
1512 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1513 return glsVertexArrayTests.GLValue.create(4 * 16777216, type);
1515 default:
1516 throw new Error('glsVertexArrayTests.GLValue.minValue - Invalid input type');
1521 * @param {glsVertexArrayTests.GLValue} val
1522 * @return {glsVertexArrayTests.GLValue}
1524 glsVertexArrayTests.GLValue.abs = function(val) {
1525 var type = val.getType();
1526 switch (type) {
1527 //case glsVertexArrayTests.deArray.InputType.FIXED:
1528 case glsVertexArrayTests.deArray.InputType.SHORT:
1529 return glsVertexArrayTests.GLValue.create(0x7FFF & val.getValue(), type);
1530 case glsVertexArrayTests.deArray.InputType.BYTE:
1531 return glsVertexArrayTests.GLValue.create(0x7F & val.getValue(), type);
1532 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1533 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1534 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1535 return val;
1536 case glsVertexArrayTests.deArray.InputType.FLOAT:
1537 case glsVertexArrayTests.deArray.InputType.HALF:
1538 //case glsVertexArrayTests.deArray.InputType.DOUBLE:
1539 return glsVertexArrayTests.GLValue.create(Math.abs(val.interpret()), type);
1540 case glsVertexArrayTests.deArray.InputType.INT:
1541 return glsVertexArrayTests.GLValue.create(0x7FFFFFFF & val.getValue(), type);
1542 default:
1543 throw new Error('glsVertexArrayTests.GLValue.abs - Invalid input type');
1548 * @return {glsVertexArrayTests.deArray.InputType}
1550 glsVertexArrayTests.GLValue.prototype.getType = function() {
1551 return this.m_type;
1555 * glsVertexArrayTests.GLValue.toFloat
1556 * @return {number}
1558 glsVertexArrayTests.GLValue.prototype.toFloat = function() {
1559 return this.interpret();
1563 * glsVertexArrayTests.GLValue.getValue
1564 * @return {number}
1566 glsVertexArrayTests.GLValue.prototype.getValue = function() {
1567 return this.m_value[0];
1571 * interpret function. Returns the m_value as a quantity so arithmetic operations can be performed on it
1572 * Only some types require this.
1573 * @return {number}
1575 glsVertexArrayTests.GLValue.prototype.interpret = function() {
1576 if (this.m_type == glsVertexArrayTests.deArray.InputType.HALF)
1577 return glsVertexArrayTests.GLValue.halfToFloat(this.m_value[0]);
1578 /*else if (this.m_type == glsVertexArrayTests.deArray.InputType.FIXED) {
1579 var maxValue = 65536;
1580 return Math.floor((2 * this.m_value[0] + 1) / (maxValue - 1));
1583 return this.m_value[0];
1587 * @param {glsVertexArrayTests.GLValue} other
1588 * @return {glsVertexArrayTests.GLValue}
1590 glsVertexArrayTests.GLValue.prototype.add = function(other) {
1591 return glsVertexArrayTests.GLValue.create(this.interpret() + other.interpret(), this.m_type);
1595 * @param {glsVertexArrayTests.GLValue} other
1596 * @return {glsVertexArrayTests.GLValue}
1598 glsVertexArrayTests.GLValue.prototype.mul = function(other) {
1599 return glsVertexArrayTests.GLValue.create(this.interpret() * other.interpret(), this.m_type);
1603 * @param {glsVertexArrayTests.GLValue} other
1604 * @return {glsVertexArrayTests.GLValue}
1606 glsVertexArrayTests.GLValue.prototype.div = function(other) {
1607 return glsVertexArrayTests.GLValue.create(this.interpret() / other.interpret(), this.m_type);
1611 * @param {glsVertexArrayTests.GLValue} other
1612 * @return {glsVertexArrayTests.GLValue}
1614 glsVertexArrayTests.GLValue.prototype.sub = function(other) {
1615 return glsVertexArrayTests.GLValue.create(this.interpret() - other.interpret(), this.m_type);
1619 * @param {glsVertexArrayTests.GLValue} other
1620 * @return {glsVertexArrayTests.GLValue}
1622 glsVertexArrayTests.GLValue.prototype.addToSelf = function(other) {
1623 this.m_value[0] = this.interpret() + other.interpret();
1624 return this;
1628 * @param {glsVertexArrayTests.GLValue} other
1629 * @return {glsVertexArrayTests.GLValue}
1631 glsVertexArrayTests.GLValue.prototype.subToSelf = function(other) {
1632 this.m_value[0] = this.interpret() - other.interpret();
1633 return this;
1637 * @param {glsVertexArrayTests.GLValue} other
1638 * @return {glsVertexArrayTests.GLValue}
1640 glsVertexArrayTests.GLValue.prototype.mulToSelf = function(other) {
1641 this.m_value[0] = this.interpret() * other.interpret();
1642 return this;
1646 * @param {glsVertexArrayTests.GLValue} other
1647 * @return {glsVertexArrayTests.GLValue}
1649 glsVertexArrayTests.GLValue.prototype.divToSelf = function(other) {
1650 this.m_value[0] = this.interpret() / other.interpret();
1651 return this;
1655 * @param {glsVertexArrayTests.GLValue} other
1656 * @return {boolean}
1658 glsVertexArrayTests.GLValue.prototype.equals = function(other) {
1659 return this.m_value[0] == other.getValue();
1663 * @param {glsVertexArrayTests.GLValue} other
1664 * @return {boolean}
1666 glsVertexArrayTests.GLValue.prototype.lessThan = function(other) {
1667 return this.interpret() < other.interpret();
1671 * @param {glsVertexArrayTests.GLValue} other
1672 * @return {boolean}
1674 glsVertexArrayTests.GLValue.prototype.greaterThan = function(other) {
1675 return this.interpret() > other.interpret();
1679 * @param {glsVertexArrayTests.GLValue} other
1680 * @return {boolean}
1682 glsVertexArrayTests.GLValue.prototype.lessOrEqualThan = function(other) {
1683 return this.interpret() <= other.interpret();
1687 * @param {glsVertexArrayTests.GLValue} other
1688 * @return {boolean}
1690 glsVertexArrayTests.GLValue.prototype.greaterOrEqualThan = function(other) {
1691 return this.interpret() >= other.interpret();
1695 * glsVertexArrayTests.RandomArrayGenerator class. Contains static methods only
1697 glsVertexArrayTests.RandomArrayGenerator = function() {};
1700 * glsVertexArrayTests.RandomArrayGenerator.setData
1701 * @param {Uint8Array} data
1702 * @param {glsVertexArrayTests.deArray.InputType} type
1703 * @param {deRandom.Random} rnd
1704 * @param {glsVertexArrayTests.GLValue} min
1705 * @param {glsVertexArrayTests.GLValue} max
1707 glsVertexArrayTests.RandomArrayGenerator.setData = function(data, type, rnd, min, max) {
1708 // Parameter type is not necessary, but we'll use it to assert the created glsVertexArrayTests.GLValue is of the correct type.
1709 /** @type {glsVertexArrayTests.GLValue} */ var value = glsVertexArrayTests.GLValue.getRandom(rnd, min, max);
1710 DE_ASSERT(value.getType() == type);
1712 glsVertexArrayTests.copyGLValueToArray(data, value);
1716 * generateArray
1717 * @param {number} seed
1718 * @param {glsVertexArrayTests.GLValue} min
1719 * @param {glsVertexArrayTests.GLValue} max
1720 * @param {number} count
1721 * @param {number} componentCount
1722 * @param {number} stride
1723 * @param {glsVertexArrayTests.deArray.InputType} type
1724 * @return {ArrayBuffer}
1726 glsVertexArrayTests.RandomArrayGenerator.generateArray = function(seed, min, max, count, componentCount, stride, type) {
1727 /** @type {ArrayBuffer} */ var data;
1728 /** @type {Uint8Array} */ var data8;
1730 var rnd = new deRandom.Random(seed);
1732 if (stride == 0)
1733 stride = componentCount * glsVertexArrayTests.deArray.inputTypeSize(type);
1735 data = new ArrayBuffer(stride * count);
1736 data8 = new Uint8Array(data);
1738 for (var vertexNdx = 0; vertexNdx < count; vertexNdx++) {
1739 for (var componentNdx = 0; componentNdx < componentCount; componentNdx++) {
1740 glsVertexArrayTests.RandomArrayGenerator.setData(data8.subarray(vertexNdx * stride + glsVertexArrayTests.deArray.inputTypeSize(type) * componentNdx), type, rnd, min, max);
1744 return data;
1747 /* {
1748 static char* generateQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, Array::InputType type, glsVertexArrayTests.GLValue min, glsVertexArrayTests.GLValue max);
1749 static char* generatePerQuad (int seed, int count, int componentCount, int stride, Array::Primitive primitive, Array::InputType type, glsVertexArrayTests.GLValue min, glsVertexArrayTests.GLValue max);
1751 private:
1752 template<typename T>
1753 static char* createQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, T min, T max);
1754 template<typename T>
1755 static char* createPerQuads (int seed, int count, int componentCount, int stride, Array::Primitive primitive, T min, T max);
1756 static char* createQuadsPacked (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive);
1757 };*/
1760 * @param {number} seed
1761 * @param {number} count
1762 * @param {number} componentCount
1763 * @param {number} offset
1764 * @param {number} stride
1765 * @param {glsVertexArrayTests.deArray.Primitive} primitive
1766 * @param {glsVertexArrayTests.deArray.InputType} type
1767 * @param {glsVertexArrayTests.GLValue} min
1768 * @param {glsVertexArrayTests.GLValue} max
1769 * @param {number} scale Coordinate scaling factor
1770 * @return {ArrayBuffer}
1772 glsVertexArrayTests.RandomArrayGenerator.generateQuads = function(seed, count, componentCount, offset, stride, primitive, type, min, max, scale) {
1773 /** @type {ArrayBuffer} */ var data;
1775 switch (type) {
1776 case glsVertexArrayTests.deArray.InputType.FLOAT:
1777 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1778 case glsVertexArrayTests.deArray.InputType.DOUBLE:*/
1779 case glsVertexArrayTests.deArray.InputType.BYTE:
1780 case glsVertexArrayTests.deArray.InputType.SHORT:
1781 case glsVertexArrayTests.deArray.InputType.UNSIGNED_BYTE:
1782 case glsVertexArrayTests.deArray.InputType.UNSIGNED_SHORT:
1783 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT:
1784 case glsVertexArrayTests.deArray.InputType.INT:
1785 case glsVertexArrayTests.deArray.InputType.HALF:
1786 data = glsVertexArrayTests.RandomArrayGenerator.createQuads(seed, count, componentCount, offset, stride, primitive, min, max, scale);
1787 break;
1789 case glsVertexArrayTests.deArray.InputType.INT_2_10_10_10:
1790 case glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10:
1791 data = glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked(seed, count, componentCount, offset, stride, primitive);
1792 break;
1794 default:
1795 throw new Error('glsVertexArrayTests.RandomArrayGenerator.generateQuads - Invalid input type');
1796 break;
1799 return data;
1803 * @param {number} seed
1804 * @param {number} count
1805 * @param {number} componentCount
1806 * @param {number} offset
1807 * @param {number} stride
1808 * @param {glsVertexArrayTests.deArray.Primitive} primitive
1809 * @return {ArrayBuffer}
1811 glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked = function(seed, count, componentCount, offset, stride, primitive) {
1812 DE_ASSERT(componentCount == 4);
1814 /** @type {number} */ var quadStride = 0;
1816 if (stride == 0)
1817 stride = deMath.INT32_SIZE;
1819 switch (primitive) {
1820 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
1821 quadStride = stride * 6;
1822 break;
1824 default:
1825 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked - Invalid primitive');
1826 break;
1829 /** @type {ArrayBuffer} */ var _data = new ArrayBuffer(offset + quadStride * (count - 1) + stride * 5 + componentCount * glsVertexArrayTests.deArray.inputTypeSize(glsVertexArrayTests.deArray.InputType.INT_2_10_10_10)); // last element must be fully in the array
1830 /** @type {Uint8Array} */ var resultData = new Uint8Array(_data).subarray(offset);
1832 /** @type {number} */ var max = 1024;
1833 /** @type {number} */ var min = 10;
1834 /** @type {number} */ var max2 = 4;
1836 var rnd = new deRandom.Random(seed);
1838 switch (primitive) {
1839 case glsVertexArrayTests.deArray.Primitive.TRIANGLES: {
1840 for (var quadNdx = 0; quadNdx < count; quadNdx++) {
1841 /** @type {number} */ var x1 = min + rnd.getInt() % (max - min);
1842 /** @type {number} */ var x2 = min + rnd.getInt() % (max - x1);
1844 /** @type {number} */ var y1 = min + rnd.getInt() % (max - min);
1845 /** @type {number} */ var y2 = min + rnd.getInt() % (max - y1);
1847 /** @type {number} */ var z = min + rnd.getInt() % (max - min);
1848 /** @type {number} */ var w = rnd.getInt() % max2;
1850 /** @type {number} */ var val1 = (w << 30) | (z << 20) | (y1 << 10) | x1;
1851 /** @type {number} */ var val2 = (w << 30) | (z << 20) | (y1 << 10) | x2;
1852 /** @type {number} */ var val3 = (w << 30) | (z << 20) | (y2 << 10) | x1;
1854 /** @type {number} */ var val4 = (w << 30) | (z << 20) | (y2 << 10) | x1;
1855 /** @type {number} */ var val5 = (w << 30) | (z << 20) | (y1 << 10) | x2;
1856 /** @type {number} */ var val6 = (w << 30) | (z << 20) | (y2 << 10) | x2;
1858 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 0), new Uint32Array([val1]));
1859 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 1), new Uint32Array([val2]));
1860 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 2), new Uint32Array([val3]));
1861 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 3), new Uint32Array([val4]));
1862 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 4), new Uint32Array([val5]));
1863 glsVertexArrayTests.copyArray(resultData.subarray(quadNdx * quadStride + stride * 5), new Uint32Array([val6]));
1866 break;
1869 default:
1870 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked - Invalid primitive');
1871 break;
1874 return _data;
1878 * @param {number} seed
1879 * @param {number} count
1880 * @param {number} componentCount
1881 * @param {number} offset
1882 * @param {number} stride
1883 * @param {glsVertexArrayTests.deArray.Primitive} primitive
1884 * @param {glsVertexArrayTests.GLValue} min
1885 * @param {glsVertexArrayTests.GLValue} max
1886 * @param {number} scale Coordinate scaling factor
1887 * @return {ArrayBuffer}
1889 glsVertexArrayTests.RandomArrayGenerator.createQuads = function(seed, count, componentCount, offset, stride, primitive, min, max, scale) {
1890 var componentStride = min.m_value.byteLength; //TODO: Fix encapsulation issue
1891 var quadStride = 0;
1892 var type = min.getType(); //Instead of using the template parameter.
1894 if (stride == 0)
1895 stride = componentCount * componentStride;
1896 DE_ASSERT(stride >= componentCount * componentStride);
1898 switch (primitive) {
1899 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
1900 quadStride = stride * 6;
1901 break;
1903 default:
1904 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuads - Invalid primitive');
1905 break;
1908 /** @type {ArrayBuffer} */ var _data = new ArrayBuffer(offset + quadStride * count);
1909 /** @type {Uint8Array} */ var resultData = new Uint8Array(_data).subarray(offset);
1911 var rnd = new deRandom.Random(seed);
1913 switch (primitive) {
1914 case glsVertexArrayTests.deArray.Primitive.TRIANGLES: {
1915 for (var quadNdx = 0; quadNdx < count; ++quadNdx) {
1916 /** @type {glsVertexArrayTests.GLValue} */ var x1 = null;
1917 /** @type {glsVertexArrayTests.GLValue} */ var x2 = null;
1918 /** @type {glsVertexArrayTests.GLValue} */ var y1 = null;
1919 /** @type {glsVertexArrayTests.GLValue} */ var y2 = null;
1920 /** @type {glsVertexArrayTests.GLValue} */ var z = null;
1921 /** @type {glsVertexArrayTests.GLValue} */ var w = null;
1923 // attempt to find a good (i.e not extremely small) quad
1924 for (var attemptNdx = 0; attemptNdx < 4; ++attemptNdx) {
1925 x1 = glsVertexArrayTests.GLValue.getRandom(rnd, min, max);
1926 x2 = glsVertexArrayTests.GLValue.getRandom(rnd, glsVertexArrayTests.GLValue.minValue(type), glsVertexArrayTests.GLValue.abs(max.sub(x1)));
1928 y1 = glsVertexArrayTests.GLValue.getRandom(rnd, min, max);
1929 y2 = glsVertexArrayTests.GLValue.getRandom(rnd, glsVertexArrayTests.GLValue.minValue(type), glsVertexArrayTests.GLValue.abs(max.sub(y1)));
1931 z = (componentCount > 2) ? (glsVertexArrayTests.GLValue.getRandom(rnd, min, max)) : (glsVertexArrayTests.GLValue.create(0, type));
1932 w = (componentCount > 3) ? (glsVertexArrayTests.GLValue.getRandom(rnd, min, max)) : (glsVertexArrayTests.GLValue.create(1, type));
1934 // no additional components, all is good
1935 if (componentCount <= 2)
1936 break;
1938 // The result quad is too thin?
1939 if ((Math.abs(x2.interpret() + z.interpret()) < glsVertexArrayTests.GLValue.minValue(type).interpret()) ||
1940 (Math.abs(y2.interpret() + w.interpret()) < glsVertexArrayTests.GLValue.minValue(type).interpret()))
1941 continue;
1943 // all ok
1944 break;
1947 x2 = x1.add(x2);
1948 y2 = y1.add(y2);
1951 * Transform GL vertex coordinates so that after vertex shading the vertices will be rounded.
1952 * We want to avoid quads that cover a pixel partially
1954 var round = function(pos, scale, offset, range) {
1955 // Perform the same transformation as the vertex shader
1956 var val = (pos.interpret() + offset) * scale;
1957 var half = range / 2;
1958 val = val * half + half;
1959 // Round it
1960 val = Math.round(val);
1961 // And reverse the vertex shading transformation
1962 val = (val - half) / half;
1963 val = val / scale - offset;
1964 return glsVertexArrayTests.GLValue.create(val, pos.m_type);
1967 var viewport = gl.getParameter(gl.VIEWPORT);
1968 var voffset = 0;
1969 if (componentCount > 2)
1970 voffset = z.interpret();
1971 x1 = round(x1, scale, voffset, viewport[2]);
1972 x2 = round(x2, scale, voffset, viewport[2]);
1973 voffset = 1;
1974 if (componentCount > 3)
1975 voffset = w.interpret();
1976 y1 = round(y1, scale, voffset, viewport[3]);
1977 y2 = round(y2, scale, voffset, viewport[3]);
1979 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride), x1);
1980 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + componentStride), y1);
1982 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride), x2);
1983 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride + componentStride), y1);
1985 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 2), x1);
1986 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 2 + componentStride), y2);
1988 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 3), x1);
1989 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 3 + componentStride), y2);
1991 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 4), x2);
1992 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 4 + componentStride), y1);
1994 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 5), x2);
1995 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * 5 + componentStride), y2);
1997 if (componentCount > 2) {
1998 for (var i = 0; i < 6; i++)
1999 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * i + componentStride * 2), z);
2002 if (componentCount > 3) {
2003 for (var i = 0; i < 6; i++)
2004 glsVertexArrayTests.copyGLValueToArray(resultData.subarray(quadNdx * quadStride + stride * i + componentStride * 3), w);
2008 break;
2011 default:
2012 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuads - Invalid primitive');
2013 break;
2016 return _data;
2020 * @param {number} seed
2021 * @param {number} count
2022 * @param {number} componentCount
2023 * @param {number} stride
2024 * @param {glsVertexArrayTests.deArray.Primitive} primitive
2025 * @param {glsVertexArrayTests.deArray.InputType} type
2026 * @param {glsVertexArrayTests.GLValue} min
2027 * @param {glsVertexArrayTests.GLValue} max
2029 glsVertexArrayTests.RandomArrayGenerator.generatePerQuad = function(seed, count, componentCount, stride, primitive, type, min, max) {
2030 /** @type {ArrayBuffer} */ var data = null;
2032 data = glsVertexArrayTests.RandomArrayGenerator.createPerQuads(seed, count, componentCount, stride, primitive, min, max);
2033 return data;
2037 * @param {number} seed
2038 * @param {number} count
2039 * @param {number} componentCount
2040 * @param {number} stride
2041 * @param {glsVertexArrayTests.deArray.Primitive} primitive
2042 * @param {glsVertexArrayTests.GLValue} min
2043 * @param {glsVertexArrayTests.GLValue} max
2045 glsVertexArrayTests.RandomArrayGenerator.createPerQuads = function(seed, count, componentCount, stride, primitive, min, max) {
2046 var rnd = new deRandom.Random(seed);
2048 var componentStride = min.m_value.byteLength; //TODO: Fix encapsulation issue.
2050 if (stride == 0)
2051 stride = componentStride * componentCount;
2053 var quadStride = 0;
2055 switch (primitive) {
2056 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
2057 quadStride = stride * 6;
2058 break;
2060 default:
2061 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createPerQuads - Invalid primitive');
2062 break;
2065 /** @type {ArrayBuffer} */ var data = new ArrayBuffer(count * quadStride);
2067 for (var quadNdx = 0; quadNdx < count; quadNdx++) {
2068 for (var componentNdx = 0; componentNdx < componentCount; componentNdx++) {
2069 /** @type {glsVertexArrayTests.GLValue} */ var val = glsVertexArrayTests.GLValue.getRandom(rnd, min, max);
2071 var data8 = new Uint8Array(data);
2072 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 0 + componentStride * componentNdx), val);
2073 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 1 + componentStride * componentNdx), val);
2074 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 2 + componentStride * componentNdx), val);
2075 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 3 + componentStride * componentNdx), val);
2076 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 4 + componentStride * componentNdx), val);
2077 glsVertexArrayTests.copyGLValueToArray(data8.subarray(quadNdx * quadStride + stride * 5 + componentStride * componentNdx), val);
2081 return data;
2085 * class glsVertexArrayTests.VertexArrayTest
2086 * @constructor
2087 * @extends {tcuTestCase.DeqpTest}
2088 * @param {string} name
2089 * @param {string} description
2091 glsVertexArrayTests.VertexArrayTest = function(name, description) {
2092 tcuTestCase.DeqpTest.call(this, name, description);
2094 var r = /** @type {number} */ (gl.getParameter(gl.RED_BITS));
2095 var g = /** @type {number} */ (gl.getParameter(gl.GREEN_BITS));
2096 var b = /** @type {number} */ (gl.getParameter(gl.BLUE_BITS));
2097 var a = /** @type {number} */ (gl.getParameter(gl.ALPHA_BITS));
2098 this.m_pixelformat = new tcuPixelFormat.PixelFormat(r, g, b, a);
2100 /** @type {sglrReferenceContext.ReferenceContextBuffers} */ this.m_refBuffers = null;
2101 /** @type {sglrReferenceContext.ReferenceContext} */ this.m_refContext = null;
2102 /** @type {sglrGLContext.GLContext} */ this.m_glesContext = null;
2103 /** @type {glsVertexArrayTests.ContextArrayPack} */ this.m_glArrayPack = null;
2104 /** @type {glsVertexArrayTests.ContextArrayPack} */ this.m_rrArrayPack = null;
2105 /** @type {boolean} */ this.m_isOk = false;
2106 /** @type {number} */ this.m_maxDiffRed = Math.ceil(256.0 * (2.0 / (1 << this.m_pixelformat.redBits)));
2107 /** @type {number} */ this.m_maxDiffGreen = Math.ceil(256.0 * (2.0 / (1 << this.m_pixelformat.greenBits)));
2108 /** @type {number} */ this.m_maxDiffBlue = Math.ceil(256.0 * (2.0 / (1 << this.m_pixelformat.blueBits)));
2111 glsVertexArrayTests.VertexArrayTest.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
2112 glsVertexArrayTests.VertexArrayTest.prototype.constructor = glsVertexArrayTests.VertexArrayTest;
2115 * init
2117 glsVertexArrayTests.VertexArrayTest.prototype.init = function() {
2118 /** @type {number}*/ var renderTargetWidth = Math.min(512, canvas.width);
2119 /** @type {number}*/ var renderTargetHeight = Math.min(512, canvas.height);
2120 /** @type {sglrReferenceContext.ReferenceContextLimits} */ var limits = new sglrReferenceContext.ReferenceContextLimits(gl);
2122 this.m_glesContext = new sglrGLContext.GLContext(gl);
2123 this.m_refBuffers = new sglrReferenceContext.ReferenceContextBuffers(this.m_pixelformat, 0, 0, renderTargetWidth, renderTargetHeight);
2124 this.m_refContext = new sglrReferenceContext.ReferenceContext(limits, this.m_refBuffers.getColorbuffer(), this.m_refBuffers.getDepthbuffer(), this.m_refBuffers.getStencilbuffer());
2126 this.m_glArrayPack = new glsVertexArrayTests.ContextArrayPack(this.m_glesContext);
2127 this.m_rrArrayPack = new glsVertexArrayTests.ContextArrayPack(this.m_refContext);
2131 * compare
2133 glsVertexArrayTests.VertexArrayTest.prototype.compare = function() {
2134 /** @type {tcuSurface.Surface} */ var ref = this.m_rrArrayPack.getSurface();
2135 /** @type {tcuSurface.Surface} */ var screen = this.m_glArrayPack.getSurface();
2137 if (/** @type {number} */ (this.m_glesContext.getParameter(gl.SAMPLES)) > 1) {
2138 // \todo [mika] Improve compare when using multisampling
2139 bufferedLogToConsole('Warning: Comparison of result from multisample render targets are not as strict as without multisampling. Might produce false positives!');
2140 this.m_isOk = tcuImageCompare.fuzzyCompare('Compare Results', 'Compare Results', ref.getAccess(), screen.getAccess(), 1.5);
2141 } else {
2142 /** @type {tcuRGBA.RGBA} */ var threshold = tcuRGBA.newRGBAComponents(this.m_maxDiffRed, this.m_maxDiffGreen, this.m_maxDiffBlue, 255);
2143 /** @type {tcuSurface.Surface} */ var error = new tcuSurface.Surface(ref.getWidth(), ref.getHeight());
2145 this.m_isOk = true;
2147 for (var y = 1; y < ref.getHeight() - 1; y++) {
2148 for (var x = 1; x < ref.getWidth() - 1; x++) {
2149 /** @type {tcuRGBA.RGBA} */ var refPixel = tcuRGBA.newRGBAFromArray(ref.getPixel(x, y));
2150 /** @type {tcuRGBA.RGBA} */ var screenPixel = tcuRGBA.newRGBAFromArray(screen.getPixel(x, y));
2151 /** @type {boolean} */ var isOkPixel = false;
2153 // Don't do comparisons for this pixel if it belongs to a one-pixel-thin part (i.e. it doesn't have similar-color neighbors in both x and y directions) in both result and reference.
2154 // This fixes some false negatives.
2155 /** @type {boolean} */ var refThin = (
2156 !tcuRGBA.compareThreshold(refPixel, tcuRGBA.newRGBAFromArray(ref.getPixel(x - 1, y)), threshold) &&
2157 !tcuRGBA.compareThreshold(refPixel, tcuRGBA.newRGBAFromArray(ref.getPixel(x + 1, y)), threshold)
2158 ) || (
2159 !tcuRGBA.compareThreshold(refPixel, tcuRGBA.newRGBAFromArray(ref.getPixel(x, y - 1)), threshold) &&
2160 !tcuRGBA.compareThreshold(refPixel, tcuRGBA.newRGBAFromArray(ref.getPixel(x, y + 1)), threshold)
2163 /** @type {boolean} */ var screenThin = (
2164 !tcuRGBA.compareThreshold(screenPixel, tcuRGBA.newRGBAFromArray(screen.getPixel(x - 1, y)), threshold) &&
2165 !tcuRGBA.compareThreshold(screenPixel, tcuRGBA.newRGBAFromArray(screen.getPixel(x + 1, y)), threshold)
2166 ) || (
2167 !tcuRGBA.compareThreshold(screenPixel, tcuRGBA.newRGBAFromArray(screen.getPixel(x, y - 1)), threshold) &&
2168 !tcuRGBA.compareThreshold(screenPixel, tcuRGBA.newRGBAFromArray(screen.getPixel(x, y + 1)), threshold)
2171 if (refThin && screenThin)
2172 isOkPixel = true;
2173 else {
2174 //NOTE: This will ignore lines less than three pixels wide, so
2175 //even if there's a difference, the test will pass.
2176 for (var dy = -1; dy < 2 && !isOkPixel; dy++) {
2177 for (var dx = -1; dx < 2 && !isOkPixel; dx++) {
2178 // Check reference pixel against screen pixel
2179 /** @type {tcuRGBA.RGBA} */ var screenCmpPixel = tcuRGBA.newRGBAFromArray(screen.getPixel(x + dx, y + dy));
2180 /** @type {number} (8-bit) */ var r = Math.abs(refPixel.getRed() - screenCmpPixel.getRed());
2181 /** @type {number} (8-bit) */ var g = Math.abs(refPixel.getGreen() - screenCmpPixel.getGreen());
2182 /** @type {number} (8-bit) */ var b = Math.abs(refPixel.getBlue() - screenCmpPixel.getBlue());
2184 if (r <= this.m_maxDiffRed && g <= this.m_maxDiffGreen && b <= this.m_maxDiffBlue)
2185 isOkPixel = true;
2187 // Check screen pixels against reference pixel
2188 /** @type {tcuRGBA.RGBA} */ var refCmpPixel = tcuRGBA.newRGBAFromArray(ref.getPixel(x + dx, y + dy));
2189 r = Math.abs(refCmpPixel.getRed() - screenPixel.getRed());
2190 g = Math.abs(refCmpPixel.getGreen() - screenPixel.getGreen());
2191 b = Math.abs(refCmpPixel.getBlue() - screenPixel.getBlue());
2193 if (r <= this.m_maxDiffRed && g <= this.m_maxDiffGreen && b <= this.m_maxDiffBlue)
2194 isOkPixel = true;
2199 if (isOkPixel)
2200 error.setPixel(x, y,
2201 [tcuRGBA.newRGBAFromArray(screen.getPixel(x, y)).getRed(),
2202 (tcuRGBA.newRGBAFromArray(screen.getPixel(x, y)).getGreen() + 255) / 2,
2203 tcuRGBA.newRGBAFromArray(screen.getPixel(x, y)).getBlue(), 255]
2205 else {
2206 error.setPixel(x, y, [255, 0, 0, 255]);
2207 this.m_isOk = false;
2212 if (!this.m_isOk) {
2213 debug('Image comparison failed, threshold = (' + this.m_maxDiffRed + ', ' + this.m_maxDiffGreen + ', ' + this.m_maxDiffBlue + ')');
2214 //log << TestLog::ImageSet("Compare result", "Result of rendering");
2215 tcuImageCompare.displayImages(screen.getAccess(), ref.getAccess(), error.getAccess());
2216 } else {
2217 //log << TestLog::ImageSet("Compare result", "Result of rendering")
2218 tcuLogImage.logImage('Result', '', screen.getAccess());
2223 //TODO: Is this actually used? -> glsVertexArrayTests.VertexArrayTest& operator= (const glsVertexArrayTests.VertexArrayTest& other);
2226 * glsVertexArrayTests.MultiVertexArrayTest class
2227 * @constructor
2228 * @extends {glsVertexArrayTests.VertexArrayTest}
2229 * @param {glsVertexArrayTests.MultiVertexArrayTest.Spec} spec
2230 * @param {string} name
2231 * @param {string} desc
2233 glsVertexArrayTests.MultiVertexArrayTest = function(spec, name, desc) {
2234 glsVertexArrayTests.VertexArrayTest.call(this, name, desc);
2236 /** @type {glsVertexArrayTests.MultiVertexArrayTest.Spec} */ this.m_spec = spec;
2237 /** @type {number} */ this.m_iteration = 0;
2240 glsVertexArrayTests.MultiVertexArrayTest.prototype = Object.create(glsVertexArrayTests.VertexArrayTest.prototype);
2241 glsVertexArrayTests.MultiVertexArrayTest.prototype.constructor = glsVertexArrayTests.MultiVertexArrayTest;
2244 * glsVertexArrayTests.MultiVertexArrayTest.Spec class
2245 * @constructor
2247 glsVertexArrayTests.MultiVertexArrayTest.Spec = function() {
2248 /** @type {glsVertexArrayTests.deArray.Primitive} */ this.primitive;
2249 /** @type {number} */ this.drawCount = 0;
2250 /** @type {number} */ this.first = 0;
2251 /** @type {Array<glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec>} */ this.arrays = [];
2255 * glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec class
2256 * @constructor
2257 * @param {glsVertexArrayTests.deArray.InputType} inputType_
2258 * @param {glsVertexArrayTests.deArray.OutputType} outputType_
2259 * @param {glsVertexArrayTests.deArray.Storage} storage_
2260 * @param {glsVertexArrayTests.deArray.Usage} usage_
2261 * @param {number} componentCount_
2262 * @param {number} offset_
2263 * @param {number} stride_
2264 * @param {boolean} normalize_
2265 * @param {glsVertexArrayTests.GLValue} min_
2266 * @param {glsVertexArrayTests.GLValue} max_
2268 glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec = function(inputType_, outputType_, storage_, usage_, componentCount_, offset_, stride_, normalize_, min_, max_) {
2269 this.inputType = inputType_;
2270 this.outputType = outputType_;
2271 this.storage = storage_;
2272 this.usage = usage_;
2273 this.componentCount = componentCount_;
2274 this.offset = offset_;
2275 /** @type {number} */ this.stride = stride_;
2276 this.normalize = normalize_;
2277 this.min = min_;
2278 this.max = max_;
2282 * getName
2283 * @return {string}
2285 glsVertexArrayTests.MultiVertexArrayTest.Spec.prototype.getName = function() {
2286 var name = '';
2288 for (var ndx = 0; ndx < this.arrays.length; ++ndx) {
2289 /** @type {glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec} */ var array = this.arrays[ndx];
2291 if (this.arrays.length > 1)
2292 name += 'array' + ndx + '_';
2294 name += glsVertexArrayTests.deArray.storageToString(array.storage) + '_' +
2295 array.offset + '_' +
2296 array.stride + '_' +
2297 glsVertexArrayTests.deArray.inputTypeToString(array.inputType);
2299 if (array.inputType != glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10 && array.inputType != glsVertexArrayTests.deArray.InputType.INT_2_10_10_10)
2300 name += array.componentCount;
2301 name += '_' +
2302 (array.normalize ? 'normalized_' : '') +
2303 glsVertexArrayTests.deArray.outputTypeToString(array.outputType) + '_' +
2304 glsVertexArrayTests.deArray.usageTypeToString(array.usage) + '_';
2307 if (this.first)
2308 name += 'first' + this.first + '_';
2310 switch (this.primitive) {
2311 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
2312 name += 'quads_';
2313 break;
2314 case glsVertexArrayTests.deArray.Primitive.POINTS:
2315 name += 'points_';
2316 break;
2318 default:
2319 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.Spec.getName - Invalid primitive type');
2320 break;
2323 name += this.drawCount;
2325 return name;
2329 * getName
2330 * @return {string}
2332 glsVertexArrayTests.MultiVertexArrayTest.Spec.prototype.getDesc = function() {
2333 var desc = '';
2335 for (var ndx = 0; ndx < this.arrays.length; ++ndx) {
2336 /** @type {glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec} */ var array = this.arrays[ndx];
2338 desc += 'Array ' + ndx + ': ' +
2339 'Storage in ' + glsVertexArrayTests.deArray.storageToString(array.storage) + ', ' +
2340 'stride ' + array.stride + ', ' +
2341 'input datatype ' + glsVertexArrayTests.deArray.inputTypeToString(array.inputType) + ', ' +
2342 'input component count ' + array.componentCount + ', ' +
2343 (array.normalize ? 'normalized, ' : '') +
2344 'used as ' + glsVertexArrayTests.deArray.outputTypeToString(array.outputType) + ', ';
2347 desc += 'drawArrays(), ' +
2348 'first ' + this.first + ', ' +
2349 this.drawCount;
2351 switch (this.primitive) {
2352 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
2353 desc += 'quads ';
2354 break;
2355 case glsVertexArrayTests.deArray.Primitive.POINTS:
2356 desc += 'points';
2357 break;
2359 default:
2360 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.Spec.getDesc - Invalid primitive type');
2361 break;
2364 return desc;
2368 * iterate
2369 * @return {tcuTestCase.IterateResult}
2371 glsVertexArrayTests.MultiVertexArrayTest.prototype.iterate = function() {
2372 if (this.m_iteration == 0) {
2373 var primitiveSize = (this.m_spec.primitive == glsVertexArrayTests.deArray.Primitive.TRIANGLES) ? (6) : (1); // in non-indexed draw Triangles means rectangles
2374 var coordScale = 1.0;
2375 var colorScale = 1.0;
2376 var useVao = true; // WebGL, WebGL 2.0 - gl.getType().getProfile() == glu::PROFILE_CORE;
2378 // Log info
2379 bufferedLogToConsole(this.m_spec.getDesc());
2381 // Color and Coord scale
2383 // First array is always position
2384 /** @type {glsVertexArrayTests.MultiVertexArrayTest.Spec.ArraySpec} */ var arraySpec = this.m_spec.arrays[0];
2385 if (arraySpec.inputType == glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10) {
2386 if (arraySpec.normalize)
2387 coordScale = 1;
2388 else
2389 coordScale = 1 / 1024;
2390 } else if (arraySpec.inputType == glsVertexArrayTests.deArray.InputType.INT_2_10_10_10) {
2391 if (arraySpec.normalize)
2392 coordScale = 1.0;
2393 else
2394 coordScale = 1.0 / 512.0;
2395 } else
2396 coordScale = arraySpec.normalize && !glsVertexArrayTests.inputTypeIsFloatType(arraySpec.inputType) ? 1.0 : 0.9 / arraySpec.max.toFloat();
2398 if (arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.VEC3 || arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.VEC4 ||
2399 arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.IVEC3 || arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.IVEC4 ||
2400 arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.UVEC3 || arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.UVEC4)
2401 coordScale = coordScale * 0.5;
2403 // And other arrays are color-like
2404 for (var arrayNdx = 1; arrayNdx < this.m_spec.arrays.length; arrayNdx++) {
2405 arraySpec = this.m_spec.arrays[arrayNdx];
2407 colorScale *= (arraySpec.normalize && !glsVertexArrayTests.inputTypeIsFloatType(arraySpec.inputType) ? 1.0 : 1.0 / arraySpec.max.toFloat());
2408 if (arraySpec.outputType == glsVertexArrayTests.deArray.OutputType.VEC4)
2409 colorScale *= (arraySpec.normalize && !glsVertexArrayTests.inputTypeIsFloatType(arraySpec.inputType) ? 1.0 : 1.0 / arraySpec.max.toFloat());
2412 // Data
2414 for (var arrayNdx = 0; arrayNdx < this.m_spec.arrays.length; arrayNdx++) {
2415 arraySpec = this.m_spec.arrays[arrayNdx];
2416 /** @type {number} */ var seed = arraySpec.inputType + 10 * arraySpec.outputType + 100 * arraySpec.storage + 1000 * this.m_spec.primitive + 10000 * arraySpec.usage + this.m_spec.drawCount + 12 * arraySpec.componentCount + arraySpec.stride + arraySpec.normalize;
2417 /** @type {ArrayBuffer} */ var data = null;
2418 /** @type {number} */ var stride = arraySpec.stride == 0 ? arraySpec.componentCount * glsVertexArrayTests.deArray.inputTypeSize(arraySpec.inputType) : arraySpec.stride;
2419 /** @type {number} */ var bufferSize = arraySpec.offset + stride * (this.m_spec.drawCount * primitiveSize - 1) + arraySpec.componentCount * glsVertexArrayTests.deArray.inputTypeSize(arraySpec.inputType);
2421 switch (this.m_spec.primitive) {
2422 // case glsVertexArrayTests.deArray.Primitive.POINTS:
2423 // data = glsVertexArrayTests.RandomArrayGenerator.generateArray(seed, arraySpec.min, arraySpec.max, arraySpec.count, arraySpec.componentCount, arraySpec.stride, arraySpec.inputType);
2424 // break;
2425 case glsVertexArrayTests.deArray.Primitive.TRIANGLES:
2426 if (arrayNdx == 0) {
2427 data = glsVertexArrayTests.RandomArrayGenerator.generateQuads(seed, this.m_spec.drawCount, arraySpec.componentCount, arraySpec.offset, arraySpec.stride, this.m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max, coordScale);
2428 } else {
2429 DE_ASSERT(arraySpec.offset == 0); // \note [jarkko] it just hasn't been implemented
2430 data = glsVertexArrayTests.RandomArrayGenerator.generatePerQuad(seed, this.m_spec.drawCount, arraySpec.componentCount, arraySpec.stride, this.m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max);
2432 break;
2434 default:
2435 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.prototype.iterate - Invalid primitive type');
2436 break;
2439 this.m_glArrayPack.newArray(arraySpec.storage);
2440 this.m_rrArrayPack.newArray(arraySpec.storage);
2442 this.m_glArrayPack.getArray(arrayNdx).data(glsVertexArrayTests.deArray.Target.ARRAY, bufferSize, new Uint8Array(data), arraySpec.usage);
2443 this.m_rrArrayPack.getArray(arrayNdx).data(glsVertexArrayTests.deArray.Target.ARRAY, bufferSize, new Uint8Array(data), arraySpec.usage);
2445 this.m_glArrayPack.getArray(arrayNdx).bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
2446 this.m_rrArrayPack.getArray(arrayNdx).bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
2449 try {
2450 this.m_glArrayPack.render(this.m_spec.primitive, this.m_spec.first, this.m_spec.drawCount * primitiveSize, useVao, coordScale, colorScale);
2451 this.m_rrArrayPack.render(this.m_spec.primitive, this.m_spec.first, this.m_spec.drawCount * primitiveSize, useVao, coordScale, colorScale);
2453 catch (err) {
2454 // GL Errors are ok if the mode is not properly aligned
2456 bufferedLogToConsole('Got error: ' + err.message);
2458 if (this.isUnalignedBufferOffsetTest())
2459 testFailedOptions('Failed to draw with unaligned buffers', false); // TODO: QP_TEST_RESULT_COMPATIBILITY_WARNING
2460 else if (this.isUnalignedBufferStrideTest())
2461 testFailedOptions('Failed to draw with unaligned stride', false); // QP_TEST_RESULT_COMPATIBILITY_WARNING
2462 else
2463 throw new Error(err.message);
2465 return tcuTestCase.IterateResult.STOP;
2468 this.m_iteration++;
2469 return tcuTestCase.IterateResult.CONTINUE;
2470 } else if (this.m_iteration == 1) {
2471 this.compare();
2473 if (this.m_isOk) {
2474 testPassedOptions('', true);
2475 } else {
2476 if (this.isUnalignedBufferOffsetTest())
2477 testFailedOptions('Failed to draw with unaligned buffers', false); // QP_TEST_RESULT_COMPATIBILITY_WARNING
2478 else if (this.isUnalignedBufferStrideTest())
2479 testFailedOptions('Failed to draw with unaligned stride', false); // QP_TEST_RESULT_COMPATIBILITY_WARNING
2480 else
2481 testFailedOptions('Image comparison failed', false);
2484 this.m_iteration++;
2485 return tcuTestCase.IterateResult.STOP;
2486 } else {
2487 testFailedOptions('glsVertexArrayTests.MultiVertexArrayTest.iterate - Invalid iteration stage', false);
2488 return tcuTestCase.IterateResult.STOP;
2493 * isUnalignedBufferOffsetTest
2494 * @return {boolean}
2496 glsVertexArrayTests.MultiVertexArrayTest.prototype.isUnalignedBufferOffsetTest = function() {
2497 // Buffer offsets should be data type size aligned
2498 for (var i = 0; i < this.m_spec.arrays.length; ++i) {
2499 if (this.m_spec.arrays[i].storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
2500 /** @type {boolean} */ var inputTypePacked = this.m_spec.arrays[i].inputType == glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10 || this.m_spec.arrays[i].inputType == glsVertexArrayTests.deArray.InputType.INT_2_10_10_10;
2502 /** @type {number} */ var dataTypeSize = glsVertexArrayTests.deArray.inputTypeSize(this.m_spec.arrays[i].inputType);
2503 if (inputTypePacked)
2504 dataTypeSize = 4;
2506 if (this.m_spec.arrays[i].offset % dataTypeSize != 0)
2507 return true;
2510 return false;
2514 * isUnalignedBufferStrideTest
2515 * @return {boolean}
2517 glsVertexArrayTests.MultiVertexArrayTest.prototype.isUnalignedBufferStrideTest = function() {
2518 // Buffer strides should be data type size aligned
2519 for (var i = 0; i < this.m_spec.arrays.length; ++i) {
2520 if (this.m_spec.arrays[i].storage == glsVertexArrayTests.deArray.Storage.BUFFER) {
2521 /** @type {boolean} */ var inputTypePacked = this.m_spec.arrays[i].inputType == glsVertexArrayTests.deArray.InputType.UNSIGNED_INT_2_10_10_10 || this.m_spec.arrays[i].inputType == glsVertexArrayTests.deArray.InputType.INT_2_10_10_10;
2523 /** @type {number} */ var dataTypeSize = glsVertexArrayTests.deArray.inputTypeSize(this.m_spec.arrays[i].inputType);
2524 if (inputTypePacked)
2525 dataTypeSize = 4;
2527 if (this.m_spec.arrays[i].stride % dataTypeSize != 0)
2528 return true;
2531 return false;