From patchwork Tue Oct 18 14:19:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 4731 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 03C3023E51 for ; Tue, 18 Oct 2011 14:19:13 +0000 (UTC) Received: from mail-gx0-f180.google.com (mail-gx0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id B00F1A18676 for ; Tue, 18 Oct 2011 14:19:12 +0000 (UTC) Received: by ggnv2 with SMTP id v2so888121ggn.11 for ; Tue, 18 Oct 2011 07:19:12 -0700 (PDT) Received: by 10.223.17.3 with SMTP id q3mr4291062faa.28.1318947551895; Tue, 18 Oct 2011 07:19:11 -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.152.1.71 with SMTP id 7cs47063lak; Tue, 18 Oct 2011 07:19:11 -0700 (PDT) Received: by 10.227.11.149 with SMTP id t21mr950794wbt.39.1318947550218; Tue, 18 Oct 2011 07:19:10 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id em9si1637845wbb.3.2011.10.18.07.19.09 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Oct 2011 07:19:10 -0700 (PDT) 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 1RGAVZ-00045O-Eu for ; Tue, 18 Oct 2011 14:19:09 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 63CC7E0042 for ; Tue, 18 Oct 2011 14:19:09 +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: 157 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 157: SceneShading: update to reflect the recent changes to SceneBuild. Enables the Message-Id: <20111018141909.28464.80609.launchpad@ackee.canonical.com> Date: Tue, 18 Oct 2011 14:19:09 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14157"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: bd01e1c9125321e3a23cefbade915f6794d9e5ae ------------------------------------------------------------ revno: 157 author: Jesse Barker committer: Alexandros Frantzis branch nick: shading-models timestamp: Mon 2011-10-17 15:56:15 -0700 message: SceneShading: update to reflect the recent changes to SceneBuild. Enables the selection of additional models, including the optional large models. modified: src/scene-shading.cpp src/scene.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/scene-shading.cpp' --- src/scene-shading.cpp 2011-10-07 18:35:47 +0000 +++ src/scene-shading.cpp 2011-10-17 22:56:15 +0000 @@ -31,6 +31,7 @@ #include #include +using LibMatrix::vec3; using std::string; using std::endl; @@ -53,12 +54,31 @@ } SceneShading::SceneShading(Canvas &pCanvas) : - Scene(pCanvas, "shading") + Scene(pCanvas, "shading"), + mOrientModel(false) { + const ModelMap& modelMap = Model::find_models(); + std::string optionDesc("Which model to use ["); + for (ModelMap::const_iterator modelIt = modelMap.begin(); + modelIt != modelMap.end(); + modelIt++) + { + static bool doSeparator(false); + if (doSeparator) + { + optionDesc += ", "; + } + const std::string& curName = modelIt->first; + optionDesc += curName; + doSeparator = true; + } + optionDesc += "]"; mOptions["shading"] = Scene::Option("shading", "gouraud", "[gouraud, blinn-phong-inf, phong]"); mOptions["num-lights"] = Scene::Option("num-lights", "1", "The number of lights applied to the scene (phong only)"); + mOptions["model"] = Scene::Option("model", "cat", + optionDesc); } SceneShading::~SceneShading() @@ -67,23 +87,6 @@ int SceneShading::load() { - Model::find_models(); - Model model; - - if(!model.load("cat")) - return 0; - - model.calculate_normals(); - - /* Tell the converter that we only care about position and normal attributes */ - std::vector > attribs; - attribs.push_back(std::pair(Model::AttribTypePosition, 3)); - attribs.push_back(std::pair(Model::AttribTypeNormal, 3)); - - model.convert_to_mesh(mMesh, attribs); - - mMesh.build_vbo(); - mRotationSpeed = 36.0f; mRunning = false; @@ -193,6 +196,61 @@ return; } + Model model; + const std::string& whichModel(mOptions["model"].value); + bool modelLoaded = model.load(whichModel); + + if(!modelLoaded) + return; + + // Now that we're successfully loaded, there are a few quirks about + // some of the known models that we need to account for. The draw + // logic for the scene wants to rotate the model around the Y axis. + // Most of our models are described this way. Some need adjustment + // (an additional rotation that gets the model into the correct + // orientation). + // + // Here's a summary: + // + // Angel rotates around the Y axis + // Armadillo rotates around the Y axis + // Buddha rotates around the X axis + // Bunny rotates around the Y axis + // Dragon rotates around the X axis + // Horse rotates around the Y axis + if (whichModel == "buddha" || whichModel == "dragon") + { + mOrientModel = true; + mOrientationAngle = -90.0; + mOrientationVec = vec3(1.0, 0.0, 0.0); + } + + model.calculate_normals(); + + /* Tell the converter that we only care about position and normal attributes */ + std::vector > attribs; + attribs.push_back(std::pair(Model::AttribTypePosition, 3)); + attribs.push_back(std::pair(Model::AttribTypeNormal, 3)); + + model.convert_to_mesh(mMesh, attribs); + + mMesh.build_vbo(); + + /* Calculate a projection matrix that is a good fit for the model */ + vec3 maxVec = model.maxVec(); + vec3 minVec = model.minVec(); + vec3 diffVec = maxVec - minVec; + mCenterVec = maxVec + minVec; + mCenterVec /= 2.0; + float diameter = diffVec.length(); + mRadius = diameter / 2; + float fovy = 2.0 * atanf(mRadius / (2.0 + mRadius)); + fovy /= M_PI; + fovy *= 180.0; + float aspect(static_cast(mCanvas.width())/static_cast(mCanvas.height())); + mPerspective.setIdentity(); + mPerspective *= LibMatrix::Mat4::perspective(fovy, aspect, 2.0, 2.0 + diameter); + mProgram.start(); std::vector attrib_locations; @@ -237,10 +295,13 @@ { // Load the ModelViewProjectionMatrix uniform in the shader LibMatrix::Stack4 model_view; - LibMatrix::mat4 model_view_proj(mCanvas.projection()); - - model_view.translate(0.0f, 0.0f, -5.0f); + model_view.translate(-mCenterVec.x(), -mCenterVec.y(), -(mCenterVec.z() + 2.0 + mRadius)); model_view.rotate(mRotation, 0.0f, 1.0f, 0.0f); + if (mOrientModel) + { + model_view.rotate(mOrientationAngle, mOrientationVec.x(), mOrientationVec.y(), mOrientationVec.z()); + } + LibMatrix::mat4 model_view_proj(mPerspective); model_view_proj *= model_view.getCurrent(); mProgram["ModelViewProjectionMatrix"] = model_view_proj; === modified file 'src/scene.h' --- src/scene.h 2011-10-11 09:46:59 +0000 +++ src/scene.h 2011-10-17 22:56:15 +0000 @@ -206,7 +206,12 @@ protected: Program mProgram; - + float mRadius; + bool mOrientModel; + float mOrientationAngle; + LibMatrix::vec3 mOrientationVec; + LibMatrix::vec3 mCenterVec; + LibMatrix::mat4 mPerspective; Mesh mMesh; float mRotation; float mRotationSpeed;