Original Post
I have a nice Scene class, which consists of a skybox and a list of items.
class SceneGraphScene
{
private:
SceneGraph *m_pParentGraph;
/*
* list of items to draw
*/
std::vector<SceneGraphItem*> m_SceneGraphItems;
/*
* list of light sources to draw
*/
std::vector<LightSource> m_LightSources;
/*
* list of texture ids necessary to draw the sky box
*/
std::vector<GLuint> m_iSkyBoxT;
void drawSkyBox();
public:
//**
virtual void RenderScene();
};
my item class should do the render-jobs for parts of the scene. for example for models.
class SceneGraphItem
{
//..
public:
//..
void RenderItem() const {draw1();}
}; my problem occurs when i try to draw via RenderItem() function in my scene. All i do is to draw a cube. if i write the same code in the renderfunction of my scene i get more than 1000 fps. but if i try to draw like in the example (down) i only have 16 frames and render problems with my skybox. there is no additional code in the render function of my item. i only run the draw1() function. this is my function:
void SceneGraphScene::RenderScene()
{
// Lichter setzen
for(unsigned int i = 0; i < m_LightSources.size(); i++) {
if(i < GL_MAX_LIGHTS) {
//std::cout<<"set up new light source"<<std::endl;
glLightfv(GL_LIGHT0 + i, GL_AMBIENT, m_LightSources.at(i).fLightAmbient);
glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, m_LightSources.at(i).fLightDiffuse);
glLightfv(GL_LIGHT0 + i, GL_POSITION, m_LightSources.at(i).fLightPosition);
glEnable(GL_LIGHT0 + i);
}
}
// Zeichne nun die Modelle
for(unsigned int i = 0; i < m_SceneGraphItems.size(); i++) {
m_SceneGraphItems.at(i)->RenderItem();
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);// reset the color to white
}
inline void draw1()
{
glPushMatrix();
glBegin(GL_QUADS);
// face v0-v1-v2-v3
glNormal3f(0,0,1);
glColor3f(1,1,1);
glVertex3f(1,1,1);
glColor3f(1,1,0);
glVertex3f(-1,1,1);
glColor3f(1,0,0);
glVertex3f(-1,-1,1);
glColor3f(1,0,1);
glVertex3f(1,-1,1);
// face v0-v3-v4-v6
glNormal3f(1,0,0);
glColor3f(1,1,1);
glVertex3f(1,1,1);
glColor3f(1,0,1);
glVertex3f(1,-1,1);
glColor3f(0,0,1);
glVertex3f(1,-1,-1);
glColor3f(0,1,1);
glVertex3f(1,1,-1);
// face v0-v5-v6-v1
glNormal3f(0,1,0);
glColor3f(1,1,1);
glVertex3f(1,1,1);
glColor3f(0,1,1);
glVertex3f(1,1,-1);
glColor3f(0,1,0);
glVertex3f(-1,1,-1);
glColor3f(1,1,0);
glVertex3f(-1,1,1);
// face v1-v6-v7-v2
glNormal3f(-1,0,0);
glColor3f(1,1,0);
glVertex3f(-1,1,1);
glColor3f(0,1,0);
glVertex3f(-1,1,-1);
glColor3f(0,0,0);
glVertex3f(-1,-1,-1);
glColor3f(1,0,0);
glVertex3f(-1,-1,1);
/..
glPopMatrix();
}
How is this possible. The code is the same, why is the indirect call over the itemclass so slow ):