1 // SwiftShader Software Renderer
3 // Copyright(c) 2005-2012 TransGaming Inc.
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,
6 // transcribed, stored in a retrieval system, translated into any human or computer
7 // language by any means, or disclosed to third parties without the explicit written
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9 // or implied, including but not limited to any patent rights, are granted to you.
12 // HandleAllocator.cpp: Implements the HandleAllocator class, which is used
13 // to allocate GL handles.
15 #include "HandleAllocator.h"
22 HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
26 HandleAllocator::~HandleAllocator()
30 void HandleAllocator::setBaseHandle(GLuint value)
32 ASSERT(mBaseValue == mNextValue);
37 GLuint HandleAllocator::allocate()
39 if(mFreeValues.size())
41 GLuint handle = mFreeValues.back();
42 mFreeValues.pop_back();
48 void HandleAllocator::release(GLuint handle)
50 if(handle == mNextValue - 1)
52 // Don't drop below base value
53 if(mNextValue > mBaseValue)
60 // Only free handles that we own - don't drop below the base value
61 if(handle >= mBaseValue)
63 mFreeValues.push_back(handle);