EGLSurface surface;
EGLint api;
- EglDrawable(const Visual *vis, int w, int h) :
- Drawable(vis, w, h), api(EGL_OPENGL_ES_API)
+ EglDrawable(const Visual *vis, int w, int h, bool pbuffer) :
+ Drawable(vis, w, h, pbuffer),
+ api(EGL_OPENGL_ES_API)
{
XVisualInfo *visinfo = static_cast<const EglVisual *>(visual)->visinfo;
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
}
+ void
+ recreate(void) {
+ EGLContext currentContext = eglGetCurrentContext();
+ EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW);
+ EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ);
+ bool rebindDrawSurface = currentDrawSurface == surface;
+ bool rebindReadSurface = currentReadSurface == surface;
+
+ if (rebindDrawSurface || rebindReadSurface) {
+ eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ }
+
+ eglDestroySurface(eglDisplay, surface);
+
+ EGLConfig config = static_cast<const EglVisual *>(visual)->config;
+ surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL);
+
+ if (rebindDrawSurface || rebindReadSurface) {
+ eglMakeCurrent(eglDisplay, surface, surface, currentContext);
+ }
+ }
+
void
resize(int w, int h) {
if (w == width && h == height) {
waitForEvent(ConfigureNotify);
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
+
+ /*
+ * Some implementations won't update the backbuffer unless we recreate
+ * the EGL surface.
+ */
+
+ int eglWidth;
+ int eglHeight;
+
+ eglQuerySurface(eglDisplay, surface, EGL_WIDTH, &eglWidth);
+ eglQuerySurface(eglDisplay, surface, EGL_HEIGHT, &eglHeight);
+
+ if (eglWidth != width || eglHeight != height) {
+ recreate();
+
+ eglQuerySurface(eglDisplay, surface, EGL_WIDTH, &eglWidth);
+ eglQuerySurface(eglDisplay, surface, EGL_HEIGHT, &eglHeight);
+ }
+
+ assert(eglWidth == width);
+ assert(eglHeight == height);
}
void show(void) {
}
Drawable *
-createDrawable(const Visual *visual, int width, int height)
+createDrawable(const Visual *visual, int width, int height, bool pbuffer)
{
- return new EglDrawable(visual, width, height);
+ return new EglDrawable(visual, width, height, pbuffer);
}
Context *