- Conditional<Bind> bind_vbuf(!direct, array.get_buffer(), ARRAY_BUFFER);
-
- const VertexFormat &fmt = array.get_format();
- unsigned stride = fmt.stride()*sizeof(float);
- if(direct)
- {
- glVertexArrayVertexBuffer(id, binding, array.get_buffer()->get_id(), 0, stride);
- glVertexArrayBindingDivisor(id, binding, divisor);
- }
-
- unsigned offset = 0;
- for(const unsigned char *a=fmt.begin(); a!=fmt.end(); ++a)
- {
- unsigned sem = get_attribute_semantic(*a);
- unsigned sz = get_attribute_size(*a);
- if(direct)
- {
- if(*a==COLOR4_UBYTE)
- glVertexArrayAttribFormat(id, sem, 4, GL_UNSIGNED_BYTE, true, offset);
- else
- glVertexArrayAttribFormat(id, sem, sz, GL_FLOAT, false, offset);
- glVertexArrayAttribBinding(id, sem, binding);
- glEnableVertexArrayAttrib(id, sem);
- }
- else
- {
- if(*a==COLOR4_UBYTE)
- glVertexAttribPointer(sem, 4, GL_UNSIGNED_BYTE, true, stride, reinterpret_cast<unsigned char *>(offset));
- else
- glVertexAttribPointer(sem, sz, GL_FLOAT, false, stride, reinterpret_cast<float *>(offset));
- if(ARB_instanced_arrays)
- glVertexAttribDivisor(sem, divisor);
- glEnableVertexAttribArray(sem);
- }
- offset += sz*sizeof(float);
- }
-}