(PropertyOwner) Distinguish between disconnection & destruction
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / uniform-meta.h
1 #ifndef __DALI_INTERNAL_UNIFORM_META_H__
2 #define __DALI_INTERNAL_UNIFORM_META_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property.h>
26 #include <dali/public-api/shader-effects/shader-effect.h>
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/common/event-to-update.h>
29 #include <dali/internal/render/shaders/shader.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class PropertyBase;
41
42 /**
43  * Holds the metadata associated with a Shader uniform.
44  */
45 class UniformMeta
46 {
47 public:
48
49   typedef Dali::ShaderEffect::UniformCoordinateType CoordinateType;
50
51   /**
52    * Create a UniformMeta.
53    */
54   static UniformMeta* New( const std::string& name, const PropertyBase& property, CoordinateType coordType )
55   {
56     return new UniformMeta( name, property, coordType );
57   }
58
59   /**
60    * Copy constructor
61    * @param [in] meta The UniformMeta to copy.
62    */
63   UniformMeta( const UniformMeta& meta )
64   : name( meta.name ),
65     property( meta.property ),
66     coordinateType( meta.coordinateType )
67   {
68     memcpy( cacheIndeces, meta.cacheIndeces, sizeof(cacheIndeces) );
69   }
70
71   /**
72    * Set the coordinate type.
73    * @param [in] coordType The new coordinate type.
74    */
75   void SetCoordinateType( CoordinateType coordType )
76   {
77     coordinateType = coordType;
78   }
79
80 private:
81
82   /**
83    * Constructor
84    */
85   UniformMeta( const std::string& uniformName, const PropertyBase& prop, CoordinateType coordType )
86   : name( uniformName ),
87     property( prop ),
88     coordinateType( coordType )
89   {
90     memset( cacheIndeces, 0, sizeof(cacheIndeces) );
91   }
92
93   // Undefined
94   UniformMeta& operator=( const UniformMeta& rhs );
95
96 public:
97
98   std::string name; ///< name of uniform to set/animate
99
100   const PropertyBase& property; ///< reference to the corresponding property
101
102   unsigned int cacheIndeces[ Log<GEOMETRY_TYPE_LAST>::value ][ SHADER_SUBTYPE_LAST ]; ///< internal program cache index, per program
103
104   CoordinateType coordinateType; ///< The coordinate type of the uniform
105 };
106
107 // Messages for UniformMeta
108
109 }; // namespace SceneGraph
110
111 // value types used by messages
112 template <> struct ParameterType< SceneGraph::UniformMeta::CoordinateType >
113 : public BasicType< SceneGraph::UniformMeta::CoordinateType > {};
114
115 namespace SceneGraph
116 {
117
118 inline void SetCoordinateTypeMessage( EventToUpdate& eventToUpdate, const UniformMeta& meta, UniformMeta::CoordinateType type )
119 {
120   typedef MessageValue1< UniformMeta, UniformMeta::CoordinateType > LocalType;
121
122   // Reserve some memory inside the message queue
123   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
124
125   // Construct message in the message queue memory; note that delete should not be called on the return value
126   new (slot) LocalType( &meta, &UniformMeta::SetCoordinateType, type );
127 }
128
129 } // namespace SceneGraph
130
131 /**
132  * Used for accessing uniform metadata by property index
133  */
134 typedef std::map<Property::Index, const SceneGraph::UniformMeta*> CustomUniformMetaLookup;
135
136 } // namespace Internal
137
138 } // namespace Dali
139
140 #endif // __DALI_INTERNAL_UNIFORM_META_H__
141