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 10 of 11

Thread: VBO question

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109

    VBO question

    I am converting some glBegin() / glEnd() code into using VBOs instead.

    While reading various articles about VBOs, I found it rather confusing.
    Some examples used element arrays to index into the buffer, some did not.
    Some examples used VAOs, some did not.
    Some used a vertex shader, some did not.
    So it became difficult to wrap my mind around VBOs.

    I got a sample working with just a simple dataset.
    No element array of indexes. Since my data is already formatted for triangle strips and fans.
    The index array would just be dumb list of
    [0] = 0;
    [1] = 1;
    [2] = 2;
    etc...
    My buffer was not interleaved. It just had a block of a bunch of vertices in the first half and a bunch of color values in the second half of the block. A couple calls to glVertexPointer() and glColorPointer() told it where to look for those things in the buffer.
    Then I just called glDrawArrays() and it worked.

    Now I am trying to get it setup so that it works with interleaved data. (Where color would be included with the vertex on every point in the list. Rather than being 2 seperate lists)

    For interleaved, what things are required and why?
    Do you have to use a shader?
    Do you have to use an element array?
    Do you have to use VAOs?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    Quote Originally Posted by CRasterImage View Post
    I am converting some glBegin() / glEnd() code into using VBOs instead.

    While reading various articles about VBOs, I found it rather confusing.
    "Vertex buffer objects" (VBOs) are just vertex arrays in driver memory (server-side memory).
    Whereas "client arrays" are just vertex arrays in application memory (client-side memory).

    Some examples used element arrays to index into the buffer, some did not.
    Sure. Sometimes you want glDrawElements. Sometimes you want glDrawArrays. If the latter, you don't need an index list.

    Some examples used VAOs, some did not.
    Some used a vertex shader, some did not.
    Yeah, those are side issues. Totally separate from the where you store your vertex attribute arrays.

    Now I am trying to get it setup so that it works with interleaved data....

    For interleaved, what things are required and why?
    Not a lot is required. As before, you provide the Pointer calls a pointer to the first element in each vertex attribute array. And you specify a stride value != 0 so the GPU knows how to skip over the other attributes for this vertex to the next attribute value for this vtx attribute for the next vertex.

    More on pointer to the first element: 1) In the case of interleaved vtx attribute arrays in client arrays, you'd specify the actual starting CPU address of each vertex attribute for the pointer attribute. 2) In the case of interleaved vtx attribute arrays in VBOs, you'd specify the byte offset into the VBO for each vertex attribute for the pointer attribute (e.g. 0 = vertex, 12 = normal, etc.). and 3) In the case of NV bindless VBOs, you'd specify the GPU address for each vertex attribute for the pointer attribute.

    Do you have to use a shader?
    Nope.

    Do you have to use an element array?
    Nope. glDrawArrays*() calls work just fine without one. If you're using glDraw*Elements*(), then you should however.

    Do you have to use VAOs?
    Nope.

    Above I'm assuming a compatibility profile (the default). If you're allocating a core profile, then the answers are Yes/No/Yes IIRC (as the core profile obsoletes the fixed-function pipeline and requires use of VAOs).
    Last edited by Dark Photon; 10-22-2012 at 06:36 PM.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    Could you explain what "core profile" means?

    I will post my code later, with: no VAO, no element array and no shader.
    Maybe someone will see what I am missing.

  4. #4

  5. #5
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Phoenix, AZ
    Posts
    109
    When you use glVertexAttribPointer() doesn't the first parameter have to be an attribute taken from a vertex shader?
    Or is there some predefined attribute numbers for vertices, colors, texture coords, etc... ?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    No, it can either by linker generated or explicit:

    Code :
    // explicit attribute index
    layout(location = 0) in vec4 Position;

Tags for this Thread

Posting Permissions

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