1 #ifndef DALI_INTERNAL_RENDER_GEOMETRY_H
2 #define DALI_INTERNAL_RENDER_GEOMETRY_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/gl-defines.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>
42 * This class encapsulates the GPU buffers. It is used to upload vertex data
43 * to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
49 using Type = Dali::Geometry::Type;
59 * Called on Gl Context created
61 void GlContextCreated(Context& context);
64 * Called on Gl Context destroyed.
66 void GlContextDestroyed();
69 * Adds a property buffer to the geometry
70 * @param[in] dataProvider The VertexBuffer data provider
72 void AddVertexBuffer(Render::VertexBuffer* vertexBuffer);
75 * Set the data for the index buffer to be used by the geometry
76 * @param[in] indices A vector containing the indices
78 void SetIndexBuffer(Dali::Vector<uint16_t>& indices);
81 * Removes a VertexBuffer from the geometry
82 * @param[in] vertexBuffer The property buffer to be removed
84 void RemoveVertexBuffer(const Render::VertexBuffer* vertexBuffer);
87 * Gets the attribute locations on the shader for the attributes defined in the geometry RenderBuffers
88 * @param[out] attributeLocation The vector where the attributes locations will be stored
89 * @param[in] program The program
90 * @param[in] bufferIndex The current buffer index
92 void GetAttributeLocationFromProgram(Vector<GLint>& attributeLocation, Program& program, BufferIndex bufferIndex) const;
95 * Called from RenderManager to notify the geometry that current rendering pass has finished.
97 void OnRenderFinished();
100 * Check if the attributes for the geometry have changed
101 * @return True if vertex buffers have been added or removed since last frame, false otherwise
103 bool AttributesChanged() const
105 return mAttributesChanged;
109 * Sets the geometry type
110 * @param[in] type The new geometry type
112 void SetType(Type type)
114 mGeometryType = type;
118 * Upload the geometry if it has changed
119 * @param[in] context The GL context
121 void Upload(Context& context);
124 * Set up the attributes and perform the Draw call corresponding to the geometry type
125 * @param[in] context The GL context
126 * @param[in] bufferIndex The current buffer index
127 * @param[in] attributeLocation The location for the attributes in the shader
128 * @param[in] elementBufferOffset The index of first element to draw if index buffer bound
129 * @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
131 void Draw(Context& context,
132 BufferIndex bufferIndex,
133 Vector<GLint>& attributeLocation,
134 uint32_t elementBufferOffset,
135 uint32_t elementBufferCount);
139 Vector<Render::VertexBuffer*> mVertexBuffers;
141 Dali::Vector<uint16_t> mIndices;
142 OwnerPointer<GpuBuffer> mIndexBuffer;
146 bool mIndicesChanged : 1;
147 bool mHasBeenUpdated : 1;
148 bool mAttributesChanged : 1;
151 } // namespace Render
152 } // namespace Internal
155 #endif // DALI_INTERNAL_RENDER_GEOMETRY_H