2

Is it possible to place a set of Vertices into a VBO, but take the Index and Texture coord. Arrays from regular memory? If yes, which syntax to use?

1 Answer 1

4

Yes, it is possible to do this. But you shouldn't.

The reason to use buffer objects is to improve performance. Doing what you suggest simply reduces the performance you would have gained by properly using buffer objects.

Also, it's a driver path that most drivers don't see very often. Either people use buffer objects for vertex data, or they use client memory arrays. Since it's a road less traveled, you're more likely to encounter driver bugs.

The syntax is just the regular syntax. The gl*Pointer calls use buffer objects or not based on whether a buffer object is bound to GL_ARRAY_BUFFER at the time the gl*Pointer call is made. As such, you can bind a buffer to GL_ARRAY_BUFFER, make a gl*Pointer call with an offset, then bind 0 to GL_ARRAY_BUFFER and make a gl*Pointer call with an actual pointer.

Similarly, the glDraw*Elements* calls use a buffer object if a buffer is bound to GL_ELEMENT_ARRAY_BUFFER. So if you want to use client memory for these functions, bind 0 to that.

Sign up to request clarification or add additional context in comments.

6 Comments

In addition to this quite good answer: You can always set a usage of GL_DYNAMIC_DRAW or GL_STREAM_DRAW if your texCoord and index buffers' data changes frequently. If this was the reason you wanted them to be sourced from CPU memory.
That is indeed my objective. But the problem is - I cannot stream that much of memory into the buffer object each frame without loosing performance. (I would have to restream it several hundred times before swap buffer). My idea was to place the vertices into GPU memory since these are never updated and create all sets of indices and texture coord. in RAM (since it is much larger then GPU memory). That way I do not need to copy any memory each frame at all - I just can pick the right array in regular memory as needed.
Would it be more convenient and maybe performing faster, if I placed all of the data in CPU and did not use VBO at all?
@Fejwin: If you are rendering so much vertex data that streaming breaks down for you, why do you think that the driver (which has to DMA it from your client arrays) will be able to do a better job? Are you streaming correctly? Also, you should test it yourself to see if it gives better performance.
@Fejwin: Binding to modify a buffer object is "free" (to the extent that the modifications are "free"). Binding to use one is not.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.