[question]how to optimize vbo

This topic contains 1 reply, has 2 voices, and was last updated by  Gordon 6 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30406

    cty41
    Member

      Hi, guys. I am newbies for opengl (and es), and now I am developing a ipad game, we have finish most of the game, now we plan to optimize it(for quick develop and save money~, we just use most functions and classes which powervr sdk support).
     
      now our fps is pretty (the best scene is 34~36 when polys num is about 16k, the worse is about 10 when polys num is about 40k),I know the performance is depend on many factors, so I thought and searched for a while. and I wonder whether we use vbo correctly, because we found very strange that some place we use vbo can boost the fps but some another place it did negative effort(slow donw the fps!?):
      we just followed and trainning course(07_IntroducingPOD) and create single vbo and index vbo for each submesh in a model, but these days I read the <POWERVR SGX.OpenGL ES 2.0 Application Development Recommendations.1.8f.External> , it suggest just not to do that ,and group meshes to create a big vbo, But I am a little confused how to write these code.

      here is my setup vbo code for <07_IntroducingPOD>(did not change other parts):
    bool OGLES2IntroducingPOD::LoadVbos(CPVRTString* pErrorStr)
    {
        if(!m_Scene.pMesh[0].pInterleaved)
        {
            *pErrorStr = “ERROR: IntroducingPOD requires the pod data to be interleaved. Please re-export with the interleaved option enabled.”;
            return false;
        }

        if (!m_puiVbo)      m_puiVbo = new GLuint[m_Scene.nNumMesh];
        if (!m_puiIndexVbo) m_puiIndexVbo = new GLuint[m_Scene.nNumMesh];

        //pool test
        glGenBuffers(1, &m_VboPools);
        glGenBuffers(1, &m_IndexVboPools);

        //m_VboPools = 0, m_IndexVboPools = 0;
        unsigned int wholeMeshSize = 0, wholeIndexSize = 0;
        for (unsigned int i = 0; i < m_Scene.nNumMesh; ++i)
        {
            SPODMesh& Mesh = m_Scene.pMesh;
            unsigned int uiSize = Mesh.nNumVertex * Mesh.sVertex.nStride;
            wholeMeshSize += uiSize;
            if (Mesh.sFaces.pData)
            {
                unsigned int uiIndexSize = PVRTModelPODCountIndices(Mesh) * sizeof(GLshort);
                wholeIndexSize += uiIndexSize;
            }
        }

        //vbo
        glBindBuffer(GL_ARRAY_BUFFER, m_VboPools);
        glBufferData(GL_ARRAY_BUFFER, wholeMeshSize, 0, GL_STATIC_DRAW);

        //index vbo
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexVboPools);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, wholeIndexSize, 0, GL_STATIC_DRAW);

        unsigned int meshOffset = 0, indexOffset = 0;
        for (unsigned int i = 0; i < m_Scene.nNumMesh; ++i)
        {
            // Load vertex data into buffer object
            SPODMesh& Mesh = m_Scene.pMesh
    ;
            unsigned int uiSize = Mesh.nNumVertex * Mesh.sVertex.nStride;
            glBufferSubData(GL_ARRAY_BUFFER, meshOffset, uiSize, Mesh.pInterleaved);
            meshOffset += uiSize;
            if (Mesh.sFaces.pData)
            {
                uiSize = PVRTModelPODCountIndices(Mesh) * sizeof(GLshort);
                glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, indexOffset, uiSize, Mesh.sFaces.pData);
            }
            indexOffset += uiSize;
           
        }
    }
    ….
    void OGLES2IntroducingPOD::DrawMesh(int i32NodeIndex)
    {
    ..
        // test
        glBindBuffer(GL_ARRAY_BUFFER, m_VboPools);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexVboPools);

    }

      but  I got some wrong  result, here is pics:
    wrong:
    http://i965.photobucket.com/albums/ae134/cty41/w2.jpg
    right:
    http://i965.photobucket.com/albums/ae134/cty41/r1.jpg

    I thought there is some steps I forgot to set( I only create a big vbo and copy the mesh data to it), but I did not find any sources to tell me how to do, so is there anyone who can give a advice or any informations? I will be very appericated!

    Best regards,
    Franky

    #34656

    Gordon
    Moderator

    How do you know that the number of VBOs is what is affecting your framerate? Have you profiled your application with Apple’s profiling tools?

    You are correct, that, if meshes can be drawn without changing state (textures, shaders etc.) then it can be better to draw them with a single call. In this example, the base of the arm doesn’t use the same texture as the arm itself so it will never look the same, however.

    Have you looked at the GL_OES_vertex_array_object extension?

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.