Blender  V3.3
GHOST_ContextWGL.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
10 #include "GHOST_ContextWGL.h"
11 
12 #include <tchar.h>
13 
14 #include <cassert>
15 #include <cstdio>
16 #include <vector>
17 
18 HGLRC GHOST_ContextWGL::s_sharedHGLRC = NULL;
19 int GHOST_ContextWGL::s_sharedCount = 0;
20 
21 /* Some third-generation Intel video-cards are constantly bring problems */
22 static bool is_crappy_intel_card()
23 {
24  return strstr((const char *)glGetString(GL_VENDOR), "Intel") != NULL;
25 }
26 
28  bool alphaBackground,
29  HWND hWnd,
30  HDC hDC,
31  int contextProfileMask,
32  int contextMajorVersion,
33  int contextMinorVersion,
34  int contextFlags,
35  int contextResetNotificationStrategy)
36  : GHOST_Context(stereoVisual),
37  m_hWnd(hWnd),
38  m_hDC(hDC),
39  m_contextProfileMask(contextProfileMask),
40  m_contextMajorVersion(contextMajorVersion),
41  m_contextMinorVersion(contextMinorVersion),
42  m_contextFlags(contextFlags),
43  m_alphaBackground(alphaBackground),
44  m_contextResetNotificationStrategy(contextResetNotificationStrategy),
45  m_hGLRC(NULL)
46 #ifndef NDEBUG
47  ,
48  m_dummyVendor(NULL),
49  m_dummyRenderer(NULL),
50  m_dummyVersion(NULL)
51 #endif
52 {
53  assert(m_hDC != NULL);
54 }
55 
57 {
58  if (m_hGLRC != NULL) {
59  if (m_hGLRC == ::wglGetCurrentContext())
60  WIN32_CHK(::wglMakeCurrent(NULL, NULL));
61 
62  if (m_hGLRC != s_sharedHGLRC || s_sharedCount == 1) {
63  assert(s_sharedCount > 0);
64 
65  s_sharedCount--;
66 
67  if (s_sharedCount == 0)
68  s_sharedHGLRC = NULL;
69 
70  WIN32_CHK(::wglDeleteContext(m_hGLRC));
71  }
72  }
73 
74 #ifndef NDEBUG
75  if (m_dummyRenderer) {
76  free((void *)m_dummyRenderer);
77  free((void *)m_dummyVendor);
78  free((void *)m_dummyVersion);
79  }
80 #endif
81 }
82 
84 {
85  return WIN32_CHK(::SwapBuffers(m_hDC)) ? GHOST_kSuccess : GHOST_kFailure;
86 }
87 
89 {
90  if (WGLEW_EXT_swap_control)
91  return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
92  else
93  return GHOST_kFailure;
94 }
95 
97 {
98  if (WGLEW_EXT_swap_control) {
99  intervalOut = ::wglGetSwapIntervalEXT();
100  return GHOST_kSuccess;
101  }
102  else {
103  return GHOST_kFailure;
104  }
105 }
106 
108 {
109  if (WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) {
110  return GHOST_kSuccess;
111  }
112  else {
113  return GHOST_kFailure;
114  }
115 }
116 
118 {
119  if (WIN32_CHK(::wglMakeCurrent(NULL, NULL))) {
120  return GHOST_kSuccess;
121  }
122  else {
123  return GHOST_kFailure;
124  }
125 }
126 
127 /* Ron Fosner's code for weighting pixel formats and forcing software.
128  * See http://www.opengl.org/resources/faq/technical/weight.cpp
129  */
130 static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd, PIXELFORMATDESCRIPTOR &preferredPFD)
131 {
132  int weight = 0;
133 
134  /* assume desktop color depth is 32 bits per pixel */
135 
136  /* cull unusable pixel formats */
137  /* if no formats can be found, can we determine why it was rejected? */
138  if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL) || !(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
139  !(pfd.dwFlags & PFD_DOUBLEBUFFER) || /* Blender _needs_ this. */
140  !(pfd.iPixelType == PFD_TYPE_RGBA) ||
141  (pfd.cColorBits > 32) || /* 64 bit formats disable AERO. */
142  (pfd.dwFlags & PFD_GENERIC_FORMAT)) /* No software renderers. */
143  {
144  return 0;
145  }
146 
147  weight = 1; /* it's usable */
148 
149  weight += pfd.cColorBits - 8;
150 
151  if (preferredPFD.cAlphaBits > 0 && pfd.cAlphaBits > 0)
152  weight++;
153 #ifdef WIN32_COMPOSITING
154  if ((preferredPFD.dwFlags & PFD_SUPPORT_COMPOSITION) && (pfd.dwFlags & PFD_SUPPORT_COMPOSITION))
155  weight++;
156 #endif
157 
158  return weight;
159 }
160 
161 /*
162  * A modification of Ron Fosner's replacement for ChoosePixelFormat
163  * returns 0 on error, else returns the pixel format number to be used
164  */
165 static int choose_pixel_format_legacy(HDC hDC, PIXELFORMATDESCRIPTOR &preferredPFD)
166 {
167  int iPixelFormat = 0;
168  int weight = 0;
169 
170  int iStereoPixelFormat = 0;
171  int stereoWeight = 0;
172 
173  /* choose a pixel format using the useless Windows function in case we come up empty handed */
174  int iLastResortPixelFormat = ::ChoosePixelFormat(hDC, &preferredPFD);
175 
176  WIN32_CHK(iLastResortPixelFormat != 0);
177 
178  int lastPFD = ::DescribePixelFormat(hDC, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
179 
180  WIN32_CHK(lastPFD != 0);
181 
182  for (int i = 1; i <= lastPFD; i++) {
183  PIXELFORMATDESCRIPTOR pfd;
184  int check = ::DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
185 
186  WIN32_CHK(check == lastPFD);
187 
188  int w = weight_pixel_format(pfd, preferredPFD);
189 
190  if (w > weight) {
191  weight = w;
192  iPixelFormat = i;
193  }
194 
195  if (w > stereoWeight && (preferredPFD.dwFlags & pfd.dwFlags & PFD_STEREO)) {
196  stereoWeight = w;
197  iStereoPixelFormat = i;
198  }
199  }
200 
201  /* choose any available stereo format over a non-stereo format */
202  if (iStereoPixelFormat != 0)
203  iPixelFormat = iStereoPixelFormat;
204 
205  if (iPixelFormat == 0) {
206  fprintf(stderr, "Warning! Using result of ChoosePixelFormat.\n");
207  iPixelFormat = iLastResortPixelFormat;
208  }
209 
210  return iPixelFormat;
211 }
212 
218 static HWND clone_window(HWND hWnd, LPVOID lpParam)
219 {
220  int count;
221 
222  SetLastError(NO_ERROR);
223 
224  DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
225  WIN32_CHK(GetLastError() == NO_ERROR);
226 
227  WCHAR lpClassName[100] = L"";
228  count = GetClassNameW(hWnd, lpClassName, sizeof(lpClassName));
229  WIN32_CHK(count != 0);
230 
231  WCHAR lpWindowName[100] = L"";
232  count = GetWindowTextW(hWnd, lpWindowName, sizeof(lpWindowName));
233  WIN32_CHK(count != 0);
234 
235  DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
236  WIN32_CHK(GetLastError() == NO_ERROR);
237 
238  RECT rect;
239  GetWindowRect(hWnd, &rect);
240  WIN32_CHK(GetLastError() == NO_ERROR);
241 
242  HWND hWndParent = (HWND)GetWindowLongPtr(hWnd, GWLP_HWNDPARENT);
243  WIN32_CHK(GetLastError() == NO_ERROR);
244 
245  HMENU hMenu = GetMenu(hWnd);
246  WIN32_CHK(GetLastError() == NO_ERROR);
247 
248  HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
249  WIN32_CHK(GetLastError() == NO_ERROR);
250 
251  HWND hwndCloned = CreateWindowExW(dwExStyle,
252  lpClassName,
253  lpWindowName,
254  dwStyle,
255  rect.left,
256  rect.top,
257  rect.right - rect.left,
258  rect.bottom - rect.top,
259  hWndParent,
260  hMenu,
261  hInstance,
262  lpParam);
263 
264  WIN32_CHK(hwndCloned != NULL);
265 
266  return hwndCloned;
267 }
268 
269 void GHOST_ContextWGL::initContextWGLEW(PIXELFORMATDESCRIPTOR &preferredPFD)
270 {
271  HWND dummyHWND = NULL;
272 
273  HDC dummyHDC = NULL;
274  HGLRC dummyHGLRC = NULL;
275 
276  HDC prevHDC;
277  HGLRC prevHGLRC;
278 
279  int iPixelFormat;
280 
281  SetLastError(NO_ERROR);
282 
283  prevHDC = ::wglGetCurrentDC();
284  WIN32_CHK(GetLastError() == NO_ERROR);
285 
286  prevHGLRC = ::wglGetCurrentContext();
287  WIN32_CHK(GetLastError() == NO_ERROR);
288 
289  iPixelFormat = choose_pixel_format_legacy(m_hDC, preferredPFD);
290 
291  if (iPixelFormat == 0)
292  goto finalize;
293 
294  PIXELFORMATDESCRIPTOR chosenPFD;
295  if (!WIN32_CHK(
296  ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD)))
297  goto finalize;
298 
299  if (m_hWnd) {
300  dummyHWND = clone_window(m_hWnd, NULL);
301 
302  if (dummyHWND == NULL)
303  goto finalize;
304 
305  dummyHDC = GetDC(dummyHWND);
306  }
307 
308  if (!WIN32_CHK(dummyHDC != NULL))
309  goto finalize;
310 
311  if (!WIN32_CHK(::SetPixelFormat(dummyHDC, iPixelFormat, &chosenPFD)))
312  goto finalize;
313 
314  dummyHGLRC = ::wglCreateContext(dummyHDC);
315 
316  if (!WIN32_CHK(dummyHGLRC != NULL))
317  goto finalize;
318 
319  if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC)))
320  goto finalize;
321 
322  if (GLEW_CHK(glewInit()) != GLEW_OK) {
323  fprintf(stderr, "Warning! Dummy GLEW/WGLEW failed to initialize properly.\n");
324  }
325 
326  /* The following are not technically WGLEW, but they also require a context to work. */
327 
328 #ifndef NDEBUG
329  free((void *)m_dummyRenderer);
330  free((void *)m_dummyVendor);
331  free((void *)m_dummyVersion);
332 
333  m_dummyRenderer = _strdup(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
334  m_dummyVendor = _strdup(reinterpret_cast<const char *>(glGetString(GL_VENDOR)));
335  m_dummyVersion = _strdup(reinterpret_cast<const char *>(glGetString(GL_VERSION)));
336 #endif
337 
338 finalize:
339  WIN32_CHK(::wglMakeCurrent(prevHDC, prevHGLRC));
340 
341  if (dummyHGLRC != NULL)
342  WIN32_CHK(::wglDeleteContext(dummyHGLRC));
343 
344  if (dummyHWND != NULL) {
345  if (dummyHDC != NULL)
346  WIN32_CHK(::ReleaseDC(dummyHWND, dummyHDC));
347 
348  WIN32_CHK(::DestroyWindow(dummyHWND));
349  }
350 }
351 
352 static void makeAttribList(std::vector<int> &out, bool stereoVisual, bool needAlpha)
353 {
354  out.clear();
355  out.reserve(30);
356 
357  out.push_back(WGL_SUPPORT_OPENGL_ARB);
358  out.push_back(GL_TRUE);
359 
360  out.push_back(WGL_DRAW_TO_WINDOW_ARB);
361  out.push_back(GL_TRUE);
362 
363  out.push_back(WGL_DOUBLE_BUFFER_ARB);
364  out.push_back(GL_TRUE);
365 
366  out.push_back(WGL_ACCELERATION_ARB);
367  out.push_back(WGL_FULL_ACCELERATION_ARB);
368 
369  if (stereoVisual) {
370  out.push_back(WGL_STEREO_ARB);
371  out.push_back(GL_TRUE);
372  }
373 
374  out.push_back(WGL_PIXEL_TYPE_ARB);
375  out.push_back(WGL_TYPE_RGBA_ARB);
376 
377  out.push_back(WGL_COLOR_BITS_ARB);
378  out.push_back(24);
379 
380  if (needAlpha) {
381  out.push_back(WGL_ALPHA_BITS_ARB);
382  out.push_back(8);
383  }
384 
385  out.push_back(0);
386 }
387 
388 int GHOST_ContextWGL::_choose_pixel_format_arb_1(bool stereoVisual, bool needAlpha)
389 {
390  std::vector<int> iAttributes;
391 
392 #define _MAX_PIXEL_FORMATS 32
393 
394  int iPixelFormat = 0;
395  int iPixelFormats[_MAX_PIXEL_FORMATS];
396 
397  makeAttribList(iAttributes, stereoVisual, needAlpha);
398 
399  UINT nNumFormats;
400  WIN32_CHK(wglChoosePixelFormatARB(
401  m_hDC, &(iAttributes[0]), NULL, _MAX_PIXEL_FORMATS, iPixelFormats, &nNumFormats));
402 
403  if (nNumFormats > 0) {
404  iPixelFormat = iPixelFormats[0];
405 
406 #ifdef WIN32_COMPOSITING
407  if (needAlpha) {
408  // scan through all pixel format to make sure one supports compositing
409  PIXELFORMATDESCRIPTOR pfd;
410  int i;
411 
412  for (i = 0; i < nNumFormats; i++) {
413  if (DescribePixelFormat(m_hDC, iPixelFormats[i], sizeof(PIXELFORMATDESCRIPTOR), &pfd)) {
414  if (pfd.dwFlags & PFD_SUPPORT_COMPOSITION) {
415  iPixelFormat = iPixelFormats[i];
416  break;
417  }
418  }
419  }
420  if (i == nNumFormats) {
421  fprintf(stderr, "Warning! Unable to find a pixel format with compositing capability.\n");
422  }
423  }
424 #endif
425  }
426 
427  // check pixel format
428  if (iPixelFormat != 0) {
429  if (needAlpha) {
430  int alphaBits, iQuery = WGL_ALPHA_BITS_ARB;
431  wglGetPixelFormatAttribivARB(m_hDC, iPixelFormat, 0, 1, &iQuery, &alphaBits);
432  if (alphaBits == 0) {
433  fprintf(stderr, "Warning! Unable to find a frame buffer with alpha channel.\n");
434  }
435  }
436  }
437  return iPixelFormat;
438 }
439 
440 int GHOST_ContextWGL::choose_pixel_format_arb(bool stereoVisual, bool needAlpha)
441 {
442  int iPixelFormat;
443 
444  iPixelFormat = _choose_pixel_format_arb_1(stereoVisual, needAlpha);
445 
446  if (iPixelFormat == 0 && stereoVisual) {
447  fprintf(stderr, "Warning! Unable to find a stereo pixel format.\n");
448 
449  iPixelFormat = _choose_pixel_format_arb_1(false, needAlpha);
450 
451  m_stereoVisual = false; // set context property to actual value
452  }
453 
454  return iPixelFormat;
455 }
456 
457 int GHOST_ContextWGL::choose_pixel_format(bool stereoVisual, bool needAlpha)
458 {
459  PIXELFORMATDESCRIPTOR preferredPFD = {
460  sizeof(PIXELFORMATDESCRIPTOR), /* size */
461  1, /* version */
462  (DWORD)(PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW |
463  PFD_DOUBLEBUFFER | /* support double-buffering */
464  (stereoVisual ? PFD_STEREO : 0) | /* support stereo */
465  (
466 #ifdef WIN32_COMPOSITING
467  /* Support composition for transparent background. */
468  needAlpha ? PFD_SUPPORT_COMPOSITION :
469 #endif
470  0)),
471  PFD_TYPE_RGBA, /* color type */
472  (BYTE)(needAlpha ? 32 : 24), /* preferred color depth */
473  0,
474  0,
475  0,
476  0,
477  0,
478  0, /* color bits (ignored) */
479  (BYTE)(needAlpha ? 8 : 0), /* alpha buffer */
480  0, /* alpha shift (ignored) */
481  0, /* no accumulation buffer */
482  0,
483  0,
484  0,
485  0, /* accum bits (ignored) */
486  0, /* depth buffer */
487  0, /* stencil buffer */
488  0, /* no auxiliary buffers */
489  PFD_MAIN_PLANE, /* main layer */
490  0, /* reserved */
491  0,
492  0,
493  0 /* layer, visible, and damage masks (ignored) */
494  };
495 
496  initContextWGLEW(preferredPFD);
497 
498  int iPixelFormat = 0;
499 
500  if (WGLEW_ARB_pixel_format)
501  iPixelFormat = choose_pixel_format_arb(stereoVisual, needAlpha);
502 
503  if (iPixelFormat == 0)
504  iPixelFormat = choose_pixel_format_legacy(m_hDC, preferredPFD);
505 
506  return iPixelFormat;
507 }
508 
509 #ifndef NDEBUG
510 static void reportContextString(const char *name, const char *dummy, const char *context)
511 {
512  fprintf(stderr, "%s: %s\n", name, context);
513 
514  if (dummy && strcmp(dummy, context) != 0)
515  fprintf(stderr, "Warning! Dummy %s: %s\n", name, dummy);
516 }
517 #endif
518 
520 {
521  SetLastError(NO_ERROR);
522 
523  HGLRC prevHGLRC = ::wglGetCurrentContext();
524  WIN32_CHK(GetLastError() == NO_ERROR);
525 
526  HDC prevHDC = ::wglGetCurrentDC();
527  WIN32_CHK(GetLastError() == NO_ERROR);
528 
529  if (!WGLEW_ARB_create_context || ::GetPixelFormat(m_hDC) == 0) {
530  const bool needAlpha = m_alphaBackground;
531  int iPixelFormat;
532  int lastPFD;
533 
534  PIXELFORMATDESCRIPTOR chosenPFD;
535 
536  iPixelFormat = choose_pixel_format(m_stereoVisual, needAlpha);
537 
538  if (iPixelFormat == 0) {
539  goto error;
540  }
541 
542  lastPFD = ::DescribePixelFormat(
543  m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD);
544 
545  if (!WIN32_CHK(lastPFD != 0)) {
546  goto error;
547  }
548 
549  if (needAlpha && chosenPFD.cAlphaBits == 0)
550  fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n");
551 
552  if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) {
553  goto error;
554  }
555  }
556 
557  if (WGLEW_ARB_create_context) {
558  int profileBitCore = m_contextProfileMask & WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
559  int profileBitCompat = m_contextProfileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
560 
561 #ifdef WITH_GLEW_ES
562  int profileBitES = m_contextProfileMask & WGL_CONTEXT_ES_PROFILE_BIT_EXT;
563 #endif
564 
565  if (!WGLEW_ARB_create_context_profile && profileBitCore)
566  fprintf(stderr, "Warning! OpenGL core profile not available.\n");
567 
568  if (!WGLEW_ARB_create_context_profile && profileBitCompat)
569  fprintf(stderr, "Warning! OpenGL compatibility profile not available.\n");
570 
571 #ifdef WITH_GLEW_ES
572  if (!WGLEW_EXT_create_context_es_profile && profileBitES && m_contextMajorVersion == 1)
573  fprintf(stderr, "Warning! OpenGL ES profile not available.\n");
574 
575  if (!WGLEW_EXT_create_context_es2_profile && profileBitES && m_contextMajorVersion == 2)
576  fprintf(stderr, "Warning! OpenGL ES2 profile not available.\n");
577 #endif
578 
579  int profileMask = 0;
580 
581  if (WGLEW_ARB_create_context_profile && profileBitCore)
582  profileMask |= profileBitCore;
583 
584  if (WGLEW_ARB_create_context_profile && profileBitCompat)
585  profileMask |= profileBitCompat;
586 
587 #ifdef WITH_GLEW_ES
588  if (WGLEW_EXT_create_context_es_profile && profileBitES)
589  profileMask |= profileBitES;
590 #endif
591 
592  if (profileMask != m_contextProfileMask)
593  fprintf(stderr, "Warning! Ignoring untested OpenGL context profile mask bits.");
594 
595  std::vector<int> iAttributes;
596 
597  if (profileMask) {
598  iAttributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
599  iAttributes.push_back(profileMask);
600  }
601 
602  if (m_contextMajorVersion != 0) {
603  iAttributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
604  iAttributes.push_back(m_contextMajorVersion);
605  }
606 
607  if (m_contextMinorVersion != 0) {
608  iAttributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
609  iAttributes.push_back(m_contextMinorVersion);
610  }
611 
612  if (m_contextFlags != 0) {
613  iAttributes.push_back(WGL_CONTEXT_FLAGS_ARB);
614  iAttributes.push_back(m_contextFlags);
615  }
616 
617  if (m_contextResetNotificationStrategy != 0) {
618  if (WGLEW_ARB_create_context_robustness) {
619  iAttributes.push_back(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB);
620  iAttributes.push_back(m_contextResetNotificationStrategy);
621  }
622  else {
623  fprintf(stderr, "Warning! Cannot set the reset notification strategy.");
624  }
625  }
626 
627  iAttributes.push_back(0);
628 
629  m_hGLRC = ::wglCreateContextAttribsARB(m_hDC, NULL, &(iAttributes[0]));
630  }
631 
632  /* Silence warnings interpreted as errors by users when trying to get
633  * a context with version higher than 3.3 Core. */
634  {
635  const bool silent = m_contextMajorVersion > 3;
636  if (!WIN32_CHK_SILENT(m_hGLRC != NULL, silent)) {
637  goto error;
638  }
639  }
640 
641  s_sharedCount++;
642 
643  if (s_sharedHGLRC == NULL) {
644  s_sharedHGLRC = m_hGLRC;
645  }
646  else if (!WIN32_CHK(::wglShareLists(s_sharedHGLRC, m_hGLRC))) {
647  goto error;
648  }
649 
650  if (!WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) {
651  goto error;
652  }
653 
654  initContextGLEW();
655 
656  if (is_crappy_intel_card()) {
657  /* Some Intel cards with context 4.1 or 4.2
658  * don't have the point sprite enabled by default.
659  *
660  * However GL_POINT_SPRITE was removed in 3.2 and is now permanently ON.
661  * Then use brute force. */
662  glEnable(GL_POINT_SPRITE);
663  }
664 
665  initClearGL();
666  ::SwapBuffers(m_hDC);
667 
668 #ifndef NDEBUG
669  {
670  const char *vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
671  const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
672  const char *version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
673 
674  reportContextString("Vendor", m_dummyVendor, vendor);
675  reportContextString("Renderer", m_dummyRenderer, renderer);
676  reportContextString("Version", m_dummyVersion, version);
677 
678  fprintf(stderr, "Context Version: %d.%d\n", m_contextMajorVersion, m_contextMinorVersion);
679  }
680 #endif
681 
682  return GHOST_kSuccess;
683 error:
684  ::wglMakeCurrent(prevHDC, prevHGLRC);
685  return GHOST_kFailure;
686 }
687 
689 {
690  GHOST_TSuccess success = m_hGLRC != s_sharedHGLRC || s_sharedCount == 1 ? GHOST_kSuccess :
692 
693  m_hWnd = NULL;
694  m_hDC = NULL;
695 
696  return success;
697 }
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
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
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
typedef UINT(API *GHOST_WIN32_GetDpiForWindow)(HWND)
#define glEnable
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
GHOST_ContextWGL(bool stereoVisual, bool alphaBackground, HWND hWnd, HDC hDC, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
GHOST_TSuccess activateDrawingContext()
GHOST_TSuccess getSwapInterval(int &intervalOut)
GHOST_TSuccess swapBuffers()
GHOST_TSuccess releaseNativeHandles()
GHOST_TSuccess initializeDrawingContext()
GHOST_TSuccess releaseDrawingContext()
GHOST_TSuccess setSwapInterval(int interval)
void initContextGLEW()
static void initClearGL()
#define GLEW_CHK(x)
Definition: glew-mx.h:48
int count
#define L
static void error(const char *str)
Definition: meshlaplacian.c:51
static const pxr::TfToken out("out", pxr::TfToken::Immortal)