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