diff mbox

[Branch,~glcompbench-dev/glcompbench/trunk] Rev 28: Refactor CompositeTest object hierarchy.

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

Commit Message

alexandros.frantzis@linaro.org June 23, 2011, 2:23 p.m. UTC
------------------------------------------------------------
revno: 28
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Thu 2011-06-23 14:22:08 +0300
message:
  Refactor CompositeTest object hierarchy.
added:
  src/composite-test-simple-base.cc
  src/composite-test-simple-default.cc
renamed:
  src/composite-test-brick.cc => src/composite-test-simple-brick.cc
modified:
  src/composite-test.cc
  src/composite-test.h
  src/glcompbench.cc
  src/composite-test-simple-brick.cc


--
lp:glcompbench
https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk

You are subscribed to branch lp:glcompbench.
To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription
diff mbox

Patch

=== added file 'src/composite-test-simple-base.cc'
--- src/composite-test-simple-base.cc	1970-01-01 00:00:00 +0000
+++ src/composite-test-simple-base.cc	2011-06-23 11:22:08 +0000
@@ -0,0 +1,144 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#include "composite-test.h"
+#include "options.h"
+#include "log.h"
+
+using std::string;
+using std::map;
+
+const string CompositeTestSimpleBase::model_view_matrix_name_("modelview");
+const string CompositeTestSimpleBase::projection_matrix_name_("projection");
+const string CompositeTestSimpleBase::texture0_name_("Texture0");
+const string CompositeTestSimpleBase::texcoord_name_("texcoord");
+const string CompositeTestSimpleBase::position_name_("position");
+
+void
+CompositeTestSimpleBase::init()
+{
+    // Initialize shader sources from input files
+    if (!gotSource(vs_filename_, vertex_shader_))
+    {
+        Log::error("Failed to get vertex shader source for test\n");
+        return;
+    }
+    if (!gotSource(fs_filename_, fragment_shader_))
+    {
+        Log::error("Failed to get fragment shader source for test\n");
+        return;
+    }
+
+    program_.init();
+    if (!program_.valid())
+    {
+        Log::error("No valid program for compositing (reason: %s)\n",
+                   program_.errorMessage().c_str());
+        return;
+    }
+    program_.addShader(GL_VERTEX_SHADER, vertex_shader_);
+    if (!program_.valid())
+    {
+        Log::error("Failed to add vertex shader to compositing program (reason: %s)\n",
+                   program_.errorMessage().c_str());
+        return;
+    }
+    program_.addShader(GL_FRAGMENT_SHADER, fragment_shader_);
+    if (!program_.valid())
+    {
+        Log::error("Failed to add fragment shader to compositing program (reason: %s)\n",
+                   program_.errorMessage().c_str());
+        return;
+    }
+    program_.build();
+    if (!program_.ready())
+    {
+        Log::error("Failed to build compositing program (reason: %s)\n",
+                   program_.errorMessage().c_str());
+        return;
+    }
+    vertexIndex_ = program_.getAttribIndex(position_name_);
+    texcoordIndex_ = program_.getAttribIndex(texcoord_name_);
+
+    // Initialize our vertex buffer object
+    using LibMatrix::vec2;
+    using LibMatrix::vec3;
+    vboData_.addVertex(vec3(-1, -1, 0));
+    vboData_.addVertex(vec3( 1, -1, 0));
+    vboData_.addVertex(vec3( 1,  1, 0));
+    vboData_.addVertex(vec3(-1,  1, 0));
+
+    vboData_.addIndex(0);
+    vboData_.addIndex(1);
+    vboData_.addIndex(2);
+    vboData_.addIndex(2);
+    vboData_.addIndex(3);
+    vboData_.addIndex(0);
+
+    vboData_.addTexCoord(vec2(0, 1));
+    vboData_.addTexCoord(vec2(1, 1));
+    vboData_.addTexCoord(vec2(1, 0));
+    vboData_.addTexCoord(vec2(0, 0));
+
+    vboData_.genBufferObject();
+    vboData_.useBufferObject(Options::use_vbo);
+}
+
+/**
+ * Prepares the test for a test run.
+ */
+void
+CompositeTestSimpleBase::prepare_for_run()
+{
+    program_.start();
+    int texUnit(0);
+    program_.loadUniformScalar(texUnit, texture0_name_);
+
+    glClearColor(0.1, 0.1, 0.3, 1.0);
+
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
+void
+CompositeTestSimpleBase::reshape(int width, int height)
+{
+    float ar = static_cast<float>(width) / static_cast<float>(height);
+
+    /* Update the projection matrix */
+    projection_matrix.loadIdentity();
+    projection_matrix.perspective(22.6, ar, 5.0, 60.0);
+
+    /* Update the modelview matrix */
+    model_view_matrix.loadIdentity();
+    model_view_matrix.translate(0.0, 0.0, -10.0);
+
+    /* Set the viewport */
+    glViewport(0, 0, width, height);
+}
+
+void
+CompositeTestSimpleBase::cleanup()
+{
+    program_.stop();
+}

=== renamed file 'src/composite-test-brick.cc' => 'src/composite-test-simple-brick.cc'
--- src/composite-test-brick.cc	2011-05-02 17:37:00 +0000
+++ src/composite-test-simple-brick.cc	2011-06-23 11:22:08 +0000
@@ -29,84 +29,14 @@ 
 using LibMatrix::vec2;
 using LibMatrix::vec3;
 
-const string CompositeTestBrick::lightPosName_("LightPosition");
-const string CompositeTestBrick::brickSizeName_("BrickSize");
-const string CompositeTestBrick::brickPctName_("BrickPct");
-const vec2 CompositeTestBrick::brickSize_(0.30, 0.15);
-const vec2 CompositeTestBrick::brickPct_(0.90, 0.85);
-
-void
-CompositeTestBrick::init()
-{
-    // Initialize shader sources from input files
-    string vsFilename(GLCOMPBENCH_DATA_PATH"/brick-vertex-shader");
-    if (!gotSource(vsFilename, vertex_shader_))
-    {
-        Log::error("Failed to get vertex shader source for test\n");
-        return;
-    }
-    string fsFilename(GLCOMPBENCH_DATA_PATH"/brick-fragment-shader");
-    if (!gotSource(fsFilename, fragment_shader_))
-    {
-        Log::error("Failed to get fragment shader source for test\n");
-        return;
-    }
-
-    program_.init();
-    if (!program_.valid())
-    {
-        Log::error("No valid program for compositing (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.addShader(GL_VERTEX_SHADER, vertex_shader_);
-    if (!program_.valid())
-    {
-        Log::error("Failed to add vertex shader to compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.addShader(GL_FRAGMENT_SHADER, fragment_shader_);
-    if (!program_.valid())
-    {
-        Log::error("Failed to add fragment shader to compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.build();
-    if (!program_.ready())
-    {
-        Log::error("Failed to build compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    vertexIndex_ = program_.getAttribIndex(position_name_);
-    texcoordIndex_ = program_.getAttribIndex(texcoord_name_);
-
-    // Initialize our vertex buffer object
-    vboData_.addVertex(vec3(-1, -1, 0));
-    vboData_.addVertex(vec3( 1, -1, 0));
-    vboData_.addVertex(vec3( 1,  1, 0));
-    vboData_.addVertex(vec3(-1,  1, 0));
-
-    vboData_.addIndex(0);
-    vboData_.addIndex(1);
-    vboData_.addIndex(2);
-    vboData_.addIndex(2);
-    vboData_.addIndex(3);
-    vboData_.addIndex(0);
-
-    vboData_.addTexCoord(vec2(0, 1));
-    vboData_.addTexCoord(vec2(1, 1));
-    vboData_.addTexCoord(vec2(1, 0));
-    vboData_.addTexCoord(vec2(0, 0));
-
-    vboData_.genBufferObject();
-    vboData_.useBufferObject(Options::use_vbo);
-}
-
-void
-CompositeTestBrick::prepare_for_run()
+const string CompositeTestSimpleBrick::lightPosName_("LightPosition");
+const string CompositeTestSimpleBrick::brickSizeName_("BrickSize");
+const string CompositeTestSimpleBrick::brickPctName_("BrickPct");
+const vec2 CompositeTestSimpleBrick::brickSize_(0.30, 0.15);
+const vec2 CompositeTestSimpleBrick::brickPct_(0.90, 0.85);
+
+void
+CompositeTestSimpleBrick::prepare_for_run()
 {
     lightPos_ = LibMatrix::vec4(0.0, 1.0, 1.0, 0.0);
 
@@ -124,7 +54,7 @@ 
 }
 
 void
-CompositeTestBrick::draw(std::list<CompositeWindow *> &window_list)
+CompositeTestSimpleBrick::draw(std::list<CompositeWindow *> &window_list)
 {
     vboData_.bind();
     glActiveTexture(GL_TEXTURE0);

=== added file 'src/composite-test-simple-default.cc'
--- src/composite-test-simple-default.cc	1970-01-01 00:00:00 +0000
+++ src/composite-test-simple-default.cc	2011-06-23 11:22:08 +0000
@@ -0,0 +1,83 @@ 
+/*
+ * Copyright © 2011 Linaro Limited
+ *
+ * This file is part of glcompbench.
+ *
+ * glcompbench is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * glcompbench is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with glcompbench.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis <alexandros.frantzis@linaro.org>
+ *  Jesse Barker <jesse.barker@linaro.org>
+ */
+
+#include "composite-test.h"
+#include "options.h"
+#include "log.h"
+
+using std::string;
+using std::map;
+
+void
+CompositeTestSimpleDefault::draw(std::list<CompositeWindow *> &window_list)
+{
+    vboData_.bind();
+    glActiveTexture(GL_TEXTURE0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+    /* Set up the position of the attributes in the vertex array */
+    glVertexAttribPointer(vertexIndex_, 3, GL_FLOAT, GL_FALSE, 0, vboData_.vertexOffset());
+    glVertexAttribPointer(texcoordIndex_, 2, GL_FLOAT, GL_FALSE, 0, vboData_.texcoordOffset());
+
+    /* Enable the attributes */
+    glEnableVertexAttribArray(vertexIndex_);
+    glEnableVertexAttribArray(texcoordIndex_);
+
+    program_.loadUniformMatrix(projection_matrix.getCurrent(),
+                               projection_matrix_name_);
+
+    /* Find out how many windows are visible and calculate the angular step */
+    GLuint visible_windows(num_visible_windows(window_list));
+    GLfloat angular_step(2 * M_PI / visible_windows);
+
+    /* Draw the windows in a circle using the calculated angular step */
+    GLint i(0);
+    for(std::list<CompositeWindow*>::iterator iter = window_list.begin();
+        iter != window_list.end(); ++iter)
+    {
+        CompositeWindow *comp_win = *iter;
+        GLuint tex = comp_win->get_texture();
+        if (tex) {
+            model_view_matrix.push();
+            model_view_matrix.translate(cos(angular_step * i),
+                                        sin(angular_step * i), 0);
+
+            /* Load shader ModelView uniform */
+            program_.loadUniformMatrix(model_view_matrix.getCurrent(),
+                                       model_view_matrix_name_);
+
+            Log::debug("Drawing Win: 0x%x Tex: 0x%x\n",
+                       comp_win->get_xwindow(), comp_win->get_texture());
+
+            glBindTexture(GL_TEXTURE_2D, tex);
+            vboData_.draw();
+            model_view_matrix.pop();
+            ++i;
+        }
+    }
+
+    /* Disable the attributes */
+    glDisableVertexAttribArray(vertexIndex_);
+    glDisableVertexAttribArray(texcoordIndex_);
+    vboData_.unbind();
+}

=== modified file 'src/composite-test.cc'
--- src/composite-test.cc	2011-06-22 09:12:20 +0000
+++ src/composite-test.cc	2011-06-23 11:22:08 +0000
@@ -28,12 +28,6 @@ 
 using std::string;
 using std::map;
 
-const string CompositeTest::model_view_matrix_name_("modelview");
-const string CompositeTest::projection_matrix_name_("projection");
-const string CompositeTest::texture0_name_("Texture0");
-const string CompositeTest::texcoord_name_("texcoord");
-const string CompositeTest::position_name_("position");
-
 /**
  * Gets the number of window that are visible.
  *
@@ -56,171 +50,6 @@ 
     return count;
 }
 
-void
-CompositeTest::init()
-{
-    // Initialize shader sources from input files
-    string vsFilename(GLCOMPBENCH_DATA_PATH"/composite-vertex-shader");
-    if (!gotSource(vsFilename, vertex_shader_))
-    {
-        Log::error("Failed to get vertex shader source for test\n");
-        return;
-    }
-    string fsFilename(GLCOMPBENCH_DATA_PATH"/composite-fragment-shader");
-    if (!gotSource(fsFilename, fragment_shader_))
-    {
-        Log::error("Failed to get fragment shader source for test\n");
-        return;
-    }
-
-    program_.init();
-    if (!program_.valid())
-    {
-        Log::error("No valid program for compositing (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.addShader(GL_VERTEX_SHADER, vertex_shader_);
-    if (!program_.valid())
-    {
-        Log::error("Failed to add vertex shader to compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.addShader(GL_FRAGMENT_SHADER, fragment_shader_);
-    if (!program_.valid())
-    {
-        Log::error("Failed to add fragment shader to compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    program_.build();
-    if (!program_.ready())
-    {
-        Log::error("Failed to build compositing program (reason: %s)\n",
-                   program_.errorMessage().c_str());
-        return;
-    }
-    vertexIndex_ = program_.getAttribIndex(position_name_);
-    texcoordIndex_ = program_.getAttribIndex(texcoord_name_);
-
-    // Initialize our vertex buffer object
-    using LibMatrix::vec2;
-    using LibMatrix::vec3;
-    vboData_.addVertex(vec3(-1, -1, 0));
-    vboData_.addVertex(vec3( 1, -1, 0));
-    vboData_.addVertex(vec3( 1,  1, 0));
-    vboData_.addVertex(vec3(-1,  1, 0));
-
-    vboData_.addIndex(0);
-    vboData_.addIndex(1);
-    vboData_.addIndex(2);
-    vboData_.addIndex(2);
-    vboData_.addIndex(3);
-    vboData_.addIndex(0);
-
-    vboData_.addTexCoord(vec2(0, 1));
-    vboData_.addTexCoord(vec2(1, 1));
-    vboData_.addTexCoord(vec2(1, 0));
-    vboData_.addTexCoord(vec2(0, 0));
-
-    vboData_.genBufferObject();
-    vboData_.useBufferObject(Options::use_vbo);
-}
-
-/**
- * Prepares the test for a test run.
- */
-void
-CompositeTest::prepare_for_run()
-{
-    program_.start();
-    int texUnit(0);
-    program_.loadUniformScalar(texUnit, texture0_name_);
-
-    glClearColor(0.1, 0.1, 0.3, 1.0);
-
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-void
-CompositeTest::reshape(int width, int height)
-{
-    float ar = static_cast<float>(width) / static_cast<float>(height);
-
-    /* Update the projection matrix */
-    projection_matrix.loadIdentity();
-    projection_matrix.perspective(22.6, ar, 5.0, 60.0);
-
-    /* Update the modelview matrix */
-    model_view_matrix.loadIdentity();
-    model_view_matrix.translate(0.0, 0.0, -10.0);
-
-    /* Set the viewport */
-    glViewport(0, 0, width, height);
-}
-
-void
-CompositeTest::draw(std::list<CompositeWindow *> &window_list)
-{
-    vboData_.bind();
-    glActiveTexture(GL_TEXTURE0);
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-    /* Set up the position of the attributes in the vertex array */
-    glVertexAttribPointer(vertexIndex_, 3, GL_FLOAT, GL_FALSE, 0, vboData_.vertexOffset());
-    glVertexAttribPointer(texcoordIndex_, 2, GL_FLOAT, GL_FALSE, 0, vboData_.texcoordOffset());
-
-    /* Enable the attributes */
-    glEnableVertexAttribArray(vertexIndex_);
-    glEnableVertexAttribArray(texcoordIndex_);
-
-    program_.loadUniformMatrix(projection_matrix.getCurrent(),
-                               projection_matrix_name_);
-
-    /* Find out how many windows are visible and calculate the angular step */
-    GLuint visible_windows(num_visible_windows(window_list));
-    GLfloat angular_step(2 * M_PI / visible_windows);
-
-    /* Draw the windows in a circle using the calculated angular step */
-    GLint i(0);
-    for(std::list<CompositeWindow*>::iterator iter = window_list.begin();
-        iter != window_list.end(); ++iter)
-    {
-        CompositeWindow *comp_win = *iter;
-        GLuint tex = comp_win->get_texture();
-        if (tex) {
-            model_view_matrix.push();
-            model_view_matrix.translate(cos(angular_step * i),
-                                        sin(angular_step * i), 0);
-
-            /* Load shader ModelView uniform */
-            program_.loadUniformMatrix(model_view_matrix.getCurrent(),
-                                       model_view_matrix_name_);
-
-            Log::debug("Drawing Win: 0x%x Tex: 0x%x\n",
-                       comp_win->get_xwindow(), comp_win->get_texture());
-
-            glBindTexture(GL_TEXTURE_2D, tex);
-            vboData_.draw();
-            model_view_matrix.pop();
-            ++i;
-        }
-    }
-
-    /* Disable the attributes */
-    glDisableVertexAttribArray(vertexIndex_);
-    glDisableVertexAttribArray(texcoordIndex_);
-    vboData_.unbind();
-}
-
-void
-CompositeTest::cleanup()
-{
-    program_.stop();
-}
-
 bool
 CompositeTest::set_option(const string &opt, const string &val)
 { 

=== modified file 'src/composite-test.h'
--- src/composite-test.h	2011-06-22 11:34:41 +0000
+++ src/composite-test.h	2011-06-23 11:22:08 +0000
@@ -39,11 +39,18 @@ 
 public:
     CompositeTest(const std::string& test_name) :
         name_(test_name) {}
-    virtual void init();
-    virtual void prepare_for_run();
-    virtual void draw(std::list<CompositeWindow*> &window_list);
-    virtual void cleanup();
-    virtual void reshape(int width, int height);
+    virtual void init() {}
+    virtual void prepare_for_run() {}
+    virtual void draw(std::list<CompositeWindow*> &window_list)
+    {
+        (void)window_list;
+    }
+    virtual void cleanup() {}
+    virtual void reshape(int width, int height)
+    {
+        (void)width;
+        (void)height;
+    }
     const std::string& name() const { return name_; }
 
     struct Option {
@@ -78,7 +85,27 @@ 
     int num_visible_windows(std::list<CompositeWindow *> &window_list);
     std::string name_;
     std::map<std::string, Option> options_;
+};
+
+class CompositeTestSimpleBase : public CompositeTest
+{
+public:
+    CompositeTestSimpleBase(const std::string& test_name,
+                            const std::string& vs_filename, 
+                            const std::string& fs_filename)
+        : CompositeTest(test_name), vs_filename_(vs_filename),
+          fs_filename_(fs_filename)
+        {}
+
+    virtual void init();
+    virtual void prepare_for_run();
+    virtual void cleanup();
+    virtual void reshape(int width, int height);
+
+protected:
     Program program_;
+    std::string vs_filename_;
+    std::string fs_filename_;
     std::string vertex_shader_;
     std::string fragment_shader_;
     int vertexIndex_;
@@ -92,19 +119,30 @@ 
 
     LibMatrix::Stack4 projection_matrix;
     LibMatrix::Stack4 model_view_matrix;
-};
-
-class CompositeTestDefault : public CompositeTest
-{
-public:
-    CompositeTestDefault() : CompositeTest("default") {}
-};
-
-class CompositeTestBrick : public CompositeTest
-{
-public:
-    CompositeTestBrick() : CompositeTest("brick") {}
-    virtual void init();
+
+};
+
+class CompositeTestSimpleDefault : public CompositeTestSimpleBase
+{
+public:
+    CompositeTestSimpleDefault() : 
+        CompositeTestSimpleBase("default",
+                                GLCOMPBENCH_DATA_PATH"/composite-vertex-shader",
+                                GLCOMPBENCH_DATA_PATH"/composite-fragment-shader")
+        {}
+
+    virtual void draw(std::list<CompositeWindow*> &window_list);
+};
+
+class CompositeTestSimpleBrick : public CompositeTestSimpleBase
+{
+public:
+    CompositeTestSimpleBrick() :
+        CompositeTestSimpleBase("brick",
+                                GLCOMPBENCH_DATA_PATH"/brick-vertex-shader",
+                                GLCOMPBENCH_DATA_PATH"/brick-fragment-shader")
+        {}
+
     virtual void draw(std::list<CompositeWindow*> &window_list);
     virtual void prepare_for_run();
 private:

=== modified file 'src/glcompbench.cc'
--- src/glcompbench.cc	2011-06-23 08:54:28 +0000
+++ src/glcompbench.cc	2011-06-23 11:22:08 +0000
@@ -107,8 +107,8 @@ 
         return 0;
     }
 
-    Benchmark::register_test(*new CompositeTestDefault());
-    Benchmark::register_test(*new CompositeTestBrick());
+    Benchmark::register_test(*new CompositeTestSimpleDefault());
+    Benchmark::register_test(*new CompositeTestSimpleBrick());
 
     if (Options::list_tests) {
         list_tests();