[英]Rendering mesh polygons in OpenGL - very slow
I recently switched from intermediate mode and have a new rendering process. 我最近从中间模式切换并有一个新的渲染过程。 There must be something I am not understanding.
必须有一些我不理解的东西。 I think it has something to do with the indices.
我认为它与指数有关。
Here is my diagram: Region->Mesh->Polygon Array->3 vertex indices which references the master list of vertices. 这是我的图:Region-> Mesh-> Polygon Array-> 3个顶点索引,它们引用顶点的主列表。
Here my render code: 这是我的渲染代码:
// 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);
}
Sorry if I left anything out. 对不起,如果我遗漏了什么。 And I really appreciate feedback and help with this.
我非常感谢您的反馈和帮助。 I would even consider paying someone who is good with OpenGL and optimization to help me with this.
我甚至会考虑付给那些擅长OpenGL和优化的人来帮助我。
There is no point in using array rendering if you're only rendering 3 vertices at a time. 如果您一次只渲染3个顶点,则使用数组渲染没有意义。 The idea is to send thousands through with a single call.
这个想法是通过一次通话发送数千个 。 That is, you render a single "Polygon Array" or "Mesh" with one call.
也就是说,通过一次调用渲染单个“多边形阵列”或“网格”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.