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

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