在OpenGL中渲染网格多边形-非常慢
Rendering mesh polygons in OpenGL - very slow
我最近从中间模式切换,并有一个新的渲染过程。一定有什么地方我不明白。我想这和指标有关。
这是我的图表:区域->网格->多边形数组->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和优化的人来帮我做这件事。
如果你一次只渲染3个顶点,那么使用数组渲染是没有意义的。这个想法是通过一个调用发送数千个。也就是说,你渲染一个单一的"多边形数组"或"网格"调用。
相关文章:
- OpenGL大的3D纹理(>2GB)非常慢
- 为什么需要复制构造函数,在哪些情况下它们非常有用
- 计算缩放多边形的比例,得到给定的多边形面积
- 为什么std::互斥需要很长的、非常不规则的时间来共享
- 将QGraphicsItem的移动区域限制在多边形区域内
- G++ C++17 类模板参数推导在非常特殊的情况下不起作用
- 使用浮点数和双精度数的非常小数字的数学
- 重新排列单线以形成闭合多边形?
- 提升几何体:C++并集多个多边形
- 在 QT C++中绘制/操作多边形
- Maya API C++:从多边形获取材质
- 在打开多个其他窗口时使用全屏窗口时帧速率非常低
- 我从int x[3]得到的一个非常奇怪的输出;
- 反向迭代器在C++中非常奇怪的行为
- 添加带有提升的多边形::p奥利贡不编译?
- 使用 C++在 OpenGL 中对 3D 多边形进行纹理处理
- 使用 C++在 OpenGL 中移动自动旋转的 3D 多边形
- 如何使用增强::几何计算多边形的旋转固体体积?
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 在OpenGL中渲染网格多边形-非常慢