daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // RefCountObject.cpp: Defines the gl::RefCountObject base class that provides |
| 8 | // lifecycle support for GL objects using the traditional BindObject scheme, but |
| 9 | // that need to be reference counted for correct cross-context deletion. |
| 10 | // (Concretely, textures, buffers and renderbuffers.) |
| 11 | |
| 12 | #include "RefCountObject.h" |
| 13 | |
| 14 | namespace gl |
| 15 | { |
| 16 | |
| 17 | RefCountObject::RefCountObject(GLuint id) |
| 18 | { |
| 19 | mId = id; |
| 20 | mRefCount = 0; |
| 21 | } |
| 22 | |
| 23 | RefCountObject::~RefCountObject() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void RefCountObject::addRef() const |
| 28 | { |
| 29 | mRefCount++; |
| 30 | } |
| 31 | |
| 32 | void RefCountObject::release() const |
| 33 | { |
| 34 | ASSERT(mRefCount > 0); |
| 35 | |
| 36 | if (--mRefCount == 0) |
| 37 | { |
| 38 | delete this; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void RefCountObjectBindingPointer::set(RefCountObject *newObject) |
| 43 | { |
| 44 | // addRef first in case newObject == mObject and this is the last reference to it. |
| 45 | if (newObject != NULL) newObject->addRef(); |
| 46 | if (mObject != NULL) mObject->release(); |
| 47 | |
| 48 | mObject = newObject; |
| 49 | } |
| 50 | |
| 51 | } |