33 #ifndef _CU_TEXTURE_H__
34 #define _CU_TEXTURE_H__
36 #include <cugl/math/CUMathBase.h>
37 #include <cugl/math/CUSize.h>
54 class Texture :
public std::enable_shared_from_this<Texture> {
110 std::shared_ptr<Texture> _parent;
128 #pragma mark Constructors
183 bool initWithData(
const void *data,
int width,
int height,
206 #pragma mark Static Constructors
222 static std::shared_ptr<Texture>
alloc(
int width,
int height,
224 std::shared_ptr<Texture> result = std::make_shared<Texture>();
244 static std::shared_ptr<Texture>
allocWithData(
const void *data,
int width,
int height,
246 std::shared_ptr<Texture> result = std::make_shared<Texture>();
269 static std::shared_ptr<Texture>
allocWithFile(
const std::string& filename) {
270 std::shared_ptr<Texture> result = std::make_shared<Texture>();
271 return (result->initWithFile(filename) ? result :
nullptr);
307 #pragma mark Attributes
327 return (_parent !=
nullptr ? _parent->isActive() : _active);
339 return (_parent !=
nullptr ? _parent->hasMipMaps() : _hasMipmaps);
368 void setName(std::string name) { _name = name; }
378 const std::string&
getName()
const {
return _name; }
420 return (_parent !=
nullptr ? _parent->getMinFilter() : _minFilter);
432 return (_parent !=
nullptr ? _parent->getMagFilter() : _magFilter);
463 return (_parent !=
nullptr ? _parent->getWrapS() : _wrapS);
474 return (_parent !=
nullptr ? _parent->getWrapT() : _wrapT);
493 #pragma mark Atlas Support
501 const std::shared_ptr<Texture>&
getParent()
const {
return _parent; }
510 std::shared_ptr<Texture>
getParent() {
return _parent; }
531 std::shared_ptr<Texture>
getSubTexture(GLfloat minS, GLfloat maxS, GLfloat minT, GLfloat maxT);
585 #pragma mark Rendering
601 #pragma mark Conversions
612 std::string
toString(
bool verbose =
false)
const;
615 operator std::string()
const {
return toString(); }
void setMagFilter(GLuint magFilter)
GLfloat getMinS() const
Definition: CUTexture.h:550
bool initWithData(const void *data, int width, int height, PixelFormat format=PixelFormat::RGBA)
GLfloat getMaxS() const
Definition: CUTexture.h:570
const Texture & set(const void *data)
std::shared_ptr< Texture > getParent()
Definition: CUTexture.h:510
const Texture & operator=(const void *data)
Definition: CUTexture.h:288
GLuint getMinFilter() const
Definition: CUTexture.h:419
std::string toString(bool verbose=false) const
GLuint getWrapT() const
Definition: CUTexture.h:473
bool isSubTexture() const
Definition: CUTexture.h:540
bool isReady() const
Definition: CUTexture.h:313
bool init(int width, int height, PixelFormat format=PixelFormat::RGBA)
GLfloat getMinT() const
Definition: CUTexture.h:560
void setWrapT(GLuint wrap)
unsigned int getWidth() const
Definition: CUTexture.h:385
GLuint getBuffer()
Definition: CUTexture.h:358
static std::shared_ptr< Texture > allocWithData(const void *data, int width, int height, PixelFormat format=PixelFormat::RGBA)
Definition: CUTexture.h:244
PixelFormat getFormat() const
Definition: CUTexture.h:409
static std::shared_ptr< Texture > allocWithFile(const std::string &filename)
Definition: CUTexture.h:269
bool hasMipMaps() const
Definition: CUTexture.h:338
~Texture()
Definition: CUTexture.h:141
void setMinFilter(GLuint minFilter)
unsigned int getHeight() const
Definition: CUTexture.h:392
GLfloat getMaxT() const
Definition: CUTexture.h:580
GLuint getMagFilter() const
Definition: CUTexture.h:431
GLuint getWrapS() const
Definition: CUTexture.h:462
Definition: CUTexture.h:54
Size getSize()
Definition: CUTexture.h:399
bool isActive() const
Definition: CUTexture.h:326
void setWrapS(GLuint wrap)
const std::string & getName() const
Definition: CUTexture.h:378
PixelFormat
Definition: CUTexture.h:64
std::shared_ptr< Texture > getSubTexture(GLfloat minS, GLfloat maxS, GLfloat minT, GLfloat maxT)
const std::shared_ptr< Texture > & getParent() const
Definition: CUTexture.h:501
Definition: CUAction.h:51
static std::shared_ptr< Texture > alloc(int width, int height, PixelFormat format=PixelFormat::RGBA)
Definition: CUTexture.h:222
void setName(std::string name)
Definition: CUTexture.h:368
bool initWithFile(const std::string &filename)