|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <TextureContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| 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 |
Definition at line 32 of file TextureContainer.h.
|
|
Destructor. Destroys the CPeriodic, CTexture and uninitializes OpenGL ES. Definition at line 165 of file TextureContainer.cpp. References CTexture::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iTexture. 00166 { 00167 delete iPeriodic; 00168 00169 /* AppExit call is made to release any allocations made in AppInit. 00170 This call has to be made here before we destroy the rendering context. */ 00171 if ( !(iTexture == NULL) ) 00172 { 00173 iTexture->AppExit(); 00174 delete iTexture; 00175 } 00176 00177 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00178 eglDestroySurface( iEglDisplay, iEglSurface ); 00179 eglDestroyContext( iEglDisplay, iEglContext ); 00180 eglTerminate( iEglDisplay ); // Release resources associated 00181 // with EGL and OpenGL ES 00182 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering.
Definition at line 29 of file TextureContainer.cpp. References iEglDisplay, iFrame, and iOpenGlInitialized. 00030 { 00031 iOpenGlInitialized = EFalse; 00032 CreateWindowL(); 00033 00034 SetExtentToWholeScreen(); // Take the whole screen into use 00035 ActivateL(); 00036 00037 iFrame = 0; // Frame counter 00038 00039 EGLConfig Config; // Describes the format, type and 00040 // size of the color buffers and 00041 // ancillary buffers for EGLSurface 00042 00043 /* Get the display for drawing graphics*/ 00044 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00045 if( iEglDisplay == NULL ) 00046 { 00047 _LIT(KEglGetDisplay, "eglGetDisplay failed"); 00048 User::Panic( KEglGetDisplay, 0 ); 00049 } 00050 00051 /* Initialize display */ 00052 if( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00053 { 00054 _LIT(KEglInitialize, "eglInitialize failed"); 00055 User::Panic( KEglInitialize, 0 ); 00056 } 00057 00058 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00059 TInt numOfConfigs = 0; 00060 TInt configSize = 0; 00061 00062 /* Get the number of possible EGLConfigs */ 00063 if( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00064 { 00065 _LIT(KEglGetConfigs, "eglGetconfigs failed"); 00066 User::Panic( KEglGetConfigs, 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(KConfigAlloc, "config alloc failed"); 00076 User::Panic( KConfigAlloc, 0 ); 00077 } 00078 00079 /* Define properties for the wanted EGLSurface. 00080 To get the best possible performance, choose 00081 an EGLConfig with a buffersize matching 00082 the current window's display mode*/ 00083 TDisplayMode DMode = Window().DisplayMode(); 00084 TInt BufferSize = 0; 00085 00086 switch(DMode) 00087 { 00088 case(EColor4K): 00089 BufferSize = 12; 00090 break; 00091 case(EColor64K): 00092 BufferSize = 16; 00093 break; 00094 case(EColor16M): 00095 BufferSize = 24; 00096 break; 00097 case(EColor16MU): 00098 BufferSize = 32; 00099 break; 00100 default: 00101 _LIT(KDModeError, "unsupported displaymode"); 00102 User::Panic( KDModeError, 0 ); 00103 break; 00104 } 00105 00106 const EGLint attrib_list[] = 00107 { 00108 EGL_BUFFER_SIZE,BufferSize, 00109 EGL_DEPTH_SIZE,16, 00110 EGL_NONE 00111 }; 00112 00113 /* Choose an EGLConfig that best matches to the properties in attrib_list */ 00114 if( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE ) 00115 { 00116 _LIT(KEglChooseConfig, "eglChooseConfig failed"); 00117 User::Panic( KEglChooseConfig, 0 ); 00118 } 00119 00120 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00121 // returned by eglChooseConfig are sorted so 00122 // that the best matching EGLConfig is first in 00123 // the list. 00124 User::Free( configList ); // Free configList, not used anymore. 00125 00126 /* Create a window where the graphics are blitted */ 00127 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00128 if( iEglSurface == NULL ) 00129 { 00130 _LIT(KEglCreateWindow, "eglCreateWindow failed"); 00131 User::Panic( KEglCreateWindow, 0 ); 00132 } 00133 00134 /* Create a rendering context */ 00135 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00136 if( iEglContext == NULL ) 00137 { 00138 _LIT(KEglCreateContext, "eglCreateContext failed"); 00139 User::Panic( KEglCreateContext, 0 ); 00140 } 00141 00142 /* Make the context current. Binds context to the current rendering thread 00143 and surface.*/ 00144 if( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00145 { 00146 _LIT(KEglMakeCurrent, "eglMakeCurrent failed"); 00147 User::Panic( KEglMakeCurrent, 0 ); 00148 } 00149 00150 TSize size; 00151 size = this->Size(); 00152 00153 iTexture = CTexture::NewL( size.iWidth, size.iHeight ); 00154 iTexture->AppInitL(); 00155 00156 iOpenGlInitialized = ETrue; 00157 00158 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00159 // animating the scene 00160 00161 iPeriodic->Start( 100, 100, TCallBack( CTextureContainer::DrawCallBack, this ) ); 00162 }
|
|
|
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 250 of file TextureContainer.cpp. References CTexture::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iTexture. 00251 { 00252 CTextureContainer* instance = (CTextureContainer*) aInstance; 00253 if ( instance->iTexture->GetState() == CTexture::ERunning ) 00254 { 00255 /* Check if the textures are loaded before doing any rendering. */ 00256 instance->iFrame++; 00257 00258 /* Call the main OpenGL ES Symbian rendering 'loop' */ 00259 instance->iTexture->AppCycle( instance->iFrame ); 00260 00261 /* Call eglSwapBuffers, which blit the graphics to the window */ 00262 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00263 00264 /* To keep the background light on */ 00265 if(!(instance->iFrame%100)) User::ResetInactivityTime(); 00266 00267 /* Suspend the current thread for a short while. Give some time 00268 to other threads and AOs, avoids the ViewSrv error in ARMI and 00269 THUMB release builds. One may try to decrease the callback 00270 function instead of this. */ 00271 if(!(instance->iFrame%50)) User::After(0); 00272 } 00273 return 0; 00274 }
|
|
|
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 189 of file TextureContainer.cpp. References iOpenGlInitialized, iTexture, and CTexture::SetScreenSize(). 00190 { 00191 if( iOpenGlInitialized && iTexture ) 00192 { 00193 TSize size; 00194 size = this->Size(); 00195 00196 iTexture->SetScreenSize( size.iWidth, size.iHeight ); 00197 } 00198 }
|
|
|
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 208 of file TextureContainer.cpp. 00209 { 00210 switch( aType ) 00211 { 00212 case KEikDynamicLayoutVariantSwitch: 00213 SetExtentToWholeScreen(); 00214 break; 00215 } 00216 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 222 of file TextureContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 231 of file TextureContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 240 of file TextureContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 281 of file TextureContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 102 of file TextureContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 105 of file TextureContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 108 of file TextureContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 111 of file TextureContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 114 of file TextureContainer.h. |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 120 of file TextureContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 125 of file TextureContainer.h. |
|
© Nokia 2006 |