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

Definition at line 31 of file BillboardContainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CBillboardContainer () |
Static Public Member Functions |
|
| static TInt | DrawCallBack (TAny *aInstance) |
| static TTime | GetTimeTick () |
Public Attributes |
|
| CBillboard * | iBillboard |
Private Member Functions |
|
| TKeyResponse | OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType) |
| void | HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType) |
| void | SizeChanged () |
| void | HandleResourceChange (TInt aType) |
| TInt | CountComponentControls () const |
| CCoeControl * | ComponentControl (TInt aIndex) const |
| void | Draw (const TRect &aRect) const |
Private Attributes |
|
| EGLDisplay | iEglDisplay |
| EGLSurface | iEglSurface |
| EGLContext | iEglContext |
| CPeriodic * | iPeriodic |
| TBool | iOpenGlInitialized |
| TUint | iStartTimeTicks |
| GLfloat | iLastFrameTimeSecs |
| TUint | iFrame |
| CBillboardInput * | iInputHandler |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CBillboard and uninitializes OpenGL ES. Definition at line 242 of file BillboardContainer.cpp. References CBillboard::AppExit(), iBillboard, iEglContext, iEglDisplay, iEglSurface, iInputHandler, and iPeriodic. 00243 { 00244 delete iPeriodic; 00245 00246 /* AppExit call is made to release any allocations made in AppInit. 00247 This call has to be made here before we destroy the rendering context. */ 00248 if ( iBillboard ) 00249 { 00250 iBillboard->AppExit(); 00251 delete iBillboard; 00252 } 00253 00254 delete iInputHandler; 00255 00256 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00257 eglDestroySurface( iEglDisplay, iEglSurface ); 00258 eglDestroyContext( iEglDisplay, iEglContext ); 00259 eglTerminate( iEglDisplay ); 00260 }
|
|
||||||||||||
|
Second phase constructor that can call methods that may leave. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 24 of file BillboardContainer.cpp. References iAppUi, iEglDisplay, iInputHandler, iOpenGlInitialized, and CBillboardInput::NewL(). Referenced by CBillboardAppUi::ConstructL(). 00025 { 00026 iAppUi = aAppUi; 00027 // Open GL hasn't been initialized 00028 iOpenGlInitialized = EFalse; 00029 // Create the input handler 00030 iInputHandler = CBillboardInput::NewL(); 00031 00032 // Create the native window 00033 CreateWindowL(); 00034 00035 // Do not go to full-screen in touch devices. 00036 if (AknLayoutUtils::PenEnabled()) 00037 { 00038 SetRect(aRect); 00039 } 00040 else 00041 { 00042 SetExtentToWholeScreen(); // Take the whole screen into use 00043 } 00044 ActivateL(); 00045 00046 // Describes the format, type and size of the color buffers and 00047 // ancillary buffers for EGLSurface 00048 EGLConfig config; 00049 00050 // Get the display for drawing graphics 00051 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00052 if ( iEglDisplay == NULL ) 00053 { 00054 _LIT( KGetDisplayFailed, "eglGetDisplay failed" ); 00055 User::Panic( KGetDisplayFailed, 0 ); 00056 } 00057 00058 // Initialize display 00059 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00060 { 00061 _LIT( KInitializeFailed, "eglInitialize failed" ); 00062 User::Panic( KInitializeFailed, 0 ); 00063 } 00064 00065 // Pointer for EGLConfigs 00066 EGLConfig *configList = NULL; 00067 EGLint numOfConfigs = 0; 00068 EGLint configSize = 0; 00069 00070 // Get the number of possible EGLConfigs 00071 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00072 { 00073 _LIT( KGetConfigsFailed, "eglGetConfigs failed" ); 00074 User::Panic( KGetConfigsFailed, 0 ); 00075 } 00076 00077 configSize = numOfConfigs; 00078 00079 // Allocate memory for the configList 00080 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00081 if ( configList == NULL ) 00082 { 00083 _LIT( KConfigAllocFailed, "config alloc failed" ); 00084 User::Panic( KConfigAllocFailed, 0 ); 00085 } 00086 00087 // Define properties for the wanted EGLSurface 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 // Choose the best EGLConfig. EGLConfigs returned by eglChooseConfig are 00158 // sorted so that the best matching EGLConfig is first in the list. 00159 config = configList[0]; 00160 00161 // Free configList, as it's not used anymore. 00162 User::Free( configList ); 00163 00164 // Create a window where the graphics are blitted 00165 iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL ); 00166 if ( iEglSurface == NULL ) 00167 { 00168 _LIT( KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed" ); 00169 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00170 } 00171 00172 // Create a rendering context 00173 iEglContext = eglCreateContext( iEglDisplay, config, EGL_NO_CONTEXT, NULL ); 00174 if ( iEglContext == NULL ) 00175 { 00176 _LIT( KCreateContextFailed, "eglCreateContext failed" ); 00177 User::Panic( KCreateContextFailed, 0 ); 00178 } 00179 00180 // Make the context current. Binds context to the current rendering thread 00181 // and surface. 00182 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00183 { 00184 _LIT( KMakeCurrentFailed, "eglMakeCurrent failed" ); 00185 User::Panic( KMakeCurrentFailed, 0 ); 00186 } 00187 00188 00189 TSize size = this->Size(); 00190 iBillboard = CBillboard::NewL( size.iWidth, size.iHeight, iInputHandler ); 00191 iBillboard->AppInitL(); 00192 00193 iOpenGlInitialized = ETrue; 00194 00195 // Initialize timers and counters 00196 iFrame = 0; 00197 iStartTimeTicks = User::NTickCount(); 00198 00199 #ifdef __WINS__ 00200 00201 // In the emulator the tickcount runs at 200Hz 00202 iLastFrameTimeSecs = ( (GLfloat) iStartTimeTicks ) / 200.f; 00203 00204 #else 00205 00206 // In the device the tickcount runs at 1000hz (as intended) 00207 iLastFrameTimeSecs = ( (GLfloat) iStartTimeTicks ) / 1000.f; 00208 00209 #endif 00210 00211 // Create an active object for animating the scene 00212 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); 00213 iPeriodic->Start( 100, 100, TCallBack( CBillboardContainer::DrawCallBack, this ) ); 00214 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CBillboard to do the rendering for each frame.
Definition at line 368 of file BillboardContainer.cpp. References CBillboard::AppCycle(), iBillboard, iEglDisplay, iEglSurface, iFrame, iLastFrameTimeSecs, and iStartTimeTicks. 00369 { 00370 // Cast parameter to container instance 00371 CBillboardContainer* instance = (CBillboardContainer*) aInstance; 00372 00373 // Update the frame counts 00374 instance->iFrame++; 00375 00376 // Compute the elapsed time in seconds since the startup of the example 00377 #ifdef __WINS__ 00378 00379 // In the emulator the tickcount runs at 200Hz 00380 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 200.f; 00381 00382 #else 00383 00384 // In the device the tickcount runs at 1000hz (as intended) 00385 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 1000.f; 00386 00387 #endif 00388 00389 // Compute the elapsed time since last frame was drawn. Note that due to the 00390 // resolution of the system timer this value can be 0.0 even though new frames are being rendered. 00391 // This applies especially when running the emulator on a PC. 00392 GLfloat deltaTimeSecs = timeSecs - instance->iLastFrameTimeSecs; 00393 00394 // Set the current time to be the last frame time for the upcoming frame 00395 instance->iLastFrameTimeSecs = timeSecs; 00396 00397 if ( instance->iBillboard->GetState() == CBillboard::ERunning ) 00398 { 00399 // Call the main OpenGL ES Symbian rendering 'loop' 00400 instance->iBillboard->AppCycle( instance->iFrame, timeSecs, deltaTimeSecs ); 00401 00402 // Call eglSwapBuffers, which blit the graphics to the window 00403 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00404 00405 if ( !(instance->iFrame % 50 ) ) 00406 { 00407 // Reset inactivity timer to keep the background light on 00408 User::ResetInactivityTime(); 00409 00410 // Suspend the current thread for a short while. Give some time 00411 // to other threads and AOs, avoids the ViewSrv error in ARMI and 00412 // THUMB release builds. One may try to decrease the callback 00413 // function instead of this. 00414 User::After( 0 ); 00415 } 00416 } 00417 00418 return 0; 00419 }
|
|
|
Returns the current system time.
Definition at line 355 of file BillboardContainer.cpp.
|
|
||||||||||||
|
Handles joystick movements and other key presses.
Definition at line 221 of file BillboardContainer.cpp. References iInputHandler, and CBillboardInput::KeyDown(). 00222 { 00223 switch( aType ) 00224 { 00225 case EEventKeyDown: 00226 { 00227 return iInputHandler->KeyDown( aKeyEvent.iScanCode ); 00228 } 00229 case EEventKeyUp: 00230 { 00231 return iInputHandler->KeyUp( aKeyEvent.iScanCode ); 00232 } 00233 } 00234 return EKeyWasNotConsumed; 00235 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 344 of file BillboardContainer.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 267 of file BillboardContainer.cpp. References iBillboard, iOpenGlInitialized, and CBillboard::SetScreenSize(). 00268 { 00269 if( iOpenGlInitialized && iBillboard ) 00270 { 00271 // If example is running and OpenGL ES is initialized 00272 // notify it of the screen size change 00273 TSize size = this->Size(); 00274 iBillboard->SetScreenSize( size.iWidth, size.iHeight ); 00275 } 00276 }
|
|
|
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 286 of file BillboardContainer.cpp. References iAppUi. 00287 { 00288 switch( aType ) 00289 { 00290 case KEikDynamicLayoutVariantSwitch: 00291 // Do not go full-screen in touch devices. 00292 if (AknLayoutUtils::PenEnabled()) 00293 { 00294 SetRect(iAppUi->ClientRect()); 00295 } 00296 else 00297 { 00298 SetExtentToWholeScreen(); // Take the whole screen into use 00299 } 00300 break; 00301 } 00302 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 309 of file BillboardContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 318 of file BillboardContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 327 of file BillboardContainer.cpp. References iBillboard. 00328 { 00329 CWindowGc& gc = SystemGc(); 00330 gc.Clear( aRect ); 00331 00332 if ( iBillboard->GetState() == CBillboard::ELoadingTextures ) 00333 { 00334 _LIT(KLoading, "Loading..."); 00335 utilOutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack ); 00336 } 00337 }
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 116 of file BillboardContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CBillboardContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 118 of file BillboardContainer.h. Referenced by DrawCallBack(), and ~CBillboardContainer(). |
|
|
OpenGL ES rendering context. Definition at line 120 of file BillboardContainer.h. Referenced by ~CBillboardContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 122 of file BillboardContainer.h. Referenced by ~CBillboardContainer(). |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 127 of file BillboardContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Time (int ticks) when the example started running (rendering frames). Definition at line 130 of file BillboardContainer.h. Referenced by DrawCallBack(). |
|
|
Time (in seconds) when the previous frame was rendered. Definition at line 132 of file BillboardContainer.h. Referenced by DrawCallBack(). |
|
|
Counts the number of frames rendered. Definition at line 134 of file BillboardContainer.h. Referenced by DrawCallBack(). |
|
|
Input handler that maps keycodes to inputs and stores the current state for each key. Definition at line 136 of file BillboardContainer.h. Referenced by ConstructL(), OfferKeyEventL(), and ~CBillboardContainer(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 139 of file BillboardContainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 144 of file BillboardContainer.h. Referenced by Draw(), DrawCallBack(), SizeChanged(), and ~CBillboardContainer(). |
|
© Nokia 2009 |