2
* Copyright (C) 2014 Canonical, Ltd.
2
* Copyright (C) 2014-2016 Canonical, Ltd.
4
4
* This program is free software: you can redistribute it and/or modify it under
5
5
* the terms of the GNU Lesser General Public License version 3, as published by
17
17
#include "glcontext.h"
19
#include "offscreensurface.h"
18
20
#include "window.h"
22
#include <QOpenGLFramebufferObject>
20
23
#include <QtPlatformSupport/private/qeglconvenience_p.h>
22
#if !defined(QT_NO_DEBUG)
23
25
static void printOpenGLESConfig() {
24
26
static bool once = true;
26
28
const char* string = (const char*) glGetString(GL_VENDOR);
27
LOG("OpenGL ES vendor: %s", string);
29
qCDebug(ubuntumirclient, "OpenGL ES vendor: %s", string);
28
30
string = (const char*) glGetString(GL_RENDERER);
29
LOG("OpenGL ES renderer: %s", string);
31
qCDebug(ubuntumirclient, "OpenGL ES renderer: %s", string);
30
32
string = (const char*) glGetString(GL_VERSION);
31
LOG("OpenGL ES version: %s", string);
33
qCDebug(ubuntumirclient, "OpenGL ES version: %s", string);
32
34
string = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
33
LOG("OpenGL ES Shading Language version: %s", string);
35
qCDebug(ubuntumirclient, "OpenGL ES Shading Language version: %s", string);
34
36
string = (const char*) glGetString(GL_EXTENSIONS);
35
LOG("OpenGL ES extensions: %s", string);
37
qCDebug(ubuntumirclient, "OpenGL ES extensions: %s", string);
41
42
static EGLenum api_in_use()
63
64
mEglContext = eglCreateContext(mEglDisplay, screen->eglConfig(), share ? share->eglContext() : EGL_NO_CONTEXT,
64
65
attribs.constData());
65
DASSERT(mEglContext != EGL_NO_CONTEXT);
66
Q_ASSERT(mEglContext != EGL_NO_CONTEXT);
68
69
UbuntuOpenGLContext::~UbuntuOpenGLContext()
73
74
bool UbuntuOpenGLContext::makeCurrent(QPlatformSurface* surface)
75
DASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface);
76
EGLSurface eglSurface = static_cast<UbuntuWindow*>(surface)->eglSurface();
77
#if defined(QT_NO_DEBUG)
78
eglBindAPI(api_in_use());
79
eglMakeCurrent(mEglDisplay, eglSurface, eglSurface, mEglContext);
81
ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
82
ASSERT(eglMakeCurrent(mEglDisplay, eglSurface, eglSurface, mEglContext) == EGL_TRUE);
83
printOpenGLESConfig();
76
Q_ASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface);
78
if (surface->surface()->surfaceClass() == QSurface::Offscreen) {
79
auto offscreen = static_cast<UbuntuOffscreenSurface *>(surface);
80
if (!offscreen->buffer()) {
81
auto buffer = new QOpenGLFramebufferObject(surface->surface()->size());
82
offscreen->setBuffer(buffer);
84
return offscreen->buffer()->bind();
86
EGLSurface eglSurface = static_cast<UbuntuWindow*>(surface)->eglSurface();
87
ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
88
ASSERT(eglMakeCurrent(mEglDisplay, eglSurface, eglSurface, mEglContext) == EGL_TRUE);
89
if (ubuntumirclient().isDebugEnabled()) {
90
printOpenGLESConfig();
88
96
void UbuntuOpenGLContext::doneCurrent()
90
#if defined(QT_NO_DEBUG)
91
eglBindAPI(api_in_use());
92
eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
94
98
ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
95
99
ASSERT(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_TRUE);
99
102
void UbuntuOpenGLContext::swapBuffers(QPlatformSurface* surface)
101
104
UbuntuWindow *ubuntuWindow = static_cast<UbuntuWindow*>(surface);
103
106
EGLSurface eglSurface = ubuntuWindow->eglSurface();
104
#if defined(QT_NO_DEBUG)
105
eglBindAPI(api_in_use());
106
eglSwapBuffers(mEglDisplay, eglSurface);
108
107
ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
109
108
ASSERT(eglSwapBuffers(mEglDisplay, eglSurface) == EGL_TRUE);
112
110
ubuntuWindow->onSwapBuffersDone();
115
113
void (*UbuntuOpenGLContext::getProcAddress(const QByteArray& procName)) ()
117
#if defined(QT_NO_DEBUG)
118
eglBindAPI(api_in_use());
120
115
ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
122
116
return eglGetProcAddress(procName.constData());