1 #ifndef __DALI_ATLAS_H__
2 #define __DALI_ATLAS_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/images/buffer-image.h>
32 namespace Internal DALI_INTERNAL
38 * @brief An Atlas is a large image containing multiple smaller images.
40 * Buffer image and resource image( by providing the url ) are supported for uploading.
41 * Images must be uploaded at a specified position, to populate the Atlas.
42 * The client is responsible for generating the appropriate geometry (UV coordinates) needed to draw images within the Atlas.
44 * For context recovery after loss:
45 * By default, the atlas will re-upload the resource images automatically,
46 * while the buffer images are left to the client to upload again by connecting to the Stage::ContextRegainedSignal().
47 * If resource and buffer images are mixed and they overlap inside the atlas, the recovered contents may be incorrect.
48 * In these case, switch off the context recovery by calling SetContextRecovery( false ),
49 * and upload both buffer images and resource image to the atlas in order to restore the atlas.
51 class DALI_IMPORT_API Atlas : public Image
55 typedef uint32_t SizeType;
60 * @brief Create a new Atlas.
62 * @pre width & height are greater than zero.
63 * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
64 * @param [in] width The atlas width in pixels.
65 * @param [in] height The atlas height in pixels.
66 * @param [in] pixelFormat The pixel format (rgba 32 bit by default).
67 * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context( true by default )
68 * @return A handle to a new Atlas.
70 static Atlas New( SizeType width,
72 Pixel::Format pixelFormat = Pixel::RGBA8888,
73 bool recoverContext = true );
76 * @brief Create an empty handle.
78 * Calling member functions of an empty handle is not allowed.
83 * @brief Clear the Atlas with the given color
85 * @note The Atlas does not clear itself automatically during construction.
86 * Application should call this clear function to avoid getting garbage pixels in the atlas.
87 * By calling Clear, all the current uploaded image information will be lost.
88 * @param [in] color The color used to clear the Atlas.
90 void Clear( const Vector4& color );
93 * @brief Upload a buffer image to the atlas.
95 * @pre The pixel format of this buffer image must match the Atlas format.
96 * @param [in] bufferImage The buffer image to upload.
97 * @param [in] xOffset Specifies an offset in the x direction within the atlas.
98 * @param [in] yOffset Specifies an offset in the y direction within the atlas.
99 * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
101 bool Upload( BufferImage bufferImage,
106 * @brief Upload a resource image to atlas
108 * @param [in] url The URL of the resource image file to use
109 * @param [in] xOffset Specifies an offset in the x direction within the atlas.
110 * @param [in] yOffset Specifies an offset in the y direction within the atlas.
111 * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
113 bool Upload( const std::string& url,
117 * @brief Downcast an Object handle to Atlas.
119 * If handle points to a Atlas the downcast produces valid
120 * handle. If not the returned handle is left uninitialized.
122 * @param[in] handle to An object
123 * @return handle to a Atlas or an empty handle
125 static Atlas DownCast( BaseHandle handle );
130 * This is non-virtual since derived Handle types must not contain data or virtual methods.
135 * @brief This copy constructor is required for (smart) pointer semantics.
137 * @param [in] handle A reference to the copied handle
139 Atlas( const Atlas& handle );
142 * @brief This assignment operator is required for (smart) pointer semantics.
144 * @param [in] rhs A reference to the copied handle
145 * @return A reference to this
147 Atlas& operator=( const Atlas& rhs);
149 public: // Not intended for application developers
151 explicit DALI_INTERNAL Atlas( Internal::Atlas* );
156 #endif // __DALI_ATLAS_H__