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::EXTENTS:
39 case Property::RECTANGLE:
40 case Property::ROTATION:
42 // types not supported by gl
45 case Property::BOOLEAN:
50 case Property::INTEGER:
56 case Property::VECTOR2:
57 case Property::VECTOR3:
58 case Property::VECTOR4:
59 case Property::MATRIX3:
60 case Property::MATRIX:
70 size_t GetPropertyImplementationGlSize( Property::Type propertyType )
74 switch( propertyType )
77 case Property::STRING:
80 case Property::EXTENTS:
81 case Property::RECTANGLE:
82 case Property::ROTATION:
84 // types not supported by gl
87 case Property::BOOLEAN:
92 case Property::INTEGER:
98 case Property::VECTOR2:
99 case Property::VECTOR3:
100 case Property::VECTOR4:
101 case Property::MATRIX3:
102 case Property::MATRIX:
111 } //Unnamed namespace
120 PropertyBuffer::PropertyBuffer()
129 PropertyBuffer::~PropertyBuffer()
133 void PropertyBuffer::SetFormat( PropertyBuffer::Format* format )
139 void PropertyBuffer::SetData( Dali::Vector<char>* data, size_t size )
146 bool PropertyBuffer::Update( Context& context )
148 if( !mData || !mFormat || !mSize )
153 if( !mGpuBuffer || mDataChanged )
157 mGpuBuffer = new GpuBuffer( context );
160 // Update the GpuBuffer
163 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
164 mGpuBuffer->UpdateDataBuffer( GetDataSize(), &((*mData)[0]), GpuBuffer::STATIC_DRAW, GpuBuffer::ARRAY_BUFFER );
167 mDataChanged = false;
173 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
177 mGpuBuffer->Bind(target);
181 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
184 unsigned int attributeCount = mFormat->components.size();
186 GLsizei elementSize = mFormat->size;
188 for( unsigned int i = 0; i < attributeCount; ++i )
190 GLint attributeLocation = vAttributeLocation[i+locationBase];
191 if( attributeLocation != -1 )
193 context.EnableVertexAttributeArray( attributeLocation );
195 const GLint attributeSize = mFormat->components[i].size;
196 size_t attributeOffset = mFormat->components[i].offset;
197 const Property::Type attributeType = mFormat->components[i].type;
199 context.VertexAttribPointer( attributeLocation,
200 attributeSize / GetPropertyImplementationGlSize(attributeType),
201 GetPropertyImplementationGlType(attributeType),
202 GL_FALSE, // Not normalized
204 reinterpret_cast< void* >( attributeOffset ) );
208 return attributeCount;