Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
14QT_BEGIN_NAMESPACE
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
43 HWND hwnd = nullptr;
44 HDC hdc = nullptr;
45};
46
48
50{
52 void apply(QSurfaceFormat *format) const;
53
55 int version = 0; //! majorVersion<<8 + minorVersion
57};
58
59#ifndef QT_NO_DEBUG_STREAM
60QDebug operator<<(QDebug d, const PIXELFORMATDESCRIPTOR &);
61QDebug operator<<(QDebug d, const QWindowsOpenGLContextFormat &);
62QDebug operator<<(QDebug d, const QOpenGLStaticContext &s);
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.
72 BOOL swapBuffers(HDC dc);
73 BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
74 int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
75
76 // WGL
79 HGLRC (WINAPI * wglGetCurrentContext)();
80 HDC (WINAPI * wglGetCurrentDC)();
81 PROC (WINAPI * wglGetProcAddress)(LPCSTR name);
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{
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
125
126 typedef BOOL
127 (APIENTRY *WglSwapInternalExt)(int interval);
128 typedef int
130
131 typedef const char *
133
134 bool hasExtensions() const
135 { return wglGetPixelFormatAttribIVARB && wglChoosePixelFormatARB && wglCreateContextAttribsARB; }
136
137 static QOpenGLStaticContext *create(bool softwareRendering = false);
138 static QByteArray getGlString(unsigned int which);
139
140 QWindowsOpenGLContext *createContext(QOpenGLContext *context) override;
141 QWindowsOpenGLContext *createContext(HGLRC context, HWND window) override;
142 void *moduleHandle() const override { return opengl32.moduleHandle(); }
144 { return QOpenGLContext::LibGL; }
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
150
154 unsigned extensions;
156
163
165};
166
168{
169public:
170 explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, QOpenGLContext *context);
171 explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC context, HWND window);
172
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
210QT_END_NAMESPACE
211
212#endif // QWINDOWSGLCONTEXT_H
Static Open GL context containing version information, extension function pointers,...
BOOL(APIENTRY * WglSwapInternalExt)(int interval)
QWindowsOpenGLContext * createContext(HGLRC context, HWND window) override
const QWindowsOpenGLContextFormat defaultFormat
void * moduleHandle() const override
WglChoosePixelFormatARB wglChoosePixelFormatARB
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
static QOpenGLStaticContext * create(bool softwareRendering=false)
const QByteArray extensionNames
static QWindowsOpengl32DLL opengl32
A temporary context that can be instantiated on the stack.
Singleton container for all relevant information.
Open GL context.
bool isValid() const override
HGLRC nativeContext() const override
void doneCurrent() override
QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC context, HWND window)
QFunctionPointer getProcAddress(const char *procName) override
Reimplement in subclass to allow dynamic querying of OpenGL symbols.
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
Raster or OpenGL Window.
static HGLRC createContext(const QOpenGLStaticContext &staticContext, HDC hdc, const QSurfaceFormat &format, const QWindowsOpenGLAdditionalFormat &, HGLRC shared=nullptr)
static int choosePixelFormat(HDC hdc, const QOpenGLStaticContext &staticContext, const QSurfaceFormat &format, const QWindowsOpenGLAdditionalFormat &additional, PIXELFORMATDESCRIPTOR *obtainedPfd)
static QSurfaceFormat qSurfaceFormatFromHDC(const QOpenGLStaticContext &staticContext, HDC hdc, int pixelFormat, QWindowsOpenGLAdditionalFormat *additionalIn=nullptr)
static PIXELFORMATDESCRIPTOR qPixelFormatFromSurfaceFormat(const QSurfaceFormat &format, const QWindowsOpenGLAdditionalFormat &additional)
static QSurfaceFormat qSurfaceFormatFromPixelFormat(const PIXELFORMATDESCRIPTOR &pfd, QWindowsOpenGLAdditionalFormat *additionalIn=nullptr)
static HGLRC createContext(HDC hdc, HGLRC shared)
static int choosePixelFormat(HDC hdc, const QSurfaceFormat &format, const QWindowsOpenGLAdditionalFormat &additional, PIXELFORMATDESCRIPTOR *obtainedPfd)
#define GL_CONTEXT_PROFILE_MASK
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
#define GL_CONTEXT_CORE_PROFILE_BIT
#define GL_CONTEXT_FLAGS
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
#define GL_CONTEXT_FLAG_DEBUG_BIT
#define GL_VERSION_3_2
#define APIENTRY
Definition qopenglext.h:51
#define GL_NUM_EXTENSIONS
Definition qopenglext.h:906
#define WGL_CONTEXT_MINOR_VERSION_ARB
#define WGL_STENCIL_BITS_ARB
#define WGL_ACCELERATION_ARB
static const QOpenGLContextData * findByHWND(const std::vector< QOpenGLContextData > &data, HWND hwnd)
static bool isDirectRendering(const PIXELFORMATDESCRIPTOR &pfd)
#define WGL_BLUE_BITS_ARB
#define RESET_NOTIFICATION_STRATEGY_ARB
#define WGL_STEREO_ARB
static QOpenGLContextData currentOpenGLContextData()
#define WGL_GREEN_BITS_ARB
static bool hasGLOverlay(const PIXELFORMATDESCRIPTOR &pd)
#define WGL_ALPHA_BITS_ARB
#define WGL_CONTEXT_MAJOR_VERSION_ARB
#define WGL_CONTEXT_PROFILE_MASK_ARB
#define WGL_NO_ACCELERATION_ARB
#define WGL_PIXEL_TYPE_ARB
#define WGL_DEPTH_BITS_ARB
#define ROBUSTNESS_EXTENSION
static bool isAcceptableFormat(const QWindowsOpenGLAdditionalFormat &additional, const PIXELFORMATDESCRIPTOR &pfd, bool ignoreGLSupport=false)
#define WGL_NUMBER_OVERLAYS_ARB
#define WGL_CONTEXT_DEBUG_BIT_ARB
#define WGL_DOUBLE_BUFFER_ARB
static HGLRC createDummyGLContext(HDC dc)
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB
static void initPixelFormatDescriptor(PIXELFORMATDESCRIPTOR *d)
static QOpenGLContextData createDummyWindowOpenGLContextData()
#define WGL_SAMPLES_ARB
#define WGL_DRAW_TO_WINDOW_ARB
static HWND handleOf(QPlatformSurface *s)
#define WGL_TYPE_RGBA_ARB
#define LOSE_CONTEXT_ON_RESET_ARB
#define WGL_CONTEXT_FLAGS_ARB
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
static void describeFormats(HDC hdc)
#define SAMPLE_BUFFER_EXTENSION
bool testFlag(MaskType mask, FlagType flag)
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
#define WGL_FULL_ACCELERATION_ARB
#define WGL_SAMPLE_BUFFERS_ARB
#define WGL_RED_BITS_ARB
static QWindowsWindow * glWindowOf(QPlatformSurface *s)
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
#define WGL_ACCUM_BITS_ARB
static HWND createDummyGLWindow()
#define WGL_COLOR_BITS_ARB
#define WGL_SUPPORT_OPENGL_ARB
QWindowsGLFormatFlags
@ QWindowsGLDirectRendering
@ QWindowsGLAccumBuffer
@ QWindowsGLOverlay
@ QWindowsGLRenderToPixmap
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)
void(APIENTRY *glGetIntegerv)(GLenum pname
QFunctionPointer resolve(const char *name)
void * moduleHandle() const
const GLubyte *APIENTRY * glGetString(GLenum name)
HDC(WINAPI *wglGetCurrentDC)()
bool moduleIsNotOpengl32() const
BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd)