2 * Copyright (c) 2020 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/render/renderers/render-vertex-buffer.h>
19 #include <dali/internal/event/rendering/vertex-buffer-impl.h> // Dali::Internal::VertexBuffer
25 using Dali::Internal::PropertyImplementationType;
27 Dali::GLenum GetPropertyImplementationGlType( Property::Type propertyType )
29 Dali::GLenum type = GL_BYTE;
31 switch( propertyType )
34 case Property::STRING:
37 case Property::EXTENTS:
38 case Property::RECTANGLE:
39 case Property::ROTATION:
41 // types not supported by gl
44 case Property::BOOLEAN:
49 case Property::INTEGER:
55 case Property::VECTOR2:
56 case Property::VECTOR3:
57 case Property::VECTOR4:
58 case Property::MATRIX3:
59 case Property::MATRIX:
69 Dali::GLint GetPropertyImplementationGlSize( Property::Type propertyType )
71 Dali::GLint size = 1u;
73 switch( propertyType )
76 case Property::STRING:
79 case Property::EXTENTS:
80 case Property::RECTANGLE:
81 case Property::ROTATION:
83 // types not supported by gl
86 case Property::BOOLEAN:
91 case Property::INTEGER:
97 case Property::VECTOR2:
98 case Property::VECTOR3:
99 case Property::VECTOR4:
100 case Property::MATRIX3:
101 case Property::MATRIX:
110 } //Unnamed namespace
119 VertexBuffer::VertexBuffer()
128 VertexBuffer::~VertexBuffer() = default;
130 void VertexBuffer::SetFormat( VertexBuffer::Format* format )
136 void VertexBuffer::SetData( Dali::Vector<uint8_t>* data, uint32_t size )
143 bool VertexBuffer::Update( Context& context )
145 if( !mData || !mFormat || !mSize )
150 if( !mGpuBuffer || mDataChanged )
154 mGpuBuffer = new GpuBuffer( context );
157 // Update the GpuBuffer
160 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
161 mGpuBuffer->UpdateDataBuffer( context, GetDataSize(), &((*mData)[0]), GpuBuffer::STATIC_DRAW, GpuBuffer::ARRAY_BUFFER );
164 mDataChanged = false;
170 void VertexBuffer::BindBuffer( Context& context, GpuBuffer::Target target )
174 mGpuBuffer->Bind(context, target);
178 uint32_t VertexBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, uint32_t locationBase )
180 const uint32_t attributeCount = static_cast<uint32_t>( mFormat->components.size() );
182 GLsizei elementSize = mFormat->size;
184 for( uint32_t i = 0; i < attributeCount; ++i )
186 GLint attributeLocation = vAttributeLocation[i+locationBase];
187 if( attributeLocation != -1 )
189 context.EnableVertexAttributeArray( attributeLocation );
191 const GLint attributeSize = mFormat->components[i].size;
192 uint32_t attributeOffset = mFormat->components[i].offset;
193 const Property::Type attributeType = mFormat->components[i].type;
195 context.VertexAttribPointer( attributeLocation,
196 attributeSize / GetPropertyImplementationGlSize(attributeType),
197 GetPropertyImplementationGlType(attributeType),
198 GL_FALSE, // Not normalized
200 reinterpret_cast< void* >( attributeOffset ) );
204 return attributeCount;