2 * Copyright (c) 2018 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-property-buffer.h>
19 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
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 PropertyBuffer::PropertyBuffer()
128 PropertyBuffer::~PropertyBuffer()
132 void PropertyBuffer::SetFormat( PropertyBuffer::Format* format )
138 void PropertyBuffer::SetData( Dali::Vector<uint8_t>* data, uint32_t size )
145 bool PropertyBuffer::Update( Context& context )
147 if( !mData || !mFormat || !mSize )
152 if( !mGpuBuffer || mDataChanged )
156 mGpuBuffer = new GpuBuffer( context );
159 // Update the GpuBuffer
162 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
163 mGpuBuffer->UpdateDataBuffer( GetDataSize(), &((*mData)[0]), GpuBuffer::STATIC_DRAW, GpuBuffer::ARRAY_BUFFER );
166 mDataChanged = false;
172 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
176 mGpuBuffer->Bind(target);
180 uint32_t PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, uint32_t locationBase )
182 const uint32_t attributeCount = static_cast<uint32_t>( mFormat->components.size() );
184 GLsizei elementSize = mFormat->size;
186 for( uint32_t i = 0; i < attributeCount; ++i )
188 GLint attributeLocation = vAttributeLocation[i+locationBase];
189 if( attributeLocation != -1 )
191 context.EnableVertexAttributeArray( attributeLocation );
193 const GLint attributeSize = mFormat->components[i].size;
194 uint32_t attributeOffset = mFormat->components[i].offset;
195 const Property::Type attributeType = mFormat->components[i].type;
197 context.VertexAttribPointer( attributeLocation,
198 attributeSize / GetPropertyImplementationGlSize(attributeType),
199 GetPropertyImplementationGlType(attributeType),
200 GL_FALSE, // Not normalized
202 reinterpret_cast< void* >( attributeOffset ) );
206 return attributeCount;