Merge "Add BuildPickingRay to devel api" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-geometry.h
1 #ifndef DALI_INTERNAL_RENDER_GEOMETRY_H
2 #define DALI_INTERNAL_RENDER_GEOMETRY_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 // INTERNAL INCLUDES
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/graphics-api/graphics-controller.h>
23 #include <dali/graphics-api/graphics-types.h>
24 #include <dali/internal/common/buffer-index.h>
25 #include <dali/internal/common/owner-pointer.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/rendering/geometry.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 class Program;
34 class GpuBuffer;
35
36 namespace Render
37 {
38 class VertexBuffer;
39
40 /**
41  * This class encapsulates the GPU buffers. It is used to upload vertex data
42  * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
43  * bindings
44  */
45 class Geometry
46 {
47 public:
48   using Type      = Dali::Geometry::Type;
49   using IndexType = Dali::Graphics::Format;
50
51   using Uint16ContainerType = Dali::Vector<uint16_t>;
52   using Uint32ContainerType = Dali::Vector<uint32_t>;
53
54   Geometry();
55
56   /**
57    * Destructor
58    */
59   ~Geometry();
60
61   /**
62    * Adds a property buffer to the geometry
63    * @param[in] dataProvider The VertexBuffer data provider
64    */
65   void AddVertexBuffer(Render::VertexBuffer* vertexBuffer);
66
67   /**
68    * Set the data for the index buffer to be used by the geometry
69    * @param[in] indices A vector containing the indices
70    */
71   void SetIndexBuffer(Uint16ContainerType& indices);
72
73   /**
74    * Set the data for the index buffer to be used by the geometry
75    * @param[in] indices A vector containing the indices
76    */
77   void SetIndexBuffer(Uint32ContainerType& indices);
78
79   /**
80    * Removes a VertexBuffer from the geometry
81    * @param[in] vertexBuffer The property buffer to be removed
82    */
83   void RemoveVertexBuffer(const Render::VertexBuffer* vertexBuffer);
84
85   /**
86    * Get the vertex buffers
87    * @return the list of vertex buffers
88    */
89   [[nodiscard]] const Vector<Render::VertexBuffer*>& GetVertexBuffers() const;
90
91   /**
92    * Called from RenderManager to notify the geometry that current rendering pass has finished.
93    */
94   void OnRenderFinished();
95
96   /**
97    * Check if the attributes for the geometry have changed
98    * @return True if vertex buffers have been added or removed since last frame, false otherwise
99    */
100   [[maybe_unused]] [[nodiscard]] bool AttributesChanged() const
101   {
102     return mAttributesChanged;
103   }
104
105   /**
106    * Sets the geometry type
107    * @param[in] type The new geometry type
108    */
109   void SetType(Type type)
110   {
111     mGeometryType = type;
112   }
113
114   /**
115    * @return the topology of this geometry
116    */
117   [[nodiscard]] Graphics::PrimitiveTopology GetTopology() const;
118
119   /**
120    * Upload the geometry if it has changed
121    */
122   void Upload(Graphics::Controller& graphicsController);
123
124   /**
125    * Set up the attributes and perform the Draw call corresponding to the geometry type.
126    *
127    * @param[in] graphicsController The graphics controller
128    * @param[in,out] commandBuffer The current command buffer queue
129    * @param[in] elementBufferOffset The index of first element to draw if index buffer bound
130    * @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
131    * @return true if the draw command was issued, false otherwise
132    */
133   bool Draw(Graphics::Controller&    graphicsController,
134             Graphics::CommandBuffer& commandBuffer,
135             uint32_t                 elementBufferOffset,
136             uint32_t                 elementBufferCount);
137
138   /**
139    * @brief Set up the attributes bind commaneds
140    *
141    * @param[in,out] commandBuffer The current command buffer queue
142    * @return true if the bind command was issued, false otherwise
143    */
144   bool BindVertexAttributes(Graphics::CommandBuffer& commandBuffer);
145
146 private:
147   // VertexBuffers
148   Vector<Render::VertexBuffer*> mVertexBuffers;
149
150   Uint16ContainerType     mIndices;
151   OwnerPointer<GpuBuffer> mIndexBuffer;
152   IndexType               mIndexType;
153   Type                    mGeometryType;
154
155   // Booleans
156   bool mIndicesChanged : 1;
157   bool mHasBeenUpdated : 1;
158   bool mAttributesChanged : 1;
159 };
160
161 } // namespace Render
162 } // namespace Internal
163 } // namespace Dali
164
165 #endif // DALI_INTERNAL_RENDER_GEOMETRY_H