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 // RefCountObject.cpp: Defines the RefCountObject base class that provides
13 // lifecycle support for GL objects using the traditional BindObject scheme, but
14 // that need to be reference counted for correct cross-context deletion.
15 // (Concretely, textures, buffers and renderbuffers.)
17 #include "RefCountObject.h"
19 #include "Common/Thread.hpp"
24 RefCountObject::RefCountObject(GLuint id)
31 RefCountObject::~RefCountObject()
33 ASSERT(referenceCount == 0);
36 void RefCountObject::addRef()
38 sw::atomicIncrement(&referenceCount);
41 void RefCountObject::release()
43 ASSERT(referenceCount > 0);
45 if(referenceCount > 0)
47 sw::atomicDecrement(&referenceCount);
50 if(referenceCount == 0)
56 void RefCountObjectBindingPointer::set(RefCountObject *newObject)
58 // addRef first in case newObject == mObject and this is the last reference to it.
59 if(newObject != NULL) newObject->addRef();
60 if(mObject != NULL) mObject->release();