PDA

View Full Version : Can glVertexAttribDivisor works with glVertexAttribFormat and glVertexAttribBinding?



Loonywx
03-09-2017, 11:50 PM
I am using glVertexAttribDivisor to specify the instancing data storage. All the instance specific data is stored in 2nd vertex buffer at vertex buffer binding index 1 (vertex buffer at binding index 0 stores data used for all instances) used as instance specific data.

This is how I specify vertex format.


glCreateVertexArrays(1, &mVertexArray);
glBindVertexArray(mVertexArray);

for (auto& vertexAttrib : vertexFormat->mVertexAttributeList)
{
glVertexAttribFormat(vertexAttrib.mLocation, vertexAttrib.mChannel,
OpenGLShaderAttributeType[int(vertexAttrib.mType)],
vertexAttrib.mNormalized, vertexAttrib.mOffset);
glVertexAttribBinding(vertexAttrib.mLocation, vertexAttrib.mBindingIndex);

if (vertexAttrib.mDivision != 0)
{
glVertexAttribDivisor(vertexAttrib.mLocation, vertexAttrib.mDivision);
}

glEnableVertexAttribArray(vertexAttrib.mLocation);
}

glBindVertexArray(0);


This is how I enable vertex buffer for 2 vertex buffer.


glBindVertexBuffer(bindingIndex, mBuffer, offset, stride);


The problem is that when I used glVertexAttribDivisor, the glDrawArraysInstanced crashs as memory read violation. Can anyone provide a hint for potential problem for this situation? Thank you.

Loonywx
03-10-2017, 01:51 AM
I checked the specification:

The command



void VertexAttribDivisor( uint index, uint divisor );


is equivalent to (assuming no errors are generated):



VertexAttribBinding(index, index);
VertexBindingDivisor(index, divisor);


I just misread the parameter in VertexAttribDivisor. The first paramter is for vertex buffer binding index, rather than the attribute index.

mhagain
03-10-2017, 05:19 AM
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_vertex_attrib_binding.txt

glVertexBindingDivisor (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexBindingDivisor.xhtml) is provided for use with the attrib binding calls.

Loonywx
03-10-2017, 06:45 AM
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_vertex_attrib_binding.txt

glVertexBindingDivisor (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexBindingDivisor.xhtml) is provided for use with the attrib binding calls.

Yeah, Thank you. I just misread the information.