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: 2983 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 7ECA223F4D for ; Thu, 21 Jul 2011 12:43:46 +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 4E8B4A18287 for ; Thu, 21 Jul 2011 12:43:46 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so845420qyk.11 for ; Thu, 21 Jul 2011 05:43:46 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr209785qcb.38.1311252226101; Thu, 21 Jul 2011 05:43:46 -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 hl14cs139555qcb; Thu, 21 Jul 2011 05:43:45 -0700 (PDT) Received: by 10.216.120.130 with SMTP id p2mr271194weh.2.1311251794715; Thu, 21 Jul 2011 05:36:34 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id x56si389388wec.87.2011.07.21.05.36.34; Thu, 21 Jul 2011 05:36:34 -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-0000DF-3L 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 882AB2EA027 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: 22 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 22: Change basic shader to use user-defined vertex attributes exclusively. Message-Id: <20110721123631.17019.41284.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: 6846763b5ceaaec57f00e9449e0ffaebcb0bdf2f ------------------------------------------------------------ revno: 22 committer: Alexandros Frantzis timestamp: Thu 2010-07-08 18:17:11 +0300 message: Change basic shader to use user-defined vertex attributes exclusively. Fix Shading Scene so that it works with the new the shader. modified: data/shaders/light-basic.frag data/shaders/light-basic.vert sceneshading.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 'data/shaders/light-basic.frag' --- data/shaders/light-basic.frag 2010-07-07 10:32:18 +0000 +++ data/shaders/light-basic.frag 2010-07-08 15:17:11 +0000 @@ -18,7 +18,7 @@ varying float Diffuse; void main(void) -{ -//Multiply the light Diffuse intensity by the color of the cube - gl_FragColor = Diffuse * vec4(0,0,1,1); +{ + // Multiply the light Diffuse intensity by the color of the + gl_FragColor = Diffuse * vec4(0.0, 0.0, 1.0, 1.0); } === modified file 'data/shaders/light-basic.vert' --- data/shaders/light-basic.vert 2010-07-08 09:08:36 +0000 +++ data/shaders/light-basic.vert 2010-07-08 15:17:11 +0000 @@ -58,15 +58,25 @@ // lesson, but it even cleared up some stuff for me without even // thinking about it. GO MATHS :) +attribute vec3 position; +attribute vec3 normal; +attribute vec2 texture; + +uniform mat4 ModelViewProjectionMatrix; +uniform mat4 NormalMatrix; +uniform vec4 LightSourcePosition; +uniform vec3 LightSourceDiffuse; +uniform vec3 MaterialDiffuse; + varying float Diffuse; void main(void) -{ - vec3 Normal = normalize(gl_NormalMatrix * gl_Normal); - - vec3 Light = normalize(gl_LightSource[0].position.xyz); - - Diffuse = max(dot(Normal, Light),0.0); - - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; +{ + vec3 N = normalize(vec3(NormalMatrix * vec4(normal, 1.0))); + + vec3 L = normalize(LightSourcePosition.xyz); + + Diffuse = max(dot(N, L), 0.0); + + gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0); } === modified file 'sceneshading.cpp' --- sceneshading.cpp 2010-07-08 13:34:28 +0000 +++ sceneshading.cpp 2010-07-08 15:17:11 +0000 @@ -1,4 +1,5 @@ #include "scene.h" +#include "matrix.h" SceneShading::~SceneShading() { @@ -79,8 +80,18 @@ glDisable(GL_TEXTURE_2D); mShader[1].use(); break; - }; - + } + + if (mCurrentPart == 0) { + glUniform4fv(mShader[mCurrentPart].mLocations.LightSourcePosition, 1, + lightPosition); + glUniform3fv(mShader[mCurrentPart].mLocations.LightSourceDiffuse, 1, + lightDiffuse); + glUniform3fv(mShader[mCurrentPart].mLocations.MaterialDiffuse, 1, + mat_diffuse); + } + + mCurrentFrame = 0; mRunning = true; mStartTime = SDL_GetTicks() / 1000.0; @@ -128,5 +139,27 @@ glColor3f(0.0f, 1.0f, 1.0f); - mMesh.render_vbo(); + if (mCurrentPart == 0) { + // 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, -5.0f); + model_view.rotate(2 * M_PI * mRotation / 360.0, 0.0f, 1.0f, 0.0f); + model_view_proj *= model_view; + + glUniformMatrix4fv(mShader[mCurrentPart].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[mCurrentPart].mLocations.NormalMatrix, 1, + GL_FALSE, model_view.m); + + mMesh.render_vbo_attrib(); + } + else { + mMesh.render_vbo(); + } }