Merge "Remove scene graph property buffer" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-property-buffer.h
1 #ifndef DALI_INTERNAL_RENDER_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_RENDER_PROPERTY_BUFFER_H
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/internal/common/owner-pointer.h>
20 #include <dali/public-api/actors/sampling.h>
21 #include <dali/devel-api/rendering/sampler.h>
22 #include <dali/internal/render/renderers/render-sampler.h>
23 #include <dali/internal/render/gl-resources/gpu-buffer.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Render
30 {
31
32 class PropertyBuffer
33 {
34 public:
35
36   struct Component
37   {
38     std::string     name;
39     unsigned int    offset;
40     unsigned int    size;
41     Property::Type  type;
42   };
43
44   /**
45    * Structure that holds the meta-data of the format of PropertyBuffer.
46    */
47   struct Format
48   {
49     std::vector<Component> components;
50     unsigned int           size;
51   };
52
53   /**
54    * @brief Default constructor
55    */
56   PropertyBuffer();
57
58   /**
59    * @brief Destructor
60    */
61   ~PropertyBuffer();
62
63   /**
64    * @brief Set the format of the buffer
65    *
66    * This function takes ownership of the pointer
67    *
68    * @param[in] format The format for the PropertyBuffer
69    */
70   void SetFormat( PropertyBuffer::Format* format );
71
72   /**
73    * @brief Set the data of the PropertyBuffer
74    *
75    * This function takes ownership of the pointer
76    * @param[in] data The new data of the PropertyBuffer
77    */
78   void SetData( Dali::Vector<char>* data );
79
80   /**
81    * @brief Set the number of elements
82    * @param[in] size The number of elements
83    */
84   void SetSize( unsigned int size );
85
86   /**
87    * @brief Bind the property buffer
88    * @param[in] target The binding point
89    */
90   void BindBuffer(GpuBuffer::Target target);
91
92   /**
93    * Perform the upload of the buffer only when requiered
94    * @param[in] context The GL context
95    * @param[in] isIndexBuffer True if the buffer is used as an index buffer
96    */
97   bool Update( Context& context, bool isIndexBuffer );
98
99   /**
100    * Enable the vertex attributes for each vertex buffer from the corresponding
101    * shader program.
102    * @param[in] context The GL context
103    * @param[in] vAttributeLocation Vector containing attributes location for current program
104    * @param[in] locationBase Index in vAttributeLocation corresponding to the first attribute defined by this buffer
105    */
106   unsigned int EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase );
107
108   /**
109    * Get the number of attributes present in the buffer
110    * @return The number of attributes stored in this buffer
111    */
112   inline unsigned int GetAttributeCount() const
113   {
114     DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
115     return mFormat->components.size();
116   }
117
118   /**
119    * Retrieve the i-essim attribute name
120    * @param[in] index The index of the attribute
121    * @return The name of the attribute
122    */
123   inline const std::string& GetAttributeName(unsigned int index ) const
124   {
125     DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
126     return mFormat->components[index].name;
127   }
128
129   /**
130    * Retrieve the size of the buffer in bytes
131    * @return The total size of the buffer
132    */
133   inline std::size_t GetDataSize() const
134   {
135     DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
136     return mFormat->size * mSize;
137   }
138
139   /**
140    * Retrieve the size of one element of the buffer
141    * @return The size of one element
142    */
143   inline std::size_t GetElementSize() const
144   {
145     DALI_ASSERT_DEBUG( mFormat && "Format should be set ");
146     return mFormat->size;
147   }
148
149   /**
150    * Retrieve the number of elements in the buffer
151    * @return The total number of elements
152    */
153   inline unsigned int GetElementCount() const
154   {
155     return mSize;
156   }
157
158 private:
159   OwnerPointer< PropertyBuffer::Format >  mFormat;  ///< Format of the buffer
160   OwnerPointer< Dali::Vector< char > >    mData;    ///< Data
161   OwnerPointer<GpuBuffer> mGpuBuffer;               ///< Pointer to the GpuBuffer associated with this RenderPropertyBuffer
162
163   size_t  mSize;      ///< Number of Elements in the buffer
164   bool mDataChanged;  ///< Flag to know if data has changed in a frame
165
166 };
167
168 } // namespace Render
169
170
171
172 } // namespace Internal
173 } // namespace Dali
174
175
176 #endif //  DALI_INTERNAL_RENDER_PROPERTY_BUFFER_H