diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 102: Refactor SceneConditionals to derive from SceneGrid base class.

Message ID 20110721123637.17019.84891.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 21, 2011, 12:36 p.m. UTC
------------------------------------------------------------
revno: 102
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
timestamp: Thu 2011-07-07 16:45:19 +0300
message:
  Refactor SceneConditionals to derive from SceneGrid base class.
modified:
  src/scene-conditionals.cpp
  src/scene.h


--
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
diff mbox

Patch

=== modified file 'src/scene-conditionals.cpp'
--- src/scene-conditionals.cpp	2011-07-05 16:18:56 +0000
+++ src/scene-conditionals.cpp	2011-07-07 13:45:19 +0000
@@ -41,7 +41,7 @@ 
 static const std::string frg_file_epilogue(shader_file_base + "epilogue.frag");
 
 SceneConditionals::SceneConditionals(Canvas &pCanvas) :
-    Scene(pCanvas, "conditionals")
+    SceneGrid(pCanvas, "conditionals")
 {
     mOptions["fragment-steps"] = Scene::Option("fragment-steps", "1",
             "The number of computational steps in the fragment shader");
@@ -51,10 +51,6 @@ 
             "The number of computational steps in the vertex shader");
     mOptions["vertex-conditionals"] = Scene::Option("vertex-conditionals", "true",
             "Whether each computational step includes an if-else clause");
-    mOptions["grid-size"] = Scene::Option("grid-size", "32",
-            "The number of squares per side of the grid (controls the number of vertices)");
-    mOptions["grid-length"] = Scene::Option("grid-length", "5.0",
-            "The length of each side of the grid (normalized) (controls the area drawn to)");
 }
 
 SceneConditionals::~SceneConditionals()
@@ -115,29 +111,15 @@ 
     return ss.str();
 }
 
-int SceneConditionals::load()
-{
-    mRotationSpeed = 36.0f;
-    mRunning = false;
-
-    return 1;
-}
-
-void SceneConditionals::unload()
-{
-}
-
 void SceneConditionals::setup()
 {
-    Scene::setup();
+    SceneGrid::setup();
 
     /* Parse options */
     bool vtx_conditionals = mOptions["vertex-conditionals"].value == "true";
     bool frg_conditionals = mOptions["fragment-conditionals"].value == "true";
     int vtx_steps = 0;
     int frg_steps = 0;
-    int grid_size = 0;
-    double grid_length = 0;
 
     std::stringstream ss;
 
@@ -146,12 +128,6 @@ 
     ss.clear();
     ss << mOptions["fragment-steps"].value;
     ss >> frg_steps;
-    ss.clear();
-    ss << mOptions["grid-size"].value;
-    ss >> grid_size;
-    ss.clear();
-    ss << mOptions["grid-length"].value;
-    ss >> grid_length;
 
     /* Load shaders */
     std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_conditionals));
@@ -162,76 +138,11 @@ 
 
     mProgram.start();
 
-    /* Create and configure the grid mesh */
-    std::vector<int> vertex_format;
-    vertex_format.push_back(3);
-    mMesh.set_vertex_format(vertex_format);
-
-    /* 
-     * The spacing needed in order for the area of the requested grid
-     * to be the same as the area of a grid with size 32 and spacing 0.02.
-     */
-    double spacing = grid_length * (1 - 4.38 / 5.0) / (grid_size - 1.0);
-
-    mMesh.make_grid(grid_size, grid_size, grid_length, grid_length,
-                    grid_size > 1 ? spacing : 0);
-    mMesh.build_vbo();
-
     std::vector<GLint> attrib_locations;
     attrib_locations.push_back(mProgram.getAttribIndex("position"));
     mMesh.set_attrib_locations(attrib_locations);
 
-    mCurrentFrame = 0;
-    mRotation = 0.0f;
     mRunning = true;
     mStartTime = Scene::get_timestamp_us() / 1000000.0;
     mLastUpdateTime = mStartTime;
 }
-
-void SceneConditionals::teardown()
-{
-    mProgram.stop();
-    mProgram.release();
-    mMesh.reset();
-
-    Scene::teardown();
-}
-
-void SceneConditionals::update()
-{
-    double current_time = Scene::get_timestamp_us() / 1000000.0;
-    double dt = current_time - mLastUpdateTime;
-    double elapsed_time = current_time - mStartTime;
-
-    mLastUpdateTime = current_time;
-
-    if (elapsed_time >= mDuration) {
-        mAverageFPS = mCurrentFrame / elapsed_time;
-        mRunning = false;
-    }
-
-    mRotation += mRotationSpeed * dt;
-
-    mCurrentFrame++;
-}
-
-void SceneConditionals::draw()
-{
-    // Load the ModelViewProjectionMatrix uniform in the shader
-    LibMatrix::Stack4 model_view;
-    LibMatrix::mat4 model_view_proj(mCanvas.projection());
-
-    model_view.translate(0.0f, 0.0f, -5.0f);
-    model_view.rotate(mRotation, 0.0f, 0.0f, 1.0f);
-    model_view_proj *= model_view.getCurrent();
-
-    mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix");
-
-    mMesh.render_vbo();
-}
-
-Scene::ValidationResult
-SceneConditionals::validate()
-{
-    return Scene::ValidationUnknown;
-}

=== modified file 'src/scene.h'
--- src/scene.h	2011-07-07 13:35:24 +0000
+++ src/scene.h	2011-07-07 13:45:19 +0000
@@ -227,26 +227,13 @@ 
     float mRotationSpeed;
 };
 
-class SceneConditionals : public Scene
+class SceneConditionals : public SceneGrid
 {
 public:
     SceneConditionals(Canvas &pCanvas);
-    int load();
-    void unload();
     void setup();
-    void teardown();
-    void update();
-    void draw();
-    ValidationResult validate();
 
     ~SceneConditionals();
-
-protected:
-    Program mProgram;
-
-    Mesh mMesh;
-    float mRotation;
-    float mRotationSpeed;
 };
 
 class SceneFunction : public SceneGrid