2010-06-28 5 views
0

저는 무엇을 더 이상해야할지 잘 모르겠습니다. 내가 VBO의 내 응용 프로그램을 사용하여 만든 내 CPU 사용량은 여전히 ​​70 년대와 80 년대에 간다. 내 렌더링 절차는 다음과 같이 작동합니다.VBO 및 CPU 사용량이 매우 높습니다.

카메라 변형을 으로 설정하고 모양을 테셀레이션하지 않은 경우에는 테셀레이션합니다. VBO가있는 경우 VBO 을 만듭니다. 사용하십시오.

표시 목록도 있습니다. VBO가 지원되지 않는 경우 사용할 수 있습니다. 나는 가서 PC에서 60fps로 32000 폴리 메쉬를 렌더링하고 4 % cpu를 사용하는 OpenGL 데모를 찾았습니다. vbos를 사용하여 60fps @ 약 10,000 개의 폴리곤을 렌더링하고 70-80 %를 사용합니다.

 glMatrixMode(GL_MODELVIEW); 
     glLoadIdentity(); 

     POINT hh = controls.MainGlFrame.GetMousePos(); 
     POINTFLOAT S; 
     S.x = static_cast<float>(hh.x); 
     S.y = static_cast<float>(hh.y); 
     POINTFLOAT t; 
     t.x = 256; 
     t.y = 256; 
     POINT dimensions; 
     dimensions.x = 512; 
     dimensions.y = 512; 
     glDeleteTextures(1,&texName); 
     texName = functions.CreateGradient(col,t,S,512,512,true); 

     itt = true; 
    } 
    HDC hdc; 
    PAINTSTRUCT ps; 
    glEnable(GL_MULTISAMPLE_ARB); 
    glEnable(GL_BLEND); 

    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

    hdc = BeginPaint(controls.MainGlContext.mhWnd,&ps); 

    //start OGL code 
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f); 
    if(!current.isdrawing) 
    glClear(GL_COLOR_BUFFER_BIT); 

    glPushMatrix(); 
    glTranslatef(controls.MainGlFrame.GetCameraX(), 
    controls.MainGlFrame.GetCameraY(),0); 
    //glTranslatef(current.ScalePoint.x,current.ScalePoint.y,0); 


    glScalef(current.ScaleFactor,current.ScaleFactor,current.ScaleFactor); 
    //glTranslatef(-current.ScalePoint.x,-current.ScalePoint.y,0); 


    if(!current.isdrawing) 
    { 
     for(unsigned int currentlayer = 0; currentlayer < layer.size(); ++currentlayer) 
     { 
      PolygonTesselator.Init(); 
      for(unsigned int i = 0; i < layer[currentlayer].Shapes.size(); i++) 
      { 
       if(layer[currentlayer].Shapes[i].DisplayListInt == -999) 
       { 
        gluTessNormal(PolygonTesselator.tobj, 0, 0, 1); 
        PolygonTesselator.Set_Winding_Rule(layer[currentlayer].Shapes[i].WindingRule); 
        glEnable(GL_TEXTURE_2D); 
        glBindTexture(GL_TEXTURE_2D, texName); 

        layer[currentlayer].Shapes[i].DisplayListInt = glGenLists(1); 
        glNewList(layer[currentlayer].Shapes[i].DisplayListInt,GL_COMPILE); 

        PolygonTesselator.SetDimensions(layer[currentlayer].Shapes[i].Dimensions,layer[currentlayer].Shapes[i].minima); 
        PolygonTesselator.Begin_Polygon(); 
        for(unsigned int c = 0; c < layer[currentlayer].Shapes[i].Contour.size(); ++c) 
        { 
         if(layer[currentlayer].Shapes[i].Color.a != 0) 
         { 
          PolygonTesselator.Begin_Contour(); 

          for(unsigned int j = 0; j < layer[currentlayer].Shapes[i].Contour[c].DrawingPoints.size(); ++j) 
          { 
           gluTessVertex(PolygonTesselator.tobj,&layer[currentlayer].Shapes[i].Contour[c].DrawingPoints[j][0], 
            &layer[currentlayer].Shapes[i].Contour[c].DrawingPoints[j][0]); 
          } 

          PolygonTesselator.End_Contour(); 
         } 
        } 
        PolygonTesselator.End_Polygon(); 
        glEndList(); 
        PolygonTesselator.TransferVerticies(layer[currentlayer].Shapes[i].OutPoints); 
        glGenBuffersARB(1,&layer[currentlayer].Shapes[i].VBOInt); 
        glBindBufferARB(GL_ARRAY_BUFFER_ARB,layer[currentlayer].Shapes[i].VBOInt); 
        glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * layer[currentlayer].Shapes[i].OutPoints.size(), 
         &layer[currentlayer].Shapes[i].OutPoints[0], GL_STATIC_DRAW_ARB); 

        InvalidateRect(controls.MainGlFrame.framehWnd,NULL,false); 
       } 
       else //run vbo 
       { 
        //glEnable(GL_TEXTURE_2D); 
        //glDisable(GL_TEXTURE_2D); 
        //glBindTexture(GL_TEXTURE_2D, texName); 
        glColor4f(layer[currentlayer].Shapes[i].Color.r, 
        layer[currentlayer].Shapes[i].Color.g, 
        layer[currentlayer].Shapes[i].Color.b, 
        layer[currentlayer].Shapes[i].Color.a); 
        //glColor4f(1,1,1,1); 

        glBindBufferARB(GL_ARRAY_BUFFER_ARB, layer[currentlayer].Shapes[i].VBOInt);  
        //glCallList(layer[currentlayer].Shapes[i].DisplayListInt); 
        glEnableClientState(GL_VERTEX_ARRAY); 
        glVertexPointer(2, GL_FLOAT, 0, 0); 
        glDrawArrays(GL_TRIANGLES, 0, layer[currentlayer].Shapes[i].OutPoints.size()/2); 

        glDisableClientState(GL_VERTEX_ARRAY); 
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
       } 

       glDisable(GL_TEXTURE_2D); 
       //Draw outlines 
       if(layer[currentlayer].Shapes[i].Outline.OutlinePoints.size() > 4) 
       { 
        glColor4f(layer[currentlayer].Shapes[i].Outline.OutlineColor.r 
         ,layer[currentlayer].Shapes[i].Outline.OutlineColor.g 
         ,layer[currentlayer].Shapes[i].Outline.OutlineColor.b 
         ,layer[currentlayer].Shapes[i].Outline.OutlineColor.a); 
       } 

      } 
      PolygonTesselator.End(); 
     } 
    } 

    glPopMatrix(); 

    //end OGL code 
    glFlush(); 
    SwapBuffers(hdc); 

    glDisable(GL_MULTISAMPLE_ARB); 
    EndPaint(controls.MainGlContext.mhWnd,&ps); 

} 

