我最近从中间模式切换,并有一个新的渲染过程。必须有一些我不了解的东西。我认为这与指数有关。在OpenGL中渲染网格多边形 - 非常慢
这是我的图:Region-> Mesh-> Polygon Array-> 3个顶点索引,它们引用主节点的顶点列表。
我在这里的渲染代码:
// Render the mesh
void WLD::render(GLuint* textures, long curRegion, CFrustum cfrustum)
{
int num = 0;
// Set up rendering states
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Set up my indices
GLuint indices[3];
// Cycle through the PVS
while(num < regions[curRegion].visibility.size())
{
int i = regions[curRegion].visibility[num];
// Make sure the region is not "dead"
if(!regions[i].dead && regions[i].meshptr != NULL)
{
// Check to see if the mesh is in the frustum
if(cfrustum.BoxInFrustum(regions[i].meshptr->min[0], regions[i].meshptr->min[2], regions[i].meshptr->min[1], regions[i].meshptr->max[0], regions[i].meshptr->max[2], regions[i].meshptr->max[1]))
{
// Cycle through every polygon in the mesh and render it
for(int j = 0; j < regions[i].meshptr->polygonCount; j++)
{
// Assign the index for the polygon to the index in the huge vertex array
// This I think, is redundant
indices[0] = regions[i].meshptr->poly[j].vertIndex[0];
indices[1] = regions[i].meshptr->poly[j].vertIndex[1];
indices[2] = regions[i].meshptr->poly[j].vertIndex[2];
// Enable texturing and bind the appropriate texture
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[regions[i].meshptr->poly[j].tex]);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &vertices[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &vertices[0].u);
// Draw
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices);
}
}
}
num++;
}
// End of rendering - disable states
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
很抱歉,如果我留下任何东西了。我非常感谢反馈并为此提供帮助。我甚至会考虑给一个善于使用OpenGL和优化的人来帮助我。
我已经做到了,所以它只在调用当前未绑定的纹理时绑定纹理。这增加了大约10-15的FPS。 –
排列网格数据,以便可以在一个glDrawElements调用中绘制具有相同纹理的所有多边形。因此,不是循环每个多边形,而是循环一些类似于meshptr-> textureCount的地方,其中存储了该纹理的索引和纹理ID。你只需要在循环之外或初始化时启用gl_texture_2d。此外,如果您有对网格内容的控制,请尝试为整个网格(或几个网格)使用单个纹理。 –