|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <ShadowsContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CShadowsContainer () |
Static Public Member Functions | |
| static int | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| CShadows * | iShadows |
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 |
Definition at line 31 of file ShadowsContainer.h.
|
|
Destructor. Destroys the CPeriodic, CShadow and uninitializes OpenGL ES. Definition at line 164 of file ShadowsContainer.cpp. References CShadows::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iShadows. 00165 { 00166 delete iPeriodic; 00167 00168 /* AppExit call is made to release 00169 any allocations made in AppInit. */ 00170 if ( iShadows ) 00171 { 00172 iShadows->AppExit(); 00173 delete iShadows; 00174 } 00175 00176 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00177 eglDestroySurface( iEglDisplay, iEglSurface ); 00178 eglDestroyContext( iEglDisplay, iEglContext ); 00179 eglTerminate( iEglDisplay ); // Release resources associated 00180 // with EGL and OpenGL ES 00181 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 27 of file ShadowsContainer.cpp. References CShadows::AppInit(), DrawCallBack(), iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iShadows, and CShadows::NewL(). 00028 { 00029 iOpenGlInitialized = EFalse; 00030 CreateWindowL(); 00031 00032 SetExtentToWholeScreen(); // Take the whole screen into use 00033 ActivateL(); 00034 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(KInitializeFailed, "eglInitialize failed"); 00054 User::Panic( KInitializeFailed, 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 To get the best possible performance, choose 00081 an EGLConfig with a buffersize matching 00082 the current window's display mode*/ 00083 TDisplayMode DMode = Window().DisplayMode(); 00084 TInt BufferSize = 0; 00085 00086 switch ( DMode ) 00087 { 00088 case(EColor4K): 00089 BufferSize = 12; 00090 break; 00091 case(EColor64K): 00092 BufferSize = 16; 00093 break; 00094 case(EColor16M): 00095 BufferSize = 24; 00096 break; 00097 case(EColor16MU): 00098 BufferSize = 32; 00099 break; 00100 default: 00101 _LIT(KDModeError, "unsupported displaymode"); 00102 User::Panic( KDModeError, 0 ); 00103 break; 00104 } 00105 00106 // Define properties for the wanted EGLSurface 00107 const EGLint attrib_list[] = { EGL_BUFFER_SIZE,BufferSize, 00108 EGL_DEPTH_SIZE,16, // 16-bit depthbuffer 00109 EGL_NONE }; 00110 00111 // Choose an EGLConfig that best matches to the properties in attrib_list 00112 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, 00113 &numOfConfigs ) == EGL_FALSE ) 00114 { 00115 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00116 User::Panic( KChooseConfigFailed, 0 ); 00117 } 00118 00119 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00120 // returned by eglChooseConfig are sorted so 00121 // that the best matching EGLConfig is first in 00122 // the list. 00123 User::Free( configList ); // Free configList, not used anymore. 00124 00125 // Create a window where the graphics are blitted 00126 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00127 if ( iEglSurface == NULL ) 00128 { 00129 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00130 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00131 } 00132 00133 // Create a rendering context 00134 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00135 if ( iEglContext == NULL ) 00136 { 00137 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00138 User::Panic( KCreateContextFailed, 0 ); 00139 } 00140 00141 /* Make the context current. Binds context to the current rendering thread 00142 and surface.*/ 00143 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00144 == EGL_FALSE ) 00145 { 00146 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00147 User::Panic( KMakeCurrentFailed, 0 ); 00148 } 00149 00150 TSize size; 00151 size = this->Size(); 00152 00153 iShadows = CShadows::NewL( size.iWidth, size.iHeight ); 00154 iShadows->AppInit(); 00155 00156 iOpenGlInitialized = ETrue; 00157 00158 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00159 // animating the scene 00160 iPeriodic->Start( 100, 100, TCallBack( DrawCallBack, this ) ); 00161 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CShadow to do the rendering for each frame.
Definition at line 250 of file ShadowsContainer.cpp. References CShadows::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iShadows. 00251 { 00252 CShadowsContainer* instance = (CShadowsContainer*) aInstance; 00253 instance->iFrame++; 00254 00255 // Call the main OpenGL ES Symbian rendering 'loop' 00256 instance->iShadows->AppCycle( instance->iFrame ); 00257 00258 // Call eglSwapBuffers, which blit the graphics to the window 00259 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00260 00261 // To keep the background light on 00262 if ( !(instance->iFrame%100) ) 00263 { 00264 User::ResetInactivityTime(); 00265 } 00266 00267 /* Suspend the current thread for a short while. Give some time 00268 to other threads and AOs, avoids the ViewSrv error in ARMI and 00269 THUMB release builds. One may try to decrease the callback 00270 function instead of this. */ 00271 if ( !(instance->iFrame%50) ) 00272 { 00273 User::After(0); 00274 } 00275 return 0; 00276 }
|
|
|
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 188 of file ShadowsContainer.cpp. References iOpenGlInitialized, iShadows, and CShadows::SetScreenSize(). 00189 { 00190 if( iOpenGlInitialized && iShadows ) 00191 { 00192 TSize size; 00193 size = this->Size(); 00194 00195 iShadows->SetScreenSize( size.iWidth, size.iHeight ); 00196 } 00197 }
|
|
|
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 207 of file ShadowsContainer.cpp. 00208 { 00209 switch( aType ) 00210 { 00211 case KEikDynamicLayoutVariantSwitch: 00212 SetExtentToWholeScreen(); 00213 break; 00214 } 00215 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 221 of file ShadowsContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 230 of file ShadowsContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 239 of file ShadowsContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 282 of file ShadowsContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 101 of file ShadowsContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 104 of file ShadowsContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 107 of file ShadowsContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 110 of file ShadowsContainer.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 116 of file ShadowsContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 119 of file ShadowsContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 124 of file ShadowsContainer.h. |
|
© Nokia 2006 |