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 8 of 8

Thread: the use of glDrawElementsBaseVertex()

  1. #1
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    82

    Unhappy the use of glDrawElementsBaseVertex()

    I am drawing an animated model of several frames. Say the model consists of 1000 vertices, and I want to render 5 frames.

    I stored the vertex positions of the five frames in a large buffer, the size of which is sizeof(float) * 1000 * 3 * 5. During rendering I do not want to change the model color, so I stored the vertex color in another buffer which is of the size sizeof(float) * 1000 * 3.

    But I have run into the problem of rendering it. I once thought of using glDrawElementsBaseVertex() that accepts an offset so I can render vertices of different frames, but the color array is shorter than the position array, so only the first frame has color associated with it. How can I solve this problem?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728
    I stored the vertex positions of the five frames in a large buffer, the size of which is sizeof(float) * 1000 * 3 * 5. During rendering I do not want to change the model color, so I stored the vertex color in another buffer which is of the size sizeof(float) * 1000 * 3.
    This situation has nothing to do with base vertex. You can't add a base index to only some of the attribute indices. Just as you can't have different indices for different attributes.

  3. #3
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    82
    Thanks for your reply.
    What should I do? Allocate the same size of space as the position buffer for the color buffer and repeat the color value five times?
    Is there any better solution for this?
    Last edited by shapeare; 07-20-2012 at 10:37 AM.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882
    Could use a diff block or buffer for vtx attribs that chg vs stay the same. Then share those that are the same.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965
    Just change the offset in your glVertexAttribPointer calls for position. Color remains the same - offset 0 - but make a glVertexAttribPointer call for position with offset sizeof(float) * 1000 * 3 * framenum. You'd need to separate position and color into different VBOs, and with only 5 frames you could even create 5 separate VAOs, one for each frame.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728
    Allocate the same size of space as the position buffer for the color buffer and repeat the color value five times?
    It depends: how much does the added performance of base vertex matter to you? It's a memory-for-performance tradeoff.

    If this is a real issue, profile it and see what the difference is.

  7. #7
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    82
    Thanks for the replies.


    Quote Originally Posted by mhagain View Post
    Just change the offset in your glVertexAttribPointer calls for position. Color remains the same - offset 0 - but make a glVertexAttribPointer call for position with offset sizeof(float) * 1000 * 3 * framenum. You'd need to separate position and color into different VBOs, and with only 5 frames you could even create 5 separate VAOs, one for each frame.
    Thank you very much. But I did not separate position and color into different VBOs. it works by only changing the offset for glVertexAttribPointer() of the position array before the rendering of each frame.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    There is also another alternative:

    If you want to keep the color the same but change the rest, you can put your color into another buffer that you bind as a texture buffer and fetch the color separately using texture buffer fetches in your vertex shader.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

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