Results 1 to 10 of 10

Thread: Vertex Buffer Object with worldwind

  1. #1

    Default Vertex Buffer Object with worldwind

    Hi All,

    I am looking to render many many points (millions) around the globe. I read a few online resources on how jogl can handle this. It looks like it comes down to Display List, Vertex Array and Vertex Buffer Object (VBO). I have tried the first two options, the performance is average, when I setup my code to use VBO, the globe stopped rendering and exception is generated constantly provided below. Does Worldwind not support VBO? Thanks a bunch for the help.

    Jan 7, 2010 9:01:35 AM gov.nasa.worldwind.render.SurfaceTileRen derer renderTiles
    SEVERE: Exception while rendering layer gov.nasa.worldwind.render.GeographicSurf aceTileRenderer
    javax.media.opengl.GLException: array vertex_buffer_object must be disabled to call this method
    at com.sun.opengl.impl.GLImpl.checkBufferOb ject(GLImpl.java:30667)
    at com.sun.opengl.impl.GLImpl.checkArrayVBO Disabled(GLImpl.java:30715)
    at com.sun.opengl.impl.GLImpl.glVertexPoint er(GLImpl.java:27936)
    at gov.nasa.worldwind.terrain.RectangularTe ssellator.render(Unknown Source)
    at gov.nasa.worldwind.terrain.RectangularTe ssellator.renderMultiTexture(Unknown Source)
    at gov.nasa.worldwind.terrain.RectangularTe ssellator.access$000(Unknown Source)
    at gov.nasa.worldwind.terrain.RectangularTe ssellator$RectTile.renderMultiTexture(Un known Source)
    at gov.nasa.worldwind.render.SurfaceTileRen derer.renderTiles(Unknown Source)
    at gov.nasa.worldwind.layers.TiledImageLaye r.draw(Unknown Source)
    at gov.nasa.worldwind.layers.TiledImageLaye r.doRender(Unknown Source)
    at gov.nasa.worldwind.layers.AbstractLayer. render(Unknown Source)
    at gov.nasa.worldwind.layers.TiledImageLaye r.render(Unknown Source)
    at gov.nasa.worldwind.AbstractSceneControll er.draw(Unknown Source)
    at gov.nasa.worldwind.BasicSceneController. doRepaint(Unknown Source)
    at gov.nasa.worldwind.AbstractSceneControll er.repaint(Unknown Source)
    at gov.nasa.worldwind.WorldWindowGLAutoDraw able.doDisplay(Unknown Source)
    at gov.nasa.worldwind.WorldWindowGLAutoDraw able.display(Unknown Source)

  2. #2
    WWJ Dev. Team
    Join Date
    May 2007
    Location
    Seattle
    Posts
    519

    Default

    Hi jason_liu,

    WorldWind does nothing to prevent you from implementing custom GL code which uses Vertex Buffer Objects, or any other GL feature for that matter.

    It looks to me like you're custom code is leaking GL state. Here's an snippet which demonstrates what your VBO usage should look like:

    Code:
    // Save the current GL buffer binding state. 
    OGLStackHandler ogsh = new OGLStackHandler();
    ogsh.pushClientAttrib(gl, GL.GL_CLIENT_VERTEX_ARRAY_BIT);
    try
    {
        // Bind your vertex buffer object, and use it as the source of vertex
        // coordinates when glDrawArrays() is executed. 
        gl.glBindBuffer(...);
        gl.glVertexPointer(...);
        gl.glDrawArrays(...);
    }
    finally
    {
        // Restore the previous GL buffer binding state.
        ogsh.pop(gl);
    }
    Note the usage of OGLStackHandler in the try/finally block. We use this pattern internally in WorldWind to prevent GL state leaks, even when an exception occurs during rendering. This is a useful pattern, and we recommend using it in your own GL code.

    Please compare your code with the above snippet, and let me know if there are any key differences.

    Thanks,
    Dave

  3. #3

    Default

    Thank you for the quick reply, the above code works perfectly. I'm not sure if I had a leak or not, but after putting my code into the try finally block, it works. One thing though is that I am changing the values of the points each frame randomly.

    Code Block below, anything seems wrong with this?

    //VBO
    vbuffer = setupBuffer(xyz[0], xyz[1], xyz[2]);
    vbuffer.rewind();
    OGLStackHandler ogsh = new OGLStackHandler();
    ogsh.pushClientAttrib(gl, GL.GL_CLIENT_VERTEX_ARRAY_BIT);
    gl.glColor3f(Color.pink.getRed(), Color.pink.getBlue(), Color.pink.getGreen());
    try {
    gl.glGenBuffersARB(1, VBOVertices, 0); // Get A Valid Name
    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_AR B, VBOVertices[0]); // Bind The Buffer
    // Load The Data
    gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_AR B, numOfPoints * 3 *
    BufferUtil.SIZEOF_FLOAT, vbuffer, GL.GL_STATIC_DRAW_AR;

    // Enable Pointers
    gl.glEnableClientState(GL.GL_VERTEX_ARRA Y); // Enable Vertex Arrays
    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_AR B, this.VBOVertices[0]);
    // Set The Vertex Pointer To The Vertex Buffer
    gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);

    // Render
    // Draw All Of The points At Once
    gl.glDrawArrays(GL.GL_POINTS, 0, numOfPoints);

    // Disable Pointers
    // Disable Vertex Arrays
    gl.glDisableClientState(GL.GL_VERTEX_ARR AY);
    } finally {
    ogsh.pop(gl);
    }

  4. #4
    WWJ Dev. Team
    Join Date
    May 2007
    Location
    Seattle
    Posts
    519

    Default

    I'm unclear on what the new problem is. Are you encountering an issue trying to use the above code block? If so, what is the issue?

    Thanks,
    Dave

  5. #5

    Default

    I apologize for the confusion.

    I included the code block above for the VBO because I thought I had done something wrong that caused the "leaking GL state" that you mentioned. As I mentioned before, what I have seems to work now. I just want to make sure I'm not doing something wrong in my code that is just getting caught by the finally clause.

    Thanks again for your help.

  6. #6
    WWJ Dev. Team
    Join Date
    May 2007
    Location
    Seattle
    Posts
    519

    Default

    Ah, I see what you meant now. Thanks for clarifying.

    The original code block invoked glBindBuffer(GL_ARRAY_BUFFER, id), which sets the GL vertex buffer binding state. To avoid leaking GL state, you must follow this with a call to glBindBuffer(GL_ARRAY_BUFFER, 0), or even better just push/pop the appropriate attribute bits.

    Finally, here are two quick recommendations:
    * It's more general to push/pop attributes than to explicitly enable/disable state. You can't know what the current GL state was when your code runs without invoking glGet__(), which can stall the GL pipeline and hurt performance.
    * The call to glDisableClientState() is unecessary. That's now handled by pushing/poping the client attribute bit GL_CLIENT_VERTEX_ARRAY_BIT.

    Thanks,
    Dave

  7. #7
    WWJ Technical Manager
    Join Date
    May 2007
    Location
    Seattle
    Posts
    1,114

    Default

    Be aware that VBOs are not uniformly the highest performance rendering option. WWJ actually has a VBO path for terrain, but because it's slower than the regular path on some important devices -- most modern Macs -- we leave it disabled by default.

  8. #8
    Super Moderator
    Join Date
    Nov 2006
    Location
    Mojave & Oxnard California
    Posts
    2,859

    Default

    "... modern Macs --" seems like a contradiction.
    "You should lobby Apple to get back on the wagon!"
    http://forum.worldwindcentral.com/sh...ighlight=wagon

    Would the VBO path for terrain be faster (for those not using Mac) and if so how could we enable it?

    jason_liu: How many points have you been able to render before a performance problem?

  9. #9
    WWJ Technical Manager
    Join Date
    May 2007
    Location
    Seattle
    Posts
    1,114

    Default

    It's not just Macs. That was only an example. (I should've made that clear.) Some PCs with ATI graphics also exhibit the problem, and we have no idea which other devices do. The set we know about is sufficient to cause us to disable VBOs by default.

    To enable VBOs, call the following on your WorldWindow (wwd) immediately after you create it:
    Code:
    wwd.getScenecontroller().getGLRuntimeCapabilities().setVertexBufferObjectEnabled(true)
    Even if set to true, VBOs will be used only if they're available.

    I don't know that anyone's run with VBOs recently, so hopefully it still works.

  10. #10
    Super Moderator
    Join Date
    Nov 2006
    Location
    Mojave & Oxnard California
    Posts
    2,859

    Default

    It may not work or I have done something wrong.
    After capitalizing 'c' in 'getSceneController' I get this error:
    The method setVertexBufferObjectEnabled(boolean) is undefined for the type Object

    SceneController.java line 63 in Build .321 (?)
    public Object getGLRuntimeCapabilities();
    In Build .346 SceneController.java line 77
    GLRuntimeCapabilities getGLRuntimeCapabilities();

    I may try this again when I update from .321 but probably leave it as is since having a WWJ app that will function consistently with different graphics cards is more important.
    Last edited by nlneilson; 01-09-2010 at 12:10 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reg compiling the source code
    By Raj in forum Developers' Corner
    Replies: 10
    Last Post: 08-26-2008, 06:58 PM
  2. DrawContext object
    By ribrown in forum Development Help
    Replies: 10
    Last Post: 10-19-2007, 02:11 PM
  3. Dependency injection instead of static singleton WorldWind
    By stolsvik in forum Feature Discussion
    Replies: 19
    Last Post: 08-06-2007, 02:57 PM
  4. WorldWind MenuBar object
    By Mandrake in forum Add-on & Script Development
    Replies: 3
    Last Post: 08-17-2005, 01:49 PM
  5. Newbies guide to worldwind
    By Llynix in forum WorldWind General
    Replies: 14
    Last Post: 12-25-2004, 01:55 PM

Posting Permissions

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