From patchwork Wed Jun 22 08:30:47 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: 2150 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 9776823F6C for ; Wed, 22 Jun 2011 08:30:50 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 07CF1A188ED for ; Wed, 22 Jun 2011 08:30:49 +0000 (UTC) Received: by vws16 with SMTP id 16so652205vws.11 for ; Wed, 22 Jun 2011 01:30:49 -0700 (PDT) Received: by 10.52.163.6 with SMTP id ye6mr546191vdb.127.1308731449316; Wed, 22 Jun 2011 01:30:49 -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.52.183.130 with SMTP id em2cs122337vdc; Wed, 22 Jun 2011 01:30:49 -0700 (PDT) Received: by 10.227.198.17 with SMTP id em17mr455051wbb.4.1308731448185; Wed, 22 Jun 2011 01:30:48 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id p6si825242wbh.0.2011.06.22.01.30.47; Wed, 22 Jun 2011 01:30:48 -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 1QZIpj-0001v5-Ey for ; Wed, 22 Jun 2011 08:30:47 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 6B0232E800B for ; Wed, 22 Jun 2011 08:30:47 +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: 22 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glcompbench-dev/glcompbench/trunk] Rev 22: Merge branch that splits different tests into separate files. Message-Id: <20110622083047.22352.91669.launchpad@loganberry.canonical.com> Date: Wed, 22 Jun 2011 08:30:47 -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: 141a4e95ebdf0655a2b643da526201ab642950cc Merge authors: Jesse Barker (jesse-barker) Related merge proposals: https://code.launchpad.net/~jesse-barker/glcompbench/split/+merge/59682 proposed by: Jesse Barker (jesse-barker) review: Approve - Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 22 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Wed 2011-06-22 11:28:05 +0300 message: Merge branch that splits different tests into separate files. added: src/composite-test-brick.cc modified: src/composite-test.cc src/composite-test.h --- 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-brick.cc' --- src/composite-test-brick.cc 1970-01-01 00:00:00 +0000 +++ src/composite-test-brick.cc 2011-05-02 17:37:00 +0000 @@ -0,0 +1,190 @@ +/* + * 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 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() +{ + lightPos_ = LibMatrix::vec4(0.0, 1.0, 1.0, 0.0); + + program_.start(); + int texUnit(0); + program_.loadUniformScalar(texUnit, texture0_name_); + program_.loadUniformVector(brickSize_, brickSizeName_); + program_.loadUniformVector(brickPct_, brickPctName_); + program_.loadUniformVector(lightPos_, lightPosName_); + + glClearColor(0.1, 0.1, 0.3, 1.0); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + +void +CompositeTestBrick::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(); + + // Pan the light around the scene. + float x(lightPos_.x()); + float y(lightPos_.y()); + if (x >= 1.0) { x = 1.0; y -= 0.1; } + if (y >= 1.0) { y = 1.0; x += 0.1; } + if (y <= 0.0) { y = 0.0; x -= 0.1; } + if (x <= 0.0) { x = 0.0; y += 0.1; } + lightPos_.x(x); + lightPos_.y(y); + program_.loadUniformVector(lightPos_, lightPosName_); +} === modified file 'src/composite-test.cc' --- src/composite-test.cc 2011-04-27 18:10:23 +0000 +++ src/composite-test.cc 2011-05-03 16:41:28 +0000 @@ -26,20 +26,12 @@ #include "log.h" using std::string; -using std::endl; -using LibMatrix::vec2; -using LibMatrix::vec3; 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"); -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); /** * Gets the number of window that are visible. @@ -48,8 +40,8 @@ * * @return the number of visible windows */ -static int -num_visible_windows(std::list &window_list) +int +CompositeTest::num_visible_windows(std::list &window_list) { int count = 0; @@ -112,6 +104,8 @@ 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)); @@ -225,157 +219,3 @@ { program_.stop(); } - -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() -{ - lightPos_ = LibMatrix::vec4(0.0, 1.0, 1.0, 0.0); - - program_.start(); - int texUnit(0); - program_.loadUniformScalar(texUnit, texture0_name_); - program_.loadUniformVector(brickSize_, brickSizeName_); - program_.loadUniformVector(brickPct_, brickPctName_); - program_.loadUniformVector(lightPos_, lightPosName_); - - glClearColor(0.1, 0.1, 0.3, 1.0); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - -void -CompositeTestBrick::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(); - - // Pan the light around the scene. - float x(lightPos_.x()); - float y(lightPos_.y()); - if (x >= 1.0) { x = 1.0; y -= 0.1; } - if (y >= 1.0) { y = 1.0; x += 0.1; } - if (y <= 0.0) { y = 0.0; x -= 0.1; } - if (x <= 0.0) { x = 0.0; y += 0.1; } - lightPos_.x(x); - lightPos_.y(y); - program_.loadUniformVector(lightPos_, lightPosName_); -} === modified file 'src/composite-test.h' --- src/composite-test.h 2011-04-27 17:49:30 +0000 +++ src/composite-test.h 2011-05-03 16:41:28 +0000 @@ -46,6 +46,14 @@ const std::string& name() const { return name_; } protected: CompositeTest(); + // + // Gets the number of windows that are visible. + // + // @param window_list the window list to search in + // + // @return the number of visible windows + // + int num_visible_windows(std::list &window_list); std::string name_; Program program_; std::string vertex_shader_;