2012-04-30 20:23:53 +02:00
|
|
|
#ifndef GLW_TEXTURE_H
|
|
|
|
#define GLW_TEXTURE_H
|
|
|
|
|
|
|
|
#include "./renderable.h"
|
|
|
|
|
|
|
|
namespace glw
|
|
|
|
{
|
|
|
|
|
|
|
|
class TextureSampleMode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef void BaseType;
|
|
|
|
typedef TextureSampleMode ThisType;
|
|
|
|
|
|
|
|
GLenum minFilter;
|
|
|
|
GLenum magFilter;
|
|
|
|
GLenum wrapS;
|
|
|
|
GLenum wrapT;
|
|
|
|
GLenum wrapR;
|
|
|
|
|
|
|
|
TextureSampleMode(void)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureSampleMode(GLenum rMinFilter, GLenum rMagFilter, GLenum rWrapS, GLenum rWrapT, GLenum rWrapR)
|
|
|
|
: minFilter (rMinFilter)
|
|
|
|
, magFilter (rMagFilter)
|
|
|
|
, wrapS (rWrapS)
|
|
|
|
, wrapT (rWrapT)
|
|
|
|
, wrapR (rWrapR)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear(void)
|
|
|
|
{
|
|
|
|
this->minFilter = GLW_DONT_CARE;
|
|
|
|
this->magFilter = GLW_DONT_CARE;
|
|
|
|
this->wrapS = GLW_DONT_CARE;
|
|
|
|
this->wrapT = GLW_DONT_CARE;
|
|
|
|
this->wrapR = GLW_DONT_CARE;
|
|
|
|
}
|
2012-05-23 20:02:22 +02:00
|
|
|
|
|
|
|
static TextureSampleMode dontCare(void)
|
|
|
|
{
|
|
|
|
return ThisType();
|
|
|
|
}
|
|
|
|
|
|
|
|
static TextureSampleMode texelFetch(void)
|
|
|
|
{
|
|
|
|
return ThisType(GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2012-04-30 20:23:53 +02:00
|
|
|
};
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
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)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
|
|
|
return TextureSampleMode(minFilter, magFilter, wrapS, wrapT, wrapR);
|
|
|
|
}
|
|
|
|
|
|
|
|
class TextureArguments : public RenderableArguments
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef RenderableArguments BaseType;
|
|
|
|
typedef TextureArguments ThisType;
|
|
|
|
|
|
|
|
TextureArguments(void)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear(void)
|
|
|
|
{
|
|
|
|
BaseType::clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
class Texture : public Renderable
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
2012-05-07 15:18:05 +02:00
|
|
|
friend class Context;
|
|
|
|
|
2012-04-30 20:23:53 +02:00
|
|
|
public:
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
typedef Renderable BaseType;
|
|
|
|
typedef Texture ThisType;
|
|
|
|
|
|
|
|
virtual ~Texture(void)
|
|
|
|
{
|
|
|
|
this->destroy();
|
|
|
|
}
|
2012-04-30 20:23:53 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
Texture(Context * ctx)
|
|
|
|
: BaseType(ctx)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
2012-05-07 15:18:05 +02:00
|
|
|
|
|
|
|
virtual void doDestroy(void)
|
|
|
|
{
|
|
|
|
glDeleteTextures(1, &(this->m_name));
|
|
|
|
}
|
2012-04-30 20:23:53 +02:00
|
|
|
};
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
namespace detail { template <> struct BaseOf <Texture> { typedef Renderable Type; }; };
|
|
|
|
typedef detail::ObjectSharedPointerTraits <Texture> ::Type TexturePtr;
|
|
|
|
|
|
|
|
class SafeTexture : public SafeRenderable
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
2012-05-07 15:18:05 +02:00
|
|
|
friend class Context;
|
|
|
|
friend class BoundTexture;
|
|
|
|
|
2012-04-30 20:23:53 +02:00
|
|
|
public:
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
typedef SafeRenderable BaseType;
|
|
|
|
typedef SafeTexture ThisType;
|
|
|
|
|
|
|
|
SafeTexture(void)
|
|
|
|
: BaseType()
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
2012-04-30 20:23:53 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
SafeTexture(const TexturePtr & texture)
|
|
|
|
: BaseType(texture)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
const TexturePtr & object(void) const
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
2012-05-07 15:18:05 +02:00
|
|
|
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();
|
2012-04-30 20:23:53 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
TexturePtr & object(void)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
2012-05-07 15:18:05 +02:00
|
|
|
return this->handle()->object();
|
2012-04-30 20:23:53 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
virtual void bind(void)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + this->m_unit);
|
2012-05-07 15:18:05 +02:00
|
|
|
glBindTexture(this->m_target, this->object()->name());
|
2012-04-30 20:23:53 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
virtual void unbind(void)
|
2012-04-30 20:23:53 +02:00
|
|
|
{
|
|
|
|
glActiveTexture(GL_TEXTURE0 + this->m_unit);
|
|
|
|
glBindTexture(this->m_target, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-07 15:18:05 +02:00
|
|
|
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;
|
2012-04-30 20:23:53 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GLW_TEXTURE_H
|