blob: e3fd36e47cb333084250fc15a961ad5ea2aa7483 [file] [log] [blame]
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00001//
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
14namespace gl
15{
16
17RefCountObject::RefCountObject(GLuint id)
18{
19 mId = id;
20 mRefCount = 0;
21}
22
23RefCountObject::~RefCountObject()
24{
25}
26
27void RefCountObject::addRef() const
28{
29 mRefCount++;
30}
31
32void RefCountObject::release() const
33{
34 ASSERT(mRefCount > 0);
35
36 if (--mRefCount == 0)
37 {
38 delete this;
39 }
40}
41
42void 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}