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

Definition at line 29 of file Mipmappingcontainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CMipmappingContainer () |
Static Public Member Functions |
|
| static TInt | DrawCallBack (TAny *aInstance) |
| static TTime | GetTimeTick () |
Public Attributes |
|
| CMipmapping * | iMipmapping |
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 |
| TUint32 | iStartTimeTicks |
| TUint32 | iLastFrameTimeSecs |
| TReal | iSecondsPerFrame |
| TInt | iFrame |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CMipmapping and uninitializes OpenGL ES. Definition at line 210 of file Mipmappingcontainer.cpp. References CMipmapping::AppExit(), iEglContext, iEglDisplay, iEglSurface, iMipmapping, and iPeriodic. 00211 { 00212 delete iPeriodic; 00213 00214 /* AppExit call is made to release any allocations made in AppInit. 00215 This call has to be made here before we destroy the rendering context. */ 00216 if ( iMipmapping ) 00217 { 00218 iMipmapping->AppExit(); 00219 delete iMipmapping; 00220 } 00221 00222 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00223 eglDestroySurface( iEglDisplay, iEglSurface ); 00224 eglDestroyContext( iEglDisplay, iEglContext ); 00225 eglTerminate( iEglDisplay ); 00226 }
|
|
||||||||||||
|
Second phase constructor that can call methods that may leave. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 25 of file Mipmappingcontainer.cpp. References iAppUi, iEglDisplay, and iOpenGlInitialized. Referenced by CMipmappingAppUi::ConstructL(). 00026 { 00027 iAppUi = aAppUi; 00028 // Open GL hasn't been initialized 00029 iOpenGlInitialized = EFalse; 00030 00031 // Create the native window 00032 CreateWindowL(); 00033 00034 // Do not go to full-screen in touch devices. 00035 if (AknLayoutUtils::PenEnabled()) 00036 { 00037 SetRect(aRect); 00038 } 00039 else 00040 { 00041 SetExtentToWholeScreen(); // Take the whole screen into use 00042 } 00043 ActivateL(); 00044 00045 // Describes the format, type and size of the color buffers and 00046 // ancillary buffers for EGLSurface 00047 EGLConfig config; 00048 00049 // Get the display for drawing graphics 00050 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00051 if ( iEglDisplay == NULL ) 00052 { 00053 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00054 User::Panic( KGetDisplayFailed, 0 ); 00055 } 00056 00057 // Initialize display 00058 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00059 { 00060 _LIT(KInitializeFailed, "eglInitialize failed"); 00061 User::Panic( KInitializeFailed, 0 ); 00062 } 00063 00064 // Pointer for EGLConfigs 00065 EGLConfig *configList = NULL; 00066 EGLint numOfConfigs = 0; 00067 EGLint configSize = 0; 00068 00069 // Get the number of possible EGLConfigs 00070 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00071 { 00072 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00073 User::Panic( KGetConfigsFailed, 0 ); 00074 } 00075 00076 configSize = numOfConfigs; 00077 00078 // Allocate memory for the configList 00079 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00080 if ( configList == NULL ) 00081 { 00082 _LIT(KConfigAllocFailed, "config alloc failed"); 00083 User::Panic( KConfigAllocFailed, 0 ); 00084 } 00085 00086 // Define properties for the wanted EGLSurface. To get the best possible 00087 // performance, choose an EGLConfig with a buffersize matching the current 00088 // window's display mode 00089 TDisplayMode DMode = Window().DisplayMode(); 00090 TInt BufferSize = 0; 00091 00092 switch(DMode) 00093 { 00094 case(EColor4K): 00095 BufferSize = 12; 00096 break; 00097 case(EColor64K): 00098 BufferSize = 16; 00099 break; 00100 case(EColor16M): 00101 BufferSize = 24; 00102 break; 00103 case(EColor16MU): 00104 case(EColor16MA): 00105 BufferSize = 32; 00106 break; 00107 default: 00108 _LIT(KDModeError, "unsupported displaymode"); 00109 User::Panic( KDModeError, 0 ); 00110 break; 00111 } 00112 00113 // Define properties for requesting a full-screen antialiased window surface 00114 const EGLint attrib_list_fsaa[] = 00115 { 00116 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00117 EGL_BUFFER_SIZE, BufferSize, 00118 EGL_DEPTH_SIZE, 16, 00119 EGL_SAMPLE_BUFFERS, 1, 00120 EGL_SAMPLES, 4, 00121 EGL_NONE 00122 }; 00123 00124 // Define properties for requesting a non-antialiased window surface 00125 const EGLint attrib_list[] = 00126 { 00127 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00128 EGL_BUFFER_SIZE, BufferSize, 00129 EGL_DEPTH_SIZE, 16, 00130 EGL_NONE 00131 }; 00132 00133 // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa 00134 if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00135 { 00136 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00137 User::Panic( KChooseConfigFailed, 0 ); 00138 } 00139 00140 // Check if no configurations were found 00141 if ( numOfConfigs == 0 ) 00142 { 00143 // No configs with antialising were found. Try to get the non-antialiased config 00144 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00145 { 00146 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00147 User::Panic( KChooseConfigFailed, 0 ); 00148 } 00149 00150 if ( numOfConfigs == 0 ) 00151 { 00152 // No configs found without antialiasing 00153 _LIT( KNoConfig, "Can't find the requested config." ); 00154 User::Panic( KNoConfig, 0 ); 00155 } 00156 } 00157 00158 // Choose the best EGLConfig. EGLConfigs returned by eglChooseConfig are 00159 // sorted so that the best matching EGLConfig is first in the list. 00160 config = configList[0]; 00161 00162 // Free configList, as it's not used anymore. 00163 User::Free( configList ); 00164 00165 // Create a window where the graphics are blitted 00166 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00167 if ( iEglSurface == NULL ) 00168 { 00169 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00170 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00171 } 00172 00173 // Create a rendering context 00174 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00175 if ( iEglContext == NULL ) 00176 { 00177 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00178 User::Panic( KCreateContextFailed, 0 ); 00179 } 00180 00181 // Make the context current. Binds context to the current rendering thread 00182 // and surface. 00183 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00184 { 00185 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00186 User::Panic( KMakeCurrentFailed, 0 ); 00187 } 00188 00189 // Reset counters 00190 iFrame = 0; 00191 iStartTimeTicks = User::NTickCount(); 00192 00193 TSize size; 00194 size = this->Size(); 00195 iMipmapping = CMipmapping::NewL( size.iWidth, size.iHeight ); 00196 iMipmapping->AppInitL(); 00197 00198 iOpenGlInitialized = ETrue; 00199 00200 // Create an active object for animating the scene 00201 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); 00202 iPeriodic->Start( 100, 100, TCallBack( CMipmappingContainer::DrawCallBack, this ) ); 00203 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CMipmapping to do the rendering for each frame.
Definition at line 334 of file Mipmappingcontainer.cpp. References CMipmapping::AppCycle(), iEglDisplay, iEglSurface, iFrame, iLastFrameTimeSecs, iMipmapping, and iStartTimeTicks. 00335 { 00336 CMipmappingContainer* instance = (CMipmappingContainer*) aInstance; 00337 00338 // Update the frame counts 00339 instance->iFrame++; 00340 00341 // Compute the elapsed time in seconds since the startup of the example 00342 #ifdef __WINS__ 00343 00344 // In the emulator the tickcount runs at 200Hz 00345 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 200.f; 00346 00347 #else 00348 00349 // In the device the tickcount runs at 1000hz (as intended) 00350 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 1000.f; 00351 00352 #endif 00353 00354 // Compute the elapsed time since last frame was drawn. Note that due to the 00355 // resolution of the system timer this value can be 0.0 even though new frames are being rendered. 00356 // This applies especially when running the emulator on a PC. 00357 GLfloat deltaTimeSecs = instance->iLastFrameTimeSecs - timeSecs; 00358 00359 // Set the current time to be the last frame time for the upcoming frame 00360 instance->iLastFrameTimeSecs = timeSecs; 00361 00362 if ( instance->iMipmapping->GetState() == CMipmapping::ERunning ) 00363 { 00364 // Call the main OpenGL ES Symbian rendering 'loop' 00365 instance->iMipmapping->AppCycle( instance->iFrame, timeSecs, deltaTimeSecs ); 00366 00367 // Call eglSwapBuffers, which blit the graphics to the window 00368 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00369 00370 // Suspend the current thread for a short while. Give some time 00371 // to other threads and AOs, avoids the ViewSrv error in ARMI and 00372 // THUMB release builds. One may try to decrease the callback 00373 // function instead of this. 00374 if ( !(instance->iFrame % 50) ) 00375 { 00376 // Reset inactivity timer to keep the background light on 00377 User::ResetInactivityTime(); 00378 00379 User::After(0); 00380 } 00381 } 00382 00383 return 0; 00384 }
|
|
|
Returns the current system time.
Definition at line 321 of file Mipmappingcontainer.cpp.
|
|
|
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 233 of file Mipmappingcontainer.cpp. References iMipmapping, iOpenGlInitialized, and CMipmapping::SetScreenSize(). 00234 { 00235 if( iOpenGlInitialized && iMipmapping ) 00236 { 00237 TSize size; 00238 size = this->Size(); 00239 00240 iMipmapping->SetScreenSize( size.iWidth, size.iHeight ); 00241 } 00242 }
|
|
|
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 252 of file Mipmappingcontainer.cpp. References iAppUi. 00253 { 00254 switch( aType ) 00255 { 00256 case KEikDynamicLayoutVariantSwitch: 00257 // Do not go full-screen in touch devices. 00258 if (AknLayoutUtils::PenEnabled()) 00259 { 00260 SetRect(iAppUi->ClientRect()); 00261 } 00262 else 00263 { 00264 SetExtentToWholeScreen(); // Take the whole screen into use 00265 } 00266 break; 00267 } 00268 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 275 of file Mipmappingcontainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 284 of file Mipmappingcontainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 293 of file Mipmappingcontainer.cpp. References iMipmapping. 00294 { 00295 CWindowGc& gc = SystemGc(); 00296 gc.Clear( aRect ); 00297 00298 if ( iMipmapping->GetState() == CMipmapping::ELoadingTextures ) 00299 { 00300 _LIT(KLoading, "Loading..."); 00301 utilOutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack ); 00302 } 00303 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 310 of file Mipmappingcontainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 106 of file Mipmappingcontainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CMipmappingContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 108 of file Mipmappingcontainer.h. Referenced by DrawCallBack(), and ~CMipmappingContainer(). |
|
|
OpenGL ES rendering context. Definition at line 110 of file Mipmappingcontainer.h. Referenced by ~CMipmappingContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 112 of file Mipmappingcontainer.h. Referenced by ~CMipmappingContainer(). |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 117 of file Mipmappingcontainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Time when the example started running (rendering frames). Definition at line 120 of file Mipmappingcontainer.h. Referenced by DrawCallBack(). |
|
|
Time when the previous frame was rendered. Definition at line 122 of file Mipmappingcontainer.h. Referenced by DrawCallBack(). |
|
|
Current average seconds per frame. Used to interpolated during frames when the internal clock hasn't updated. Definition at line 124 of file Mipmappingcontainer.h. |
|
|
Counts the number of frames rendered. Definition at line 126 of file Mipmappingcontainer.h. Referenced by DrawCallBack(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 129 of file Mipmappingcontainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 134 of file Mipmappingcontainer.h. Referenced by Draw(), DrawCallBack(), CMipmappingAppUi::HandleCommandL(), SizeChanged(), and ~CMipmappingContainer(). |
|
© Nokia 2009 |