我会四处寻找适合您的缓冲区大小,并在可能的情况下将您的垂直数据组合到 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 上上下交换东西是昂贵的。试错是游戏的名称(游戏正在编程)。