Blender V5.3
GHOST_ContextWGL.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "GHOST_ContextWGL.hh"
12
13#include <tchar.h>
14
15#include <cassert>
16#include <cstdio>
17#include <vector>
18
19HGLRC GHOST_ContextWGL::s_sharedHGLRC = nullptr;
20int GHOST_ContextWGL::s_sharedCount = 0;
21std::list<GHOST_ContextWGL::OffscreenWindowHandle>
22 GHOST_ContextWGL::s_sharedOffscreenWindowHandles;
23
24/* Some third-generation Intel video-cards are constantly bring problems */
26{
27 return strstr((const char *)glGetString(GL_VENDOR), "Intel") != nullptr;
28}
29
31 bool alphaBackground,
32 HWND hWnd,
33 HDC hDC,
34 int contextProfileMask,
35 int contextMajorVersion,
36 int contextMinorVersion,
37 int contextFlags,
38 int contextResetNotificationStrategy)
39 : GHOST_Context(context_params),
40 h_wnd_(hWnd),
41 h_DC_(hDC),
42 context_profile_mask_(contextProfileMask),
43 context_major_version_(contextMajorVersion),
44 context_minor_version_(contextMinorVersion),
45 context_flags_(contextFlags),
46 alpha_background_(alphaBackground),
47 context_reset_notification_strategy_(contextResetNotificationStrategy),
48 h_GLRC_(nullptr),
49#ifndef NDEBUG
50 dummy_vendor_(nullptr),
51 dummy_renderer_(nullptr),
52 dummy_version_(nullptr),
53#endif
54 offscreen_window_handle_(nullptr)
55{
56 if (h_wnd_ == nullptr) {
57 /* For offscreen context, OpenGL needs a dummy window to create a context on windows.
58 * Create or reuse an existing one. */
59 for (OffscreenWindowHandle &handle : s_sharedOffscreenWindowHandles) {
60 if (!handle.used) {
61 offscreen_window_handle_ = &handle;
62 break;
63 }
64 }
65 if (offscreen_window_handle_ == nullptr) {
66 offscreen_window_handle_ = &s_sharedOffscreenWindowHandles.emplace_back();
67 }
68 offscreen_window_handle_->used = true;
69 h_wnd_ = offscreen_window_handle_->h_wnd;
70 h_DC_ = offscreen_window_handle_->h_DC;
71 }
72
73 assert(h_DC_ != nullptr);
74}
75
77{
78 if (h_GLRC_ != nullptr) {
79 if (h_GLRC_ == ::wglGetCurrentContext()) {
80 WIN32_CHK(::wglMakeCurrent(nullptr, nullptr));
81 }
82
83 if (h_GLRC_ != s_sharedHGLRC || s_sharedCount == 1) {
84 assert(s_sharedCount > 0);
85
86 s_sharedCount--;
87
88 if (s_sharedCount == 0) {
89 s_sharedHGLRC = nullptr;
90 }
91
92 WIN32_CHK(::wglDeleteContext(h_GLRC_));
93 }
94 }
95
97
98#ifndef NDEBUG
99 if (dummy_renderer_) {
100 free((void *)dummy_renderer_);
101 free((void *)dummy_vendor_);
102 free((void *)dummy_version_);
103 }
104#endif
105}
106
108{
109 return WIN32_CHK(::SwapBuffers(h_DC_)) ? GHOST_kSuccess : GHOST_kFailure;
110}
111
113{
114 if (epoxy_has_wgl_extension(h_DC_, "WGL_EXT_swap_control")) {
115 return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
116 }
117 else {
118 return GHOST_kFailure;
119 }
120}
121
123{
124 if (epoxy_has_wgl_extension(h_DC_, "WGL_EXT_swap_control")) {
125 interval_out = ::wglGetSwapIntervalEXT();
126 return GHOST_kSuccess;
127 }
128 else {
129 return GHOST_kFailure;
130 }
131}
132
134{
135 if (WIN32_CHK(::wglMakeCurrent(h_DC_, h_GLRC_))) {
136 active_context_ = this;
137 return GHOST_kSuccess;
138 }
139 else {
140 return GHOST_kFailure;
141 }
142}
143
145{
146 /* Calling wglMakeCurrent(nullptr, nullptr) without an active context returns an error,
147 * so we always pass the device context handle. */
148 if (WIN32_CHK(::wglMakeCurrent(h_DC_, nullptr))) {
149 active_context_ = nullptr;
150 return GHOST_kSuccess;
151 }
152 else {
153 return GHOST_kFailure;
154 }
155}
156
157/* Ron Fosner's code for weighting pixel formats and forcing software.
158 * See http://www.opengl.org/resources/faq/technical/weight.cpp
159 */
160static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd, PIXELFORMATDESCRIPTOR &preferredPFD)
161{
162 int weight = 0;
163
164 /* assume desktop color depth is 32 bits per pixel */
165
166 /* cull unusable pixel formats */
167 /* if no formats can be found, can we determine why it was rejected? */
168 if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL) || !(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
169 !(pfd.dwFlags & PFD_DOUBLEBUFFER) || /* Blender _needs_ this. */
170 !(pfd.iPixelType == PFD_TYPE_RGBA) ||
171 (pfd.cColorBits > 32) || /* 64 bit formats disable AERO. */
172 (pfd.dwFlags & PFD_GENERIC_FORMAT)) /* No software renderers. */
173 {
174 return 0;
175 }
176
177 weight = 1; /* it's usable */
178
179 weight += pfd.cColorBits - 8;
180
181 if (preferredPFD.cAlphaBits > 0 && pfd.cAlphaBits > 0) {
182 weight++;
183 }
184
185 return weight;
186}
187
188/*
189 * A modification of Ron Fosner's replacement for ChoosePixelFormat
190 * returns 0 on error, else returns the pixel format number to be used
191 */
192static int choose_pixel_format_legacy(HDC hDC, PIXELFORMATDESCRIPTOR &preferredPFD)
193{
194 int iPixelFormat = 0;
195 int weight = 0;
196
197 int iStereoPixelFormat = 0;
198 int stereoWeight = 0;
199
200 /* choose a pixel format using the useless Windows function in case we come up empty handed */
201 int iLastResortPixelFormat = ::ChoosePixelFormat(hDC, &preferredPFD);
202
203 WIN32_CHK(iLastResortPixelFormat != 0);
204
205 int lastPFD = ::DescribePixelFormat(hDC, 1, sizeof(PIXELFORMATDESCRIPTOR), nullptr);
206
207 WIN32_CHK(lastPFD != 0);
208
209 for (int i = 1; i <= lastPFD; i++) {
210 PIXELFORMATDESCRIPTOR pfd;
211 int check = ::DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
212
213 WIN32_CHK(check == lastPFD);
214
215 int w = weight_pixel_format(pfd, preferredPFD);
216
217 if (w > weight) {
218 weight = w;
219 iPixelFormat = i;
220 }
221
222 if (w > stereoWeight && (preferredPFD.dwFlags & pfd.dwFlags & PFD_STEREO)) {
223 stereoWeight = w;
224 iStereoPixelFormat = i;
225 }
226 }
227
228 /* choose any available stereo format over a non-stereo format */
229 if (iStereoPixelFormat != 0) {
230 iPixelFormat = iStereoPixelFormat;
231 }
232
233 if (iPixelFormat == 0) {
234 fprintf(stderr, "Warning! Using result of ChoosePixelFormat.\n");
235 iPixelFormat = iLastResortPixelFormat;
236 }
237
238 return iPixelFormat;
239}
240
246static HWND clone_window(HWND hWnd, LPVOID lpParam)
247{
248 int count;
249
250 SetLastError(NO_ERROR);
251
252 DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
253 WIN32_CHK(GetLastError() == NO_ERROR);
254
255 /* The maximum length for WNDCLASSEXW.lpszClassName is 256. */
256 WCHAR lpClassName[257] = L"";
257 count = GetClassNameW(hWnd, lpClassName, sizeof(lpClassName) / sizeof(WCHAR));
258 WIN32_CHK(count != 0);
259
260 const int titleLength = GetWindowTextLengthW(hWnd);
261 WIN32_CHK(titleLength != 0 || GetLastError() == NO_ERROR);
262
263 /* Allocate space for characters + terminating null. */
264 std::wstring WindowName(static_cast<size_t>(titleLength) + 1, L'\0');
265 count = GetWindowTextW(hWnd, WindowName.data(), static_cast<int>(WindowName.size()));
266 WIN32_CHK(count >= 0);
267
268 WindowName.resize(static_cast<size_t>(count));
269
270 DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
271 WIN32_CHK(GetLastError() == NO_ERROR);
272
273 RECT rect;
274 GetWindowRect(hWnd, &rect);
275 WIN32_CHK(GetLastError() == NO_ERROR);
276
277 HWND hWndParent = (HWND)GetWindowLongPtr(hWnd, GWLP_HWNDPARENT);
278 WIN32_CHK(GetLastError() == NO_ERROR);
279
280 HMENU hMenu = GetMenu(hWnd);
281 WIN32_CHK(GetLastError() == NO_ERROR);
282
283 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
284 WIN32_CHK(GetLastError() == NO_ERROR);
285
286 HWND hwndCloned = CreateWindowExW(dwExStyle,
287 lpClassName,
288 WindowName.c_str(),
289 dwStyle,
290 rect.left,
291 rect.top,
292 rect.right - rect.left,
293 rect.bottom - rect.top,
294 hWndParent,
295 hMenu,
296 hInstance,
297 lpParam);
298
299 WIN32_CHK(hwndCloned != nullptr);
300
301 return hwndCloned;
302}
303
304static void makeAttribList(std::vector<int> &out, bool stereoVisual, bool needAlpha)
305{
306 out.clear();
307 out.reserve(30);
308
309 out.push_back(WGL_SUPPORT_OPENGL_ARB);
310 out.push_back(GL_TRUE);
311
312 out.push_back(WGL_DRAW_TO_WINDOW_ARB);
313 out.push_back(GL_TRUE);
314
315 out.push_back(WGL_DOUBLE_BUFFER_ARB);
316 out.push_back(GL_TRUE);
317
318 out.push_back(WGL_ACCELERATION_ARB);
319 out.push_back(WGL_FULL_ACCELERATION_ARB);
320
321 if (stereoVisual) {
322 out.push_back(WGL_STEREO_ARB);
323 out.push_back(GL_TRUE);
324 }
325
326 out.push_back(WGL_PIXEL_TYPE_ARB);
327 out.push_back(WGL_TYPE_RGBA_ARB);
328
329 out.push_back(WGL_COLOR_BITS_ARB);
330 out.push_back(24);
331
332 if (needAlpha) {
333 out.push_back(WGL_ALPHA_BITS_ARB);
334 out.push_back(8);
335 }
336
337 out.push_back(0);
338}
339
340/* Temporary context used to create the actual context. We need ARB pixel format
341 * and context extensions, which are only available within a context. */
343 HWND dummyHWND = nullptr;
344
345 HDC dummyHDC = nullptr;
346 HGLRC dummyHGLRC = nullptr;
347
348 HDC prevHDC = nullptr;
349 HGLRC prevHGLRC = nullptr;
350
352
353 PIXELFORMATDESCRIPTOR preferredPFD;
354
359
360 DummyContextWGL(HDC hDC, HWND hWnd, bool stereoVisual, bool needAlpha)
361 {
362 preferredPFD = {
363 sizeof(PIXELFORMATDESCRIPTOR), /* size */
364 1, /* version */
365 (DWORD)(PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW |
366 PFD_DOUBLEBUFFER | /* support double-buffering */
367 (stereoVisual ? PFD_STEREO : 0)), /* support stereo */
368 PFD_TYPE_RGBA, /* color type */
369 (BYTE)(needAlpha ? 32 : 24), /* preferred color depth */
370 0,
371 0,
372 0,
373 0,
374 0,
375 0, /* color bits (ignored) */
376 (BYTE)(needAlpha ? 8 : 0), /* alpha buffer */
377 0, /* alpha shift (ignored) */
378 0, /* no accumulation buffer */
379 0,
380 0,
381 0,
382 0, /* Accumulation bits (ignored). */
383 0, /* depth buffer */
384 0, /* stencil buffer */
385 0, /* no auxiliary buffers */
386 PFD_MAIN_PLANE, /* main layer */
387 0, /* reserved */
388 0,
389 0,
390 0 /* layer, visible, and damage masks (ignored) */
391 };
392
393 SetLastError(NO_ERROR);
394
395 prevHDC = ::wglGetCurrentDC();
396 WIN32_CHK(GetLastError() == NO_ERROR);
397
398 prevHGLRC = ::wglGetCurrentContext();
399 WIN32_CHK(GetLastError() == NO_ERROR);
400
402
403 if (dummyPixelFormat == 0) {
404 return;
405 }
406
407 PIXELFORMATDESCRIPTOR chosenPFD;
408 if (!WIN32_CHK(::DescribePixelFormat(
409 hDC, dummyPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD)))
410 {
411 return;
412 }
413
414 if (hWnd) {
415 dummyHWND = clone_window(hWnd, nullptr);
416
417 if (dummyHWND == nullptr) {
418 return;
419 }
420
421 dummyHDC = GetDC(dummyHWND);
422 }
423
424 if (!WIN32_CHK(dummyHDC != nullptr)) {
425 return;
426 }
427
428 if (!WIN32_CHK(::SetPixelFormat(dummyHDC, dummyPixelFormat, &chosenPFD))) {
429 return;
430 }
431
432 dummyHGLRC = ::wglCreateContext(dummyHDC);
433
434 if (!WIN32_CHK(dummyHGLRC != nullptr)) {
435 return;
436 }
437
438 if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC))) {
439 return;
440 }
441
442 has_WGL_ARB_pixel_format = epoxy_has_wgl_extension(hDC, "WGL_ARB_pixel_format");
443 has_WGL_ARB_create_context = epoxy_has_wgl_extension(hDC, "WGL_ARB_create_context");
444 has_WGL_ARB_create_context_profile = epoxy_has_wgl_extension(hDC,
445 "WGL_ARB_create_context_profile");
446 has_WGL_ARB_create_context_robustness = epoxy_has_wgl_extension(
447 hDC, "WGL_ARB_create_context_robustness");
448 }
449
451 {
452 WIN32_CHK(::wglMakeCurrent(prevHDC, prevHGLRC));
453
454 if (dummyHGLRC != nullptr) {
455 WIN32_CHK(::wglDeleteContext(dummyHGLRC));
456 }
457
458 if (dummyHWND != nullptr) {
459 if (dummyHDC != nullptr) {
460 WIN32_CHK(::ReleaseDC(dummyHWND, dummyHDC));
461 }
462
463 WIN32_CHK(::DestroyWindow(dummyHWND));
464 }
465 }
466};
467
468int GHOST_ContextWGL::_choose_pixel_format_arb_1(bool stereoVisual, bool needAlpha)
469{
470 std::vector<int> iAttributes;
471
472#define _MAX_PIXEL_FORMATS 32
473
474 int iPixelFormat = 0;
475 int iPixelFormats[_MAX_PIXEL_FORMATS];
476
477 makeAttribList(iAttributes, stereoVisual, needAlpha);
478
479 uint nNumFormats;
480 WIN32_CHK(wglChoosePixelFormatARB(
481 h_DC_, &(iAttributes[0]), nullptr, _MAX_PIXEL_FORMATS, iPixelFormats, &nNumFormats));
482
483 if (nNumFormats > 0) {
484 iPixelFormat = iPixelFormats[0];
485 }
486
487 // check pixel format
488 if (iPixelFormat != 0) {
489 if (needAlpha) {
490 int alphaBits, iQuery = WGL_ALPHA_BITS_ARB;
491 wglGetPixelFormatAttribivARB(h_DC_, iPixelFormat, 0, 1, &iQuery, &alphaBits);
492 if (alphaBits == 0) {
493 fprintf(stderr, "Warning! Unable to find a frame buffer with alpha channel.\n");
494 }
495 }
496 }
497 return iPixelFormat;
498}
499
500int GHOST_ContextWGL::choose_pixel_format_arb(bool stereoVisual, bool needAlpha)
501{
502 int iPixelFormat;
503
504 iPixelFormat = _choose_pixel_format_arb_1(stereoVisual, needAlpha);
505
506 if (iPixelFormat == 0 && stereoVisual) {
507 fprintf(stderr, "Warning! Unable to find a stereo pixel format.\n");
508
509 iPixelFormat = _choose_pixel_format_arb_1(false, needAlpha);
510
511 context_params_.is_stereo_visual = false; /* Set context property to actual value. */
512 }
513
514 return iPixelFormat;
515}
516
517#ifndef NDEBUG
518static void reportContextString(const char *name, const char *dummy, const char *context)
519{
520 fprintf(stderr, "%s: %s\n", name, context);
521
522 if (dummy && strcmp(dummy, context) != 0) {
523 fprintf(stderr, "Warning! Dummy %s: %s\n", name, dummy);
524 }
525}
526#endif
527
529{
530 SetLastError(NO_ERROR);
531
532 HGLRC prevHGLRC = ::wglGetCurrentContext();
533 WIN32_CHK(GetLastError() == NO_ERROR);
534
535 HDC prevHDC = ::wglGetCurrentDC();
536 WIN32_CHK(GetLastError() == NO_ERROR);
537
538 {
539 const bool needAlpha = alpha_background_;
540 DummyContextWGL dummy(h_DC_, h_wnd_, context_params_.is_stereo_visual, needAlpha);
541
542 if (!dummy.has_WGL_ARB_create_context || ::GetPixelFormat(h_DC_) == 0) {
543 int iPixelFormat = 0;
544
545 if (dummy.has_WGL_ARB_pixel_format) {
546 iPixelFormat = choose_pixel_format_arb(context_params_.is_stereo_visual, needAlpha);
547 }
548
549 if (iPixelFormat == 0) {
550 iPixelFormat = choose_pixel_format_legacy(h_DC_, dummy.preferredPFD);
551 }
552
553 if (iPixelFormat == 0) {
554 goto error;
555 }
556
557 PIXELFORMATDESCRIPTOR chosenPFD;
558 int lastPFD = ::DescribePixelFormat(
559 h_DC_, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD);
560
561 if (!WIN32_CHK(lastPFD != 0)) {
562 goto error;
563 }
564
565 if (needAlpha && chosenPFD.cAlphaBits == 0) {
566 fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n");
567 }
568
569 if (!WIN32_CHK(::SetPixelFormat(h_DC_, iPixelFormat, &chosenPFD))) {
570 goto error;
571 }
572 }
573
574 if (dummy.has_WGL_ARB_create_context) {
575 int profileBitCore = context_profile_mask_ & WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
576 int profileBitCompat = context_profile_mask_ & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
577
578 if (!dummy.has_WGL_ARB_create_context_profile && profileBitCore) {
579 fprintf(stderr, "Warning! OpenGL core profile not available.\n");
580 }
581
582 if (!dummy.has_WGL_ARB_create_context_profile && profileBitCompat) {
583 fprintf(stderr, "Warning! OpenGL compatibility profile not available.\n");
584 }
585
586 int profileMask = 0;
587
588 if (dummy.has_WGL_ARB_create_context_profile && profileBitCore) {
589 profileMask |= profileBitCore;
590 }
591
592 if (dummy.has_WGL_ARB_create_context_profile && profileBitCompat) {
593 profileMask |= profileBitCompat;
594 }
595
596 if (profileMask != context_profile_mask_) {
597 fprintf(stderr, "Warning! Ignoring untested OpenGL context profile mask bits.");
598 }
599
600 std::vector<int> iAttributes;
601
602 if (profileMask) {
603 iAttributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
604 iAttributes.push_back(profileMask);
605 }
606
607 if (context_major_version_ != 0) {
608 iAttributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
609 iAttributes.push_back(context_major_version_);
610 }
611
612 if (context_minor_version_ != 0) {
613 iAttributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
614 iAttributes.push_back(context_minor_version_);
615 }
616
617 if (context_flags_ != 0) {
618 iAttributes.push_back(WGL_CONTEXT_FLAGS_ARB);
619 iAttributes.push_back(context_flags_);
620 }
621
622 if (context_reset_notification_strategy_ != 0) {
624 iAttributes.push_back(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB);
625 iAttributes.push_back(context_reset_notification_strategy_);
626 }
627 else {
628 fprintf(stderr, "Warning! Cannot set the reset notification strategy.");
629 }
630 }
631
632 iAttributes.push_back(0);
633
634 h_GLRC_ = ::wglCreateContextAttribsARB(h_DC_, s_sharedHGLRC, &(iAttributes[0]));
635 }
636 }
637
638 /* Silence warnings interpreted as errors by users when trying to get
639 * a context with version higher than 3.3 Core. */
640 {
641 const bool silent = context_major_version_ > 3;
642 if (!WIN32_CHK_SILENT(h_GLRC_ != nullptr, silent)) {
643 goto error;
644 }
645 }
646
647 s_sharedCount++;
648
649 if (s_sharedHGLRC == nullptr) {
650 s_sharedHGLRC = h_GLRC_;
651 }
652
653 if (!WIN32_CHK(::wglMakeCurrent(h_DC_, h_GLRC_))) {
654 goto error;
655 }
656
657 {
658 const GHOST_TVSyncModes vsync = getVSync();
659 if (vsync != GHOST_kVSyncModeUnset) {
660 setSwapInterval(int(vsync));
661 }
662 }
663
664 if (is_crappy_intel_card()) {
665 /* Some Intel cards with context 4.1 or 4.2
666 * don't have the point sprite enabled by default.
667 *
668 * However GL_POINT_SPRITE was removed in 3.2 and is now permanently ON.
669 * Then use brute force. */
670 glEnable(GL_POINT_SPRITE);
671 }
672
673 initClearGL();
674 ::SwapBuffers(h_DC_);
675
676#ifndef NDEBUG
677 {
678 const char *vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
679 const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
680 const char *version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
681
682 reportContextString("Vendor", dummy_vendor_, vendor);
683 reportContextString("Renderer", dummy_renderer_, renderer);
684 reportContextString("Version", dummy_version_, version);
685
686 fprintf(stderr, "Context Version: %d.%d\n", context_major_version_, context_minor_version_);
687 }
688#endif
689
690 active_context_ = this;
691 return GHOST_kSuccess;
692error:
693 ::wglMakeCurrent(prevHDC, prevHGLRC);
694 return GHOST_kFailure;
695}
696
698{
699 GHOST_TSuccess success = h_GLRC_ != s_sharedHGLRC || s_sharedCount == 1 ? GHOST_kSuccess :
701
702 if (offscreen_window_handle_) {
703 offscreen_window_handle_->used = false;
704 offscreen_window_handle_ = nullptr;
705 }
706
707 h_wnd_ = nullptr;
708 h_DC_ = nullptr;
709
710 return success;
711}
712
713GHOST_ContextWGL::OffscreenWindowHandle::OffscreenWindowHandle()
714{
715 h_wnd = CreateWindowA("STATIC",
716 "BlenderGLEW",
717 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
718 0,
719 0,
720 64,
721 64,
722 nullptr,
723 nullptr,
724 GetModuleHandle(nullptr),
725 nullptr);
726 h_DC = GetDC(h_wnd);
727}
728
729GHOST_ContextWGL::OffscreenWindowHandle::~OffscreenWindowHandle()
730{
731 if (h_DC != nullptr) {
732 WIN32_CHK(::ReleaseDC(h_wnd, h_DC));
733 }
734 if (h_wnd != nullptr) {
735 WIN32_CHK(::DestroyWindow(h_wnd));
736 }
737}
static void makeAttribList(std::vector< int > &out, bool stereoVisual, bool needAlpha)
static int choose_pixel_format_legacy(HDC hDC, PIXELFORMATDESCRIPTOR &preferredPFD)
#define _MAX_PIXEL_FORMATS
static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd, PIXELFORMATDESCRIPTOR &preferredPFD)
static void reportContextString(const char *name, const char *dummy, const char *context)
static bool is_crappy_intel_card()
static HWND clone_window(HWND hWnd, LPVOID lpParam)
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
GHOST_TVSyncModes
@ GHOST_kVSyncModeUnset
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
GHOST_ContextWGL(const GHOST_ContextParams &context_params, bool alphaBackground, HWND hWnd, HDC hDC, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
GHOST_TSuccess releaseNativeHandles() override
GHOST_TSuccess releaseDrawingContext() override
GHOST_TSuccess initializeDrawingContext() override
GHOST_TSuccess setSwapInterval(int interval) override
~GHOST_ContextWGL() override
GHOST_TSuccess activateDrawingContext() override
GHOST_TSuccess getSwapInterval(int &interval_out) override
GHOST_TSuccess swapBufferRelease() override
GHOST_Context(const GHOST_ContextParams &context_params)
static GHOST_Context * active_context_
virtual GHOST_TVSyncModes getVSync()
GHOST_ContextParams context_params_
#define assert(assertion)
#define L
unsigned int uint
Definition BKE_text.h:55
bool has_WGL_ARB_create_context_robustness
PIXELFORMATDESCRIPTOR preferredPFD
DummyContextWGL(HDC hDC, HWND hWnd, bool stereoVisual, bool needAlpha)
bool has_WGL_ARB_create_context_profile