Blender  V3.3
GHOST_Context.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_Context.h"
11 
12 #ifdef _WIN32
13 # include <GL/wglew.h> // only for symbolic constants, do not use API functions
14 # include <tchar.h>
15 #
16 # ifndef ERROR_PROFILE_DOES_NOT_MATCH_DEVICE
17 # define ERROR_PROFILE_DOES_NOT_MATCH_DEVICE 0x7E7
18 # endif
19 #endif
20 
21 #include <cstdio>
22 #include <cstring>
23 
24 #ifdef _WIN32
25 
26 bool win32_silent_chk(bool result)
27 {
28  if (!result) {
29  SetLastError(NO_ERROR);
30  }
31 
32  return result;
33 }
34 
35 bool win32_chk(bool result, const char *file, int line, const char *text)
36 {
37  if (!result) {
38  LPTSTR formattedMsg = NULL;
39 
40  DWORD error = GetLastError();
41 
42  const char *msg;
43 
44  DWORD count = 0;
45 
46  /* Some drivers returns a HRESULT instead of a standard error message.
47  * i.e: 0xC0072095 instead of 0x2095 for ERROR_INVALID_VERSION_ARB
48  * So strip down the error to the valid error code range. */
49  switch (error & 0x0000FFFF) {
50  case ERROR_INVALID_VERSION_ARB:
51  msg =
52  "The specified OpenGL version and feature set are either invalid or not supported.\n";
53  break;
54 
55  case ERROR_INVALID_PROFILE_ARB:
56  msg =
57  "The specified OpenGL profile and feature set are either invalid or not supported.\n";
58  break;
59 
60  case ERROR_INVALID_PIXEL_TYPE_ARB:
61  msg = "The specified pixel type is invalid.\n";
62  break;
63 
64  case ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB:
65  msg =
66  ("The device contexts specified are not compatible. "
67  "This can occur if the device contexts are managed by "
68  "different drivers or possibly on different graphics adapters.\n");
69  break;
70 
71 # ifdef WITH_GLEW_ES
72  case ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV:
73  msg = "The device context(s) and rendering context have non-matching affinity masks.\n";
74  break;
75 
76  case ERROR_MISSING_AFFINITY_MASK_NV:
77  msg = "The rendering context does not have an affinity mask set.\n";
78  break;
79 # endif
80 
81  case ERROR_PROFILE_DOES_NOT_MATCH_DEVICE:
82  msg =
83  ("The specified profile is intended for a device of a "
84  "different type than the specified device.\n");
85  break;
86 
87  default: {
88  count = FormatMessage((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
89  FORMAT_MESSAGE_IGNORE_INSERTS),
90  NULL,
91  error,
92  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
93  (LPTSTR)(&formattedMsg),
94  0,
95  NULL);
96 
97  msg = count > 0 ? formattedMsg : "<no system message>\n";
98  break;
99  }
100  }
101 
102 # ifndef NDEBUG
103  _ftprintf(stderr,
104  "%s(%d):[%s] -> Win32 Error# (%lu): %s",
105  file,
106  line,
107  text,
108  (unsigned long)error,
109  msg);
110 # else
111  _ftprintf(stderr, "Win32 Error# (%lu): %s", (unsigned long)error, msg);
112 # endif
113 
114  SetLastError(NO_ERROR);
115 
116  if (count != 0)
117  LocalFree(formattedMsg);
118  }
119 
120  return result;
121 }
122 
123 #endif // _WIN32
124 
126 {
127  GLEW_CHK(glewInit());
128 }
129 
131 {
132  glClearColor(0.294, 0.294, 0.294, 0.000);
133  glClear(GL_COLOR_BUFFER_BIT);
134  glClearColor(0.000, 0.000, 0.000, 0.000);
135 }
void initContextGLEW()
static void initClearGL()
FILE * file
#define GLEW_CHK(x)
Definition: glew-mx.h:48
int count
static void error(const char *str)
Definition: meshlaplacian.c:51