Displaying two framebuffers simultaneously is a very interesting application!
First of all, there is always only one Graphics Engine within a GUI application - as a result, there is only one call to EwInitGraphicsEngine() necessary.
Since you already have both framebuffers initialized via EGL, it is necessary to create two viewports (one for each framebuffer) and to update the content of the current GUI application into both viewports.
Prerequisite is, that your EGL is configured so that both framebuffers are visible and accessible for drawing operations via OpenGL ES 2.0.
First, we need some variables to access both destinations:
static EGLDisplay EglDisplay1 = 0;
static EGLSurface EglSurface1 = 0;
static XViewport* Viewport1 = 0;
static GLint Framebuffer1 = 0xFFFFFFFF;
static EGLDisplay EglDisplay2 = 0;
static EGLSurface EglSurface2 = 0;
static XViewport* Viewport2 = 0;
static GLint Framebuffer2 = 0xFFFFFFFF;
static EGLContext EglContext = 0;
The intialization should look like this:
int main( int argc, char** argv )
{
...
/* initialize EGL to get access to display 1 and display 2 */
EglInit( &EglDisplay1, &EglSurface1, &EglDisplay2, &EglSurface2, &EglContext );
/* get the framebuffer 1 and its size in pixel */
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &Framebuffer1 );
...
/* get the framebuffer 2 and its size in pixel */
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &Framebuffer2 );
...
/* initialize the Graphics Engine as always */
EwInitGraphicsEngine( 0 );
/* create the applications root object and initialize it */
rootObject = (CoreRoot)EwNewObjectIndirect( EwApplicationClass, 0 );
EwLockObject( rootObject );
CoreRoot__Initialize( rootObject, EwScreenSize );
/* create viewport 1 object to provide uniform access to the framebuffer 1 */
Viewport1 = EwInitViewport( EwScreenSize, EwNewRect( 0, 0, w, h ), 0, 255,
&Framebuffer1, EglDisplay1, EglSurface1, ViewportProc );
/* create viewport 2 object to provide uniform access to the framebuffer 2 */
Viewport2 = EwInitViewport( EwScreenSize, EwNewRect( 0, 0, w, h ), 0, 255,
&framebuffer2, EglDisplay2, EglSurface2, ViewportProc );
...
In principle, the initialization of EGL is doubled in order to get a double set of EglDisplay, EglSurface - please take care that only one EglContext is created. The two EwInitViewport() calls create two independent drawing destinations (viewports).
The rest of the main loop is unchanged and the GUI application operates as always. However, the Update() method has to be enhanced, in order to draw into both destinations:
static void Update( CoreRoot aApplication )
{
XBitmap* bitmap;
GraphicsCanvas canvas = EwNewObject( GraphicsCanvas, 0 );
XRect updateRect = {{ 0, 0 }, { 0, 0 }};
if ( !canvas )
return;
/* ensure that framebuffer 1 is current drawing destination for OpenGL */
eglMakeCurrent( EglDisplay1, EglSurface1, EglSurface1, EglContext );
/* begin update with viewport 1 */
bitmap = EwBeginUpdate( Viewport1 );
if ( !bitmap )
return;
/* redraw the dirty area of the screen */
GraphicsCanvas__AttachBitmap( canvas, (XUInt32)bitmap );
updateRect = CoreRoot__UpdateGE20( aApplication, canvas );
GraphicsCanvas__DetachBitmap( canvas );
/* complete the update of viewport1 */
EwEndUpdate( Viewport1, updateRect );
/* invalidate the previously drawn area again */
CoreRoot__InvalidateArea( aApplication, updateRect );
/* ensure that framebuffer 2 is current drawing destination for OpenGL */
eglMakeCurrent( EglDisplay2, EglSurface2, EglSurface2, EglContext );
/* begin update with viewport 2 */
bitmap = EwBeginUpdate( Viewport2 );
if ( !bitmap )
return;
/* redraw the dirty area of the screen */
GraphicsCanvas__AttachBitmap( canvas, (XUInt32)bitmap );
updateRect = CoreRoot__UpdateGE20( aApplication, canvas );
GraphicsCanvas__DetachBitmap( canvas );
/* complete the update of viewport2 */
EwEndUpdate( Viewport2, updateRect );
}
The idea of this Update() function is: The update the first framebuffer is done "as always" and the returned dirty area is used to invalidate the area again to force a second update. This second update is done into the second drawing destination.
Please note, that the above code is not compiled and tested - there might be some minor adaptations necessary, depending on your particular EGL configuration.
In principle "it should work" - please let us know your results!