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

Thread: creating vertex buffer object

  1. #1

    creating vertex buffer object

    Is there any way to use an array directly from CPU and not read it everytime from GPU?
    In the example below, a VBO is created and the buffer is transfered to GPU, so every time the screen gets rendered,
    it reads from GPU and not CPU. How can we modify this implementation if we don't want to keep the buffer in GPU and instead read it every time from CPU?

    Code :
        Vector3f Vertices[1];
        Vertices[0] = Vector3f(0.0f, 0.0f, 0.0f);
     
     	glGenBuffers(1, &VBO);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,201
    That's client-side vertex arrays, which have been available since OpenGL 1.1. They're deprecated in modern GL_VERSIONs which means - in practice - that they may not work seamlessly with newer functionality, but if you're coding to a pre-GL 3 target you can freely use them.

    Code :
    // ensure that no buffer is bound
    glBindBuffer (GL_ARRAY_BUFFER, 0);
     
    // data to draw with
    float data[] = {/* vertex data goes here */};
     
    // set up arrays
    glEnableVertexAttribArray (0);
    glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, sizeof (float) * 3, data);
     
    // draw a single triangle from the enabled array pointers
    glDrawArrays (GL_TRIANGLES, 0, 3);

    If all of your vertex data is static - i.e. it doesn't need to change - there's no advantage to this method. Since the GPU does the drawing it makes sense to store your vertex data on the GPU. If you're dealing with dynamic data then you have a number of options available, such as client-side arrays, immediate mode, buffer-object streaming, or even the MultiDraw commands (which may be useful in cases where the data is static but individual polys may or may not be drawn).

  3. #3
    Intern Contributor
    Join Date
    May 2013
    Posts
    67
    My guess would be that, except on very old hardware, using client-side vertex arrays is no difference then using glBufferData with GL_STREAM_DRAW as usage hint.
    With client side arrays the driver only has two options: Stall the CPU until the GPU is in sync and has drawn the array or just copy the data and put the draw command on the GPU work queue. Guess what the driver will most likely do?

Posting Permissions

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