Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | List of all members
jop::TextureAtlas Class Reference

#include <TextureAtlas.hpp>

Inheritance diagram for jop::TextureAtlas:
jop::Resource jop::SafeReferenceable< Resource > jop::SerializeInfo jop::AnimationAtlas

Public Types

enum  LoadMode { LoadMode::Separate, LoadMode::Sheet, LoadMode::TextureOnly }
 Load mode. More...
 

Public Member Functions

 TextureAtlas (const std::string &name)
 Constructor. More...
 
 ~TextureAtlas () override
 Destructor. More...
 
bool load (const glm::uvec2 &atlasSize)
 Load an empty atlas. More...
 
template<typename... Args>
bool load (const glm::uvec2 &atlasSize, const Args &...args)
 Load this atlas. More...
 
bool load (const std::string &path, const LoadMode mode)
 Load from JSON file. More...
 
void destroy ()
 Destroy this atlas. More...
 
unsigned int addTexture (const Image &image)
 Add texture from image to the atlas. More...
 
unsigned int addTexture (const Texture2D &texture)
 Add texture to the atlas. More...
 
unsigned int addTexture (const std::string &texturePath)
 Add texture from file to atlas. More...
 
unsigned int defineTexture (const glm::vec2 &start, const glm::vec2 &end)
 Define a texture. More...
 
std::pair< glm::vec2, glm::vec2 > getCoordinates (const unsigned int index) const
 Get texture location inside atlas. More...
 
unsigned int getTextureAmount () const
 Get amount of textures inside atlas. More...
 
const Texture2DgetTexture () const
 Get the texture of atlas. More...
 
- Public Member Functions inherited from jop::Resource
 Resource (const std::string &name)
 Constructor. More...
 
virtual ~Resource ()=0
 Virtual destructor. More...
 
const std::string & getName () const
 Get the name of this resource. More...
 
void setPersistence (const unsigned short level)
 Set the persistence level. More...
 
unsigned short getPersistence () const
 Get the persistence level. More...
 
- Public Member Functions inherited from jop::SafeReferenceable< Resource >
WeakReference< ResourcegetReference () const
 Get a weak reference to the bound object. More...
 
- Public Member Functions inherited from jop::SerializeInfo
 SerializeInfo ()
 
void setSerializePackage (const uint16 package)
 
uint16 getSerializePackage () const
 
void setShouldSerialize (const bool set)
 
bool shouldSerialize () const
 
void setLightSerializeable (const bool set)
 
bool isLightSerializeable () const
 

Additional Inherited Members

- Protected Member Functions inherited from jop::Resource
 Resource (const Resource &other, const std::string &newName)
 Copy constructor. More...
 
- Protected Member Functions inherited from jop::SafeReferenceable< Resource >
 SafeReferenceable (Resource *ref)
 Constructor. More...
 
 SafeReferenceable (SafeReferenceable< Resource > &&other)
 Move constructor. More...
 
SafeReferenceableoperator= (SafeReferenceable< Resource > &&other)
 Move assignment operator. More...
 
 ~SafeReferenceable ()
 Protected destructor. More...
 

Detailed Description

Definition at line 42 of file TextureAtlas.hpp.

Member Enumeration Documentation

Load mode.

Enumerator
Separate 

Load from separate textures.

Sheet 

Use if you have a complete sheet (inside a single texture)

TextureOnly 

Only load the texture.

Definition at line 47 of file TextureAtlas.hpp.

Constructor & Destructor Documentation

jop::TextureAtlas::TextureAtlas ( const std::string &  name)

Constructor.

Parameters
nameName for the resource
jop::TextureAtlas::~TextureAtlas ( )
override

Destructor.

Member Function Documentation

unsigned int jop::TextureAtlas::addTexture ( const Image image)

Add texture from image to the atlas.

Parameters
imageImage to be added
Returns
The texture index
unsigned int jop::TextureAtlas::addTexture ( const Texture2D texture)

Add texture to the atlas.

Parameters
textureTexture to be added
Returns
The texture index
unsigned int jop::TextureAtlas::addTexture ( const std::string &  texturePath)

Add texture from file to atlas.

Parameters
texturePathPath to the texture in file
Returns
The texture index
unsigned int jop::TextureAtlas::defineTexture ( const glm::vec2 &  start,
const glm::vec2 &  end 
)

Define a texture.

Adds a texture to memory with given dimension. This call must not be mixed with addTexture().

Parameters
startThe start coordinates
endThe end coordinates
Returns
The texture index
void jop::TextureAtlas::destroy ( )

Destroy this atlas.

Called implicitly by all load methods.

std::pair<glm::vec2, glm::vec2> jop::TextureAtlas::getCoordinates ( const unsigned int  index) const

Get texture location inside atlas.

Parameters
indexIndex of the texture
Returns
The texture coordinates. First = min, second = max
const Texture2D& jop::TextureAtlas::getTexture ( ) const

Get the texture of atlas.

If no textures have been added to atlas default texture will be returned.

Returns
Reference to the internal atlas texture
unsigned int jop::TextureAtlas::getTextureAmount ( ) const

Get amount of textures inside atlas.

Returns
The amount of textures inside atlas
bool jop::TextureAtlas::load ( const glm::uvec2 &  atlasSize)

Load an empty atlas.

Parameters
atlasSizeSize of the atlas to be created
Returns
True if successful
template<typename... Args>
bool jop::TextureAtlas::load ( const glm::uvec2 &  atlasSize,
const Args &...  args 
)

Load this atlas.

Loads this atlas of given size and with variable amount of given Images, Texture2D's or file paths using addTexture() for each argument.

Parameters
atlasSizeSize of the atlas to be created
argsVariable amount of Texture2D's, Images or file paths
Returns
True if successful
bool jop::TextureAtlas::load ( const std::string &  path,
const LoadMode  mode 
)

Load from JSON file.

Parameters
pathPath to the JSON file
modeLoad mode

Information about the JSON formats.

Returns
True if successful

The documentation for this class was generated from the following file: