PDA

View Full Version : DSA: Segmentation fault when setting attribute pointers.



Ploppz
05-07-2015, 05:17 PM
Hi. I'm trying to set vertex attribute pointers using the DSA technique. As a test I'm trying to substitute something that already works in a test program. The following two lines (including relevant function) worked in my program:


void setVertexAttribPointer(GLuint shaderProgram, const char* name, GLint numComponents, GLenum type, GLsizei stride, int offset)
{
GLint attrib = glGetAttribLocation(shaderProgram, name);
glEnableVertexAttribArray(attrib);
glVertexAttribPointer(attrib, numComponents, type, GL_FALSE, stride, (void*)((intptr_t)offset));
}

// in main.cpp:

setVertexAttribPointer(skylineShader, "position", 2, GL_FLOAT, 5*sizeof(GLfloat), 0);
setVertexAttribPointer(skylineShader, "color", 3, GL_FLOAT, 5*sizeof(GLfloat), 2*sizeof(GLfloat));


Now I have changed that to:

GLint attrib = glGetAttribLocation(skylineShader, "position");
glEnableVertexArrayAttrib(skylineVAO, attrib);
glVertexArrayVertexAttribOffsetEXT(skylineVAO, skylineBuffer, attrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
I didn't include the lines setting up the vertex attribute pointers for "color", as the program crashes after the function call to glVertexArrayVertexAttribOffsetEXT.

Here (https://bpaste.net/show/4a82bc7bfe10) is more of the context, and here (https://bpaste.net/show/881f2220ae7d) are the functions I used in that code - it should not be necessary to pay too much attention to those.

As you can see, skylineBuffer is the output of glGenBuffers, and it's sent to glVertexArrayVertexAttribOffsetEXT after uploading the vertices (just the same as in the working test case).

I would greatly appreciate any help that can point me in the right direction.

Thanks!

Alfonse Reinheart
05-07-2015, 06:27 PM
glEnableVertexArrayAttrib(skylineVAO, attrib);
glVertexArrayVertexAttribOffsetEXT(skylineVAO, skylineBuffer, attrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

You're combining two different extensions: EXT_direct_state_access and ARB_direct_state_access. While they are similar, there are distinct differences between them. So you may well have confused the implementation by combining two similar-yet-distinct sets of functions. glEnableVertexArrayAttrib is from the ARB extension, while obviously the EXT function is from the EXT extension.

If you're going to use ARB_DSA, then use that, alone. Which requires the separation of vertex format from buffer bindings (https://www.opengl.org/wiki/Vertex_Specification#Separate_attribute_format).

Ploppz
05-08-2015, 08:43 AM
Thanks for the reply! I'm not sure about the difference between EXT and ARB, but I think I will stay with EXT - then what is the EXT equivalent of glEnableVertexArrayAttrib?

Additional question: in that link, it says that glVertexAttribPointer incorporates both "the vertex format for an attribute array, and the source data for that array". I'm confused about this, because it does not seem like glVertexAttribPointer deals with the source data at all. You specify an attribute pointer (variable name, shader program), number of components, data type, normalization, stride and offset. Which of these are considered "the source data"? (I automatically think about the actual bytes getting uploaded to the buffer).

Alfonse Reinheart
05-08-2015, 10:11 AM
Thanks for the reply! I'm not sure about the difference between EXT and ARB, but I think I will stay with EXT - then what is the EXT equivalent of glEnableVertexArrayAttrib?

glEnableVertexArrayEXT

The EXT_DSA extension isn't quite as consistent about its inconsistent nomenclature as the ARB version.


Additional question: in that link, it says that glVertexAttribPointer incorporates both "the vertex format for an attribute array, and the source data for that array". I'm confused about this, because it does not seem like glVertexAttribPointer deals with the source data at all. You specify an attribute pointer (variable name, shader program), number of components, data type, normalization, stride and offset. Which of these are considered "the source data"? (I automatically think about the actual bytes getting uploaded to the buffer).

It's the buffer bound to GL_ARRAY_BUFFER. The offset specified by the "pointer" is an offset into whatever buffer is bound to GL_ARRAY_BUFFER at the time glVertexAttribArray is called. The function basically takes an extra parameter through the global context.

You can think of glVertexAttribArray as being implemented in terms of VertexArrayVertexAttribOffsetEXT:



void glVertexAttribArray(GLuint index​, GLint size​, GLenum type​, GLboolean normalized​, GLsizei stride​, const void *offset​)
{
VertexArrayVertexAttribOffsetEXT(GetCurrVAO(), GetCurrBuffer(GL_ARRAY_BUFFER),
index, size, type, normalized, stride, (GLintptr)offset);
}

Ploppz
05-12-2015, 04:11 PM
This is a rather late reply - haven't had time to continue this lately.

I can't seem to find out what enum array is supposed to be in void EnableVertexArrayEXT(uint vaobj, enum array); I tried to call the function with the same arguments as I had in the ARB function, I also tried GL_TEXTURE_COORD_ARRAY, but both ended in segmentation fault.

Alfonse Reinheart
05-12-2015, 05:36 PM
Oh, I'm sorry; I read the wrong thing in EXT_DSA. The function you're looking for is glEnableVertexArrayAttribEXT.

Ploppz
05-13-2015, 03:45 PM
Ah. Well in the end it turned out that my GPU (or some other layer) doesn't have support for EXT... That said, since it's so uncertain whether a user has support for the extension, I think I'll just go without the extension. Thanks for the help anyway!