S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CEnvMappingContainer Class Reference

#include <EnvMappingContainer.h>

List of all members.

Public Member Functions

void ConstructL (const TRect &aRect)
virtual ~CEnvMappingContainer ()

Static Public Member Functions

static int DrawCallBack (TAny *aInstance)

Public Attributes

CEnvMapping * iEnvMapping

Private Member Functions

void SizeChanged ()
void HandleResourceChange (TInt aType)
TInt CountComponentControls () const
CCoeControl * ComponentControl (TInt aIndex) const
void Draw (const TRect &aRect) const
void HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)

Private Attributes

EGLDisplay iEglDisplay
EGLSurface iEglSurface
EGLContext iEglContext
TInt iFrame
CPeriodic * iPeriodic
TBool iOpenGlInitialized


Detailed Description

Container control class that handles the OpenGL ES initialization and deinitializations. Also uses the CEnvMapping class to do the actual OpenGL ES rendering.

Definition at line 32 of file EnvMappingContainer.h.


Constructor & Destructor Documentation

CEnvMappingContainer::~CEnvMappingContainer (   )  [virtual]
 

Destructor. Destroys the CPeriodic, CEnvMapping and uninitializes OpenGL ES.

Definition at line 164 of file EnvMappingContainer.cpp.

References CEnvMapping::AppExit(), iEglContext, iEglDisplay, iEglSurface, iEnvMapping, and iPeriodic.

00165 {
00166     delete iPeriodic;
00167 
00168     /* AppExit call is made to release any allocations made in AppInit. 
00169      This call has to be made here before we destroy the rendering context. */
00170     if ( !(iEnvMapping == NULL) )
00171     {
00172         iEnvMapping->AppExit();
00173         delete iEnvMapping;
00174     }
00175 
00176     eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
00177     eglDestroySurface( iEglDisplay, iEglSurface ); 
00178     eglDestroyContext( iEglDisplay, iEglContext );
00179     eglTerminate( iEglDisplay );                   // Release resources associated
00180                                                    // with EGL and OpenGL ES
00181 
00182 }


Member Function Documentation

void CEnvMappingContainer::ConstructL (  const TRect &  aRect  ) 
 

EPOC default constructor. Initializes the OpenGL ES for rendering.

Parameters:
aRect Screen rectangle for container.

Definition at line 27 of file EnvMappingContainer.cpp.

References iEglDisplay, iFrame, and iOpenGlInitialized.

