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 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/vector-wrapper.h>
26 #include <dali/public-api/images/image-attributes.h>
27 #include <dali/integration-api/resource-declarations.h>
38 * Extendable set of resource types
52 * The abstract base class for resource types.
54 struct DALI_IMPORT_API ResourceType
58 * @param[in] typeId resource type id
60 ResourceType(ResourceTypeId typeId)
66 virtual ~ResourceType() {}
69 * Create a copy of the resource type with the same attributes.
70 * @return pointer to the new ResourceType.
72 virtual ResourceType* Clone() const = 0;
74 const ResourceTypeId id;
78 // Undefined copy constructor.
79 ResourceType(const ResourceType& typePath);
81 // Undefined assignment operator.
82 ResourceType& operator=(const ResourceType& rhs);
86 * BitmapResourceType describes a bitmap resource, which can be requested
87 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
89 struct DALI_IMPORT_API BitmapResourceType : public ResourceType
93 * @param[in] attribs parameters for image loading request
95 BitmapResourceType(const ImageAttributes& attribs)
96 : ResourceType(ResourceBitmap),
97 imageAttributes(attribs) {}
102 virtual ~BitmapResourceType() {}
105 * @copydoc ResourceType::Clone
107 virtual ResourceType* Clone() const
109 return new BitmapResourceType(imageAttributes);
113 * Attributes are copied from the request.
115 ImageAttributes imageAttributes;
119 // Undefined copy constructor.
120 BitmapResourceType(const BitmapResourceType& typePath);
122 // Undefined assignment operator.
123 BitmapResourceType& operator=(const BitmapResourceType& rhs);
127 * NativeImageResourceType describes a native image resource, which can be injected
128 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
129 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
131 struct DALI_IMPORT_API NativeImageResourceType : public ResourceType
136 NativeImageResourceType()
137 : ResourceType(ResourceNativeImage) {}
141 * @param[in] attribs parameters for image loading request
143 NativeImageResourceType(const ImageAttributes& attribs)
144 : ResourceType(ResourceNativeImage),
145 imageAttributes(attribs) {}
150 virtual ~NativeImageResourceType() {}
153 * @copydoc ResourceType::Clone
155 virtual ResourceType* Clone() const
157 return new NativeImageResourceType(imageAttributes);
161 * Attributes are copied from the request (if supplied).
163 ImageAttributes imageAttributes;
167 // Undefined copy constructor.
168 NativeImageResourceType(const NativeImageResourceType& typePath);
170 // Undefined assignment operator.
171 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
175 * RenderTargetResourceType describes a bitmap resource, which can injected
176 * through ResourceManager::AddTargetImage()
178 struct DALI_IMPORT_API RenderTargetResourceType : public ResourceType
183 RenderTargetResourceType()
184 : ResourceType(ResourceTargetImage) {}
188 * @param[in] attribs parameters for image loading request
190 RenderTargetResourceType(const ImageAttributes& attribs)
191 : ResourceType(ResourceTargetImage),
192 imageAttributes(attribs) {}
197 virtual ~RenderTargetResourceType() {}
200 * @copydoc ResourceType::Clone
202 virtual ResourceType* Clone() const
204 return new RenderTargetResourceType(imageAttributes);
208 * Attributes are copied from the request.
210 ImageAttributes imageAttributes;
214 // Undefined copy constructor.
215 RenderTargetResourceType(const RenderTargetResourceType& typePath);
217 // Undefined assignment operator.
218 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
222 * ShaderResourceType describes a shader program resource, which can be requested
223 * from PlatformAbstraction::LoadResource()
225 struct DALI_IMPORT_API ShaderResourceType : public ResourceType
230 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
231 : ResourceType(ResourceShader),
233 vertexShader(vertexSource),
234 fragmentShader(fragmentSource)
241 virtual ~ShaderResourceType()
246 * @copydoc ResourceType::Clone
248 virtual ResourceType* Clone() const
250 return new ShaderResourceType(hash, vertexShader, fragmentShader);
253 public: // Attributes
254 size_t hash; ///< Hash of the vertex/fragment sources
255 const std::string vertexShader; ///< source code for vertex program
256 const std::string fragmentShader; ///< source code for fragment program
260 // Undefined copy constructor.
261 ShaderResourceType(const ShaderResourceType& typePath);
263 // Undefined assignment operator.
264 ShaderResourceType& operator=(const ShaderResourceType& rhs);
268 * TextResourceType describes a font resource, which can be requested.
269 * from PlatformAbstraction::LoadResource() No font atlas is created.
271 struct DALI_IMPORT_API TextResourceType : public ResourceType
278 TextQualityLow, ///< Request lower quality text
279 TextQualityHigh ///< Request higher quality text
283 * Structure for requesting character to be loaded from file with atlas position
284 * for automatic texture upload
288 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
297 /** \addtogroup GlyphPositionPackedWord
298 * We have 32 bits available for this data because of the alignment restrictions
299 * on the 32 bit words that follow so rather than using the minimum number of
300 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
301 * address to make access possible via a plain byte load instead of a load,
302 * mask, shift sequence. The naive bitwidths before this modification are as follows:
308 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
309 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
310 uint32_t loaded:8; ///< true if Loaded
313 uint32_t xPosition; ///< X Position in atlas
314 uint32_t yPosition; ///< Y Position in atlas
317 * Used by ResourceTypeCompare
319 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
322 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
326 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
327 GLYPH_CACHE_WRITE, ///< Caches glyphs.
331 * Text resource type constructor
332 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
333 * @param [in] style The font style
334 * @param [in] characterList The requested text as a vector or UTF-32 codes
335 * @param [in] textureAtlasId The resource ID of the texture atlas
336 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
337 * @param [in] maxGlyphSize The size of the largest glyph in the font.
338 * @param [in] cache Whether text glyph should be cached or not.
340 TextResourceType( const size_t hash,
341 const std::string& style,
342 const CharacterList& characterList,
343 ResourceId textureAtlasId,
344 TextQuality quality = TextQualityLow,
345 Vector2 maxGlyphSize = Vector2::ONE,
346 GlyphCacheMode cache = GLYPH_CACHE_READ )
347 : ResourceType(ResourceText),
350 mCharacterList(characterList),
351 mTextureAtlasId(textureAtlasId),
353 mMaxGlyphSize(maxGlyphSize),
361 virtual ~TextResourceType()
366 * @copydoc ResourceType::Clone
368 virtual ResourceType* Clone() const
370 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
374 * Font resource hash.
376 const size_t mFontHash;
381 const std::string mStyle;
384 * Displayed text (UTF-32 codes)
387 CharacterList mCharacterList; ///< List of characters
389 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
391 TextQuality mQuality; ///< Text quality setting
393 Vector2 mMaxGlyphSize; ///< Max glyph size for font
395 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
399 // Undefined copy constructor.
400 TextResourceType(const TextResourceType& typePath);
402 // Undefined copy constructor.
403 TextResourceType& operator=(const TextResourceType& rhs);
407 * ModelResourceType describes a model resource, which can be requested
408 * from PlatformAbstraction::LoadResource()
410 struct DALI_IMPORT_API ModelResourceType : public ResourceType
416 : ResourceType(ResourceModel)
423 virtual ~ModelResourceType()
428 * @copydoc ResourceType::Clone
430 virtual ResourceType* Clone() const
432 return new ModelResourceType();
437 // Undefined copy constructor.
438 ModelResourceType(const ModelResourceType& typePath);
440 // Undefined assignment operator.
441 ModelResourceType& operator=(const ModelResourceType& rhs);
446 * MeshResourceType describes a mesh program resource, which can be created
447 * using ResourceManager::AllocateMesh.
449 struct DALI_IMPORT_API MeshResourceType : public ResourceType
455 : ResourceType(ResourceMesh) {}
460 virtual ~MeshResourceType() {}
463 * @copydoc ResourceType::Clone
465 virtual ResourceType* Clone() const
467 return new MeshResourceType();
472 // Undefined copy constructor.
473 MeshResourceType(const MeshResourceType& typePath);
475 // Undefined assignment operator.
476 MeshResourceType& operator=(const MeshResourceType& rhs);
479 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
481 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
484 } // namespace Integration
488 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__