2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "gles-graphics-buffer.h"
22 #include <dali/integration-api/gl-abstraction.h>
23 #include <dali/integration-api/gl-defines.h>
26 #include "egl-graphics-controller.h"
28 namespace Dali::Graphics::GLES
30 Buffer::Buffer(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphicsController& controller)
31 : BufferResource(createInfo, controller)
33 controller.AddBuffer(*this);
36 bool Buffer::InitializeResource()
38 auto gl = mController.GetGL();
39 gl->GenBuffers(1, &mBufferId);
40 gl->BindBuffer(GL_ARRAY_BUFFER, mBufferId);
41 gl->BufferData(GL_ARRAY_BUFFER, mCreateInfo.size, nullptr, GL_STATIC_DRAW);
45 void Buffer::DestroyResource()
47 auto gl = mController.GetGL();
48 gl->DeleteBuffers(1, &mBufferId);
51 void Buffer::DiscardResource()
53 mController.DiscardResource(this);
56 void Buffer::Bind(Graphics::BufferUsage bindingTarget) const
58 auto gl = mController.GetGL();
61 case Graphics::BufferUsage::VERTEX_BUFFER:
63 gl->BindBuffer(GL_ARRAY_BUFFER, mBufferId);
66 case Graphics::BufferUsage::INDEX_BUFFER:
68 gl->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
78 } // namespace Dali::Graphics::GLES