00028 {
00029         iOpenGlInitialized = EFalse;
00030     CreateWindowL();
00031 
00032     SetExtentToWholeScreen();                // Take the whole screen into use
00033     ActivateL();
00034     
00035     iFrame = 0;                              // Frame counter
00036 
00037     EGLConfig Config;                        // Describes the format, type and 
00038                                              // size of the color buffers and
00039                                              // ancillary buffers for EGLSurface
00040 
00041     /* Get the display for drawing graphics*/
00042     iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
00043     if( iEglDisplay == NULL )
00044     {
00045         _LIT(KEglGetDisplay,    "eglGetDisplay failed");
00046         User::Panic( KEglGetDisplay, 0 );
00047     }
00048 
00049     /* Initialize display */
00050     if( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE )
00051     {
00052         _LIT(KEglInitialize,    "eglInitialize failed");
00053         User::Panic( KEglInitialize, 0 );
00054     }
00055 
00056     EGLConfig *configList = NULL;            // Pointer for EGLConfigs
00057     EGLint numOfConfigs   = 0; 
00058     EGLint configSize     = 0;
00059 
00060     /* Get the number of possible EGLConfigs */
00061     if( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00062     {
00063         _LIT(KEglGetConfigs,    "eglGetconfigs failed");
00064         User::Panic( KEglGetConfigs, 0 );
00065     }
00066 
00067     configSize = numOfConfigs;
00068 
00069     /* Allocate memory for the configList */
00070     configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize );
00071     if( configList == NULL )
00072     {
00073         _LIT(KConfigAlloc,      "config alloc failed");
00074         User::Panic( KConfigAlloc, 0 );
00075     }
00076 
00077     /* Define properties for the wanted EGLSurface.
00078        To get the best possible performance, choose
00079        an EGLConfig with a buffersize matching
00080        the current window's display mode*/
00081     TDisplayMode DMode = Window().DisplayMode();
00082     TInt BufferSize = 0;
00083 
00084     switch(DMode)
00085     {
00086     case(EColor4K):
00087         BufferSize = 12;
00088         break;
00089     case(EColor64K):
00090         BufferSize = 16;
00091         break;
00092     case(EColor16M):
00093         BufferSize = 24;
00094         break;
00095     case(EColor16MU):
00096         BufferSize = 32;
00097         break;
00098     default:
00099         _LIT(KDModeError, "unsupported displaymode");
00100         User::Panic( KDModeError, 0 );
00101         break;
00102     }
00103 
00104     const EGLint attrib_list[] =
00105         {
00106         EGL_BUFFER_SIZE, BufferSize,   
00107         EGL_DEPTH_SIZE, 16,    
00108         EGL_NONE
00109         };
00110 
00111     /* Choose an EGLConfig that best matches to the properties in attrib_list */
00112     if( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00113     {
00114         _LIT(KEglChooseConfig,  "eglChooseConfig failed");
00115         User::Panic( KEglChooseConfig, 0 );
00116     }
00117 
00118     Config = configList[0];  // Choose the best EGLConfig. EGLConfigs 
00119                               // returned by eglChooseConfig are sorted so 
00120                               // that the best matching EGLConfig is first in
00121                               // the list.
00122     User::Free( configList ); // Free configList, not used anymore.
00123 
00124     /* Create a window where the graphics are blitted */
00125     iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL );
00126     
00127     if( iEglSurface == NULL )
00128     {
00129         _LIT(KEglCreateWindow,  "eglCreateWindow failed");
00130         User::Panic( KEglCreateWindow, 0 );
00131     }
00132     
00133     
00134     /* Create a rendering context */
00135     iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL );
00136     if( iEglContext == NULL )
00137     {
00138         _LIT(KEglCreateContext, "eglCreateContext failed");
00139         User::Panic( KEglCreateContext, 0 );
00140     }
00141     
00142     /* Make the context current. Binds context to the current rendering thread
00143        and surface.*/
00144     if( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE )
00145     {
00146         _LIT(KEglMakeCurrent,   "eglMakeCurrent failed");
00147         User::Panic( KEglMakeCurrent, 0 );
00148     }
00149     
00150     TSize size;
00151     size = this->Size();
00152     
00153     iEnvMapping = CEnvMapping::NewL( size.iWidth, size.iHeight ); 
00154     iEnvMapping->AppInitL();
00155     
00156         iOpenGlInitialized = ETrue;
00157 
00158     iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle );     // Create an active object for
00159                                                                // animating the scene  
00160     iPeriodic->Start( 100, 100, TCallBack( CEnvMappingContainer::DrawCallBack, this ) );
00161 }

int CEnvMappingContainer::DrawCallBack (  TAny *  aInstance  )  [static]
 

Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CEnvMapping to do the rendering for each frame.

Parameters:
aInstance Pointer to this instance of CEnvMappingContainer.

Definition at line 233 of file EnvMappingContainer.cpp.

References CEnvMapping::AppCycle(), iEglDisplay, iEglSurface, iEnvMapping, and iFrame.

