【问题标题】:vbo management in openglopengl中的vbo管理
【发布时间】:2011-02-08 13:36:13
【问题描述】:

我想在 OpenGL 中渲染不同的模型。每个模型都有不同的顶点和索引。

使用 vbo 渲染这些模型时,我应该遵循的最佳做法是什么?我应该为每个模型制作一个 VBO 来渲染它吗?我已经读到使用几个小型 VBO 以及使用几个大型 VBO 都会对性能造成很大影响。

例如:我有一个盒子,旁边有一辆车,盒子有8个顶点,而车有2000个顶点,这是完全不同的数字。我有不同的模型,它们有时也会消失,这意味着这些模型应该从服务器端缓冲区中删除。我该怎么做?

也许有人可以指导我阅读一篇文章,以消除这种困惑并展示处理我的情况的好方法。

【问题讨论】:

    标签: opengl vbo


    【解决方案1】:

    我会四处寻找适合您的缓冲区大小,并在可能的情况下将您的垂直数据合并到 VBO 中。您的目标硬件确实决定了这一点,因此最好使用不同的数字。

    使用某个类来引用您的模型实际用于渲染的 VBO 中的偏移量。例如,您有盒子和汽车。

    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();
    }
    

    类似的东西。显然我没有存储那些加载的网格 ID,但我想你明白了。我不是专家,但这是一个关于我将如何去做的粗略例子。还要记住尽可能多地尝试和批量渲染。按 1) 需要加载的 VBO 2) 需要加载的材料对渲染进行排序。不断地在 GPU 上上下交换东西是昂贵的。 Trial and error 是游戏的名称(游戏是 Programming)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多