47de0dc4d97500ad5bc852b7fd917d3a4ca0ec88
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / vertex-buffer-impl.h
1 #ifndef DALI_INTERNAL_VERTEX_BUFFER_H
2 #define DALI_INTERNAL_VERTEX_BUFFER_H
3
4 /*
5  * Copyright (c) 2020 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-map.h> // Dali::Property::Map
26 #include <dali/internal/event/common/event-thread-services.h>
27 #include <dali/internal/render/renderers/render-vertex-buffer.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33
34 class VertexBuffer;
35 using VertexBufferPtr = IntrusivePtr<VertexBuffer>;
36
37 /**
38  * VertexBuffer is an object that contains an array of structures of values that
39  * can be accessed as properties.
40  */
41 class VertexBuffer : public BaseObject
42 {
43 public:
44
45   /**
46    * @copydoc PropertBuffer::New()
47    */
48   static VertexBufferPtr New( Dali::Property::Map& format );
49
50   /**
51    * @copydoc PropertBuffer::SetData()
52    */
53   void SetData( const void* data, uint32_t size );
54
55   /**
56    * @copydoc PropertBuffer::GetSize()
57    */
58   uint32_t GetSize() const;
59
60 public: // Default property extensions from Object
61
62   /**
63    * @brief Get the render thread side of the VertexBuffer
64    *
65    * @return The render thread side of this VertexBuffer
66    */
67   const Render::VertexBuffer* GetRenderObject() const;
68
69 protected:
70   /**
71    * @brief Destructor
72    */
73   ~VertexBuffer();
74
75 private: // implementation
76   /**
77    * @brief Default constructor
78    */
79   VertexBuffer();
80
81   /**
82    * Second stage initialization
83    */
84   void Initialize( Dali::Property::Map& format );
85
86 private: // unimplemented methods
87   VertexBuffer( const VertexBuffer& );
88   VertexBuffer& operator=( const VertexBuffer& );
89
90 private: // data
91   EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
92   Render::VertexBuffer* mRenderObject;        ///<Render side object
93   uint32_t mBufferFormatSize;
94   uint32_t mSize; ///< Number of elements in the buffer
95 };
96
97 /**
98  * Get the implementation type from a Property::Type
99  */
100 template<Property::Type type> struct PropertyImplementationType
101 {
102   // typedef ... Type; not defined, only support types declared below
103 };
104 template<>
105 struct PropertyImplementationType<Property::BOOLEAN>
106 {
107   using Type = bool;
108 };
109 template<>
110 struct PropertyImplementationType<Property::FLOAT>
111 {
112   using Type = float;
113 };
114 template<>
115 struct PropertyImplementationType<Property::INTEGER>
116 {
117   using Type = int;
118 };
119 template<>
120 struct PropertyImplementationType<Property::VECTOR2>
121 {
122   using Type = Vector2;
123 };
124 template<>
125 struct PropertyImplementationType<Property::VECTOR3>
126 {
127   using Type = Vector3;
128 };
129 template<>
130 struct PropertyImplementationType<Property::VECTOR4>
131 {
132   using Type = Vector4;
133 };
134 template<>
135 struct PropertyImplementationType<Property::MATRIX3>
136 {
137   using Type = Matrix3;
138 };
139 template<>
140 struct PropertyImplementationType<Property::MATRIX>
141 {
142   using Type = Matrix;
143 };
144 template<>
145 struct PropertyImplementationType<Property::RECTANGLE>
146 {
147   using Type = Rect<int>;
148 };
149 template<>
150 struct PropertyImplementationType<Property::ROTATION>
151 {
152   using Type = Quaternion;
153 };
154
155 uint32_t GetPropertyImplementationSize( Property::Type& propertyType );
156
157 } // namespace Internal
158
159 // Helpers for public-api forwarding methods
160 inline Internal::VertexBuffer& GetImplementation(Dali::VertexBuffer& handle)
161 {
162   DALI_ASSERT_ALWAYS(handle && "VertexBuffer handle is empty");
163
164   BaseObject& object = handle.GetBaseObject();
165
166   return static_cast<Internal::VertexBuffer&>(object);
167 }
168
169 inline const Internal::VertexBuffer& GetImplementation(const Dali::VertexBuffer& handle)
170 {
171   DALI_ASSERT_ALWAYS(handle && "VertexBuffer handle is empty");
172
173   const BaseObject& object = handle.GetBaseObject();
174
175   return static_cast<const Internal::VertexBuffer&>(object);
176 }
177
178 } // namespace Dali
179
180 #endif // DALI_INTERNAL_VERTEX_BUFFER_H