466372779d312e46e719caddef4f4ae19e165bec
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / geometry-impl.h
1 #ifndef DALI_INTERNAL_GEOMETRY_H
2 #define DALI_INTERNAL_GEOMETRY_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h> // std::vector
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>   // DALI_ASSERT_ALWAYS
26 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/rendering/geometry.h> // Dali::Geometry
29
30 #include <dali/internal/event/rendering/vertex-buffer-impl.h> // Dali::Internal::VertexBuffer
31 #include <dali/internal/render/renderers/render-geometry.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace SceneGraph
38 {
39 class Geometry;
40 }
41
42 class Geometry;
43 using GeometryPtr = IntrusivePtr<Geometry>;
44
45 /**
46  * Geometry is an object that contains an array of structures of values that
47  * can be accessed as properties.
48  */
49 class Geometry : public BaseObject
50 {
51 public:
52   /**
53    * Create a new Geometry.
54    * @return A smart-pointer to the newly allocated Geometry.
55    */
56   static GeometryPtr New();
57
58   /**
59    * @copydoc Dali::Geometry::AddVertexBuffer()
60    */
61   uint32_t AddVertexBuffer(VertexBuffer& vertexBuffer);
62
63   /**
64    * @copydoc Dali::Geometry::GetNumberOfVertexBuffers()
65    */
66   uint32_t GetNumberOfVertexBuffers() const;
67
68   /**
69    * @copydoc Dali::Geometry::RemoveVertexBuffer()
70    */
71   void RemoveVertexBuffer(uint32_t index);
72
73   /**
74    * @copydoc Dali::Geometry::SetIndexBuffer()
75    */
76   void SetIndexBuffer(const uint16_t* indices, uint32_t count);
77
78   /**
79    * @copydoc Dali::Geometry::SetType()
80    */
81   void SetType(Dali::Geometry::Type geometryType);
82
83   /**
84    * @copydoc Dali::Geometry::GetType()
85    */
86   Dali::Geometry::Type GetType() const;
87
88   /**
89    * @brief Get the geometry scene object
90    *
91    * @return the geometry scene object
92    */
93   const Render::Geometry* GetRenderObject() const;
94
95 private: // implementation
96   /**
97    * Constructor
98    */
99   Geometry();
100
101   /**
102    * Second stage initialization of the Geometry
103    */
104   void Initialize();
105
106 protected:
107   /**
108    * A reference counted object may only be deleted by calling Unreference()
109    */
110   ~Geometry() override;
111
112 private: // unimplemented methods
113   Geometry(const Geometry&);
114   Geometry& operator=(const Geometry&);
115
116 private:                                     // data
117   EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
118   Render::Geometry*    mRenderObject;
119
120   std::vector<VertexBufferPtr> mVertexBuffers; ///< Vector of intrusive pointers to vertex buffers
121   Dali::Geometry::Type         mType;          ///< Geometry type (cached)
122 };
123
124 } // namespace Internal
125
126 // Helpers for public-api forwarding methods
127 inline Internal::Geometry& GetImplementation(Dali::Geometry& handle)
128 {
129   DALI_ASSERT_ALWAYS(handle && "Geometry handle is empty");
130
131   BaseObject& object = handle.GetBaseObject();
132
133   return static_cast<Internal::Geometry&>(object);
134 }
135
136 inline const Internal::Geometry& GetImplementation(const Dali::Geometry& handle)
137 {
138   DALI_ASSERT_ALWAYS(handle && "Geometry handle is empty");
139
140   const BaseObject& object = handle.GetBaseObject();
141
142   return static_cast<const Internal::Geometry&>(object);
143 }
144
145 } // namespace Dali
146
147 #endif // DALI_INTERNAL_GEOMETRY_H