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>
28 #include <dali/devel-api/images/pixel-data.h>
33 namespace Internal DALI_INTERNAL
39 * @brief An Atlas is a large image containing multiple smaller images.
41 * Buffer image and resource image( by providing the url ) are supported for uploading.
42 * Images must be uploaded at a specified position, to populate the Atlas.
43 * The client is responsible for generating the appropriate geometry (UV coordinates) needed to draw images within the Atlas.
45 * @note For gles 2.0, matched pixel format is demanded to ensure the correct atlasing.
46 * The only exception supported is uploading image of RGB888 to atlas of RGBA8888 format which is converted manually before pushing to GPU.
48 * For context recovery after loss:
49 * By default, the atlas will re-upload the resource images automatically,
50 * while the buffer images are left to the client to upload again by connecting to the Stage::ContextRegainedSignal().
51 * If resource and buffer images are mixed and they overlap inside the atlas, the recovered contents may be incorrect.
52 * In these case, switch off the context recovery by calling SetContextRecovery( false ),
53 * and upload both buffer images and resource image to the atlas in order to restore the atlas.
55 class DALI_IMPORT_API Atlas : public Image
59 typedef uint32_t SizeType;
64 * @brief Create a new Atlas.
66 * @pre width & height are greater than zero.
67 * The maximum size of the atlas is limited by GL_MAX_TEXTURE_SIZE.
68 * @param [in] width The atlas width in pixels.
69 * @param [in] height The atlas height in pixels.
70 * @param [in] pixelFormat The pixel format (rgba 32 bit by default).
71 * @param [in] recoverContext Whether re-uploading the resource images automatically when regaining the context( true by default )
72 * @return A handle to a new Atlas.
74 static Atlas New( SizeType width,
76 Pixel::Format pixelFormat = Pixel::RGBA8888,
77 bool recoverContext = true );
80 * @brief Create an empty handle.
82 * Calling member functions of an empty handle is not allowed.
87 * @brief Clear the Atlas with the given color
89 * @note The Atlas does not clear itself automatically during construction.
90 * Application should call this clear function to avoid getting garbage pixels in the atlas.
91 * By calling Clear, all the current uploaded image information will be lost.
92 * @param [in] color The color used to clear the Atlas.
94 void Clear( const Vector4& color );
97 * @brief Upload a buffer image to the atlas.
99 * @pre The pixel format of this buffer image must match the Atlas format.
100 * @param [in] bufferImage The buffer image to upload.
101 * @param [in] xOffset Specifies an offset in the x direction within the atlas.
102 * @param [in] yOffset Specifies an offset in the y direction within the atlas.
103 * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
105 bool Upload( BufferImage bufferImage,
110 * @brief Upload a resource image to atlas
112 * @param [in] url The URL of the resource image file to use
113 * @param [in] xOffset Specifies an offset in the x direction within the atlas.
114 * @param [in] yOffset Specifies an offset in the y direction within the atlas.
115 * @return True if the image has compatible pixel format and fits within the atlas at the specified offset.
117 bool Upload( const std::string& url,
122 * @brief Upload a pixel buffer to atlas
124 * @param [in] pixelData The pixel data.
125 * @param [in] xOffset Specifies an offset in the x direction within the atlas.
126 * @param [in] yOffset Specifies an offset in the y direction within the atlas.
128 bool Upload( PixelData pixelData,
132 * @brief Downcast an Object handle to Atlas.
134 * If handle points to a Atlas the downcast produces valid
135 * handle. If not the returned handle is left uninitialized.
137 * @param[in] handle to An object
138 * @return handle to a Atlas or an empty handle
140 static Atlas DownCast( BaseHandle handle );
145 * This is non-virtual since derived Handle types must not contain data or virtual methods.
150 * @brief This copy constructor is required for (smart) pointer semantics.
152 * @param [in] handle A reference to the copied handle
154 Atlas( const Atlas& handle );
157 * @brief This assignment operator is required for (smart) pointer semantics.
159 * @param [in] rhs A reference to the copied handle
160 * @return A reference to this
162 Atlas& operator=( const Atlas& rhs);
164 public: // Not intended for application developers
166 explicit DALI_INTERNAL Atlas( Internal::Atlas* );
171 #endif // __DALI_ATLAS_H__