main internal changes to glw and some public interface changes that affect naming. CHANGES ARE NOT BACKWARD COMPATIBLE.
This commit is contained in:
parent
cb3fc0dbe2
commit
d8897e798e
|
@ -6,29 +6,85 @@
|
|||
namespace glw
|
||||
{
|
||||
|
||||
class Context;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename TObject>
|
||||
class SharedObjectBase
|
||||
{
|
||||
friend class Context;
|
||||
struct NoBase { };
|
||||
template <typename T> struct DefaultDeleter { void operator () (T * t) { delete t; } };
|
||||
|
||||
template <typename T> struct BaseOf { typedef NoBase Type; };
|
||||
|
||||
template <typename T, typename B> struct RootOfType { typedef typename RootOfType<B, typename BaseOf<B>::Type>::Type Type; };
|
||||
template <typename T> struct RootOfType<T, NoBase> { typedef T Type; };
|
||||
template <typename T> struct RootOf { typedef typename RootOfType<T, typename BaseOf<T>::Type>::Type Type; };
|
||||
|
||||
template <typename T, typename B> struct DeleterOfType { typedef typename DeleterOfType<B, typename BaseOf<B>::Type>::Type Type; };
|
||||
template <typename T> struct DeleterOfType<T, NoBase> { typedef DefaultDeleter<T> Type; };
|
||||
template <typename T> struct DeleterOf { typedef typename DeleterOfType<T, typename BaseOf<T>::Type>::Type Type; };
|
||||
|
||||
template <typename TObject, typename TDeleter, typename TBaseObject>
|
||||
class RefCountedObject : public RefCountedObject<TBaseObject, TDeleter, typename BaseOf<TBaseObject>::Type>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SharedObjectBase<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef RefCountedObject<TBaseObject, TDeleter, typename BaseOf<TBaseObject>::Type> BaseType;
|
||||
typedef RefCountedObject<TObject, TDeleter, TBaseObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TDeleter DeleterType;
|
||||
typedef TBaseObject BaseObjectType;
|
||||
|
||||
RefCountedObject(ObjectType * object, const DeleterType & deleter)
|
||||
: BaseType(object, deleter)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ObjectType * object(void) const
|
||||
{
|
||||
return static_cast<const ObjectType *>(BaseType::object());
|
||||
}
|
||||
|
||||
ObjectType * object(void)
|
||||
{
|
||||
return static_cast<ObjectType *>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TObject, typename TDeleter>
|
||||
class RefCountedObject<TObject, TDeleter, NoBase>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef RefCountedObject<TObject, TDeleter, NoBase> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TDeleter DeleterType;
|
||||
typedef NoBase BaseObjectType;
|
||||
|
||||
RefCountedObject(ObjectType * object, const DeleterType & deleter)
|
||||
: m_object (object)
|
||||
, m_refCount (0)
|
||||
, m_deleter (deleter)
|
||||
{
|
||||
GLW_ASSERT(this->m_object != 0);
|
||||
}
|
||||
|
||||
~RefCountedObject(void)
|
||||
{
|
||||
this->destroyObject();
|
||||
}
|
||||
|
||||
bool isNull(void) const
|
||||
{
|
||||
return (this->m_object == 0);
|
||||
}
|
||||
|
||||
void setNull(void)
|
||||
void setNull(bool deleteObject)
|
||||
{
|
||||
if (deleteObject)
|
||||
{
|
||||
this->destroyObject();
|
||||
}
|
||||
this->m_object = 0;
|
||||
}
|
||||
|
||||
|
@ -42,6 +98,16 @@ class SharedObjectBase
|
|||
return this->m_object;
|
||||
}
|
||||
|
||||
const DeleterType & deleter(void) const
|
||||
{
|
||||
return this->m_deleter;
|
||||
}
|
||||
|
||||
DeleterType & deleter(void)
|
||||
{
|
||||
return this->m_deleter;
|
||||
}
|
||||
|
||||
void ref(void)
|
||||
{
|
||||
this->m_refCount++;
|
||||
|
@ -53,400 +119,86 @@ class SharedObjectBase
|
|||
this->m_refCount--;
|
||||
if (this->m_refCount == 0)
|
||||
{
|
||||
if (this->m_object != 0)
|
||||
{
|
||||
this->signalDestruction();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
int refCount(void) const
|
||||
{
|
||||
return this->m_refCount;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Context * m_context;
|
||||
ObjectType * m_object;
|
||||
int m_refCount;
|
||||
DeleterType m_deleter;
|
||||
|
||||
SharedObjectBase(Context * Context, ObjectType * Object)
|
||||
: m_context (Context)
|
||||
, m_object (Object)
|
||||
, m_refCount (0)
|
||||
{
|
||||
GLW_ASSERT(this->m_context != 0);
|
||||
GLW_ASSERT(this->m_object != 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
SharedObjectBase(const ThisType & other);
|
||||
RefCountedObject(const ThisType & other);
|
||||
ThisType & operator = (const ThisType & other);
|
||||
|
||||
inline void signalDestruction(void);
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SharedObject;
|
||||
|
||||
template <typename TObject, typename TObjectBase>
|
||||
class SharedObjectTraits
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SharedObjectTraits<TObject, TObjectBase> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TObjectBase ObjectBaseType;
|
||||
typedef SharedObject<ObjectBaseType> SharedObjectBaseType;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SharedObjectTraits<TObject, void>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SharedObjectTraits<TObject, void> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef void ObjectBaseType;
|
||||
typedef SharedObjectBase<ObjectType> SharedObjectBaseType;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SharedObject : public SharedObjectTraits<TObject, typename TObject::BaseType>::SharedObjectBaseType
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef typename SharedObjectTraits<TObject, typename TObject::BaseType>::SharedObjectBaseType BaseType;
|
||||
typedef SharedObject<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
|
||||
const ObjectType * object(void) const
|
||||
void destroyObject(void)
|
||||
{
|
||||
return static_cast<const ObjectType *>(BaseType::object());
|
||||
}
|
||||
|
||||
ObjectType * object(void)
|
||||
{
|
||||
return static_cast<ObjectType *>(BaseType::object());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SharedObject(Context * Context, ObjectType * Object)
|
||||
: BaseType(Context, Object)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
SharedObject(const ThisType & other);
|
||||
ThisType & operator = (const ThisType & other);
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SharedObjectBinding
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SharedObjectBinding<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef ObjectType UnsafeType;
|
||||
|
||||
~SharedObjectBinding(void)
|
||||
{
|
||||
this->detach();
|
||||
}
|
||||
|
||||
bool isNull(void) const
|
||||
{
|
||||
if (this->m_shared == 0) return true;
|
||||
return this->m_shared->isNull();
|
||||
}
|
||||
|
||||
void setNull(void)
|
||||
{
|
||||
this->m_shared = 0;
|
||||
}
|
||||
|
||||
const ObjectType * object(void) const
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
const ObjectType * obj = this->m_shared->object();
|
||||
obj->setBinding(this->m_target, this->m_unit);
|
||||
return obj;
|
||||
}
|
||||
|
||||
ObjectType * object(void)
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
ObjectType * obj = this->m_shared->object();
|
||||
obj->setBinding(this->m_target, this->m_unit);
|
||||
return obj;
|
||||
}
|
||||
|
||||
GLenum target(void) const
|
||||
{
|
||||
return this->m_target;
|
||||
}
|
||||
|
||||
GLint unit(void) const
|
||||
{
|
||||
return this->m_unit;
|
||||
}
|
||||
|
||||
void ref(void)
|
||||
{
|
||||
this->m_refCount++;
|
||||
}
|
||||
|
||||
void unref(void)
|
||||
{
|
||||
GLW_ASSERT(this->m_refCount > 0);
|
||||
this->m_refCount--;
|
||||
if (this->m_refCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
typedef SharedObject<ObjectType> SharedObjectType;
|
||||
|
||||
SharedObjectBinding(SharedObjectType * shared, GLenum target, GLint unit)
|
||||
: m_shared (0)
|
||||
, m_refCount (0)
|
||||
, m_target (target)
|
||||
, m_unit (unit)
|
||||
{
|
||||
this->attach(shared);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
SharedObjectType * m_shared;
|
||||
int m_refCount;
|
||||
GLenum m_target;
|
||||
GLint m_unit;
|
||||
|
||||
SharedObjectBinding(const ThisType & other);
|
||||
ThisType & operator = (const ThisType & other);
|
||||
|
||||
void attach(SharedObjectType * shared)
|
||||
{
|
||||
this->detach();
|
||||
this->m_shared = shared;
|
||||
if (this->m_shared != 0)
|
||||
{
|
||||
this->m_shared->ref();
|
||||
}
|
||||
}
|
||||
|
||||
void detach(void)
|
||||
{
|
||||
if (this->m_shared == 0) return;
|
||||
this->m_shared->unref();
|
||||
this->m_shared = 0;
|
||||
if (this->m_object == 0) return;
|
||||
this->m_deleter(this->m_object);
|
||||
this->m_object = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SafeHandleBase
|
||||
{
|
||||
friend class Context;
|
||||
template <typename T> struct RefCountedObjectTraits { typedef RefCountedObject<T, typename DeleterOf<T>::Type, typename BaseOf<T>::Type> Type; };
|
||||
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SafeHandleBase<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef typename ObjectType::SafeType SafeType;
|
||||
|
||||
SafeHandleBase(void)
|
||||
: m_shared(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SafeHandleBase(const ThisType & other)
|
||||
: m_shared(0)
|
||||
{
|
||||
this->attach(other.shared());
|
||||
}
|
||||
|
||||
~SafeHandleBase(void)
|
||||
{
|
||||
this->detach();
|
||||
}
|
||||
|
||||
bool isNull(void) const
|
||||
{
|
||||
if (this->m_shared == 0) return true;
|
||||
return this->m_shared->isNull();
|
||||
}
|
||||
|
||||
void setNull(void)
|
||||
{
|
||||
this->detach();
|
||||
}
|
||||
|
||||
const SafeType * operator -> (void) const
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_shared->object();
|
||||
}
|
||||
|
||||
SafeType * operator -> (void)
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_shared->object();
|
||||
}
|
||||
|
||||
ThisType & operator = (const ThisType & other)
|
||||
{
|
||||
this->attach(other.shared());
|
||||
return (*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
typedef SharedObject<ObjectType> SharedObjectType;
|
||||
|
||||
SafeHandleBase(SharedObjectType * shared)
|
||||
: m_shared(0)
|
||||
{
|
||||
this->attach(shared);
|
||||
}
|
||||
|
||||
const ObjectType * object(void) const
|
||||
{
|
||||
if (this->m_shared == 0) return 0;
|
||||
return this->m_shared->object();
|
||||
}
|
||||
|
||||
ObjectType * object(void)
|
||||
{
|
||||
if (this->m_shared == 0) return 0;
|
||||
return this->m_shared->object();
|
||||
}
|
||||
|
||||
SharedObjectType * shared(void) const
|
||||
{
|
||||
return this->m_shared;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
SharedObjectType * m_shared;
|
||||
|
||||
void attach(SharedObjectType * shared)
|
||||
{
|
||||
this->detach();
|
||||
this->m_shared = shared;
|
||||
if (this->m_shared != 0)
|
||||
{
|
||||
this->m_shared->ref();
|
||||
}
|
||||
}
|
||||
|
||||
void detach(void)
|
||||
{
|
||||
if (this->m_shared == 0) return;
|
||||
this->m_shared->unref();
|
||||
this->m_shared = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SafeHandle;
|
||||
|
||||
template <typename TObject, typename TObjectBase>
|
||||
class SafeHandleTraits
|
||||
template <typename TObject, typename TDeleter, typename TBaseObject>
|
||||
class ObjectSharedPointer : public ObjectSharedPointer<TBaseObject, TDeleter, typename BaseOf<TBaseObject>::Type>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SafeHandleTraits<TObject, TObjectBase> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TObjectBase ObjectBaseType;
|
||||
typedef SafeHandle<ObjectBaseType> SafeHandleBaseType;
|
||||
};
|
||||
typedef ObjectSharedPointer<TBaseObject, TDeleter, typename BaseOf<TBaseObject>::Type> BaseType;
|
||||
typedef ObjectSharedPointer<TObject, TDeleter, TBaseObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TDeleter DeleterType;
|
||||
typedef TBaseObject BaseObjectType;
|
||||
typedef RefCountedObject<ObjectType, DeleterType, BaseObjectType> RefCountedObjectType;
|
||||
|
||||
template <typename TObject>
|
||||
class SafeHandleTraits<TObject, void>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SafeHandleTraits<TObject, void> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef void ObjectBaseType;
|
||||
typedef SafeHandleBase<ObjectType> SafeHandleBaseType;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class SafeHandle : public SafeHandleTraits<TObject, typename TObject::BaseType>::SafeHandleBaseType
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef typename SafeHandleTraits<TObject, typename TObject::BaseType>::SafeHandleBaseType BaseType;
|
||||
typedef SafeHandle<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef typename ObjectType::SafeType SafeType;
|
||||
|
||||
SafeHandle(void)
|
||||
ObjectSharedPointer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SafeHandle(const ThisType & other)
|
||||
ObjectSharedPointer(const ThisType & other)
|
||||
: BaseType(other)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const SafeType * operator -> (void) const
|
||||
{
|
||||
return dynamic_cast<const SafeType *>(BaseType:: operator ->());
|
||||
}
|
||||
|
||||
SafeType * operator -> (void)
|
||||
{
|
||||
return dynamic_cast<SafeType *>(BaseType:: operator ->());
|
||||
}
|
||||
|
||||
/*
|
||||
ThisType & operator = (const ThisType & other)
|
||||
{
|
||||
this->attach(other.shared());
|
||||
return (*this);
|
||||
}
|
||||
*/
|
||||
|
||||
operator bool (void) const
|
||||
{
|
||||
return !this->isNull();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
typedef SharedObject<ObjectType> SharedObjectType;
|
||||
|
||||
SafeHandle(SharedObjectType * shared)
|
||||
: BaseType(shared)
|
||||
ObjectSharedPointer(RefCountedObjectType * refObject)
|
||||
: BaseType(refObject)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ObjectType & operator * (void) const
|
||||
{
|
||||
return (*(this->object()));
|
||||
}
|
||||
|
||||
ObjectType & operator * (void)
|
||||
{
|
||||
return (*(this->object()));
|
||||
}
|
||||
|
||||
const ObjectType * operator -> (void) const
|
||||
{
|
||||
return this->object();
|
||||
}
|
||||
|
||||
ObjectType * operator -> (void)
|
||||
{
|
||||
return this->object();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
const ObjectType * object(void) const
|
||||
{
|
||||
return static_cast<const ObjectType *>(BaseType::object());
|
||||
|
@ -457,45 +209,51 @@ class SafeHandle : public SafeHandleTraits<TObject, typename TObject::BaseType>:
|
|||
return static_cast<ObjectType *>(BaseType::object());
|
||||
}
|
||||
|
||||
SharedObjectType * shared(void) const
|
||||
RefCountedObjectType * refObject(void) const
|
||||
{
|
||||
return static_cast<SharedObjectType *>(BaseType::shared());
|
||||
return static_cast<RefCountedObjectType *>(BaseType::refObject());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
class UnsafeHandle
|
||||
template <typename TObject, typename TDeleter>
|
||||
class ObjectSharedPointer<TObject, TDeleter, NoBase>
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef UnsafeHandle<TObject> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef ObjectType UnsafeType;
|
||||
typedef void BaseType;
|
||||
typedef ObjectSharedPointer<TObject, TDeleter, NoBase> ThisType;
|
||||
typedef TObject ObjectType;
|
||||
typedef TDeleter DeleterType;
|
||||
typedef NoBase BaseObjectType;
|
||||
typedef RefCountedObject<ObjectType, DeleterType, NoBase> RefCountedObjectType;
|
||||
|
||||
UnsafeHandle(void)
|
||||
: m_shared(0)
|
||||
ObjectSharedPointer(void)
|
||||
: m_refObject(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
UnsafeHandle(const ThisType & other)
|
||||
: m_shared(0)
|
||||
ObjectSharedPointer(const ThisType & other)
|
||||
: m_refObject(0)
|
||||
{
|
||||
this->attach(other.shared());
|
||||
this->attach(other.refObject());
|
||||
}
|
||||
|
||||
~UnsafeHandle(void)
|
||||
ObjectSharedPointer(RefCountedObjectType * refObject)
|
||||
: m_refObject(0)
|
||||
{
|
||||
this->attach(refObject);
|
||||
}
|
||||
|
||||
~ObjectSharedPointer(void)
|
||||
{
|
||||
this->detach();
|
||||
}
|
||||
|
||||
bool isNull(void) const
|
||||
{
|
||||
if (this->m_shared == 0) return true;
|
||||
return this->m_shared->isNull();
|
||||
if (this->m_refObject == 0) return true;
|
||||
return this->m_refObject->isNull();
|
||||
}
|
||||
|
||||
void setNull(void)
|
||||
|
@ -503,78 +261,80 @@ class UnsafeHandle
|
|||
this->detach();
|
||||
}
|
||||
|
||||
const UnsafeType * operator -> (void) const
|
||||
const ObjectType & operator * (void) const
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_shared->object();
|
||||
return (*(this->object()));
|
||||
}
|
||||
|
||||
UnsafeType * operator -> (void)
|
||||
ObjectType & operator * (void)
|
||||
{
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_shared->object();
|
||||
return (*(this->object()));
|
||||
}
|
||||
|
||||
ThisType & operator = (const ThisType & other)
|
||||
const ObjectType * operator -> (void) const
|
||||
{
|
||||
this->attach(other.shared());
|
||||
return (*this);
|
||||
return this->object();
|
||||
}
|
||||
|
||||
ObjectType * operator -> (void)
|
||||
{
|
||||
return this->object();
|
||||
}
|
||||
|
||||
operator bool (void) const
|
||||
{
|
||||
return !this->isNull();
|
||||
return (!this->isNull());
|
||||
}
|
||||
|
||||
ThisType & operator = (const ThisType & other)
|
||||
{
|
||||
this->attach(other.refObject());
|
||||
return (*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
typedef SharedObjectBinding<ObjectType> SharedObjectBindingType;
|
||||
|
||||
UnsafeHandle(SharedObjectBindingType * shared)
|
||||
: m_shared(0)
|
||||
const ObjectType * object(void) const
|
||||
{
|
||||
this->attach(shared);
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_refObject->object();
|
||||
}
|
||||
|
||||
const ObjectType * Object(void) const
|
||||
ObjectType * object(void)
|
||||
{
|
||||
if (this->m_shared == 0) return true;
|
||||
return this->m_shared->object();
|
||||
GLW_ASSERT(!this->isNull());
|
||||
return this->m_refObject->object();
|
||||
}
|
||||
|
||||
ObjectType * Object(void)
|
||||
RefCountedObjectType * refObject(void) const
|
||||
{
|
||||
if (this->m_shared == 0) return true;
|
||||
return this->m_shared->object();
|
||||
return this->m_refObject;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
SharedObjectBindingType * m_shared;
|
||||
RefCountedObjectType * m_refObject;
|
||||
|
||||
void attach(SharedObjectBindingType * shared)
|
||||
void attach(RefCountedObjectType * reObject)
|
||||
{
|
||||
this->detach();
|
||||
this->m_shared = shared;
|
||||
if (this->m_shared != 0)
|
||||
this->m_refObject = reObject;
|
||||
if (this->m_refObject != 0)
|
||||
{
|
||||
this->m_shared->ref();
|
||||
this->m_refObject->ref();
|
||||
}
|
||||
}
|
||||
|
||||
void detach(void)
|
||||
{
|
||||
if (this->m_shared == 0) return;
|
||||
this->m_shared->unref();
|
||||
this->m_shared = 0;
|
||||
}
|
||||
|
||||
SharedObjectBindingType * shared(void) const
|
||||
{
|
||||
return this->m_shared;
|
||||
if (this->m_refObject == 0) return;
|
||||
this->m_refObject->unref();
|
||||
this->m_refObject = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct ObjectSharedPointerTraits { typedef ObjectSharedPointer<T, typename DeleterOf<typename RootOf<T>::Type>::Type, typename BaseOf<T>::Type> Type; };
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -18,27 +18,52 @@ class BufferArguments : public ObjectArguments
|
|||
const void * data;
|
||||
|
||||
BufferArguments(void)
|
||||
: BaseType ()
|
||||
, size (0)
|
||||
, usage (GL_STATIC_DRAW)
|
||||
, data (0)
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
BufferArguments(GLsizeiptr aSize, GLenum aUsage = GL_STATIC_DRAW, const void * aData = 0)
|
||||
: BaseType ()
|
||||
, size (aSize)
|
||||
, usage (aUsage)
|
||||
, data (aData)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
{
|
||||
BaseType::clear();
|
||||
this->size = 0;
|
||||
this->usage = GL_NONE;
|
||||
this->usage = GL_STATIC_DRAW;
|
||||
this->data = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class SafeBuffer : public virtual SafeObject
|
||||
class Buffer : public Object
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeBuffer ThisType;
|
||||
typedef Object BaseType;
|
||||
typedef Buffer ThisType;
|
||||
|
||||
GLsizei size(void) const
|
||||
virtual ~Buffer(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
return BufferType;
|
||||
}
|
||||
|
||||
GLsizeiptr size(void) const
|
||||
{
|
||||
return this->m_size;
|
||||
}
|
||||
|
@ -48,163 +73,631 @@ class SafeBuffer : public virtual SafeObject
|
|||
return this->m_usage;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GLsizeiptr m_size;
|
||||
GLenum m_usage;
|
||||
|
||||
SafeBuffer(Context * ctx)
|
||||
: BaseType (ctx)
|
||||
, m_size (0)
|
||||
, m_usage (GL_NONE)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Buffer : public Object, public SafeBuffer
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<Buffer>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Object BaseType;
|
||||
typedef SafeBuffer SafeType;
|
||||
typedef Buffer ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
return BufferType;
|
||||
}
|
||||
|
||||
void setData(const GLsizeiptr size, GLenum usage, const void * data)
|
||||
void setData(GLenum target, GLint unit, const GLsizeiptr size, GLenum usage, const GLvoid * data)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glBufferData(this->m_target, size, data, usage);
|
||||
glBufferData(target, size, data, usage);
|
||||
this->m_size = size;
|
||||
this->m_usage = usage;
|
||||
}
|
||||
|
||||
void setSubData(GLintptr offset, GLsizeiptr size, const void * data)
|
||||
void setSubData(GLenum target, GLint unit, GLintptr offset, GLsizeiptr size, const GLvoid * data)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glBufferSubData(this->m_target, offset, size, data);
|
||||
glBufferSubData(target, offset, size, data);
|
||||
}
|
||||
|
||||
void getSubData(GLintptr offset, GLsizeiptr size, void * data)
|
||||
void getSubData(GLenum target, GLint unit, GLintptr offset, GLsizeiptr size, GLvoid * data)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glGetBufferSubData(this->m_target, offset, size, data);
|
||||
glGetBufferSubData(target, offset, size, data);
|
||||
}
|
||||
|
||||
void * map(GLenum access)
|
||||
void * map(GLenum target, GLint unit, GLenum access)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
GLW_ASSERT(!this->isMapped());
|
||||
void * ptr = glMapBuffer(this->m_target, access);
|
||||
GLW_ASSERT(!this->isMapped(target, unit));
|
||||
void * ptr = glMapBuffer(target, access);
|
||||
if (ptr == 0) return 0;
|
||||
this->m_mapAccess = access;
|
||||
this->m_mapPtr = ptr;
|
||||
this->m_mapAccess = access;
|
||||
this->m_mapPointer = ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void unmap(void)
|
||||
void unmap(GLenum target, GLint unit)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
GLW_ASSERT(this->isMapped());
|
||||
glUnmapBuffer(this->m_target);
|
||||
this->m_mapAccess = GL_NONE;
|
||||
this->m_mapPtr = 0;
|
||||
GLW_ASSERT(this->isMapped(target, unit));
|
||||
glUnmapBuffer(target);
|
||||
this->m_mapAccess = GL_NONE;
|
||||
this->m_mapPointer = 0;
|
||||
}
|
||||
|
||||
GLenum mapAccess(void) const
|
||||
GLenum mapAccess(GLenum target, GLint unit) const
|
||||
{
|
||||
(void)target;
|
||||
(void)unit;
|
||||
return this->m_mapAccess;
|
||||
}
|
||||
|
||||
bool isMapped(void) const
|
||||
bool isMapped(GLenum target, GLint unit) const
|
||||
{
|
||||
(void)target;
|
||||
(void)unit;
|
||||
return (this->m_mapAccess != GL_NONE);
|
||||
}
|
||||
|
||||
void * mapPointer(void) const
|
||||
void * mapPointer(GLenum target, GLint unit) const
|
||||
{
|
||||
return this->m_mapPtr;
|
||||
(void)target;
|
||||
(void)unit;
|
||||
return this->m_mapPointer;
|
||||
}
|
||||
|
||||
void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * offset)
|
||||
void vertexAttribPointer(GLenum target, GLint unit, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * offset)
|
||||
{
|
||||
(void)target;
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
GLW_ASSERT(this->m_target == GL_ARRAY_BUFFER);
|
||||
glVertexAttribPointer(index, size, type, normalized, stride, offset);
|
||||
}
|
||||
|
||||
void drawElements(GLenum target, GLint unit, GLenum mode, GLsizei count, GLenum type, const GLvoid * indices)
|
||||
{
|
||||
(void)target;
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glDrawElements(mode, count, type, indices);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GLsizeiptr m_size;
|
||||
GLenum m_usage;
|
||||
GLenum m_mapAccess;
|
||||
void * m_mapPointer;
|
||||
|
||||
Buffer(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
, m_mapAccess (GL_NONE)
|
||||
, m_mapPtr (0)
|
||||
: BaseType (ctx)
|
||||
, m_size (0)
|
||||
, m_usage (GL_NONE)
|
||||
, m_mapAccess (GL_NONE)
|
||||
, m_mapPointer (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~Buffer(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
bool create(const BufferArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
||||
GLint boundName = 0;
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &boundName);
|
||||
|
||||
glGenBuffers(1, &(this->m_name));
|
||||
this->setBinding(GL_ARRAY_BUFFER, 0);
|
||||
this->bind();
|
||||
this->setData(args.size, args.usage, args.data);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->m_name);
|
||||
glBufferData(GL_ARRAY_BUFFER, args.size, args.data, args.usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, boundName);
|
||||
|
||||
this->m_size = args.size;
|
||||
this->m_usage = args.usage;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
if (this->isMapped()) this->unmap();
|
||||
this->m_size = 0;
|
||||
this->m_usage = GL_NONE;
|
||||
this->m_mapAccess = GL_NONE;
|
||||
this->m_mapPtr = 0;
|
||||
glDeleteBuffers(1, &name);
|
||||
glDeleteBuffers(1, &(this->m_name));
|
||||
this->m_size = 0;
|
||||
this->m_usage = GL_NONE;
|
||||
this->m_mapAccess = GL_NONE;
|
||||
this->m_mapPointer = 0;
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
glBindBuffer(this->m_target, this->m_name);
|
||||
return (this->m_size > 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <Buffer> { typedef Object Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Buffer> ::Type BufferPtr;
|
||||
|
||||
class SafeBuffer : public SafeObject
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundBuffer;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeBuffer ThisType;
|
||||
|
||||
SafeBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
GLsizeiptr size(void) const
|
||||
{
|
||||
return this->object()->size();
|
||||
}
|
||||
|
||||
GLenum usage(void) const
|
||||
{
|
||||
return this->object()->usage();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeBuffer(const BufferPtr & buffer)
|
||||
: BaseType(buffer)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const BufferPtr & object(void) const
|
||||
{
|
||||
return static_cast<const BufferPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
BufferPtr & object(void)
|
||||
{
|
||||
return static_cast<BufferPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeBuffer> { typedef SafeObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeBuffer> { typedef Buffer Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Buffer > { typedef SafeBuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeBuffer> ::Type BufferHandle;
|
||||
|
||||
class BufferBindingParams : public ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ObjectBindingParams BaseType;
|
||||
typedef BufferBindingParams ThisType;
|
||||
|
||||
BufferBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
BufferBindingParams(GLenum aTarget, GLenum aUnit)
|
||||
: BaseType(aTarget, aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundBuffer : public BoundObject
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundObject BaseType;
|
||||
typedef BoundBuffer ThisType;
|
||||
|
||||
BoundBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const BufferHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const BufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
BufferHandle & handle(void)
|
||||
{
|
||||
return static_cast<BufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
void setData(const GLsizeiptr size, GLenum usage, const GLvoid * data)
|
||||
{
|
||||
this->object()->setData(this->m_target, this->m_unit, size, usage, data);
|
||||
}
|
||||
|
||||
void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid * data)
|
||||
{
|
||||
this->object()->setSubData(this->m_target, this->m_unit, offset, size, data);
|
||||
}
|
||||
|
||||
void getSubData(GLintptr offset, GLsizeiptr size, GLvoid * data)
|
||||
{
|
||||
this->object()->getSubData(this->m_target, this->m_unit, offset, size, data);
|
||||
}
|
||||
|
||||
void * map(GLenum access)
|
||||
{
|
||||
return this->object()->map(this->m_target, this->m_unit, access);
|
||||
}
|
||||
|
||||
void unmap(void)
|
||||
{
|
||||
this->object()->unmap(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
GLenum mapAccess(void) const
|
||||
{
|
||||
return this->object()->mapAccess(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
bool isMapped(void) const
|
||||
{
|
||||
return this->object()->isMapped(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
void * mapPointer(void) const
|
||||
{
|
||||
return this->object()->mapPointer(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundBuffer(const BufferHandle & handle, const BufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const BufferPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
BufferPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glBindBuffer(this->m_target, this->object()->name());
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glBindBuffer(this->m_target, 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundBuffer> { typedef BufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundBuffer> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundBuffer> { typedef Buffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Buffer > { typedef BoundBuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundBuffer> ::Type BoundBufferHandle;
|
||||
|
||||
class VertexBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef VertexBufferBindingParams ThisType;
|
||||
|
||||
VertexBufferBindingParams(void)
|
||||
: BaseType(GL_ARRAY_BUFFER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundVertexBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundVertexBuffer ThisType;
|
||||
|
||||
BoundVertexBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * offset)
|
||||
{
|
||||
this->object()->vertexAttribPointer(this->m_target, this->m_unit, index, size, type, normalized, stride, offset);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundVertexBuffer(const BufferHandle & handle, const VertexBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundVertexBuffer> { typedef VertexBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundVertexBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundVertexBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundVertexBuffer> ::Type BoundVertexBufferHandle;
|
||||
|
||||
class IndexBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef IndexBufferBindingParams ThisType;
|
||||
|
||||
IndexBufferBindingParams(void)
|
||||
: BaseType(GL_ELEMENT_ARRAY_BUFFER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundIndexBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundIndexBuffer ThisType;
|
||||
|
||||
BoundIndexBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices)
|
||||
{
|
||||
this->object()->drawElements(this->m_target, this->m_unit, mode, count, type, indices);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundIndexBuffer(const BufferHandle & handle, const IndexBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundIndexBuffer> { typedef IndexBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundIndexBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundIndexBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundIndexBuffer> ::Type BoundIndexBufferHandle;
|
||||
|
||||
class PixelPackBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef PixelPackBufferBindingParams ThisType;
|
||||
|
||||
PixelPackBufferBindingParams(void)
|
||||
: BaseType(GL_PIXEL_PACK_BUFFER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundPixelPackBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundPixelPackBuffer ThisType;
|
||||
|
||||
BoundPixelPackBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundPixelPackBuffer(const BufferHandle & handle, const PixelPackBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundPixelPackBuffer> { typedef PixelPackBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundPixelPackBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundPixelPackBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundPixelPackBuffer> ::Type BoundPixelPackBufferHandle;
|
||||
|
||||
class PixelUnpackBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef PixelUnpackBufferBindingParams ThisType;
|
||||
|
||||
PixelUnpackBufferBindingParams(void)
|
||||
: BaseType(GL_PIXEL_UNPACK_BUFFER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundPixelUnpackBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundPixelUnpackBuffer ThisType;
|
||||
|
||||
BoundPixelUnpackBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundPixelUnpackBuffer(const BufferHandle & handle, const PixelUnpackBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundPixelUnpackBuffer> { typedef PixelUnpackBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundPixelUnpackBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundPixelUnpackBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundPixelUnpackBuffer> ::Type BoundPixelUnpackBufferHandle;
|
||||
|
||||
class UniformBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef UniformBufferBindingParams ThisType;
|
||||
|
||||
GLintptr offset;
|
||||
GLsizeiptr size;
|
||||
|
||||
UniformBufferBindingParams(void)
|
||||
: BaseType (GL_UNIFORM_BUFFER, 0)
|
||||
, offset (0)
|
||||
, size (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
UniformBufferBindingParams(GLuint aIndex, GLintptr aOffset, GLsizeiptr aSize)
|
||||
: BaseType (GL_UNIFORM_BUFFER, GLint(aIndex))
|
||||
, offset (aOffset)
|
||||
, size (aSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundUniformBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundUniformBuffer ThisType;
|
||||
|
||||
BoundUniformBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundUniformBuffer(const BufferHandle & handle, const UniformBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glBindBufferRange(this->m_target, GLuint(this->m_unit), this->object()->name(), this->m_offset, this->m_size);
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glBindBufferRange(this->m_target, GLuint(this->m_unit), 0, 0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
GLenum m_mapAccess;
|
||||
void * m_mapPtr;
|
||||
GLintptr m_offset;
|
||||
GLsizeiptr m_size;
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Buffer> BufferHandle;
|
||||
typedef detail::UnsafeHandle <Buffer> BoundBuffer;
|
||||
namespace detail { template <> struct ParamsOf <BoundUniformBuffer> { typedef UniformBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundUniformBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundUniformBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundUniformBuffer> ::Type BoundUniformBufferHandle;
|
||||
|
||||
} // end namespace glw
|
||||
class FeedbackBufferBindingParams : public BufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef BufferBindingParams BaseType;
|
||||
typedef FeedbackBufferBindingParams ThisType;
|
||||
|
||||
GLintptr offset;
|
||||
GLsizeiptr size;
|
||||
|
||||
FeedbackBufferBindingParams(void)
|
||||
: BaseType (GL_TRANSFORM_FEEDBACK_BUFFER, 0)
|
||||
, offset (0)
|
||||
, size (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
FeedbackBufferBindingParams(GLuint aIndex, GLintptr aOffset, GLsizeiptr aSize)
|
||||
: BaseType (GL_TRANSFORM_FEEDBACK_BUFFER, GLint(aIndex))
|
||||
, offset (aOffset)
|
||||
, size (aSize)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundFeedbackBuffer : public BoundBuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundBuffer BaseType;
|
||||
typedef BoundFeedbackBuffer ThisType;
|
||||
|
||||
BoundFeedbackBuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundFeedbackBuffer(const BufferHandle & handle, const FeedbackBufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glBindBufferRange(this->m_target, GLuint(this->m_unit), this->object()->name(), this->m_offset, this->m_size);
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glBindBufferRange(this->m_target, GLuint(this->m_unit), 0, 0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
GLintptr m_offset;
|
||||
GLsizeiptr m_size;
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundFeedbackBuffer> { typedef FeedbackBufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundFeedbackBuffer> { typedef BoundBuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundFeedbackBuffer> { typedef Buffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundFeedbackBuffer> ::Type BoundFeedbackBufferHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_BUFFER_H
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
#include "./config.h"
|
||||
|
||||
#define GLW_DONT_CARE (0xFFFFFFFF)
|
||||
#define GLW_CARE_OF(X) ((X) != GLW_DONT_CARE)
|
||||
#define GLW_DONT_CARE (0xFFFFFFFF)
|
||||
#define GLW_CARE_OF(X) ((X) != GLW_DONT_CARE)
|
||||
|
||||
#define GLW_CHECK_GL_ERROR GLW_ASSERT(glGetError() == GL_NO_ERROR)
|
||||
#define GLW_CHECK_GL_READ_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
#define GLW_CHECK_GL_DRAW_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
#define GLW_CHECK_GL_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
#define GLW_CHECK_GL_ERROR GLW_ASSERT(glGetError() == GL_NO_ERROR)
|
||||
#define GLW_CHECK_GL_READ_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
#define GLW_CHECK_GL_DRAW_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
#define GLW_CHECK_GL_READ_DRAW_FRAMEBUFFER_STATUS GLW_ASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
|
||||
namespace glw
|
||||
{
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
#define GLW_CONTEXT_H
|
||||
|
||||
#include "./noncopyable.h"
|
||||
#include "./objectdeleter.h"
|
||||
#include "./buffer.h"
|
||||
#include "./renderbuffer.h"
|
||||
#include "./vertexshader.h"
|
||||
#include "./geometryshader.h"
|
||||
#include "./fragmentshader.h"
|
||||
#include "./program.h"
|
||||
#include "./renderbuffer.h"
|
||||
#include "./texture2d.h"
|
||||
#include "./framebuffer.h"
|
||||
|
||||
|
@ -20,7 +21,7 @@ namespace glw
|
|||
|
||||
class Context : public detail::NonCopyable
|
||||
{
|
||||
friend class detail::SharedObjectBase<Object>;
|
||||
friend class detail::ObjectDeleter;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -52,7 +53,7 @@ class Context : public detail::NonCopyable
|
|||
if (!this->isAcquired()) return;
|
||||
this->m_acquired = false;
|
||||
this->terminateTargets();
|
||||
this->destroyAllObjects();
|
||||
this->invalidateReferencesToAllObjects();
|
||||
}
|
||||
|
||||
bool isAcquired(void) const
|
||||
|
@ -68,13 +69,13 @@ class Context : public detail::NonCopyable
|
|||
BufferHandle createBuffer(const BufferArguments & args)
|
||||
{
|
||||
BufferHandle handle = this->createHandle<Buffer>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundBuffer bindVertexBuffer(BufferHandle & handle)
|
||||
BoundVertexBufferHandle bindVertexBuffer(BufferHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_ARRAY_BUFFER, 0), handle);
|
||||
return this->bind<BoundVertexBuffer>(handle);
|
||||
}
|
||||
|
||||
void unbindVertexBuffer(void)
|
||||
|
@ -83,9 +84,9 @@ class Context : public detail::NonCopyable
|
|||
this->bindVertexBuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundBuffer bindIndexBuffer(BufferHandle & handle)
|
||||
BoundIndexBufferHandle bindIndexBuffer(BufferHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_ELEMENT_ARRAY_BUFFER, 0), handle);
|
||||
return this->bind<BoundIndexBuffer>(handle);
|
||||
}
|
||||
|
||||
void unbindIndexBuffer(void)
|
||||
|
@ -94,16 +95,60 @@ class Context : public detail::NonCopyable
|
|||
this->bindIndexBuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundPixelPackBufferHandle bindPixelPackBuffer(BufferHandle & handle)
|
||||
{
|
||||
return this->bind<BoundPixelPackBuffer>(handle);
|
||||
}
|
||||
|
||||
void unbindPixelPackBuffer(void)
|
||||
{
|
||||
BufferHandle nullHandle;
|
||||
this->bindPixelPackBuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundPixelUnpackBufferHandle bindPixelUnpackBuffer(BufferHandle & handle)
|
||||
{
|
||||
return this->bind<BoundPixelUnpackBuffer>(handle);
|
||||
}
|
||||
|
||||
void unbindPixelUnpackBuffer(void)
|
||||
{
|
||||
BufferHandle nullHandle;
|
||||
this->bindPixelUnpackBuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundUniformBufferHandle bindUniformBuffer(BufferHandle & handle, GLuint index, GLintptr offset, GLsizeiptr size)
|
||||
{
|
||||
return this->bind<BoundUniformBuffer>(handle, UniformBufferBindingParams(index, offset, size));
|
||||
}
|
||||
|
||||
void unbindUniformBuffer(GLuint index)
|
||||
{
|
||||
BufferHandle nullHandle;
|
||||
this->bindUniformBuffer(nullHandle, index, 0, 0);
|
||||
}
|
||||
|
||||
BoundFeedbackBufferHandle bindFeedbackBuffer(BufferHandle & handle, GLuint index, GLintptr offset, GLsizeiptr size)
|
||||
{
|
||||
return this->bind<BoundFeedbackBuffer>(handle, FeedbackBufferBindingParams(index, offset, size));
|
||||
}
|
||||
|
||||
void unbindFeedbackBuffer(GLuint index)
|
||||
{
|
||||
BufferHandle nullHandle;
|
||||
this->bindFeedbackBuffer(nullHandle, index, 0, 0);
|
||||
}
|
||||
|
||||
RenderbufferHandle createRenderbuffer(const RenderbufferArguments & args)
|
||||
{
|
||||
RenderbufferHandle handle = this->createHandle<Renderbuffer>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundRenderbuffer bindRenderbuffer(RenderbufferHandle & handle)
|
||||
BoundRenderbufferHandle bindRenderbuffer(RenderbufferHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_RENDERBUFFER, 0), handle);
|
||||
return this->bind<BoundRenderbuffer>(handle);
|
||||
}
|
||||
|
||||
void unbindRenderbuffer(void)
|
||||
|
@ -115,13 +160,13 @@ class Context : public detail::NonCopyable
|
|||
VertexShaderHandle createVertexShader(const VertexShaderArguments & args)
|
||||
{
|
||||
VertexShaderHandle handle = this->createHandle<VertexShader>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundVertexShader bindVertexShader(VertexShaderHandle & handle)
|
||||
BoundVertexShaderHandle bindVertexShader(VertexShaderHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_VERTEX_SHADER, 0), handle);
|
||||
return this->bind<BoundVertexShader>(handle, VertexShaderBindingParams());
|
||||
}
|
||||
|
||||
void unbindVertexShader(void)
|
||||
|
@ -133,13 +178,13 @@ class Context : public detail::NonCopyable
|
|||
GeometryShaderHandle createGeometryShader(const GeometryShaderArguments & args)
|
||||
{
|
||||
GeometryShaderHandle handle = this->createHandle<GeometryShader>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundGeometryShader bindGeometryShader(GeometryShaderHandle & handle)
|
||||
BoundGeometryShaderHandle bindGeometryShader(GeometryShaderHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_GEOMETRY_SHADER, 0), handle);
|
||||
return this->bind<BoundGeometryShader>(handle, GeometryShaderBindingParams());
|
||||
}
|
||||
|
||||
void unbindGeometryShader(void)
|
||||
|
@ -151,13 +196,13 @@ class Context : public detail::NonCopyable
|
|||
FragmentShaderHandle createFragmentShader(const FragmentShaderArguments & args)
|
||||
{
|
||||
FragmentShaderHandle handle = this->createHandle<FragmentShader>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundFragmentShader bindFragmentShader(FragmentShaderHandle & handle)
|
||||
BoundFragmentShaderHandle bindFragmentShader(FragmentShaderHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_FRAGMENT_SHADER, 0), handle);
|
||||
return this->bind<BoundFragmentShader>(handle, FragmentShaderBindingParams());
|
||||
}
|
||||
|
||||
void unbindFragmentShader(void)
|
||||
|
@ -169,13 +214,13 @@ class Context : public detail::NonCopyable
|
|||
ProgramHandle createProgram(const ProgramArguments & args)
|
||||
{
|
||||
ProgramHandle handle = this->createHandle<Program>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundProgram bindProgram(ProgramHandle & handle)
|
||||
BoundProgramHandle bindProgram(ProgramHandle & handle)
|
||||
{
|
||||
return this->bind(BindingTarget(GL_CURRENT_PROGRAM, 0), handle);
|
||||
return this->bind<BoundProgram>(handle, ProgramBindingParams());
|
||||
}
|
||||
|
||||
void unbindProgram(void)
|
||||
|
@ -187,34 +232,33 @@ class Context : public detail::NonCopyable
|
|||
Texture2DHandle createTexture2D(const Texture2DArguments & args)
|
||||
{
|
||||
Texture2DHandle handle = this->createHandle<Texture2D>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundTexture2D bindTexture2D(GLint unit, Texture2DHandle & handle)
|
||||
BoundTexture2DHandle bindTexture2D(Texture2DHandle & handle, GLint unit)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + unit);
|
||||
return this->bind(BindingTarget(GL_TEXTURE_2D, unit), handle);
|
||||
return this->bind<BoundTexture2D>(handle, Texture2DBindingParams(unit));
|
||||
}
|
||||
|
||||
void unbindTexture2D(GLint unit)
|
||||
{
|
||||
Texture2DHandle nullHandle;
|
||||
this->bindTexture2D(unit, nullHandle);
|
||||
this->bindTexture2D(nullHandle, unit);
|
||||
}
|
||||
|
||||
FramebufferHandle createFramebuffer(const FramebufferArguments & args)
|
||||
{
|
||||
FramebufferHandle handle = this->createHandle<Framebuffer>();
|
||||
handle.object()->create(args);
|
||||
handle->object()->create(args);
|
||||
return handle;
|
||||
}
|
||||
|
||||
BoundFramebuffer bindReadFramebuffer(FramebufferHandle & handle)
|
||||
BoundReadFramebufferHandle bindReadFramebuffer(FramebufferHandle & handle)
|
||||
{
|
||||
FramebufferHandle nullHandle;
|
||||
this->bind(BindingTarget(GL_FRAMEBUFFER, 0), nullHandle);
|
||||
return this->bind(BindingTarget(GL_READ_FRAMEBUFFER, 0), handle);
|
||||
this->bind<BoundReadDrawFramebuffer>(nullHandle, ReadDrawFramebufferBindingParams());
|
||||
return this->bind<BoundReadFramebuffer>(handle, ReadFramebufferBindingParams());
|
||||
}
|
||||
|
||||
void unbindReadFramebuffer(void)
|
||||
|
@ -223,11 +267,11 @@ class Context : public detail::NonCopyable
|
|||
this->bindReadFramebuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundFramebuffer bindDrawFramebuffer(FramebufferHandle & handle)
|
||||
BoundDrawFramebufferHandle bindDrawFramebuffer(FramebufferHandle & handle)
|
||||
{
|
||||
FramebufferHandle nullHandle;
|
||||
this->bind(BindingTarget(GL_FRAMEBUFFER, 0), nullHandle);
|
||||
return this->bind(BindingTarget(GL_DRAW_FRAMEBUFFER, 0), handle);
|
||||
this->bind<BoundReadDrawFramebuffer>(nullHandle, ReadDrawFramebufferBindingParams());
|
||||
return this->bind<BoundDrawFramebuffer>(handle, DrawFramebufferBindingParams());
|
||||
}
|
||||
|
||||
void unbindDrawFramebuffer(void)
|
||||
|
@ -236,199 +280,296 @@ class Context : public detail::NonCopyable
|
|||
this->bindDrawFramebuffer(nullHandle);
|
||||
}
|
||||
|
||||
BoundFramebuffer bindFramebuffer(FramebufferHandle & handle)
|
||||
BoundReadDrawFramebufferHandle bindReadDrawFramebuffer(FramebufferHandle & handle)
|
||||
{
|
||||
FramebufferHandle nullHandle;
|
||||
this->bind(BindingTarget(GL_READ_FRAMEBUFFER, 0), nullHandle);
|
||||
this->bind(BindingTarget(GL_DRAW_FRAMEBUFFER, 0), nullHandle);
|
||||
return this->bind(BindingTarget(GL_FRAMEBUFFER, 0), handle);
|
||||
this->bind<BoundReadFramebuffer>(nullHandle, ReadFramebufferBindingParams());
|
||||
this->bind<BoundDrawFramebuffer>(nullHandle, DrawFramebufferBindingParams());
|
||||
return this->bind<BoundReadDrawFramebuffer>(handle, ReadDrawFramebufferBindingParams());
|
||||
}
|
||||
|
||||
void unbindFramebuffer(void)
|
||||
void unbindReadDrawFramebuffer(void)
|
||||
{
|
||||
FramebufferHandle nullHandle;
|
||||
this->bindFramebuffer(nullHandle);
|
||||
this->bindReadDrawFramebuffer(nullHandle);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
typedef detail::SharedObjectBase<Object> SharedObjectType;
|
||||
|
||||
typedef void * GenericPtr;
|
||||
typedef std::pair<GLenum, GLint> BindingTarget;
|
||||
|
||||
typedef std::set<SharedObjectType *> ShaderObjecPtrSet;
|
||||
typedef ShaderObjecPtrSet::const_iterator ShaderObjecPtrSetConstIterator;
|
||||
typedef ShaderObjecPtrSet::iterator ShaderObjecPtrSetIterator;
|
||||
|
||||
typedef std::map<BindingTarget, GenericPtr> SharedObjectBindingPtrMap;
|
||||
typedef SharedObjectBindingPtrMap::const_iterator SharedObjectBindingPtrConstIterator;
|
||||
typedef SharedObjectBindingPtrMap::iterator SharedObjectBindingPtrIterator;
|
||||
typedef SharedObjectBindingPtrMap::value_type SharedObjectBindingPtrValue;
|
||||
|
||||
bool m_acquired;
|
||||
int m_textureUnits;
|
||||
ShaderObjecPtrSet m_shareds;
|
||||
SharedObjectBindingPtrMap m_bindings;
|
||||
template <typename TObject>
|
||||
struct ObjectSafeFromObject
|
||||
{
|
||||
typedef typename detail::ObjectSafe<TObject>::Type Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
void initializeTarget(BindingTarget bt)
|
||||
struct ObjectBoundFromObject
|
||||
{
|
||||
typedef TObject ObjectType;
|
||||
typedef detail::UnsafeHandle<ObjectType> UnsafeObjectType;
|
||||
typedef typename detail::ObjectBound<TObject>::Type Type;
|
||||
};
|
||||
|
||||
UnsafeObjectType * unsafeObject = 0;
|
||||
this->m_bindings.insert(SharedObjectBindingPtrValue(bt, unsafeObject));
|
||||
template <typename TBinding>
|
||||
struct ObjectFromBinding
|
||||
{
|
||||
typedef typename detail::ObjectBase<TBinding>::Type Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct RefCountedPtrFromObject
|
||||
{
|
||||
typedef detail::RefCountedObject<TObject, typename detail::DeleterOf<typename detail::RootOf<TObject>::Type>::Type, typename detail::BaseOf<TObject>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct RefCountedSafeHandleFromObject
|
||||
{
|
||||
typedef typename ObjectSafeFromObject<TObject>::Type ObjectSafeType;
|
||||
typedef detail::RefCountedObject<ObjectSafeType, typename detail::DeleterOf<typename detail::RootOf<ObjectSafeType>::Type>::Type, typename detail::BaseOf<ObjectSafeType>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct RefCountedBindingHandleFromObject
|
||||
{
|
||||
typedef typename ObjectBoundFromObject<TObject>::Type ObjectBoundType;
|
||||
typedef detail::RefCountedObject<ObjectBoundType, typename detail::DeleterOf<typename detail::RootOf<ObjectBoundType>::Type>::Type, typename detail::BaseOf<ObjectBoundType>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TBinding>
|
||||
struct RefCountedBindingHandleFromBinding
|
||||
{
|
||||
typedef detail::RefCountedObject<TBinding, typename detail::DeleterOf<typename detail::RootOf<TBinding>::Type>::Type, typename detail::BaseOf<TBinding>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct PtrFromObject
|
||||
{
|
||||
typedef detail::ObjectSharedPointer<TObject, typename detail::DeleterOf<typename detail::RootOf<TObject>::Type>::Type, typename detail::BaseOf<TObject>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct SafeHandleFromObject
|
||||
{
|
||||
typedef typename ObjectSafeFromObject<TObject>::Type ObjectSafeType;
|
||||
typedef detail::ObjectSharedPointer<ObjectSafeType, typename detail::DeleterOf<typename detail::RootOf<ObjectSafeType>::Type>::Type, typename detail::BaseOf<ObjectSafeType>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TObject>
|
||||
struct BindingHandleFromObject
|
||||
{
|
||||
typedef typename ObjectBoundFromObject<TObject>::Type ObjectBoundType;
|
||||
typedef detail::ObjectSharedPointer<ObjectBoundType, typename detail::DeleterOf<typename detail::RootOf<ObjectBoundType>::Type>::Type, typename detail::BaseOf<ObjectBoundType>::Type> Type;
|
||||
};
|
||||
|
||||
template <typename TBinding>
|
||||
struct SafeHandleFromBinding
|
||||
{
|
||||
typedef typename SafeHandleFromObject<typename ObjectFromBinding<TBinding>::Type>::Type Type;
|
||||
};
|
||||
|
||||
template <typename TBinding>
|
||||
struct BindingHandleFromBinding
|
||||
{
|
||||
typedef detail::ObjectSharedPointer<TBinding, typename detail::DeleterOf<typename detail::RootOf<TBinding>::Type>::Type, typename detail::BaseOf<TBinding>::Type> Type;
|
||||
};
|
||||
|
||||
typedef Object ObjectType;
|
||||
typedef RefCountedPtrFromObject<ObjectType>::Type RefCountedPtrType;
|
||||
typedef std::map<Object *, RefCountedPtrType *> RefCountedPtrPtrMap;
|
||||
typedef RefCountedPtrPtrMap::const_iterator RefCountedPtrPtrMapConstIterator;
|
||||
typedef RefCountedPtrPtrMap::iterator RefCountedPtrPtrMapIterator;
|
||||
typedef RefCountedPtrPtrMap::value_type RefCountedPtrPtrMapValue;
|
||||
|
||||
typedef std::pair<GLenum, GLint> BindingTarget;
|
||||
typedef BoundObjectHandle::RefCountedObjectType RefCountedBindingType;
|
||||
typedef std::map<BindingTarget, RefCountedBindingType *> RefCountedBindingPtrMap;
|
||||
typedef RefCountedBindingPtrMap::const_iterator RefCountedBindingPtrMapConstIterator;
|
||||
typedef RefCountedBindingPtrMap::iterator RefCountedBindingPtrMapIterator;
|
||||
typedef RefCountedBindingPtrMap::value_type RefCountedBindingPtrMapValue;
|
||||
|
||||
bool m_acquired;
|
||||
int m_textureUnits;
|
||||
RefCountedPtrPtrMap m_objects;
|
||||
RefCountedBindingPtrMap m_bindings;
|
||||
|
||||
template <typename TBinding, typename TBindingParams>
|
||||
void initializeTarget(const TBindingParams & params)
|
||||
{
|
||||
typedef TBinding BindingType;
|
||||
typedef typename RefCountedBindingHandleFromBinding<BindingType>::Type RefCountedBindingHandleType;
|
||||
|
||||
const BindingTarget bt = BindingTarget(params.target, params.unit);
|
||||
RefCountedBindingHandleType * binding = 0;
|
||||
this->m_bindings.insert(RefCountedBindingPtrMapValue(bt, binding));
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
void terminateTarget(BindingTarget bt)
|
||||
template <typename TBinding, typename TBindingParams>
|
||||
void terminateTarget(const TBindingParams & params)
|
||||
{
|
||||
typedef TObject ObjectType;
|
||||
typedef detail::SafeHandle<ObjectType> SafeObjectType;
|
||||
typedef TBinding BindingType;
|
||||
typedef typename SafeHandleFromBinding<BindingType>::Type SafeHandleType;
|
||||
|
||||
SafeObjectType nullHandle;
|
||||
this->bind<ObjectType>(bt, nullHandle);
|
||||
SafeHandleType nullHandle;
|
||||
this->bind<BindingType>(nullHandle, params);
|
||||
}
|
||||
|
||||
void initializeTargets(void)
|
||||
{
|
||||
this->initializeTarget<BoundVertexBuffer, VertexBufferBindingParams >(VertexBufferBindingParams () );
|
||||
this->initializeTarget<BoundIndexBuffer, IndexBufferBindingParams >(IndexBufferBindingParams () );
|
||||
this->initializeTarget<BoundPixelPackBuffer, PixelPackBufferBindingParams >(PixelPackBufferBindingParams () );
|
||||
this->initializeTarget<BoundPixelUnpackBuffer, PixelUnpackBufferBindingParams >(PixelUnpackBufferBindingParams () );
|
||||
this->initializeTarget<BoundUniformBuffer, UniformBufferBindingParams >(UniformBufferBindingParams (0, 0, 0));
|
||||
this->initializeTarget<BoundFeedbackBuffer, FeedbackBufferBindingParams >(FeedbackBufferBindingParams (0, 0, 0));
|
||||
this->initializeTarget<BoundRenderbuffer, RenderbufferBindingParams >(RenderbufferBindingParams () );
|
||||
this->initializeTarget<BoundVertexShader, VertexShaderBindingParams >(VertexShaderBindingParams () );
|
||||
this->initializeTarget<BoundGeometryShader, GeometryShaderBindingParams >(GeometryShaderBindingParams () );
|
||||
this->initializeTarget<BoundFragmentShader, FragmentShaderBindingParams >(FragmentShaderBindingParams () );
|
||||
this->initializeTarget<BoundProgram, ProgramBindingParams >(ProgramBindingParams () );
|
||||
this->initializeTarget<BoundReadFramebuffer, ReadFramebufferBindingParams >(ReadFramebufferBindingParams () );
|
||||
this->initializeTarget<BoundDrawFramebuffer, DrawFramebufferBindingParams >(DrawFramebufferBindingParams () );
|
||||
this->initializeTarget<BoundReadDrawFramebuffer, ReadDrawFramebufferBindingParams >(ReadDrawFramebufferBindingParams () );
|
||||
|
||||
{
|
||||
GLint texUnits = 0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texUnits);
|
||||
this->m_textureUnits = int(texUnits);
|
||||
}
|
||||
|
||||
this->initializeTarget<Buffer >(BindingTarget(GL_ARRAY_BUFFER, 0));
|
||||
this->initializeTarget<Buffer >(BindingTarget(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
this->initializeTarget<Renderbuffer >(BindingTarget(GL_RENDERBUFFER, 0));
|
||||
this->initializeTarget<VertexShader >(BindingTarget(GL_VERTEX_SHADER, 0));
|
||||
this->initializeTarget<GeometryShader>(BindingTarget(GL_GEOMETRY_SHADER, 0));
|
||||
this->initializeTarget<FragmentShader>(BindingTarget(GL_FRAGMENT_SHADER, 0));
|
||||
this->initializeTarget<Program >(BindingTarget(GL_CURRENT_PROGRAM, 0));
|
||||
|
||||
for (int i=0; i<this->m_textureUnits; ++i)
|
||||
{
|
||||
this->initializeTarget<Texture2D>(BindingTarget(GL_TEXTURE_2D, GLint(i)));
|
||||
this->initializeTarget<BoundTexture2D>(Texture2DBindingParams(GLint(i)));
|
||||
}
|
||||
this->initializeTarget<Framebuffer >(BindingTarget(GL_READ_FRAMEBUFFER, 0));
|
||||
this->initializeTarget<Framebuffer >(BindingTarget(GL_DRAW_FRAMEBUFFER, 0));
|
||||
this->initializeTarget<Framebuffer >(BindingTarget(GL_FRAMEBUFFER, 0));
|
||||
}
|
||||
|
||||
void terminateTargets(void)
|
||||
{
|
||||
this->terminateTarget<Buffer >(BindingTarget(GL_ARRAY_BUFFER, 0));
|
||||
this->terminateTarget<Buffer >(BindingTarget(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
this->terminateTarget<Renderbuffer >(BindingTarget(GL_RENDERBUFFER, 0));
|
||||
this->terminateTarget<VertexShader >(BindingTarget(GL_VERTEX_SHADER, 0));
|
||||
this->terminateTarget<GeometryShader>(BindingTarget(GL_GEOMETRY_SHADER, 0));
|
||||
this->terminateTarget<FragmentShader>(BindingTarget(GL_FRAGMENT_SHADER, 0));
|
||||
this->terminateTarget<Program >(BindingTarget(GL_CURRENT_PROGRAM, 0));
|
||||
this->terminateTarget<BoundVertexBuffer, VertexBufferBindingParams >(VertexBufferBindingParams () );
|
||||
this->terminateTarget<BoundIndexBuffer, IndexBufferBindingParams >(IndexBufferBindingParams () );
|
||||
this->terminateTarget<BoundPixelPackBuffer, PixelPackBufferBindingParams >(PixelPackBufferBindingParams () );
|
||||
this->terminateTarget<BoundPixelUnpackBuffer, PixelUnpackBufferBindingParams >(PixelUnpackBufferBindingParams () );
|
||||
this->terminateTarget<BoundUniformBuffer, UniformBufferBindingParams >(UniformBufferBindingParams (0, 0, 0));
|
||||
this->terminateTarget<BoundFeedbackBuffer, FeedbackBufferBindingParams >(FeedbackBufferBindingParams (0, 0, 0));
|
||||
this->terminateTarget<BoundRenderbuffer, RenderbufferBindingParams >(RenderbufferBindingParams () );
|
||||
this->terminateTarget<BoundVertexShader, VertexShaderBindingParams >(VertexShaderBindingParams () );
|
||||
this->terminateTarget<BoundGeometryShader, GeometryShaderBindingParams >(GeometryShaderBindingParams () );
|
||||
this->terminateTarget<BoundFragmentShader, FragmentShaderBindingParams >(FragmentShaderBindingParams () );
|
||||
this->terminateTarget<BoundProgram, ProgramBindingParams >(ProgramBindingParams () );
|
||||
this->terminateTarget<BoundReadFramebuffer, ReadFramebufferBindingParams >(ReadFramebufferBindingParams () );
|
||||
this->terminateTarget<BoundDrawFramebuffer, DrawFramebufferBindingParams >(DrawFramebufferBindingParams () );
|
||||
this->terminateTarget<BoundReadDrawFramebuffer, ReadDrawFramebufferBindingParams >(ReadDrawFramebufferBindingParams () );
|
||||
|
||||
for (int i=0; i<this->m_textureUnits; ++i)
|
||||
{
|
||||
this->terminateTarget<Texture2D>(BindingTarget(GL_TEXTURE_2D, GLint(i)));
|
||||
this->terminateTarget<BoundTexture2D>(Texture2DBindingParams(GLint(i)));
|
||||
}
|
||||
this->terminateTarget<Framebuffer >(BindingTarget(GL_READ_FRAMEBUFFER, 0));
|
||||
this->terminateTarget<Framebuffer >(BindingTarget(GL_DRAW_FRAMEBUFFER, 0));
|
||||
this->terminateTarget<Framebuffer >(BindingTarget(GL_FRAMEBUFFER, 0));
|
||||
|
||||
this->m_textureUnits = 0;
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
detail::UnsafeHandle<TObject> bind(BindingTarget bt, detail::SafeHandle<TObject> & h)
|
||||
{
|
||||
typedef TObject ObjectType;
|
||||
typedef detail::SharedObjectBinding<ObjectType> SharedObjectBindingType;
|
||||
typedef detail::UnsafeHandle<ObjectType> UnsafeObjectType;
|
||||
|
||||
SharedObjectBindingPtrIterator it = this->m_bindings.find(bt);
|
||||
GLW_ASSERT(it != this->m_bindings.end());
|
||||
|
||||
ObjectType * Object = h.object();
|
||||
|
||||
SharedObjectBindingType * currentBinding = static_cast<SharedObjectBindingType *>(it->second);
|
||||
if (currentBinding != 0)
|
||||
{
|
||||
GLW_ASSERT(!currentBinding->isNull());
|
||||
// WARNING: as state could have been changed outside GLW, uncommenting the following line may prevent correct binding.
|
||||
//if (currentBinding->object() == Object) return UnsafeObjectType(currentBinding);
|
||||
if (h.isNull()) currentBinding->object()->unbind();
|
||||
currentBinding->setNull();
|
||||
currentBinding->unref();
|
||||
currentBinding = 0;
|
||||
it->second = 0;
|
||||
}
|
||||
|
||||
if (h.isNull()) return UnsafeObjectType();
|
||||
|
||||
SharedObjectBindingType * newBinding = new SharedObjectBindingType(h.shared(), bt.first, bt.second);
|
||||
newBinding->ref();
|
||||
it->second = newBinding;
|
||||
|
||||
Object->setBinding(bt.first, bt.second);
|
||||
Object->bind();
|
||||
|
||||
return UnsafeObjectType(newBinding);
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
TObject * createObject(void)
|
||||
{
|
||||
typedef TObject ObjectType;
|
||||
ObjectType * Object = new ObjectType(this);
|
||||
return Object;
|
||||
ObjectType * object = new ObjectType(this);
|
||||
return object;
|
||||
}
|
||||
|
||||
void destroyObject(Object * Object)
|
||||
void destroyObject(Object * object)
|
||||
{
|
||||
GLW_ASSERT(Object != 0);
|
||||
Object->destroy();
|
||||
delete Object;
|
||||
}
|
||||
|
||||
void removeShared(SharedObjectType * shared)
|
||||
{
|
||||
GLW_ASSERT(shared != 0);
|
||||
GLW_ASSERT(this->m_shareds.count(shared) > 0);
|
||||
this->m_shareds.erase(shared);
|
||||
this->destroyObject(shared->object());
|
||||
}
|
||||
|
||||
void destroyAllObjects(void)
|
||||
{
|
||||
for (ShaderObjecPtrSetIterator it=this->m_shareds.begin(); it!=this->m_shareds.end(); ++it)
|
||||
{
|
||||
SharedObjectType * shared = *it;
|
||||
Object * Object = shared->object();
|
||||
shared->setNull();
|
||||
this->destroyObject(Object);
|
||||
}
|
||||
GLW_ASSERT(object != 0);
|
||||
object->destroy();
|
||||
delete object;
|
||||
}
|
||||
|
||||
template <typename TObject>
|
||||
detail::SafeHandle<TObject> createHandle(void)
|
||||
typename SafeHandleFromObject<TObject>::Type createHandle(void)
|
||||
{
|
||||
typedef TObject ObjectType;
|
||||
typedef detail::SharedObject<ObjectType> SharedObjectType;
|
||||
typedef detail::SafeHandle<ObjectType> SafeType;
|
||||
typedef TObject ObjectType;
|
||||
typedef typename RefCountedPtrFromObject<ObjectType>::Type RefCountedPtrType;
|
||||
typedef typename PtrFromObject<ObjectType>::Type PtrType;
|
||||
|
||||
ObjectType * Object = new ObjectType(this);
|
||||
SharedObjectType * shared = new SharedObjectType(this, Object);
|
||||
typedef typename ObjectSafeFromObject<ObjectType>::Type ObjectSafeType;
|
||||
typedef typename RefCountedSafeHandleFromObject<ObjectType>::Type RefCountedSafeHandleType;
|
||||
typedef typename SafeHandleFromObject<TObject>::Type SafeHandleType;
|
||||
|
||||
this->m_shareds.insert(shared);
|
||||
ObjectType * object = this->createObject<ObjectType>();
|
||||
RefCountedPtrType * refCountedPtr = new RefCountedPtrType(object, typename detail::DeleterOf<Object>::Type());
|
||||
PtrType ptr = PtrType(refCountedPtr);
|
||||
|
||||
return SafeType(shared);
|
||||
ObjectSafeType * objecSafe = new ObjectSafeType(ptr);
|
||||
RefCountedSafeHandleType * refCountedHandle = new RefCountedSafeHandleType(objecSafe, typename detail::DeleterOf<ObjectSafeType>::Type());
|
||||
SafeHandleType handle = SafeHandleType(refCountedHandle);
|
||||
|
||||
this->m_objects.insert(RefCountedPtrPtrMapValue(object, refCountedPtr));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void noMoreReferencesTo(Object * object)
|
||||
{
|
||||
GLW_ASSERT(object != 0);
|
||||
RefCountedPtrPtrMapIterator it = this->m_objects.find(object);
|
||||
GLW_ASSERT(it != this->m_objects.end());
|
||||
this->m_objects.erase(it);
|
||||
this->destroyObject(object);
|
||||
}
|
||||
|
||||
void invalidateReferencesToAllObjects(void)
|
||||
{
|
||||
for (RefCountedPtrPtrMapIterator it=this->m_objects.begin(); it!=this->m_objects.end(); ++it)
|
||||
{
|
||||
Object * object = it->first;
|
||||
RefCountedPtrType * refPtr = it->second;
|
||||
refPtr->setNull(false);
|
||||
this->destroyObject(object);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TBinding>
|
||||
typename BindingHandleFromBinding<TBinding>::Type bind(typename SafeHandleFromBinding<TBinding>::Type & h, const typename detail::ParamsOf<TBinding>::Type & params = typename detail::ParamsOf<TBinding>::Type())
|
||||
{
|
||||
typedef TBinding BindingType;
|
||||
typedef typename detail::ParamsOf<TBinding>::Type BindingParamsType;
|
||||
typedef typename BindingHandleFromBinding<BindingType>::Type BindingHandleType;
|
||||
typedef typename RefCountedBindingHandleFromBinding<BindingType>::Type RefCountedBindingHandleType;
|
||||
|
||||
const BindingTarget bt = BindingTarget(params.target, params.unit);
|
||||
|
||||
RefCountedBindingPtrMapIterator it = this->m_bindings.find(bt);
|
||||
GLW_ASSERT(it != this->m_bindings.end());
|
||||
|
||||
RefCountedBindingHandleType * currentBinding = static_cast<RefCountedBindingHandleType *>(it->second);
|
||||
if (currentBinding != 0)
|
||||
{
|
||||
GLW_ASSERT(!currentBinding->isNull());
|
||||
// WARNING: as state could have been changed outside GLW, uncommenting the following line may prevent correct binding.
|
||||
//if (currentBinding->object() == Object) return UnsafeObjectType(currentBinding);
|
||||
if (h.isNull()) currentBinding->object()->unbind();
|
||||
currentBinding->setNull(true);
|
||||
currentBinding->unref();
|
||||
currentBinding = 0;
|
||||
it->second = 0;
|
||||
}
|
||||
|
||||
if (h.isNull()) return BindingHandleType();
|
||||
|
||||
BindingType * binding = new BindingType(h, params);
|
||||
RefCountedBindingHandleType * newBinding = new RefCountedBindingHandleType(binding, typename detail::DeleterOf<BindingType>::Type());
|
||||
newBinding->ref();
|
||||
newBinding->object()->bind();
|
||||
it->second = newBinding;
|
||||
|
||||
return BindingHandleType(newBinding);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename TObject>
|
||||
inline void SharedObjectBase<TObject>::signalDestruction(void)
|
||||
inline void ObjectDeleter :: operator () (Object * object) const
|
||||
{
|
||||
this->m_context->removeShared(this);
|
||||
if (object == 0) return;
|
||||
object->context()->noMoreReferencesTo(object);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -10,12 +10,13 @@ class FragmentShaderArguments : public ShaderArguments
|
|||
{
|
||||
public:
|
||||
|
||||
typedef ShaderArguments BaseType;
|
||||
typedef ShaderArguments BaseType;
|
||||
typedef FragmentShaderArguments ThisType;
|
||||
|
||||
FragmentShaderArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -24,33 +25,14 @@ class FragmentShaderArguments : public ShaderArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeFragmentShader : public virtual SafeShader
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeFragmentShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeFragmentShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class FragmentShader : public Shader, public SafeFragmentShader
|
||||
class FragmentShader : public Shader
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<FragmentShader>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Shader BaseType;
|
||||
typedef SafeFragmentShader SafeType;
|
||||
typedef FragmentShader ThisType;
|
||||
typedef Shader BaseType;
|
||||
typedef FragmentShader ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
|
@ -60,10 +42,7 @@ class FragmentShader : public Shader, public SafeFragmentShader
|
|||
protected:
|
||||
|
||||
FragmentShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeShader (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -79,9 +58,101 @@ class FragmentShader : public Shader, public SafeFragmentShader
|
|||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <FragmentShader> FragmentShaderHandle;
|
||||
typedef detail::UnsafeHandle <FragmentShader> BoundFragmentShader;
|
||||
namespace detail { template <> struct BaseOf <FragmentShader> { typedef Shader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <FragmentShader> ::Type FragmentShaderPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeFragmentShader : public SafeShader
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundFragmentShader;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeFragmentShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeFragmentShader(const FragmentShaderPtr & fragmentShader)
|
||||
: BaseType(fragmentShader)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const FragmentShaderPtr & object(void) const
|
||||
{
|
||||
return static_cast<const FragmentShaderPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
FragmentShaderPtr & object(void)
|
||||
{
|
||||
return static_cast<FragmentShaderPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeFragmentShader> { typedef SafeShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeFragmentShader> { typedef FragmentShader Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <FragmentShader > { typedef SafeFragmentShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeFragmentShader> ::Type FragmentShaderHandle;
|
||||
|
||||
class FragmentShaderBindingParams : public ShaderBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ShaderBindingParams BaseType;
|
||||
typedef FragmentShaderBindingParams ThisType;
|
||||
|
||||
FragmentShaderBindingParams(void)
|
||||
: BaseType(GL_FRAGMENT_SHADER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundFragmentShader : public BoundShader
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundShader BaseType;
|
||||
typedef BoundFragmentShader ThisType;
|
||||
|
||||
const FragmentShaderHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const FragmentShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
FragmentShaderHandle & handle(void)
|
||||
{
|
||||
return static_cast<FragmentShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundFragmentShader(const FragmentShaderHandle & handle, const ShaderBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const FragmentShaderPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
FragmentShaderPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundFragmentShader> { typedef FragmentShaderBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundFragmentShader> { typedef BoundShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundFragmentShader> { typedef FragmentShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <FragmentShader > { typedef BoundFragmentShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundFragmentShader> ::Type BoundFragmentShaderHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_FRAGMENTSHADER_H
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef GLW_FRAMEBUFFER_H
|
||||
#define GLW_FRAMEBUFFER_H
|
||||
|
||||
#include "./object.h"
|
||||
#include "./texture2D.h"
|
||||
#include "./renderbuffer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace glw
|
||||
{
|
||||
|
@ -134,12 +137,12 @@ class FramebufferArguments : public ObjectArguments
|
|||
RenderTargetMapping colorTargets;
|
||||
RenderTarget depthTarget;
|
||||
RenderTarget stencilTarget;
|
||||
RenderTarget depthStencilTarget;
|
||||
RenderTargetBinding targetInputs;
|
||||
|
||||
FramebufferArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -148,58 +151,102 @@ class FramebufferArguments : public ObjectArguments
|
|||
this->colorTargets .clear();
|
||||
this->depthTarget .clear();
|
||||
this->stencilTarget .clear();
|
||||
this->depthStencilTarget .clear();
|
||||
this->targetInputs .clear();
|
||||
}
|
||||
};
|
||||
|
||||
class SafeFramebuffer : public virtual SafeObject
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeFramebuffer ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeFramebuffer(Context * ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Framebuffer : public Object, public SafeFramebuffer
|
||||
class Framebuffer : public Object
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<Framebuffer>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Object BaseType;
|
||||
typedef SafeFramebuffer SafeType;
|
||||
typedef Framebuffer ThisType;
|
||||
typedef Object BaseType;
|
||||
typedef Framebuffer ThisType;
|
||||
|
||||
virtual ~Framebuffer(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
return FramebufferType;
|
||||
}
|
||||
|
||||
const FramebufferArguments & arguments(void) const
|
||||
{
|
||||
return this->m_config;
|
||||
}
|
||||
|
||||
bool setColorTarget(GLenum target, GLint unit, GLint index, const RenderTarget & renderTarget)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
this->m_config.colorTargets[index].clear();
|
||||
const bool r = this->attachTarget(target, GL_COLOR_ATTACHMENT0 + index, renderTarget);
|
||||
if (!r) return false;
|
||||
this->m_config.colorTargets[index] = renderTarget;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeColorTarget(GLenum target, GLint unit, GLint index)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glFramebufferRenderbuffer(target, GL_COLOR_ATTACHMENT0 + index, GL_RENDERBUFFER, 0);
|
||||
this->m_config.colorTargets[index].clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setDepthTarget(GLenum target, GLint unit, const RenderTarget & renderTarget)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
this->m_config.depthTarget.clear();
|
||||
const bool r = this->attachTarget(target, GL_DEPTH_ATTACHMENT, renderTarget);
|
||||
if (!r) return false;
|
||||
this->m_config.depthTarget = renderTarget;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeDepthTarget(GLenum target, GLint unit)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glFramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
this->m_config.depthTarget.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setStencilTarget(GLenum target, GLint unit, const RenderTarget & renderTarget)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
this->m_config.stencilTarget.clear();
|
||||
const bool r = this->attachTarget(target, GL_STENCIL_ATTACHMENT, renderTarget);
|
||||
if (!r) return false;
|
||||
this->m_config.stencilTarget = renderTarget;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removeStencilTarget(GLenum target, GLint unit)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glFramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
this->m_config.stencilTarget.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Framebuffer(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~Framebuffer(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
bool create(const FramebufferArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
@ -213,9 +260,9 @@ class Framebuffer : public Object, public SafeFramebuffer
|
|||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &boundNameRead);
|
||||
|
||||
glGenFramebuffers(1, &(this->m_name));
|
||||
this->setBinding(GL_FRAMEBUFFER, 0);
|
||||
this->bind();
|
||||
this->configure();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, this->m_name);
|
||||
this->configure(GL_FRAMEBUFFER);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, boundNameDraw);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, boundNameRead);
|
||||
|
@ -223,45 +270,30 @@ class Framebuffer : public Object, public SafeFramebuffer
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
glDeleteFramebuffers(1, &name);
|
||||
glDeleteFramebuffers(1, &(this->m_name));
|
||||
this->m_config.clear();
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
glBindFramebuffer(this->m_target, this->m_name);
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
{
|
||||
glBindFramebuffer(this->m_target, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
FramebufferArguments m_config;
|
||||
|
||||
void configure(void)
|
||||
void configure(GLenum target)
|
||||
{
|
||||
for (RenderTargetMapping::Iterator it=this->m_config.colorTargets.bindings.begin(); it!=this->m_config.colorTargets.bindings.end(); ++it)
|
||||
{
|
||||
this->attachTarget(GL_COLOR_ATTACHMENT0 + it->first, it->second);
|
||||
this->attachTarget(target, GL_COLOR_ATTACHMENT0 + it->first, it->second);
|
||||
}
|
||||
|
||||
if (this->m_config.depthStencilTarget.target)
|
||||
{
|
||||
this->attachTarget(GL_DEPTH_ATTACHMENT, this->m_config.depthStencilTarget);
|
||||
this->attachTarget(GL_STENCIL_ATTACHMENT, this->m_config.depthStencilTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->attachTarget(GL_DEPTH_ATTACHMENT, this->m_config.depthTarget );
|
||||
this->attachTarget(GL_STENCIL_ATTACHMENT, this->m_config.stencilTarget);
|
||||
}
|
||||
this->attachTarget(target, GL_DEPTH_ATTACHMENT, this->m_config.depthTarget );
|
||||
this->attachTarget(target, GL_STENCIL_ATTACHMENT, this->m_config.stencilTarget);
|
||||
|
||||
if (this->m_config.colorTargets.bindings.empty())
|
||||
{
|
||||
|
@ -287,30 +319,318 @@ class Framebuffer : public Object, public SafeFramebuffer
|
|||
}
|
||||
}
|
||||
|
||||
bool attachTarget(GLenum attachment, RenderTarget & target)
|
||||
bool attachTarget(GLenum target, GLenum attachment, const RenderTarget & renderTarget)
|
||||
{
|
||||
RenderableHandle & handle = target.target;
|
||||
const RenderableHandle & handle = renderTarget.target;
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
glFramebufferRenderbuffer(this->m_target, attachment, GL_RENDERBUFFER, 0);
|
||||
glFramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (handle->type())
|
||||
{
|
||||
case RenderbufferType : glFramebufferRenderbuffer (this->m_target, attachment, GL_RENDERBUFFER, handle->name() ); break;
|
||||
case Texture2DType : glFramebufferTexture2D (this->m_target, attachment, GL_TEXTURE_2D, handle->name(), target.level); break;
|
||||
default : GLW_ASSERT(0); break;
|
||||
case RenderbufferType : glFramebufferRenderbuffer (target, attachment, GL_RENDERBUFFER, handle->name() ); break;
|
||||
case Texture2DType : glFramebufferTexture2D (target, attachment, GL_TEXTURE_2D, handle->name(), renderTarget.level); break;
|
||||
default : GLW_ASSERT(0); break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Framebuffer> FramebufferHandle;
|
||||
typedef detail::UnsafeHandle <Framebuffer> BoundFramebuffer;
|
||||
namespace detail { template <> struct BaseOf <Framebuffer> { typedef Object Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Framebuffer> ::Type FramebufferPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeFramebuffer : public SafeObject
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundFramebuffer;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeFramebuffer ThisType;
|
||||
|
||||
const FramebufferArguments & arguments(void) const
|
||||
{
|
||||
return this->object()->arguments();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeFramebuffer(const FramebufferPtr & program)
|
||||
: BaseType(program)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const FramebufferPtr & object(void) const
|
||||
{
|
||||
return static_cast<const FramebufferPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
FramebufferPtr & object(void)
|
||||
{
|
||||
return static_cast<FramebufferPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeFramebuffer> { typedef SafeObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeFramebuffer> { typedef Framebuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Framebuffer > { typedef SafeFramebuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeFramebuffer> ::Type FramebufferHandle;
|
||||
|
||||
class FramebufferBindingParams : public ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ObjectBindingParams BaseType;
|
||||
typedef FramebufferBindingParams ThisType;
|
||||
|
||||
FramebufferBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
FramebufferBindingParams(GLenum target)
|
||||
: BaseType(target, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundFramebuffer : public BoundObject
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundObject BaseType;
|
||||
typedef BoundFramebuffer ThisType;
|
||||
|
||||
BoundFramebuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const FramebufferHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const FramebufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
FramebufferHandle & handle(void)
|
||||
{
|
||||
return static_cast<FramebufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
GLenum getStatus(void) const
|
||||
{
|
||||
return glCheckFramebufferStatus(this->m_target);
|
||||
}
|
||||
|
||||
bool isComplete(void) const
|
||||
{
|
||||
return (this->getStatus() == GL_FRAMEBUFFER_COMPLETE);
|
||||
}
|
||||
|
||||
bool setColorTarget(GLint index, const RenderTarget & renderTarget)
|
||||
{
|
||||
return this->object()->setColorTarget(this->m_target, this->m_unit, index, renderTarget);
|
||||
}
|
||||
|
||||
bool removeColorTarget(GLint index)
|
||||
{
|
||||
return this->object()->removeColorTarget(this->m_target, this->m_unit, index);
|
||||
}
|
||||
|
||||
bool setDepthTarget(const RenderTarget & renderTarget)
|
||||
{
|
||||
return this->object()->setDepthTarget(this->m_target, this->m_unit, renderTarget);
|
||||
}
|
||||
|
||||
bool removeDepthTarget(void)
|
||||
{
|
||||
return this->object()->removeDepthTarget(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
bool setStencilTarget(const RenderTarget & renderTarget)
|
||||
{
|
||||
return this->object()->setStencilTarget(this->m_target, this->m_unit, renderTarget);
|
||||
}
|
||||
|
||||
bool removeStencilTarget(void)
|
||||
{
|
||||
return this->object()->removeStencilTarget(this->m_target, this->m_unit);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundFramebuffer(const FramebufferHandle & handle, const FramebufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const FramebufferPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
FramebufferPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glBindFramebuffer(this->m_target, this->object()->name());
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glBindFramebuffer(this->m_target, 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundFramebuffer> { typedef FramebufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundFramebuffer> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundFramebuffer> { typedef Framebuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Framebuffer > { typedef BoundFramebuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundFramebuffer> ::Type BoundFramebufferHandle;
|
||||
|
||||
class ReadFramebufferBindingParams : public FramebufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef FramebufferBindingParams BaseType;
|
||||
typedef ReadFramebufferBindingParams ThisType;
|
||||
|
||||
ReadFramebufferBindingParams(void)
|
||||
: BaseType(GL_READ_FRAMEBUFFER)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundReadFramebuffer : public BoundFramebuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundFramebuffer BaseType;
|
||||
typedef BoundReadFramebuffer ThisType;
|
||||
|
||||
BoundReadFramebuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundReadFramebuffer(const FramebufferHandle & handle, const ReadFramebufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundReadFramebuffer> { typedef ReadFramebufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundReadFramebuffer> { typedef BoundFramebuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundReadFramebuffer> { typedef Framebuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundReadFramebuffer> ::Type BoundReadFramebufferHandle;
|
||||
|
||||
class DrawFramebufferBindingParams : public FramebufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef FramebufferBindingParams BaseType;
|
||||
typedef DrawFramebufferBindingParams ThisType;
|
||||
|
||||
DrawFramebufferBindingParams(void)
|
||||
: BaseType(GL_DRAW_FRAMEBUFFER)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundDrawFramebuffer : public BoundFramebuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundFramebuffer BaseType;
|
||||
typedef BoundDrawFramebuffer ThisType;
|
||||
|
||||
BoundDrawFramebuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundDrawFramebuffer(const FramebufferHandle & handle, const DrawFramebufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundDrawFramebuffer> { typedef DrawFramebufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundDrawFramebuffer> { typedef BoundFramebuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundDrawFramebuffer> { typedef Framebuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundDrawFramebuffer> ::Type BoundDrawFramebufferHandle;
|
||||
|
||||
class ReadDrawFramebufferBindingParams : public FramebufferBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef FramebufferBindingParams BaseType;
|
||||
typedef ReadDrawFramebufferBindingParams ThisType;
|
||||
|
||||
ReadDrawFramebufferBindingParams(void)
|
||||
: BaseType(GL_FRAMEBUFFER)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundReadDrawFramebuffer : public BoundFramebuffer
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundFramebuffer BaseType;
|
||||
typedef BoundReadDrawFramebuffer ThisType;
|
||||
|
||||
BoundReadDrawFramebuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundReadDrawFramebuffer(const FramebufferHandle & handle, const ReadDrawFramebufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundReadDrawFramebuffer> { typedef ReadDrawFramebufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundReadDrawFramebuffer> { typedef BoundFramebuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundReadDrawFramebuffer> { typedef Framebuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundReadDrawFramebuffer> ::Type BoundReadDrawFramebufferHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_FRAMEBUFFER_H
|
||||
|
|
|
@ -10,12 +10,13 @@ class GeometryShaderArguments : public ShaderArguments
|
|||
{
|
||||
public:
|
||||
|
||||
typedef ShaderArguments BaseType;
|
||||
typedef ShaderArguments BaseType;
|
||||
typedef GeometryShaderArguments ThisType;
|
||||
|
||||
GeometryShaderArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -24,33 +25,14 @@ class GeometryShaderArguments : public ShaderArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeGeometryShader : public virtual SafeShader
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeGeometryShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeGeometryShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class GeometryShader : public Shader, public SafeGeometryShader
|
||||
class GeometryShader : public Shader
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<GeometryShader>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Shader BaseType;
|
||||
typedef SafeGeometryShader SafeType;
|
||||
typedef GeometryShader ThisType;
|
||||
typedef Shader BaseType;
|
||||
typedef GeometryShader ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
|
@ -60,10 +42,7 @@ class GeometryShader : public Shader, public SafeGeometryShader
|
|||
protected:
|
||||
|
||||
GeometryShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeShader (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -79,9 +58,101 @@ class GeometryShader : public Shader, public SafeGeometryShader
|
|||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <GeometryShader> GeometryShaderHandle;
|
||||
typedef detail::UnsafeHandle <GeometryShader> BoundGeometryShader;
|
||||
namespace detail { template <> struct BaseOf <GeometryShader> { typedef Shader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <GeometryShader> ::Type GeometryShaderPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeGeometryShader : public SafeShader
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundGeometryShader;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeGeometryShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeGeometryShader(const GeometryShaderPtr & geometryShader)
|
||||
: BaseType(geometryShader)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const GeometryShaderPtr & object(void) const
|
||||
{
|
||||
return static_cast<const GeometryShaderPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
GeometryShaderPtr & object(void)
|
||||
{
|
||||
return static_cast<GeometryShaderPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeGeometryShader> { typedef SafeShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeGeometryShader> { typedef GeometryShader Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <GeometryShader > { typedef SafeGeometryShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeGeometryShader> ::Type GeometryShaderHandle;
|
||||
|
||||
class GeometryShaderBindingParams : public ShaderBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ShaderBindingParams BaseType;
|
||||
typedef GeometryShaderBindingParams ThisType;
|
||||
|
||||
GeometryShaderBindingParams(void)
|
||||
: BaseType(GL_GEOMETRY_SHADER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundGeometryShader : public BoundShader
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundShader BaseType;
|
||||
typedef BoundGeometryShader ThisType;
|
||||
|
||||
const GeometryShaderHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const GeometryShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
GeometryShaderHandle & handle(void)
|
||||
{
|
||||
return static_cast<GeometryShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundGeometryShader(const GeometryShaderHandle & handle, const ShaderBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const GeometryShaderPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
GeometryShaderPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundGeometryShader> { typedef GeometryShaderBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundGeometryShader> { typedef BoundShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundGeometryShader> { typedef GeometryShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <GeometryShader > { typedef BoundGeometryShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundGeometryShader> ::Type BoundGeometryShaderHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_GEOMETRYSHADER_H
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "./bookkeeping.h"
|
||||
#include "./noncopyable.h"
|
||||
#include "./objectdeleter.h"
|
||||
#include "./type.h"
|
||||
#include "./glheaders.h"
|
||||
|
||||
|
@ -20,7 +21,7 @@ class ObjectArguments
|
|||
|
||||
ObjectArguments(void)
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -29,26 +30,31 @@ class ObjectArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeObject
|
||||
class Object : public detail::NonCopyable
|
||||
{
|
||||
friend class Object;
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SafeObject ThisType;
|
||||
typedef detail::NonCopyable BaseType;
|
||||
typedef Object ThisType;
|
||||
|
||||
virtual ~Object(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
bool isValid(void) const
|
||||
{
|
||||
return (this->m_name != 0);
|
||||
return ((this->m_name != 0) && this->doIsValid());
|
||||
}
|
||||
|
||||
Context * context(void)
|
||||
const Context * context(void) const
|
||||
{
|
||||
return this->m_context;
|
||||
}
|
||||
|
||||
const Context * context(void) const
|
||||
Context * context(void)
|
||||
{
|
||||
return this->m_context;
|
||||
}
|
||||
|
@ -62,12 +68,48 @@ class SafeObject
|
|||
|
||||
protected:
|
||||
|
||||
Context * m_context;
|
||||
GLuint m_name;
|
||||
Context * m_context;
|
||||
|
||||
SafeObject(Context * ctx)
|
||||
: m_context (ctx)
|
||||
, m_name (0)
|
||||
Object(Context * ctx)
|
||||
: m_name (0)
|
||||
, m_context (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void destroy(void)
|
||||
{
|
||||
if (this->m_name == 0) return;
|
||||
this->doDestroy();
|
||||
this->m_name = 0;
|
||||
this->m_context = 0;
|
||||
}
|
||||
|
||||
virtual void doDestroy(void) = 0;
|
||||
virtual bool doIsValid(void) const = 0;
|
||||
};
|
||||
|
||||
namespace detail { template <typename T> struct ObjectBase { typedef NoBase Type; }; };
|
||||
namespace detail { template <typename T> struct ObjectSafe { typedef NoBase Type; }; };
|
||||
namespace detail { template <typename T> struct ObjectBound { typedef NoBase Type; }; };
|
||||
|
||||
namespace detail { template <> struct BaseOf <Object> { typedef NoBase Type; }; };
|
||||
namespace detail { template <> struct DeleterOf <Object> { typedef ObjectDeleter Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Object> ::Type ObjectPtr;
|
||||
|
||||
class SafeObject : public detail::NonCopyable
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundObject;
|
||||
|
||||
public:
|
||||
|
||||
typedef detail::NonCopyable BaseType;
|
||||
typedef SafeObject ThisType;
|
||||
|
||||
SafeObject(void)
|
||||
: m_object(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -76,67 +118,178 @@ class SafeObject
|
|||
{
|
||||
;
|
||||
}
|
||||
|
||||
bool isNull(void) const
|
||||
{
|
||||
return this->m_object.isNull();
|
||||
}
|
||||
|
||||
bool isValid(void) const
|
||||
{
|
||||
return this->m_object->isValid();
|
||||
}
|
||||
|
||||
const Context * context(void) const
|
||||
{
|
||||
if (this->isNull()) return 0;
|
||||
return this->m_object->context();
|
||||
}
|
||||
|
||||
Context * context(void)
|
||||
{
|
||||
if (this->isNull()) return 0;
|
||||
return this->m_object->context();
|
||||
}
|
||||
|
||||
GLuint name(void) const
|
||||
{
|
||||
if (this->isNull()) return 0;
|
||||
return this->m_object->name();
|
||||
}
|
||||
|
||||
Type type(void) const
|
||||
{
|
||||
if (this->isNull()) return NoType;
|
||||
return this->m_object->type();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeObject(const ObjectPtr & object)
|
||||
: m_object(object)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ObjectPtr & object(void) const
|
||||
{
|
||||
return this->m_object;
|
||||
}
|
||||
|
||||
ObjectPtr & object(void)
|
||||
{
|
||||
return this->m_object;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
ObjectPtr m_object;
|
||||
};
|
||||
|
||||
class Object : public detail::NonCopyable, public virtual SafeObject
|
||||
namespace detail { template <> struct BaseOf <SafeObject> { typedef NoBase Type; }; };
|
||||
namespace detail { template <> struct DeleterOf <SafeObject> { typedef DefaultDeleter<SafeObject> Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeObject> { typedef Object Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Object > { typedef SafeObject Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeObject> ::Type ObjectHandle;
|
||||
|
||||
class ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef ObjectBindingParams ThisType;
|
||||
|
||||
GLenum target;
|
||||
GLint unit;
|
||||
|
||||
ObjectBindingParams(void)
|
||||
: target (GL_NONE)
|
||||
, unit (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ObjectBindingParams(GLenum aTarget, GLenum aUnit)
|
||||
: target (aTarget)
|
||||
, unit (aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundObject : public detail::NonCopyable
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef SafeObject SafeType;
|
||||
typedef Object ThisType;
|
||||
typedef detail::NonCopyable BaseType;
|
||||
typedef BoundObject ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
GLenum m_target;
|
||||
GLint m_unit;
|
||||
|
||||
Object(Context * ctx)
|
||||
: SafeType (ctx)
|
||||
, m_target (GL_NONE)
|
||||
, m_unit (0)
|
||||
BoundObject(void)
|
||||
: m_handle (0)
|
||||
, m_target (GL_NONE)
|
||||
, m_unit (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void destroy(void)
|
||||
virtual ~BoundObject(void)
|
||||
{
|
||||
if (!this->isValid()) return;
|
||||
|
||||
this->doDestroy(this->m_context, this->m_name);
|
||||
|
||||
this->m_context = 0;
|
||||
this->m_name = 0;
|
||||
;
|
||||
}
|
||||
|
||||
void setBinding(GLenum target, GLint unit) const
|
||||
bool isNull(void) const
|
||||
{
|
||||
ThisType * that = const_cast<ThisType *>(this);
|
||||
that->m_target = target;
|
||||
that->m_unit = unit;
|
||||
return this->m_handle.isNull();
|
||||
}
|
||||
|
||||
void bind(void)
|
||||
const ObjectHandle & handle(void) const
|
||||
{
|
||||
GLW_ASSERT(this->isValid());
|
||||
this->doBind();
|
||||
return this->m_handle;
|
||||
}
|
||||
|
||||
void unbind(void)
|
||||
ObjectHandle & handle(void)
|
||||
{
|
||||
GLW_ASSERT(this->isValid());
|
||||
this->doUnbind();
|
||||
return this->m_handle;
|
||||
}
|
||||
|
||||
virtual void doDestroy (Context * ctx, GLuint name) = 0;
|
||||
virtual void doBind (void) = 0;
|
||||
virtual void doUnbind (void) = 0;
|
||||
GLenum target(void) const
|
||||
{
|
||||
return this->m_target;
|
||||
}
|
||||
|
||||
GLint unit(void) const
|
||||
{
|
||||
return this->m_unit;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ObjectHandle m_handle;
|
||||
GLenum m_target;
|
||||
GLint m_unit;
|
||||
|
||||
BoundObject(const ObjectHandle & handle, const ObjectBindingParams & params)
|
||||
: m_handle (handle)
|
||||
, m_target (params.target)
|
||||
, m_unit (params.unit)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ObjectPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
ObjectPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind (void) = 0;
|
||||
virtual void unbind (void) = 0;
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Object> ObjectHandle;
|
||||
typedef detail::UnsafeHandle <Object> BoundObject;
|
||||
namespace detail { template <typename T> struct ParamsOf { typedef NoBase Type; }; };
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundObject> { typedef ObjectBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundObject> { typedef NoBase Type; }; };
|
||||
namespace detail { template <> struct DeleterOf <BoundObject> { typedef DefaultDeleter<BoundObject> Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundObject> { typedef Object Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Object > { typedef BoundObject Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundObject> ::Type BoundObjectHandle;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef GLW_OBJECTDELETER_H
|
||||
#define GLW_OBJECTDELETER_H
|
||||
|
||||
#include "./common.h"
|
||||
|
||||
namespace glw
|
||||
{
|
||||
|
||||
class Object;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class ObjectDeleter
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void BaseType;
|
||||
typedef ObjectDeleter ThisType;
|
||||
|
||||
inline void operator () (Object * object) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_OBJECTDELETER_H
|
|
@ -182,8 +182,9 @@ class ProgramArguments : public ObjectArguments
|
|||
FragmentOutputBinding fragmentOutputs;
|
||||
|
||||
ProgramArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -198,12 +199,24 @@ class ProgramArguments : public ObjectArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeProgram : public virtual SafeObject
|
||||
class Program : public Object
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeProgram ThisType;
|
||||
typedef Object BaseType;
|
||||
typedef Program ThisType;
|
||||
|
||||
virtual ~Program(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
return ProgramType;
|
||||
}
|
||||
|
||||
const ProgramArguments & arguments(void) const
|
||||
{
|
||||
|
@ -220,36 +233,6 @@ class SafeProgram : public virtual SafeObject
|
|||
return this->m_linked;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ProgramArguments m_arguments;
|
||||
std::string m_log;
|
||||
bool m_linked;
|
||||
|
||||
SafeProgram(Context * ctx)
|
||||
: BaseType (ctx)
|
||||
, m_linked (false)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Program : public Object, public SafeProgram
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<Program>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Object BaseType;
|
||||
typedef SafeProgram SafeType;
|
||||
typedef Program ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
return ProgramType;
|
||||
}
|
||||
|
||||
GLint getUniformLocation(const std::string & name) const
|
||||
{
|
||||
GLW_ASSERT(this->m_uniforms.count(name) > 0);
|
||||
|
@ -296,18 +279,12 @@ class Program : public Object, public SafeProgram
|
|||
protected:
|
||||
|
||||
Program(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType (ctx)
|
||||
, m_linked (false)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~Program(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
bool create(const ProgramArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
@ -385,31 +362,22 @@ class Program : public Object, public SafeProgram
|
|||
this->postLink();
|
||||
}
|
||||
|
||||
this->setBinding(GL_CURRENT_PROGRAM, 0);
|
||||
this->bind();
|
||||
// TODO
|
||||
// ... nothing to do ...
|
||||
|
||||
glUseProgram(boundName);
|
||||
|
||||
return this->m_linked;
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
virtual void doDestroy()
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
glDeleteProgram(name);
|
||||
glDeleteProgram(this->m_name);
|
||||
this->m_arguments.clear();
|
||||
this->m_log.clear();
|
||||
this->m_linked = false;
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
glUseProgram(this->m_name);
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
{
|
||||
glUseProgram(0);
|
||||
return this->m_linked;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -440,7 +408,10 @@ class Program : public Object, public SafeProgram
|
|||
typedef UniformMap::iterator UniformMapIterator;
|
||||
typedef UniformMap::value_type UniformMapValue;
|
||||
|
||||
UniformMap m_uniforms;
|
||||
ProgramArguments m_arguments;
|
||||
UniformMap m_uniforms;
|
||||
std::string m_log;
|
||||
bool m_linked;
|
||||
|
||||
static std::string getInfoLog(GLuint Program)
|
||||
{
|
||||
|
@ -496,9 +467,167 @@ class Program : public Object, public SafeProgram
|
|||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Program> ProgramHandle;
|
||||
typedef detail::UnsafeHandle <Program> BoundProgram;
|
||||
namespace detail { template <> struct BaseOf <Program> { typedef Object Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Program> ::Type ProgramPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeProgram : public SafeObject
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundProgram;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeProgram ThisType;
|
||||
|
||||
const ProgramArguments & arguments(void) const
|
||||
{
|
||||
return this->object()->arguments();
|
||||
}
|
||||
|
||||
const std::string & log(void) const
|
||||
{
|
||||
return this->object()->log();
|
||||
}
|
||||
|
||||
bool isLinked(void) const
|
||||
{
|
||||
return this->object()->isLinked();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeProgram(const ProgramPtr & program)
|
||||
: BaseType(program)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ProgramPtr & object(void) const
|
||||
{
|
||||
return static_cast<const ProgramPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
ProgramPtr & object(void)
|
||||
{
|
||||
return static_cast<ProgramPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeProgram> { typedef SafeObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeProgram> { typedef Program Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Program > { typedef SafeProgram Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeProgram> ::Type ProgramHandle;
|
||||
|
||||
class ProgramBindingParams : public ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ObjectBindingParams BaseType;
|
||||
typedef ProgramBindingParams ThisType;
|
||||
|
||||
ProgramBindingParams(void)
|
||||
: BaseType(GL_CURRENT_PROGRAM, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundProgram : public BoundObject
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundObject BaseType;
|
||||
typedef BoundProgram ThisType;
|
||||
|
||||
BoundProgram(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ProgramHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const ProgramHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
ProgramHandle & handle(void)
|
||||
{
|
||||
return static_cast<ProgramHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
#define _GLW_FORWARD_SCALAR_UNIFORM_(TYPE) \
|
||||
void setUniform (const std::string & name, TYPE x ) { this->object()->setUniform(name, x ); } \
|
||||
void setUniform (const std::string & name, TYPE x, TYPE y ) { this->object()->setUniform(name, x, y ); } \
|
||||
void setUniform (const std::string & name, TYPE x, TYPE y, TYPE z ) { this->object()->setUniform(name, x, y, z ); } \
|
||||
void setUniform (const std::string & name, TYPE x, TYPE y, TYPE z, TYPE w ) { this->object()->setUniform(name, x, y, z, w); }
|
||||
|
||||
#define _GLW_FORWARD_VECTOR_UNIFORM_(TYPE) \
|
||||
void setUniform1 (const std::string & name, const TYPE * v, int count = 1) { this->object()->setUniform1(name, v, count); } \
|
||||
void setUniform2 (const std::string & name, const TYPE * v, int count = 1) { this->object()->setUniform2(name, v, count); } \
|
||||
void setUniform3 (const std::string & name, const TYPE * v, int count = 1) { this->object()->setUniform3(name, v, count); } \
|
||||
void setUniform4 (const std::string & name, const TYPE * v, int count = 1) { this->object()->setUniform4(name, v, count); }
|
||||
|
||||
#define _GLW_FORWARD_MATRIX_UNIFORM_(TYPE) \
|
||||
void setUniform2x2 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform2x2(name, m, transpose, count); } \
|
||||
void setUniform2x3 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform2x3(name, m, transpose, count); } \
|
||||
void setUniform2x4 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform2x4(name, m, transpose, count); } \
|
||||
void setUniform3x2 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform3x2(name, m, transpose, count); } \
|
||||
void setUniform3x3 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform3x3(name, m, transpose, count); } \
|
||||
void setUniform3x4 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform3x4(name, m, transpose, count); } \
|
||||
void setUniform4x2 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform4x2(name, m, transpose, count); } \
|
||||
void setUniform4x3 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform4x3(name, m, transpose, count); } \
|
||||
void setUniform4x4 (const std::string & name, const TYPE * m, bool transpose, int count = 1) { this->object()->setUniform4x4(name, m, transpose, count); }
|
||||
|
||||
_GLW_FORWARD_SCALAR_UNIFORM_(int)
|
||||
_GLW_FORWARD_SCALAR_UNIFORM_(unsigned int)
|
||||
_GLW_FORWARD_SCALAR_UNIFORM_(float)
|
||||
_GLW_FORWARD_VECTOR_UNIFORM_(int)
|
||||
_GLW_FORWARD_VECTOR_UNIFORM_(unsigned int)
|
||||
_GLW_FORWARD_VECTOR_UNIFORM_(float)
|
||||
_GLW_FORWARD_MATRIX_UNIFORM_(float)
|
||||
|
||||
#undef _GLW_FORWARD_SCALAR_UNIFORM_
|
||||
#undef _GLW_FORWARD_VECTOR_UNIFORM_
|
||||
#undef _GLW_FORWARD_MATRIX_UNIFORM_
|
||||
|
||||
protected:
|
||||
|
||||
BoundProgram(const ProgramHandle & handle, const ProgramBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ProgramPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
ProgramPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glUseProgram(this->object()->name());
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glUseProgram(0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundProgram> { typedef ProgramBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundProgram> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundProgram> { typedef Program Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Program > { typedef BoundProgram Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundProgram> ::Type BoundProgramHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_PROGRAM_H
|
||||
|
|
|
@ -18,23 +18,34 @@ class RenderableArguments : public ObjectArguments
|
|||
GLenum format;
|
||||
|
||||
RenderableArguments(void)
|
||||
: BaseType ()
|
||||
, format (GL_RGBA8)
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
RenderableArguments(GLenum aFormat)
|
||||
: BaseType ()
|
||||
, format (aFormat)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
{
|
||||
BaseType::clear();
|
||||
this->format = GL_NONE;
|
||||
this->format = GL_RGBA8;
|
||||
}
|
||||
};
|
||||
|
||||
class SafeRenderable : public virtual SafeObject
|
||||
class Renderable : public Object
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeRenderable ThisType;
|
||||
typedef Object BaseType;
|
||||
typedef Renderable ThisType;
|
||||
|
||||
GLenum format(void) const
|
||||
{
|
||||
|
@ -48,7 +59,7 @@ class SafeRenderable : public virtual SafeObject
|
|||
|
||||
GLenum m_format;
|
||||
|
||||
SafeRenderable(Context * ctx)
|
||||
Renderable(Context * ctx)
|
||||
: BaseType (ctx)
|
||||
, m_format (GL_NONE)
|
||||
{
|
||||
|
@ -56,27 +67,133 @@ class SafeRenderable : public virtual SafeObject
|
|||
}
|
||||
};
|
||||
|
||||
class Renderable : public Object, public virtual SafeRenderable
|
||||
namespace detail { template <> struct BaseOf <Renderable> { typedef Object Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Renderable> ::Type RenderablePtr;
|
||||
|
||||
class SafeRenderable : public SafeObject
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundRenderable;
|
||||
|
||||
public:
|
||||
|
||||
typedef Object BaseType;
|
||||
typedef SafeRenderable SafeType;
|
||||
typedef Renderable ThisType;
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeRenderable ThisType;
|
||||
|
||||
SafeRenderable(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
GLenum format(void) const
|
||||
{
|
||||
return this->object()->format();
|
||||
}
|
||||
|
||||
int imageDimensions(void) const
|
||||
{
|
||||
return this->object()->imageDimensions();
|
||||
}
|
||||
|
||||
bool isArray(void) const
|
||||
{
|
||||
return this->object()->isArray();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Renderable(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeType (ctx)
|
||||
, BaseType (ctx)
|
||||
SafeRenderable(const RenderablePtr & renderable)
|
||||
: BaseType(renderable)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderablePtr & object(void) const
|
||||
{
|
||||
return static_cast<const RenderablePtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
RenderablePtr & object(void)
|
||||
{
|
||||
return static_cast<RenderablePtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeRenderable> { typedef SafeObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeRenderable> { typedef Renderable Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Renderable > { typedef SafeRenderable Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeRenderable> ::Type RenderableHandle;
|
||||
|
||||
class RenderableBindingParams : public ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ObjectBindingParams BaseType;
|
||||
typedef RenderableBindingParams ThisType;
|
||||
|
||||
RenderableBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
RenderableBindingParams(GLenum aTarget, GLenum aUnit)
|
||||
: BaseType(aTarget, aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Renderable> RenderableHandle;
|
||||
typedef detail::UnsafeHandle <Renderable> BoundRenderable;
|
||||
class BoundRenderable : public BoundObject
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundObject BaseType;
|
||||
typedef BoundRenderable ThisType;
|
||||
|
||||
BoundRenderable(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderableHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const RenderableHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
RenderableHandle & handle(void)
|
||||
{
|
||||
return static_cast<RenderableHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundRenderable(const RenderableHandle & handle, const RenderableBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderablePtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
RenderablePtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundRenderable> { typedef RenderableBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundRenderable> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundRenderable> { typedef Renderable Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Renderable > { typedef BoundRenderable Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundRenderable> ::Type BoundRenderableHandle;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -17,8 +17,18 @@ class RenderbufferArguments : public RenderableArguments
|
|||
GLsizei height;
|
||||
|
||||
RenderbufferArguments(void)
|
||||
: BaseType ()
|
||||
, width (0)
|
||||
, height (0)
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
RenderbufferArguments(GLenum aFormat, GLsizei aWidth, GLsizei aHeight)
|
||||
: BaseType (aFormat)
|
||||
, width (aWidth)
|
||||
, height (aHeight)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -29,48 +39,19 @@ class RenderbufferArguments : public RenderableArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeRenderbuffer : public virtual SafeRenderable
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeRenderable BaseType;
|
||||
typedef SafeRenderbuffer ThisType;
|
||||
|
||||
GLsizei width(void) const
|
||||
{
|
||||
return this->m_width;
|
||||
}
|
||||
|
||||
GLsizei height(void) const
|
||||
{
|
||||
return this->m_height;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
|
||||
SafeRenderbuffer(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
, m_width (0)
|
||||
, m_height (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Renderbuffer : public Renderable, public SafeRenderbuffer
|
||||
class Renderbuffer : public Renderable
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<Renderbuffer>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Renderable BaseType;
|
||||
typedef SafeRenderbuffer SafeType;
|
||||
typedef Renderbuffer ThisType;
|
||||
typedef Renderable BaseType;
|
||||
typedef Renderbuffer ThisType;
|
||||
|
||||
virtual ~Renderbuffer(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
|
@ -87,72 +68,180 @@ class Renderbuffer : public Renderable, public SafeRenderbuffer
|
|||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Renderbuffer(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeRenderable (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
void setStorage(GLenum target, GLint unit, GLenum format, GLsizei width, GLsizei height)
|
||||
{
|
||||
;
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glRenderbufferStorage(target, format, width, height);
|
||||
this->m_format = format;
|
||||
this->m_width = width;
|
||||
this->m_height = height;
|
||||
}
|
||||
|
||||
virtual ~Renderbuffer(void)
|
||||
protected:
|
||||
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
|
||||
Renderbuffer(Context * ctx)
|
||||
: BaseType (ctx)
|
||||
, m_width (0)
|
||||
, m_height (0)
|
||||
{
|
||||
this->destroy();
|
||||
;
|
||||
}
|
||||
|
||||
bool create(const RenderbufferArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
||||
GLint boundName = 0;
|
||||
glGetIntegerv(GL_RENDERBUFFER_BINDING, &boundName);
|
||||
|
||||
glGenRenderbuffers(1, &(this->m_name));
|
||||
this->setBinding(GL_RENDERBUFFER, 0);
|
||||
this->bind();
|
||||
this->allocate(args.format, args.width, args.height);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, this->m_name);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, args.format, args.width, args.height);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, boundName);
|
||||
|
||||
this->m_format = args.format;
|
||||
this->m_width = args.width;
|
||||
this->m_height = args.height;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
glDeleteRenderbuffers(1, &(this->m_name));
|
||||
this->m_format = GL_NONE;
|
||||
this->m_width = 0;
|
||||
this->m_height = 0;
|
||||
glDeleteRenderbuffers(1, &name);
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
glBindRenderbuffer(this->m_target, this->m_name);
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
{
|
||||
glBindRenderbuffer(this->m_target, 0);
|
||||
}
|
||||
|
||||
void allocate(GLenum format, GLsizei width, GLsizei height)
|
||||
{
|
||||
GLW_ASSERT(this->isValid());
|
||||
glRenderbufferStorage(this->m_target, format, width, height);
|
||||
this->m_format = format;
|
||||
this->m_width = width;
|
||||
this->m_height = height;
|
||||
return ((this->m_format != GL_NONE) && (this->m_width > 0) && (this->m_height > 0));
|
||||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Renderbuffer> RenderbufferHandle;
|
||||
typedef detail::UnsafeHandle <Renderbuffer> BoundRenderbuffer;
|
||||
namespace detail { template <> struct BaseOf <Renderbuffer> { typedef Renderable Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Renderbuffer> ::Type RenderbufferPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeRenderbuffer : public SafeRenderable
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundRenderbuffer;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeRenderable BaseType;
|
||||
typedef SafeRenderbuffer ThisType;
|
||||
|
||||
SafeRenderbuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeRenderbuffer(const RenderbufferPtr & renderbuffer)
|
||||
: BaseType(renderbuffer)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderbufferPtr & object(void) const
|
||||
{
|
||||
return static_cast<const RenderbufferPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
RenderbufferPtr & object(void)
|
||||
{
|
||||
return static_cast<RenderbufferPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeRenderbuffer> { typedef SafeRenderable Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeRenderbuffer> { typedef Renderbuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Renderbuffer > { typedef SafeRenderbuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeRenderbuffer> ::Type RenderbufferHandle;
|
||||
|
||||
class RenderbufferBindingParams : public RenderableBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef RenderableBindingParams BaseType;
|
||||
typedef RenderbufferBindingParams ThisType;
|
||||
|
||||
RenderbufferBindingParams(void)
|
||||
: BaseType(GL_RENDERBUFFER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundRenderbuffer : public BoundRenderable
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundRenderable BaseType;
|
||||
typedef BoundRenderbuffer ThisType;
|
||||
|
||||
BoundRenderbuffer(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderbufferHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const RenderbufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
RenderbufferHandle & handle(void)
|
||||
{
|
||||
return static_cast<RenderbufferHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
void setStorage(GLenum format, GLsizei width, GLsizei height)
|
||||
{
|
||||
this->object()->setStorage(this->m_target, this->m_unit, format, width, height);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundRenderbuffer(const RenderbufferHandle & handle, const RenderbufferBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const RenderbufferPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
RenderbufferPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glBindRenderbuffer(this->m_target, this->object()->name());
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glBindRenderbuffer(this->m_target, 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundRenderbuffer> { typedef RenderbufferBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundRenderbuffer> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundRenderbuffer> { typedef Renderbuffer Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Renderbuffer > { typedef BoundRenderbuffer Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundRenderbuffer> ::Type BoundRenderbufferHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_RENDERBUFFER_H
|
||||
|
|
|
@ -18,8 +18,9 @@ class ShaderArguments : public ObjectArguments
|
|||
std::string source;
|
||||
|
||||
ShaderArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -29,12 +30,19 @@ class ShaderArguments : public ObjectArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeShader : public virtual SafeObject
|
||||
class Shader : public Object
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeShader ThisType;
|
||||
typedef Object BaseType;
|
||||
typedef Shader ThisType;
|
||||
|
||||
virtual ~Shader(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
const std::string & source(void) const
|
||||
{
|
||||
|
@ -57,77 +65,39 @@ class SafeShader : public virtual SafeObject
|
|||
std::string m_log;
|
||||
bool m_compiled;
|
||||
|
||||
SafeShader(Context * ctx)
|
||||
Shader(Context * ctx)
|
||||
: BaseType (ctx)
|
||||
, m_compiled (false)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Shader : public Object, public virtual SafeShader
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Object BaseType;
|
||||
typedef SafeShader SafeType;
|
||||
typedef Shader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
Shader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeType (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~Shader(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual GLenum shaderType(void) const = 0;
|
||||
|
||||
bool create(const ShaderArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
||||
const GLenum shType = this->shaderType();
|
||||
|
||||
this->m_name = glCreateShader(shType);
|
||||
this->setBinding(shType, 0);
|
||||
this->bind();
|
||||
this->compile(args.source);
|
||||
|
||||
return this->m_compiled;
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
glDeleteShader(this->m_name);
|
||||
this->m_source.clear();
|
||||
this->m_log.clear();
|
||||
this->m_compiled = false;
|
||||
glDeleteShader(name);
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
{
|
||||
;
|
||||
return this->m_compiled;
|
||||
}
|
||||
|
||||
void compile(const std::string & source)
|
||||
{
|
||||
GLW_ASSERT(this->isValid());
|
||||
|
||||
const char * src = source.c_str();
|
||||
glShaderSource(this->m_name, 1, &src, 0);
|
||||
glCompileShader(this->m_name);
|
||||
|
@ -166,9 +136,144 @@ class Shader : public Object, public virtual SafeShader
|
|||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Shader> ShaderHandle;
|
||||
typedef detail::UnsafeHandle <Shader> BoundShader;
|
||||
namespace detail { template <> struct BaseOf <Shader> { typedef Object Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Shader> ::Type ShaderPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeShader : public SafeObject
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundShader;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeObject BaseType;
|
||||
typedef SafeShader ThisType;
|
||||
|
||||
SafeShader(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const std::string & source(void) const
|
||||
{
|
||||
return this->object()->source();
|
||||
}
|
||||
|
||||
const std::string & log(void) const
|
||||
{
|
||||
return this->object()->log();
|
||||
}
|
||||
|
||||
bool isCompiled(void) const
|
||||
{
|
||||
return this->object()->isCompiled();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeShader(const ShaderPtr & shader)
|
||||
: BaseType(shader)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ShaderPtr & object(void) const
|
||||
{
|
||||
return static_cast<const ShaderPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
ShaderPtr & object(void)
|
||||
{
|
||||
return static_cast<ShaderPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeShader> { typedef SafeObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeShader> { typedef Shader Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Shader > { typedef SafeShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeShader> ::Type ShaderHandle;
|
||||
|
||||
class ShaderBindingParams : public ObjectBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ObjectBindingParams BaseType;
|
||||
typedef ShaderBindingParams ThisType;
|
||||
|
||||
ShaderBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
ShaderBindingParams(GLenum aTarget, GLenum aUnit)
|
||||
: BaseType(aTarget, aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundShader : public BoundObject
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundObject BaseType;
|
||||
typedef BoundShader ThisType;
|
||||
|
||||
BoundShader(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ShaderHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const ShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
ShaderHandle & handle(void)
|
||||
{
|
||||
return static_cast<ShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundShader(const ShaderHandle & handle, const ShaderBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const ShaderPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
ShaderPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual void unbind(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundShader> { typedef ShaderBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundShader> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundShader> { typedef Shader Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Shader > { typedef BoundShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundShader> ::Type BoundShaderHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_SHADER_H
|
||||
|
|
|
@ -44,7 +44,7 @@ class TextureSampleMode
|
|||
}
|
||||
};
|
||||
|
||||
inline TextureSampleMode texSampleMode(GLenum minFilter = GLW_DONT_CARE, GLenum magFilter = GLW_DONT_CARE, GLenum wrapS = GLW_DONT_CARE, GLenum wrapT = GLW_DONT_CARE, GLenum wrapR = GLW_DONT_CARE)
|
||||
inline TextureSampleMode textureSampleMode(GLenum minFilter = GLW_DONT_CARE, GLenum magFilter = GLW_DONT_CARE, GLenum wrapS = GLW_DONT_CARE, GLenum wrapT = GLW_DONT_CARE, GLenum wrapR = GLW_DONT_CARE)
|
||||
{
|
||||
return TextureSampleMode(minFilter, magFilter, wrapS, wrapT, wrapR);
|
||||
}
|
||||
|
@ -67,69 +67,158 @@ class TextureArguments : public RenderableArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeTexture : public virtual SafeRenderable
|
||||
class Texture : public Renderable
|
||||
{
|
||||
public:
|
||||
friend class Context;
|
||||
|
||||
typedef SafeRenderable BaseType;
|
||||
typedef SafeTexture ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeTexture(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Texture : public Renderable, public virtual SafeTexture
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Renderable BaseType;
|
||||
typedef SafeTexture SafeType;
|
||||
typedef Texture ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
Texture(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeRenderable (ctx)
|
||||
, SafeType (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~Texture(void)
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
virtual void doDestroy(Context * ctx, GLuint name)
|
||||
protected:
|
||||
|
||||
Texture(Context * ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
if (name == 0) return;
|
||||
glDeleteTextures(1, &name);
|
||||
;
|
||||
}
|
||||
|
||||
virtual void doBind(void)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
glDeleteTextures(1, &(this->m_name));
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <Texture> { typedef Renderable Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Texture> ::Type TexturePtr;
|
||||
|
||||
class SafeTexture : public SafeRenderable
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundTexture;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeRenderable BaseType;
|
||||
typedef SafeTexture ThisType;
|
||||
|
||||
SafeTexture(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeTexture(const TexturePtr & texture)
|
||||
: BaseType(texture)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const TexturePtr & object(void) const
|
||||
{
|
||||
return static_cast<const TexturePtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
TexturePtr & object(void)
|
||||
{
|
||||
return static_cast<TexturePtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeTexture> { typedef SafeRenderable Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeTexture> { typedef Texture Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Texture > { typedef SafeTexture Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeTexture> ::Type TextureHandle;
|
||||
|
||||
class TextureBindingParams : public RenderableBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef RenderableBindingParams BaseType;
|
||||
typedef TextureBindingParams ThisType;
|
||||
|
||||
TextureBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
TextureBindingParams(GLenum aTarget, GLenum aUnit)
|
||||
: BaseType(aTarget, aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundTexture : public BoundRenderable
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundRenderable BaseType;
|
||||
typedef BoundTexture ThisType;
|
||||
|
||||
BoundTexture(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const TextureHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const TextureHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
TextureHandle & handle(void)
|
||||
{
|
||||
return static_cast<TextureHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundTexture(const TextureHandle & handle, const TextureBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const TexturePtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
TexturePtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
virtual void bind(void)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + this->m_unit);
|
||||
glBindTexture(this->m_target, this->m_name);
|
||||
glBindTexture(this->m_target, this->object()->name());
|
||||
}
|
||||
|
||||
virtual void doUnbind(void)
|
||||
virtual void unbind(void)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + this->m_unit);
|
||||
glBindTexture(this->m_target, 0);
|
||||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Texture> TextureHandle;
|
||||
typedef detail::UnsafeHandle <Texture> BoundTexture;
|
||||
namespace detail { template <> struct ParamsOf <BoundTexture> { typedef TextureBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundTexture> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundTexture> { typedef Texture Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Texture > { typedef BoundTexture Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundTexture> ::Type BoundTextureHandle;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -37,49 +37,14 @@ class Texture2DArguments : public TextureArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeTexture2D : public virtual SafeTexture
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeTexture BaseType;
|
||||
typedef SafeTexture2D ThisType;
|
||||
|
||||
GLsizei width(void) const
|
||||
{
|
||||
return this->m_width;
|
||||
}
|
||||
|
||||
GLsizei height(void) const
|
||||
{
|
||||
return this->m_height;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
|
||||
SafeTexture2D(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeRenderable (ctx)
|
||||
, BaseType (ctx)
|
||||
, m_width (0)
|
||||
, m_height (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class Texture2D : public Texture, public SafeTexture2D
|
||||
class Texture2D : public Texture
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<Texture2D>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Texture BaseType;
|
||||
typedef SafeTexture2D SafeType;
|
||||
typedef Texture ThisType;
|
||||
typedef Texture BaseType;
|
||||
typedef Texture2D ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
|
@ -96,41 +61,46 @@ class Texture2D : public Texture, public SafeTexture2D
|
|||
return false;
|
||||
}
|
||||
|
||||
void allocateLevel(GLint level, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
|
||||
void setImage(GLenum target, GLint unit, GLint level, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glTexImage2D(this->m_target, level, this->m_format, width, height, 0, dataFormat, dataType, data);
|
||||
glTexImage2D(target, level, this->m_format, width, height, 0, dataFormat, dataType, data);
|
||||
}
|
||||
|
||||
void setSubImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
|
||||
void setSubImage(GLenum target, GLint unit, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glTexSubImage2D(this->m_target, level, xoffset, yoffset, width, height, dataFormat, dataType, data);
|
||||
glTexSubImage2D(target, level, xoffset, yoffset, width, height, dataFormat, dataType, data);
|
||||
}
|
||||
|
||||
void generateMipmap(void)
|
||||
void generateMipmap(GLenum target, GLint unit)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
glGenerateMipmap(this->m_target);
|
||||
glGenerateMipmap(target);
|
||||
}
|
||||
|
||||
void setSampleMode(const TextureSampleMode & sampler)
|
||||
void setSampleMode(GLenum target, GLint unit, const TextureSampleMode & sampler)
|
||||
{
|
||||
(void)unit;
|
||||
GLW_ASSERT(this->isValid());
|
||||
if (GLW_CARE_OF(sampler.minFilter)) glTexParameteri(this->m_target, GL_TEXTURE_MIN_FILTER, sampler.minFilter);
|
||||
if (GLW_CARE_OF(sampler.magFilter)) glTexParameteri(this->m_target, GL_TEXTURE_MAG_FILTER, sampler.magFilter);
|
||||
if (GLW_CARE_OF(sampler.wrapS )) glTexParameteri(this->m_target, GL_TEXTURE_WRAP_S, sampler.wrapS );
|
||||
if (GLW_CARE_OF(sampler.wrapT )) glTexParameteri(this->m_target, GL_TEXTURE_WRAP_T, sampler.wrapT );
|
||||
if (GLW_CARE_OF(sampler.minFilter)) glTexParameteri(target, GL_TEXTURE_MIN_FILTER, sampler.minFilter);
|
||||
if (GLW_CARE_OF(sampler.magFilter)) glTexParameteri(target, GL_TEXTURE_MAG_FILTER, sampler.magFilter);
|
||||
if (GLW_CARE_OF(sampler.wrapS )) glTexParameteri(target, GL_TEXTURE_WRAP_S, sampler.wrapS );
|
||||
if (GLW_CARE_OF(sampler.wrapT )) glTexParameteri(target, GL_TEXTURE_WRAP_T, sampler.wrapT );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
GLsizei m_width;
|
||||
GLsizei m_height;
|
||||
|
||||
Texture2D(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeRenderable (ctx)
|
||||
, SafeTexture (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType (ctx)
|
||||
, m_width (0)
|
||||
, m_height (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -138,38 +108,146 @@ class Texture2D : public Texture, public SafeTexture2D
|
|||
bool create(const Texture2DArguments & args)
|
||||
{
|
||||
this->destroy();
|
||||
|
||||
GLint activeUnit = 0;
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeUnit);
|
||||
|
||||
GLint boundName = 0;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundName);
|
||||
|
||||
glGenRenderbuffers(1, &(this->m_name));
|
||||
this->setBinding(GL_TEXTURE_2D, 0);
|
||||
this->bind();
|
||||
this->allocate(args.format, args.width, args.height, args.dataFormat, args.dataType, args.data);
|
||||
this->setSampleMode(args.sampler);
|
||||
|
||||
glActiveTexture(activeUnit);
|
||||
glGenTextures(1, &(this->m_name));
|
||||
glBindTexture(GL_TEXTURE_2D, this->m_name);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, args.format, args.width, args.height, 0, args.dataFormat, args.dataType, args.data);
|
||||
this->m_format = args.format;
|
||||
this->m_width = args.width;
|
||||
this->m_height = args.height;
|
||||
this->setSampleMode(GL_TEXTURE_2D, 0, args.sampler);
|
||||
glBindTexture(GL_TEXTURE_2D, boundName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void allocate(GLenum format, GLsizei width, GLsizei height, GLenum dataFormat, GLenum dataType, const void * data)
|
||||
virtual void doDestroy(void)
|
||||
{
|
||||
GLW_ASSERT(this->isValid());
|
||||
glTexImage2D(this->m_target, 0, format, width, height, 0, dataFormat, dataType, data);
|
||||
this->m_format = format;
|
||||
this->m_width = width;
|
||||
this->m_height = height;
|
||||
BaseType::doDestroy();
|
||||
this->m_format = GL_NONE;
|
||||
this->m_width = 0;
|
||||
this->m_height = 0;
|
||||
}
|
||||
|
||||
virtual bool doIsValid(void) const
|
||||
{
|
||||
return ((this->m_format != GL_NONE) && (this->m_width > 0) && (this->m_height > 0));
|
||||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <Texture2D> Texture2DHandle;
|
||||
typedef detail::UnsafeHandle <Texture2D> BoundTexture2D;
|
||||
namespace detail { template <> struct BaseOf <Texture2D> { typedef Texture Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <Texture2D> ::Type Texture2DPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeTexture2D : public SafeTexture
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundTexture2D;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeTexture BaseType;
|
||||
typedef SafeTexture2D ThisType;
|
||||
|
||||
SafeTexture2D(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SafeTexture2D(const Texture2DPtr & texture2D)
|
||||
: BaseType(texture2D)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const Texture2DPtr & object(void) const
|
||||
{
|
||||
return static_cast<const Texture2DPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
Texture2DPtr & object(void)
|
||||
{
|
||||
return static_cast<Texture2DPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeTexture2D> { typedef SafeTexture Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeTexture2D> { typedef Texture2D Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <Texture2D > { typedef SafeTexture2D Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeTexture2D> ::Type Texture2DHandle;
|
||||
|
||||
class Texture2DBindingParams : public TextureBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef TextureBindingParams BaseType;
|
||||
typedef Texture2DBindingParams ThisType;
|
||||
|
||||
Texture2DBindingParams(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
Texture2DBindingParams(GLenum aUnit)
|
||||
: BaseType(GL_TEXTURE_2D, aUnit)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundTexture2D : public BoundTexture
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundTexture BaseType;
|
||||
typedef BoundTexture2D ThisType;
|
||||
|
||||
BoundTexture2D(void)
|
||||
: BaseType()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const Texture2DHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const Texture2DHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
Texture2DHandle & handle(void)
|
||||
{
|
||||
return static_cast<Texture2DHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundTexture2D(const Texture2DHandle & handle, const Texture2DBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const Texture2DPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
Texture2DPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundTexture2D> { typedef Texture2DBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundTexture2D> { typedef BoundObject Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundTexture2D> { typedef Texture2D Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <Texture2D > { typedef BoundTexture2D Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundTexture2D> ::Type BoundTexture2DHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_TEXTURE2D_H
|
||||
|
|
|
@ -283,6 +283,6 @@ inline ProgramHandle loadProgram(Context & ctx, const std::string & srcPrefix, c
|
|||
return loadProgram(ctx, srcPrefix, vertexFile, "", fragmentFile.c_str(), args);
|
||||
}
|
||||
|
||||
} // end namespace glw
|
||||
};
|
||||
|
||||
#endif // GLW_UTILITY_H
|
||||
|
|
|
@ -14,8 +14,9 @@ class VertexShaderArguments : public ShaderArguments
|
|||
typedef VertexShaderArguments ThisType;
|
||||
|
||||
VertexShaderArguments(void)
|
||||
: BaseType()
|
||||
{
|
||||
this->clear();
|
||||
;
|
||||
}
|
||||
|
||||
void clear(void)
|
||||
|
@ -24,33 +25,14 @@ class VertexShaderArguments : public ShaderArguments
|
|||
}
|
||||
};
|
||||
|
||||
class SafeVertexShader : public virtual SafeShader
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeVertexShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeVertexShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, BaseType (ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class VertexShader : public Shader, public SafeVertexShader
|
||||
class VertexShader : public Shader
|
||||
{
|
||||
friend class Context;
|
||||
friend class detail::SharedObjectBinding<VertexShader>;
|
||||
|
||||
public:
|
||||
|
||||
typedef Shader BaseType;
|
||||
typedef SafeVertexShader SafeType;
|
||||
typedef VertexShader ThisType;
|
||||
typedef Shader BaseType;
|
||||
typedef VertexShader ThisType;
|
||||
|
||||
virtual Type type(void) const
|
||||
{
|
||||
|
@ -60,10 +42,7 @@ class VertexShader : public Shader, public SafeVertexShader
|
|||
protected:
|
||||
|
||||
VertexShader(Context * ctx)
|
||||
: SafeObject (ctx)
|
||||
, SafeShader (ctx)
|
||||
, BaseType (ctx)
|
||||
, SafeType (ctx)
|
||||
: BaseType(ctx)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -79,9 +58,101 @@ class VertexShader : public Shader, public SafeVertexShader
|
|||
}
|
||||
};
|
||||
|
||||
typedef detail::SafeHandle <VertexShader> VertexShaderHandle;
|
||||
typedef detail::UnsafeHandle <VertexShader> BoundVertexShader;
|
||||
namespace detail { template <> struct BaseOf <VertexShader> { typedef Shader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <VertexShader> ::Type VertexShaderPtr;
|
||||
|
||||
} // end namespace glw
|
||||
class SafeVertexShader : public SafeShader
|
||||
{
|
||||
friend class Context;
|
||||
friend class BoundVertexShader;
|
||||
|
||||
public:
|
||||
|
||||
typedef SafeShader BaseType;
|
||||
typedef SafeVertexShader ThisType;
|
||||
|
||||
protected:
|
||||
|
||||
SafeVertexShader(const VertexShaderPtr & vertexShader)
|
||||
: BaseType(vertexShader)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const VertexShaderPtr & object(void) const
|
||||
{
|
||||
return static_cast<const VertexShaderPtr &>(BaseType::object());
|
||||
}
|
||||
|
||||
VertexShaderPtr & object(void)
|
||||
{
|
||||
return static_cast<VertexShaderPtr &>(BaseType::object());
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct BaseOf <SafeVertexShader> { typedef SafeShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <SafeVertexShader> { typedef VertexShader Type; }; };
|
||||
namespace detail { template <> struct ObjectSafe <VertexShader > { typedef SafeVertexShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <SafeVertexShader> ::Type VertexShaderHandle;
|
||||
|
||||
class VertexShaderBindingParams : public ShaderBindingParams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ShaderBindingParams BaseType;
|
||||
typedef VertexShaderBindingParams ThisType;
|
||||
|
||||
VertexShaderBindingParams(void)
|
||||
: BaseType(GL_VERTEX_SHADER, 0)
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class BoundVertexShader : public BoundShader
|
||||
{
|
||||
friend class Context;
|
||||
|
||||
public:
|
||||
|
||||
typedef BoundShader BaseType;
|
||||
typedef BoundVertexShader ThisType;
|
||||
|
||||
const VertexShaderHandle & handle(void) const
|
||||
{
|
||||
return static_cast<const VertexShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
VertexShaderHandle & handle(void)
|
||||
{
|
||||
return static_cast<VertexShaderHandle &>(BaseType::handle());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BoundVertexShader(const VertexShaderHandle & handle, const ShaderBindingParams & params)
|
||||
: BaseType(handle, params)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const VertexShaderPtr & object(void) const
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
|
||||
VertexShaderPtr & object(void)
|
||||
{
|
||||
return this->handle()->object();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail { template <> struct ParamsOf <BoundVertexShader> { typedef VertexShaderBindingParams Type; }; };
|
||||
namespace detail { template <> struct BaseOf <BoundVertexShader> { typedef BoundShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBase <BoundVertexShader> { typedef VertexShader Type; }; };
|
||||
namespace detail { template <> struct ObjectBound <VertexShader > { typedef BoundVertexShader Type; }; };
|
||||
typedef detail::ObjectSharedPointerTraits <BoundVertexShader> ::Type BoundVertexShaderHandle;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLW_VERTEXSHADER_H
|
||||
|
|
Loading…
Reference in New Issue