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.h: 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 #ifndef LIBGLESV2_REFCOUNTOBJECT_H_
18 #define LIBGLESV2_REFCOUNTOBJECT_H_
20 #include "common/debug.h"
23 #include <GLES2/gl2.h>
33 explicit RefCountObject(GLuint id);
34 virtual ~RefCountObject();
36 virtual void addRef();
37 virtual void release();
39 GLuint id() const {return mId;}
44 volatile int referenceCount;
47 class RefCountObjectBindingPointer
50 RefCountObjectBindingPointer() : mObject(NULL) { }
51 ~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
53 void set(RefCountObject *newObject);
54 RefCountObject *get() const { return mObject; }
57 GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; }
58 bool operator ! () const { return (get() == NULL); }
61 RefCountObject *mObject;
64 template<class ObjectType>
65 class BindingPointer : public RefCountObjectBindingPointer
68 void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); }
69 ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
70 ObjectType *operator -> () const { return get(); }
75 #endif // LIBGLESV2_REFCOUNTOBJECT_H_