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