=== modified file 'main.cpp'
@@ -17,12 +17,19 @@
return 0;
printf("===================================================\n");
- SceneBuild scenebuild(screen);
- SceneTexture scenetexture(screen);
- SceneShading sceneshading(screen);
-
- if(!scenebuild.load() || !scenetexture.load() || !sceneshading.load())
- return 0;
+ // Create the scenes.
+ Scene *scene[] = {
+ new SceneBuild(screen),
+ new SceneTexture(screen),
+ new SceneShading(screen),
+ };
+
+ unsigned num_scenes = sizeof(scene) / sizeof(*scene);
+
+ // Load the first scene
+ if (!scene[current_scene]->load())
+ return 1;
+ scene[current_scene]->start();
while(running)
{
@@ -42,47 +49,36 @@
screen.clear();
- switch(current_scene)
- {
- case 0:
+ // Draw the next state of the current scene
+ scene[current_scene]->update();
+ scene[current_scene]->draw();
+
+ // If the scene has finished, move to the next one
+ if (!scene[current_scene]->is_running()) {
+ // Unload this scene
+ scene[current_scene]->unload();
+
current_scene++;
- scenebuild.start();
- break;
- case 1:
- scenebuild.update();
- scenebuild.draw();
- if(!scenebuild.mRunning)
- {
- current_scene++;
- scenetexture.start();
- }
- break;
- case 2:
- scenetexture.update();
- scenetexture.draw();
- if(!scenetexture.mRunning)
- {
- current_scene++;
- sceneshading.start();
- }
- break;
- case 3:
- sceneshading.update();
- sceneshading.draw();
- if(!sceneshading.mRunning)
+
+ // Do we have another scene?
+ if (current_scene < num_scenes) {
+ // Load and start next scene
+ if (!scene[current_scene]->load())
+ return 1;
+ scene[current_scene]->start();
+ }
+ else
running = false;
- break;
}
+
screen.update();
}
- scenebuild.calculate_score();
- scenetexture.calculate_score();
- sceneshading.calculate_score();
+ unsigned score = 0;
+ for (unsigned i = 0; i < num_scenes; i++)
+ score += scene[i]->calculate_score();
- unsigned score = scenebuild.mScore + scenetexture.mScore + sceneshading.mScore;
-
printf("===================================================\n");
printf("Your GLMark08 Score is %u ^_^\n", score);
printf("===================================================\n");
=== modified file 'scene.cpp'
@@ -3,6 +3,21 @@
Scene::Scene(Screen &pScreen) :
mScreen(pScreen)
{
+ mPartsQty = 0;
+ mCurrentPart = 0;
+ mPartDuration = 0;
+
+ mLastTime = 0;
+ mCurrentTime = 0;
+ mDt = 0;
+ mCurrentFrame = 0;
+ mRunning = false;
+
+ mAverageFPS = 0;
+ mScoreScale = 0;
+
+ mStartTime = 0;
+ mElapsedTime = 0;
}
Scene::~Scene()
@@ -12,11 +27,39 @@
delete [] mScoreScale;
}
-void Scene::calculate_score()
-{
- mScore = 0;
+int Scene::load()
+{
+ return 1;
+}
+
+void Scene::unload()
+{
+}
+
+void Scene::start()
+{
+}
+
+void Scene::update()
+{
+}
+
+void Scene::draw()
+{
+}
+
+unsigned Scene::calculate_score()
+{
+ unsigned mScore = 0;
+
for(unsigned i = 0; i < mPartsQty; i++)
mScore += mAverageFPS[i] * mScoreScale[i];
-}
-
-
+
+ return mScore;
+}
+
+
+bool Scene::is_running()
+{
+ return mRunning;
+}
=== modified file 'scene.h'
@@ -15,7 +15,17 @@
public:
Scene(Screen &pScreen);
~Scene();
-
+
+ virtual int load();
+ virtual void unload();
+ virtual void start();
+ virtual void update();
+ virtual void draw();
+
+ unsigned calculate_score();
+ bool is_running();
+
+protected:
unsigned mPartsQty; // How many parts for the scene
unsigned mCurrentPart; // The current part being rendered
double *mPartDuration; // Duration per part in seconds
@@ -26,11 +36,7 @@
unsigned *mAverageFPS; // Average FPS per part
float *mScoreScale;
- unsigned mScore; // Score
-
- void calculate_score();
-
-protected:
+
double mStartTime;
double mElapsedTime;
@@ -42,12 +48,14 @@
public:
SceneBuild(Screen &pScreen) : Scene(pScreen) {}
int load();
+ void unload();
void start();
void update();
void draw();
~SceneBuild();
+protected:
Shader mShader;
Mesh mMesh;
@@ -60,12 +68,14 @@
public:
SceneTexture(Screen &pScreen) : Scene(pScreen) {}
int load();
+ void unload();
void start();
void update();
void draw();
~SceneTexture();
+protected:
Mesh mCubeMesh;
GLuint mTexture[3];
Vector3f mRotation;
@@ -77,12 +87,14 @@
public:
SceneShading(Screen &pScreen) : Scene(pScreen) {}
int load();
+ void unload();
void start();
void update();
void draw();
~SceneShading();
+protected:
Shader mShader[2];
Mesh mMesh;
=== modified file 'scenebuild.cpp'
@@ -32,8 +32,6 @@
mScoreScale[0] = 1.898f;
mScoreScale[1] = 0.540f;
- mScore = 0;
-
mPartDuration[0] = 10.0;
mPartDuration[1] = 10.0;
@@ -44,6 +42,12 @@
return 1;
}
+void SceneBuild::unload()
+{
+ mShader.remove();
+ mShader.unload();
+}
+
void SceneBuild::start()
{
GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};
@@ -89,7 +93,6 @@
printf(" Vertex buffer object FPS: %u\n", mAverageFPS[mCurrentPart]);
break;
}
- mScore += mAverageFPS[mCurrentPart];
mCurrentPart++;
start();
if(mCurrentPart >= mPartsQty)
=== modified file 'sceneshading.cpp'
@@ -35,8 +35,6 @@
mScoreScale[0] = 0.534f;
mScoreScale[1] = 0.532f;
- mScore = 0;
-
mPartDuration[0] = 10.0;
mPartDuration[1] = 10.0;
@@ -47,6 +45,14 @@
return 1;
}
+void SceneShading::unload()
+{
+ for(unsigned i = 0; i < mPartsQty; i++) {
+ mShader[i].remove();
+ mShader[i].unload();
+ }
+}
+
void SceneShading::start()
{
GLfloat lightAmbient[] = {0.1f, 0.1f, 0.1f, 1.0f};
@@ -119,7 +125,6 @@
printf(" GLSL per pixel lighting FPS: %u\n", mAverageFPS[mCurrentPart]);
break;
}
- mScore += mAverageFPS[mCurrentPart];
mCurrentPart++;
start();
if(mCurrentPart >= mPartsQty)
=== modified file 'scenetexture.cpp'
@@ -33,8 +33,6 @@
mScoreScale[1] = 0.533f;
mScoreScale[2] = 0.405f;
- mScore = 0;
-
mPartDuration[0] = 10.0;
mPartDuration[1] = 10.0;
mPartDuration[2] = 10.0;
@@ -46,6 +44,10 @@
return 1;
}
+void SceneTexture::unload()
+{
+}
+
void SceneTexture::start()
{
GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f};
@@ -91,7 +93,6 @@
printf(" Mipmapped FPS: %u\n", mAverageFPS[mCurrentPart]);
break;
}
- mScore += mAverageFPS[mCurrentPart];
mCurrentPart++;
start();
if(mCurrentPart >= mPartsQty)