|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <SnowContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CSnowContainer () |
Static Public Member Functions | |
| static TInt | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| TInt | iFrame |
| 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 |
Definition at line 31 of file SnowContainer.h.
|
|
Destructor. Destroys the CPeriodic, CSnow and uninitializes OpenGL ES. Definition at line 167 of file SnowContainer.cpp. References CSnow::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iSnow. 00168 { 00169 delete iPeriodic; 00170 00171 /* AppExit call is made to release any allocations made in AppInit. 00172 This call has to be made here before we destroy the rendering context. */ 00173 if ( iSnow ) 00174 { 00175 iSnow->AppExit(); 00176 delete iSnow; 00177 } 00178 00179 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00180 eglDestroySurface( iEglDisplay, iEglSurface ); 00181 eglDestroyContext( iEglDisplay, iEglContext ); 00182 eglTerminate( iEglDisplay ); // Release resources associated 00183 00184 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 26 of file SnowContainer.cpp. References iEglDisplay, iFrame, and iOpenGlInitialized. 00027 { 00028 iOpenGlInitialized = EFalse; 00029 CreateWindowL(); 00030 00031 00032 SetExtentToWholeScreen(); // Take the whole screen into use 00033 ActivateL(); 00034 00035 iFrame = 0; // Initialize 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( NULL ); 00043 if ( iEglDisplay == NULL ) 00044 { 00045 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00046 User::Panic( KGetDisplayFailed, 0 ); 00047 } 00048 00049 /* Initialize display */ 00050 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00051 { 00052 _LIT(KInitializeFailed, "eglInitialize failed"); 00053 User::Panic( KInitializeFailed, 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(KGetConfigsFailed, "eglGetConfigs failed"); 00064 User::Panic( KGetConfigsFailed, 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(KConfigAllocFailed, "config alloc failed"); 00074 User::Panic( KConfigAllocFailed, 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(KChooseConfigFailed, "eglChooseConfig failed"); 00115 User::Panic( KChooseConfigFailed, 0 ); 00116 } 00117 if ( numOfConfigs == 0 ) 00118 { 00119 _LIT(KNoConfig, "Can't find the requested config."); 00120 User::Panic( KNoConfig, 0 ); 00121 } 00122 00123 config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00124 // returned by eglChooseConfig are sorted so 00125 // that the best matching EGLConfig is first in 00126 // the list. 00127 User::Free( configList ); // Free configList, not used anymore. 00128 00129 /* Create a window where the graphics are blitted */ 00130 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00131 if ( iEglSurface == NULL ) 00132 { 00133 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00134 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00135 } 00136 00137 /* Create a rendering context */ 00138 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00139 if ( iEglContext == NULL ) 00140 { 00141 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00142 User::Panic( KCreateContextFailed, 0 ); 00143 } 00144 00145 /* Make the context current. Binds context to the current rendering thread 00146 and surface.*/ 00147 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00148 { 00149 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00150 User::Panic( KMakeCurrentFailed, 0 ); 00151 } 00152 00153 00154 TSize size; 00155 size = this->Size(); 00156 iSnow = CSnow::NewL( size.iWidth, size.iHeight ); 00157 iSnow->AppInitL(); 00158 00159 iOpenGlInitialized = ETrue; 00160 00161 iPeriodic = CPeriodic::NewL( -100 ); // Create an active object for 00162 // animating the scene 00163 iPeriodic->Start( 100, 100, TCallBack( CSnowContainer::DrawCallBack, this ) ); 00164 }
|
|
|
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 273 of file SnowContainer.cpp. References CSnow::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iSnow. 00274 { 00275 CSnowContainer* instance = (CSnowContainer*) aInstance; 00276 00277 if ( instance->iSnow->GetState() == CSnow::ERunning ) 00278 { 00279 instance->iFrame++; 00280 00281 /* Call the main OpenGL ES Symbian rendering 'loop' */ 00282 instance->iSnow->AppCycle( instance->iFrame ); 00283 00284 /* Call eglSwapBuffers, which blit the graphics to the window */ 00285 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00286 00287 /* To keep the background light on */ 00288 User::ResetInactivityTime(); 00289 00290 /* Suspend the current thread for a short while. Give some time 00291 to other threads and AOs, avoids the ViewSrv error in ARMI and 00292 THUMB release builds. One may try to decrease the callback 00293 function instead of this. */ 00294 if ( !(instance->iFrame % 50) ) 00295 { 00296 User::After(0); 00297 } 00298 } 00299 00300 return 0; 00301 }
|
|
|
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 191 of file SnowContainer.cpp. References iOpenGlInitialized, iSnow, and CSnow::SetScreenSize(). 00192 { 00193 if( iOpenGlInitialized && iSnow ) 00194 { 00195 TSize size; 00196 size = this->Size(); 00197 00198 iSnow->SetScreenSize( size.iWidth, size.iHeight ); 00199 } 00200 }
|
|
|
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 210 of file SnowContainer.cpp. 00211 { 00212 switch( aType ) 00213 { 00214 case KEikDynamicLayoutVariantSwitch: 00215 SetExtentToWholeScreen(); 00216 break; 00217 } 00218 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 227 of file SnowContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 236 of file SnowContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 245 of file SnowContainer.cpp. References iSnow. 00246 { 00247 CWindowGc& gc = SystemGc(); 00248 gc.Clear( aRect ); 00249 00250 if ( iSnow->GetState() == CSnow::ELoadingTextures ) 00251 { 00252 _LIT(KLoading, "Loading..."); 00253 Utils::OutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack ); 00254 } 00255 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 262 of file SnowContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 101 of file SnowContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 103 of file SnowContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 105 of file SnowContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 108 of file SnowContainer.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 114 of file SnowContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 119 of file SnowContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 121 of file SnowContainer.h. |
|
© Nokia 2006 |