From patchwork Fri Nov 11 11:12:13 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: 5078 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 3C7AE23EF5 for ; Fri, 11 Nov 2011 11:12:17 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 19450A18321 for ; Fri, 11 Nov 2011 11:12:17 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id n26so5555625faa.11 for ; Fri, 11 Nov 2011 03:12:17 -0800 (PST) Received: by 10.152.105.226 with SMTP id gp2mr6444558lab.28.1321009936670; Fri, 11 Nov 2011 03:12:16 -0800 (PST) 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.152.40.7 with SMTP id t7cs43790lak; Fri, 11 Nov 2011 03:12:16 -0800 (PST) Received: by 10.216.197.20 with SMTP id s20mr928140wen.14.1321009933956; Fri, 11 Nov 2011 03:12:13 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id n49si6266895weq.122.2011.11.11.03.12.13 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 Nov 2011 03:12:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1ROp1p-0006YL-BV for ; Fri, 11 Nov 2011 11:12:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 4DC21E032C for ; Fri, 11 Nov 2011 11:12:13 +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: 167 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 167: *: Merge cleanup branch part 2. Message-Id: <20111111111213.23901.91569.launchpad@ackee.canonical.com> Date: Fri, 11 Nov 2011 11:12:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14277"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: b11ffafec9a73eb8fd46a7f3cf24829dcf975960 Merge authors: Alexandros Frantzis (afrantzis) Jesse Barker (jesse-barker) ------------------------------------------------------------ revno: 167 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Fri 2011-11-11 13:07:15 +0200 message: *: Merge cleanup branch part 2. added: src/default-benchmarks.h modified: src/android.cpp src/benchmark.h src/canvas-x11-glx.cpp src/main.cpp src/mesh.cpp src/mesh.h src/model.cpp src/model.h src/scene-buffer.cpp src/scene-build.cpp src/scene-bump.cpp src/scene-conditionals.cpp src/scene-desktop.cpp src/scene-effect-2d.cpp src/scene-function.cpp src/scene-grid.cpp src/scene-loop.cpp src/scene-pulsar.cpp src/scene-shading.cpp src/scene-texture.cpp src/scene.cpp src/scene.h src/texture.cpp src/texture.h src/util.cpp src/util.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 === modified file 'src/android.cpp' --- src/android.cpp 2011-10-17 10:13:12 +0000 +++ src/android.cpp 2011-11-08 20:20:02 +0000 @@ -29,36 +29,7 @@ #include "options.h" #include "log.h" #include "util.h" - -static const char *default_benchmarks[] = { - "build:use-vbo=false", - "build:use-vbo=true", - "texture:texture-filter=nearest", - "texture:texture-filter=linear", - "texture:texture-filter=mipmap", - "shading:shading=gouraud", - "shading:shading=blinn-phong-inf", - "shading:shading=phong", - "bump:bump-render=high-poly", - "bump:bump-render=normals", - "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", - "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", - "pulsar:quads=5:texture=false:light=false", - "desktop:windows=4:effect=blur:blur-radius=5:passes=1:separable=true", - "desktop:windows=4:effect=shadow", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=false", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=subdata:interleave=false", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=true", - "conditionals:vertex-steps=0:fragment-steps=0", - "conditionals:vertex-steps=0:fragment-steps=5", - "conditionals:vertex-steps=5:fragment-steps=0", - "function:fragment-steps=5:fragment-complexity=low", - "function:fragment-steps=5:fragment-complexity=medium", - "loop:vertex-steps=5:fragment-steps=5:fragment-loop=false", - "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=false", - "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=true", - NULL -}; +#include "default-benchmarks.h" static Canvas *g_canvas; static std::vector g_benchmarks; @@ -66,8 +37,14 @@ static void add_default_benchmarks(std::vector &benchmarks) { - for (const char **s = default_benchmarks; *s != NULL; s++) - benchmarks.push_back(new Benchmark(*s)); + const std::vector &default_benchmarks = DefaultBenchmarks::get(); + + for (std::vector::const_iterator iter = default_benchmarks.begin(); + iter != default_benchmarks.end(); + iter++) + { + benchmarks.push_back(new Benchmark(*iter)); + } } void @@ -144,14 +121,26 @@ } static JNINativeMethod glmark2_native_methods[] = { - {"nativeInit", "(Landroid/content/res/AssetManager;)V", - (void*)Java_org_linaro_glmark2_Glmark2Renderer_nativeInit}, - {"nativeResize", "(II)V", - (void*)Java_org_linaro_glmark2_Glmark2Renderer_nativeResize}, - {"nativeDone", "()V", - (void*)Java_org_linaro_glmark2_Glmark2Renderer_nativeDone}, - {"nativeRender", "()Z", - (void*)Java_org_linaro_glmark2_Glmark2Renderer_nativeRender} + { + "nativeInit", + "(Landroid/content/res/AssetManager;)V", + reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeInit) + }, + { + "nativeResize", + "(II)V", + reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeResize) + }, + { + "nativeDone", + "()V", + reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeDone) + }, + { + "nativeRender", + "()Z", + reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeRender) + } }; static int @@ -193,7 +182,7 @@ JNIEnv* env = NULL; jint result = -1; - if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_4) != JNI_OK) { Log::error("JNI_OnLoad: GetEnv failed\n"); goto bail; } === modified file 'src/benchmark.h' --- src/benchmark.h 2011-10-25 20:18:30 +0000 +++ src/benchmark.h 2011-11-08 22:01:16 +0000 @@ -28,22 +28,75 @@ #include "scene.h" +/** + * A glmark2 benchmark. + * + * A benchmark is a Scene configured with a set of option values. + */ class Benchmark { public: typedef std::pair OptionPair; + /** + * Creates a benchmark using a scene object reference. + * + * @param scene the scene to use + * @param options the options to use + */ Benchmark(Scene &scene, const std::vector &options); + + /** + * Creates a benchmark using a scene name. + * + * To use a scene by name, that scene must have been previously registered + * using ::register_scene(). + * + * @param name the name of the scene to use + * @param options the options to use + */ Benchmark(const std::string &name, const std::vector &options); - // Create a benchmark from a description string of the form: - // scene[:opt1=val1:opt2=val2...] + + /** + * Creates a benchmark from a description string. + * + * The description string is of the form scene[:opt1=val1:opt2=val2...]. + * The specified scene must have been previously registered using + * ::register_scene(). + * + * @param s a description string + */ Benchmark(const std::string &s); + /** + * Sets up the Scene associated with the benchmark. + * + * @return the Scene + */ Scene &setup_scene(); + + /** + * Tears down the Scene associated with the benchmark. + */ void teardown_scene(); + /** + * Registers a Scene, so that it becomes accessible by name. + */ static void register_scene(Scene &scene); + + /** + * Gets a registered scene by its name. + * + * @return the Scene + */ static Scene &get_scene_by_name(const std::string &name); + + /** + * Gets the registered scenes. + * + * @return the Scene + */ static const std::map &scenes() { return sceneMap_; } private: === modified file 'src/canvas-x11-glx.cpp' --- src/canvas-x11-glx.cpp 2011-11-02 14:56:58 +0000 +++ src/canvas-x11-glx.cpp 2011-11-11 11:07:15 +0000 @@ -110,12 +110,18 @@ if (extString.find("GLX_EXT_swap_control") != std::string::npos) { glXSwapIntervalEXT_ = reinterpret_cast( - glXGetProcAddress((const GLubyte *)"glXSwapIntervalEXT")); + glXGetProcAddress( + reinterpret_cast("glXSwapIntervalEXT") + ) + ); } else if (extString.find("GLX_MESA_swap_control") != std::string::npos) { glXSwapIntervalMESA_ = reinterpret_cast( - glXGetProcAddress((const GLubyte *)"glXSwapIntervalMESA")); + glXGetProcAddress( + reinterpret_cast("glXSwapIntervalMESA") + ) + ); } === added file 'src/default-benchmarks.h' --- src/default-benchmarks.h 1970-01-01 00:00:00 +0000 +++ src/default-benchmarks.h 2011-11-08 20:20:02 +0000 @@ -0,0 +1,73 @@ +/* + * Copyright © 2011 Linaro Limited + * + * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark. + * + * glmark2 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. + * + * glmark2 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 + * glmark2. If not, see . + * + * Authors: + * Alexandros Frantzis (glmark2) + */ +#ifndef GLMARK2_DEFAULT_BENCHMARKS_H_ +#define GLMARK2_DEFAULT_BENCHMARKS_H_ + +#include +#include + +class DefaultBenchmarks +{ +public: + static const std::vector& get() + { + static std::vector default_benchmarks; + + if (default_benchmarks.empty()) + populate(default_benchmarks); + + return default_benchmarks; + } + +private: + static void populate(std::vector& benchmarks) + { + benchmarks.push_back("build:use-vbo=false"); + benchmarks.push_back("build:use-vbo=true"); + benchmarks.push_back("texture:texture-filter=nearest"); + benchmarks.push_back("texture:texture-filter=linear"); + benchmarks.push_back("texture:texture-filter=mipmap"); + benchmarks.push_back("shading:shading=gouraud"); + benchmarks.push_back("shading:shading=blinn-phong-inf"); + benchmarks.push_back("shading:shading=phong"); + benchmarks.push_back("bump:bump-render=high-poly"); + benchmarks.push_back("bump:bump-render=normals"); + benchmarks.push_back("effect2d:kernel=0,1,0;1,-4,1;0,1,0;"); + benchmarks.push_back("effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;"); + benchmarks.push_back("pulsar:quads=5:texture=false:light=false"); + benchmarks.push_back("desktop:windows=4:effect=blur:blur-radius=5:passes=1:separable=true"); + benchmarks.push_back("desktop:windows=4:effect=shadow"); + benchmarks.push_back("buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=false"); + benchmarks.push_back("buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=subdata:interleave=false"); + benchmarks.push_back("buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=true"); + benchmarks.push_back("conditionals:vertex-steps=0:fragment-steps=0"); + benchmarks.push_back("conditionals:vertex-steps=0:fragment-steps=5"); + benchmarks.push_back("conditionals:vertex-steps=5:fragment-steps=0"); + benchmarks.push_back("function:fragment-steps=5:fragment-complexity=low"); + benchmarks.push_back("function:fragment-steps=5:fragment-complexity=medium"); + benchmarks.push_back("loop:vertex-steps=5:fragment-steps=5:fragment-loop=false"); + benchmarks.push_back("loop:vertex-steps=5:fragment-steps=5:fragment-uniform=false"); + benchmarks.push_back("loop:vertex-steps=5:fragment-steps=5:fragment-uniform=true"); + } +}; + +#endif === modified file 'src/main.cpp' --- src/main.cpp 2011-11-08 11:58:19 +0000 +++ src/main.cpp 2011-11-11 11:07:15 +0000 @@ -27,6 +27,7 @@ #include "options.h" #include "log.h" #include "util.h" +#include "default-benchmarks.h" #include #include @@ -41,41 +42,17 @@ using std::map; using std::string; -static const char *default_benchmarks[] = { - "build:use-vbo=false", - "build:use-vbo=true", - "texture:texture-filter=nearest", - "texture:texture-filter=linear", - "texture:texture-filter=mipmap", - "shading:shading=gouraud", - "shading:shading=blinn-phong-inf", - "shading:shading=phong", - "bump:bump-render=high-poly", - "bump:bump-render=normals", - "effect2d:kernel=0,1,0;1,-4,1;0,1,0;", - "effect2d:kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;", - "pulsar:quads=5:texture=false:light=false", - "desktop:windows=4:effect=blur:blur-radius=5:passes=1:separable=true", - "desktop:windows=4:effect=shadow", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=false", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=subdata:interleave=false", - "buffer:update-fraction=0.5:update-dispersion=0.9:columns=200:update-method=map:interleave=true", - "conditionals:vertex-steps=0:fragment-steps=0", - "conditionals:vertex-steps=0:fragment-steps=5", - "conditionals:vertex-steps=5:fragment-steps=0", - "function:fragment-steps=5:fragment-complexity=low", - "function:fragment-steps=5:fragment-complexity=medium", - "loop:vertex-steps=5:fragment-steps=5:fragment-loop=false", - "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=false", - "loop:vertex-steps=5:fragment-steps=5:fragment-uniform=true", - NULL -}; - void add_default_benchmarks(vector &benchmarks) { - for (const char **s = default_benchmarks; *s != NULL; s++) - benchmarks.push_back(new Benchmark(*s)); + const vector &default_benchmarks = DefaultBenchmarks::get(); + + for (vector::const_iterator iter = default_benchmarks.begin(); + iter != default_benchmarks.end(); + iter++) + { + benchmarks.push_back(new Benchmark(*iter)); + } } void === modified file 'src/mesh.cpp' --- src/mesh.cpp 2011-10-27 17:40:51 +0000 +++ src/mesh.cpp 2011-11-09 10:14:02 +0000 @@ -79,6 +79,14 @@ } +/** + * Checks that an attribute is of the correct dimensionality. + * + * @param pos the position/index of the attribute to check + * @param dim the size of the attribute (in #floats) + * + * @return whether the check succeeded + */ bool Mesh::check_attrib(unsigned int pos, int dim) { @@ -96,6 +104,11 @@ } +/** + * Ensures that we have a vertex to process. + * + * @return the vertex to process + */ std::vector & Mesh::ensure_vertex() { @@ -224,6 +237,9 @@ interleave_ = interleave; } +/** + * Resets a Mesh object to its initial, empty state. + */ void Mesh::reset() { @@ -238,6 +254,12 @@ vertex_stride_ = 0; } +/** + * Builds a vertex array containing the mesh vertex data. + * + * The way the vertex array is constructed is affected by the current + * interleave value, which can set using ::interleave(). + */ void Mesh::build_array() { @@ -287,6 +309,12 @@ } } +/** + * Builds a vertex buffer object containing the mesh vertex data. + * + * The way the VBO is constructed is affected by the current interleave + * value (::interleave()) and the vbo usage hint (::vbo_usage()). + */ void Mesh::build_vbo() { @@ -300,7 +328,7 @@ GLenum buffer_usage; if (vbo_usage_ == Mesh::VBOUsageStream) buffer_usage = GL_STREAM_DRAW; - if (vbo_usage_ == Mesh::VBOUsageDynamic) + else if (vbo_usage_ == Mesh::VBOUsageDynamic) buffer_usage = GL_DYNAMIC_DRAW; else /* if (vbo_usage_ == Mesh::VBOUsageStatic) */ buffer_usage = GL_STATIC_DRAW; @@ -477,6 +505,9 @@ } +/** + * Deletes all resources associated with built vertex arrays. + */ void Mesh::delete_array() { @@ -487,6 +518,9 @@ vertex_arrays_.clear(); } +/** + * Deletes all resources associated with built VBOs. + */ void Mesh::delete_vbo() { @@ -499,6 +533,12 @@ } +/** + * Renders a mesh using vertex arrays. + * + * The vertex arrays must have been previously initialized using + * ::build_array(). + */ void Mesh::render_array() { @@ -516,6 +556,12 @@ } } +/** + * Renders a mesh using vertex buffer objects. + * + * The vertex buffer objects must have been previously initialized using + * ::build_vbo(). + */ void Mesh::render_vbo() { @@ -534,6 +580,16 @@ } } +/** + * Creates a grid mesh. + * + * @param n_x the number of grid cells on the X axis + * @param n_y the number of grid cells on the Y axis + * @param width the width X of the grid (normalized) + * @param height the height Y of the grid (normalized) + * @param spacing the spacing between cells (normalized) + * @param conf_func a function to call to configure the grid (or NULL) + */ void Mesh::make_grid(int n_x, int n_y, double width, double height, double spacing, grid_configuration_func conf_func) === modified file 'src/mesh.h' --- src/mesh.h 2011-10-27 17:40:51 +0000 +++ src/mesh.h 2011-11-09 10:14:02 +0000 @@ -20,17 +20,18 @@ * Authors: * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #ifndef GLMARK2_MESH_H_ #define GLMARK2_MESH_H_ -#include "canvas.h" +#include #include "vec.h" - -#include -#include -#include - +#include "gl-headers.h" + +/** + * A mesh of vertices. + */ class Mesh { public: @@ -81,8 +82,6 @@ double spacing, grid_configuration_func conf_func = 0); private: - // check_attrib ensures that the attribute at the specified position is of - // the correct dimensionality (see the description of vertex_format_ below). bool check_attrib(unsigned int pos, int dim); std::vector &ensure_vertex(); void update_single_array(const std::vector >& ranges, === modified file 'src/model.cpp' --- src/model.cpp 2011-11-01 16:55:51 +0000 +++ src/model.cpp 2011-11-09 10:41:52 +0000 @@ -48,6 +48,11 @@ } \ } while(0); +/** + * Computes the bounding box for a Model::Object. + * + * @param object the Model object + */ void Model::compute_bounding_box(const Object& object) { @@ -89,6 +94,15 @@ minVec_ = vec3(minX, minY, minZ); } +/** + * Appends the vertices of a Model::Object to a Mesh. + * + * @param object the object to append + * @param mesh the mesh to append to + * @param p_pos the attribute position to use for the 'position' attribute + * @param n_pos the attribute position to use for the 'normal' attribute + * @param t_pos the attribute position to use for the 'texcoord' attribute + */ void Model::append_object_to_mesh(const Object &object, Mesh &mesh, int p_pos, int n_pos, int t_pos) @@ -129,6 +143,13 @@ } +/** + * Converts a model to a mesh using the default attributes bindings. + * + * The default attributes and their order is: Position, Normal, Texcoord + * + * @param mesh the mesh to populate + */ void Model::convert_to_mesh(Mesh &mesh) { @@ -141,6 +162,14 @@ convert_to_mesh(mesh, attribs); } +/** + * Converts a model to a mesh using custom attribute bindings. + * + * The attribute bindings are pairs of . + * + * @param mesh the mesh to populate + * @param attribs the attribute bindings to use + */ void Model::convert_to_mesh(Mesh &mesh, const std::vector > &attribs) @@ -175,6 +204,9 @@ } } +/** + * Calculates the normal vectors of the model vertices. + */ void Model::calculate_normals() { @@ -207,6 +239,13 @@ } } +/** + * Load a model from a 3DS file. + * + * @param filename the name of the file + * + * @return whether loading succeeded + */ bool Model::load_3ds(const std::string &filename) { @@ -377,8 +416,14 @@ return true; } -void -get_values(const string& source, vec3& v) +/** + * Parse vec3 values from an OBJ file. + * + * @param source the source line to parse + * @param v the vec3 to populate + */ +static void +obj_get_values(const string& source, vec3& v) { // Skip the definition type... string::size_type endPos = source.find(" "); @@ -428,47 +473,14 @@ v.z(z); } -void -get_values(const string& source, vec2& v) -{ - // Skip the definition type... - string::size_type endPos = source.find(" "); - string::size_type startPos(0); - if (endPos == string::npos) - { - Log::error("Bad element '%s'\n", source.c_str()); - return; - } - // Find the first value... - startPos = endPos + 1; - endPos = source.find(" ", startPos); - if (endPos == string::npos) - { - Log::error("Bad element '%s'\n", source.c_str()); - return; - } - string::size_type numChars(endPos - startPos); - string xs(source, startPos, numChars); - float x = Util::fromString(xs); - // Then the second value (there might be a third, but we don't care)... - startPos = endPos + 1; - endPos = source.find(" ", startPos); - if (endPos == string::npos) - { - numChars = endPos; - } - else - { - numChars = endPos - startPos; - } - string ys(source, startPos, numChars); - float y = Util::fromString(ys); - v.x(x); - v.y(y); -} - -void -get_values(const string& source, uvec3& v) +/** + * Parse uvec3 values from an OBJ file. + * + * @param source the source line to parse + * @param v the uvec3 to populate + */ +static void +obj_get_values(const string& source, uvec3& v) { // Skip the definition type... string::size_type endPos = source.find(" "); @@ -518,6 +530,13 @@ v.z(z); } +/** + * Load a model from an OBJ file. + * + * @param filename the name of the file + * + * @return whether loading succeeded + */ bool Model::load_obj(const std::string &filename) { @@ -557,7 +576,7 @@ if (definitionType == vertex_definition) { Vertex v; - get_values(curSrc, v.v); + obj_get_values(curSrc, v.v); object.vertices.push_back(v); } else if (definitionType == normal_definition) @@ -575,7 +594,7 @@ else if (definitionType == face_definition) { uvec3 v; - get_values(curSrc, v); + obj_get_values(curSrc, v); Face f; // OBJ models index from '1'. f.a = v.x() - 1; @@ -597,6 +616,15 @@ ModelMap modelMap; } +/** + * Locate all available models. + * + * This method scans the built-in data paths and build a database of usable + * models available to scenes. Map is available on a read-only basis to scenes + * that might find it useful for listing models, etc. + * + * @return a map containing information about the located models + */ const ModelMap& Model::find_models() { @@ -655,6 +683,16 @@ return ModelPrivate::modelMap; } +/** + * Load a model by name. + * + * You must initialize the available model collection using + * Model::find_models() before using this method. + * + * @param modelName the model name + * + * @return whether the operation succeeded + */ bool Model::load(const string& modelName) { === modified file 'src/model.h' --- src/model.h 2011-11-01 16:55:51 +0000 +++ src/model.h 2011-11-09 10:34:35 +0000 @@ -39,6 +39,9 @@ MODEL_OBJ }; +/** + * A descriptor for a model file. + */ class ModelDescriptor { std::string name_; @@ -58,7 +61,9 @@ typedef std::map ModelMap; -// A model as loaded from a 3D object data file +/** + * A model as loaded from a 3D object data file. + */ class Model { public: @@ -73,7 +78,6 @@ Model() {} ~Model() {} - // Load a named model from the ModelMap. bool load(const std::string& name); void calculate_normals(); @@ -82,11 +86,6 @@ const std::vector > &attribs); const LibMatrix::vec3& minVec() const { return minVec_; } const LibMatrix::vec3& maxVec() const { return maxVec_; } - // Scan the built-in data paths and build a database of usable models - // available to scenes. Map is available on a read-only basis to scenes - // that might find it useful for listing models, etc. - // - // NOTE: This must be called before load(). static const ModelMap& find_models(); private: struct Face { === modified file 'src/scene-buffer.cpp' --- src/scene-buffer.cpp 2011-11-09 15:22:18 +0000 +++ src/scene-buffer.cpp 2011-11-11 11:07:15 +0000 @@ -322,12 +322,12 @@ delete priv_; } -int +bool SceneBuffer::load() { running_ = false; - return 1; + return true; } void @@ -393,7 +393,7 @@ currentFrame_ = 0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -411,7 +411,7 @@ void SceneBuffer::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double elapsed_time = current_time - startTime_; lastUpdateTime_ = current_time; === modified file 'src/scene-build.cpp' --- src/scene-build.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-build.cpp 2011-11-11 11:07:15 +0000 @@ -20,12 +20,15 @@ * Authors: * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include "scene.h" #include "log.h" #include "mat.h" #include "stack.h" #include "shader-source.h" +#include "model.h" +#include "util.h" #include SceneBuild::SceneBuild(Canvas &pCanvas) : @@ -60,14 +63,14 @@ { } -int +bool SceneBuild::load() { rotationSpeed_ = 36.0f; running_ = false; - return 1; + return true; } void @@ -175,7 +178,7 @@ currentFrame_ = 0; rotation_ = 0.0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -193,7 +196,7 @@ void SceneBuild::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-bump.cpp' --- src/scene-bump.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-bump.cpp 2011-11-11 11:07:15 +0000 @@ -18,12 +18,16 @@ * * Authors: * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include "scene.h" #include "log.h" #include "mat.h" #include "stack.h" #include "shader-source.h" +#include "model.h" +#include "texture.h" +#include "util.h" #include SceneBump::SceneBump(Canvas &pCanvas) : @@ -38,14 +42,14 @@ { } -int +bool SceneBump::load() { rotationSpeed_ = 36.0f; running_ = false; - return 1; + return true; } void @@ -178,7 +182,7 @@ currentFrame_ = 0; rotation_ = 0.0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -199,7 +203,7 @@ void SceneBump::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-conditionals.cpp' --- src/scene-conditionals.cpp 2011-11-09 15:22:18 +0000 +++ src/scene-conditionals.cpp 2011-11-11 11:07:15 +0000 @@ -113,7 +113,7 @@ mesh_.set_attrib_locations(attrib_locations); running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } === modified file 'src/scene-desktop.cpp' --- src/scene-desktop.cpp 2011-11-09 15:22:18 +0000 +++ src/scene-desktop.cpp 2011-11-11 11:07:15 +0000 @@ -18,6 +18,7 @@ * * Authors: * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include #include @@ -30,6 +31,7 @@ #include "program.h" #include "shader-source.h" #include "util.h" +#include "texture.h" enum BlurDirection { BlurDirectionHorizontal, @@ -758,10 +760,10 @@ delete priv_; } -int +bool SceneDesktop::load() { - return 1; + return true; } void @@ -840,7 +842,7 @@ currentFrame_ = 0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -862,7 +864,7 @@ void SceneDesktop::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-effect-2d.cpp' --- src/scene-effect-2d.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-effect-2d.cpp 2011-11-11 11:07:15 +0000 @@ -18,6 +18,7 @@ * * Authors: * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include #include @@ -31,7 +32,7 @@ #include "program.h" #include "shader-source.h" #include "util.h" - +#include "texture.h" SceneEffect2D::SceneEffect2D(Canvas &pCanvas) : Scene(pCanvas, "effect2d") @@ -274,14 +275,14 @@ } -int +bool SceneEffect2D::load() { Texture::load(GLMARK_DATA_PATH"/textures/effect-2d.png", &texture_, GL_NEAREST, GL_NEAREST, 0); running_ = false; - return 1; + return true; } void @@ -349,7 +350,7 @@ currentFrame_ = 0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -367,7 +368,7 @@ void SceneEffect2D::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double elapsed_time = current_time - startTime_; lastUpdateTime_ = current_time; === modified file 'src/scene-function.cpp' --- src/scene-function.cpp 2011-11-09 15:22:18 +0000 +++ src/scene-function.cpp 2011-11-11 11:07:15 +0000 @@ -145,7 +145,7 @@ mesh_.set_attrib_locations(attrib_locations); running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } === modified file 'src/scene-grid.cpp' --- src/scene-grid.cpp 2011-11-01 16:46:08 +0000 +++ src/scene-grid.cpp 2011-11-08 21:40:36 +0000 @@ -39,13 +39,13 @@ { } -int +bool SceneGrid::load() { rotationSpeed_ = 36.0f; running_ = false; - return 1; + return true; } void @@ -93,7 +93,7 @@ void SceneGrid::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-loop.cpp' --- src/scene-loop.cpp 2011-11-09 15:22:18 +0000 +++ src/scene-loop.cpp 2011-11-11 11:07:15 +0000 @@ -140,7 +140,7 @@ mesh_.set_attrib_locations(attrib_locations); running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } === modified file 'src/scene-pulsar.cpp' --- src/scene-pulsar.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-pulsar.cpp 2011-11-11 11:07:15 +0000 @@ -21,7 +21,7 @@ * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) * Marc Ordinas i Llopis, Collabora Ltd. (pulsar scene) - * Jesse Barker + * Jesse Barker (glmark2) */ #include #include "scene.h" @@ -31,7 +31,7 @@ #include "log.h" #include "shader-source.h" #include "util.h" - +#include "texture.h" #include using LibMatrix::vec2; @@ -55,14 +55,14 @@ { } -int +bool ScenePulsar::load() { scale_ = vec3(1.0, 1.0, 1.0); running_ = false; - return 1; + return true; } void @@ -141,7 +141,7 @@ currentFrame_ = 0; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -169,7 +169,7 @@ void ScenePulsar::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-shading.cpp' --- src/scene-shading.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-shading.cpp 2011-11-11 11:07:15 +0000 @@ -20,6 +20,7 @@ * Authors: * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include "scene.h" #include "mat.h" @@ -28,6 +29,7 @@ #include "log.h" #include "util.h" #include "shader-source.h" +#include "model.h" #include #include @@ -68,14 +70,14 @@ { } -int +bool SceneShading::load() { rotationSpeed_ = 36.0f; running_ = false; - return 1; + return true; } void @@ -247,7 +249,7 @@ currentFrame_ = 0; rotation_ = 0.0f; running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -263,7 +265,7 @@ void SceneShading::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene-texture.cpp' --- src/scene-texture.cpp 2011-11-08 13:57:38 +0000 +++ src/scene-texture.cpp 2011-11-11 11:07:15 +0000 @@ -20,6 +20,7 @@ * Authors: * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) + * Jesse Barker (glmark2) */ #include "scene.h" #include "mat.h" @@ -28,7 +29,9 @@ #include "log.h" #include "program.h" #include "shader-source.h" - +#include "texture.h" +#include "model.h" +#include "util.h" #include SceneTexture::SceneTexture(Canvas &pCanvas) : @@ -42,14 +45,14 @@ { } -int +bool SceneTexture::load() { Model::find_models(); Model model; if(!model.load("cube")) - return 0; + return false; model.calculate_normals(); model.convert_to_mesh(mesh_); @@ -59,7 +62,7 @@ running_ = false; - return 1; + return true; } void @@ -123,7 +126,7 @@ currentFrame_ = 0; rotation_ = LibMatrix::vec3(); running_ = true; - startTime_ = Scene::get_timestamp_us() / 1000000.0; + startTime_ = Util::get_timestamp_us() / 1000000.0; lastUpdateTime_ = startTime_; } @@ -141,7 +144,7 @@ void SceneTexture::update() { - double current_time = Scene::get_timestamp_us() / 1000000.0; + double current_time = Util::get_timestamp_us() / 1000000.0; double dt = current_time - lastUpdateTime_; double elapsed_time = current_time - startTime_; === modified file 'src/scene.cpp' --- src/scene.cpp 2011-11-11 10:48:24 +0000 +++ src/scene.cpp 2011-11-11 11:07:15 +0000 @@ -28,7 +28,6 @@ #include "util.h" #include #include -#include using std::stringstream; using std::string; @@ -53,10 +52,10 @@ { } -int +bool Scene::load() { - return 1; + return true; } void @@ -232,33 +231,3 @@ return true; } - -bool -Scene::load_shaders_from_files(Program &program, - const std::string &vtx_shader_filename, - const std::string &frg_shader_filename) -{ - std::string vtx_shader; - std::string frg_shader; - - if (!gotSource(vtx_shader_filename, vtx_shader)) - return false; - - if (!gotSource(frg_shader_filename, frg_shader)) - return false; - - return Scene::load_shaders_from_strings(program, vtx_shader, frg_shader, - vtx_shader_filename, - frg_shader_filename); - -} - -uint64_t -Scene::get_timestamp_us() -{ - struct timeval tv; - gettimeofday(&tv, NULL); - uint64_t now = static_cast(tv.tv_sec) * 1000000 + - static_cast(tv.tv_usec); - return now; -} === modified file 'src/scene.h' --- src/scene.h 2011-11-08 13:57:38 +0000 +++ src/scene.h 2011-11-11 11:07:15 +0000 @@ -21,6 +21,7 @@ * Ben Smith (original glmark benchmark) * Alexandros Frantzis (glmark2) * Marc Ordinas i Llopis, Collabora Ltd. (pulsar scene) + * Jesse Barker (glmark2) */ #ifndef GLMARK2_SCENE_H_ #define GLMARK2_SCENE_H_ @@ -28,8 +29,6 @@ #include "gl-headers.h" #include "mesh.h" -#include "model.h" -#include "texture.h" #include "vec.h" #include "program.h" @@ -38,12 +37,19 @@ #include #include #include +#include "canvas.h" +/** + * A configurable scene used for creating benchmarks. + */ class Scene { public: virtual ~Scene(); + /** + * Scene options. + */ struct Option { Option(const std::string &nam, const std::string &val, const std::string &desc) : name(nam), value(val), default_value(val), description(desc), set(false) {} @@ -55,56 +61,144 @@ bool set; }; + /** + * The result of a validation check. + */ enum ValidationResult { ValidationFailure, ValidationSuccess, ValidationUnknown }; - // load() and unload() handle option-independent configuration. - // It should be safe to call these only once per program execution, - // although you may choose to do so more times to better manage - // resource consumption. - virtual int load(); + /** + * Performs option-independent resource loading and configuration. + * + * It should be safe to call ::load() (and the corresponding ::unload()) + * only once per program execution, although you may choose to do so more + * times to better manage resource consumption. + * + * @return whether loading succeeded + */ + virtual bool load(); + + /** + * Performs option-independent resource unloading. + */ virtual void unload(); - // setup() and teardown() handle option-dependent configuration and - // also prepare a scene for a benchmark run. - // They should be called just before and after running a scene/benchmark. + /** + * Performs option-dependent resource loading and configuration. + * + * This method also prepares a scene for a benchmark run. + * It should be called just before running a scene/benchmark. + * + * @return the operation status + */ virtual void setup(); + + /** + * Performs option-dependent resource unloading. + * + * This method should be called just after running a scene/benchmark. + * + * @return the operation status + */ virtual void teardown(); + /** + * Updates the scene state. + */ virtual void update(); + + /** + * Draws the current scene state. + */ virtual void draw(); + + /** + * Gets an informational string describing the scene. + * + * @param title if specified, a custom title to use, instead of the default + */ virtual std::string info_string(const std::string &title = ""); + /** + * Sets the value of an option for this scene. + * + * @param opt the option to set + * @param val the value to set the option to + * + * @return whether the option value was set successfully + */ + virtual bool set_option(const std::string &opt, const std::string &val); + + /** + * Validates the current output of this scene. + * + * This method should be called after having called ::draw() once. + * + * @return the validation result + */ + virtual ValidationResult validate() { return ValidationUnknown; } + + /** + * Gets whether this scene is running. + * + * @return true if running, false otherwise + */ + bool is_running(); + + /** + * Gets the average FPS value for this scene. + * + * @return the average FPS value + */ unsigned average_fps(); - bool is_running(); + /** + * Gets the name of the scene. + * @return the name of the scene + */ const std::string &name() { return name_; } - virtual bool set_option(const std::string &opt, const std::string &val); + + /** + * Resets all scene options to their default values. + */ void reset_options(); + + /** + * Sets the default value of a scene option. + */ bool set_option_default(const std::string &opt, const std::string &val); + + /** + * Gets the scene options. + * + * @return the scene options + */ const std::map &options() { return options_; } + /** + * Gets a dummy scene object reference. + * + * @return the dummy Scene + */ static Scene &dummy() { static Scene dummy_scene(Canvas::dummy(), ""); return dummy_scene; } - virtual ValidationResult validate() { return ValidationUnknown; } - + /** + * Loads a shader program from a pair of vertex and fragment shader strings. + * + * @return whether the operation succeeded + */ static bool load_shaders_from_strings(Program &program, const std::string &vtx_shader, const std::string &frg_shader, const std::string &vtx_shader_filename = "None", const std::string &frg_shader_filename = "None"); - static bool load_shaders_from_files(Program &program, - const std::string &vtx_shader_filename, - const std::string &frg_shader_filename); - - static uint64_t get_timestamp_us(); protected: Scene(Canvas &pCanvas, const std::string &name); @@ -139,7 +233,7 @@ { public: SceneBuild(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -167,7 +261,7 @@ { public: SceneTexture(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -189,7 +283,7 @@ { public: SceneShading(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -216,7 +310,7 @@ { public: SceneGrid(Canvas &pCanvas, const std::string &name); - virtual int load(); + virtual bool load(); virtual void unload(); virtual void setup(); virtual void teardown(); @@ -267,7 +361,7 @@ { public: SceneBump(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -292,7 +386,7 @@ { public: SceneEffect2D(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -313,7 +407,7 @@ { public: ScenePulsar(Canvas &pCanvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -342,7 +436,7 @@ { public: SceneDesktop(Canvas &canvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); @@ -362,7 +456,7 @@ { public: SceneBuffer(Canvas &canvas); - int load(); + bool load(); void unload(); void setup(); void teardown(); === modified file 'src/texture.cpp' --- src/texture.cpp 2011-08-11 08:42:00 +0000 +++ src/texture.cpp 2011-11-08 21:41:23 +0000 @@ -177,13 +177,13 @@ } } -int +bool Texture::load(const std::string &filename, GLuint *pTexture, ...) { ImageData image; if (!image.load_png(filename)) - return 0; + return false; va_list ap; va_start(ap, pTexture); @@ -197,5 +197,5 @@ va_end(ap); - return 1; + return true; } === modified file 'src/texture.h' --- src/texture.h 2011-06-30 13:33:37 +0000 +++ src/texture.h 2011-11-08 21:41:23 +0000 @@ -31,7 +31,7 @@ class Texture { public: - static int load(const std::string &filename, GLuint *pTexture, ...); + static bool load(const std::string &filename, GLuint *pTexture, ...); }; #endif === modified file 'src/util.cpp' --- src/util.cpp 2011-10-26 11:12:19 +0000 +++ src/util.cpp 2011-11-08 20:41:46 +0000 @@ -23,6 +23,7 @@ #include #include +#include #ifdef ANDROID #include #else @@ -49,6 +50,16 @@ elems.push_back(item); } +uint64_t +Util::get_timestamp_us() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t now = static_cast(tv.tv_sec) * 1000000 + + static_cast(tv.tv_usec); + return now; +} + #ifndef ANDROID std::istream * === modified file 'src/util.h' --- src/util.h 2011-10-31 20:42:52 +0000 +++ src/util.h 2011-11-08 20:41:46 +0000 @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef ANDROID #include @@ -35,6 +36,7 @@ struct Util { static void split(const std::string &s, char delim, std::vector &elems); + static uint64_t get_timestamp_us(); static std::istream *get_resource(const std::string &path); static void list_files(const std::string& dirName, std::vector& fileVec); template static void dispose_pointer_vector(std::vector &vec)