Hi guys,

I'm having a problem with two different OpenGL ES and EGL implementations on windows, namely AMD Catalyst Driver 11.10 and Imagination SDK, when trying to implement a multiple windows application, where contexts are shared. First it was written with Imagination SDK, but as there is native EGL and GLES2 support in AMD's drivers i also want to support (and benchmark) that.

I'm quite confused in the meaning of EGLDisplay, but as far as i understood here really the windows themselves are meant, as they are created in both cases out of the windows HDCs.

But when declaring an EGLContext on the first display and one on the second (to be shared with the first), then on Imagination it works fine, while on Catalyst driver this results in EGL_NO_CONTEXT. here the window was created with style CS_OWNDC.
When creating the window with style CS_CLASSDC, than it works the other way round with both windows being created and their content displayed on AMD, and basically working, but strange results (flickering, always rendered on "active" window) on Imagination. The CLASSDC solution working on AMD i already found with help of AMD's forums.

Here's my display initialization:
class DisplayContext{

public:
DisplayContext():
hwnd(0),hInstance(0),disp(0),windowConfig(0), context(0)
{

}

~DisplayContext()
{

}

bool OpenWindow(int width, int height, const TCHAR* wndClass, const TCHAR* wndName)
{

hInstance = GetModuleHandle(NULL);
wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_OWNDC;
wcex.lpfnWndProc = &DefWindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = 0; //(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = wndClass;
wcex.hIconSm = NULL;

RegisterClassEx(&wcex);
RECT rect = {0,0, width, height};
int style = WS_BORDER | WS_CAPTION;
AdjustWindowRect(&rect, style, FALSE);

hwnd = CreateWindow(wndClass, wndName, style,
CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandle(NULL), NULL);
ShowWindow(hwnd, SW_SHOW);

return hwnd != 0;
}

bool CreateEGLContext(EGLContext share)
{
if(hwnd != 0) {
HDC hdc = GetDC(hwnd);

disp = eglGetDisplay(hdc);

EGLint major, minor;
eglInitialize(disp,&major, &minor);
eglBindAPI(EGL_OPENGL_ES_API);

EGLint attributes[] =
{
EGL_BUFFER_SIZE, 0,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
// EGL_LUMINANCE_SIZE, 0,
EGL_ALPHA_SIZE, 0,
//EGL_ALPHA_MASK_SIZE, 0,
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
EGL_CONFIG_CAVEAT, EGL_DONT_CARE,
EGL_CONFIG_ID, EGL_DONT_CARE,
//EGL_CONFORMANT, 0,
EGL_DEPTH_SIZE, 24,
EGL_LEVEL, 0,
EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE,
EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE,
EGL_NATIVE_RENDERABLE, EGL_DONT_CARE,
EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
EGL_STENCIL_SIZE, 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_TRANSPARENT_TYPE, EGL_NONE,
EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE,
EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE,
EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE,
EGL_NONE
};

EGLint surfaceAttributes[] = {EGL_NONE};
EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};

EGLint nrOfConfigs;
eglChooseConfig(disp, attributes,&windowConfig,1,&nrOfConfigs);
surface = eglCreateWindowSurface(disp, windowConfig, hwnd,surfaceAttributes);

context = eglCreateContext(disp, windowConfig, share,contextAttributes);

return context != EGL_NO_CONTEXT;
}
}

EGLContext GetContext(){
return context;
}

private:
WNDCLASSEX wcex;
HINSTANCE hInstance;
HWND hwnd;

EGLDisplay disp;
EGLConfig windowConfig;
EGLContext context;
EGLSurface surface;


};

They are called an instatiated as follows:

DisplayContext context1;
DisplayContext context2;

bool res = context1.OpenWindow(640,480, "TEST", "TEST1");
res = context1.CreateEGLContext(EGL_NO_CONTEXT);

res = context2.OpenWindow(640,480, "TEST", "TEST2");
res = context2.CreateEGLContext(context1.GetContext());

Could someone tell me if that should be right from the EGL point of view? or what might go wrong in there? As said this version doesn't work on AMD, and exchanging wcex.style with CS_CLASSDC is the other case.

Cheers,
Georg