Removing some uses of gl Context object
[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/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 PropertBuffer::New()
48    */
49   static VertexBufferPtr New(Dali::Property::Map& format);
50
51   /**
52    * @copydoc PropertBuffer::SetData()
53    */
54   void SetData(const void* data, uint32_t size);
55
56   /**
57    * @copydoc PropertBuffer::GetSize()
58    */
59   uint32_t GetSize() const;
60
61 public: // Default property extensions from Object
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() override;
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>
101 struct PropertyImplementationType
102 {
103   // typedef ... Type; not defined, only support types declared below
104 };
105 template<>
106 struct PropertyImplementationType<Property::BOOLEAN>
107 {
108   using Type = bool;
109 };
110 template<>
111 struct PropertyImplementationType<Property::FLOAT>
112 {
113   using Type = float;
114 };
115 template<>
116 struct PropertyImplementationType<Property::INTEGER>
117 {
118   using Type = int;
119 };
120 template<>
121 struct PropertyImplementationType<Property::VECTOR2>
122 {
123   using Type = Vector2;
124 };
125 template<>
126 struct PropertyImplementationType<Property::VECTOR3>
127 {
128   using Type = Vector3;
129 };
130 template<>
131 struct PropertyImplementationType<Property::VECTOR4>
132 {
133   using Type = Vector4;
134 };
135 template<>
136 struct PropertyImplementationType<Property::MATRIX3>
137 {
138   using Type = Matrix3;
139 };
140 template<>
141 struct PropertyImplementationType<Property::MATRIX>
142 {
143   using Type = Matrix;
144 };
145 template<>
146 struct PropertyImplementationType<Property::RECTANGLE>
147 {
148   using Type = Rect<int>;
149 };
150 template<>
151 struct PropertyImplementationType<Property::ROTATION>
152 {
153   using Type = Quaternion;
154 };
155
156 uint32_t GetPropertyImplementationSize(Property::Type& propertyType);
157
158 } // namespace Internal
159
160 // Helpers for public-api forwarding methods
161 inline Internal::VertexBuffer& GetImplementation(Dali::VertexBuffer& handle)
162 {
163   DALI_ASSERT_ALWAYS(handle && "VertexBuffer handle is empty");
164
165   BaseObject& object = handle.GetBaseObject();
166
167   return static_cast<Internal::VertexBuffer&>(object);
168 }
169
170 inline const Internal::VertexBuffer& GetImplementation(const Dali::VertexBuffer& handle)
171 {
172   DALI_ASSERT_ALWAYS(handle && "VertexBuffer handle is empty");
173
174   const BaseObject& object = handle.GetBaseObject();
175
176   return static_cast<const Internal::VertexBuffer&>(object);
177 }
178
179 } // namespace Dali
180
181 #endif // DALI_INTERNAL_VERTEX_BUFFER_H