|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <HierarchyContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CHierarchyContainer () |
Static Public Member Functions | |
| static int | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| CHierarchy * | iHierarchy |
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 |
| CPeriodic * | iPeriodic |
| TBool | iOpenGlInitialized |
| TInt | iFrame |
Definition at line 31 of file HierarchyContainer.h.
|
|
Destructor. Destroys the CPeriodic, CHierarchy and uninitializes OpenGL ES. Definition at line 164 of file HierarchyContainer.cpp. References CHierarchy::AppExit(), iEglContext, iEglDisplay, iEglSurface, iHierarchy, and iPeriodic. 00165 { 00166 delete iPeriodic; 00167 00168 /* AppExit call is made to release 00169 any allocations made in AppInit. */ 00170 if ( iHierarchy ) 00171 { 00172 iHierarchy->AppExit(); 00173 delete iHierarchy; 00174 } 00175 00176 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00177 eglDestroySurface( iEglDisplay, iEglSurface ); 00178 eglDestroyContext( iEglDisplay, iEglContext ); 00179 eglTerminate( iEglDisplay ); // Release resources associated 00180 // with EGL and OpenGL ES 00181 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 26 of file HierarchyContainer.cpp. References CHierarchy::AppInit(), DrawCallBack(), iEglContext, iEglDisplay, iEglSurface, iFrame, iHierarchy, iOpenGlInitialized, iPeriodic, and CHierarchy::NewL(). 00027 { 00028 iOpenGlInitialized = EFalse; 00029 00030 CreateWindowL(); 00031 00032 SetExtentToWholeScreen(); // Take the whole screen into use 00033 ActivateL(); 00034 00035 iFrame = 0; // Frame counter 00036 00037 EGLConfig Config; // Describes the format, type and 00038 // size of the color buffers and 00039 // ancillary buffers for EGLSurface 00040 00041 // Get the display for drawing graphics 00042 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00043 if ( iEglDisplay == NULL ) 00044 { 00045 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00046 User::Panic( KGetDisplayFailed, 0 ); 00047 } 00048 00049 // Initialize display 00050 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00051 { 00052 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00053 User::Panic( KGetDisplayFailed, 0 ); 00054 } 00055 00056 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00057 EGLint numOfConfigs = 0; 00058 EGLint configSize = 0; 00059 00060 // Get the number of possible EGLConfigs 00061 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 00062 == EGL_FALSE ) 00063 { 00064 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00065 User::Panic( KGetConfigsFailed, 0 ); 00066 } 00067 00068 configSize = numOfConfigs; 00069 00070 // Allocate memory for the configList 00071 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00072 if ( configList == NULL ) 00073 { 00074 _LIT(KConfigAllocFailed, "config alloc failed"); 00075 User::Panic( KConfigAllocFailed, 0 ); 00076 } 00077 00078 /* Define properties for the wanted EGLSurface. 00079 To get the best possible performance, choose 00080 an EGLConfig with a buffersize matching 00081 the current window's display mode*/ 00082 TDisplayMode DMode = Window().DisplayMode(); 00083 TInt BufferSize = 0; 00084 00085 switch ( DMode ) 00086 { 00087 case(EColor4K): 00088 BufferSize = 12; 00089 break; 00090 case(EColor64K): 00091 BufferSize = 16; 00092 break; 00093 case(EColor16M): 00094 BufferSize = 24; 00095 break; 00096 case(EColor16MU): 00097 BufferSize = 32; 00098 break; 00099 default: 00100 _LIT(KDModeError, "unsupported displaymode"); 00101 User::Panic( KDModeError, 0 ); 00102 break; 00103 } 00104 00105 // Define properties for the wanted EGLSurface 00106 const EGLint attrib_list[] = { EGL_BUFFER_SIZE,BufferSize, 00107 EGL_DEPTH_SIZE,16, // 16-bit depthbuffer 00108 EGL_NONE }; 00109 00110 // Choose an EGLConfig that best matches to the properties in attrib_list 00111 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, 00112 &numOfConfigs ) == EGL_FALSE ) 00113 { 00114 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00115 User::Panic( KChooseConfigFailed, 0 ); 00116 } 00117 00118 Config = configList[0]; // Choose the best EGLConfig. EGLConfigs 00119 // returned by eglChooseConfig are sorted so 00120 // that the best matching EGLConfig is first in 00121 // the list. 00122 User::Free( configList ); // Free configList, not used anymore. 00123 00124 // Create a window where the graphics are blitted 00125 iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL ); 00126 if ( iEglSurface == NULL ) 00127 { 00128 _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed"); 00129 User::Panic( KCreateWindowSurfaceFailed, 0 ); 00130 } 00131 00132 // Create a rendering context 00133 iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL ); 00134 if ( iEglContext == NULL ) 00135 { 00136 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00137 User::Panic( KCreateContextFailed, 0 ); 00138 } 00139 00140 /* Make the context current. Binds context to the current rendering thread 00141 and surface.*/ 00142 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00143 == EGL_FALSE ) 00144 { 00145 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00146 User::Panic( KMakeCurrentFailed, 0 ); 00147 } 00148 00149 TSize size; 00150 size = this->Size(); 00151 00152 iHierarchy = CHierarchy::NewL( size.iWidth, size.iHeight ); 00153 iHierarchy->AppInit(); 00154 00155 iOpenGlInitialized = ETrue; 00156 00157 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00158 // animating the scene 00159 iPeriodic->Start( 100, 100, 00160 TCallBack( CHierarchyContainer::DrawCallBack, this ) ); 00161 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CHierarchy to do the rendering for each frame.
Definition at line 251 of file HierarchyContainer.cpp. References CHierarchy::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iHierarchy. 00252 { 00253 CHierarchyContainer* instance = (CHierarchyContainer*) aInstance; 00254 instance->iFrame++; 00255 00256 // Call the main OpengGL ES Symbian rendering 'loop' 00257 instance->iHierarchy->AppCycle( instance->iFrame ); 00258 00259 // Call eglSwapBuffers, which blit the graphics to the window 00260 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00261 00262 // To keep the background light on 00263 if ( !(instance->iFrame%100) ) 00264 { 00265 User::ResetInactivityTime(); 00266 } 00267 00268 /* Suspend the current thread for a short while. Give some time 00269 to other threads and AOs, avoids the ViewSrv error in ARMI and 00270 THUMB release builds. One may try to decrease the callback 00271 function instead of this. */ 00272 if ( !(instance->iFrame%50) ) 00273 { 00274 User::After(0); 00275 } 00276 00277 return 0; 00278 }
|
|
|
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 188 of file HierarchyContainer.cpp. References iHierarchy, iOpenGlInitialized, and CHierarchy::SetScreenSize(). 00189 { 00190 if( iOpenGlInitialized && iHierarchy ) 00191 { 00192 TSize size; 00193 size = this->Size(); 00194 00195 iHierarchy->SetScreenSize( size.iWidth, size.iHeight ); 00196 } 00197 }
|
|
|
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 207 of file HierarchyContainer.cpp. 00208 { 00209 switch( aType ) 00210 { 00211 case KEikDynamicLayoutVariantSwitch: 00212 SetExtentToWholeScreen(); 00213 break; 00214 } 00215 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 222 of file HierarchyContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 231 of file HierarchyContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 240 of file HierarchyContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 285 of file HierarchyContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 101 of file HierarchyContainer.h. |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 104 of file HierarchyContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 107 of file HierarchyContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 110 of file HierarchyContainer.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 116 of file HierarchyContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 119 of file HierarchyContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 124 of file HierarchyContainer.h. |
|
© Nokia 2006 |