Results 1 to 7 of 7

Thread: Multiple VBO with QGLBuffer

  1. #1
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Exclamation Multiple VBO with QGLBuffer

    ---------
    SITUATION
    ---------
    In a QGraphicsView - QGraphicsScene framework ...

    I have two VBOs declared as ...

    QVarLengthArray<Vertex> mVertices1;
    QGLBuffer mVBO1;

    QVarLengthArray<Vertex> mVertices1;
    QGLBuffer mVBO2;

    They are instantiated in the scene constructor as ...

    mVBO1.create();
    mVBO1.bind();
    mVBO1.setUsagePattern(QGLBuffer::StaticDraw);
    mVBO1.allocate(mVertices1.data(), sizeof(Vertex)*nVertices1);

    mVBO2.create();
    mVBO2.bind();
    mVBO2.setUsagePattern(QGLBuffer::StaticDraw);
    mVBO2.allocate(mVertices2.data(),sizeof(Vertex)*nV ertices2);


    In the draw background method of QGraphicsScene, I am ...

    // Binding my shader program mShaderProgram.bind();
    // Initialising my attribute variables mShaderProgram.attributeLocation("
    // Enabling the attribute array mShaderProgram.enableAttributeArray( ..
    // Setting the attribute Buffer mShaderProgram.setAttributeBuffer(...


    Further, the draw calls are made as below ...

    if (mVBO1.bind()) // mVBO1 draw block
    {
    glDrawArrays(GL_LINES,0,nVertices1);
    // mVBO1.release();
    }

    if (mVBO2.bind()) // mVBO2 draw block
    {
    glDrawArrays(GL_LINE_STRIP,0,nVertices2);
    //mVBO2.release();
    }

    Finally in the drawbackground method itself ..

    // Disabling the attribute arrays mShaderProgram.disableAttributeArray(...
    // Releasing the shader program mShaderProgram.release();


    ---------
    PROBLEMS
    ---------
    Independently, each of the "if" blocks shown above render the expected values.

    However, when i wish to use both the VBOs together (mVBO1 and mVBO2), during the second or subsequent rendering loops
    glDrawArrays within mVBO1 draw block will render nVertices1 values as GL_LINES from mVBO2 [mVertices2.data]

    I tried releasing the VBOs (mVBO2.release()) but that results in a crash at glDrawArrays(GL_LINES,0,nVertices1);

    Any help, ideas to fix this is greatly appreciated.

    Note .. Binding the QGLBuffers (VBOs) return true, their buffer ids are also distinct when checked using the QGLBuffers::bufferid() api !!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple VBO with QGLBuffer

    How do you want to use them "together"? I think only one buffer can be bound at the same time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Multiple VBO with QGLBuffer

    Yes, I agree that only one buffer can be bound at the same time.
    I want to use two vertex buffer objects.
    .. Bind one and draw from it.
    .. Then bind the other one and draw from the second one.

    I do not release the buffer objects as they result in the program crashing !!

    I have attached sample project using QT 4.8 that demonstrates the problem.
    Comments in scene.cpp line 98-102 describe the problem
    /* PROBLEM !!
    * The follwing glDrawArrays (GL_LINE_STRIP ... renders from VBO2 !!
    * Instead of the horizontal line strip in red color, this draws the vertical line strip with data from VBO2
    * If the mVB02.bind() block below is commented then the red horizontal strip is drawn correctly.
    */
    Attached Files Attached Files
    Last edited by brijesh; 22nd March 2013 at 05:23.

  4. #4
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple VBO with QGLBuffer

    You should initialize QVarLengthArrays prior to their use
    Qt Code:
    1. nVertices1 = 4;
    2. mVertices1.resize(nVertices1);
    To copy to clipboard, switch view to plain text mode 
    (the same for the second array)

  5. #5
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Multiple VBO with QGLBuffer

    Qt doc says QVarLengthArray is default initialised to 256 if not specified.
    Nevertheless, I tried your suggestion
    .. mVertices1.resize(4);
    as well as
    .. mVertices2.resize(8);

    But that did not solve my problem

    Is the code working on your machine with those changes and rendering both the red horizontal lines & blue vertical lines ?

  6. #6
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple VBO with QGLBuffer

    Qt Code:
    1. mShaderProgram.setAttributeBuffer(inPositionLocation, GL_FLOAT, 0, 3, sizeof(MyVertex));
    2. mShaderProgram.setAttributeBuffer(inColorLocation, GL_FLOAT, 12, 3, sizeof(MyVertex));
    To copy to clipboard, switch view to plain text mode 
    From the docs:
    Sets an array of vertex values on the attribute at location in this shader program, starting at a specific offset in the currently bound vertex buffer.
    So you should call it after you bind specific buffer, I get it to work with the following code:
    Qt Code:
    1. if (mVBO1.bind()) {
    2. mShaderProgram.setAttributeBuffer(inPositionLocation, GL_FLOAT, 0, 3, sizeof(MyVertex));
    3. mShaderProgram.setAttributeBuffer(inColorLocation, GL_FLOAT, 12, 3, sizeof(MyVertex));
    4. glDrawArrays(GL_LINES,0,nVertices1);
    5. }
    6. if (mVBO2.bind())
    7. {
    8. mShaderProgram.setAttributeBuffer(inPositionLocation, GL_FLOAT, 0, 3, sizeof(MyVertex));
    9. mShaderProgram.setAttributeBuffer(inColorLocation, GL_FLOAT, 12, 3, sizeof(MyVertex));
    10. glDrawArrays(GL_LINES,0,nVertices2);
    11. }
    To copy to clipboard, switch view to plain text mode 
    So in your case these commands were executed with second buffer still bound from the previous call (and hence crash when you tried to release buffer).
    Last edited by lanz; 22nd March 2013 at 12:59. Reason: Wrong tag

  7. The following user says thank you to lanz for this useful post:

    brijesh (22nd March 2013)

  8. #7
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Thumbs up Re: Multiple VBO with QGLBuffer

    Thanks for the solution.
    That works perfect !!

Similar Threads

  1. Using QGLBuffer and QGLWidget::renderText problem.
    By oleg_stepanenko@bk.ru in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2012, 11:59
  2. Replies: 2
    Last Post: 19th October 2011, 10:30
  3. Replies: 1
    Last Post: 17th May 2011, 17:12
  4. QGLBuffer instead of Vertex Buffer Object -> How To?
    By FlashMuller in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2010, 12:41
  5. Replies: 0
    Last Post: 21st December 2006, 12:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.