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.
18 #include <dali/internal/event/rendering/vertex-buffer-impl.h> // Dali::Internal::VertexBuffer
19 #include <dali/internal/render/renderers/render-vertex-buffer.h>
24 using Dali::Internal::PropertyImplementationType;
26 Dali::GLenum GetPropertyImplementationGlType(Property::Type propertyType)
28 Dali::GLenum type = GL_BYTE;
33 case Property::STRING:
36 case Property::EXTENTS:
37 case Property::RECTANGLE:
38 case Property::ROTATION:
40 // types not supported by gl
43 case Property::BOOLEAN:
48 case Property::INTEGER:
54 case Property::VECTOR2:
55 case Property::VECTOR3:
56 case Property::VECTOR4:
57 case Property::MATRIX3:
58 case Property::MATRIX:
68 Dali::GLint GetPropertyImplementationGlSize(Property::Type propertyType)
70 Dali::GLint size = 1u;
75 case Property::STRING:
78 case Property::EXTENTS:
79 case Property::RECTANGLE:
80 case Property::ROTATION:
82 // types not supported by gl
85 case Property::BOOLEAN:
90 case Property::INTEGER:
96 case Property::VECTOR2:
97 case Property::VECTOR3:
98 case Property::VECTOR4:
99 case Property::MATRIX3:
100 case Property::MATRIX:
109 } //Unnamed namespace
117 VertexBuffer::VertexBuffer()
126 VertexBuffer::~VertexBuffer() = default;
128 void VertexBuffer::SetFormat(VertexBuffer::Format* format)
134 void VertexBuffer::SetData(Dali::Vector<uint8_t>* data, uint32_t size)
141 bool VertexBuffer::Update(Context& context)
143 if(!mData || !mFormat || !mSize)
148 if(!mGpuBuffer || mDataChanged)
152 mGpuBuffer = new GpuBuffer(context);
155 // Update the GpuBuffer
158 DALI_ASSERT_DEBUG(mSize && "No data in the property buffer!");
159 mGpuBuffer->UpdateDataBuffer(context, GetDataSize(), &((*mData)[0]), GpuBuffer::STATIC_DRAW, GpuBuffer::ARRAY_BUFFER);
162 mDataChanged = false;
168 void VertexBuffer::BindBuffer(Context& context, GpuBuffer::Target target)
172 mGpuBuffer->Bind(context, target);
176 uint32_t VertexBuffer::EnableVertexAttributes(Context& context, Vector<GLint>& vAttributeLocation, uint32_t locationBase)
178 const uint32_t attributeCount = static_cast<uint32_t>(mFormat->components.size());
180 GLsizei elementSize = mFormat->size;
182 for(uint32_t i = 0; i < attributeCount; ++i)
184 GLint attributeLocation = vAttributeLocation[i + locationBase];
185 if(attributeLocation != -1)
187 context.EnableVertexAttributeArray(attributeLocation);
189 const GLint attributeSize = mFormat->components[i].size;
190 uint32_t attributeOffset = mFormat->components[i].offset;
191 const Property::Type attributeType = mFormat->components[i].type;
193 context.VertexAttribPointer(attributeLocation,
194 attributeSize / GetPropertyImplementationGlSize(attributeType),
195 GetPropertyImplementationGlType(attributeType),
196 GL_FALSE, // Not normalized
198 reinterpret_cast<void*>(attributeOffset));
202 return attributeCount;
205 } // namespace Render
206 } // namespace Internal