From patchwork Thu Jun 23 14:23:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 2213 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 D4C8423F6D for ; Thu, 23 Jun 2011 14:23:19 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7B0D5A189BA for ; Thu, 23 Jun 2011 14:23:19 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so1372729qyk.11 for ; Thu, 23 Jun 2011 07:23:19 -0700 (PDT) Received: by 10.229.117.95 with SMTP id p31mr1608061qcq.97.1308838999229; Thu, 23 Jun 2011 07:23:19 -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.230.139 with SMTP id jm11cs19226qcb; Thu, 23 Jun 2011 07:23:18 -0700 (PDT) Received: by 10.216.233.92 with SMTP id o70mr1966668weq.71.1308838996061; Thu, 23 Jun 2011 07:23:16 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id v60si3951675wec.40.2011.06.23.07.23.15; Thu, 23 Jun 2011 07:23:16 -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 1QZkoN-0003mK-3h for ; Thu, 23 Jun 2011 14:23:15 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 181732E8060 for ; Thu, 23 Jun 2011 14:23:15 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glcompbench X-Launchpad-Branch: ~glcompbench-dev/glcompbench/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 28 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glcompbench-dev/glcompbench/trunk] Rev 28: Refactor CompositeTest object hierarchy. Message-Id: <20110623142315.3922.70458.launchpad@loganberry.canonical.com> Date: Thu, 23 Jun 2011 14:23:15 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13265"; Instance="initZopeless config overlay" X-Launchpad-Hash: 4af9e8bd6d37fa22a11f7b0348d39bc3c587c79b ------------------------------------------------------------ revno: 28 committer: Alexandros Frantzis 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 === 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 . + * + * Authors: + * Alexandros Frantzis + * Jesse Barker + */ + +#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(width) / static_cast(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 &window_list) +CompositeTestSimpleBrick::draw(std::list &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 . + * + * Authors: + * Alexandros Frantzis + * Jesse Barker + */ + +#include "composite-test.h" +#include "options.h" +#include "log.h" + +using std::string; +using std::map; + +void +CompositeTestSimpleDefault::draw(std::list &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::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(width) / static_cast(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 &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::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 &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 &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 &window_list); std::string name_; std::map 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 &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 &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();