1 #ifndef __DALI_INTEGRATION_RESOURCE_TYPES_H__
2 #define __DALI_INTEGRATION_RESOURCE_TYPES_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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/images/image-attributes.h>
26 #include <dali/integration-api/resource-declarations.h>
37 * Extendable set of resource types
51 * The abstract base class for resource types.
53 struct DALI_IMPORT_API ResourceType
57 * @param[in] typeId resource type id
59 ResourceType(ResourceTypeId typeId)
65 virtual ~ResourceType() {}
68 * Create a copy of the resource type with the same attributes.
69 * @return pointer to the new ResourceType.
71 virtual ResourceType* Clone() const = 0;
73 const ResourceTypeId id;
77 // Undefined copy constructor.
78 ResourceType(const ResourceType& typePath);
80 // Undefined assignment operator.
81 ResourceType& operator=(const ResourceType& rhs);
85 * BitmapResourceType describes a bitmap resource, which can be requested
86 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
88 struct DALI_IMPORT_API BitmapResourceType : public ResourceType
92 * @param[in] attribs parameters for image loading request
94 BitmapResourceType(const ImageAttributes& attribs)
95 : ResourceType(ResourceBitmap),
96 imageAttributes(attribs) {}
101 virtual ~BitmapResourceType() {}
104 * @copydoc ResourceType::Clone
106 virtual ResourceType* Clone() const
108 return new BitmapResourceType(imageAttributes);
112 * Attributes are copied from the request.
114 ImageAttributes imageAttributes;
118 // Undefined copy constructor.
119 BitmapResourceType(const BitmapResourceType& typePath);
121 // Undefined assignment operator.
122 BitmapResourceType& operator=(const BitmapResourceType& rhs);
126 * NativeImageResourceType describes a native image resource, which can be injected
127 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
128 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
130 struct DALI_IMPORT_API NativeImageResourceType : public ResourceType
135 NativeImageResourceType()
136 : ResourceType(ResourceNativeImage) {}
140 * @param[in] attribs parameters for image loading request
142 NativeImageResourceType(const ImageAttributes& attribs)
143 : ResourceType(ResourceNativeImage),
144 imageAttributes(attribs) {}
149 virtual ~NativeImageResourceType() {}
152 * @copydoc ResourceType::Clone
154 virtual ResourceType* Clone() const
156 return new NativeImageResourceType(imageAttributes);
160 * Attributes are copied from the request (if supplied).
162 ImageAttributes imageAttributes;
166 // Undefined copy constructor.
167 NativeImageResourceType(const NativeImageResourceType& typePath);
169 // Undefined assignment operator.
170 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
174 * RenderTargetResourceType describes a bitmap resource, which can injected
175 * through ResourceManager::AddTargetImage()
177 struct DALI_IMPORT_API RenderTargetResourceType : public ResourceType
182 RenderTargetResourceType()
183 : ResourceType(ResourceTargetImage) {}
187 * @param[in] attribs parameters for image loading request
189 RenderTargetResourceType(const ImageAttributes& attribs)
190 : ResourceType(ResourceTargetImage),
191 imageAttributes(attribs) {}
196 virtual ~RenderTargetResourceType() {}
199 * @copydoc ResourceType::Clone
201 virtual ResourceType* Clone() const
203 return new RenderTargetResourceType(imageAttributes);
207 * Attributes are copied from the request.
209 ImageAttributes imageAttributes;
213 // Undefined copy constructor.
214 RenderTargetResourceType(const RenderTargetResourceType& typePath);
216 // Undefined assignment operator.
217 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
221 * ShaderResourceType describes a shader program resource, which can be requested
222 * from PlatformAbstraction::LoadResource()
224 struct DALI_IMPORT_API ShaderResourceType : public ResourceType
229 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
230 : ResourceType(ResourceShader),
232 vertexShader(vertexSource),
233 fragmentShader(fragmentSource)
240 virtual ~ShaderResourceType()
245 * @copydoc ResourceType::Clone
247 virtual ResourceType* Clone() const
249 return new ShaderResourceType(hash, vertexShader, fragmentShader);
252 public: // Attributes
253 size_t hash; ///< Hash of the vertex/fragment sources
254 const std::string vertexShader; ///< source code for vertex program
255 const std::string fragmentShader; ///< source code for fragment program
259 // Undefined copy constructor.
260 ShaderResourceType(const ShaderResourceType& typePath);
262 // Undefined assignment operator.
263 ShaderResourceType& operator=(const ShaderResourceType& rhs);
267 * TextResourceType describes a font resource, which can be requested.
268 * from PlatformAbstraction::LoadResource() No font atlas is created.
270 struct DALI_IMPORT_API TextResourceType : public ResourceType
277 TextQualityLow, ///< Request lower quality text
278 TextQualityHigh ///< Request higher quality text
282 * Structure for requesting character to be loaded from file with atlas position
283 * for automatic texture upload
287 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
296 /** \addtogroup GlyphPositionPackedWord
297 * We have 32 bits available for this data because of the alignment restrictions
298 * on the 32 bit words that follow so rather than using the minimum number of
299 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
300 * address to make access possible via a plain byte load instead of a load,
301 * mask, shift sequence. The naive bitwidths before this modification are as follows:
307 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
308 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
309 uint32_t loaded:8; ///< true if Loaded
312 uint32_t xPosition; ///< X Position in atlas
313 uint32_t yPosition; ///< Y Position in atlas
316 * Used by ResourceTypeCompare
318 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
321 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
325 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
326 GLYPH_CACHE_WRITE, ///< Caches glyphs.
330 * Text resource type constructor
331 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
332 * @param [in] style The font style
333 * @param [in] characterList The requested text as a vector or UTF-32 codes
334 * @param [in] textureAtlasId The resource ID of the texture atlas
335 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
336 * @param [in] maxGlyphSize The size of the largest glyph in the font.
337 * @param [in] cache Whether text glyph should be cached or not.
339 TextResourceType( const size_t hash,
340 const std::string& style,
341 const CharacterList& characterList,
342 ResourceId textureAtlasId,
343 TextQuality quality = TextQualityLow,
344 Vector2 maxGlyphSize = Vector2::ONE,
345 GlyphCacheMode cache = GLYPH_CACHE_READ )
346 : ResourceType(ResourceText),
349 mCharacterList(characterList),
350 mTextureAtlasId(textureAtlasId),
352 mMaxGlyphSize(maxGlyphSize),
360 virtual ~TextResourceType()
365 * @copydoc ResourceType::Clone
367 virtual ResourceType* Clone() const
369 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
373 * Font resource hash.
375 const size_t mFontHash;
380 const std::string mStyle;
383 * Displayed text (UTF-32 codes)
386 CharacterList mCharacterList; ///< List of characters
388 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
390 TextQuality mQuality; ///< Text quality setting
392 Vector2 mMaxGlyphSize; ///< Max glyph size for font
394 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
398 // Undefined copy constructor.
399 TextResourceType(const TextResourceType& typePath);
401 // Undefined copy constructor.
402 TextResourceType& operator=(const TextResourceType& rhs);
406 * ModelResourceType describes a model resource, which can be requested
407 * from PlatformAbstraction::LoadResource()
409 struct DALI_IMPORT_API ModelResourceType : public ResourceType
415 : ResourceType(ResourceModel)
422 virtual ~ModelResourceType()
427 * @copydoc ResourceType::Clone
429 virtual ResourceType* Clone() const
431 return new ModelResourceType();
436 // Undefined copy constructor.
437 ModelResourceType(const ModelResourceType& typePath);
439 // Undefined assignment operator.
440 ModelResourceType& operator=(const ModelResourceType& rhs);
445 * MeshResourceType describes a mesh program resource, which can be created
446 * using ResourceManager::AllocateMesh.
448 struct DALI_IMPORT_API MeshResourceType : public ResourceType
454 : ResourceType(ResourceMesh) {}
459 virtual ~MeshResourceType() {}
462 * @copydoc ResourceType::Clone
464 virtual ResourceType* Clone() const
466 return new MeshResourceType();
471 // Undefined copy constructor.
472 MeshResourceType(const MeshResourceType& typePath);
474 // Undefined assignment operator.
475 MeshResourceType& operator=(const MeshResourceType& rhs);
478 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
480 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
483 } // namespace Integration
487 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__