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.
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/images/image-attributes.h>
26 #include <dali/integration-api/resource-declarations.h>
41 * Extendable set of resource types
55 * The abstract base class for resource types.
61 * @param[in] typeId resource type id
63 ResourceType(ResourceTypeId typeId)
69 virtual ~ResourceType() {}
72 * Create a copy of the resource type with the same attributes.
73 * @return pointer to the new ResourceType.
75 virtual ResourceType* Clone() const = 0;
77 const ResourceTypeId id;
81 // Undefined copy constructor.
82 ResourceType(const ResourceType& typePath);
84 // Undefined assignment operator.
85 ResourceType& operator=(const ResourceType& rhs);
89 * BitmapResourceType describes a bitmap resource, which can be requested
90 * from ResourceLoader::LoadResource() or AllocateBitmapImage.
92 struct BitmapResourceType : public ResourceType
96 * @param[in] attribs parameters for image loading request
98 BitmapResourceType(const ImageAttributes& attribs)
99 : ResourceType(ResourceBitmap),
100 imageAttributes(attribs) {}
105 virtual ~BitmapResourceType() {}
108 * @copydoc ResourceType::Clone
110 virtual ResourceType* Clone() const
112 return new BitmapResourceType(imageAttributes);
116 * Attributes are copied from the request.
118 ImageAttributes imageAttributes;
122 // Undefined copy constructor.
123 BitmapResourceType(const BitmapResourceType& typePath);
125 // Undefined assignment operator.
126 BitmapResourceType& operator=(const BitmapResourceType& rhs);
130 * NativeImageResourceType describes a native image resource, which can be injected
131 * through ResourceManager::AddNativeImage() or requested through ResourceLoader::LoadResource().
132 * If the adaptor does not support NativeImages, it can fall back to Bitmap type.
134 struct NativeImageResourceType : public ResourceType
139 NativeImageResourceType()
140 : ResourceType(ResourceNativeImage) {}
144 * @param[in] attribs parameters for image loading request
146 NativeImageResourceType(const ImageAttributes& attribs)
147 : ResourceType(ResourceNativeImage),
148 imageAttributes(attribs) {}
153 virtual ~NativeImageResourceType() {}
156 * @copydoc ResourceType::Clone
158 virtual ResourceType* Clone() const
160 return new NativeImageResourceType(imageAttributes);
164 * Attributes are copied from the request (if supplied).
166 ImageAttributes imageAttributes;
170 // Undefined copy constructor.
171 NativeImageResourceType(const NativeImageResourceType& typePath);
173 // Undefined assignment operator.
174 NativeImageResourceType& operator=(const NativeImageResourceType& rhs);
178 * RenderTargetResourceType describes a bitmap resource, which can injected
179 * through ResourceManager::AddTargetImage()
181 struct RenderTargetResourceType : public ResourceType
186 RenderTargetResourceType()
187 : ResourceType(ResourceTargetImage) {}
191 * @param[in] attribs parameters for image loading request
193 RenderTargetResourceType(const ImageAttributes& attribs)
194 : ResourceType(ResourceTargetImage),
195 imageAttributes(attribs) {}
200 virtual ~RenderTargetResourceType() {}
203 * @copydoc ResourceType::Clone
205 virtual ResourceType* Clone() const
207 return new RenderTargetResourceType(imageAttributes);
211 * Attributes are copied from the request.
213 ImageAttributes imageAttributes;
217 // Undefined copy constructor.
218 RenderTargetResourceType(const RenderTargetResourceType& typePath);
220 // Undefined assignment operator.
221 RenderTargetResourceType& operator=(const RenderTargetResourceType& rhs);
225 * ShaderResourceType describes a shader program resource, which can be requested
226 * from PlatformAbstraction::LoadResource()
228 struct ShaderResourceType : public ResourceType
233 ShaderResourceType(size_t shaderHash, const std::string& vertexSource, const std::string& fragmentSource)
234 : ResourceType(ResourceShader),
236 vertexShader(vertexSource),
237 fragmentShader(fragmentSource)
244 virtual ~ShaderResourceType()
249 * @copydoc ResourceType::Clone
251 virtual ResourceType* Clone() const
253 return new ShaderResourceType(hash, vertexShader, fragmentShader);
256 public: // Attributes
257 size_t hash; ///< Hash of the vertex/fragment sources
258 const std::string vertexShader; ///< source code for vertex program
259 const std::string fragmentShader; ///< source code for fragment program
263 // Undefined copy constructor.
264 ShaderResourceType(const ShaderResourceType& typePath);
266 // Undefined assignment operator.
267 ShaderResourceType& operator=(const ShaderResourceType& rhs);
271 * TextResourceType describes a font resource, which can be requested.
272 * from PlatformAbstraction::LoadResource() No font atlas is created.
274 struct TextResourceType : public ResourceType
281 TextQualityLow, ///< Request lower quality text
282 TextQualityHigh ///< Request higher quality text
286 * Structure for requesting character to be loaded from file with atlas position
287 * for automatic texture upload
291 GlyphPosition(unsigned int chr, unsigned int xPos, unsigned int yPos)
300 /** \addtogroup GlyphPositionPackedWord
301 * We have 32 bits available for this data because of the alignment restrictions
302 * on the 32 bit words that follow so rather than using the minimum number of
303 * bits for each, we give "loaded" a whole 8 bits and push it to a byte-aligned
304 * address to make access possible via a plain byte load instead of a load,
305 * mask, shift sequence. The naive bitwidths before this modification are as follows:
311 uint32_t character:21; ///< character code (UTF-32), max value of 0x10ffff (21 bits)
312 uint32_t quality:3; ///< Loaded quality 0 = low quality, 1 = high quality
313 uint32_t loaded:8; ///< true if Loaded
316 uint32_t xPosition; ///< X Position in atlas
317 uint32_t yPosition; ///< Y Position in atlas
320 * Used by ResourceTypeCompare
322 friend bool operator==(const GlyphPosition& lhs, const GlyphPosition& rhs);
325 typedef std::vector< GlyphPosition > CharacterList; ///< List of glyphs requested
329 GLYPH_CACHE_READ, ///< Doesn't cache glyphs.
330 GLYPH_CACHE_WRITE, ///< Caches glyphs.
334 * Text resource type constructor
335 * @param [in] hash The resourceHash for the FontAtlas and FontMetrics
336 * @param [in] style The font style
337 * @param [in] characterList The requested text as a vector or UTF-32 codes
338 * @param [in] textureAtlasId The resource ID of the texture atlas
339 * @param [in] quality A boolean, set to true to request high quality glyph bitmaps.
340 * @param [in] maxGlyphSize The size of the largest glyph in the font.
341 * @param [in] cache Whether text glyph should be cached or not.
343 TextResourceType( const size_t hash,
344 const std::string& style,
345 const CharacterList& characterList,
346 ResourceId textureAtlasId,
347 TextQuality quality = TextQualityLow,
348 Vector2 maxGlyphSize = Vector2::ONE,
349 GlyphCacheMode cache = GLYPH_CACHE_READ )
350 : ResourceType(ResourceText),
353 mCharacterList(characterList),
354 mTextureAtlasId(textureAtlasId),
356 mMaxGlyphSize(maxGlyphSize),
364 virtual ~TextResourceType()
369 * @copydoc ResourceType::Clone
371 virtual ResourceType* Clone() const
373 return new TextResourceType(mFontHash, mStyle, mCharacterList, mTextureAtlasId, mQuality, mMaxGlyphSize, mCache);
377 * Font resource hash.
379 const size_t mFontHash;
384 const std::string mStyle;
387 * Displayed text (UTF-32 codes)
390 CharacterList mCharacterList; ///< List of characters
392 ResourceId mTextureAtlasId; ///< Resource ID of the texture atlas this request is for
394 TextQuality mQuality; ///< Text quality setting
396 Vector2 mMaxGlyphSize; ///< Max glyph size for font
398 GlyphCacheMode mCache; ///< Whether text glyphs should be cached.
402 // Undefined copy constructor.
403 TextResourceType(const TextResourceType& typePath);
405 // Undefined copy constructor.
406 TextResourceType& operator=(const TextResourceType& rhs);
410 * ModelResourceType describes a model resource, which can be requested
411 * from PlatformAbstraction::LoadResource()
413 struct ModelResourceType : public ResourceType
419 : ResourceType(ResourceModel)
426 virtual ~ModelResourceType()
431 * @copydoc ResourceType::Clone
433 virtual ResourceType* Clone() const
435 return new ModelResourceType();
440 // Undefined copy constructor.
441 ModelResourceType(const ModelResourceType& typePath);
443 // Undefined assignment operator.
444 ModelResourceType& operator=(const ModelResourceType& rhs);
449 * MeshResourceType describes a mesh program resource, which can be created
450 * using ResourceManager::AllocateMesh.
452 struct MeshResourceType : public ResourceType
458 : ResourceType(ResourceMesh) {}
463 virtual ~MeshResourceType() {}
466 * @copydoc ResourceType::Clone
468 virtual ResourceType* Clone() const
470 return new MeshResourceType();
475 // Undefined copy constructor.
476 MeshResourceType(const MeshResourceType& typePath);
478 // Undefined assignment operator.
479 MeshResourceType& operator=(const MeshResourceType& rhs);
482 inline bool operator==(const TextResourceType::GlyphPosition& lhs, const TextResourceType::GlyphPosition& rhs)
484 return lhs.character == rhs.character && lhs.xPosition == rhs.xPosition && lhs.yPosition == rhs.yPosition && lhs.quality == rhs.quality;
487 } // namespace Integration
491 #endif // __DALI_INTEGRATION_RESOURCE_TYPES_H__