Nokia N97 SDK
Example Applications Guide

SimpleCubePixmapContainer.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : SimpleCubePixmapContainer.h
00004  *  Part of     : OpenGLEx / SimpleCubePixmap
00005  *
00006  *  Copyright (c) 2004-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 SIMPLECUBEPIXMAPCONTAINER_H
00014 #define SIMPLECUBEPIXMAPCONTAINER_H
00015 
00016 // INCLUDES
00017 #include <coecntrl.h>
00018 #include <GLES/egl.h>
00019 #include <akndef.h>
00020 #include <aknappui.h> 
00021 #include "SimpleCubePixmap.h"
00022 
00023 // CLASS DECLARATION
00024 
00025 /**
00026  * Container control class that handles the OpenGL ES initialization and deinitializations.
00027  * Also uses the CSimpleCubePixmap class to do the actual OpenGL ES rendering.
00028  */
00029 class CSimpleCubePixmapContainer : public CCoeControl, MCoeControlObserver
00030     {
00031     public: // Constructors and destructor
00032 
00033         /**
00034          * EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
00035          * @param aRect Screen rectangle for container.
00036          */
00037         void ConstructL(const TRect& aRect, CAknAppUi* aAppUi);
00038 
00039         /**
00040          * Destructor. Destroys the CPeriodic, CSimpleCubePixmap and uninitializes OpenGL ES.
00041          */
00042         virtual ~CSimpleCubePixmapContainer();
00043 
00044     public: // New functions
00045 
00046         /**
00047          * Callback function for the CPeriodic. Calculates the current frame, keeps the background
00048          * light from turning off and orders the CSimpleCubePixmap to do the rendering for each frame.
00049          *@param aInstance Pointer to this instance of CSimpleCubePixmapContainer.
00050          */
00051         static TInt DrawCallBack( TAny* aInstance );
00052 
00053     private: // Functions from base classes
00054 
00055         /**
00056          * Method from CoeControl that gets called when the display size changes.
00057          * If OpenGL has been initialized, notifies the renderer class that the screen
00058          * size has changed.
00059          */
00060         void SizeChanged();
00061 
00062         /**
00063          * Handles a change to the control's resources. This method
00064          * reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of
00065          * screen size change) by calling the SetExtentToWholeScreen() again so that
00066          * this control fills the new screen size. This will then trigger a call to the
00067          * SizeChanged() method.
00068          * @param aType Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.
00069          */
00070         void HandleResourceChange(TInt aType);
00071 
00072         /**
00073          * Method from CoeControl. Does nothing in this implementation.
00074          */
00075         TInt CountComponentControls() const;
00076 
00077         /**
00078          * Method from CCoeControl. Does nothing in this implementation.
00079          */
00080         CCoeControl* ComponentControl(TInt aIndex) const;
00081 
00082         /**
00083          * Method from CCoeControl. Does nothing in this implementation.
00084          * All rendering is done in the DrawCallBack() method.
00085          */
00086         void Draw(const TRect& aRect) const;
00087 
00088         /**
00089          * Method from MCoeControlObserver that handles an event from the observed control.
00090          * Does nothing in this implementation.
00091                  * @param aControl   Control changing its state.
00092                  * @param aEventType Type of the control event.
00093          */
00094         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
00095 
00096     private: //data
00097 
00098         /** Display where the OpenGL ES window surface resides. */
00099         EGLDisplay  iEglDisplay;
00100 
00101         /** Describes the format, type and size of the color buffers and ancillary buffers for EGLSurface. */
00102         EGLConfig iConfig;
00103 
00104         /** The bitmap where the framebuffer is drawn. */
00105         CWsBitmap*  iPixmap;
00106 
00107         /** Pixmap surface (that uses the iPixmap) that is the target of OpenGL ES graphics rendering. */
00108         EGLSurface  iEglSurface;
00109 
00110         /** OpenGL ES rendering context. */
00111         EGLContext  iEglContext;
00112 
00113         /** Active object that is the timing source for the animation. */
00114         CPeriodic*  iPeriodic;
00115 
00116         /**
00117          * Flag that indicates if OpenGL ES has been initialized or not.
00118          * Used to check if SizeChanged() can react to incoming notifications.
00119          */
00120         TBool iOpenGlInitialized;
00121 
00122 /** Application UI class for querying the client rectangle size. */ 
00123         CAknAppUi* iAppUi;
00124 
00125     public:  //data
00126 
00127         /** Frame counter variable, used in the animation. */
00128         TInt iFrame;
00129 
00130         /** Used in DrawCallBack() method to do the actual OpenGL ES rendering.  */
00131         CSimpleCubePixmap* iSimpleCubePixmap;
00132     };
00133 
00134 #endif
00135 
00136 // End of File

© Nokia 2009

Back to top