왜 점점 수 높은 CPU 사용량 : 여기

내 렌더링 PROC입니까?

+2

프로필러를 가져옵니다. 즉시 귀하의 질문에 답변 해드립니다. vtune을 시험판으로 사용할 수 있습니다 : 콜 그래프 샘플링 테스트로 시도해보십시오. 그러면 CPU 시간이 어디에 사용되었는지 정확히 알 수 있습니다. – stinky472

+1

맨 위 부분이 코드 단편에서 잘립니다. 누락 된 코드를 포함하도록 질문을 편집 할 수 있습니까 (또는 적어도 그곳의 정보를 설명 할 수 있습니까)? 특히,'}'에 약 18 줄이 있습니다; is는'if'에 가깝습니까? 루프? 다른 것? – bta

답변

0

어떤 조건에서 첫 번째 비트가 실행됩니까? 의심스러운 보이는 라인의 몇 가지에있다 :

glDeleteTextures(1,&texName); 
texName = functions.CreateGradient(col,t,S,512,512,true); 

은 삭제하고 질감에게 당신이 칠 때마다 다시하는 경우, 그 비싼 얻을 수 있습니다. 나는 OpenGL 부분의 비용이 얼마나 들지는 모르겠다. 텍스쳐 이름을 삭제하고 생성하는 것이 덜하다 할지라도 텍스처 데이터를 업로드하는 것이 합리적이라고 기대할 수는 있지만 아마도 CreateGradient은 본질적으로 느리다. 또는 실수로 그래픽 카드의 속도가 느린 경우가 있습니다. 또는 함수가 모든 밉맵 레벨을 작성 중입니다. 등등. 그에서 제외

, 어떤 임의의 아이디어 :

  • 본 구간은 무엇입니까? 버퍼 스왑이 모니터와 동기화되도록 설정되어 있으면 버퍼 스왑이 지연 될 수 있습니다. (이 값을 조정하기 위해 WGL_EXT_swap_control 확장을 사용할 수 있습니다.)

  • 이 모든 것이 WM_PAINT에 대한 응답으로 실행되는 경우, 어떤 이유로 든 예기치 않은 추가 WM_PAINT가 발생하지 않는지 확인하십시오.

  • polygon tesselator InitEnd 함수는 테셀레이션이 수행되지 않아도 매번 호출되므로 아무 것도 수행하지 않는지 확인하십시오.

+0

텍스처는 테스트 일 뿐이며 한 번만 실행됩니다. Init 및 End 문제를 해결하고 이미 wgl_ext_swap_control을 사용하고 있으며 스크롤 할 때 wm 페인트를 사용합니다. 2-3 폴리곤은 매우 빠르지 만 더 많이 추가하면 기하 급수적으로 느려집니다. NeHe는 2-3 %의 CPU를 사용하여 60kps에서 32k 폴리곤을 렌더링합니다. – jmasterx

0

제공된 코드 스 니펫을 기반으로 한 번에 4 개의 레이어가 중첩 된 루프가 있습니다. 이러한 각 루프를 너무 많이 실행하면 CPU로드가 높아질 수 있습니다. 이 루프가 얼마나 많은 반복을 거쳐야하는지 알 수 있습니까?

각 루프 반복 내에서 타임 스탬프를 가져 와서 이전 루프와 비교하여 각 루프의 한 반복을 실행하는 데 걸리는 시간을 확인하십시오. 이것은 함수의 어느 부분이 CPU 시간의 대부분을 차지하는지를 결정하는데 도움을 줄 것입니다.

+0

음, 모든 루프를 제거하고 지우고 교환하면 약 30 %가됩니다. – jmasterx

+0

Sleep (1)을 추가하면 SwapBuffers 문제가 해결되었지만 모양이 여전히 병목 현상이되었습니다 – jmasterx

+0

몇 개의 도형을 사용하려고합니까? 모양의 수를 조정하면 어떻게됩니까? CPU 사용량이 도형의 수와 함께 확장됩니까? – bta

관련 문제