os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappopenglanimation.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappopenglanimation.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,178 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include "t_pseudoappopenglanimation.h"
1.26 +
1.27 +/** Vertex co-ordinates for a cube */
1.28 +const GLfloat KVertexArray[] = { -10.0f, 10.0f, 10.0f,
1.29 + 10.0f, 10.0f, 10.0f,
1.30 + -10.0f, -10.0f, 10.0f,
1.31 + 10.0f, -10.0f, 10.0f,
1.32 + -10.0f, 10.0f, -10.0f,
1.33 + 10.0f, 10.0f, -10.0f,
1.34 + -10.0f, -10.0f, -10.0f,
1.35 + 10.0f, -10.0f, -10.0f };
1.36 +
1.37 +/** Left, near, top co-ordinate index */
1.38 +const GLubyte LNT = 0;
1.39 +/** Right, near, top co-ordinate index */
1.40 +const GLubyte RNT = 1;
1.41 +/** Left, far, top co-ordinate index */
1.42 +const GLubyte LFT = 2;
1.43 +/** Right, far, top co-ordinate index */
1.44 +const GLubyte RFT = 3;
1.45 +/** Left, near, bottom co-ordinate index */
1.46 +const GLubyte LNB = 4;
1.47 +/** Right, near, bottom co-ordinate index */
1.48 +const GLubyte RNB = 5;
1.49 +/** Left, far, bottom co-ordinate index */
1.50 +const GLubyte LFB = 6;
1.51 +/** Right, far, bottom co-ordinate index */
1.52 +const GLubyte RFB = 7;
1.53 +/** Number of indicies per face */
1.54 +const TInt KNumFaceIndices = 6;
1.55 +
1.56 +/** Array of indicies into vertex array to define a cube */
1.57 +const GLubyte KIndexArray[] = { RNB, LNB, LFB, RNB, LFB, RFB,
1.58 + RNB, RFB, RFT, RNB, RFT, RNT,
1.59 + LNB, RNB, RNT, LNB, RNT, LNT,
1.60 + LFB, LNB, LNT, LFB, LNT, LFT,
1.61 + RFB, LFB, LFT, RFB, LFT, RFT,
1.62 + LNT, RNT, RFT, LNT, RFT, LFT };
1.63 +
1.64 +
1.65 +COpenGLAnimation* COpenGLAnimation::NewL(RWindow* aWin, const TDisplayMode& aMode, const TSize& aSurfaceSize,
1.66 + const TInt aHorizontalRate,
1.67 + const TInt aVerticalRate)
1.68 + {
1.69 + RDebug::Print(_L("Creating COpenGLAnimation class\n"));
1.70 + COpenGLAnimation* self = new (ELeave) COpenGLAnimation(aMode,aSurfaceSize,aHorizontalRate,aVerticalRate);
1.71 + CleanupStack::PushL(self);
1.72 + self->ConstructL(aWin);
1.73 + CleanupStack::Pop(); // self;
1.74 + return self;
1.75 + }
1.76 +
1.77 +COpenGLAnimation::COpenGLAnimation(const TDisplayMode& aMode, const TSize& aSurfaceSize, const TInt aHorizontalRate, const TInt aVerticalRate)
1.78 +: CEglBase(aMode,aSurfaceSize,aHorizontalRate,aVerticalRate)
1.79 + {
1.80 + }
1.81 +
1.82 +void COpenGLAnimation::ConstructL(RWindow* aWin)
1.83 + {
1.84 + BaseConstructL(aWin);
1.85 +
1.86 + // eglBindAPI
1.87 + TInt ret = eglBindAPI(EGL_OPENGL_ES_API);
1.88 + TestL(ret, _L("eglBindAPI failed"));
1.89 +
1.90 + __ASSERT_DEBUG(iUseConfig>0, User::Panic(_L("COpenGLAnimation"), KErrArgument));
1.91 +
1.92 + // eglCreateContext
1.93 + iContext = eglCreateContext(iDisplay, iUseConfig, EGL_NO_CONTEXT, NULL);
1.94 + TestL(iContext!=EGL_NO_CONTEXT, _L("eglCreateContext failed"));
1.95 +
1.96 + // Make surface and context current on the display object
1.97 + ret = eglMakeCurrent(iDisplay, iSurface, iSurface, iContext);
1.98 + TestL(ret, _L("eglMakeCurrent failed"));
1.99 +
1.100 + CheckGlErrorL(_L("GL_Problems creating second surface"));
1.101 + }
1.102 +
1.103 +COpenGLAnimation::~COpenGLAnimation()
1.104 + {
1.105 + }
1.106 +
1.107 +/** Draws a cube using OpenGLES commands */
1.108 +void COpenGLAnimation::DrawToEglL()
1.109 + {
1.110 + // Increment rotation variable
1.111 + iRotAngle += 15;
1.112 +
1.113 + // Set half-transparent drawing value
1.114 + const GLfloat KAlphaValue = 0.5f;
1.115 +
1.116 + // Remove hidden faces
1.117 + glEnable(GL_CULL_FACE);
1.118 + glCullFace(GL_FRONT);
1.119 +
1.120 + // Use a flat shading model
1.121 + glShadeModel(GL_FLAT);
1.122 +
1.123 + // Set the projection parameters
1.124 + glMatrixMode(GL_PROJECTION);
1.125 + glLoadIdentity();
1.126 + glFrustumf(-0.154f, 0.154f, -0.0577f, 0.0577f, 0.1f, 100.0f);
1.127 +
1.128 + // Set the cube position
1.129 + glMatrixMode(GL_MODELVIEW);
1.130 + glLoadIdentity();
1.131 + // Move position away from viewpoitn
1.132 + glTranslatef(iX+=iHorizontalRate, 0.0f, -50.0f);
1.133 +
1.134 + // Rotate 45 degrees about the z-axis
1.135 + glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
1.136 + // Rotate iX degrees about the y- and z-axes
1.137 + glRotatef(iRotAngle, 0.0f, 1.0f, 1.0f);
1.138 +
1.139 + // Clear the buffer
1.140 + glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1.141 + glClear(GL_COLOR_BUFFER_BIT);
1.142 +
1.143 + // Enable vertex processing
1.144 + glEnableClientState(GL_VERTEX_ARRAY);
1.145 +
1.146 + // Set the vertex array to use
1.147 + glVertexPointer(3, GL_FLOAT, 0, KVertexArray);
1.148 +
1.149 + const GLubyte* faceIndex = KIndexArray;
1.150 +
1.151 + // Process cube faces
1.152 + for (TInt face = 1; face <= 6; face++)
1.153 + {
1.154 + const GLfloat red = (face < 2 || face > 4) ? 1.0f : 0;
1.155 + const GLfloat green = (face > 0 && face < 4) ? 1.0f : 0;
1.156 + const GLfloat blue = (face > 2) ? 1.0f : 0;
1.157 + // Set colour to draw in
1.158 + glColor4f(red, green, blue, KAlphaValue);
1.159 + // Draw the vertices that make up each face as two triangles
1.160 + glDrawElements(GL_TRIANGLES, KNumFaceIndices, GL_UNSIGNED_BYTE, faceIndex);
1.161 + faceIndex += KNumFaceIndices;
1.162 + }
1.163 +
1.164 + // Flush colour buffer to the window surface
1.165 + eglSwapBuffers(iDisplay, iSurface);
1.166 + }
1.167 +
1.168 +void COpenGLAnimation::DrawL(CTestSurfaceRasterizer* /*aSurfaceRasterizer*/, SurfaceDetails& /*aSurfDetails*/)
1.169 + {
1.170 + DrawToEglL();
1.171 + }
1.172 +
1.173 +void COpenGLAnimation::CheckGlErrorL(const TDesC& aMessage)
1.174 + {
1.175 + GLenum err=glGetError();
1.176 + if ( err != GL_NO_ERROR )
1.177 + {
1.178 + RDebug::Print(_L("Error:0x%x - %S"),err,&aMessage);
1.179 + User::Leave(KErrUnknown);
1.180 + }
1.181 + }