|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <LensFlareContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CLensFlareContainer () |
Static Public Member Functions | |
| static TInt | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| CLensflare * | iLensflare |
Private Member Functions | |
| void | SizeChanged () |
| TInt | CountComponentControls () const |
| CCoeControl * | ComponentControl (TInt aIndex) const |
| void | Draw (const TRect &aRect) const |
| void | HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType) |
| void | HandleResourceChange (TInt aType) |
Private Attributes | |
| EGLDisplay | iEglDisplay |
| EGLSurface | iEglSurface |
| EGLContext | iEglContext |
| TInt | iFrame |
| CPeriodic * | iPeriodic |
| TBool | iOpenGlInitialized |
Definition at line 32 of file LensFlareContainer.h.
|
|
Destructor. Destroys the CPeriodic, CLensFlare and uninitializes OpenGL ES. Definition at line 186 of file LensFlareContainer.cpp. References CLensflare::AppExit(), iEglContext, iEglDisplay, iEglSurface, iLensflare, and iPeriodic. 00187 { 00188 delete iPeriodic; 00189 00190 /* AppExit call is made to release any allocations made in AppInit. 00191 This call has to be made here before we destroy the rendering context. */ 00192 if ( !(iLensflare == NULL) ) 00193 { 00194 iLensflare->AppExit(); 00195 delete iLensflare; 00196 } 00197 00198 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00199 eglDestroySurface( iEglDisplay, iEglSurface ); 00200 eglDestroyContext( iEglDisplay, iEglContext ); 00201 eglTerminate( iEglDisplay ); // Release resources associated 00202 00203 }
|
|
|
Symbian default constructor.
Definition at line 44 of file LensFlareContainer.cpp. References iEglDisplay, iFrame, and iOpenGlInitialized. 00045 { 00046 iOpenGlInitialized = EFalse; 00047 CreateWindowL(); 00048 00049 SetExtentToWholeScreen(); // Take the whole screen into use 00050 ActivateL(); 00051 00052 00053 iFrame = 0; // Initialize frame counter 00054 00055 EGLConfig config; // Describes the format, type and 00056 // size of the color buffers and 00057 // ancillary buffers for EGLSurface 00058 00059 /* Get the display for drawing graphics*/ 00060 iEglDisplay = eglGetDisplay( NULL ); 00061 if ( iEglDisplay == NULL ) 00062 { 00063 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00064 User::Panic( KGetDisplayFailed, 0 ); 00065 } 00066 00067 /* Initialize display */ 00068 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00069 { 00070 _LIT(KInitializeFailed, "eglInitialize failed"); 00071 User::Panic( KInitializeFailed, 0 ); 00072 } 00073 00074 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00075 EGLint numOfConfigs = 0; 00076 EGLint configSize = 0; 00077 00078 /* Get the number of possible EGLConfigs */ 00079 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00080 { 00081 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00082 User::Panic( KGetConfigsFailed, 0 ); 00083 } 00084 00085 configSize = numOfConfigs; 00086 00087 /* Allocate memory for the configList */ 00088 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00089 if ( configList == NULL ) 00090 { 00091 _LIT(KConfigAllocFailed, "config alloc failed"); 00092 User::Panic( KConfigAllocFailed, 0 ); 00093 } 00094 00095 /* Define properties for the wanted EGLSurface. 00096 To get the best possible performance, choose 00097 an EGLConfig with a buffersize matching 00098 the current window's display mode*/ 00099 TDisplayMode DMode = Window().DisplayMode(); 00100 TInt BufferSize = 0; 00101 00102 switch(DMode) 00103 { 00104 case(EColor4K): 00105 BufferSize = 12; 00106 break; 00107 case(EColor64K): 00108 BufferSize = 16; 00109 break; 00110 case(EColor16M): 00111 BufferSize = 24; 00112 break; 00113 case(EColor16MU): 00114 BufferSize = 32; 00115 break; 00116 default: 00117 _LIT(KDModeError, "unsupported displaymode"); 00118 User::Panic( KDModeError, 0 ); 00119 break; 00120 } 00121 00122 const EGLint attrib_list[] = 00123 { 00124 EGL_BUFFER_SIZE, BufferSize, 00125 EGL_DEPTH_SIZE, 16, 00126 EGL_NONE 00127 }; 00128 00129 /* Choose an EGLConfig that best matches to the properties in attrib_list */ 00130 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00131 { 00132 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00133 User::Panic( KChooseConfigFailed, 0 ); 00134 } 00135 if ( numOfConfigs == 0 ) 00136 { 00137 _LIT(KNoConfig, "Can't find the requested config."); 00138 User::Panic( KNoConfig, 0 ); 00139 } 00140 00141 config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00142 // returned by eglChooseConfig are sorted so 00143 // that the best matching EGLConfig is first in 00144 // the list. 00145 User::Free( configList ); // Free configList, not used anymore. 00146 00147 /* Create a window where the graphics are blitted */ 00148 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00149 if ( iEglSurface == NULL ) 00150 { 00151 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00152 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00153 } 00154 00155 /* Create a rendering context */ 00156 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00157 if ( iEglContext == NULL ) 00158 { 00159 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00160 User::Panic( KCreateContextFailed, 0 ); 00161 } 00162 00163 /* Make the context current. Binds context to the current rendering thread 00164 and surface.*/ 00165 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00166 { 00167 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00168 User::Panic( KMakeCurrentFailed, 0 ); 00169 } 00170 00171 00172 TSize size; 00173 size = this->Size(); 00174 00175 iLensflare = CLensflare::NewL( size.iWidth, size.iHeight ); 00176 iLensflare->AppInitL(); 00177 00178 iOpenGlInitialized = ETrue; 00179 00180 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00181 // animating the scene 00182 iPeriodic->Start( 100, 100, TCallBack( CLensFlareContainer::DrawCallBack, this ) ); 00183 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CLensFlare to do the rendering for each frame.
Definition at line 289 of file LensFlareContainer.cpp. References CLensflare::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iLensflare. 00290 { 00291 CLensFlareContainer* instance = (CLensFlareContainer*) aInstance; 00292 00293 if ( instance->iLensflare->GetState() == CLensflare::ERunning ) 00294 { 00295 instance->iFrame++; 00296 00297 /* Call the main OpenGL ES Symbian rendering 'loop' */ 00298 instance->iLensflare->AppCycle( instance->iFrame ); 00299 00300 /* Call eglSwapBuffers, which blit the graphics to the window */ 00301 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00302 00303 /* To keep the background light on */ 00304 User::ResetInactivityTime(); 00305 00306 /* Suspend the current thread for a short while. Give some time 00307 to other threads and AOs, avoids the ViewSrv error in ARMI and 00308 THUMB release builds. One may try to decrease the callback 00309 function instead of this. */ 00310 if ( !(instance->iFrame % 50) ) 00311 { 00312 User::After(0); 00313 } 00314 } 00315 return 0; 00316 }
|
|
|
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 210 of file LensFlareContainer.cpp. References iLensflare, iOpenGlInitialized, and CLensflare::SetScreenSize(). 00211 { 00212 if( iOpenGlInitialized && iLensflare ) 00213 { 00214 TSize size; 00215 size = this->Size(); 00216 00217 iLensflare->SetScreenSize( size.iWidth, size.iHeight ); 00218 } 00219 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 243 of file LensFlareContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 252 of file LensFlareContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 261 of file LensFlareContainer.cpp. References iLensflare. 00262 { 00263 CWindowGc& gc = SystemGc(); 00264 gc.Clear( aRect ); 00265 00266 if ( iLensflare->GetState() == CLensflare::ELoadingTextures ) 00267 { 00268 _LIT(KLoadingText, "Loading..."); 00269 Utils::OutputText(gc, KLoadingText, TPoint(70, 105), KRgbBlack ); 00270 } 00271 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 278 of file LensFlareContainer.cpp.
|
|
|
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.
Definition at line 229 of file LensFlareContainer.cpp. 00230 { 00231 switch( aType ) 00232 { 00233 case KEikDynamicLayoutVariantSwitch: 00234 SetExtentToWholeScreen(); 00235 break; 00236 } 00237 }
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 103 of file LensFlareContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 106 of file LensFlareContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 109 of file LensFlareContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 112 of file LensFlareContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 115 of file LensFlareContainer.h. |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 121 of file LensFlareContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 126 of file LensFlareContainer.h. |
|
© Nokia 2006 |