From patchwork Thu Jul 21 12:36:36 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: 2986 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 9715B23F52 for ; Thu, 21 Jul 2011 12:43:48 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 65BE3A18287 for ; Thu, 21 Jul 2011 12:43:48 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so853237qwb.11 for ; Thu, 21 Jul 2011 05:43:48 -0700 (PDT) Received: by 10.229.68.200 with SMTP id w8mr191755qci.114.1311252228179; Thu, 21 Jul 2011 05:43:48 -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.217.78 with SMTP id hl14cs139559qcb; Thu, 21 Jul 2011 05:43:47 -0700 (PDT) Received: by 10.216.220.220 with SMTP id o70mr731869wep.71.1311251797580; Thu, 21 Jul 2011 05:36:37 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id x47si2406070weq.2.2011.07.21.05.36.37; Thu, 21 Jul 2011 05:36:37 -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 1QjsUW-0000Cu-Lu for ; Thu, 21 Jul 2011 12:36:36 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id A432C2E889B for ; Thu, 21 Jul 2011 12:36:36 +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: 90 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 90: Bring some sanity to source file names. Message-Id: <20110721123636.17019.46032.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:36 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13475"; Instance="initZopeless config overlay" X-Launchpad-Hash: d07cb1f5256327c4768025e5eacee71b4cae81ae ------------------------------------------------------------ revno: 90 committer: Alexandros Frantzis timestamp: Thu 2011-06-23 15:48:15 +0300 message: Bring some sanity to source file names. removed: src/scenebuild.cpp src/scenedefaultoptions.cpp src/sceneshading.cpp src/scenetexture.cpp added: src/scene-build.cpp src/scene-default-options.cpp src/scene-shading.cpp src/scene-texture.cpp --- 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 === added file 'src/scene-build.cpp' --- src/scene-build.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-build.cpp 2011-06-23 12:48:15 +0000 @@ -0,0 +1,185 @@ +/* + * Copyright © 2008 Ben Smith + * Copyright © 2010-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: + * Ben Smith (original glmark benchmark) + * Alexandros Frantzis (glmark2) + */ +#include "scene.h" +#include "log.h" +#include "mat.h" +#include "stack.h" +#include + +SceneBuild::SceneBuild(Screen &pScreen) : + Scene(pScreen, "build") +{ + mOptions["use-vbo"] = Scene::Option("use-vbo", "true", + "Whether to use VBOs for rendering [true,false]"); +} + +SceneBuild::~SceneBuild() +{ +} + +int SceneBuild::load() +{ + static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert"); + static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.frag"); + Model model; + + if(!model.load_3ds(GLMARK_DATA_PATH"/models/horse.3ds")) + return 0; + + model.calculate_normals(); + model.convert_to_mesh(&mMesh); + + if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) + return 0; + + mVertexAttribLocation = mProgram.getAttribIndex("position"); + mNormalAttribLocation = mProgram.getAttribIndex("normal"); + mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); + + mRotationSpeed = 36.0f; + + mRunning = false; + + return 1; +} + +void SceneBuild::unload() +{ + mMesh.reset(); + + mProgram.stop(); + mProgram.release(); +} + +void SceneBuild::setup() +{ + Scene::setup(); + + static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f); + static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f); + static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); + static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f); + + mUseVbo = (mOptions["use-vbo"].value == "true"); + + if (mUseVbo) + mMesh.build_vbo(); + + mProgram.start(); + + // Load lighting and material uniforms + mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); + mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); + mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); + mProgram.loadUniformVector(materialColor, "MaterialColor"); + + mCurrentFrame = 0; + mRotation = 0.0; + mRunning = true; + mStartTime = SDL_GetTicks() / 1000.0; + mLastUpdateTime = mStartTime; +} + +void +SceneBuild::teardown() +{ + mProgram.stop(); + + if (mUseVbo) + mMesh.delete_vbo(); + + Scene::teardown(); +} + +void SceneBuild::update() +{ + double current_time = SDL_GetTicks() / 1000.0; + double dt = current_time - mLastUpdateTime; + double elapsed_time = current_time - mStartTime; + + mLastUpdateTime = current_time; + + if (elapsed_time >= mDuration) { + mAverageFPS = mCurrentFrame / elapsed_time; + mRunning = false; + } + + mRotation += mRotationSpeed * dt; + + mCurrentFrame++; +} + +void SceneBuild::draw() +{ + LibMatrix::Stack4 model_view; + + // Load the ModelViewProjectionMatrix uniform in the shader + LibMatrix::mat4 model_view_proj(mScreen.mProjection); + + model_view.translate(0.0f, 0.0f, -2.5f); + model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f); + model_view_proj *= model_view.getCurrent(); + + mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); + + // Load the NormalMatrix uniform in the shader. The NormalMatrix is the + // inverse transpose of the model view matrix. + LibMatrix::mat4 normal_matrix(model_view.getCurrent()); + normal_matrix.inverse().transpose(); + mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); + + if (mUseVbo) { + mMesh.render_vbo(mVertexAttribLocation, + mNormalAttribLocation, + mTexcoordAttribLocation); + } + else { + mMesh.render_array(mVertexAttribLocation, + mNormalAttribLocation, + mTexcoordAttribLocation); + } +} + +Scene::ValidationResult +SceneBuild::validate() +{ + static const double radius_3d(std::sqrt(3.0)); + + if (mRotation != 0) + return Scene::ValidationUnknown; + + Screen::Pixel ref(0xa7, 0xa7, 0xa7, 0xff); + Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, + mScreen.mHeight / 2); + + double dist = pixel_value_distance(pixel, ref); + if (dist < radius_3d + 0.01) { + return Scene::ValidationSuccess; + } + else { + Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", + ref.to_le32(), pixel.to_le32(), dist); + return Scene::ValidationFailure; + } +} === added file 'src/scene-default-options.cpp' --- src/scene-default-options.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-default-options.cpp 2011-06-23 12:48:15 +0000 @@ -0,0 +1,47 @@ +/* + * Copyright © 2010-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) + */ +#include "scene.h" +#include "benchmark.h" + +void SceneDefaultOptions::setup() +{ + const std::map &scenes = Benchmark::scenes(); + + for (std::list >::const_iterator iter = mDefaultOptions.begin(); + iter != mDefaultOptions.end(); + iter++) + { + for (std::map::const_iterator scene_iter = scenes.begin(); + scene_iter != scenes.end(); + scene_iter++) + { + scene_iter->second->set_option_default(iter->first, iter->second); + } + } +} + +bool +SceneDefaultOptions::set_option(const std::string &opt, const std::string &val) +{ + mDefaultOptions.push_back(std::pair(opt, val)); + return true; +} === added file 'src/scene-shading.cpp' --- src/scene-shading.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-shading.cpp 2011-06-23 12:48:15 +0000 @@ -0,0 +1,209 @@ +/* + * Copyright © 2008 Ben Smith + * Copyright © 2010-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: + * Ben Smith (original glmark benchmark) + * Alexandros Frantzis (glmark2) + */ +#include "scene.h" +#include "mat.h" +#include "stack.h" +#include "vec.h" +#include "log.h" + +#include + +SceneShading::SceneShading(Screen &pScreen) : + Scene(pScreen, "shading") +{ + mOptions["shading"] = Scene::Option("shading", "gouraud", + "[gouraud, phong]"); +} + +SceneShading::~SceneShading() +{ +} + +int SceneShading::load() +{ + Model model; + + if(!model.load_3ds(GLMARK_DATA_PATH"/models/cat.3ds")) + return 0; + + model.calculate_normals(); + model.convert_to_mesh(&mMesh); + + mMesh.build_vbo(); + + mRotationSpeed = 36.0f; + + mRunning = false; + + return 1; +} + +void SceneShading::unload() +{ + mMesh.reset(); +} + +void SceneShading::setup() +{ + Scene::setup(); + + static const LibMatrix::vec3 lightAmbient(0.1f, 0.1f, 0.1f); + static const LibMatrix::vec3 lightDiffuse(0.8f, 0.8f, 0.8f); + static const LibMatrix::vec3 lightSpecular(0.8f, 0.8f, 0.8f); + static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); + + static const LibMatrix::vec3 materialAmbient(1.0f, 1.0f, 1.0f); + static const LibMatrix::vec3 materialDiffuse(1.0f, 1.0f, 1.0f); + static const LibMatrix::vec3 materialSpecular(1.0f, 1.0f, 1.0f); + static const LibMatrix::vec4 materialColor(0.0f, 0.0f, 1.0f, 1.0f); + + std::string vtx_shader_filename; + std::string frg_shader_filename; + const std::string &shading = mOptions["shading"].value; + + if (shading == "gouraud") { + vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.vert"; + frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag"; + } + else if (shading == "phong") { + vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.vert"; + frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.frag"; + } + + if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) + return; + + mProgram.start(); + + mVertexAttribLocation = mProgram.getAttribIndex("position"); + mNormalAttribLocation = mProgram.getAttribIndex("normal"); + mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); + + // Load lighting and material uniforms + mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); + mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); + mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); + mProgram.loadUniformVector(lightSpecular, "LightSourceSpecular"); + + mProgram.loadUniformVector(materialAmbient, "MaterialAmbient"); + mProgram.loadUniformVector(materialDiffuse, "MaterialDiffuse"); + mProgram.loadUniformVector(materialSpecular, "MaterialSpecular"); + mProgram.loadUniformVector(materialColor, "MaterialColor"); + + // Calculate and load the half vector + LibMatrix::vec3 halfVector(lightPosition[0], lightPosition[1], lightPosition[2]); + halfVector.normalize(); + halfVector += LibMatrix::vec3(0.0, 0.0, 1.0); + halfVector.normalize(); + mProgram.loadUniformVector(halfVector, "LightSourceHalfVector"); + + mCurrentFrame = 0; + mRotation = 0.0f; + mRunning = true; + mStartTime = SDL_GetTicks() / 1000.0; + mLastUpdateTime = mStartTime; +} + +void SceneShading::teardown() +{ + mProgram.stop(); + mProgram.release(); + + Scene::teardown(); +} + +void SceneShading::update() +{ + double current_time = SDL_GetTicks() / 1000.0; + double dt = current_time - mLastUpdateTime; + double elapsed_time = current_time - mStartTime; + + mLastUpdateTime = current_time; + + if (elapsed_time >= mDuration) { + mAverageFPS = mCurrentFrame / elapsed_time; + mRunning = false; + } + + mRotation += mRotationSpeed * dt; + + mCurrentFrame++; +} + +void SceneShading::draw() +{ + // Load the ModelViewProjectionMatrix uniform in the shader + LibMatrix::Stack4 model_view; + LibMatrix::mat4 model_view_proj(mScreen.mProjection); + + model_view.translate(0.0f, 0.0f, -5.0f); + model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f); + model_view_proj *= model_view.getCurrent(); + + mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); + + // Load the NormalMatrix uniform in the shader. The NormalMatrix is the + // inverse transpose of the model view matrix. + LibMatrix::mat4 normal_matrix(model_view.getCurrent()); + normal_matrix.inverse().transpose(); + mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); + + mMesh.render_vbo(mVertexAttribLocation, + mNormalAttribLocation, + mTexcoordAttribLocation); +} + +Scene::ValidationResult +SceneShading::validate() +{ + static const double radius_3d(std::sqrt(3.0)); + + if (mRotation != 0) + return Scene::ValidationUnknown; + + Screen::Pixel ref; + + Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, + mScreen.mHeight / 2); + + const std::string &filter = mOptions["shading"].value; + + if (filter == "gouraud") + ref = Screen::Pixel(0x00, 0x00, 0xca, 0xff); + else if (filter == "phong") + ref = Screen::Pixel(0x1a, 0x1a, 0xbb, 0xff); + else + return Scene::ValidationUnknown; + + double dist = pixel_value_distance(pixel, ref); + + if (dist < radius_3d + 0.01) { + return Scene::ValidationSuccess; + } + else { + Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", + ref.to_le32(), pixel.to_le32(), dist); + return Scene::ValidationFailure; + } +} === added file 'src/scene-texture.cpp' --- src/scene-texture.cpp 1970-01-01 00:00:00 +0000 +++ src/scene-texture.cpp 2011-06-23 12:48:15 +0000 @@ -0,0 +1,212 @@ +/* + * Copyright © 2008 Ben Smith + * Copyright © 2010-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: + * Ben Smith (original glmark benchmark) + * Alexandros Frantzis (glmark2) + */ +#include "scene.h" +#include "mat.h" +#include "stack.h" +#include "vec.h" +#include "log.h" + +#include "program.h" +#include + +SceneTexture::SceneTexture(Screen &pScreen) : + Scene(pScreen, "texture") +{ + mOptions["texture-filter"] = Scene::Option("texture-filter", "nearest", + "[nearest, linear, mipmap]"); +} + +SceneTexture::~SceneTexture() +{ +} + +int SceneTexture::load() +{ + static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert"); + static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex.frag"); + Model model; + + if(!model.load_3ds(GLMARK_DATA_PATH"/models/cube.3ds")) + return 0; + + model.calculate_normals(); + model.convert_to_mesh(&mCubeMesh); + mCubeMesh.build_vbo(); + + if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) + return 0; + + mVertexAttribLocation = mProgram.getAttribIndex("position"); + mNormalAttribLocation = mProgram.getAttribIndex("normal"); + mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); + + mRotationSpeed = LibMatrix::vec3(36.0f, 36.0f, 36.0f); + + mRunning = false; + + return 1; +} + +void SceneTexture::unload() +{ + mCubeMesh.reset(); + + mProgram.stop(); + mProgram.release(); +} + +void SceneTexture::setup() +{ + Scene::setup(); + + static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f); + static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f); + static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); + static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f); + + // Create texture according to selected filtering + GLint min_filter = GL_NONE; + GLint mag_filter = GL_NONE; + const std::string &filter = mOptions["texture-filter"].value; + + if (filter == "nearest") { + min_filter = GL_NEAREST; + mag_filter = GL_NEAREST; + } + else if (filter == "linear") { + min_filter = GL_LINEAR; + mag_filter = GL_LINEAR; + } + else if (filter == "mipmap") { + min_filter = GL_LINEAR_MIPMAP_LINEAR; + mag_filter = GL_LINEAR; + } + + Texture::load(GLMARK_DATA_PATH"/textures/crate-base.bmp", &mTexture, + min_filter, mag_filter, 0); + + mProgram.start(); + + // Load lighting and material uniforms + mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); + mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); + mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); + mProgram.loadUniformVector(materialColor, "MaterialColor"); + + mCurrentFrame = 0; + mRotation = LibMatrix::vec3(); + mRunning = true; + mStartTime = SDL_GetTicks() / 1000.0; + mLastUpdateTime = mStartTime; +} + +void SceneTexture::teardown() +{ + mProgram.stop(); + glDeleteTextures(1, &mTexture); + + Scene::teardown(); +} + +void SceneTexture::update() +{ + double current_time = SDL_GetTicks() / 1000.0; + double dt = current_time - mLastUpdateTime; + double elapsed_time = current_time - mStartTime; + + mLastUpdateTime = current_time; + + if (elapsed_time >= mDuration) { + mAverageFPS = mCurrentFrame / elapsed_time; + mRunning = false; + } + + mRotation += mRotationSpeed * dt; + + mCurrentFrame++; +} + +void SceneTexture::draw() +{ + // Load the ModelViewProjectionMatrix uniform in the shader + LibMatrix::Stack4 model_view; + LibMatrix::mat4 model_view_proj(mScreen.mProjection); + + model_view.translate(0.0f, 0.0f, -5.0f); + model_view.rotate(mRotation.x(), 1.0f, 0.0f, 0.0f); + model_view.rotate(mRotation.y(), 0.0f, 1.0f, 0.0f); + model_view.rotate(mRotation.z(), 0.0f, 0.0f, 1.0f); + model_view_proj *= model_view.getCurrent(); + + mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); + + // Load the NormalMatrix uniform in the shader. The NormalMatrix is the + // inverse transpose of the model view matrix. + LibMatrix::mat4 normal_matrix(model_view.getCurrent()); + normal_matrix.inverse().transpose(); + mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, mTexture); + + mCubeMesh.render_vbo(mVertexAttribLocation, + mNormalAttribLocation, + mTexcoordAttribLocation); +} + +Scene::ValidationResult +SceneTexture::validate() +{ + static const double radius_3d(std::sqrt(3.0)); + + if (mRotation.x() != 0 || mRotation.y() != 0 || mRotation.z() != 0) + return Scene::ValidationUnknown; + + Screen::Pixel ref; + + Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, + mScreen.mHeight / 2); + + const std::string &filter = mOptions["texture-filter"].value; + + if (filter == "nearest") + ref = Screen::Pixel(0x3a, 0x3a, 0x3b, 0xff); + else if (filter == "linear") + ref = Screen::Pixel(0x34, 0x34, 0x35, 0xff); + else if (filter == "mipmap") + ref = Screen::Pixel(0x33, 0x33, 0x35, 0xff); + else + return Scene::ValidationUnknown; + + double dist = pixel_value_distance(pixel, ref); + + if (dist < radius_3d + 0.01) { + return Scene::ValidationSuccess; + } + else { + Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", + ref.to_le32(), pixel.to_le32(), dist); + return Scene::ValidationFailure; + } +} === removed file 'src/scenebuild.cpp' --- src/scenebuild.cpp 2011-06-17 13:16:16 +0000 +++ src/scenebuild.cpp 1970-01-01 00:00:00 +0000 @@ -1,185 +0,0 @@ -/* - * Copyright © 2008 Ben Smith - * Copyright © 2010-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: - * Ben Smith (original glmark benchmark) - * Alexandros Frantzis (glmark2) - */ -#include "scene.h" -#include "log.h" -#include "mat.h" -#include "stack.h" -#include - -SceneBuild::SceneBuild(Screen &pScreen) : - Scene(pScreen, "build") -{ - mOptions["use-vbo"] = Scene::Option("use-vbo", "true", - "Whether to use VBOs for rendering [true,false]"); -} - -SceneBuild::~SceneBuild() -{ -} - -int SceneBuild::load() -{ - static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert"); - static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.frag"); - Model model; - - if(!model.load_3ds(GLMARK_DATA_PATH"/models/horse.3ds")) - return 0; - - model.calculate_normals(); - model.convert_to_mesh(&mMesh); - - if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) - return 0; - - mVertexAttribLocation = mProgram.getAttribIndex("position"); - mNormalAttribLocation = mProgram.getAttribIndex("normal"); - mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); - - mRotationSpeed = 36.0f; - - mRunning = false; - - return 1; -} - -void SceneBuild::unload() -{ - mMesh.reset(); - - mProgram.stop(); - mProgram.release(); -} - -void SceneBuild::setup() -{ - Scene::setup(); - - static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f); - static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f); - static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); - static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f); - - mUseVbo = (mOptions["use-vbo"].value == "true"); - - if (mUseVbo) - mMesh.build_vbo(); - - mProgram.start(); - - // Load lighting and material uniforms - mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); - mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); - mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); - mProgram.loadUniformVector(materialColor, "MaterialColor"); - - mCurrentFrame = 0; - mRotation = 0.0; - mRunning = true; - mStartTime = SDL_GetTicks() / 1000.0; - mLastUpdateTime = mStartTime; -} - -void -SceneBuild::teardown() -{ - mProgram.stop(); - - if (mUseVbo) - mMesh.delete_vbo(); - - Scene::teardown(); -} - -void SceneBuild::update() -{ - double current_time = SDL_GetTicks() / 1000.0; - double dt = current_time - mLastUpdateTime; - double elapsed_time = current_time - mStartTime; - - mLastUpdateTime = current_time; - - if (elapsed_time >= mDuration) { - mAverageFPS = mCurrentFrame / elapsed_time; - mRunning = false; - } - - mRotation += mRotationSpeed * dt; - - mCurrentFrame++; -} - -void SceneBuild::draw() -{ - LibMatrix::Stack4 model_view; - - // Load the ModelViewProjectionMatrix uniform in the shader - LibMatrix::mat4 model_view_proj(mScreen.mProjection); - - model_view.translate(0.0f, 0.0f, -2.5f); - model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f); - model_view_proj *= model_view.getCurrent(); - - mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); - - // Load the NormalMatrix uniform in the shader. The NormalMatrix is the - // inverse transpose of the model view matrix. - LibMatrix::mat4 normal_matrix(model_view.getCurrent()); - normal_matrix.inverse().transpose(); - mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); - - if (mUseVbo) { - mMesh.render_vbo(mVertexAttribLocation, - mNormalAttribLocation, - mTexcoordAttribLocation); - } - else { - mMesh.render_array(mVertexAttribLocation, - mNormalAttribLocation, - mTexcoordAttribLocation); - } -} - -Scene::ValidationResult -SceneBuild::validate() -{ - static const double radius_3d(std::sqrt(3.0)); - - if (mRotation != 0) - return Scene::ValidationUnknown; - - Screen::Pixel ref(0xa7, 0xa7, 0xa7, 0xff); - Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, - mScreen.mHeight / 2); - - double dist = pixel_value_distance(pixel, ref); - if (dist < radius_3d + 0.01) { - return Scene::ValidationSuccess; - } - else { - Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", - ref.to_le32(), pixel.to_le32(), dist); - return Scene::ValidationFailure; - } -} === removed file 'src/scenedefaultoptions.cpp' --- src/scenedefaultoptions.cpp 2011-06-23 12:32:34 +0000 +++ src/scenedefaultoptions.cpp 1970-01-01 00:00:00 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright © 2010-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) - */ -#include "scene.h" -#include "benchmark.h" - -void SceneDefaultOptions::setup() -{ - const std::map &scenes = Benchmark::scenes(); - - for (std::list >::const_iterator iter = mDefaultOptions.begin(); - iter != mDefaultOptions.end(); - iter++) - { - for (std::map::const_iterator scene_iter = scenes.begin(); - scene_iter != scenes.end(); - scene_iter++) - { - scene_iter->second->set_option_default(iter->first, iter->second); - } - } -} - -bool -SceneDefaultOptions::set_option(const std::string &opt, const std::string &val) -{ - mDefaultOptions.push_back(std::pair(opt, val)); - return true; -} === removed file 'src/sceneshading.cpp' --- src/sceneshading.cpp 2011-06-17 13:16:16 +0000 +++ src/sceneshading.cpp 1970-01-01 00:00:00 +0000 @@ -1,209 +0,0 @@ -/* - * Copyright © 2008 Ben Smith - * Copyright © 2010-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: - * Ben Smith (original glmark benchmark) - * Alexandros Frantzis (glmark2) - */ -#include "scene.h" -#include "mat.h" -#include "stack.h" -#include "vec.h" -#include "log.h" - -#include - -SceneShading::SceneShading(Screen &pScreen) : - Scene(pScreen, "shading") -{ - mOptions["shading"] = Scene::Option("shading", "gouraud", - "[gouraud, phong]"); -} - -SceneShading::~SceneShading() -{ -} - -int SceneShading::load() -{ - Model model; - - if(!model.load_3ds(GLMARK_DATA_PATH"/models/cat.3ds")) - return 0; - - model.calculate_normals(); - model.convert_to_mesh(&mMesh); - - mMesh.build_vbo(); - - mRotationSpeed = 36.0f; - - mRunning = false; - - return 1; -} - -void SceneShading::unload() -{ - mMesh.reset(); -} - -void SceneShading::setup() -{ - Scene::setup(); - - static const LibMatrix::vec3 lightAmbient(0.1f, 0.1f, 0.1f); - static const LibMatrix::vec3 lightDiffuse(0.8f, 0.8f, 0.8f); - static const LibMatrix::vec3 lightSpecular(0.8f, 0.8f, 0.8f); - static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); - - static const LibMatrix::vec3 materialAmbient(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec3 materialDiffuse(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec3 materialSpecular(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec4 materialColor(0.0f, 0.0f, 1.0f, 1.0f); - - std::string vtx_shader_filename; - std::string frg_shader_filename; - const std::string &shading = mOptions["shading"].value; - - if (shading == "gouraud") { - vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.vert"; - frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag"; - } - else if (shading == "phong") { - vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.vert"; - frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.frag"; - } - - if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) - return; - - mProgram.start(); - - mVertexAttribLocation = mProgram.getAttribIndex("position"); - mNormalAttribLocation = mProgram.getAttribIndex("normal"); - mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); - - // Load lighting and material uniforms - mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); - mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); - mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); - mProgram.loadUniformVector(lightSpecular, "LightSourceSpecular"); - - mProgram.loadUniformVector(materialAmbient, "MaterialAmbient"); - mProgram.loadUniformVector(materialDiffuse, "MaterialDiffuse"); - mProgram.loadUniformVector(materialSpecular, "MaterialSpecular"); - mProgram.loadUniformVector(materialColor, "MaterialColor"); - - // Calculate and load the half vector - LibMatrix::vec3 halfVector(lightPosition[0], lightPosition[1], lightPosition[2]); - halfVector.normalize(); - halfVector += LibMatrix::vec3(0.0, 0.0, 1.0); - halfVector.normalize(); - mProgram.loadUniformVector(halfVector, "LightSourceHalfVector"); - - mCurrentFrame = 0; - mRotation = 0.0f; - mRunning = true; - mStartTime = SDL_GetTicks() / 1000.0; - mLastUpdateTime = mStartTime; -} - -void SceneShading::teardown() -{ - mProgram.stop(); - mProgram.release(); - - Scene::teardown(); -} - -void SceneShading::update() -{ - double current_time = SDL_GetTicks() / 1000.0; - double dt = current_time - mLastUpdateTime; - double elapsed_time = current_time - mStartTime; - - mLastUpdateTime = current_time; - - if (elapsed_time >= mDuration) { - mAverageFPS = mCurrentFrame / elapsed_time; - mRunning = false; - } - - mRotation += mRotationSpeed * dt; - - mCurrentFrame++; -} - -void SceneShading::draw() -{ - // Load the ModelViewProjectionMatrix uniform in the shader - LibMatrix::Stack4 model_view; - LibMatrix::mat4 model_view_proj(mScreen.mProjection); - - model_view.translate(0.0f, 0.0f, -5.0f); - model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f); - model_view_proj *= model_view.getCurrent(); - - mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); - - // Load the NormalMatrix uniform in the shader. The NormalMatrix is the - // inverse transpose of the model view matrix. - LibMatrix::mat4 normal_matrix(model_view.getCurrent()); - normal_matrix.inverse().transpose(); - mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); - - mMesh.render_vbo(mVertexAttribLocation, - mNormalAttribLocation, - mTexcoordAttribLocation); -} - -Scene::ValidationResult -SceneShading::validate() -{ - static const double radius_3d(std::sqrt(3.0)); - - if (mRotation != 0) - return Scene::ValidationUnknown; - - Screen::Pixel ref; - - Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, - mScreen.mHeight / 2); - - const std::string &filter = mOptions["shading"].value; - - if (filter == "gouraud") - ref = Screen::Pixel(0x00, 0x00, 0xca, 0xff); - else if (filter == "phong") - ref = Screen::Pixel(0x1a, 0x1a, 0xbb, 0xff); - else - return Scene::ValidationUnknown; - - double dist = pixel_value_distance(pixel, ref); - - if (dist < radius_3d + 0.01) { - return Scene::ValidationSuccess; - } - else { - Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", - ref.to_le32(), pixel.to_le32(), dist); - return Scene::ValidationFailure; - } -} === removed file 'src/scenetexture.cpp' --- src/scenetexture.cpp 2011-06-17 13:16:16 +0000 +++ src/scenetexture.cpp 1970-01-01 00:00:00 +0000 @@ -1,212 +0,0 @@ -/* - * Copyright © 2008 Ben Smith - * Copyright © 2010-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: - * Ben Smith (original glmark benchmark) - * Alexandros Frantzis (glmark2) - */ -#include "scene.h" -#include "mat.h" -#include "stack.h" -#include "vec.h" -#include "log.h" - -#include "program.h" -#include - -SceneTexture::SceneTexture(Screen &pScreen) : - Scene(pScreen, "texture") -{ - mOptions["texture-filter"] = Scene::Option("texture-filter", "nearest", - "[nearest, linear, mipmap]"); -} - -SceneTexture::~SceneTexture() -{ -} - -int SceneTexture::load() -{ - static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert"); - static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex.frag"); - Model model; - - if(!model.load_3ds(GLMARK_DATA_PATH"/models/cube.3ds")) - return 0; - - model.calculate_normals(); - model.convert_to_mesh(&mCubeMesh); - mCubeMesh.build_vbo(); - - if (!Scene::load_shaders(mProgram, vtx_shader_filename, frg_shader_filename)) - return 0; - - mVertexAttribLocation = mProgram.getAttribIndex("position"); - mNormalAttribLocation = mProgram.getAttribIndex("normal"); - mTexcoordAttribLocation = mProgram.getAttribIndex("texcoord"); - - mRotationSpeed = LibMatrix::vec3(36.0f, 36.0f, 36.0f); - - mRunning = false; - - return 1; -} - -void SceneTexture::unload() -{ - mCubeMesh.reset(); - - mProgram.stop(); - mProgram.release(); -} - -void SceneTexture::setup() -{ - Scene::setup(); - - static const LibMatrix::vec4 lightAmbient(0.0f, 0.0f, 0.0f, 1.0f); - static const LibMatrix::vec4 lightDiffuse(0.8f, 0.8f, 0.8f, 1.0f); - static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); - static const LibMatrix::vec4 materialColor(1.0f, 1.0f, 1.0f, 1.0f); - - // Create texture according to selected filtering - GLint min_filter = GL_NONE; - GLint mag_filter = GL_NONE; - const std::string &filter = mOptions["texture-filter"].value; - - if (filter == "nearest") { - min_filter = GL_NEAREST; - mag_filter = GL_NEAREST; - } - else if (filter == "linear") { - min_filter = GL_LINEAR; - mag_filter = GL_LINEAR; - } - else if (filter == "mipmap") { - min_filter = GL_LINEAR_MIPMAP_LINEAR; - mag_filter = GL_LINEAR; - } - - Texture::load(GLMARK_DATA_PATH"/textures/crate-base.bmp", &mTexture, - min_filter, mag_filter, 0); - - mProgram.start(); - - // Load lighting and material uniforms - mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); - mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); - mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); - mProgram.loadUniformVector(materialColor, "MaterialColor"); - - mCurrentFrame = 0; - mRotation = LibMatrix::vec3(); - mRunning = true; - mStartTime = SDL_GetTicks() / 1000.0; - mLastUpdateTime = mStartTime; -} - -void SceneTexture::teardown() -{ - mProgram.stop(); - glDeleteTextures(1, &mTexture); - - Scene::teardown(); -} - -void SceneTexture::update() -{ - double current_time = SDL_GetTicks() / 1000.0; - double dt = current_time - mLastUpdateTime; - double elapsed_time = current_time - mStartTime; - - mLastUpdateTime = current_time; - - if (elapsed_time >= mDuration) { - mAverageFPS = mCurrentFrame / elapsed_time; - mRunning = false; - } - - mRotation += mRotationSpeed * dt; - - mCurrentFrame++; -} - -void SceneTexture::draw() -{ - // Load the ModelViewProjectionMatrix uniform in the shader - LibMatrix::Stack4 model_view; - LibMatrix::mat4 model_view_proj(mScreen.mProjection); - - model_view.translate(0.0f, 0.0f, -5.0f); - model_view.rotate(mRotation.x(), 1.0f, 0.0f, 0.0f); - model_view.rotate(mRotation.y(), 0.0f, 1.0f, 0.0f); - model_view.rotate(mRotation.z(), 0.0f, 0.0f, 1.0f); - model_view_proj *= model_view.getCurrent(); - - mProgram.loadUniformMatrix(model_view_proj, "ModelViewProjectionMatrix"); - - // Load the NormalMatrix uniform in the shader. The NormalMatrix is the - // inverse transpose of the model view matrix. - LibMatrix::mat4 normal_matrix(model_view.getCurrent()); - normal_matrix.inverse().transpose(); - mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, mTexture); - - mCubeMesh.render_vbo(mVertexAttribLocation, - mNormalAttribLocation, - mTexcoordAttribLocation); -} - -Scene::ValidationResult -SceneTexture::validate() -{ - static const double radius_3d(std::sqrt(3.0)); - - if (mRotation.x() != 0 || mRotation.y() != 0 || mRotation.z() != 0) - return Scene::ValidationUnknown; - - Screen::Pixel ref; - - Screen::Pixel pixel = mScreen.read_pixel(mScreen.mWidth / 2, - mScreen.mHeight / 2); - - const std::string &filter = mOptions["texture-filter"].value; - - if (filter == "nearest") - ref = Screen::Pixel(0x3a, 0x3a, 0x3b, 0xff); - else if (filter == "linear") - ref = Screen::Pixel(0x34, 0x34, 0x35, 0xff); - else if (filter == "mipmap") - ref = Screen::Pixel(0x33, 0x33, 0x35, 0xff); - else - return Scene::ValidationUnknown; - - double dist = pixel_value_distance(pixel, ref); - - if (dist < radius_3d + 0.01) { - return Scene::ValidationSuccess; - } - else { - Log::debug("Validation failed! Expected: 0x%x Actual: 0x%x Distance: %f\n", - ref.to_le32(), pixel.to_le32(), dist); - return Scene::ValidationFailure; - } -}