S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CPickSelectContainer Class Reference

#include <PickSelectContainer.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

static TInt DrawCallBack (TAny *aInstance)

Public Attributes

CPickSelect * iPickSelect

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
CPeriodic * iPeriodic
TBool iOpenGlInitialized
TInt iFrame


Detailed Description

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

Definition at line 31 of file PickSelectContainer.h.


Constructor & Destructor Documentation

CPickSelectContainer::~CPickSelectContainer (   )  [virtual]
 

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

Definition at line 143 of file PickSelectContainer.cpp.

References CPickSelect::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iPickSelect.

00144     {
00145     delete iPeriodic;
00146 
00147     if ( iPickSelect )
00148         {
00149         /* AppExit call is made to release 
00150            any allocations made in AppInit. */
00151         iPickSelect->AppExit();
00152         delete iPickSelect;
00153         }
00154     
00155     eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
00156     eglDestroySurface( iEglDisplay, iEglSurface ); 
00157     eglDestroyContext( iEglDisplay, iEglContext );
00158     eglTerminate( iEglDisplay );                   // Release resources associated
00159                                                    // with EGL and OpenGL ES
00160     }


Member Function Documentation

void CPickSelectContainer::ConstructL (  const TRect &  aRect  ) 
 

EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.

Parameters:
aRect Screen rectangle for container.

Definition at line 27 of file PickSelectContainer.cpp.

References CPickSelect::AppInit(), DrawCallBack(), iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iPickSelect, and CPickSelect::NewL().

00028     {
00029     iOpenGlInitialized = EFalse;
00030 
00031     CreateWindowL();
00032 
00033     SetExtentToWholeScreen();                // Take the whole screen into use
00034     ActivateL();
00035 
00036     iFrame = 0;                              // Frame counter
00037     
00038     EGLConfig Config;                        // Describes the format, type and 
00039                                              // size of the color buffers and
00040                                              // ancillary buffers for EGLSurface
00041 
00042     // Get the display for drawing graphics
00043     iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
00044     if ( iEglDisplay == NULL )
00045         {
00046         _LIT(KGetDisplayFailed, "eglGetDisplay failed");
00047         User::Panic( KGetDisplayFailed, 0 );
00048         }
00049     
00050     // Initialize display 
00051     if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE )
00052         {
00053         _LIT(KGetDisplayFailed, "eglGetDisplay failed");
00054         User::Panic( KGetDisplayFailed, 0 );
00055         }
00056     
00057     EGLConfig *configList = NULL;            // Pointer for EGLConfigs
00058     EGLint numOfConfigs = 0; 
00059     EGLint configSize   = 0;
00060 
00061     // Get the number of possible EGLConfigs 
00062     if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 
00063         == EGL_FALSE )
00064         {
00065         _LIT(KGetConfigsFailed, "eglGetConfigs failed");
00066         User::Panic( KGetConfigsFailed, 0 );
00067         }
00068     
00069     configSize = numOfConfigs;
00070 
00071     // Allocate memory for the configList 
00072     configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize );
00073     if ( configList == NULL )
00074         {
00075         _LIT(KConfigAllocFailed, "config alloc failed");
00076         User::Panic( KConfigAllocFailed, 0 );
00077         }
00078     
00079     /* Define properties for the wanted EGLSurface.
00080        We need to choose a 32-bit framebuffer, since the picking
00081        method needs an 8-bit alpha channel.
00082      */
00083  
00084     // Define properties for the wanted EGLSurface 
00085     const EGLint attrib_list[] = { EGL_BUFFER_SIZE,32,   // 32-bit framebuffer
00086                                    EGL_DEPTH_SIZE,16,    // 16-bit depthbuffer
00087                                    EGL_NONE };
00088 
00089     // Choose an EGLConfig that best matches to the properties in attrib_list 
00090     if ( eglChooseConfig( iEglDisplay, attrib_list, configList, 
00091                          configSize, &numOfConfigs ) == EGL_FALSE )
00092         {
00093         _LIT(KChooseConfigFailed, "eglChooseConfig failed");
00094         User::Panic( KChooseConfigFailed, 0 );
00095         }
00096     
00097     Config = configList[0];  // Choose the best EGLConfig. EGLConfigs 
00098                               // returned by eglChooseConfig are sorted so 
00099                               // that the best matching EGLConfig is first in
00100                               // the list.
00101     User::Free( configList ); // Free configList, not used anymore.
00102 
00103     // Create a window where the graphics are blitted 
00104     iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL );
00105     if ( iEglSurface == NULL )
00106         {
00107         _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed");
00108         User::Panic( KCreateWindowSurfaceFailed, 0 );
00109         }
00110     
00111     // Create a rendering context 
00112     iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL );
00113     if ( iEglContext == NULL )
00114         {
00115         _LIT(KCreateContextFailed, "eglCreateContext failed");
00116         User::Panic( KCreateContextFailed, 0 );
00117         }
00118     
00119     /* Make the context current. Binds context to the current rendering thread
00120        and surface.*/
00121     if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 
00122         == EGL_FALSE )
00123         {
00124         _LIT(KMakeCurrentFailed, "eglMakeCurrent failed");
00125         User::Panic( KMakeCurrentFailed, 0 );
00126         }
00127     
00128     TSize size;
00129     size = this->Size();
00130 
00131     iPickSelect = CPickSelect::NewL( size.iWidth, size.iHeight ); // Create an instance of PickSelect
00132     iPickSelect->AppInit();                                // Initialize OpenGL ES
00133 
00134     iOpenGlInitialized = ETrue;
00135     
00136     iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for
00137                                                            // animating the scene
00138     iPeriodic->Start( 100, 100, 
00139                       TCallBack( CPickSelectContainer::DrawCallBack, this ) );
00140 }

