|
Nokia N97 SDK Example Applications Guide |
#include <SnowContainer.h>
Inheritance diagram for CSnowContainer:

Definition at line 29 of file SnowContainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CSnowContainer () |
Static Public Member Functions |
|
| static TInt | DrawCallBack (TAny *aInstance) |
| static TTime | GetTimeTick () |
Public Attributes |
|
| CSnow * | iSnow |
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 |
| TUint | iStartTime |
| GLfloat | iLastFrameTime |
| TUint | iFrame |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CSnow and uninitializes OpenGL ES. Definition at line 208 of file SnowContainer.cpp. References CSnow::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iSnow. 00209 { 00210 delete iPeriodic; 00211 00212 /* AppExit call is made to release any allocations made in AppInit. 00213 This call has to be made here before we destroy the rendering context. */ 00214 if ( iSnow ) 00215 { 00216 iSnow->AppExit(); 00217 delete iSnow; 00218 } 00219 00220 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00221 eglDestroySurface( iEglDisplay, iEglSurface ); 00222 eglDestroyContext( iEglDisplay, iEglContext ); 00223 eglTerminate( iEglDisplay ); 00224 }
|
|
||||||||||||
|
Second phase constructor that can call methods that may leave. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 24 of file SnowContainer.cpp. References iAppUi, iEglDisplay, and iOpenGlInitialized. Referenced by CSnowAppUi::ConstructL(). 00025 { 00026 iAppUi = aAppUi; 00027 // Open GL hasn't been initialized 00028 iOpenGlInitialized = EFalse; 00029 00030 // Create the native window 00031 CreateWindowL(); 00032 00033 // Do not go to full-screen in touch devices. 00034 if (AknLayoutUtils::PenEnabled()) 00035 { 00036 SetRect(aRect); 00037 } 00038 else 00039 { 00040 SetExtentToWholeScreen(); // Take the whole screen into use 00041 } 00042 ActivateL(); 00043 00044 // Describes the format, type and size of the color buffers and 00045 // ancillary buffers for EGLSurface 00046 EGLConfig config; 00047 00048 // Get the display for drawing graphics 00049 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00050 if ( iEglDisplay == NULL ) 00051 { 00052 _LIT( KGetDisplayFailed, "eglGetDisplay failed" ); 00053 User::Panic( KGetDisplayFailed, 0 ); 00054 } 00055 00056 // Initialize display 00057 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00058 { 00059 _LIT( KInitializeFailed, "eglInitialize failed" ); 00060 User::Panic( KInitializeFailed, 0 ); 00061 } 00062 00063 // Pointer for EGLConfigs 00064 EGLConfig *configList = NULL; 00065 EGLint numOfConfigs = 0; 00066 EGLint configSize = 0; 00067 00068 // Get the number of possible EGLConfigs 00069 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00070 { 00071 _LIT( KGetConfigsFailed, "eglGetConfigs failed" ); 00072 User::Panic( KGetConfigsFailed, 0 ); 00073 } 00074 00075 configSize = numOfConfigs; 00076 00077 // Allocate memory for the configList 00078 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00079 if ( configList == NULL ) 00080 { 00081 _LIT( KConfigAllocFailed, "config alloc failed" ); 00082 User::Panic( KConfigAllocFailed, 0 ); 00083 } 00084 00085 // Define properties for the wanted EGLSurface 00086 TDisplayMode DMode = Window().DisplayMode(); 00087 TInt BufferSize = 0; 00088 00089 switch(DMode) 00090 { 00091 case(EColor4K): 00092 BufferSize = 12; 00093 break; 00094 case(EColor64K): 00095 BufferSize = 16; 00096 break; 00097 case(EColor16M): 00098 BufferSize = 24; 00099 break; 00100 case(EColor16MU): 00101 case(EColor16MA): 00102 BufferSize = 32; 00103 break; 00104 default: 00105 _LIT(KDModeError, "unsupported displaymode"); 00106 User::Panic( KDModeError, 0 ); 00107 break; 00108 } 00109 00110 // Define properties for requesting a full-screen antialiased window surface 00111 const EGLint attrib_list_fsaa[] = 00112 { 00113 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00114 EGL_BUFFER_SIZE, BufferSize, 00115 EGL_DEPTH_SIZE, 16, 00116 EGL_SAMPLE_BUFFERS, 1, 00117 EGL_SAMPLES, 4, 00118 EGL_NONE 00119 }; 00120 00121 // Define properties for requesting a non-antialiased window surface 00122 const EGLint attrib_list[] = 00123 { 00124 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00125 EGL_BUFFER_SIZE, BufferSize, 00126 EGL_DEPTH_SIZE, 16, 00127 EGL_NONE 00128 }; 00129 00130 // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa 00131 if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00132 { 00133 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00134 User::Panic( KChooseConfigFailed, 0 ); 00135 } 00136 00137 // Check if no configurations were found 00138 if ( numOfConfigs == 0 ) 00139 { 00140 // No configs with antialising were found. Try to get the non-antialiased config 00141 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00142 { 00143 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00144 User::Panic( KChooseConfigFailed, 0 ); 00145 } 00146 00147 if ( numOfConfigs == 0 ) 00148 { 00149 // No configs found without antialiasing 00150 _LIT( KNoConfig, "Can't find the requested config." ); 00151 User::Panic( KNoConfig, 0 ); 00152 } 00153 } 00154 00155 // Choose the best EGLConfig. EGLConfigs returned by eglChooseConfig are 00156 // sorted so that the best matching EGLConfig is first in the list. 00157 config = configList[0]; 00158 00159 // Free configList, as it's not used anymore. 00160 User::Free( configList ); 00161 00162 // Create a window where the graphics are blitted 00163 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00164 if ( iEglSurface == NULL ) 00165 { 00166 _LIT( KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed" ); 00167 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00168 } 00169 00170 // Create a rendering context 00171 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00172 if ( iEglContext == NULL ) 00173 { 00174 _LIT( KCreateContextFailed, "eglCreateContext failed" ); 00175 User::Panic( KCreateContextFailed, 0 ); 00176 } 00177 00178 // Make the context current. Binds context to the current rendering thread 00179 // and surface. 00180 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00181 { 00182 _LIT( KMakeCurrentFailed, "eglMakeCurrent failed" ); 00183 User::Panic( KMakeCurrentFailed, 0 ); 00184 } 00185 00186 00187 TSize size = this->Size(); 00188 iSnow = CSnow::NewL( size.iWidth, size.iHeight ); 00189 iSnow->AppInitL(); 00190 00191 iOpenGlInitialized = ETrue; 00192 00193 // Initialize timers and counters 00194 iFrame = 0; 00195 iStartTime = User::NTickCount(); 00196 iLastFrameTime = iStartTime; 00197 00198 // Create an active object for animating the scene 00199 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); 00200 iPeriodic->Start( 100, 100, TCallBack( CSnowContainer::DrawCallBack, this ) ); 00201 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CSnow to do the rendering for each frame.
Definition at line 332 of file SnowContainer.cpp. References CSnow::AppCycle(), iEglDisplay, iEglSurface, iFrame, iLastFrameTime, iSnow, and iStartTime. 00333 { 00334 // Cast parameter to container instance 00335 CSnowContainer* instance = (CSnowContainer*) aInstance; 00336 00337 // Update the frame counts 00338 instance->iFrame++; 00339 00340 // Compute the elapsed time in seconds since the startup of the example 00341 #ifdef __WINS__ 00342 00343 // In the emulator the tickcount runs at 200Hz 00344 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTime ) ) / 200.f; 00345 00346 #else 00347 00348 // In the device the tickcount runs at 1000hz (as intended) 00349 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTime ) ) / 1000.f; 00350 00351 #endif 00352 00353 GLfloat deltaTimeSecs = timeSecs - instance->iLastFrameTime; 00354 00355 if ( instance->iSnow->GetState() == CSnow::ERunning ) 00356 { 00357 // Call the main OpenGL ES Symbian rendering 'loop' 00358 instance->iSnow->AppCycle( instance->iFrame, timeSecs, deltaTimeSecs ); 00359 00360 // Call eglSwapBuffers, which blit the graphics to the window 00361 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00362 00363 if ( !(instance->iFrame % 50 ) ) 00364 { 00365 // Reset inactivity timer to keep the background light on 00366 User::ResetInactivityTime(); 00367 00368 // Suspend the current thread for a short while. Give some time 00369 // to other threads and AOs, avoids the ViewSrv error in ARMI and 00370 // THUMB release builds. One may try to decrease the callback 00371 // function instead of this. 00372 User::After( 0 ); 00373 } 00374 } 00375 00376 // Set the current time to be the last frame time for the upcoming frame 00377 instance->iLastFrameTime = timeSecs; 00378 00379 return 0; 00380 }
|
|
|
Returns the current system time.
Definition at line 319 of file SnowContainer.cpp.
|
|
|
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 231 of file SnowContainer.cpp. References iOpenGlInitialized, iSnow, and CSnow::SetScreenSize(). 00232 { 00233 if( iOpenGlInitialized && iSnow ) 00234 { 00235 // If example is running and OpenGL ES is initialized 00236 // notify it of the screen size change 00237 TSize size = this->Size(); 00238 iSnow->SetScreenSize( size.iWidth, size.iHeight ); 00239 } 00240 }
|
|
|
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 250 of file SnowContainer.cpp. References iAppUi. 00251 { 00252 switch( aType ) 00253 { 00254 case KEikDynamicLayoutVariantSwitch: 00255 // Do not go full-screen in touch devices. 00256 if (AknLayoutUtils::PenEnabled()) 00257 { 00258 SetRect(iAppUi->ClientRect()); 00259 } 00260 else 00261 { 00262 SetExtentToWholeScreen(); // Take the whole screen into use 00263 } 00264 break; 00265 } 00266 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 273 of file SnowContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 282 of file SnowContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 291 of file SnowContainer.cpp. References iSnow. 00292 { 00293 CWindowGc& gc = SystemGc(); 00294 gc.Clear( aRect ); 00295 00296 if ( iSnow->GetState() == CSnow::ELoadingTextures ) 00297 { 00298 _LIT(KLoading, "Loading..."); 00299 utilOutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack ); 00300 } 00301 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 308 of file SnowContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 106 of file SnowContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CSnowContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 108 of file SnowContainer.h. Referenced by DrawCallBack(), and ~CSnowContainer(). |
|
|
OpenGL ES rendering context. Definition at line 110 of file SnowContainer.h. Referenced by ~CSnowContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 112 of file SnowContainer.h. Referenced by ~CSnowContainer(). |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 117 of file SnowContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Time when the example started running (rendering frames). Definition at line 120 of file SnowContainer.h. Referenced by DrawCallBack(). |
|
|
Time when the previous frame was rendered. Definition at line 122 of file SnowContainer.h. Referenced by DrawCallBack(). |
|
|
Counts the number of frames rendered. Definition at line 124 of file SnowContainer.h. Referenced by DrawCallBack(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 127 of file SnowContainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 132 of file SnowContainer.h. Referenced by Draw(), DrawCallBack(), SizeChanged(), and ~CSnowContainer(). |
|
© Nokia 2009 |