Sign in to follow this  

Binding Buffer Objects

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

when you bind buffer objects: glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbObj); does this disable the current client states such as GL_VERTEX_ARRAY? The spec says that the buffer binding state does push/pop. so i'm assuming that this value will be restored when you do glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0). i'm just trying to figure out if I really need to update glVertexAttribPointerARB for every mesh. currently i am sorting static geometry by material and generating a vertex buffer for all surfaces that share the same material. many materials use the same shader program and have identical vertex formats, so i'm considering sorting these batches by shader (to minimize shader switching). what i'd like to do is only change glVertexAttribPointerARB when the shader changes. if the overhead is small i'll just shutup and deal with it i guess. i am also trying to determine how much my buffer objects (vertex buffer/index buffer) need to know about the vertex format. seems like they really don't need to know whats contained in the vertex, just the size. any thoughts would be appreciated.

Share this post


Link to post
Share on other sites
As far as i know client states are not enabled or disabled unless you do it yourself. Minimizing switches is always good, pointer switches i believe took more of a hit on NVIDIA cards then ATi ones (someone correct me if i am wrong) but aren't that noticeable with everything else that will be going on. I say worry about those switches last, focus on render target, shader and texture switches first.

OpenGL doesn't need to know anything about the vertex or index format when buffering, except the total size you'd like to buffer (offset into the buffer, if you are using it) and where to start reading to copy the data over.

HTH

Share this post


Link to post
Share on other sites
thanks for the insight, once i get everything organized i will run a few tests.

what i meant with the vertex format, was actually more of an object oriented design question. i basically have these objects (these are the interfaces/objects that concern themselves with vertex arrangement i guess).

ShaderSystem
MaterialSystem
Mesh
VertexBuffer
IndexBuffer

Mesh contains a vertexbuffer and/or indexbuffer. ShaderSystem contains everything related to the programmable pipeline (shaders/attributes/etc). The material system is really the persistant link between everything. Basically I'm trying to figure out who should deal with the vertex format. Currently I have the material system handling which attributes the vertex should have (vertex/normal/texcoord/binormal/etc), but not storing the size/offsets. At first I thought that the shader system would be the only class that needed to know the size/offset/index/usage for each element in the vertex structure. but it turns out that i need that data in other places for cleaner code VertexPointer/DrawElements.

It seems apparent now that the two buffer objects really only need to know the size of their contents. I'm thinking that the Mesh might be a better choice for the vertex element descriptions. Perhaps the mesh can store the data, and the ShaderSystem can calculate it. Sound logical?

btw in this context i use mesh to represent a collection of surfaces/triangles that share the same material.

Share this post


Link to post
Share on other sites
This is how i do it in my engine, i have the index buffer and vertex buffer merged into one struct. The buffer can contain almost any type of data (floats, shorts, bytes, etc), when creating it I set up a descriptor (none if its an index buffer, then just pass the size of each element) which then calculates the size of each element and can pad the data to some alignment.

A mesh or geometry chunk in my case holds two buffers (index and vertex, dont have to use both) along with other data for shaders (effectId, tags), material (ambient, diffuse, emmissive, ...), the textures (diffuse, bump, etc) and groups (with bones, currently undergoing redesign).

Then we have the shaders, each mesh is rendered through 1 or more shaders. The shaders are basically the only things that know what vertex format to expect (buffers store their format but this isn't used anywhere). The shaders are responsible for telling me how to cache the data (VBO), some might convert the data format of a buffer to something else, and how to bind the pointers (vertex, normal, texcoord, etc) for the data (data type [float, short...]). They also bind any vertex/fragment program, set the render state, enable the lights they need and whatever else they need to do. After the shaders have set this up i can simply place a call to 'glDrawElements' or 'glDrawArrays'.

My implementation is semi-based on this thread (uses the same principals but the implementation is different).

HTH

Share this post


Link to post
Share on other sites

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this