From patchwork Thu Jul 21 12:36:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandros Frantzis X-Patchwork-Id: 2966 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 B059723F4D for ; Thu, 21 Jul 2011 12:43:19 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id 79168A18398 for ; Thu, 21 Jul 2011 12:43:19 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so845420qyk.11 for ; Thu, 21 Jul 2011 05:43:19 -0700 (PDT) Received: by 10.229.68.200 with SMTP id w8mr191319qci.114.1311252199254; Thu, 21 Jul 2011 05:43:19 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs139532qcb; Thu, 21 Jul 2011 05:43:19 -0700 (PDT) Received: by 10.227.2.144 with SMTP id 16mr210351wbj.9.1311251795639; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id p2si2366518wbh.145.2011.07.21.05.36.35; Thu, 21 Jul 2011 05:36:35 -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 1QjsUT-0000Cq-Dh for ; Thu, 21 Jul 2011 12:36:33 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id D1F462E8951 for ; Thu, 21 Jul 2011 12:36:31 +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: 27 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 27: Change Build Scene to use a shader for rendering. Message-Id: <20110721123631.17019.51467.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:31 -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: bdef319a6865696f22ae857a6c477f7f59571a41 ------------------------------------------------------------ revno: 27 committer: Alexandros Frantzis timestamp: Fri 2010-07-09 13:16:27 +0300 message: Change Build Scene to use a shader for rendering. modified: scene.h scenebuild.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 === modified file 'scene.h' --- scene.h 2010-07-08 13:04:49 +0000 +++ scene.h 2010-07-09 10:16:27 +0000 @@ -46,6 +46,10 @@ void update(); void draw(); + ~SceneBuild(); + + Shader mShader; + Mesh mMesh; float mRotation; float mRotationSpeed; === modified file 'scenebuild.cpp' --- scenebuild.cpp 2010-07-08 13:34:28 +0000 +++ scenebuild.cpp 2010-07-09 10:16:27 +0000 @@ -1,5 +1,9 @@ #include "scene.h" +SceneBuild::~SceneBuild() +{ +} + int SceneBuild::load() { Model model; @@ -11,6 +15,9 @@ model.convert_to_mesh(&mMesh); mMesh.build_vbo(); + + mShader.load(GLMARK_DATA_PATH"data/shaders/light-basic.vert", + GLMARK_DATA_PATH"data/shaders/light-basic.frag"); mRotationSpeed = 36.0f; mRotation = 0.0; @@ -43,11 +50,13 @@ GLfloat lightDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f}; GLfloat lightPosition[] = {20.0f, 20.0f, 10.0f, 1.0f}; - glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - glEnable(GL_LIGHT0); - glEnable(GL_LIGHTING); + mShader.use(); + + // Load lighting and material uniforms + glUniform4fv(mShader.mLocations.LightSourcePosition, 1, lightPosition); + + glUniform3fv(mShader.mLocations.LightSourceAmbient, 1, lightAmbient); + glUniform3fv(mShader.mLocations.LightSourceDiffuse, 1, lightDiffuse); mCurrentFrame = 0; mRunning = true; @@ -91,17 +100,30 @@ void SceneBuild::draw() { - glTranslatef(0.0f, 0.0f,-2.5f); - glRotated(mRotation, 0.0f, 1.0, 0.0f); - - glColor3f(0.0f, 1.0f, 1.0f); + // Load the ModelViewProjectionMatrix uniform in the shader + Matrix4f model_view(1.0f, 1.0f, 1.0f); + Matrix4f model_view_proj(mScreen.mProjection); + + model_view.translate(0.0f, 0.0f, -2.5f); + model_view.rotate(2 * M_PI * mRotation / 360.0, 0.0f, 1.0f, 0.0f); + model_view_proj *= model_view; + + glUniformMatrix4fv(mShader.mLocations.ModelViewProjectionMatrix, 1, + GL_FALSE, model_view_proj.m); + + // Load the NormalMatrix uniform in the shader. The NormalMatrix is the + // inverse transpose of the model view matrix. + model_view.invert().transpose(); + glUniformMatrix4fv(mShader.mLocations.NormalMatrix, 1, + GL_FALSE, model_view.m); + switch(mCurrentPart) { case 0: - mMesh.render_array(); + mMesh.render_array_attrib(); break; case 1: - mMesh.render_vbo(); + mMesh.render_vbo_attrib(); break; } }