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