rrVertexPacket.js (3831B)
1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program OpenGL ES Utilities 3 * ------------------------------------------------ 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 */ 20 21 'use strict'; 22 goog.provide('framework.referencerenderer.rrVertexPacket'); 23 goog.require('framework.common.tcuTexture'); 24 goog.require('framework.delibs.debase.deMath'); 25 26 goog.scope(function() { 27 28 var rrVertexPacket = framework.referencerenderer.rrVertexPacket; 29 var tcuTexture = framework.common.tcuTexture; 30 var deMath = framework.delibs.debase.deMath; 31 32 /** 33 * rrVertexPacket.VertexPacket class. (Should only be created by rrVertexPacket.VertexPacketAllocator) 34 * @constructor 35 */ 36 rrVertexPacket.VertexPacket = function() { 37 /** @type {number} */ this.instanceNdx; 38 /** @type {number} */ this.vertexNdx; 39 /** @type {goog.NumberArray} */ this.position; //!< Transformed position - must be written always. 40 /** @type {number} */ this.pointSize; //!< Point size, required when rendering points. 41 // /** @type {number} */ this.primitiveID; //!< Geometry shader output (Not used in webGL) 42 /** @type {Array<goog.NumberArray>} */ this.outputs = [[0, 0, 0, 0]]; 43 }; 44 45 /** 46 * rrVertexPacket.VertexPacketAllocator class 47 * @constructor 48 * @param {number} numberOfVertexOutputs 49 */ 50 rrVertexPacket.VertexPacketAllocator = function(numberOfVertexOutputs) { 51 /** @type {number} */ this.m_numberOfVertexOutputs = numberOfVertexOutputs; 52 /** @type {Uint8Array} */ this.m_allocations; 53 /** @type {Array<rrVertexPacket.VertexPacket>} */ this.m_singleAllocPool = []; 54 }; 55 56 /** 57 * @return {number} 58 */ 59 rrVertexPacket.VertexPacketAllocator.prototype.getNumVertexOutputs = function() { 60 return this.m_numberOfVertexOutputs; 61 }; 62 63 /** 64 * allocArray 65 * @param {number} count 66 * @return {Array<rrVertexPacket.VertexPacket>} 67 */ 68 rrVertexPacket.VertexPacketAllocator.prototype.allocArray = function(count) { 69 if (!count) 70 return []; 71 72 /** @type {number} */ var extraVaryings = (this.m_numberOfVertexOutputs == 0) ? (0) : (this.m_numberOfVertexOutputs - 1); 73 // /** @type {number} TODO: Check what this size is used for */ var packetSize = sizeof(rrVertexPacket.VertexPacket) + extraVaryings * sizeof(GenericVec4); 74 75 /** @type {Array<rrVertexPacket.VertexPacket>} */ var retVal = []; 76 // /** @type {Uint8Array} TODO: same as above */ var ptr = new deInt8[packetSize * count]; // throws bad_alloc => ok 77 78 //run ctors 79 for (var i = 0; i < count; ++i) 80 retVal.push(new rrVertexPacket.VertexPacket()); 81 82 /** TODO: same as previous - this.m_allocations.push_back(ptr); */ 83 84 return retVal; 85 }; 86 87 /** 88 * @return {rrVertexPacket.VertexPacket} 89 */ 90 rrVertexPacket.VertexPacketAllocator.prototype.alloc = function() { 91 /** @type {number} */ var poolSize = 8; 92 93 if (this.m_singleAllocPool.length == 0) 94 this.m_singleAllocPool = this.allocArray(poolSize); 95 96 /** @type {rrVertexPacket.VertexPacket} */ var packet = this.m_singleAllocPool.pop(); 97 98 return packet; 99 }; 100 101 });