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.
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/images/image-attributes.h>
29 #include <dali/integration-api/resource-declarations.h>
40 * Extendable set of resource types
54 * The abstract base class for resource types.
60 * @param[in] typeId resource type id
62 ResourceType(ResourceTypeId typeId)
68 virtual ~ResourceType() {}
71 * Create a copy of the resource type with the same attributes.
72 * @return pointer to the new ResourceType.
74 virtual ResourceType* Clone() const = 0;
76 const ResourceTypeId id;
80 // Undefined copy constructor.
81 ResourceType(const ResourceType& typePath);
83 // Undefined assignment operator.
84 ResourceType& operator=(const ResourceType& rhs);
88 * BitmapResourceType describes a bitmap resource, which can be requested
89 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
91 struct BitmapResourceType : public ResourceType
95 * @param[in] attribs parameters for image loading request
97 BitmapResourceType(const ImageAttributes& attribs)
98 : ResourceType(ResourceBitmap),
99 imageAttributes(attribs) {}
104 virtual ~BitmapResourceType() {}
107 * @copydoc ResourceType::Clone
109 virtual ResourceType* Clone() const
111 return new BitmapResourceType(imageAttributes);
115 * Attributes are copied from the request.
117 ImageAttributes imageAttributes;
121 // Undefined copy constructor.
122 BitmapResourceType(const BitmapResourceType& typePath);
124 // Undefined assignment operator.
125 BitmapResourceType& operator=(const BitmapResourceType& rhs);
129 * NativeImageResourceType describes a native image resource, which can be injected
130 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
131 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
133 struct NativeImageResourceType : public ResourceType
138 NativeImageResourceType()
139 : ResourceType(ResourceNativeImage) {}
143 * @param[in] attribs parameters for image loading request
145 NativeImageResourceType(const ImageAttributes& attribs)
146 : ResourceType(ResourceNativeImage),
147 imageAttributes(attribs) {}
152 virtual ~NativeImageResourceType() {}
155 * @copydoc ResourceType::Clone
157 virtual ResourceType* Clone() const
159 return new NativeImageResourceType(imageAttributes);
163 * Attributes are copied from the request (if supplied).
165 ImageAttributes imageAttributes;
169 // Undefined copy constructor.
170 NativeImageResourceType(const NativeImageResourceType& typePath);
172 // Undefined assignment operator.
173 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
177 * RenderTargetResourceType describes a bitmap resource, which can injected
178 * through ResourceManager::AddTargetImage()
180 struct RenderTargetResourceType : public ResourceType
185 RenderTargetResourceType()
186 : ResourceType(ResourceTargetImage) {}
190 * @param[in] attribs parameters for image loading request
192 RenderTargetResourceType(const ImageAttributes& attribs)
193 : ResourceType(ResourceTargetImage),
194 imageAttributes(attribs) {}
199 virtual ~RenderTargetResourceType() {}
202 * @copydoc ResourceType::Clone
204 virtual ResourceType* Clone() const
206 return new RenderTargetResourceType(imageAttributes);
210 * Attributes are copied from the request.
212 ImageAttributes imageAttributes;
216 // Undefined copy constructor.
217 RenderTargetResourceType(const RenderTargetResourceType& typePath);
219 // Undefined assignment operator.
220 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
224 * ShaderResourceType describes a shader program resource, which can be requested
225 * from PlatformAbstraction::LoadResource()
227 struct ShaderResourceType : public ResourceType
232 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
233 : ResourceType(ResourceShader),
235 vertexShader(vertexSource),
236 fragmentShader(fragmentSource)
243 virtual ~ShaderResourceType()
248 * @copydoc ResourceType::Clone
250 virtual ResourceType* Clone() const
252 return new ShaderResourceType(hash, vertexShader, fragmentShader);
255 public: // Attributes
256 size_t hash; ///< Hash of the vertex/fragment sources
257 const std::string vertexShader; ///< source code for vertex program
258 const std::string fragmentShader; ///< source code for fragment program
262 // Undefined copy constructor.
263 ShaderResourceType(const ShaderResourceType& typePath);
265 // Undefined assignment operator.
266 ShaderResourceType& operator=(const ShaderResourceType& rhs);
270 * TextResourceType describes a font resource, which can be requested.
271 * from PlatformAbstraction::LoadResource() No font atlas is created.
273 struct TextResourceType : public ResourceType
280 TextQualityLow, ///< Request lower quality text
281 TextQualityHigh ///< Request higher quality text
285 * Structure for requesting character to be loaded from file with atlas position
286 * for automatic texture upload
290 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
299 /** \addtogroup GlyphPositionPackedWord
300 * We have 32 bits available for this data because of the alignment restrictions
301 * on the 32 bit words that follow so rather than using the minimum number of
302 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
303 * address to make access possible via a plain byte load instead of a load,
304 * mask, shift sequence. The naive bitwidths before this modification are as follows:
310 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
311 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
312 uint32_t loaded:8; ///< true if Loaded
315 uint32_t xPosition; ///< X Position in atlas
316 uint32_t yPosition; ///< Y Position in atlas
319 * Used by ResourceTypeCompare
321 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
324 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
328 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
329 GLYPH_CACHE_WRITE, ///< Caches glyphs.
333 * Text resource type constructor
334 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
335 * @param [in] style The font style
336 * @param [in] characterList The requested text as a vector or UTF-32 codes
337 * @param [in] textureAtlasId The resource ID of the texture atlas
338 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
339 * @param [in] maxGlyphSize The size of the largest glyph in the font.
340 * @param [in] cache Whether text glyph should be cached or not.
342 TextResourceType( const size_t hash,
343 const std::string& style,
344 const CharacterList& characterList,
345 ResourceId textureAtlasId,
346 TextQuality quality = TextQualityLow,
347 Vector2 maxGlyphSize = Vector2::ONE,
348 GlyphCacheMode cache = GLYPH_CACHE_READ )
349 : ResourceType(ResourceText),
352 mCharacterList(characterList),
353 mTextureAtlasId(textureAtlasId),
355 mMaxGlyphSize(maxGlyphSize),
363 virtual ~TextResourceType()
368 * @copydoc ResourceType::Clone
370 virtual ResourceType* Clone() const
372 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
376 * Font resource hash.
378 const size_t mFontHash;
383 const std::string mStyle;
386 * Displayed text (UTF-32 codes)
389 CharacterList mCharacterList; ///< List of characters
391 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
393 TextQuality mQuality; ///< Text quality setting
395 Vector2 mMaxGlyphSize; ///< Max glyph size for font
397 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
401 // Undefined copy constructor.
402 TextResourceType(const TextResourceType& typePath);
404 // Undefined copy constructor.
405 TextResourceType& operator=(const TextResourceType& rhs);
409 * ModelResourceType describes a model resource, which can be requested
410 * from PlatformAbstraction::LoadResource()
412 struct ModelResourceType : public ResourceType
418 : ResourceType(ResourceModel)
425 virtual ~ModelResourceType()
430 * @copydoc ResourceType::Clone
432 virtual ResourceType* Clone() const
434 return new ModelResourceType();
439 // Undefined copy constructor.
440 ModelResourceType(const ModelResourceType& typePath);
442 // Undefined assignment operator.
443 ModelResourceType& operator=(const ModelResourceType& rhs);
448 * MeshResourceType describes a mesh program resource, which can be created
449 * using ResourceManager::AllocateMesh.
451 struct MeshResourceType : public ResourceType
457 : ResourceType(ResourceMesh) {}
462 virtual ~MeshResourceType() {}
465 * @copydoc ResourceType::Clone
467 virtual ResourceType* Clone() const
469 return new MeshResourceType();
474 // Undefined copy constructor.
475 MeshResourceType(const MeshResourceType& typePath);
477 // Undefined assignment operator.
478 MeshResourceType& operator=(const MeshResourceType& rhs);
481 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
483 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
486 } // namespace Integration
490 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__