开发者

vbo management in opengl

I have different models that I want to render in OpenGL. Every model has different vertices and indices.

What is the best practice that I should follow when rendering these models using vbo? Should i make a VBO for each model in order to render it? I've开发者_开发百科 read that using several small VBOs will be a big performance hit as well as using few big VBOs.

For example: I have a box and a car next to it, where the box is of 8 vertices and the car is of 2000 vertices, which is totally different number. I have different models and they might disappear sometimes as well, which means that these models should be removed from the server-side buffer. How can I do that ?

Maybe someone could guide me to an article that clears this confusion and show a good way to handle my situation.


I would play around and find a buffer size that works well for you and the combine your vert data into VBOs if possible. Your target hardware is really what's going to dictate this, so it's best to play around with different numbers.

Use some class to reference the offset in the VBO that your model should actually use for rendering. For example, you have the box and the car.

class MeshManager
{
public:
    int loadMesh(const Mesh * mesh)
    {
        //load the mesh
        //Add it to some current VBO or manage the creation of VBOs better.
        ManagedMesh managedMesh(theVao, theVbo, theOffset, theLength, theType, theIdentifier);
        theIdentifier++;
    }
private:
    std::map<std::string, ManagedMesh> meshMap;
    int theIdentifier;
}

class Renderer
{
public:
    void render(int meshId, Vector3f translation, Vector3f rotation);
}

int main(int argc, char** argv)
{
MeshManager meshManager;
Model model("mymodel.obj");
const Mesh * meshes = model.getMeshes();
int meshCount = model.getMeshCount();
for(int i=0; i<meshCount; i++)
{
    meshManager.loadMesh(mesh);
}
model.freeMeshes();
}

something of the sort. Obviously I'm not storing off those loaded mesh ids, but I think you get the picture. I'm not expert, but this is a rough example about how I would go about it. Also remember to try and batch rendering as much as possible. Sort your rendering by 1) the VBOs you need loaded 2) the materials you need loaded. Swapping things on and off the GPU constantly is costly. Trial and error is the name of the game (the game being Programming).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