簡體   English   中英

在OpenGL中渲染網格多邊形 - 非常慢

[英]Rendering mesh polygons in OpenGL - very slow

我最近從中間模式切換並有一個新的渲染過程。 必須有一些我不理解的東西。 我認為它與指數有關。

這是我的圖: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和優化的人來幫助我。

如果您一次只渲染3個頂點,則使用數組渲染沒有意義。 這個想法是通過一次通話發送數千個 也就是說,通過一次調用渲染單個“多邊形陣列”或“網格”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM