|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <EnvMappingContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CEnvMappingContainer () |
Static Public Member Functions | |
| static int | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| CEnvMapping * | iEnvMapping |
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 |
| TInt | iFrame |
| CPeriodic * | iPeriodic |
| TBool | iOpenGlInitialized |
Definition at line 32 of file EnvMappingContainer.h.
|
|
Destructor. Destroys the CPeriodic, CEnvMapping and uninitializes OpenGL ES. Definition at line 164 of file EnvMappingContainer.cpp. References CEnvMapping::AppExit(), iEglContext, iEglDisplay, iEglSurface, iEnvMapping, and iPeriodic. 00165 { 00166 delete iPeriodic; 00167 00168 /* AppExit call is made to release any allocations made in AppInit. 00169 This call has to be made here before we destroy the rendering context. */ 00170 if ( !(iEnvMapping == NULL) ) 00171 { 00172 iEnvMapping->AppExit(); 00173 delete iEnvMapping; 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 00182 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering.
Definition at line 27 of file EnvMappingContainer.cpp. References iEglDisplay, iFrame, and iOpenGlInitialized. 00028 { 00029 iOpenGlInitialized = EFalse; 00030 CreateWindowL(); 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(KEglGetDisplay, "eglGetDisplay failed"); 00046 User::Panic( KEglGetDisplay, 0 ); 00047 } 00048 00049 /* Initialize display */ 00050 if( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00051 { 00052 _LIT(KEglInitialize, "eglInitialize failed"); 00053 User::Panic( KEglInitialize, 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(KEglGetConfigs, "eglGetconfigs failed"); 00064 User::Panic( KEglGetConfigs, 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(KConfigAlloc, "config alloc failed"); 00074 User::Panic( KConfigAlloc, 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(KEglChooseConfig, "eglChooseConfig failed"); 00115 User::Panic( KEglChooseConfig, 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 00127 if( iEglSurface == NULL ) 00128 { 00129 _LIT(KEglCreateWindow, "eglCreateWindow failed"); 00130 User::Panic( KEglCreateWindow, 0 ); 00131 } 00132 00133 00134 /* Create a rendering context */ 00135 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00136 if( iEglContext == NULL ) 00137 { 00138 _LIT(KEglCreateContext, "eglCreateContext failed"); 00139 User::Panic( KEglCreateContext, 0 ); 00140 } 00141 00142 /* Make the context current. Binds context to the current rendering thread 00143 and surface.*/ 00144 if( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00145 { 00146 _LIT(KEglMakeCurrent, "eglMakeCurrent failed"); 00147 User::Panic( KEglMakeCurrent, 0 ); 00148 } 00149 00150 TSize size; 00151 size = this->Size(); 00152 00153 iEnvMapping = CEnvMapping::NewL( size.iWidth, size.iHeight ); 00154 iEnvMapping->AppInitL(); 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( CEnvMappingContainer::DrawCallBack, this ) ); 00161 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CEnvMapping to do the rendering for each frame.
Definition at line 233 of file EnvMappingContainer.cpp. References CEnvMapping::AppCycle(), iEglDisplay, iEglSurface, iEnvMapping, and iFrame. 00234 { 00235 CEnvMappingContainer* instance = (CEnvMappingContainer*) aInstance; 00236 00237 if ( instance->iEnvMapping->GetState() == CEnvMapping::ERunning ) 00238 { 00239 instance->iFrame++; 00240 00241 /* Call the main OpenGL ES Symbian rendering 'loop' */ 00242 instance->iEnvMapping->AppCycle( instance->iFrame ); 00243 00244 /* Call eglSwapBuffers, which blit the graphics to the window */ 00245 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00246 00247 /* To keep the background light on */ 00248 if(!(instance->iFrame%100)) 00249 { 00250 User::ResetInactivityTime(); 00251 } 00252 00253 /* Suspend the current thread for a short while. Give some time 00254 to other threads and AOs, avoids the ViewSrv error in ARMI and 00255 THUMB release builds. One may try to decrease the callback 00256 function instead of this. */ 00257 if(!(instance->iFrame%50)) 00258 { 00259 User::After(0); 00260 } 00261 } 00262 00263 return 0; 00264 }
|
|
|
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 189 of file EnvMappingContainer.cpp. References iEnvMapping, iOpenGlInitialized, and CEnvMapping::SetScreenSize(). 00190 { 00191 if( iOpenGlInitialized && iEnvMapping ) 00192 { 00193 TSize size; 00194 size = this->Size(); 00195 00196 iEnvMapping->SetScreenSize( size.iWidth, size.iHeight ); 00197 } 00198 }
|
|
|
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 283 of file EnvMappingContainer.cpp. 00284 { 00285 switch( aType ) 00286 { 00287 case KEikDynamicLayoutVariantSwitch: 00288 SetExtentToWholeScreen(); 00289 break; 00290 } 00291 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 204 of file EnvMappingContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 213 of file EnvMappingContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 222 of file EnvMappingContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 271 of file EnvMappingContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 102 of file EnvMappingContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 105 of file EnvMappingContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 108 of file EnvMappingContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 111 of file EnvMappingContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 114 of file EnvMappingContainer.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 120 of file EnvMappingContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 125 of file EnvMappingContainer.h. |
|
© Nokia 2006 |