2 * Copyright (c) 2017 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
26 using Dali::Internal::PropertyImplementationType;
28 Dali::GLenum GetPropertyImplementationGlType( Property::Type propertyType )
30 Dali::GLenum type = GL_BYTE;
32 switch( propertyType )
35 case Property::STRING:
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 size_t GetPropertyImplementationGlSize( Property::Type propertyType )
73 switch( propertyType )
76 case Property::STRING:
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
118 PropertyBuffer::PropertyBuffer()
127 PropertyBuffer::~PropertyBuffer()
131 void PropertyBuffer::SetFormat( PropertyBuffer::Format* format )
137 void PropertyBuffer::SetData( Dali::Vector<char>* data, size_t size )
144 bool PropertyBuffer::Update( Context& context )
146 if( !mData || !mFormat || !mSize )
151 if( !mGpuBuffer || mDataChanged )
155 mGpuBuffer = new GpuBuffer( context );
158 // Update the GpuBuffer
161 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
162 mGpuBuffer->UpdateDataBuffer( GetDataSize(), &((*mData)[0]), GpuBuffer::STATIC_DRAW, GpuBuffer::ARRAY_BUFFER );
165 mDataChanged = false;
171 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
175 mGpuBuffer->Bind(target);
179 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
182 unsigned int attributeCount = mFormat->components.size();
184 GLsizei elementSize = mFormat->size;
186 for( unsigned int 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 size_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;