~gerboland/qtubuntu/enable-debug-mode

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/glcontext.cpp

  • Committer: Gerry Boland
  • Date: 2016-04-12 13:10:43 UTC
  • mfrom: (280.2.34 enable-debug-mode)
  • Revision ID: gerry.boland@canonical.com-20160412131043-t14zmcbheuxclmhr
Merge lp:~dandrader/qtubuntu/enable-debug-mode, he kindly fixed merging this with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2014 Canonical, Ltd.
 
2
 * Copyright (C) 2014-2016 Canonical, Ltd.
3
3
 *
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
15
15
 */
16
16
 
17
17
#include "glcontext.h"
 
18
#include "logging.h"
 
19
#include "offscreensurface.h"
18
20
#include "window.h"
19
 
#include "logging.h"
 
21
 
 
22
#include <QOpenGLFramebufferObject>
20
23
#include <QtPlatformSupport/private/qeglconvenience_p.h>
21
24
 
22
 
#if !defined(QT_NO_DEBUG)
23
25
static void printOpenGLESConfig() {
24
26
  static bool once = true;
25
27
  if (once) {
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);
36
38
    once = false;
37
39
  }
38
40
}
39
 
#endif
40
41
 
41
42
static EGLenum api_in_use()
42
43
{
62
63
 
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);
66
67
}
67
68
 
68
69
UbuntuOpenGLContext::~UbuntuOpenGLContext()
72
73
 
73
74
bool UbuntuOpenGLContext::makeCurrent(QPlatformSurface* surface)
74
75
{
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);
80
 
#else
81
 
    ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
82
 
    ASSERT(eglMakeCurrent(mEglDisplay, eglSurface, eglSurface, mEglContext) == EGL_TRUE);
83
 
    printOpenGLESConfig();
84
 
#endif
85
 
    return true;
 
76
    Q_ASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface);
 
77
 
 
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);
 
83
        }
 
84
        return offscreen->buffer()->bind();
 
85
    } else {
 
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();
 
91
        }
 
92
        return true;
 
93
    }
86
94
}
87
95
 
88
96
void UbuntuOpenGLContext::doneCurrent()
89
97
{
90
 
#if defined(QT_NO_DEBUG)
91
 
    eglBindAPI(api_in_use());
92
 
    eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
93
 
#else
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);
96
 
#endif
97
100
}
98
101
 
99
102
void UbuntuOpenGLContext::swapBuffers(QPlatformSurface* surface)
101
104
    UbuntuWindow *ubuntuWindow = static_cast<UbuntuWindow*>(surface);
102
105
 
103
106
    EGLSurface eglSurface = ubuntuWindow->eglSurface();
104
 
#if defined(QT_NO_DEBUG)
105
 
    eglBindAPI(api_in_use());
106
 
    eglSwapBuffers(mEglDisplay, eglSurface);
107
 
#else
108
107
    ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
109
108
    ASSERT(eglSwapBuffers(mEglDisplay, eglSurface) == EGL_TRUE);
110
 
#endif
111
109
 
112
110
    ubuntuWindow->onSwapBuffersDone();
113
111
}
114
112
 
115
113
void (*UbuntuOpenGLContext::getProcAddress(const QByteArray& procName)) ()
116
114
{
117
 
#if defined(QT_NO_DEBUG)
118
 
    eglBindAPI(api_in_use());
119
 
#else
120
115
    ASSERT(eglBindAPI(api_in_use()) == EGL_TRUE);
121
 
#endif
122
116
    return eglGetProcAddress(procName.constData());
123
117
}