|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <RainContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CRainContainer () |
Static Public Member Functions | |
| static TInt | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| CRain * | iRain |
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 |
| TInt | iFrame |
| TBool | iOpenGlInitialized |
Definition at line 32 of file RainContainer.h.
|
|
Destructor. Destroys the CPeriodic, CRain and uninitializes OpenGL ES. Definition at line 168 of file RainContainer.cpp. References CRain::AppExit(), iPeriodic, and iRain. 00169 { 00170 delete iPeriodic; 00171 00172 /* AppExit call is made to release any allocations made in AppInit. 00173 This call has to be made here before we destroy the rendering context. */ 00174 if( iRain ) 00175 { 00176 iRain->AppExit(); 00177 delete iRain; 00178 } 00179 00180 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00181 eglDestroySurface( iEglDisplay, iEglSurface ); 00182 eglDestroyContext( iEglDisplay, iEglContext ); 00183 eglTerminate( iEglDisplay ); // Release resources associated 00184 00185 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering.
Definition at line 28 of file RainContainer.cpp. References iEglDisplay, iFrame, and iOpenGlInitialized. 00029 { 00030 iOpenGlInitialized = EFalse; 00031 CreateWindowL(); 00032 00033 SetExtentToWholeScreen(); // Take the whole screen into use 00034 ActivateL(); 00035 00036 iFrame = 0; // Initialize 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( NULL ); 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(KInitializeFailed, "eglInitialize failed"); 00054 User::Panic( KInitializeFailed, 0 ); 00055 } 00056 00057 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00058 TInt numOfConfigs = 0; 00059 TInt configSize = 0; 00060 00061 /* Get the number of possible EGLConfigs */ 00062 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00063 { 00064 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00065 User::Panic( KGetConfigsFailed, 0 ); 00066 } 00067 00068 configSize = numOfConfigs; 00069 00070 /* Allocate memory for the configList */ 00071 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00072 if ( configList == NULL ) 00073 { 00074 _LIT(KConfigAllocFailed, "config alloc failed"); 00075 User::Panic( KConfigAllocFailed, 0 ); 00076 } 00077 00078 /* Define properties for the wanted EGLSurface. 00079 To get the best possible performance, choose 00080 an EGLConfig with a buffersize matching 00081 the current window's display mode*/ 00082 TDisplayMode DMode = Window().DisplayMode(); 00083 TInt BufferSize = 0; 00084 00085 switch(DMode) 00086 { 00087 case(EColor4K): 00088 BufferSize = 12; 00089 break; 00090 case(EColor64K): 00091 BufferSize = 16; 00092 break; 00093 case(EColor16M): 00094 BufferSize = 24; 00095 break; 00096 case(EColor16MU): 00097 BufferSize = 32; 00098 break; 00099 default: 00100 _LIT(KDModeError, "unsupported displaymode"); 00101 User::Panic( KDModeError, 0 ); 00102 break; 00103 } 00104 00105 const EGLint attrib_list[] = 00106 { 00107 EGL_BUFFER_SIZE, BufferSize, 00108 EGL_DEPTH_SIZE, 16, 00109 EGL_NONE 00110 }; 00111 00112 /* Choose an EGLConfig that best matches to the properties in attrib_list */ 00113 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00114 { 00115 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00116 User::Panic( KChooseConfigFailed, 0 ); 00117 } 00118 if ( numOfConfigs == 0 ) 00119 { 00120 _LIT(KNoConfig, "Can't find the requested config."); 00121 User::Panic( KNoConfig, 0 ); 00122 } 00123 00124 config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00125 // returned by eglChooseConfig are sorted so 00126 // that the best matching EGLConfig is first in 00127 // the list. 00128 User::Free( configList ); // Free configList, not used anymore. 00129 00130 /* Create a window where the graphics are blitted */ 00131 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00132 if ( iEglSurface == NULL ) 00133 { 00134 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00135 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00136 } 00137 00138 /* Create a rendering context */ 00139 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00140 if ( iEglContext == NULL ) 00141 { 00142 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00143 User::Panic( KCreateContextFailed, 0 ); 00144 } 00145 00146 /* Make the context current. Binds context to the current rendering thread 00147 and surface.*/ 00148 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00149 { 00150 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00151 User::Panic( KMakeCurrentFailed, 0 ); 00152 } 00153 00154 00155 TSize size; 00156 size = this->Size(); 00157 iRain = CRain::NewL( size.iWidth, size.iHeight ); 00158 iRain->AppInitL(); 00159 00160 iOpenGlInitialized = ETrue; 00161 00162 iPeriodic = CPeriodic::NewL( -100 ); // Create an active object for 00163 // animating the scene 00164 iPeriodic->Start( 100, 100, TCallBack( CRainContainer::DrawCallBack, this ) ); 00165 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CRain to do the rendering for each frame.
Definition at line 270 of file RainContainer.cpp. References CRain::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iRain. 00271 { 00272 CRainContainer* instance = (CRainContainer*) aInstance; 00273 00274 if ( instance->iRain->GetState() == CRain::ERunning ) 00275 { 00276 instance->iFrame++; 00277 00278 /* Call the main OpenGL ES Symbian rendering 'loop' */ 00279 instance->iRain->AppCycle( instance->iFrame ); 00280 00281 /* Call eglSwapBuffers, which blit the graphics to the window */ 00282 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00283 00284 /* To keep the background light on */ 00285 User::ResetInactivityTime(); 00286 00287 /* Suspend the current thread for a short while. Give some time 00288 to other threads and AOs, avoids the ViewSrv error in ARMI and 00289 THUMB release builds. One may try to decrease the callback 00290 function instead of this. */ 00291 if ( !(instance->iFrame % 50) ) 00292 { 00293 User::After(0); 00294 } 00295 } 00296 return 0; 00297 }
|
|
|
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 192 of file RainContainer.cpp. References iOpenGlInitialized, iRain, and CRain::SetScreenSize(). 00193 { 00194 if( iOpenGlInitialized && iRain ) 00195 { 00196 TSize size; 00197 size = this->Size(); 00198 00199 iRain->SetScreenSize( size.iWidth, size.iHeight ); 00200 } 00201 }
|
|
|
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 211 of file RainContainer.cpp. 00212 { 00213 switch( aType ) 00214 { 00215 case KEikDynamicLayoutVariantSwitch: 00216 SetExtentToWholeScreen(); 00217 break; 00218 } 00219 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 225 of file RainContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 234 of file RainContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 243 of file RainContainer.cpp. References iRain. 00244 { 00245 CWindowGc& gc = SystemGc(); 00246 gc.Clear( aRect ); 00247 00248 if ( iRain->GetState() == CRain::ELoadingTextures ) 00249 { 00250 _LIT(KLoading, "Loading..."); 00251 Utils::OutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack ); 00252 } 00253 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 260 of file RainContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 103 of file RainContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 106 of file RainContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 109 of file RainContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 112 of file RainContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 115 of file RainContainer.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 RainContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 126 of file RainContainer.h. |
|
© Nokia 2006 |