9 #ifndef _CU_TEXTURE_H__
10 #define _CU_TEXTURE_H__
12 #include "../math/CUMathBase.h"
13 #include "../math/CUSize.h"
30 class Texture :
public std::enable_shared_from_this<Texture> {
86 std::shared_ptr<Texture> _parent;
104 #pragma mark Constructors
159 bool initWithData(
const void *data,
int width,
int height,
182 #pragma mark Static Constructors
198 static std::shared_ptr<Texture>
alloc(
int width,
int height,
200 std::shared_ptr<Texture> result = std::make_shared<Texture>();
220 static std::shared_ptr<Texture>
allocWithData(
const void *data,
int width,
int height,
222 std::shared_ptr<Texture> result = std::make_shared<Texture>();
245 static std::shared_ptr<Texture>
allocWithFile(
const std::string& filename) {
246 std::shared_ptr<Texture> result = std::make_shared<Texture>();
247 return (result->initWithFile(filename) ? result :
nullptr);
283 #pragma mark Attributes
303 return (_parent !=
nullptr ? _parent->isActive() : _active);
315 return (_parent !=
nullptr ? _parent->hasMipMaps() : _hasMipmaps);
344 void setName(std::string name) { _name = name; }
354 const std::string&
getName()
const {
return _name; }
396 return (_parent !=
nullptr ? _parent->getMinFilter() : _minFilter);
408 return (_parent !=
nullptr ? _parent->getMagFilter() : _magFilter);
439 return (_parent !=
nullptr ? _parent->getWrapS() : _wrapS);
450 return (_parent !=
nullptr ? _parent->getWrapT() : _wrapT);
469 #pragma mark Atlas Support
477 const std::shared_ptr<Texture>&
getParent()
const {
return _parent; }
486 std::shared_ptr<Texture>
getParent() {
return _parent; }
507 std::shared_ptr<Texture>
getSubTexture(GLfloat minS, GLfloat maxS, GLfloat minT, GLfloat maxT);
561 #pragma mark Rendering
577 #pragma mark Conversions
588 std::string
toString(
bool verbose =
false)
const;
591 operator std::string()
const {
return toString(); }
void setMagFilter(GLuint magFilter)
GLfloat getMinS() const
Definition: CUTexture.h:526
bool initWithData(const void *data, int width, int height, PixelFormat format=PixelFormat::RGBA)
GLfloat getMaxS() const
Definition: CUTexture.h:546
const Texture & set(const void *data)
std::shared_ptr< Texture > getParent()
Definition: CUTexture.h:486
const Texture & operator=(const void *data)
Definition: CUTexture.h:264
GLuint getMinFilter() const
Definition: CUTexture.h:395
std::string toString(bool verbose=false) const
GLuint getWrapT() const
Definition: CUTexture.h:449
bool isSubTexture() const
Definition: CUTexture.h:516
bool isReady() const
Definition: CUTexture.h:289
bool init(int width, int height, PixelFormat format=PixelFormat::RGBA)
GLfloat getMinT() const
Definition: CUTexture.h:536
void setWrapT(GLuint wrap)
unsigned int getWidth() const
Definition: CUTexture.h:361
GLuint getBuffer()
Definition: CUTexture.h:334
static std::shared_ptr< Texture > allocWithData(const void *data, int width, int height, PixelFormat format=PixelFormat::RGBA)
Definition: CUTexture.h:220
PixelFormat getFormat() const
Definition: CUTexture.h:385
static std::shared_ptr< Texture > allocWithFile(const std::string &filename)
Definition: CUTexture.h:245
bool hasMipMaps() const
Definition: CUTexture.h:314
~Texture()
Definition: CUTexture.h:117
void setMinFilter(GLuint minFilter)
unsigned int getHeight() const
Definition: CUTexture.h:368
GLfloat getMaxT() const
Definition: CUTexture.h:556
GLuint getMagFilter() const
Definition: CUTexture.h:407
GLuint getWrapS() const
Definition: CUTexture.h:438
Definition: CUTexture.h:30
Size getSize()
Definition: CUTexture.h:375
bool isActive() const
Definition: CUTexture.h:302
void setWrapS(GLuint wrap)
const std::string & getName() const
Definition: CUTexture.h:354
PixelFormat
Definition: CUTexture.h:40
std::shared_ptr< Texture > getSubTexture(GLfloat minS, GLfloat maxS, GLfloat minT, GLfloat maxT)
const std::shared_ptr< Texture > & getParent() const
Definition: CUTexture.h:477
Definition: CUAnimationNode.h:52
static std::shared_ptr< Texture > alloc(int width, int height, PixelFormat format=PixelFormat::RGBA)
Definition: CUTexture.h:198
void setName(std::string name)
Definition: CUTexture.h:344
bool initWithFile(const std::string &filename)