diff -r 000000000000 -r 5d03bc08d59c graphicsdeviceinterface/directgdi/test/tdirectgdieglcontent_cube.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graphicsdeviceinterface/directgdi/test/tdirectgdieglcontent_cube.cpp Tue Feb 02 01:47:50 2010 +0200 @@ -0,0 +1,424 @@ +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#include "tdirectgdieglcontent_cube.h" +#include "tdisplaymode_mapping.h" +#include +#include +#include + +// CONSTANTS +/** Camera parameters */ +const TInt KCameraDistance = 100; +const TReal32 KFrustumLeft = -1.f; //left vertical clipping plane +const TReal32 KFrustumRight = 1.f; //right vertical clipping plane +const TReal32 KFrustumBottom = -1.f;//bottom horizontal clipping plane +const TReal32 KFrustumTop = 1.f; //top horizontal clipping plane +const TReal32 KFrustumNear = 3.f; //near depth clipping plane +const TReal32 KFrustumFar = 1000.f; //far depth clipping plane + +/* Define vertice coordinates for the cube + Duplication of vertices needed for texturing every surface of the cube */ +static const GLbyte KVertices[24 * 3] = + { + /* top */ + -1, 1, 1, + 1, 1, 1, + 1, -1, 1, + -1, -1, 1, + + /* front */ + 1, 1, 1, + 1, 1, -1, + 1, -1, -1, + 1, -1, 1, + + /* right */ + -1, 1, 1, + -1, 1, -1, + 1, 1, -1, + 1, 1, 1, + + /* left */ + 1, -1, 1, + 1, -1, -1, + -1, -1, -1, + -1, -1, 1, + + /* back */ + -1, -1, 1, + -1, -1, -1, + -1, 1, -1, + -1, 1, 1, + + /* bottom */ + -1, 1, -1, + 1, 1, -1, + 1, -1, -1, + -1, -1, -1 + }; + +/** +Indices for drawing the triangles. +The color of the triangle is determined by +the color of the last vertex of the triangle. +*/ +static const GLubyte KTriangles[12 * 3] = + { + /* top */ + 1,0,3, + 1,3,2, + + /* front */ + 5,4,7, + 5,7,6, + + /* right */ + 9,8,11, + 9,11,10, + + /* left */ + 13,12,15, + 13,15,14, + + /* back */ + 17,16,19, + 17,19,18, + + /* bottom */ + 21,22,23, + 21,23,20 + }; + +/* Macro for changing the input texture coordinate values from + GLubyte [0,255] to GLbyte [-128,127]. See more info below. */ +#define tex(u,v) (GLbyte)( (u) - 128 ) , (GLbyte)( (v) - 128 ) + +/* Input texture coordinates for each of the object vertices. + The coordinates are given in GLbyte [-128,127] format. + Since the texture picture coordinates are between values + [0,255] for both width and height, we have defined a macro + to change the input coordinates into a appropriate form. + It is easier to think the texture coordinates as corresponding + image pixel coordinates. This alone is not enough because + if texture coordinates are not given between values [0,1], + texture wrapping will occur. Therefore we need to + scale the texture coordinates with appropriate texture matrix, + which is defined in AppInit(). */ +static const GLbyte KTexCoords[24 * 2] = + { + /* top */ + tex(0,0), + tex(255,0), + tex(255,255), + tex(0,255), + + /* front */ + tex(0,255), + tex(127,255), + tex(127,127), + tex(0,127), + + /* right */ + tex(127,255), + tex(255,255), + tex(255,127), + tex(127,127), + + /* left */ + tex(0,127), + tex(127,127), + tex(127,0), + tex(0,0), + + /* back */ + tex(127,127), + tex(255,127), + tex(255,0), + tex(127,0), + + /* bottom */ + tex(255,255), + tex(255,0), + tex(0,0), + tex(0,255) + }; + +/** +Static constructor. +@param aPixelFormat Pixel format of pixmap buffer. +@param aSize Size of pixmap buffer. +*/ +CGLCube* CGLCube::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize) + { + CGLCube* self = NewLC(aPixelFormat, aSize); + CleanupStack::Pop(self); + return self; + } + +CGLCube* CGLCube::NewLC(TUidPixelFormat aPixelFormat, const TSize& aSize) + { + CGLCube* self = new(ELeave) CGLCube(); + CleanupStack::PushL(self); + self->ConstructL(aPixelFormat, aSize); + return self; + } + +/** +1st phase constructor +*/ +CGLCube::CGLCube() + { + } + +/** +2nd phase constructor +@param aPixelFormat Pixel format of pixmap buffer. +@param aSize Size of pixmap buffer. +*/ +void CGLCube::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize) + { + // init graphic environment + User::LeaveIfError(SgDriver::Open()); + FbsStartup(); + User::LeaveIfError(RFbsSession::Connect()); + InitEglL(aPixelFormat, aSize); + } + +/** +Destructor +*/ +CGLCube::~CGLCube() + { + // deinit gfx environment + DeInitEgl(); + SgDriver::Close(); + RFbsSession::Disconnect(); + } + +/** +Egl environment initialisation for pixmap surface rendering. +@param aPixelFormat Pixel format of pixmap buffer. +@param aSize Size of pixmap buffer. +*/ +void CGLCube::InitEglL(TUidPixelFormat aPixelFormat, const TSize& aSize) + { + // Get the display for drawing graphics + iEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if(iEglDisplay == NULL) + { + _LIT(KGetDisplayFailed, "eglGetDisplay failed"); + User::Panic(KGetDisplayFailed, 0); + } + + // Initialize display + if(eglInitialize(iEglDisplay, NULL, NULL) == EGL_FALSE) + { + _LIT(KInitializeFailed, "eglInitialize failed"); + User::Panic(KInitializeFailed, 0); + } + + // switch api to GLES + eglBindAPI(EGL_OPENGL_ES_API); + + iImageInfo.iSizeInPixels = aSize; + iImageInfo.iPixelFormat = aPixelFormat; + iImageInfo.iCpuAccess = ESgCpuAccessNone; + iImageInfo.iUsage = ESgUsageOpenGlesTarget|ESgUsageDirectGdiSource; + iImageInfo.iShareable = ETrue; + iImageInfo.iScreenId = KSgScreenIdMain; + + for(TInt i=0; i