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, size_t size )
128 bool PropertyBuffer::Update( Context& context, bool isIndexBuffer )
130 if( !mData || !mFormat || !mSize )
135 if( !mGpuBuffer || mDataChanged )
139 mGpuBuffer = new GpuBuffer( context );
142 // Update the GpuBuffer
145 DALI_ASSERT_DEBUG( mSize && "No data in the property buffer!" );
147 const void *data = &((*mData)[0]);
148 std::size_t dataSize = GetDataSize();
150 // Index buffer needs to be unsigned short which is not supported by the property system
151 Vector<unsigned short> ushortData;
154 ushortData.Resize(mSize);
155 const unsigned int* unsignedData = static_cast<const unsigned int*>(data);
156 for( unsigned int i = 0; i < mSize; ++i )
158 ushortData[i] = unsignedData[i];
160 data = &(ushortData[0]);
161 dataSize = ushortData.Size() * sizeof( unsigned short );
164 GpuBuffer::Target target = GpuBuffer::ARRAY_BUFFER;
167 target = GpuBuffer::ELEMENT_ARRAY_BUFFER;
169 mGpuBuffer->UpdateDataBuffer( dataSize, data, GpuBuffer::STATIC_DRAW, target );
173 mDataChanged = false;
179 void PropertyBuffer::BindBuffer(GpuBuffer::Target target)
183 mGpuBuffer->Bind(target);
187 unsigned int PropertyBuffer::EnableVertexAttributes( Context& context, Vector<GLint>& vAttributeLocation, unsigned int locationBase )
190 unsigned int attributeCount = mFormat->components.size();
192 GLsizei elementSize = mFormat->size;
194 for( unsigned int i = 0; i < attributeCount; ++i )
196 GLint attributeLocation = vAttributeLocation[i+locationBase];
197 if( attributeLocation != -1 )
199 context.EnableVertexAttributeArray( attributeLocation );
201 const GLint attributeSize = mFormat->components[i].size;
202 size_t attributeOffset = mFormat->components[i].offset;
203 const Property::Type attributeType = mFormat->components[i].type;
205 context.VertexAttribPointer( attributeLocation,
206 attributeSize / GetPropertyImplementationGlSize(attributeType),
207 GetPropertyImplementationGlType(attributeType),
208 GL_FALSE, // Not normalized
210 (void*)attributeOffset );
214 return attributeCount;