S60 3rd Edition SDK for Symbian OS
Example Applications Guide

HierarchyContainer.h

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

© Nokia 2006

Back to top