[dali_1.1.32] Merge branch 'devel/master'
[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) 2015 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/devel-api/rendering/geometry.h> // Dali::Geometry
28 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
29 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
30 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
31 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
32 #include <dali/internal/render/renderers/render-geometry.h>
33
34 namespace Dali
35 {
36 namespace Internal
37 {
38 namespace SceneGraph
39 {
40 class Geometry;
41 }
42
43 class Geometry;
44 typedef IntrusivePtr<Geometry> GeometryPtr;
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   /**
55    * Create a new Geometry.
56    * @return A smart-pointer to the newly allocated Geometry.
57    */
58   static GeometryPtr New();
59
60   /**
61    * @copydoc Dali::Geometry::AddVertexBuffer()
62    */
63   std::size_t AddVertexBuffer( PropertyBuffer& vertexBuffer );
64
65   /**
66    * @copydoc Dali::Geometry::GetNumberOfVertexBuffers()
67    */
68   std::size_t GetNumberOfVertexBuffers() const;
69
70   /**
71    * @copydoc Dali::Geometry::RemoveVertexBuffer()
72    */
73   void RemoveVertexBuffer( std::size_t index );
74
75   /**
76    * @copydoc Dali::Geometry::SetIndexBuffer()
77    */
78   void SetIndexBuffer( const unsigned short* indices, size_t count );
79
80   /**
81    * @copydoc Dali::Geometry::SetGeometryType()
82    */
83   void SetGeometryType( Dali::Geometry::GeometryType geometryType );
84
85   /**
86    * @copydoc Dali::Geometry::GetGeometryType()
87    */
88   Dali::Geometry::GeometryType GetGeometryType() const;
89
90   /**
91    * @copydoc Dali::Geometry::SetRequiresDepthTesting()
92    */
93   void SetRequiresDepthTesting( bool requiresDepthTest );
94
95   /**
96    * @copydoc Dali::Geometry::GetRequiresDepthTesting()
97    */
98   bool GetRequiresDepthTesting() const;
99
100   /**
101    * @brief Get the geometry scene object
102    *
103    * @return the geometry scene object
104    */
105   const Render::Geometry* GetRenderObject() const;
106
107 private: // implementation
108
109   /**
110    * Constructor
111    */
112   Geometry();
113
114   /**
115    * Second stage initialization of the Geometry
116    */
117   void Initialize();
118
119 protected:
120
121   /**
122    * A reference counted object may only be deleted by calling Unreference()
123    */
124   virtual ~Geometry();
125
126 private: // unimplemented methods
127   Geometry( const Geometry& );
128   Geometry& operator=( const Geometry& );
129
130 private: // data
131
132   EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
133   Render::Geometry* mRenderObject;
134
135   std::vector<PropertyBufferPtr> mVertexBuffers; ///< Vector of intrusive pointers to vertex buffers
136   Dali::Geometry::GeometryType mGeometryType;      ///< Geometry type (cached)
137   bool                         mRequiresDepthTest; ///< Establish if geometry requires depth testing (cached)
138
139 };
140
141 } // namespace Internal
142
143 // Helpers for public-api forwarding methods
144 inline Internal::Geometry& GetImplementation(Dali::Geometry& handle)
145 {
146   DALI_ASSERT_ALWAYS(handle && "Geometry handle is empty");
147
148   BaseObject& object = handle.GetBaseObject();
149
150   return static_cast<Internal::Geometry&>(object);
151 }
152
153 inline const Internal::Geometry& GetImplementation(const Dali::Geometry& handle)
154 {
155   DALI_ASSERT_ALWAYS(handle && "Geometry handle is empty");
156
157   const BaseObject& object = handle.GetBaseObject();
158
159   return static_cast<const Internal::Geometry&>(object);
160 }
161
162 } // namespace Dali
163
164 #endif // DALI_INTERNAL_GEOMETRY_H