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.
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
) {
66 throw new Error('Assert failed');
72 glsVertexArrayTests
.deArray = function() {};
75 * glsVertexArrayTests.deArray.Target enum
78 glsVertexArrayTests
.deArray
.Target
= {
84 * glsVertexArrayTests.deArray.InputType enum
87 glsVertexArrayTests
.deArray
.InputType
= {
101 UNSIGNED_INT_2_10_10_10
: 8,
106 * glsVertexArrayTests.deArray.OutputType enum
109 glsVertexArrayTests
.deArray
.OutputType
= {
128 * glsVertexArrayTests.deArray.Usage enum
131 glsVertexArrayTests
.deArray
.Usage
= {
147 * glsVertexArrayTests.deArray.Storage enum
150 glsVertexArrayTests
.deArray
.Storage
= {
156 * glsVertexArrayTests.deArray.Primitive enum
159 glsVertexArrayTests
.deArray
.Primitive
= {
166 //glsVertexArrayTests.deArray static functions
169 * @param {glsVertexArrayTests.deArray.Target} target
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
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
);
214 * @param {glsVertexArrayTests.deArray.OutputType} type
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
);
244 * @param {glsVertexArrayTests.deArray.Usage} usage
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
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
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
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
);
334 * @param {glsVertexArrayTests.deArray.InputType} type
337 glsVertexArrayTests
.inputTypeIsFloatType = function(type
) {
338 if (type
== glsVertexArrayTests
.deArray
.InputType
.FLOAT
)
340 /*if (type == glsVertexArrayTests.deArray.InputType.FIXED)
342 if (type == glsVertexArrayTests.deArray.InputType.DOUBLE)
344 if (type
== glsVertexArrayTests
.deArray
.InputType
.HALF
)
350 * @param {glsVertexArrayTests.deArray.OutputType} type
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
)
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
) {};
395 glsVertexArrayTests
.deArray
.prototype.unBind = function() {};
400 glsVertexArrayTests
.deArray
.prototype.isBound = function() {};
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() {};
430 glsVertexArrayTests
.deArray
.prototype.getNormalized = function() {};
435 glsVertexArrayTests
.deArray
.prototype.getStride = function() {};
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
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
482 glsVertexArrayTests
.ContextArray
.prototype.unBind = function() { this.m_bound
= false; };
487 glsVertexArrayTests
.ContextArray
.prototype.isBound = function() { return this.m_bound
; };
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
; };
517 glsVertexArrayTests
.ContextArray
.prototype.getNormalized = function() { return this.m_normalize
; };
522 glsVertexArrayTests
.ContextArray
.prototype.getStride = function() { return this.m_stride
; };
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
) {
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
];
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
];
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
;
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
);
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
);
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
));
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
));
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
));
655 throw new Error('glsVertexArrayTests.ContextArray.prototype.glBind - Invalid storage type specified');
658 //glsVertexArrayTests.ContextArray static functions
661 * @param {glsVertexArrayTests.deArray.Target} target
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
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
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
);
731 * @param {glsVertexArrayTests.deArray.OutputType} type
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
);
761 * @param {glsVertexArrayTests.deArray.Primitive} primitive
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
];
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
)
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
));
810 * @return {glsVertexArrayTests.ContextArray}
812 glsVertexArrayTests
.ContextArrayPack
.prototype.getArray = function(i
) {
813 return this.m_arrays
[i
];
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
) {
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
);
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
);
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
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
) {
922 switch (numComponents
) {
924 coord
[0] = attribValue
[0];
925 coord
[1] = attribValue
[0];
928 coord
[0] = attribValue
[0];
929 coord
[1] = attribValue
[1];
932 coord
[0] = attribValue
[0] + attribValue
[2];
933 coord
[1] = attribValue
[1];
936 coord
[0] = attribValue
[0] + attribValue
[2];
937 coord
[1] = attribValue
[1] + attribValue
[3];
940 throw new Error('glsVertexArrayTests.calcShaderColorCoord - Invalid number of components');
942 switch (numComponents
) {
944 color
[0] = color
[0] * attribValue
[0];
947 color
[0] = color
[0] * attribValue
[0];
948 color
[1] = color
[1] * attribValue
[1];
951 color
[0] = color
[0] * attribValue
[0];
952 color
[1] = color
[1] * attribValue
[1];
953 color
[2] = color
[2] * attribValue
[2];
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];
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
];
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];
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;
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
1015 glsVertexArrayTests
.ContextShaderProgram
.prototype.genVertexSource = function(arrays
) {
1016 var vertexShaderSrc
= '';
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';
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' +
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
):
1047 '\tcoord = vec2(a_0);\n';
1050 case (glsVertexArrayTests
.deArray
.OutputType
.VEC2
):
1052 '\tcoord = a_0.xy;\n';
1055 case (glsVertexArrayTests
.deArray
.OutputType
.VEC3
):
1057 '\tcoord = a_0.xy;\n' +
1058 '\tcoord.x = coord.x + a_0.z;\n';
1061 case (glsVertexArrayTests
.deArray
.OutputType
.VEC4
):
1063 '\tcoord = a_0.xy;\n' +
1064 '\tcoord += a_0.zw;\n';
1067 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC2
):
1068 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC2
):
1070 '\tcoord = vec2(a_0.xy);\n';
1073 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC3
):
1074 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC3
):
1076 '\tcoord = vec2(a_0.xy);\n' +
1077 '\tcoord.x = coord.x + float(a_0.z);\n';
1080 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC4
):
1081 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC4
):
1083 '\tcoord = vec2(a_0.xy);\n' +
1084 '\tcoord += vec2(a_0.zw);\n';
1088 throw new Error('Invalid output type');
1094 switch (arrays
[arrayNdx
].getOutputType()) {
1095 case (glsVertexArrayTests
.deArray
.OutputType
.FLOAT
):
1097 '\tcolor = color * a_' + arrays
[arrayNdx
].getAttribNdx() + ';\n';
1100 case (glsVertexArrayTests
.deArray
.OutputType
.VEC2
):
1102 '\tcolor.rg = color.rg * a_' + arrays
[arrayNdx
].getAttribNdx() + '.xy;\n';
1105 case (glsVertexArrayTests
.deArray
.OutputType
.VEC3
):
1107 '\tcolor = color.rgb * a_' + arrays
[arrayNdx
].getAttribNdx() + '.xyz;\n';
1110 case (glsVertexArrayTests
.deArray
.OutputType
.VEC4
):
1112 '\tcolor = color.rgb * a_' + arrays
[arrayNdx
].getAttribNdx() + '.xyz * a_' + arrays
[arrayNdx
].getAttribNdx() + '.w;\n';
1116 throw new Error('Invalid output type');
1122 '\tv_color = vec4(u_colorScale * color, 1.0);\n' +
1123 '\tgl_Position = vec4(u_coordScale * coord, 1.0, 1.0);\n' +
1126 return vertexShaderSrc
;
1132 glsVertexArrayTests
.ContextShaderProgram
.prototype.genFragmentSource = function() {
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' +
1148 '\t' + params
['FRAG_COLOR'] + ' = v_color;\n' +
1151 return fragmentShaderSrc
;
1155 * @param {glsVertexArrayTests.deArray.OutputType} type
1156 * @return {rrGenericVector.GenericVecType}
1158 glsVertexArrayTests
.ContextShaderProgram
.prototype.mapOutputType = function(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
;
1179 throw new Error('Invalid output type');
1184 * @param {glsVertexArrayTests.deArray.OutputType} type
1187 glsVertexArrayTests
.ContextShaderProgram
.prototype.getComponentCount = function(type
) {
1189 case (glsVertexArrayTests
.deArray
.OutputType
.FLOAT
):
1190 case (glsVertexArrayTests
.deArray
.OutputType
.INT
):
1191 case (glsVertexArrayTests
.deArray
.OutputType
.UINT
):
1194 case (glsVertexArrayTests
.deArray
.OutputType
.VEC2
):
1195 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC2
):
1196 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC2
):
1199 case (glsVertexArrayTests
.deArray
.OutputType
.VEC3
):
1200 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC3
):
1201 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC3
):
1204 case (glsVertexArrayTests
.deArray
.OutputType
.VEC4
):
1205 case (glsVertexArrayTests
.deArray
.OutputType
.IVEC4
):
1206 case (glsVertexArrayTests
.deArray
.OutputType
.UVEC4
):
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
));
1238 * glsVertexArrayTests.GLValue class
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
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
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
) {
1273 case glsVertexArrayTests
.deArray
.InputType
.FLOAT
:
1274 array
= new Float32Array(1);
1276 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1277 array = new Int32Array(1);
1279 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1280 array = new Float32Array(1); // 64-bit?
1283 case glsVertexArrayTests
.deArray
.InputType
.BYTE
:
1284 array
= new Int8Array(1);
1286 case glsVertexArrayTests
.deArray
.InputType
.SHORT
:
1287 array
= new Int16Array(1);
1290 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_BYTE
:
1291 array
= new Uint8Array(1);
1293 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_SHORT
:
1294 array
= new Uint16Array(1);
1297 case glsVertexArrayTests
.deArray
.InputType
.INT
:
1298 array
= new Int32Array(1);
1300 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_INT
:
1301 array
= new Uint32Array(1);
1303 case glsVertexArrayTests
.deArray
.InputType
.HALF
:
1304 array
= new Uint16Array(1);
1305 value
= glsVertexArrayTests
.GLValue
.floatToHalf(value
);
1307 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_INT_2_10_10_10
:
1308 array
= new Uint32Array(1);
1310 case glsVertexArrayTests
.deArray
.InputType
.INT_2_10_10_10
:
1311 array
= new Int32Array(1);
1314 throw new Error('glsVertexArrayTests.GLValue.typeToTypedArray - Invalid InputType');
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
);
1334 * glsVertexArrayTests.GLValue.halfToFloat
1335 * @param {number} value
1338 glsVertexArrayTests
.GLValue
.halfToFloat = function(value
) {
1339 return tcuFloat
.halfFloatToNumberNoDenorm(value
);
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
) {
1360 case glsVertexArrayTests
.deArray
.InputType
.FLOAT
:
1363 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1366 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1369 case glsVertexArrayTests
.deArray
.InputType
.BYTE
:
1372 case glsVertexArrayTests
.deArray
.InputType
.SHORT
:
1375 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_BYTE
:
1378 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_SHORT
:
1381 case glsVertexArrayTests
.deArray
.InputType
.INT
:
1384 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_INT
:
1387 case glsVertexArrayTests
.deArray
.InputType
.HALF
:
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
) {
1406 case glsVertexArrayTests
.deArray
.InputType
.FLOAT
:
1409 /*case glsVertexArrayTests.deArray.InputType.FIXED:
1412 case glsVertexArrayTests.deArray.InputType.DOUBLE:
1415 case glsVertexArrayTests
.deArray
.InputType
.BYTE
:
1418 case glsVertexArrayTests
.deArray
.InputType
.SHORT
:
1421 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_BYTE
:
1424 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_SHORT
:
1427 case glsVertexArrayTests
.deArray
.InputType
.INT
:
1428 value
= -2147483647;
1430 case glsVertexArrayTests
.deArray
.InputType
.UNSIGNED_INT
:
1433 case glsVertexArrayTests
.deArray
.InputType
.HALF
:
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();
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
);
1470 /*case glsVertexArrayTests.deArray.InputType.FIXED: {
1471 return minv == maxv ? min : glsVertexArrayTests.GLValue.create(minv + rnd.getInt() % (maxv - minv), type);
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
);
1486 throw new Error('glsVertexArrayTests.GLValue.getRandom - Invalid input type');
1491 // Minimum difference required between coordinates
1494 * @param {glsVertexArrayTests.deArray.InputType} type
1495 * @return {glsVertexArrayTests.GLValue}
1497 glsVertexArrayTests
.GLValue
.minValue = function(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
);
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();
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
:
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
);
1543 throw new Error('glsVertexArrayTests.GLValue.abs - Invalid input type');
1548 * @return {glsVertexArrayTests.deArray.InputType}
1550 glsVertexArrayTests
.GLValue
.prototype.getType = function() {
1555 * glsVertexArrayTests.GLValue.toFloat
1558 glsVertexArrayTests
.GLValue
.prototype.toFloat = function() {
1559 return this.interpret();
1563 * glsVertexArrayTests.GLValue.getValue
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.
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();
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();
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();
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();
1655 * @param {glsVertexArrayTests.GLValue} other
1658 glsVertexArrayTests
.GLValue
.prototype.equals = function(other
) {
1659 return this.m_value
[0] == other
.getValue();
1663 * @param {glsVertexArrayTests.GLValue} other
1666 glsVertexArrayTests
.GLValue
.prototype.lessThan = function(other
) {
1667 return this.interpret() < other
.interpret();
1671 * @param {glsVertexArrayTests.GLValue} other
1674 glsVertexArrayTests
.GLValue
.prototype.greaterThan = function(other
) {
1675 return this.interpret() > other
.interpret();
1679 * @param {glsVertexArrayTests.GLValue} other
1682 glsVertexArrayTests
.GLValue
.prototype.lessOrEqualThan = function(other
) {
1683 return this.interpret() <= other
.interpret();
1687 * @param {glsVertexArrayTests.GLValue} other
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
);
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
);
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
);
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);
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);
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
;
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
);
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
);
1795 throw new Error('glsVertexArrayTests.RandomArrayGenerator.generateQuads - Invalid input type');
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;
1817 stride
= deMath
.INT32_SIZE
;
1819 switch (primitive
) {
1820 case glsVertexArrayTests
.deArray
.Primitive
.TRIANGLES
:
1821 quadStride
= stride
* 6;
1825 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked - Invalid primitive');
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
]));
1870 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuadsPacked - Invalid primitive');
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
1892 var type
= min
.getType(); //Instead of using the template parameter.
1895 stride
= componentCount
* componentStride
;
1896 DE_ASSERT(stride
>= componentCount
* componentStride
);
1898 switch (primitive
) {
1899 case glsVertexArrayTests
.deArray
.Primitive
.TRIANGLES
:
1900 quadStride
= stride
* 6;
1904 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuads - Invalid primitive');
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)
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()))
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
;
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
);
1969 if (componentCount
> 2)
1970 voffset
= z
.interpret();
1971 x1
= round(x1
, scale
, voffset
, viewport
[2]);
1972 x2
= round(x2
, scale
, voffset
, viewport
[2]);
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
);
2012 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createQuads - Invalid primitive');
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
);
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.
2051 stride
= componentStride
* componentCount
;
2055 switch (primitive
) {
2056 case glsVertexArrayTests
.deArray
.Primitive
.TRIANGLES
:
2057 quadStride
= stride
* 6;
2061 throw new Error('glsVertexArrayTests.RandomArrayGenerator.createPerQuads - Invalid primitive');
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
);
2085 * class glsVertexArrayTests.VertexArrayTest
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
;
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
);
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);
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());
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
)
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
)
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
)
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
)
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
)
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]
2206 error
.setPixel(x
, y
, [255, 0, 0, 255]);
2207 this.m_isOk
= false;
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());
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
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
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
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_
;
2285 glsVertexArrayTests
.MultiVertexArrayTest
.Spec
.prototype.getName = function() {
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
;
2302 (array
.normalize
? 'normalized_' : '') +
2303 glsVertexArrayTests
.deArray
.outputTypeToString(array
.outputType
) + '_' +
2304 glsVertexArrayTests
.deArray
.usageTypeToString(array
.usage
) + '_';
2308 name
+= 'first' + this.first
+ '_';
2310 switch (this.primitive
) {
2311 case glsVertexArrayTests
.deArray
.Primitive
.TRIANGLES
:
2314 case glsVertexArrayTests
.deArray
.Primitive
.POINTS
:
2319 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.Spec.getName - Invalid primitive type');
2323 name
+= this.drawCount
;
2332 glsVertexArrayTests
.MultiVertexArrayTest
.Spec
.prototype.getDesc = function() {
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
+ ', ' +
2351 switch (this.primitive
) {
2352 case glsVertexArrayTests
.deArray
.Primitive
.TRIANGLES
:
2355 case glsVertexArrayTests
.deArray
.Primitive
.POINTS
:
2360 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.Spec.getDesc - Invalid primitive type');
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;
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
)
2389 coordScale
= 1 / 1024;
2390 } else if (arraySpec
.inputType
== glsVertexArrayTests
.deArray
.InputType
.INT_2_10_10_10
) {
2391 if (arraySpec
.normalize
)
2394 coordScale
= 1.0 / 512.0;
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());
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);
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
);
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
);
2435 throw new Error('glsVertexArrayTests.MultiVertexArrayTest.prototype.iterate - Invalid primitive type');
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
);
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
);
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
2463 throw new Error(err
.message
);
2465 return tcuTestCase
.IterateResult
.STOP
;
2469 return tcuTestCase
.IterateResult
.CONTINUE
;
2470 } else if (this.m_iteration
== 1) {
2474 testPassedOptions('', true);
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
2481 testFailedOptions('Image comparison failed', false);
2485 return tcuTestCase
.IterateResult
.STOP
;
2487 testFailedOptions('glsVertexArrayTests.MultiVertexArrayTest.iterate - Invalid iteration stage', false);
2488 return tcuTestCase
.IterateResult
.STOP
;
2493 * isUnalignedBufferOffsetTest
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
)
2506 if (this.m_spec
.arrays
[i
].offset
% dataTypeSize
!= 0)
2514 * isUnalignedBufferStrideTest
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
)
2527 if (this.m_spec
.arrays
[i
].stride
% dataTypeSize
!= 0)