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