|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : PickSelectContainer.cpp 00004 * Part of : OpenGLEx / PickSelect 00005 * 00006 * Copyright (c) 2004-2006 Nokia Corporation. 00007 * This material, including documentation and any related 00008 * computer programs, is protected by copyright controlled by 00009 * Nokia Corporation. 00010 * ============================================================================== 00011 */ 00012 00013 // INCLUDE FILES 00014 #include "PickSelectContainer.h" 00015 #include <AknUtils.h> // Pen support. 00016 00017 // ================= MEMBER FUNCTIONS ======================= 00018 00019 // --------------------------------------------------------- 00020 // CPickSelectContainer::ConstructL(const TRect& aRect) 00021 // EPOC two phased constructor 00022 // --------------------------------------------------------- 00023 // 00024 void CPickSelectContainer::ConstructL(const TRect& aRect, CAknAppUi* aAppUi) 00025 { 00026 iAppUi = aAppUi; 00027 iOpenGlInitialized = EFalse; 00028 00029 CreateWindowL(); 00030 00031 // Do not go to full-screen in touch devices. 00032 if (AknLayoutUtils::PenEnabled()) 00033 { 00034 SetRect(aRect); 00035 } 00036 else 00037 { 00038 SetExtentToWholeScreen(); // Take the whole screen into use 00039 } 00040 ActivateL(); 00041 00042 iFrame = 0; // Frame counter 00043 00044 EGLConfig Config; // Describes the format, type and 00045 // size of the color buffers and 00046 // ancillary buffers for EGLSurface 00047 00048 // Get the display for drawing graphics 00049 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00050 if ( iEglDisplay == NULL ) 00051 { 00052 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00053 User::Panic( KGetDisplayFailed, 0 ); 00054 } 00055 00056 // Initialize display 00057 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00058 { 00059 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00060 User::Panic( KGetDisplayFailed, 0 ); 00061 } 00062 00063 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00064 EGLint numOfConfigs = 0; 00065 EGLint configSize = 0; 00066 00067 // Get the number of possible EGLConfigs 00068 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 00069 == EGL_FALSE ) 00070 { 00071 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00072 User::Panic( KGetConfigsFailed, 0 ); 00073 } 00074 00075 configSize = numOfConfigs; 00076 00077 // Allocate memory for the configList 00078 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00079 if ( configList == NULL ) 00080 { 00081 _LIT(KConfigAllocFailed, "config alloc failed"); 00082 User::Panic( KConfigAllocFailed, 0 ); 00083 } 00084 00085 /* 00086 Define properties for the wanted EGLSurface. 00087 We need to choose a 32-bit framebuffer, since the picking 00088 method needs an 8-bit alpha channel. 00089 */ 00090 00091 // Define properties for requesting a full-screen antialiased window surface 00092 const EGLint attrib_list_fsaa[] = 00093 { 00094 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00095 EGL_BUFFER_SIZE, 32, 00096 EGL_DEPTH_SIZE, 16, 00097 EGL_SAMPLE_BUFFERS, 1, 00098 EGL_SAMPLES, 4, 00099 EGL_NONE 00100 }; 00101 00102 // Define properties for requesting a non-antialiased window surface 00103 const EGLint attrib_list[] = 00104 { 00105 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00106 EGL_BUFFER_SIZE, 32, 00107 EGL_DEPTH_SIZE, 16, 00108 EGL_NONE 00109 }; 00110 00111 // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa 00112 if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00113 { 00114 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00115 User::Panic( KChooseConfigFailed, 0 ); 00116 } 00117 00118 // Check if no configurations were found 00119 if ( numOfConfigs == 0 ) 00120 { 00121 // No configs with antialising were found. Try to get the non-antialiased config 00122 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00123 { 00124 _LIT( KChooseConfigFailed, "eglChooseConfig failed" ); 00125 User::Panic( KChooseConfigFailed, 0 ); 00126 } 00127 00128 if ( numOfConfigs == 0 ) 00129 { 00130 // No configs found without antialiasing 00131 _LIT( KNoConfig, "Can't find the requested config." ); 00132 User::Panic( KNoConfig, 0 ); 00133 } 00134 } 00135 00136 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00137 // returned by eglChooseConfig are sorted so 00138 // that the best matching EGLConfig is first in 00139 // the list. 00140 User::Free( configList ); // Free configList, not used anymore. 00141 00142 // Create a window where the graphics are blitted 00143 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00144 if ( iEglSurface == NULL ) 00145 { 00146 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00147 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00148 } 00149 00150 // Create a rendering context 00151 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00152 if ( iEglContext == NULL ) 00153 { 00154 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00155 User::Panic( KCreateContextFailed, 0 ); 00156 } 00157 00158 /* Make the context current. Binds context to the current rendering thread 00159 and surface.*/ 00160 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00161 == EGL_FALSE ) 00162 { 00163 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00164 User::Panic( KMakeCurrentFailed, 0 ); 00165 } 00166 00167 TSize size; 00168 size = this->Size(); 00169 00170 iPickSelect = CPickSelect::NewL( size.iWidth, size.iHeight ); // Create an instance of PickSelect 00171 iPickSelect->AppInit(); // Initialize OpenGL ES 00172 00173 iOpenGlInitialized = ETrue; 00174 00175 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00176 // animating the scene 00177 iPeriodic->Start( 100, 100, 00178 TCallBack( CPickSelectContainer::DrawCallBack, this ) ); 00179 } 00180 00181 // Destructor 00182 CPickSelectContainer::~CPickSelectContainer() 00183 { 00184 delete iPeriodic; 00185 00186 if ( iPickSelect ) 00187 { 00188 /* AppExit call is made to release 00189 any allocations made in AppInit. */ 00190 iPickSelect->AppExit(); 00191 delete iPickSelect; 00192 } 00193 00194 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00195 eglDestroySurface( iEglDisplay, iEglSurface ); 00196 eglDestroyContext( iEglDisplay, iEglContext ); 00197 eglTerminate( iEglDisplay ); // Release resources associated 00198 // with EGL and OpenGL ES 00199 } 00200 00201 // --------------------------------------------------------- 00202 // CPickSelectContainer::SizeChanged 00203 // Called by framework when the view size is changed 00204 // --------------------------------------------------------- 00205 // 00206 void CPickSelectContainer::SizeChanged() 00207 { 00208 if( iOpenGlInitialized && iPickSelect ) 00209 { 00210 TSize size; 00211 size = this->Size(); 00212 00213 iPickSelect->SetScreenSize( size.iWidth, size.iHeight ); 00214 } 00215 } 00216 00217 00218 // --------------------------------------------------------- 00219 // CPickSelectContainer::HandleResourceChange( 00220 // TInt aType) 00221 // Dynamic screen resize changes by calling the 00222 // SetExtentToWholeScreen() method again. 00223 // --------------------------------------------------------- 00224 // 00225 void CPickSelectContainer::HandleResourceChange(TInt aType) 00226 { 00227 switch( aType ) 00228 { 00229 case KEikDynamicLayoutVariantSwitch: 00230 // Do not go full-screen in touch devices. 00231 if (AknLayoutUtils::PenEnabled()) 00232 { 00233 SetRect(iAppUi->ClientRect()); 00234 } 00235 else 00236 { 00237 SetExtentToWholeScreen(); // Take the whole screen into use 00238 } 00239 break; 00240 } 00241 } 00242 00243 // --------------------------------------------------------- 00244 // CPickSelectContainer::CountComponentControls 00245 // --------------------------------------------------------- 00246 // 00247 TInt CPickSelectContainer::CountComponentControls() const 00248 { 00249 return 0; 00250 } 00251 00252 // --------------------------------------------------------- 00253 // CPickSelectContainer::ComponentControl 00254 // --------------------------------------------------------- 00255 // 00256 CCoeControl* CPickSelectContainer::ComponentControl(TInt /*aIndex*/ ) const 00257 { 00258 return NULL; 00259 } 00260 00261 // --------------------------------------------------------- 00262 // CPickSelectContainer::Draw 00263 // --------------------------------------------------------- 00264 // 00265 void CPickSelectContainer::Draw(const TRect& /*aRect*/ ) const 00266 { 00267 // No need to implement anything here! 00268 } 00269 00270 // --------------------------------------------------------- 00271 // CPickSelectContainer::DrawCallBack 00272 // Called by the CPeriodic in order to draw the graphics 00273 // --------------------------------------------------------- 00274 // 00275 TInt CPickSelectContainer::DrawCallBack( TAny* aInstance ) 00276 { 00277 CPickSelectContainer* instance = (CPickSelectContainer*) aInstance; 00278 instance->iFrame++; 00279 00280 // Call the main OpenGL ES Symbian rendering 'loop' 00281 instance->iPickSelect->AppCycle( instance->iFrame ); 00282 00283 // Call eglSwapBuffers, which blit the graphics to the window 00284 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00285 00286 // To keep the background light on 00287 if ( !(instance->iFrame%100) ) 00288 { 00289 User::ResetInactivityTime(); 00290 } 00291 00292 /* Suspend the current thread for a short while. Give some time 00293 to other threads and AOs, avoids the ViewSrv error in ARMI and 00294 THUMB release builds. One may try to decrease the callback 00295 function instead of this. */ 00296 if ( !(instance->iFrame%50) ) 00297 { 00298 User::After(0); 00299 } 00300 00301 return 0; 00302 } 00303 00304 // --------------------------------------------------------- 00305 // CPickSelectContainer::HandleControlEventL 00306 // --------------------------------------------------------- 00307 // 00308 void CPickSelectContainer::HandleControlEventL( 00309 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) 00310 { 00311 } 00312 00313 // End of File
|
© Nokia 2009 |