|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <SimpleLightContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CSimpleLightContainer () |
Static Public Member Functions | |
| static int | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| TInt | iFrame |
| CSimpleLight * | iSimpleLight |
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 SimpleLightContainer.h.
|
|
Destructor. Destroys the CPeriodic, CSimpleLight and uninitializes OpenGL ES. Definition at line 165 of file SimpleLightContainer.cpp. References CSimpleLight::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iSimpleLight. 00166 { 00167 delete iPeriodic; 00168 00169 if ( iSimpleLight ) 00170 { 00171 iSimpleLight->AppExit(); 00172 delete iSimpleLight; 00173 } 00174 00175 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00176 eglDestroySurface( iEglDisplay, iEglSurface ); 00177 eglDestroyContext( iEglDisplay, iEglContext ); 00178 eglTerminate( iEglDisplay ); // Release resources associated 00179 // with EGL and OpenGL ES 00180 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES and creates the rendering context.
Definition at line 27 of file SimpleLightContainer.cpp. References CSimpleLight::AppInit(), DrawCallBack(), iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iSimpleLight, and CSimpleLight::NewL(). 00028 { 00029 CreateWindowL(); 00030 iOpenGlInitialized = EFalse; 00031 00032 SetExtentToWholeScreen(); // Take the whole screen into use 00033 ActivateL(); 00034 00035 iFrame = 0; // 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( EGL_DEFAULT_DISPLAY ); 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 ) 00062 == 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 // Define properties for the wanted EGLSurface 00106 const EGLint attrib_list[] = { EGL_BUFFER_SIZE,BufferSize, 00107 EGL_DEPTH_SIZE,16, // 16-bit depthbuffer 00108 EGL_NONE }; 00109 00110 // Choose an EGLConfig that best matches to the properties in attrib_list 00111 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, 00112 &numOfConfigs ) == EGL_FALSE ) 00113 { 00114 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00115 User::Panic( KChooseConfigFailed, 0 ); 00116 } 00117 00118 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00119 // returned by eglChooseConfig are sorted so 00120 // that the best matching EGLConfig is first in 00121 // the list. 00122 User::Free( configList ); // Free configList, not used anymore. 00123 00124 // Create a window where the graphics are blitted 00125 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00126 if ( iEglSurface == NULL ) 00127 { 00128 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00129 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00130 } 00131 00132 // Create a rendering context 00133 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00134 if ( iEglContext == NULL ) 00135 { 00136 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00137 User::Panic( KCreateContextFailed, 0 ); 00138 } 00139 00140 /* Make the context current. Binds context to the current rendering thread 00141 and surface.*/ 00142 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00143 == EGL_FALSE ) 00144 { 00145 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00146 User::Panic( KMakeCurrentFailed, 0 ); 00147 } 00148 00149 00150 TSize size; 00151 size = this->Size(); 00152 00153 iSimpleLight = CSimpleLight::NewL( size.iWidth, size.iHeight ); // Create an instance of SimpleLight 00154 iSimpleLight->AppInit(); // Initialize OpenGL ES 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, 00161 TCallBack( CSimpleLightContainer::DrawCallBack, this ) ); 00162 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CSimpleLight to do the rendering for each frame.
Definition at line 248 of file SimpleLightContainer.cpp. References CSimpleLight::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iSimpleLight. 00249 { 00250 CSimpleLightContainer* instance = (CSimpleLightContainer*) aInstance; 00251 instance->iFrame++; 00252 00253 // Call the main OpenGL ES Symbian rendering 'loop' 00254 instance->iSimpleLight->AppCycle( instance->iFrame ); 00255 00256 // Call eglSwapBuffers, which blit the graphics to the window 00257 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00258 00259 // To keep the background light on 00260 if ( !(instance->iFrame%100) ) 00261 { 00262 User::ResetInactivityTime(); 00263 } 00264 00265 /* Suspend the current thread for a short while. Give some time 00266 to other threads and AOs, avoids the ViewSrv error in ARMI and 00267 THUMB release builds. One may try to decrease the callback 00268 function instead of this. */ 00269 if ( !(instance->iFrame%50) ) 00270 { 00271 User::After(0); 00272 } 00273 00274 return 0; 00275 }
|
|
|
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 187 of file SimpleLightContainer.cpp. References iOpenGlInitialized, iSimpleLight, and CSimpleLight::SetScreenSize(). 00188 { 00189 if( iOpenGlInitialized && iSimpleLight ) 00190 { 00191 TSize size; 00192 size = this->Size(); 00193 00194 iSimpleLight->SetScreenSize( size.iWidth, size.iHeight ); 00195 } 00196 }
|
|
|
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 206 of file SimpleLightContainer.cpp. 00207 { 00208 switch( aType ) 00209 { 00210 case KEikDynamicLayoutVariantSwitch: 00211 SetExtentToWholeScreen(); 00212 break; 00213 } 00214 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 220 of file SimpleLightContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 229 of file SimpleLightContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 238 of file SimpleLightContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 282 of file SimpleLightContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 101 of file SimpleLightContainer.h. |
|
|
Window surface that is the target of OpenGL ES graphics rendering. Definition at line 104 of file SimpleLightContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 107 of file SimpleLightContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 110 of file SimpleLightContainer.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 SimpleLightContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 121 of file SimpleLightContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 124 of file SimpleLightContainer.h. |
|
© Nokia 2006 |