1 #ifndef DALI_GRAPHICS_GLES_BUFFER_H
2 #define DALI_GRAPHICS_GLES_BUFFER_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.
22 #include <dali/graphics-api/graphics-buffer-create-info.h>
23 #include <dali/graphics-api/graphics-buffer.h>
26 #include "gles-graphics-resource.h"
28 namespace Dali::Graphics
30 class EglGraphicsController;
34 using BufferResource = Resource<Graphics::Buffer, Graphics::BufferCreateInfo>;
37 * Buffer class represents a GPU buffer object. It may represent
38 * vertex buffer, index buffer, pixel buffer, uniform buffer and
41 class Buffer : public BufferResource
44 Buffer(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
46 ~Buffer() override = default;
49 * @brief Called when resource is being destroyed
51 void DestroyResource() override;
53 bool InitializeResource() override;
55 void DiscardResource() override;
57 void Bind(Graphics::BufferUsage bindingTarget) const;
59 [[nodiscard]] uint32_t GetGLBuffer() const
64 [[nodiscard]] void* GetCPUAllocatedAddress() const
69 [[nodiscard]] bool IsTransient() const
74 [[nodiscard]] bool IsCPUAllocated() const
81 void InitializeCPUBuffer();
83 void InitializeGPUBuffer();
86 void* mBufferPtr{nullptr}; // CPU allocated memory
87 bool mCpuAllocated{false};
88 bool mTransient{false};
91 } // namespace Dali::Graphics
94 struct std::default_delete<Dali::Graphics::Buffer>
96 void operator()(Dali::Graphics::Buffer* object)
99 auto resource = static_cast<Dali::Graphics::GLES::Buffer*>(object);
100 resource->DiscardResource();