-void VertexSetup::update_vertex_array(const VertexArray &array, unsigned binding, unsigned divisor, bool direct) const
-{
- 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);
- }
-}
-
-void VertexSetup::bind() const
-{
- if(!vertex_array || !index_buffer)
- throw invalid_operation("VertexSetup::bind");
-
- if(set_current(this))
- {
- vertex_array->refresh();
- if(inst_array)
- inst_array->refresh();
- glBindVertexArray(id);
- if(dirty)
- {
- update(dirty);
- dirty = 0;
- }
- }
-}
-
-void VertexSetup::unbind()
-{
- if(set_current(0))
- glBindVertexArray(0);
-}
-
-void VertexSetup::set_debug_name(const string &name)
-{
-#ifdef DEBUG
- if(KHR_debug)
- glObjectLabel(GL_VERTEX_ARRAY, id, name.size(), name.c_str());
-#else
- (void)name;
-#endif