|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <SimpleCubePixmapContainer.h>
Public Member Functions | |
| void | ConstructL (const TRect &aRect) |
| virtual | ~CSimpleCubePixmapContainer () |
Static Public Member Functions | |
| static TInt | DrawCallBack (TAny *aInstance) |
Public Attributes | |
| TInt | iFrame |
| CSimpleCubePixmap * | iSimpleCubePixmap |
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 |
| EGLConfig | iConfig |
| CWsBitmap * | iPixmap |
| EGLSurface | iEglSurface |
| EGLContext | iEglContext |
| CPeriodic * | iPeriodic |
| TBool | iOpenGlInitialized |
Definition at line 31 of file SimpleCubePixmapContainer.h.
|
|
Destructor. Destroys the CPeriodic, CSimpleCubePixmap and uninitializes OpenGL ES. Definition at line 169 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, iPixmap, and iSimpleCubePixmap. 00170 { 00171 delete iPeriodic; 00172 00173 /* AppExit call is made to release 00174 any allocations made in AppInit. */ 00175 if ( iSimpleCubePixmap ) 00176 { 00177 iSimpleCubePixmap->AppExit(); 00178 delete iSimpleCubePixmap; 00179 } 00180 00181 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00182 eglDestroySurface( iEglDisplay, iEglSurface ); 00183 eglDestroyContext( iEglDisplay, iEglContext ); 00184 eglTerminate( iEglDisplay ); // Release resources associated 00185 // with EGL and OpenGL ES 00186 00187 delete iPixmap; 00188 }
|
|
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 29 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppInit(), DrawCallBack(), iConfig, iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iPixmap, iSimpleCubePixmap, and CSimpleCubePixmap::NewL(). 00030 { 00031 iOpenGlInitialized = EFalse; 00032 CreateWindowL(); 00033 00034 SetExtentToWholeScreen(); // Take the whole screen into use 00035 ActivateL(); 00036 00037 iFrame = 0; // Initialize frame counter 00038 00039 00040 // Get the display for drawing graphics 00041 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00042 if ( iEglDisplay == NULL ) 00043 { 00044 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00045 User::Panic( KGetDisplayFailed, 0 ); 00046 } 00047 00048 // Initialize display 00049 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00050 { 00051 _LIT(KInitializeFailed, "eglInitialize failed"); 00052 User::Panic( KInitializeFailed, 0 ); 00053 } 00054 00055 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00056 EGLint numOfConfigs = 0; 00057 EGLint configSize = 0; 00058 00059 // Get the number of possible EGLConfigs 00060 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 00061 == EGL_FALSE ) 00062 { 00063 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00064 User::Panic( KGetConfigsFailed, 0 ); 00065 } 00066 00067 configSize = numOfConfigs; 00068 00069 // Allocate memory for the configList 00070 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00071 if ( configList == NULL ) 00072 { 00073 _LIT(KConfigAllocFailed, "config alloc failed"); 00074 User::Panic( KConfigAllocFailed, 0 ); 00075 } 00076 00077 /* Define properties for the wanted EGLSurface. 00078 To get the best possible performance, choose 00079 an EGLConfig with a buffersize matching 00080 the current window's display mode*/ 00081 TDisplayMode DMode = Window().DisplayMode(); 00082 TInt BufferSize = 0; 00083 00084 switch ( DMode ) 00085 { 00086 case(EColor4K): 00087 BufferSize = 12; 00088 break; 00089 case(EColor64K): 00090 BufferSize = 16; 00091 break; 00092 case(EColor16M): 00093 BufferSize = 24; 00094 break; 00095 case(EColor16MU): 00096 BufferSize = 32; 00097 break; 00098 default: 00099 _LIT(KDModeError, "unsupported displaymode"); 00100 User::Panic( KDModeError, 0 ); 00101 break; 00102 } 00103 00104 // Define properties for the wanted EGLSurface 00105 const EGLint attrib_list[] = { EGL_BUFFER_SIZE, 00106 BufferSize, 00107 EGL_SURFACE_TYPE, 00108 EGL_PIXMAP_BIT, 00109 EGL_NONE}; 00110 00111 // Choose an EGLConfig that best matches to the properties in attrib_list 00112 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, 00113 &numOfConfigs ) == EGL_FALSE ) 00114 { 00115 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00116 User::Panic( KChooseConfigFailed, 0 ); 00117 } 00118 00119 iConfig = configList[0]; // Choose the best EGLConfig. EGLConfigs 00120 // returned by eglChooseConfig are sorted so 00121 // that the best matching EGLConfig is first in 00122 // the list. 00123 User::Free( configList ); // Free configList, not used anymore. 00124 00125 // Create a Symbian bitmap where the graphics are blitted 00126 iPixmap = new CWsBitmap( iEikonEnv->WsSession() ); 00127 iPixmap->Create( Window().Size(), DMode); 00128 iEglSurface = eglCreatePixmapSurface( iEglDisplay, iConfig, iPixmap, NULL ); 00129 00130 if ( iEglSurface == NULL ) 00131 { 00132 _LIT(KCreatePixmapSurfaceFailed, "eglCreatePixmapSurface failed"); 00133 User::Panic( KCreatePixmapSurfaceFailed, 0 ); 00134 } 00135 00136 // Create a rendering context 00137 iEglContext = eglCreateContext( iEglDisplay, iConfig, EGL_NO_CONTEXT, NULL ); 00138 if ( iEglContext == NULL ) 00139 { 00140 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00141 User::Panic( KCreateContextFailed, 0 ); 00142 } 00143 00144 /* Make the context current. Binds context to the current rendering thread 00145 and surface.*/ 00146 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00147 == EGL_FALSE ) 00148 { 00149 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00150 User::Panic( KMakeCurrentFailed, 0 ); 00151 } 00152 00153 00154 TSize size; 00155 size = this->Size(); 00156 00157 // Create an instance of SimpleCubePixmap 00158 iSimpleCubePixmap = CSimpleCubePixmap::NewL( size.iWidth, size.iHeight ); 00159 iSimpleCubePixmap->AppInit(); // Initialize OpenGL ES 00160 00161 iOpenGlInitialized = ETrue; 00162 00163 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00164 // animating the scene 00165 iPeriodic->Start( 100, 100, TCallBack( CSimpleCubePixmapContainer::DrawCallBack, this ) ); 00166 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CSimpleCubePixmap to do the rendering for each frame.
Definition at line 296 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppCycle(), iFrame, and iSimpleCubePixmap. 00297 { 00298 CSimpleCubePixmapContainer* instance 00299 = (CSimpleCubePixmapContainer*) aInstance; 00300 instance->iFrame++; 00301 00302 // Call the main OpenGL ES Symbian rendering 'loop' 00303 instance->iSimpleCubePixmap->AppCycle( instance->iFrame ); 00304 00305 /* eglSwapBuffers is not called when usin Pixmap surfaces. 00306 Instead, standard Symbian BitBlt has to be used. */ 00307 instance->DrawNow( ); 00308 00309 // To keep the background light on 00310 if ( !(instance->iFrame%100) ) 00311 { 00312 User::ResetInactivityTime(); 00313 } 00314 00315 /* Suspend the current thread for a short while. Give some time 00316 to other threads and AOs, avoids the ViewSrv error in ARMI and 00317 THUMB release builds. One may try to decrease the callback 00318 function instead of this. */ 00319 if ( !(instance->iFrame%50) ) 00320 { 00321 User::After(0); 00322 } 00323 00324 return 0; 00325 }
|
|
|
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 195 of file SimpleCubePixmapContainer.cpp. References iConfig, iEglContext, iEglDisplay, iEglSurface, iOpenGlInitialized, iPixmap, iSimpleCubePixmap, and CSimpleCubePixmap::SetScreenSize(). 00196 { 00197 if( iOpenGlInitialized && iSimpleCubePixmap ) 00198 { 00199 TSize size; 00200 size = this->Size(); 00201 00202 // Destroy the old context, surface and bitmap 00203 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00204 eglDestroySurface( iEglDisplay, iEglSurface ); 00205 eglDestroyContext( iEglDisplay, iEglContext ); 00206 if( iPixmap ) 00207 { 00208 delete iPixmap; 00209 } 00210 00211 // Recreate the Symbian bitmap where the graphics are blitted 00212 iPixmap = new CWsBitmap( iEikonEnv->WsSession() ); 00213 iPixmap->Create( Window().Size(), Window().DisplayMode() ); 00214 00215 00216 // Recreate and rebind the new surface 00217 iEglSurface = eglCreatePixmapSurface( iEglDisplay, iConfig, iPixmap, NULL ); 00218 if ( iEglSurface == NULL ) 00219 { 00220 _LIT(KCreatePixmapSurfaceFailed, "eglCreatePixmapSurface failed"); 00221 User::Panic( KCreatePixmapSurfaceFailed, 0 ); 00222 } 00223 00224 // Create a rendering context 00225 iEglContext = eglCreateContext( iEglDisplay, iConfig, EGL_NO_CONTEXT, NULL ); 00226 if ( iEglContext == NULL ) 00227 { 00228 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00229 User::Panic( KCreateContextFailed, 0 ); 00230 } 00231 00232 // Make the context current. Binds context to the current 00233 // rendering thread and surface. 00234 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00235 { 00236 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00237 User::Panic( KMakeCurrentFailed, 0 ); 00238 } 00239 00240 00241 // Notify the renderer class 00242 iSimpleCubePixmap->SetScreenSize( size.iWidth, size.iHeight ); 00243 } 00244 }
|
|
|
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 254 of file SimpleCubePixmapContainer.cpp. 00255 { 00256 switch( aType ) 00257 { 00258 case KEikDynamicLayoutVariantSwitch: 00259 SetExtentToWholeScreen(); 00260 break; 00261 } 00262 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 268 of file SimpleCubePixmapContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 277 of file SimpleCubePixmapContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 285 of file SimpleCubePixmapContainer.cpp. References iPixmap. 00286 { 00287 CWindowGc& gc = SystemGc(); 00288 gc.BitBlt( TPoint( 0, 0 ), iPixmap ); 00289 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 331 of file SimpleCubePixmapContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 101 of file SimpleCubePixmapContainer.h. |
|
|
Describes the format, type and size of the color buffers and ancillary buffers for EGLSurface. Definition at line 104 of file SimpleCubePixmapContainer.h. |
|
|
The bitmap where the framebuffer is drawn. Definition at line 107 of file SimpleCubePixmapContainer.h. |
|
|
Pixmap surface (that uses the iPixmap) that is the target of OpenGL ES graphics rendering. Definition at line 110 of file SimpleCubePixmapContainer.h. |
|
|
OpenGL ES rendering context. Definition at line 113 of file SimpleCubePixmapContainer.h. |
|
|
Active object that is the timing source for the animation. Definition at line 116 of file SimpleCubePixmapContainer.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 122 of file SimpleCubePixmapContainer.h. |
|
|
Frame counter variable, used in the animation. Definition at line 127 of file SimpleCubePixmapContainer.h. |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 130 of file SimpleCubePixmapContainer.h. |
|
© Nokia 2006 |