TInt CPickSelectContainer::DrawCallBack (  TAny *  aInstance  )  [static]
 

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

Parameters:
aInstance Pointer to this instance of CPickSelectContainer.

Definition at line 229 of file PickSelectContainer.cpp.

References CPickSelect::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iPickSelect.

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

void CPickSelectContainer::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 167 of file PickSelectContainer.cpp.

References iOpenGlInitialized, iPickSelect, and CPickSelect::SetScreenSize().

00168     {
00169     if( iOpenGlInitialized && iPickSelect )
00170         {
00171         TSize size;
00172         size = this->Size();
00173         
00174         iPickSelect->SetScreenSize( size.iWidth, size.iHeight );
00175         }
00176     }

void CPickSelectContainer::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 186 of file PickSelectContainer.cpp.

00187     {
00188         switch( aType )
00189         {
00190             case KEikDynamicLayoutVariantSwitch:
00191                     SetExtentToWholeScreen();
00192                     break;
00193             }
00194     }

TInt CPickSelectContainer::CountComponentControls (   )  const [private]
 

Method from CoeControl. Does nothing in this implementation.

Definition at line 200 of file PickSelectContainer.cpp.

00201     {
00202     return 0;
00203     }

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

Method from CCoeControl. Does nothing in this implementation.

Definition at line 209 of file PickSelectContainer.cpp.

00210     {
00211     return NULL;
00212     }

void CPickSelectContainer::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 218 of file PickSelectContainer.cpp.

00219     {
00220     CWindowGc& gc = SystemGc();
00221     gc.Clear( Rect() );
00222     }

void CPickSelectContainer::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 262 of file PickSelectContainer.cpp.

00264     {
00265     }


Member Data Documentation

EGLDisplay CPickSelectContainer::iEglDisplay [private]
 

Display where the OpenGL ES window surface resides.

Definition at line 101 of file PickSelectContainer.h.

EGLSurface CPickSelectContainer::iEglSurface [private]
 

Window surface where the OpenGL ES rendering is blitted to.

Definition at line 104 of file PickSelectContainer.h.

EGLContext CPickSelectContainer::iEglContext [private]
 

OpenGL ES rendering context.

Definition at line 107 of file PickSelectContainer.h.

CPeriodic* CPickSelectContainer::iPeriodic [private]
 

Active object that is the timing source for the animation.

Definition at line 110 of file PickSelectContainer.h.

TBool CPickSelectContainer::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 116 of file PickSelectContainer.h.

TInt CPickSelectContainer::iFrame [private]
 

Frame counter variable, used in the animation.

Definition at line 119 of file PickSelectContainer.h.

CPickSelect* CPickSelectContainer::iPickSelect
 

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

Definition at line 124 of file PickSelectContainer.h.


© Nokia 2006

Back to top