Hello,
i am working on a little CAD-system. my scene has only one object at this time. this object is a geosphere with 5120 triangles and 2562 vertices for testing the performance.
the vertices and mesh-description for the geosphere are precalculated, so that they would not be calculated while rendering. access-members for complex classes in my structure like cobject, cvertex, cmeshface, will always return references for faster access.
i am using visual c++ in release-mode and no vertical synchronization for my gfx-card and monitor.
when i render in imidiate mode, i get only 7 fps. using a displaylist for the geosphere speeds up rendering to 50 fps. i think this is not very fast, because popular games render more triangles in less times.
here is the render-method :
void C3DViewGL::RenderScene()
{
CExp3DDoc *pDoc = (CExp3DDoc *) GetDocument();
if (!pDoc) return;
CScene *pScene = pDoc->GetScene();
if (!pScene) return;
wglMakeCurrent(m_hDC,m_hRC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
RenderGrid();
glRotatef(m_rotAngleX,1.0,0.0,0.0);
glRotatef(m_rotAngleY,0.0,1.0,0.0);
glRotatef(m_rotAngleZ,0.0,0.0,1.0);
glTranslatef(m_trans[1],m_trans[2],m_trans[3]);
glBegin(GL_TRIANGLES);
for (long i=0; i < pScene->Get3DObjectCount(); i++)
{
C3DObject *pObject = pScene->Get3DObjectAt(i);
if (pObject)
{
if (pObject->GetMemObj())
//Execute displaylist
pObject->GetMemObj()->Execute();
else
//Render in imidiate-mode
RenderObject(pObject);
}
}
glEnd();
RenderCoorSys();
SwapBuffers(m_hDC);
glPopMatrix();
}
void C3DViewGL::RenderObject(C3DObject *pObject)
{
CScene *pScene = pObject->GetScene();
if (!pScene) return;
if (pScene->GetColorMode() == CM_OBJECT)
glColor3f(pObject->GetRed()/255.0, pObject->GetGreen()/255.0, pObject->GetBlue()/255.0);
for (long j=0; j < pObject->GetMeshFaceCount(); j++)
{
CMeshFace *pMesh = pObject->GetMeshFaceAt(j);
if (pMesh)
{
CVertex *pA, *pB, *pC;
pA = pObject->GetVertexAt(pMesh->GetIndexA());
pB = pObject->GetVertexAt(pMesh->GetIndexB());
pC = pObject->GetVertexAt(pMesh->GetIndexC());
if (pA && pB && pC)
{
if (pScene->GetShadingModel() == SM_FLAT)
glNormal3f(pMesh->GetNormal()[1], pMesh->GetNormal()[2], pMesh->GetNormal()[3]);
if (pScene->GetShadingModel() == SM_SMOOTH)
glNormal3f(pA->GetNormal()[1], pA->GetNormal()[2], pA->GetNormal()[3]);
if (pScene->GetColorMode() == CM_VERTEX)
glColor3f(pA->GetRed()/255.0, pA->GetGreen()/255.0, pA->GetBlue()/255.0);
glVertex3f(pA->GetVertex()[1], pA->GetVertex()[2], pA->GetVertex()[3]);
if (pScene->GetShadingModel() == SM_SMOOTH)
glNormal3f(pB->GetNormal()[1], pB->GetNormal()[2], pB->GetNormal()[3]);
if (pScene->GetColorMode() == CM_VERTEX)
glColor3f(pB->GetRed()/255.0, pB->GetGreen()/255.0, pB->GetBlue()/255.0);
glVertex3f(pB->GetVertex()[1], pB->GetVertex()[2], pB->GetVertex()[3]);
if (pScene->GetShadingModel() == SM_SMOOTH)
glNormal3f(pC->GetNormal()[1], pC->GetNormal()[2], pC->GetNormal()[3]);
if (pScene->GetColorMode() == CM_VERTEX)
glColor3f(pC->GetRed()/255.0, pC->GetGreen()/255.0, pC->GetBlue()/255.0);
glVertex3f(pC->GetVertex()[1], pC->GetVertex()[2], pC->GetVertex()[3]);
}
}
}
}
maybe someone can give me a hint to speed this up !
best regards
tabor25