OSDN Git Service

Implement a Radiance prototype.
[android-x86/external-swiftshader.git] / src / Radiance / libRAD / HandleAllocator.cpp
1 // SwiftShader Software Renderer
2 //
3 // Copyright(c) 2005-2012 TransGaming Inc.
4 //
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.
10 //
11
12 // HandleAllocator.cpp: Implements the HandleAllocator class, which is used
13 // to allocate GL handles.
14
15 #include "HandleAllocator.h"
16
17 #include "main.h"
18
19 namespace es2
20 {
21
22 HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
23 {
24 }
25
26 HandleAllocator::~HandleAllocator()
27 {
28 }
29
30 void HandleAllocator::setBaseHandle(GLuint value)
31 {
32     ASSERT(mBaseValue == mNextValue);
33     mBaseValue = value;
34     mNextValue = value;
35 }
36
37 GLuint HandleAllocator::allocate()
38 {
39     if(mFreeValues.size())
40     {
41         GLuint handle = mFreeValues.back();
42         mFreeValues.pop_back();
43         return handle;
44     }
45     return mNextValue++;
46 }
47
48 void HandleAllocator::release(GLuint handle)
49 {
50     if(handle == mNextValue - 1)
51     {
52         // Don't drop below base value
53         if(mNextValue > mBaseValue)
54         {
55             mNextValue--;
56         }
57     }
58     else
59     {
60         // Only free handles that we own - don't drop below the base value
61         if(handle >= mBaseValue)
62         {
63             mFreeValues.push_back(handle);
64         }
65     }
66 }
67
68 }