1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Reference Renderer
3 * -----------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Vertex packet and Vertex packet allocator
22 *//*--------------------------------------------------------------------*/
24 #include "rrVertexPacket.hpp"
29 VertexPacket::VertexPacket (void)
33 VertexPacket::~VertexPacket (void)
37 VertexPacketAllocator::VertexPacketAllocator (const size_t numberOfVertexOutputs)
38 : m_numberOfVertexOutputs(numberOfVertexOutputs)
42 VertexPacketAllocator::~VertexPacketAllocator (void)
44 for (size_t i = 0; i < m_allocations.size(); ++i)
45 delete [] m_allocations[i];
46 m_allocations.clear();
49 std::vector<VertexPacket*> VertexPacketAllocator::allocArray (size_t count)
52 return std::vector<VertexPacket*>();
54 const size_t extraVaryings = (m_numberOfVertexOutputs == 0) ? (0) : (m_numberOfVertexOutputs-1);
55 const size_t packetSize = sizeof(VertexPacket) + extraVaryings * sizeof(GenericVec4);
57 std::vector<VertexPacket*> retVal;
58 deInt8* ptr = new deInt8[packetSize * count]; // throws bad_alloc => ok
60 // *.push_back might throw bad_alloc
64 for (size_t i = 0; i < count; ++i)
65 retVal.push_back(new (ptr + i*packetSize) VertexPacket()); // throws bad_alloc
67 m_allocations.push_back(ptr); // throws bad_alloc
69 catch (std::bad_alloc& )
78 VertexPacket* VertexPacketAllocator::alloc (void)
80 const size_t poolSize = 8;
82 if (m_singleAllocPool.empty())
83 m_singleAllocPool = allocArray(poolSize);
85 VertexPacket* packet = *--m_singleAllocPool.end();
86 m_singleAllocPool.pop_back();