Qt 4.8
qplatformglcontext_qpa.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qplatformglcontext_qpa.h"
43 
44 #include <QtCore/QThreadStorage>
45 #include <QtCore/QThread>
46 
47 #include <QDebug>
48 
50 {
51 public:
53  if (context)
55  }
57 };
58 
60 
62 {
63 public:
65  :qGLContextHandle(0)
66  {
67  }
68 
70  {
71  //do not delete the QGLContext handle here as it is deleted in
72  //QWidgetPrivate::deleteTLSysExtra()
73  }
75  void (*qGLContextDeleteFunction)(void *handle);
77 
78  static void setCurrentContext(QPlatformGLContext *context);
79 };
80 
82 
84 {
85  QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData();
86  if (!threadContext) {
87  if (!QThread::currentThread()) {
88  qWarning("No QTLS available. currentContext wont work");
89  return;
90  }
91  threadContext = new QPlatformGLThreadContext;
92  qplatformgl_context_storage.setLocalData(threadContext);
93  }
94  threadContext->context = context;
95 }
96 
101 {
102  QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData();
103  if(threadContext) {
104  return threadContext->context;
105  }
106  return 0;
107 }
108 
113  :d_ptr(new QPlatformGLContextPrivate())
114 {
115 }
116 
121 {
122  if (QPlatformGLContext::currentContext() == this) {
123  doneCurrent();
124  }
125 
126 }
127 
132 {
134 }
135 
141 {
143 }
144 
145 /*
146  internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant
147  have any type information.
148 */
150 {
151  Q_D(const QPlatformGLContext);
152  return d->qGLContextHandle;
153 }
154 
155 void QPlatformGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *))
156 {
158  d->qGLContextHandle = handle;
159  d->qGLContextDeleteFunction = qGLContextDeleteFunction;
160 }
161 
163 {
165  if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
166  d->qGLContextDeleteFunction(d->qGLContextHandle);
167  d->qGLContextDeleteFunction = 0;
168  d->qGLContextHandle = 0;
169  }
170 }
171 
static const QPlatformGLContext * currentContext()
Returns the last context which called makeCurrent.
double d
Definition: qnumeric_p.h:62
virtual void doneCurrent()
Reimplement in subclass to release current context.
static QThreadStorage< QPlatformGLThreadContext * > qplatformgl_context_storage
static void setCurrentContext(QPlatformGLContext *context)
#define Q_D(Class)
Definition: qglobal.h:2482
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
T & localData()
Returns a reference to the data that was set by the calling thread.
Q_CORE_EXPORT void qWarning(const char *,...)
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
virtual ~QPlatformGLContext()
If this is the current context for the thread, doneCurrent is called.
The QPlatformGLContext class provides an abstraction for native GL contexts.
static QPlatformGLContext * staticSharedContext
void setLocalData(T t)
Sets the local data for the calling thread to data.
void setQGLContextHandle(void *handle, void(*qGLContextDeleteFunction)(void *))
QPlatformGLContext()
All subclasses needs to specify the platformWindow.
The QThreadStorage class provides per-thread data storage.