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]);
155 // Index buffer needs to be unsigned short which is not supported by the property system
156 Vector<unsigned short> ushortData;
159 ushortData.Resize(mSize);
160 const unsigned int* unsignedData = static_cast<const unsigned int*>(data);
161 for( unsigned int i = 0; i < mSize; ++i )
163 ushortData[i] = unsignedData[i];
165 data = &(ushortData[0]);
168 GpuBuffer::Target target = GpuBuffer::ARRAY_BUFFER;
171 target = GpuBuffer::ELEMENT_ARRAY_BUFFER;
174 mGpuBuffer->UpdateDataBuffer( GetDataSize(), data, GpuBuffer::STATIC_DRAW, target );
178 mDataChanged = false;
184 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
188 mGpuBuffer->Bind(target);
192 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
195 unsigned int attributeCount = mFormat->components.size();
197 GLsizei elementSize = mFormat->size;
199 for( unsigned int i = 0; i < attributeCount; ++i )
201 GLint attributeLocation = vAttributeLocation[i+locationBase];
202 if( attributeLocation != -1 )
204 context.EnableVertexAttributeArray( attributeLocation );
206 const GLint attributeSize = mFormat->components[i].size;
207 size_t attributeOffset = mFormat->components[i].offset;
208 const Property::Type attributeType = mFormat->components[i].type;
210 context.VertexAttribPointer( attributeLocation,
211 attributeSize / GetPropertyImplementationGlSize(attributeType),
212 GetPropertyImplementationGlType(attributeType),
213 GL_FALSE, // Not normalized
215 (void*)attributeOffset );
219 return attributeCount;