} // namespace Internal
-/**
- * AtlasManager
- * ------------
- *
- * Creates and manages additions and removals of images from Texture Atlases
- *
- * The AtlasManager will match pixeltype and optimal block use to determine
- * the appropriate atlas to upload an image to.
- *
- * A policy can be specified to determine the action the AtlasManager will carry
- * out, should it not be able to add an image. This can return an error, or create
- * a new atlas of pre-determined dimensions to accomodate the new image.
- *
- * Images are referenced by an ImageId once they have been successfully uploaded.
- *
- * Once an image has been successfully uploaded, Geometry can be generated by passing
- * the ImageId to the GenerateMeshData method and geometry can be consolidated via
- * the StitchMesh method.
- *
- * Images are reference counted once mesh data has been generated. An image is removed
- * from the Atlas via the Remove( ImageId ) method. This unreferences the image and only
- * physically removes it from the atlas once all references have been freed.
- *
- * If the AddPolicy is set to generate and error if an image can't be uploaded, then it
- * is the applications responsibility to deal with the situation. An error will be indicated
- * with an ImageId of 0.
- *
- * Examples using the AtlasManager
- *
- * Create or obtain the AtlasManager
- * @code
- *
- * AtlasManager manager = AtlasManager::Get();
- *
- * @endcode
- *
- * Set the AtlasManager AddPolicy
- *
- * @code
- *
- * // Tell the atlas manager to create a new atlas, if it needs to
- * manager.SetAddPolicy( FAIL_ON_ADD_CREATES );
- *
- * // Tell the atlas manager to return an error, if it can't add an image
- * manager.SetAddPolicy( FAIL_ON_ADD_FAILS );
- *
- * @endcode
- *
- * Simple add and removal of BufferImage to and from an atlas
- *
- * @code
- *
- * // Structure returned by AtlasManager operations
- * AtlasSlot slot;
- *
- * // Add image to an atlas ( will be created if none suitable exists )
- * manager.Add( bitmapImage, slot );
- *
- * // slot.mImage returns the imageId for the bitmap, slot.mAtlas indicates the atlasId
- * // that the image was added to. The imageId is used to communicate with the AtlasManager
- * uint32_t imageId = slot.mImage;
- * if ( !imageId )
- * {
- * // Addition has failed.....
- * }
- * ...
- * ...
- * // Done with image, so remove from atlas, if not being used elsewhere
- * manager.Remove( imageId );
- *
- * @endcode
- *
- * Create a Specific Atlas for adding BufferImages to
- *
- * @code
- *
- * // Create an RGB888 atlas of 2048x2848, with a blocksize of 128x128
- * uint32_t atlas = manager.CreateAtlas( 2048u, 2048u, 128u, 128u, Pixel::RGB888 );
- *
- * // Add an image to a preferred atlas ( note not specifying atlas may still result
- * // in the bitmap being added to the atlas above )
- * manager.Add( bitmapImage, slot, atlas );
- *
- * @endcode
- *
- * Create Geometry for a previously added image
- *
- * @code
- *
- * // Top left corner of geometry to be generated
- * Vector2 position( 1.0f, 1.0f );
- *
- * // Geometry will end up here!
- * MeshData meshData;
- * manager.GenerateMeshData( imageId, position, meshData );
- *
- * @endcode
- *
- * Generating Geometry from multiple images in the same atlas
- *
- * @code
- *
- * MeshData firstMesh;
- * MeshData secondMesh;
- * manager.GenerateMeshData( imageid_1, position_1, firstMesh );
- * manager.GenerateMeshData( imageid_2, position_2, secondMesh );
- *
- * // Combine the two meshes. Passing MESH_OPTIMIZE as an optional third parameter will remove duplicate vertices
- * manager.StitchMesh( first, second );
- *
- * @endcode
- *
- */
-
class AtlasManager : public BaseHandle
{
public:
typedef uint32_t SizeType;
typedef SizeType AtlasId;
typedef SizeType ImageId;
- static const bool MESH_OPTIMIZE = true;
struct AtlasSize
{
struct Vertex2D
{
- Vector2 mPosition;
- Vector2 mTexCoords;
+ Vector2 mPosition; ///< Vertex posiiton
+ Vector2 mTexCoords; ///< Vertex texture co-ordinates
};
struct Mesh2D
{
- Vector< Vertex2D > mVertices;
- Vector< unsigned int> mIndices;
+ Vector< Vertex2D > mVertices; ///< container of vertices
+ Vector< SizeType > mIndices; ///< container of indices
};
/**
* @param[in] image reference to a bitmapimage
* @param[out] slot result of add operation
* @param[in] atlas optional preferred atlas
+ *
+ * @return true if a new atlas was created
*/
- void Add( const BufferImage& image,
+ bool Add( const BufferImage& image,
AtlasSlot& slot,
AtlasId atlas = 0 );
bool addReference = true );
/**
- * @brief Append second mesh to the first mesh
- *
- * @param[in] first First mesh
- * @param[in] second Second mesh
- * @param[in] optimize should we optimize vertex data
- */
- void StitchMesh( Mesh2D& first,
- const Mesh2D& second,
- bool optimize = false );
-
- /**
* @brief Get the BufferImage containing an atlas
*
* @param[in] atlas AtlasId returned when atlas was created
/**
* @brief Get Material used by atlas
*
- * @param atlas[in] atlas AtlasId
+ * @param[in] atlas AtlasId
*
* @return Material used by atlas
*/
Material GetMaterial( AtlasId atlas ) const;
- /**
- * @brief Get Image used by atlas
- *
- * @param atlas[in] atlas AtlasId
+ /**
+ * @brief Set the material used by an atlas
*
- * @return Sampler used by atlas
+ * @param[in] atlas AtlasId
+ * @param[in] material The Material to assign
*/
- Image GetImage( AtlasId atlas ) const;
+ void SetMaterial( AtlasId atlas, Material& material );
+
private:
explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);