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

Definition at line 29 of file SimpleCubePixmapContainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| 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 |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CSimpleCubePixmap and uninitializes OpenGL ES. Definition at line 157 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, iPixmap, and iSimpleCubePixmap. 00158 { 00159 delete iPeriodic; 00160 00161 /* AppExit call is made to release 00162 any allocations made in AppInit. */ 00163 if ( iSimpleCubePixmap ) 00164 { 00165 iSimpleCubePixmap->AppExit(); 00166 delete iSimpleCubePixmap; 00167 } 00168 00169 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00170 eglDestroySurface( iEglDisplay, iEglSurface ); 00171 eglDestroyContext( iEglDisplay, iEglContext ); 00172 eglTerminate( iEglDisplay ); // Release resources associated 00173 // with EGL and OpenGL ES 00174 00175 delete iPixmap; 00176 }
|
|
||||||||||||
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 27 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppInit(), DrawCallBack(), iAppUi, iConfig, iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iPixmap, iSimpleCubePixmap, and CSimpleCubePixmap::NewL(). Referenced by CSimpleCubePixmapAppUi::ConstructL(). 00028 { 00029 iAppUi = aAppUi; 00030 iOpenGlInitialized = EFalse; 00031 CreateWindowL(); 00032 00033 // Don't go full-screen in touch devices. 00034 if (AknLayoutUtils::PenEnabled()) 00035 { 00036 TRect touchRect(0, 0, aRect.Width(), aRect.iTl.iY+aRect.Height()); 00037 SetRect(touchRect); 00038 } 00039 else 00040 { 00041 SetExtentToWholeScreen(); // Take the whole screen into use 00042 } 00043 ActivateL(); 00044 00045 iFrame = 0; // Initialize frame counter 00046 00047 00048 // Get the display for drawing graphics 00049 iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY ); 00050 if ( iEglDisplay == NULL ) 00051 { 00052 _LIT(KGetDisplayFailed, "eglGetDisplay failed"); 00053 User::Panic( KGetDisplayFailed, 0 ); 00054 } 00055 00056 // Initialize display 00057 if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE ) 00058 { 00059 _LIT(KInitializeFailed, "eglInitialize failed"); 00060 User::Panic( KInitializeFailed, 0 ); 00061 } 00062 00063 EGLConfig *configList = NULL; // Pointer for EGLConfigs 00064 EGLint numOfConfigs = 0; 00065 EGLint configSize = 0; 00066 00067 // Get the number of possible EGLConfigs 00068 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) 00069 == EGL_FALSE ) 00070 { 00071 _LIT(KGetConfigsFailed, "eglGetConfigs failed"); 00072 User::Panic( KGetConfigsFailed, 0 ); 00073 } 00074 00075 configSize = numOfConfigs; 00076 00077 // Allocate memory for the configList 00078 configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize ); 00079 if ( configList == NULL ) 00080 { 00081 _LIT(KConfigAllocFailed, "config alloc failed"); 00082 User::Panic( KConfigAllocFailed, 0 ); 00083 } 00084 00085 /* Define properties for the wanted EGLSurface. 00086 To get the best possible performance, choose 00087 an EGLConfig with a buffersize matching 00088 the current window's display mode*/ 00089 TDisplayMode DMode = Window().DisplayMode(); 00090 TInt BufferSize = TDisplayModeUtils::NumDisplayModeBitsPerPixel(DMode); 00091 00092 // Define properties for the wanted EGLSurface 00093 const EGLint attrib_list[] = { EGL_BUFFER_SIZE, 00094 BufferSize, 00095 EGL_SURFACE_TYPE, 00096 EGL_PIXMAP_BIT, 00097 EGL_NONE}; 00098 00099 // Choose an EGLConfig that best matches to the properties in attrib_list 00100 if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, 00101 &numOfConfigs ) == EGL_FALSE ) 00102 { 00103 _LIT(KChooseConfigFailed, "eglChooseConfig failed"); 00104 User::Panic( KChooseConfigFailed, 0 ); 00105 } 00106 00107 iConfig = configList[0]; // Choose the best EGLConfig. EGLConfigs 00108 // returned by eglChooseConfig are sorted so 00109 // that the best matching EGLConfig is first in 00110 // the list. 00111 User::Free( configList ); // Free configList, not used anymore. 00112 00113 // Create a Symbian bitmap where the graphics are blitted 00114 iPixmap = new CWsBitmap( iEikonEnv->WsSession() ); 00115 iPixmap->Create( Window().Size(), DMode); 00116 iEglSurface = eglCreatePixmapSurface( iEglDisplay, iConfig, iPixmap, NULL ); 00117 00118 if ( iEglSurface == NULL ) 00119 { 00120 _LIT(KCreatePixmapSurfaceFailed, "eglCreatePixmapSurface failed"); 00121 User::Panic( KCreatePixmapSurfaceFailed, 0 ); 00122 } 00123 00124 // Create a rendering context 00125 iEglContext = eglCreateContext( iEglDisplay, iConfig, EGL_NO_CONTEXT, NULL ); 00126 if ( iEglContext == NULL ) 00127 { 00128 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00129 User::Panic( KCreateContextFailed, 0 ); 00130 } 00131 00132 /* Make the context current. Binds context to the current rendering thread 00133 and surface.*/ 00134 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) 00135 == EGL_FALSE ) 00136 { 00137 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00138 User::Panic( KMakeCurrentFailed, 0 ); 00139 } 00140 00141 00142 TSize size; 00143 size = this->Size(); 00144 00145 // Create an instance of SimpleCubePixmap 00146 iSimpleCubePixmap = CSimpleCubePixmap::NewL( size.iWidth, size.iHeight ); 00147 iSimpleCubePixmap->AppInit(); // Initialize OpenGL ES 00148 00149 iOpenGlInitialized = ETrue; 00150 00151 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for 00152 // animating the scene 00153 iPeriodic->Start( 100, 100, TCallBack( CSimpleCubePixmapContainer::DrawCallBack, this ) ); 00154 }
|
|
|
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 293 of file SimpleCubePixmapContainer.cpp. References CSimpleCubePixmap::AppCycle(), iFrame, and iSimpleCubePixmap. Referenced by ConstructL(). 00294 { 00295 CSimpleCubePixmapContainer* instance 00296 = (CSimpleCubePixmapContainer*) aInstance; 00297 instance->iFrame++; 00298 00299 // Call the main OpenGL ES Symbian rendering 'loop' 00300 instance->iSimpleCubePixmap->AppCycle( instance->iFrame ); 00301 00302 /* eglSwapBuffers is not called when usin Pixmap surfaces. 00303 Instead, standard Symbian BitBlt has to be used. */ 00304 instance->DrawNow( ); 00305 00306 00307 if ( !(instance->iFrame % 50 ) ) 00308 { 00309 // Reset inactivity timer to keep the background light on 00310 User::ResetInactivityTime(); 00311 } 00312 // Suspend the current thread for a short while. Give some time 00313 // to other threads and AOs, avoids the ViewSrv error in ARMI and 00314 // THUMB release builds. One may try to decrease the callback 00315 // function instead of this. 00316 User::After( 100 ); 00317 00318 return 0; 00319 }
|
|
|
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 183 of file SimpleCubePixmapContainer.cpp. References iConfig, iEglContext, iEglDisplay, iEglSurface, iOpenGlInitialized, iPixmap, iSimpleCubePixmap, and CSimpleCubePixmap::SetScreenSize(). 00184 { 00185 if( iOpenGlInitialized && iSimpleCubePixmap ) 00186 { 00187 TSize size; 00188 size = this->Size(); 00189 00190 // Destroy the old context, surface and bitmap 00191 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00192 eglDestroySurface( iEglDisplay, iEglSurface ); 00193 eglDestroyContext( iEglDisplay, iEglContext ); 00194 if( iPixmap ) 00195 { 00196 delete iPixmap; 00197 } 00198 00199 // Recreate the Symbian bitmap where the graphics are blitted 00200 iPixmap = new CWsBitmap( iEikonEnv->WsSession() ); 00201 iPixmap->Create( Window().Size(), Window().DisplayMode() ); 00202 00203 00204 // Recreate and rebind the new surface 00205 iEglSurface = eglCreatePixmapSurface( iEglDisplay, iConfig, iPixmap, NULL ); 00206 if ( iEglSurface == NULL ) 00207 { 00208 _LIT(KCreatePixmapSurfaceFailed, "eglCreatePixmapSurface failed"); 00209 User::Panic( KCreatePixmapSurfaceFailed, 0 ); 00210 } 00211 00212 // Create a rendering context 00213 iEglContext = eglCreateContext( iEglDisplay, iConfig, EGL_NO_CONTEXT, NULL ); 00214 if ( iEglContext == NULL ) 00215 { 00216 _LIT(KCreateContextFailed, "eglCreateContext failed"); 00217 User::Panic( KCreateContextFailed, 0 ); 00218 } 00219 00220 // Make the context current. Binds context to the current 00221 // rendering thread and surface. 00222 if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE ) 00223 { 00224 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00225 User::Panic( KMakeCurrentFailed, 0 ); 00226 } 00227 00228 00229 // Notify the renderer class 00230 iSimpleCubePixmap->SetScreenSize( size.iWidth, size.iHeight ); 00231 } 00232 }
|
|
|
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 242 of file SimpleCubePixmapContainer.cpp. References iAppUi. 00243 { 00244 switch( aType ) 00245 { 00246 case KEikDynamicLayoutVariantSwitch: 00247 // Do not go to full-screen in touch devices. 00248 if (AknLayoutUtils::PenEnabled()) 00249 { 00250 TRect touchRect(0, 0, iAppUi->ClientRect().Width(), iAppUi->ClientRect().iTl.iY+iAppUi->ClientRect().Height()); 00251 SetRect(touchRect); // Leave place for soft buttons 00252 } 00253 else 00254 { 00255 SetExtentToWholeScreen(); // Take the whole screen into use 00256 } 00257 break; 00258 } 00259 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 265 of file SimpleCubePixmapContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 274 of file SimpleCubePixmapContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 282 of file SimpleCubePixmapContainer.cpp. References iPixmap. 00283 { 00284 CWindowGc& gc = SystemGc(); 00285 gc.BitBlt( TPoint( 0, 0 ), iPixmap ); 00286 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 325 of file SimpleCubePixmapContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 99 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), SizeChanged(), and ~CSimpleCubePixmapContainer(). |
|
|
Describes the format, type and size of the color buffers and ancillary buffers for EGLSurface. Definition at line 102 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
The bitmap where the framebuffer is drawn. Definition at line 105 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), Draw(), SizeChanged(), and ~CSimpleCubePixmapContainer(). |
|
|
Pixmap surface (that uses the iPixmap) that is the target of OpenGL ES graphics rendering. Definition at line 108 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), SizeChanged(), and ~CSimpleCubePixmapContainer(). |
|
|
OpenGL ES rendering context. Definition at line 111 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), SizeChanged(), and ~CSimpleCubePixmapContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 114 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), and ~CSimpleCubePixmapContainer(). |
|
|
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 SimpleCubePixmapContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 123 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Frame counter variable, used in the animation. Definition at line 128 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), and DrawCallBack(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 131 of file SimpleCubePixmapContainer.h. Referenced by ConstructL(), DrawCallBack(), CSimpleCubePixmapAppUi::HandleCommandL(), SizeChanged(), and ~CSimpleCubePixmapContainer(). |
|
© Nokia 2009 |