|
Nokia N97 SDK Example Applications Guide |
#include <SimpleCubeContainer.h>
Inheritance diagram for CSimpleCubeContainer:

Definition at line 29 of file SimpleCubeContainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CSimpleCubeContainer () |
Static Public Member Functions |
|
| static TInt | DrawCallBack (TAny *aInstance) |
Public Attributes |
|
| CSimpleCube * | iSimpleCube |
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 |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CSimpleCube and uninitializes OpenGL ES. Definition at line 205 of file SimpleCubeContainer.cpp. References CSimpleCube::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iSimpleCube. 00206 { 00207 delete iPeriodic; 00208 00209 /* AppExit call is made to release 00210 any allocations made in AppInit. */ 00211 if ( iSimpleCube ) 00212 { 00213 iSimpleCube->AppExit(); 00214 delete iSimpleCube; 00215 } 00216 00217 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00218 eglDestroySurface( iEglDisplay, iEglSurface ); 00219 eglDestroyContext( iEglDisplay, iEglContext ); 00220 eglTerminate( iEglDisplay ); // Release resources associated 00221 // with EGL and OpenGL ES 00222 }
|
|
||||||||||||
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 24 of file SimpleCubeContainer.cpp. References CSimpleCube::AppInit(), DrawCallBack(), iAppUi, iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iSimpleCube, and CSimpleCube::NewL(). Referenced by CSimpleCubeAppUi::ConstructL(). 00025 { 00026 iAppUi = aAppUi; 00027 iOpenGlInitialized = EFalse; 00028 CreateWindowL(); 00029 00030 // Do not go to full-screen in touch devices. 00031 if (AknLayoutUtils::PenEnabled()) 00032 { 00033 SetRect(aRect); 00034 } 00035 else 00036 { 00037 SetExtentToWholeScreen(); // Take the whole screen into use 00038 } 00039 ActivateL(); 00040 00041 iFrame = 0; // Initialize frame counter 00042 00043 EGLConfig Config; // Describes the format, type and 00044 // size of the color buffers and 00045 // ancillary buffers for EGLSurface 00046 00047 // Get the display for drawing graphics 00048 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00049 if ( iEglDisplay == NULL ) 00050 { 00051 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00052 User::Panic( KGetDisplayFailed, 0 ); 00053 } 00054 00055 // Initialize display 00056 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00057 { 00058 _LIT(KInitializeFailed, "eglInitialize failed"); 00059 User::Panic( KInitializeFailed, 0 ); 00060 } 00061 00062 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00063 EGLint numOfConfigs = 0; 00064 EGLint configSize = 0; 00065 00066 // Get the number of possible EGLConfigs 00067 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 00068 == EGL_FALSE ) 00069 { 00070 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00071 User::Panic( KGetConfigsFailed, 0 ); 00072 } 00073 00074 configSize = numOfConfigs; 00075 00076 // Allocate memory for the configList 00077 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00078 if ( configList == NULL ) 00079 { 00080 _LIT(KConfigAllocFailed, "config alloc failed"); 00081 User::Panic( KConfigAllocFailed, 0 ); 00082 } 00083 00084 /* Define properties for the wanted EGLSurface. 00085 To get the best possible performance, choose 00086 an EGLConfig with a buffersize matching 00087 the current window's display mode*/ 00088 TDisplayMode DMode = Window().DisplayMode(); 00089 TInt BufferSize = 0; 00090 00091 switch ( DMode ) 00092 { 00093 case(EColor4K): 00094 BufferSize = 12; 00095 break; 00096 case(EColor64K): 00097 BufferSize = 16; 00098 break; 00099 case(EColor16M): 00100 BufferSize = 24; 00101 break; 00102 case(EColor16MU): 00103 case(EColor16MA): 00104 BufferSize = 32; 00105 break; 00106 default: 00107 _LIT(KDModeError, "unsupported displaymode"); 00108 User::Panic( KDModeError, 0 ); 00109 break; 00110 } 00111 00112 // Define properties for requesting a full-screen antialiased window surface 00113 const EGLint attrib_list_fsaa[] = 00114 { 00115 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00116 EGL_BUFFER_SIZE, BufferSize, 00117 EGL_DEPTH_SIZE, 16, 00118 EGL_SAMPLE_BUFFERS, 1, 00119 EGL_SAMPLES, 4, 00120 EGL_NONE 00121 }; 00122 00123 // Define properties for requesting a non-antialiased window surface 00124 const EGLint attrib_list[] = 00125 { 00126 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00127 EGL_BUFFER_SIZE, BufferSize, 00128 EGL_DEPTH_SIZE, 16, 00129 EGL_NONE 00130 }; 00131 00132 // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa 00133 if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00134 { 00135 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00136 User::Panic( KChooseConfigFailed, 0 ); 00137 } 00138 00139 // Check if no configurations were found 00140 if ( numOfConfigs == 0 ) 00141 { 00142 // No configs with antialising were found. Try to get the non-antialiased config 00143 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00144 { 00145 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00146 User::Panic( KChooseConfigFailed, 0 ); 00147 } 00148 00149 if ( numOfConfigs == 0 ) 00150 { 00151 // No configs found without antialiasing 00152 _LIT( KNoConfig, "Can't find the requested config." ); 00153 User::Panic( KNoConfig, 0 ); 00154 } 00155 } 00156 00157 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00158 // returned by eglChooseConfig are sorted so 00159 // that the best matching EGLConfig is first in 00160 // the list. 00161 User::Free( configList ); // Free configList, not used anymore. 00162 00163 // Create a window where the graphics are blitted 00164 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00165 if ( iEglSurface == NULL ) 00166 { 00167 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00168 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00169 } 00170 00171 // Create a rendering context 00172 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00173 if ( iEglContext == NULL ) 00174 { 00175 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00176 User::Panic( KCreateContextFailed, 0 ); 00177 } 00178 00179 /* Make the context current. Binds context to the current rendering thread 00180 and surface.*/ 00181 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00182 == EGL_FALSE ) 00183 { 00184 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00185 User::Panic( KMakeCurrentFailed, 0 ); 00186 } 00187 00188 00189 TSize size; 00190 size = this->Size(); 00191 00192 iSimpleCube = CSimpleCube::NewL( size.iWidth, size.iHeight ); // Create an instance of SimpleCube 00193 iSimpleCube->AppInit(); // Initialize OpenGL ES 00194 00195 iOpenGlInitialized = ETrue; 00196 00197 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00198 // animating the scene 00199 iPeriodic->Start( 100, 100, 00200 TCallBack( CSimpleCubeContainer::DrawCallBack, this ) ); 00201 00202 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CSimpleCube to do the rendering for each frame.
Definition at line 298 of file SimpleCubeContainer.cpp. References CSimpleCube::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iSimpleCube. Referenced by ConstructL(). 00299 { 00300 CSimpleCubeContainer* instance = (CSimpleCubeContainer*) aInstance; 00301 instance->iFrame++; 00302 00303 // Call the main OpenGL ES Symbian rendering 'loop' 00304 instance->iSimpleCube->AppCycle( instance->iFrame ); 00305 00306 // Call eglSwapBuffers, which blit the graphics to the window 00307 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00308 00309 // To keep the background light on 00310 if ( !(instance->iFrame%100) ) 00311 { 00312 User::ResetInactivityTime(); 00313 } 00314 00315 /* Suspend the current thread for a short while. Give some time 00316 to other threads and AOs, avoids the ViewSrv error in ARMI and 00317 THUMB release builds. One may try to decrease the callback 00318 function instead of this. */ 00319 if ( !(instance->iFrame%50) ) 00320 { 00321 User::After(0); 00322 } 00323 00324 return 0; 00325 }
|
|
|
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 229 of file SimpleCubeContainer.cpp. References iOpenGlInitialized, iSimpleCube, and CSimpleCube::SetScreenSize(). 00230 { 00231 if( iOpenGlInitialized && iSimpleCube ) 00232 { 00233 TSize size; 00234 size = this->Size(); 00235 00236 iSimpleCube->SetScreenSize( size.iWidth, size.iHeight ); 00237 } 00238 }
|
|
|
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 248 of file SimpleCubeContainer.cpp. References iAppUi. 00249 { 00250 switch( aType ) 00251 { 00252 case KEikDynamicLayoutVariantSwitch: 00253 // Do not go full-screen in touch devices. 00254 if (AknLayoutUtils::PenEnabled()) 00255 { 00256 SetRect(iAppUi->ClientRect()); 00257 } 00258 else 00259 { 00260 SetExtentToWholeScreen(); // Take the whole screen into use 00261 } 00262 break; 00263 } 00264 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 270 of file SimpleCubeContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 279 of file SimpleCubeContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 288 of file SimpleCubeContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 332 of file SimpleCubeContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 99 of file SimpleCubeContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CSimpleCubeContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 102 of file SimpleCubeContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CSimpleCubeContainer(). |
|
|
OpenGL ES rendering context. Definition at line 105 of file SimpleCubeContainer.h. Referenced by ConstructL(), and ~CSimpleCubeContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 108 of file SimpleCubeContainer.h. Referenced by ConstructL(), and ~CSimpleCubeContainer(). |
|
|
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 SimpleCubeContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Frame counter variable, used in the animation. Definition at line 117 of file SimpleCubeContainer.h. Referenced by ConstructL(), and DrawCallBack(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 120 of file SimpleCubeContainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 125 of file SimpleCubeContainer.h. Referenced by ConstructL(), DrawCallBack(), CSimpleCubeAppUi::HandleCommandL(), SizeChanged(), and ~CSimpleCubeContainer(). |
|
© Nokia 2009 |