2 #include <dali/internal/render/renderers/render-property-buffer.h>
3 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
10 using Dali::Internal::PropertyImplementationType;
12 Dali::GLenum GetPropertyImplementationGlType( Property::Type propertyType )
14 Dali::GLenum type = GL_BYTE;
16 switch( propertyType )
19 case Property::STRING:
22 case Property::RECTANGLE:
23 case Property::ROTATION:
25 // types not supported by gl
28 case Property::BOOLEAN:
33 case Property::INTEGER:
39 case Property::VECTOR2:
40 case Property::VECTOR3:
41 case Property::VECTOR4:
42 case Property::MATRIX3:
43 case Property::MATRIX:
53 size_t GetPropertyImplementationGlSize( Property::Type propertyType )
57 switch( propertyType )
60 case Property::STRING:
63 case Property::RECTANGLE:
64 case Property::ROTATION:
66 // types not supported by gl
69 case Property::BOOLEAN:
74 case Property::INTEGER:
80 case Property::VECTOR2:
81 case Property::VECTOR3:
82 case Property::VECTOR4:
83 case Property::MATRIX3:
84 case Property::MATRIX:
102 PropertyBuffer::PropertyBuffer()
111 PropertyBuffer::~PropertyBuffer()
115 void PropertyBuffer::SetFormat( PropertyBuffer::Format* format )
121 void PropertyBuffer::SetData( Dali::Vector<char>* data )
127 void PropertyBuffer::SetSize( unsigned int size )
134 bool PropertyBuffer::Update( Context& context, bool isIndexBuffer )
136 if( !mData || !mFormat || !mSize )
141 if( !mGpuBuffer || mDataChanged )
145 mGpuBuffer = new GpuBuffer( context );
148 // Update the GpuBuffer
151 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
153 const void *data = &((*mData)[0]);
154 std::size_t dataSize = GetDataSize();
156 // Index buffer needs to be unsigned short which is not supported by the property system
157 Vector<unsigned short> ushortData;
160 ushortData.Resize(mSize);
161 const unsigned int* unsignedData = static_cast<const unsigned int*>(data);
162 for( unsigned int i = 0; i < mSize; ++i )
164 ushortData[i] = unsignedData[i];
166 data = &(ushortData[0]);
167 dataSize = ushortData.Size() * sizeof( unsigned short );
170 GpuBuffer::Target target = GpuBuffer::ARRAY_BUFFER;
173 target = GpuBuffer::ELEMENT_ARRAY_BUFFER;
175 mGpuBuffer->UpdateDataBuffer( dataSize, data, GpuBuffer::STATIC_DRAW, target );
179 mDataChanged = false;
185 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
189 mGpuBuffer->Bind(target);
193 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
196 unsigned int attributeCount = mFormat->components.size();
198 GLsizei elementSize = mFormat->size;
200 for( unsigned int i = 0; i < attributeCount; ++i )
202 GLint attributeLocation = vAttributeLocation[i+locationBase];
203 if( attributeLocation != -1 )
205 context.EnableVertexAttributeArray( attributeLocation );
207 const GLint attributeSize = mFormat->components[i].size;
208 size_t attributeOffset = mFormat->components[i].offset;
209 const Property::Type attributeType = mFormat->components[i].type;
211 context.VertexAttribPointer( attributeLocation,
212 attributeSize / GetPropertyImplementationGlSize(attributeType),
213 GetPropertyImplementationGlType(attributeType),
214 GL_FALSE, // Not normalized
216 (void*)attributeOffset );
220 return attributeCount;