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 mGpuBuffer->UpdateDataBuffer( GetDataSize(), data, GpuBuffer::STATIC_DRAW );
171 mDataChanged = false;
177 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
181 mGpuBuffer->Bind(target);
185 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
188 unsigned int attributeCount = mFormat->components.size();
190 GLsizei elementSize = mFormat->size;
192 for( unsigned int i = 0; i < attributeCount; ++i )
194 GLint attributeLocation = vAttributeLocation[i+locationBase];
195 if( attributeLocation != -1 )
197 context.EnableVertexAttributeArray( attributeLocation );
199 GLint attributeSize = mFormat->components[i].size;
200 size_t attributeOffset = mFormat->components[i].offset;
201 Property::Type attributeType = mFormat->components[i].type;
203 context.VertexAttribPointer( attributeLocation,
204 attributeSize / GetPropertyImplementationGlSize(attributeType),
205 GetPropertyImplementationGlType(attributeType),
206 GL_FALSE, // Not normalized
208 (void*)attributeOffset );
212 return attributeCount;