From patchwork Thu Jul 21 12:36:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandros Frantzis X-Patchwork-Id: 2971 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 56FD523F52 for ; Thu, 21 Jul 2011 12:43:25 +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 265F6A1822A for ; Thu, 21 Jul 2011 12:43:25 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so853237qwb.11 for ; Thu, 21 Jul 2011 05:43:25 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr209471qcb.38.1311252204905; Thu, 21 Jul 2011 05:43:24 -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 hl14cs139538qcb; Thu, 21 Jul 2011 05:43:24 -0700 (PDT) Received: by 10.216.63.17 with SMTP id z17mr714555wec.98.1311251795828; 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 j4si2371573wed.124.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-0000Ct-K9 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 6600E2EA05E for ; Thu, 21 Jul 2011 12:36:32 +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: 33 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 33: Use a shader to draw the Texture Scene. Message-Id: <20110721123632.17019.30115.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:32 -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: adf995741eec47f82e5f66e95116f072454401a7 ------------------------------------------------------------ revno: 33 committer: Alexandros Frantzis timestamp: Fri 2010-07-09 16:36:15 +0300 message: Use a shader to draw the Texture Scene. added: data/shaders/light-basic-tex.frag modified: scene.h scenetexture.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 'data/shaders/light-basic-tex.frag' --- data/shaders/light-basic-tex.frag 1970-01-01 00:00:00 +0000 +++ data/shaders/light-basic-tex.frag 2010-07-09 13:36:15 +0000 @@ -0,0 +1,11 @@ +uniform sampler2D MaterialTexture0; + +varying vec4 Color; +varying vec2 TextureCoord; + +void main(void) +{ + vec4 texel = texture2D(MaterialTexture0, TextureCoord); + gl_FragColor = texel * Color; +} + === modified file 'scene.h' --- scene.h 2010-07-09 12:11:52 +0000 +++ scene.h 2010-07-09 13:36:15 +0000 @@ -76,6 +76,8 @@ ~SceneTexture(); protected: + Shader mShader; + Mesh mCubeMesh; GLuint mTexture[3]; Vector3f mRotation; === modified file 'scenetexture.cpp' --- scenetexture.cpp 2010-07-09 12:16:42 +0000 +++ scenetexture.cpp 2010-07-09 13:36:15 +0000 @@ -1,4 +1,5 @@ #include "scene.h" +#include "matrix.h" SceneTexture::~SceneTexture() { @@ -19,6 +20,9 @@ model.calculate_normals(); model.convert_to_mesh(&mCubeMesh); mCubeMesh.build_vbo(); + + mShader.load(GLMARK_DATA_PATH"data/shaders/light-basic.vert", + GLMARK_DATA_PATH"data/shaders/light-basic-tex.frag"); mRotationSpeed = Vector3f(36.0f, 36.0f, 36.0f); @@ -46,6 +50,8 @@ void SceneTexture::unload() { + mShader.remove(); + mShader.unload(); } void SceneTexture::start() @@ -53,15 +59,18 @@ GLfloat lightAmbient[] = {0.0f, 0.0f, 0.0f, 1.0f}; 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); - - glEnable(GL_TEXTURE_2D); - + GLfloat materialColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; + + 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); + + glUniform3fv(mShader.mLocations.MaterialColor, 1, materialColor); + mCurrentFrame = 0; mRunning = true; mStartTime = SDL_GetTicks() / 1000.0; @@ -107,26 +116,27 @@ void SceneTexture::draw() { - glLoadIdentity(); - glColor3f(1.0f, 1.0f, 1.0f); - glTranslatef(0.0f, 0.0f, -4.0f); - - glRotatef(mRotation.x, 1.0f, 0.0f, 0.0f); - glRotatef(mRotation.y, 0.0f, 1.0f, 0.0f); - glRotatef(mRotation.z, 0.0f, 0.0f, 1.0f); - - switch(mCurrentPart) - { - case 0: - glBindTexture(GL_TEXTURE_2D, mTexture[0]); - mCubeMesh.render_vbo(); - break; - case 1: - glBindTexture(GL_TEXTURE_2D, mTexture[1]); - mCubeMesh.render_vbo(); - case 2: - glBindTexture(GL_TEXTURE_2D, mTexture[2]); - mCubeMesh.render_vbo(); - break; - } + // 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.x / 360.0, 1.0f, 0.0f, 0.0f); + model_view.rotate(2 * M_PI * mRotation.y / 360.0, 0.0f, 1.0f, 0.0f); + model_view.rotate(2 * M_PI * mRotation.z / 360.0, 0.0f, 0.0f, 1.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); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, mTexture[mCurrentPart]); + + mCubeMesh.render_vbo_attrib(); }