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