00234 {
00235     CEnvMappingContainer* instance = (CEnvMappingContainer*) aInstance;
00236     
00237     if ( instance->iEnvMapping->GetState() == CEnvMapping::ERunning )
00238     {
00239         instance->iFrame++;
00240         
00241         /* Call the main OpenGL ES Symbian rendering 'loop' */
00242         instance->iEnvMapping->AppCycle( instance->iFrame );
00243         
00244         /* Call eglSwapBuffers, which blit the graphics to the window */
00245         eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface );
00246         
00247         /* To keep the background light on */
00248         if(!(instance->iFrame%100))
00249         {
00250             User::ResetInactivityTime();
00251         }
00252         
00253         /* Suspend the current thread for a short while. Give some time 
00254            to other threads and AOs, avoids the ViewSrv error in ARMI and
00255            THUMB release builds. One may try to decrease the callback 
00256            function instead of this. */ 
00257         if(!(instance->iFrame%50))
00258         {
00259             User::After(0);
00260         }
00261     }
00262     
00263     return 0;
00264 }

void CEnvMappingContainer::SizeChanged (   )  [private]
 

Method from CoeControl that gets called when the display size changes. If OpenGL has been initialized, notifies the renderer class that the screen size has changed.

Definition at line 189 of file EnvMappingContainer.cpp.

References iEnvMapping, iOpenGlInitialized, and CEnvMapping::SetScreenSize().

00190     {
00191     if( iOpenGlInitialized && iEnvMapping )
00192         {
00193         TSize size;
00194         size = this->Size();
00195         
00196         iEnvMapping->SetScreenSize( size.iWidth, size.iHeight );
00197         }
00198     }

void CEnvMappingContainer::HandleResourceChange (  TInt  aType  )  [private]
 

Handles a change to the control's resources. This method reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of screen size change) by calling the SetExtentToWholeScreen() again so that this control fills the new screen size. This will then trigger a call to the SizeChanged() method.

Parameters:
aType Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.

Definition at line 283 of file EnvMappingContainer.cpp.

00284     {
00285         switch( aType )
00286         {
00287             case KEikDynamicLayoutVariantSwitch:
00288                     SetExtentToWholeScreen();
00289                     break;
00290             }
00291     }

TInt CEnvMappingContainer::CountComponentControls (   )  const [private]
 

Method from CoeControl. Does nothing in this implementation.

Definition at line 204 of file EnvMappingContainer.cpp.

00205 {
00206     return 0;
00207 }

CCoeControl * CEnvMappingContainer::ComponentControl (  TInt  aIndex  )  const [private]
 

Method from CCoeControl. Does nothing in this implementation.

Definition at line 213 of file EnvMappingContainer.cpp.

00214 {
00215     return NULL;
00216 }

void CEnvMappingContainer::Draw (  const TRect &  aRect  )  const [private]
 

Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method.

Definition at line 222 of file EnvMappingContainer.cpp.

00223 {
00224     CWindowGc& gc = SystemGc();
00225     gc.Clear( Rect() );
00226 }

void CEnvMappingContainer::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
)  [private]
 

Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.

Parameters:
aControl Control changing its state.
aEventType Type of the control event.

Definition at line 271 of file EnvMappingContainer.cpp.

00273 {
00274 }


Member Data Documentation

EGLDisplay CEnvMappingContainer::iEglDisplay [private]
 

Display where the OpenGL ES window surface resides.

Definition at line 102 of file EnvMappingContainer.h.

EGLSurface CEnvMappingContainer::iEglSurface [private]
 

Window surface where the OpenGL ES rendering is blitted to.

Definition at line 105 of file EnvMappingContainer.h.

EGLContext CEnvMappingContainer::iEglContext [private]
 

OpenGL ES rendering context.

Definition at line 108 of file EnvMappingContainer.h.

TInt CEnvMappingContainer::iFrame [private]
 

Frame counter variable, used in the animation.

Definition at line 111 of file EnvMappingContainer.h.

CPeriodic* CEnvMappingContainer::iPeriodic [private]
 

Active object that is the timing source for the animation.

Definition at line 114 of file EnvMappingContainer.h.

TBool CEnvMappingContainer::iOpenGlInitialized [private]
 

Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications.

Definition at line 120 of file EnvMappingContainer.h.

CEnvMapping* CEnvMappingContainer::iEnvMapping
 

Used in DrawCallBack() method to do the actual OpenGL ES rendering.

Definition at line 125 of file EnvMappingContainer.h.


© Nokia 2006

Back to top