47 #include <QtCore/QDebug> 48 #include <QtGui/QWidget> 51 #include <xcb/xfixes.h> 53 #define MESA_EGL_NO_X11_HEADERS 54 #define EGL_EGLEXT_PROTOTYPES 56 #include <EGL/eglext.h> 58 #define GL_GLEXT_PROTOTYPES 59 #include <GLES2/gl2.h> 60 #include <GLES2/gl2ext.h> 94 static const EGLint contextAttribs[] = {
95 EGL_CONTEXT_CLIENT_VERSION, 2,
99 eglBindAPI(EGL_OPENGL_ES_API);
101 EGLContext shareContext = EGL_NO_CONTEXT;
102 if (window->
widget()->platformWindowFormat().sharedGLContext()) {
106 d->eglContext = eglCreateContext(EGL_DISPLAY_FROM_XCB(
d->qXcbWindow), NULL,
107 shareContext, contextAttribs);
109 if (
d->eglContext == EGL_NO_CONTEXT) {
110 qDebug() <<
"No eglContext!" << eglGetError();
113 EGLBoolean makeCurrentSuccess = eglMakeCurrent(EGL_DISPLAY_FROM_XCB(
d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,
d->eglContext);
114 if (!makeCurrentSuccess) {
115 qDebug() <<
"eglMakeCurrent failed!" << eglGetError();
118 xcb_dri2_create_drawable (
d->xcbConnection(),
d->xcbWindow());
130 resize(
d->qXcbWindow->widget()->geometry().size());
152 eglMakeCurrent(EGL_DISPLAY_FROM_XCB(
d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,
d->eglContext);
161 eglMakeCurrent(EGL_DISPLAY_FROM_XCB(
d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
167 xcb_rectangle_t rectangle;
170 rectangle.width =
d->qXcbWindow->widget()->geometry().width();
171 rectangle.height =
d->qXcbWindow->widget()->geometry().height();
173 xcb_xfixes_region_t xfixesRegion = xcb_generate_id(
d->xcbConnection());
174 xcb_xfixes_create_region(
d->xcbConnection(), xfixesRegion,
177 xcb_dri2_copy_region_cookie_t cookie = xcb_dri2_copy_region_unchecked(
d->xcbConnection(),
178 d->qXcbWindow->window(),
180 XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
181 XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
183 xcb_dri2_copy_region_reply_t *reply = xcb_dri2_copy_region_reply(
d->xcbConnection(),cookie,NULL);
187 xcb_xfixes_destroy_region(
d->xcbConnection(), xfixesRegion);
193 return (
void *)eglGetProcAddress(
qPrintable(procName));
203 xcb_dri2_dri2_buffer_t *backBfr =
backBuffer();
206 qDebug() <<
"destroing image";
210 EGLint imgAttribs[] = {
211 EGL_WIDTH,
d->size.width(),
212 EGL_HEIGHT,
d->size.height(),
213 EGL_DRM_BUFFER_STRIDE_MESA, backBfr->pitch /4,
214 EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
236 return d->windowFormat;
243 unsigned int backBufferAttachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT;
244 xcb_dri2_get_buffers_cookie_t cookie = xcb_dri2_get_buffers_unchecked (
d->xcbConnection(),
246 1, 1, &backBufferAttachment);
248 xcb_dri2_get_buffers_reply_t *reply = xcb_dri2_get_buffers_reply (
d->xcbConnection(), cookie, NULL);
250 qDebug() <<
"failed to get buffers reply";
254 xcb_dri2_dri2_buffer_t *buffers = xcb_dri2_get_buffers_buffers (reply);
256 qDebug() <<
"failed to get buffers";
270 return d->eglContext;
static const QPlatformGLContext * currentContext()
Returns the last context which called makeCurrent.
QPointer< QWidget > widget
QDri2ContextPrivate(QXcbWindow *window)
virtual void doneCurrent()
Reimplement in subclass to release current context.
xcb_connection_t * xcb_connection() const
#define glGenRenderbuffers
The QString class provides a Unicode character string.
QPlatformWindowFormat platformWindowFormat() const
QWidget has the function qplatformWindowFormat().
#define glBindFramebuffer
#define GL_DEPTH_ATTACHMENT
Q_CORE_EXPORT void qDebug(const char *,...)
Q_GUI_EXPORT EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
void doneCurrent()
Reimplement in subclass to release current context.
#define glGenFramebuffers
void * eglContext() const
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void resize(const QSize &size)
#define glBindRenderbuffer
QPlatformWindowFormat windowFormat
#define glEGLImageTargetRenderbufferStorageOES
The QPlatformGLContext class provides an abstraction for native GL contexts.
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
xcb_window_t window() const
QDri2Context(QXcbWindow *window)
#define GL_STENCIL_ATTACHMENT
#define GL_COLOR_ATTACHMENT0
#define glFramebufferRenderbuffer
The QSize class defines the size of a two-dimensional object using integer point precision.
Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
void * getProcAddress(const QString &procName)
Reimplement in subclass to native getProcAddr calls.
xcb_connection_t * xcbConnection()
#define qPrintable(string)
#define glRenderbufferStorage
xcb_dri2_dri2_buffer_t * backBuffer()