From patchwork Thu Jul 21 12:36:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandros Frantzis X-Patchwork-Id: 2917 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C5CB623F52 for ; Thu, 21 Jul 2011 12:36:46 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 95210A184F2 for ; Thu, 21 Jul 2011 12:36:46 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so850361qwb.11 for ; Thu, 21 Jul 2011 05:36:46 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr202973qcb.38.1311251806360; Thu, 21 Jul 2011 05:36:46 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs139339qcb; Thu, 21 Jul 2011 05:36:46 -0700 (PDT) Received: by 10.216.81.69 with SMTP id l47mr709089wee.78.1311251795582; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id p71si2386193weq.80.2011.07.21.05.36.35; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjsUT-0000Ch-Gf for ; Thu, 21 Jul 2011 12:36:33 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 2A7692EA057 for ; Thu, 21 Jul 2011 12:36:32 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 30 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 30: Refactor Scene class and main(). Message-Id: <20110721123632.17019.52545.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:32 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13475"; Instance="initZopeless config overlay" X-Launchpad-Hash: 3df6b065f81c9d54d520e1229969248f131349c1 ------------------------------------------------------------ revno: 30 committer: Alexandros Frantzis timestamp: Fri 2010-07-09 15:11:52 +0300 message: Refactor Scene class and main(). modified: main.cpp scene.cpp scene.h scenebuild.cpp sceneshading.cpp scenetexture.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'main.cpp' --- main.cpp 2010-07-08 13:04:49 +0000 +++ main.cpp 2010-07-09 12:11:52 +0000 @@ -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' --- scene.cpp 2010-07-08 13:04:49 +0000 +++ scene.cpp 2010-07-09 12:11:52 +0000 @@ -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' --- scene.h 2010-07-09 10:16:27 +0000 +++ scene.h 2010-07-09 12:11:52 +0000 @@ -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' --- scenebuild.cpp 2010-07-09 10:28:57 +0000 +++ scenebuild.cpp 2010-07-09 12:11:52 +0000 @@ -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' --- sceneshading.cpp 2010-07-09 10:28:57 +0000 +++ sceneshading.cpp 2010-07-09 12:11:52 +0000 @@ -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' --- scenetexture.cpp 2010-07-08 13:34:28 +0000 +++ scenetexture.cpp 2010-07-09 12:11:52 +0000 @@ -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)