Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsglcontext.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWINDOWSGLCONTEXT_H
5#define QWINDOWSGLCONTEXT_H
6
7#include <QtCore/qt_windows.h>
9
10#include <QtGui/qopenglcontext.h>
11
12#include <vector>
13
15#ifndef QT_NO_OPENGL
16
17class QDebug;
18
26
27// Additional format information for Windows.
29{
30 QWindowsOpenGLAdditionalFormat(unsigned formatFlagsIn = 0, unsigned pixmapDepthIn = 0) :
31 formatFlags(formatFlagsIn), pixmapDepth(pixmapDepthIn) { }
32 unsigned formatFlags; // QWindowsGLFormatFlags.
33 unsigned pixmapDepth; // for QWindowsGLRenderToPixmap
34};
35
36// Per-window data for active OpenGL contexts.
38{
39 QOpenGLContextData(HGLRC r, HWND h, HDC d) : renderingContext(r), hwnd(h), hdc(d) {}
41
42 HGLRC renderingContext = nullptr;
43 HWND hwnd = nullptr;
44 HDC hdc = nullptr;
45};
46
48
58
59#ifndef QT_NO_DEBUG_STREAM
60QDebug operator<<(QDebug d, const PIXELFORMATDESCRIPTOR &);
63#endif
64
66{
67 bool init(bool softwareRendering);
68 void *moduleHandle() const { return m_lib; }
69 bool moduleIsNotOpengl32() const { return m_nonOpengl32; }
70
71 // Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc.
73 BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
74 int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
75
76 // WGL
77 HGLRC (WINAPI * wglCreateContext)(HDC dc);
78 BOOL (WINAPI * wglDeleteContext)(HGLRC context);
79 HGLRC (WINAPI * wglGetCurrentContext)();
80 HDC (WINAPI * wglGetCurrentDC)();
81 PROC (WINAPI * wglGetProcAddress)(LPCSTR name);
82 BOOL (WINAPI * wglMakeCurrent)(HDC dc, HGLRC context);
83 BOOL (WINAPI * wglShareLists)(HGLRC context1, HGLRC context2);
84
85 // GL1+GLES2 common
86 GLenum (APIENTRY * glGetError)();
87 void (APIENTRY * glGetIntegerv)(GLenum pname, GLint* params);
88 const GLubyte * (APIENTRY * glGetString)(GLenum name);
89
90 QFunctionPointer resolve(const char *name);
91private:
92 HMODULE m_lib;
93 bool m_nonOpengl32;
94
95 // For Mesa llvmpipe shipped with a name other than opengl32.dll
96 BOOL (WINAPI * wglSwapBuffers)(HDC dc);
97 BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
98 int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
99};
100
102{
103 Q_DISABLE_COPY_MOVE(QOpenGLStaticContext)
105public:
112
113 typedef bool
115 (HDC hdc, int iPixelFormat, int iLayerPlane,
116 uint nAttributes, const int *piAttributes, int *piValues);
117
118 typedef bool
119 (APIENTRY *WglChoosePixelFormatARB)(HDC hdc, const int *piAttribList,
120 const float *pfAttribFList, uint nMaxFormats, int *piFormats,
121 UINT *nNumFormats);
122
123 typedef HGLRC
124 (APIENTRY *WglCreateContextAttribsARB)(HDC, HGLRC, const int *);
125
126 typedef BOOL
127 (APIENTRY *WglSwapInternalExt)(int interval);
128 typedef int
130
131 typedef const char *
133
136
137 static QOpenGLStaticContext *create(bool softwareRendering = false);
138 static QByteArray getGlString(unsigned int which);
139
141 QWindowsOpenGLContext *createContext(HGLRC context, HWND window) override;
142 void *moduleHandle() const override { return opengl32.moduleHandle(); }
145
146 // For a regular opengl32.dll report the ThreadedOpenGL capability.
147 // For others, which are likely to be software-only, don't.
148 bool supportsThreadedOpenGL() const override
149 { return !opengl32.moduleIsNotOpengl32(); }
150
154 unsigned extensions;
156
163
165};
166
168{
169public:
171 explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC context, HWND window);
172
173 ~QWindowsGLContext() override;
174 bool isSharing() const override { return context()->shareHandle(); }
175 bool isValid() const override { return m_renderingContext && !m_lost; }
176 QSurfaceFormat format() const override { return m_obtainedFormat; }
177
178 void swapBuffers(QPlatformSurface *surface) override;
179
180 bool makeCurrent(QPlatformSurface *surface) override;
181 void doneCurrent() override;
182
183 typedef void (*GL_Proc) ();
184
185 QFunctionPointer getProcAddress(const char *procName) override;
186
187 HGLRC renderingContext() const { return m_renderingContext; }
188
189 HGLRC nativeContext() const override { return m_renderingContext; }
190
191private:
192 typedef GLenum (APIENTRY *GlGetGraphicsResetStatusArbType)();
193
194 inline void releaseDCs();
195 bool updateObtainedParams(HDC hdc, int *obtainedSwapInterval = nullptr);
196
197 QOpenGLStaticContext *m_staticContext = nullptr;
198 QSurfaceFormat m_obtainedFormat;
199 HGLRC m_renderingContext = nullptr;
200 std::vector<QOpenGLContextData> m_windowContexts;
201 PIXELFORMATDESCRIPTOR m_obtainedPixelFormatDescriptor;
202 int m_pixelFormat = 0;
203 bool m_extensionsUsed = false;
204 int m_swapInterval = -1;
205 bool m_ownsContext = true;
206 GlGetGraphicsResetStatusArbType m_getGraphicsResetStatus = nullptr;
207 bool m_lost = false;
208};
209#endif
211
212#endif // QWINDOWSGLCONTEXT_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inheaderfile QOpenGLContext
\inmodule QtGui
OpenGLModuleType
This enum defines the type of the underlying OpenGL implementation.
QPlatformOpenGLContext * shareHandle() const
Returns the underlying platform context with which this context is sharing.
Static Open GL context containing version information, extension function pointers,...
BOOL(APIENTRY * WglSwapInternalExt)(int interval)
const QWindowsOpenGLContextFormat defaultFormat
void * moduleHandle() const override
WglChoosePixelFormatARB wglChoosePixelFormatARB
const char *(APIENTRY * WglGetExtensionsStringARB)(HDC)
WglCreateContextAttribsARB wglCreateContextAttribsARB
static QByteArray getGlString(unsigned int which)
QOpenGLContext::OpenGLModuleType moduleType() const override
HGLRC(APIENTRY * WglCreateContextAttribsARB)(HDC, HGLRC, const int *)
WglGetExtensionsStringARB wglGetExtensionsStringARB
WglGetSwapInternalExt wglGetSwapInternalExt
const QByteArray renderer
QWindowsOpenGLContext * createContext(QOpenGLContext *context) override
const QByteArray vendor
WglGetPixelFormatAttribIVARB wglGetPixelFormatAttribIVARB
bool(APIENTRY * WglGetPixelFormatAttribIVARB)(HDC hdc, int iPixelFormat, int iLayerPlane, uint nAttributes, const int *piAttributes, int *piValues)
WglSwapInternalExt wglSwapInternalExt
bool supportsThreadedOpenGL() const override
bool(APIENTRY * WglChoosePixelFormatARB)(HDC hdc, const int *piAttribList, const float *pfAttribFList, uint nMaxFormats, int *piFormats, UINT *nNumFormats)
int(APIENTRY * WglGetSwapInternalExt)(void)
const QByteArray extensionNames
static QWindowsOpengl32DLL opengl32
QOpenGLContext * context() const
The QPlatformSurface class provides an abstraction for a surface.
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
OpenGLContextProfile
This enum is used to specify the OpenGL context profile, in conjunction with QSurfaceFormat::setMajor...
Open GL context.
bool isValid() const override
HGLRC nativeContext() const override
void doneCurrent() override
bool makeCurrent(QPlatformSurface *surface) override
QWindowsGLContext(QOpenGLStaticContext *staticContext, QOpenGLContext *context)
QSurfaceFormat format() const override
void swapBuffers(QPlatformSurface *surface) override
Reimplement in subclass to native swap buffers calls.
bool isSharing() const override
HGLRC renderingContext() const
static QWindowsStaticOpenGLContext * create()
Combined button and popup list for selecting options.
static void * context
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
typedef GLint(GL_APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXEXTPROC)(GLuint program
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLenum pname
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLuint name
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
#define APIENTRY
Definition qopenglext.h:51
const void * getProcAddress
unsigned int uint
Definition qtypes.h:34
HINSTANCE HMODULE
QDebug operator<<(QDebug d, const PIXELFORMATDESCRIPTOR &)
QWindowsGLFormatFlags
@ QWindowsGLDirectRendering
@ QWindowsGLAccumBuffer
@ QWindowsGLOverlay
@ QWindowsGLRenderToPixmap
aWidget window() -> setWindowTitle("New Window Title")
[2]
QOpenGLContextData(HGLRC r, HWND h, HDC d)
Additional format information that is not in QSurfaceFormat.
QWindowsOpenGLAdditionalFormat(unsigned formatFlagsIn=0, unsigned pixmapDepthIn=0)
QSurfaceFormat::FormatOptions options
majorVersion<<8 + minorVersion
QSurfaceFormat::OpenGLContextProfile profile
static QWindowsOpenGLContextFormat current()
void apply(QSurfaceFormat *format) const
bool init(bool softwareRendering)
int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd)
BOOL(WINAPI *wglDeleteContext)(HGLRC context)
GLenum(APIENTRY *glGetError)()
PROC(WINAPI *wglGetProcAddress)(LPCSTR name)
HGLRC(WINAPI *wglCreateContext)(HDC dc)
BOOL(WINAPI *wglMakeCurrent)(HDC dc
QFunctionPointer resolve(const char *name)
void * moduleHandle() const
const GLubyte *APIENTRY * glGetString(GLenum name)
HGLRC(WINAPI *wglGetCurrentContext)()
HDC(WINAPI *wglGetCurrentDC)()
BOOL(WINAPI *wglShareLists)(HGLRC context1
bool moduleIsNotOpengl32() const
BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd)