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// Qt-Security score:significant reason:default
4
5#ifndef QWINDOWSGLCONTEXT_H
6#define QWINDOWSGLCONTEXT_H
7
8#include <QtCore/qt_windows.h>
10
11#include <QtGui/qopenglcontext.h>
12
13#include <vector>
14
15QT_BEGIN_NAMESPACE
16#ifndef QT_NO_OPENGL
17
18class QDebug;
19
27
28// Additional format information for Windows.
30{
31 QWindowsOpenGLAdditionalFormat(unsigned formatFlagsIn = 0, unsigned pixmapDepthIn = 0) :
32 formatFlags(formatFlagsIn), pixmapDepth(pixmapDepthIn) { }
33 unsigned formatFlags; // QWindowsGLFormatFlags.
34 unsigned pixmapDepth; // for QWindowsGLRenderToPixmap
35};
36
37// Per-window data for active OpenGL contexts.
39{
40 QOpenGLContextData(HGLRC r, HWND h, HDC d) : renderingContext(r), hwnd(h), hdc(d) {}
42
44 HWND hwnd = nullptr;
45 HDC hdc = nullptr;
46};
47
49
51{
53 void apply(QSurfaceFormat *format) const;
54
56 int version = 0; //! majorVersion<<8 + minorVersion
58};
59
60#ifndef QT_NO_DEBUG_STREAM
61QDebug operator<<(QDebug d, const PIXELFORMATDESCRIPTOR &);
62QDebug operator<<(QDebug d, const QWindowsOpenGLContextFormat &);
63QDebug operator<<(QDebug d, const QOpenGLStaticContext &s);
64#endif
65
67{
68 bool init(bool softwareRendering);
69 void *moduleHandle() const { return m_lib; }
70 bool moduleIsNotOpengl32() const { return m_nonOpengl32; }
71
72 // Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc.
73 BOOL swapBuffers(HDC dc);
74 BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
75 int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
76
77 // WGL
80 HGLRC (WINAPI * wglGetCurrentContext)();
81 HDC (WINAPI * wglGetCurrentDC)();
82 PROC (WINAPI * wglGetProcAddress)(LPCSTR name);
84 BOOL (WINAPI * wglShareLists)(HGLRC context1, HGLRC context2);
85
86 // GL1+GLES2 common
87 GLenum (APIENTRY * glGetError)();
88 void (APIENTRY * glGetIntegerv)(GLenum pname, GLint* params);
89 const GLubyte * (APIENTRY * glGetString)(GLenum name);
90
91 QFunctionPointer resolve(const char *name);
92private:
93 HMODULE m_lib;
94 bool m_nonOpengl32;
95
96 // For Mesa llvmpipe shipped with a name other than opengl32.dll
97 BOOL (WINAPI * wglSwapBuffers)(HDC dc);
98 BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
99 int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
100};
101
103{
106public:
113
114 typedef bool
116 (HDC hdc, int iPixelFormat, int iLayerPlane,
117 uint nAttributes, const int *piAttributes, int *piValues);
118
119 typedef bool
120 (APIENTRY *WglChoosePixelFormatARB)(HDC hdc, const int *piAttribList,
121 const float *pfAttribFList, uint nMaxFormats, int *piFormats,
122 UINT *nNumFormats);
123
124 typedef HGLRC
126
127 typedef BOOL
128 (APIENTRY *WglSwapInternalExt)(int interval);
129 typedef int
131
132 typedef const char *
134
135 bool hasExtensions() const
136 { return wglGetPixelFormatAttribIVARB && wglChoosePixelFormatARB && wglCreateContextAttribsARB; }
137
138 static QOpenGLStaticContext *create(bool softwareRendering = false);
139 static QByteArray getGlString(unsigned int which);
140
141 QWindowsOpenGLContext *createContext(QOpenGLContext *context) override;
142 QWindowsOpenGLContext *createContext(HGLRC context, HWND window) override;
143 void *moduleHandle() const override { return opengl32.moduleHandle(); }
145 { return QOpenGLContext::LibGL; }
146
147 // For a regular opengl32.dll report the ThreadedOpenGL capability.
148 // For others, which are likely to be software-only, don't.
149 bool supportsThreadedOpenGL() const override
151
155 unsigned extensions;
157
164
166};
167
169{
170public:
171 explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, QOpenGLContext *context);
172 explicit QWindowsGLContext(QOpenGLStaticContext *staticContext, HGLRC context, HWND window);
173
175 bool isSharing() const override { return context()->shareHandle(); }
176 bool isValid() const override { return m_renderingContext && !m_lost; }
177 QSurfaceFormat format() const override { return m_obtainedFormat; }
178
179 void swapBuffers(QPlatformSurface *surface) override;
180
181 bool makeCurrent(QPlatformSurface *surface) override;
182 void doneCurrent() override;
183
184 typedef void (*GL_Proc) ();
185
186 QFunctionPointer getProcAddress(const char *procName) override;
187
188 HGLRC renderingContext() const { return m_renderingContext; }
189
190 HGLRC nativeContext() const override { return m_renderingContext; }
191
192private:
193 typedef GLenum (APIENTRY *GlGetGraphicsResetStatusArbType)();
194
195 inline void releaseDCs();
196 bool updateObtainedParams(HDC hdc, int *obtainedSwapInterval = nullptr);
197
198 QOpenGLStaticContext *m_staticContext = nullptr;
199 QSurfaceFormat m_obtainedFormat;
200 HGLRC m_renderingContext = nullptr;
201 std::vector<QOpenGLContextData> m_windowContexts;
202 PIXELFORMATDESCRIPTOR m_obtainedPixelFormatDescriptor;
203 int m_pixelFormat = 0;
204 bool m_extensionsUsed = false;
205 int m_swapInterval = -1;
206 bool m_ownsContext = true;
207 GlGetGraphicsResetStatusArbType m_getGraphicsResetStatus = nullptr;
208 bool m_lost = false;
209};
210#endif
211QT_END_NAMESPACE
212
213#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.
static QWindowsContext * instance()
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)