Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: DSA: Segmentation fault when setting attribute pointers.

  1. #1
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    11

    DSA: Segmentation fault when setting attribute pointers.

    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:
    Code :
    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:
    Code :
    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 is more of the context, and here 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!

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,015
    Code :
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    11
    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).

  4. #4
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,015
    Quote Originally Posted by Ploppz View Post
    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.

    Quote Originally Posted by Ploppz View Post
    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:

    Code :
    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);
    }

  5. #5
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    11
    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.

  6. #6
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,015
    Oh, I'm sorry; I read the wrong thing in EXT_DSA. The function you're looking for is glEnableVertexArrayAttribEXT.

  7. #7
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    11
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •