Nokia N97 SDK
Example Applications Guide

Mipmapping.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : Mipmapping.h
00004  *  Part of     : OpenGLEx / Mipmapping
00005  *
00006  *  Copyright (c) 2005-2006 Nokia Corporation.
00007  *  This material, including documentation and any related
00008  *  computer programs, is protected by copyright controlled by
00009  *  Nokia Corporation.
00010  * ==============================================================================
00011  */
00012 
00013 #ifndef MIPMAPPING_H
00014 #define MIPMAPPING_H
00015 
00016 //  INCLUDES
00017 
00018 #include <e32base.h> // for CBase definition
00019 #include <GLES\gl.h>      // OpenGL ES header file
00020 #include "Textureutils.h"
00021 #include "Mathutils.h"
00022 #include "Utils3d.h"
00023 
00024 // MACROS
00025 
00026 /** Split the screen horizontally to highlight the benefit of mipmapping */
00027 //#define MIPMAPPING_SPLIT_SCREEN
00028 
00029 // FORWARD DECLARATIONS
00030 
00031 /**
00032  * Class that does the actual OpenGL ES rendering.
00033  * Subclass of CFiniteStateMachine because the application
00034  * needs to handle loading textures and running states.
00035  */
00036 class CMipmapping
00037         : public CFiniteStateMachine, public MTextureLoadingListener
00038         {
00039         public: // Constructors and destructor
00040 
00041         /**
00042          * Factory method for creating a new CMipmapping object.
00043                  * Calls the hidden constructors.
00044          */
00045                 static CMipmapping* NewL( TUint aWidth, TUint aHeight, TUint aSegments = 16, TUint aSlices = 7 );
00046 
00047         /**
00048          * Destructor. Does nothing.
00049          */
00050                 virtual ~CMipmapping();
00051 
00052         protected: // Hidden constructors
00053 
00054         /**
00055          * Standard constructor that must never Leave.
00056          * Stores the given screen width and height.
00057          * @param aWidth Width of the screen.
00058          * @param aHeight Height of the screen.
00059          * @param aSegments Number of segments in the tunnel.
00060          * @param aSlices Number of slices in one segment of the tunnel.
00061          */
00062                 CMipmapping( TUint aWidth, TUint aHeight, TUint aSegments, TUint aSlices );
00063 
00064         /**
00065          * Second phase constructor that can call methods that may leave. Does nothing.
00066          */
00067                 void ConstructL( void );
00068 
00069 
00070         public: // New methods
00071 
00072                 enum EFilteringMode
00073                 {
00074         EMipmappedNearestNeighbourFiltering,
00075                 EMipmappedBilinearFiltering,
00076                 EMipmappedTrilinearFiltering,
00077         ENearestNeighbourFiltering,
00078                 EBilinearFiltering,
00079                 };
00080 
00081         /**
00082          * Initializes OpenGL ES, sets the vertex and color
00083          * arrays and pointers. Also selects the shading mode and
00084          * creates the CTextureManager instance and starts loading
00085          * of required textures.
00086          */
00087                 void AppInitL( void );
00088 
00089         /**
00090          * Called upon application exit. Destroys the CTextureManager
00091          * instance that was created in AppInitL() method.
00092          */
00093                 void AppExit( void );
00094 
00095         /**
00096          * Renders one frame.
00097          * @param aFrame Number of the frame to be rendered.
00098                  * @param aTimeSecs Seconds elapsed since the application started running.
00099                  * @param aDeltaTimeSecs Seconds elapsed since last call to AppCycle().
00100          */
00101                 void AppCycle( TInt aFrame, TReal aTimeSecs, TReal aDeltaTimeSecs );
00102 
00103         /**
00104          * Called when the finite state machine enters a new state.
00105          * Does nothing in this implementation.
00106          * @param aState State that is about to be entered.
00107          */
00108                 void OnEnterStateL( TInt aState);
00109 
00110         /**
00111          * Called when texture manager starts loading the textures.
00112          * Sets the current state to "loading textures".
00113          */
00114                 void OnStartLoadingTexturesL();
00115 
00116         /**
00117          * Called when texture manager has completed texture loading.
00118          * Changes the current state to "running".
00119          */
00120                 void OnEndLoadingTexturesL();
00121 
00122         /**
00123          * Notifies that the screen size has dynamically changed during execution of
00124          * this program. Resets the viewport to this new size and sets this size
00125          * to the CTextureManager.
00126          * @param aWidth New width of the screen.
00127          * @param aHeight New height of the screen.
00128          */
00129         void SetScreenSize( TUint aWidth, TUint aHeight );
00130 
00131         /**
00132          *  Set texture filtering mode.
00133          */
00134         void SetFilteringMode( EFilteringMode aMode );
00135 
00136         public: // Data
00137         /**
00138          * Application states:
00139          * ELoadingTextures - indicates that the app. is loading textures.
00140          * ERunning - indicates that the app. is running.
00141          */
00142                 enum
00143                 {
00144                 ELoadingTextures,
00145                 ERunning
00146                 };
00147 
00148     private: // Methods
00149         /**
00150          *  Update the tunnel vertices based on the current time.
00151          *  @param aTime Time parameter.
00152          */
00153         void UpdateTunnel( TReal aTime );
00154 
00155         /**
00156          *  The tunnel function calculates the coordinates and radius of the tunnel at a given point
00157          *  aTime with the animation phase aPhase.
00158          *  @param aTime Time parameter.
00159          *  @param aPhase Phase parameter. This controls the animation of the tunnel.
00160          *  @param aPos Coordinates of the tunnel (output).
00161          *  @param aRadius Radius of the tunnel (output).
00162          */
00163         void TunnelFunction( TReal aTime, TReal aPhase, TReal aPos[3], TReal& aRadius) const;
00164 
00165         /**
00166          *  Converts a real number to fixed point format.
00167          *  @param aReal Number to convert.
00168          *  @returns the given number in fixed point format.
00169          */
00170         inline static GLfixed RealToFixed( TReal aReal );
00171 
00172         private: // Data
00173 
00174         /** Texture manager that is used to load the used textures. */
00175                 CTextureManager * iTextureManager;
00176         /** Width of the screen */
00177         TUint iScreenWidth;
00178         /** Height of the screen */
00179         TUint iScreenHeight;
00180         /** Number of segments in the tunnel */
00181         TUint iSegments;
00182         /** Number of slices in one segment of the tunnel  */
00183         TUint iSlices;
00184         /** Tunnel texture */
00185         TTexture iTexture;
00186         /** Vertices of the tunnel  */
00187         GLfixed * iVertices;
00188         /** Normals of the tunnel */
00189         GLfixed * iNormals;
00190         /** Texture coordinates of the tunnel  */
00191         GLfixed * iTexCoords;
00192         /** Indices for the tunnel triangle strips  */
00193         GLshort * iIndices;
00194         /** Texture filtering mode */
00195         EFilteringMode iFilteringMode;
00196         };
00197 
00198 #endif
00199 
00200 // End of File
00201 

© Nokia 2009

Back to top