Results 1 to 6 of 6

Thread: Working with multiple VBO's

  1. #1
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Working with multiple VBO's

    I have modified my code to use two different VBO's...one for the static walls, and one for the user path that changes almost every frame. This is to speed up processing on the backend, so I don't have to redo the walls every time I change paths.

    I basically duplicated all of my VBO code. Problem is when I get down to my glDrawElements (which is in my render call), I can't figure out how to tell it WHICH buffer to draw from.

    Do I need to do something with my ClientState or something to switch which buffer I'm drawing from?

    Edit: Update: I was getting a crash because one of the buffers was being passed an empty index array. I added at least two to keep it from crashing (there's no pathing info at the start) and it now works...but its still only drawing from the second VBO.

    I'm calling glDrawElements and passing it the first array of indices, and it doesn't do anything, but it is drawing the stuff from the second VBO's indices when I call glDrawElements a second time and pass it the second set of indices.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Working with multiple VBO's

    Forgot to bind the vbo ?

    Here is a (random) tutorial about VBO I found: http://www.ozone3d.net/tutorials/opengl_vbo.php

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,651

    Re: Working with multiple VBO's

    Quote Originally Posted by Robbie
    I have modified my code to use two different VBO's...one for the static walls, and one for the user path that changes almost every frame....but its still only drawing from the second VBO.
    Let's see your VBO bind, update, and batch dispatch code.

    Once you get this 2-VBO approach working, be sure to bench this (with the maximum number of VBO binds) against using a single VBO. Lots of VBO binding really hurts perf. To avoid, use one VBO (or avoid buffer binds when at all possible), or use NV bindless (or display lists).

  4. #4
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: Working with multiple VBO's

    I decided based on your suggestions and further reading to avoid the multiple VBO approach, and decided to optimize my VBO recreation code. For example, I've separated the code that plots the vertices, indices, colors for the walls, and am only recreating the indices for the pathing when necessary. Problem I'm having now is that I'm unable to use the resize method of the vector class without throwing an error.

    I have two structs in my header file, one for Vertex(x, y, z) and one for Color(r, g, b). Those are what I'm adding to the vertex vector array and the color vector array.

    Code :
    m_vertices.push_back(Vertex(1.0f, 2.0f, -1.0f));
    m_colors.push_back(Color(1.0f, 1.0f, 1.0f));

    I'm using:
    Code :
    m_vertices.resize(wallVertexCount);
    m_colors.resize(wallVertexCount);
    to dump all the vertex data for the paths, leaving only the vertex data for the walls in the arrays. But this throws a error C2512: 'Vertex:Vertex' : no appropriate default constructor available.

    my structs look like this:
    Code :
    struct Vertex {
      float x, y, z;
      Vertex(float x, float y, float z)
      {
        this->x = x;
        this->y = y;
        this->z = z;
      }
    };
    struct Color {
      float r, g, b;
      Vertex(float r, float g, float b)
      {
        this->r = r;
        this->g = g;
        this->b = b;
      }
    };

    Do I need to modify my structs to allow the resize method to work?

  5. #5
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: Working with multiple VBO's

    Quote Originally Posted by Robbie
    error C2512: 'Vertex:Vertex' : no appropriate default constructor available.
    Add default values to your constructors
    Code :
    Vertex(float x = 0.0f, float y = 0.0f, float z = 0.0f)

  6. #6
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: Working with multiple VBO's

    Ahh. Thanks!

    I worked around it by modifying my code to modify the vertices instead of dump them and replot them. It's working quite well actually.

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2018, 08:16 AM
  2. Replies: 0
    Last Post: 04-27-2018, 08:20 PM
  3. Multiple texcoord arrays=sure, multiple color streams?
    By mattropolis in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-01-2014, 07:52 AM
  4. Replies: 1
    Last Post: 11-18-2011, 08:13 AM
  5. Multiple X session, OpenGL stops working!!
    By sleepkreep in forum OpenGL: Linux
    Replies: 12
    Last Post: 06-21-2005, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean