首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在OpenGL中渲染网格多边形-非常慢

在OpenGL中渲染网格多边形-非常慢
EN

Stack Overflow用户
提问于 2011-08-09 12:43:49
回答 1查看 1.7K关注 0票数 3

我最近从中间模式切换到了一个新的渲染进程。一定有什么我不明白的地方。我认为这与指数有关。

这是我的图表: Region->Mesh->Polygon Array->3个顶点索引,它引用了顶点的主列表。

下面是我的渲染代码:

代码语言:javascript
复制
// 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和优化的人来帮我做这件事。

EN

Stack Overflow用户

回答已采纳

发布于 2011-08-09 13:22:31

如果一次只渲染3个顶点,那么使用数组渲染是没有意义的。这个想法是通过一个单一的呼叫发送数千人。也就是说,您可以通过一次调用来呈现单个“多边形数组”或“网格”。

票数 8
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6991453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档