Blender  V2.93
GHOST_Context.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #include "GHOST_Context.h"
27 
28 #ifdef _WIN32
29 # include <GL/wglew.h> // only for symbolic constants, do not use API functions
30 # include <tchar.h>
31 #
32 # ifndef ERROR_PROFILE_DOES_NOT_MATCH_DEVICE
33 # define ERROR_PROFILE_DOES_NOT_MATCH_DEVICE 0x7E7
34 # endif
35 #endif
36 
37 #include <cstdio>
38 #include <cstring>
39 
40 #ifdef _WIN32
41 
42 bool win32_silent_chk(bool result)
43 {
44  if (!result) {
45  SetLastError(NO_ERROR);
46  }
47 
48  return result;
49 }
50 
51 bool win32_chk(bool result, const char *file, int line, const char *text)
52 {
53  if (!result) {
54  LPTSTR formattedMsg = NULL;
55 
56  DWORD error = GetLastError();
57 
58  const char *msg;
59 
60  DWORD count = 0;
61 
62  /* Some drivers returns a HRESULT instead of a standard error message.
63  * i.e: 0xC0072095 instead of 0x2095 for ERROR_INVALID_VERSION_ARB
64  * So strip down the error to the valid error code range. */
65  switch (error & 0x0000FFFF) {
66  case ERROR_INVALID_VERSION_ARB:
67  msg =
68  "The specified OpenGL version and feature set are either invalid or not supported.\n";
69  break;
70 
71  case ERROR_INVALID_PROFILE_ARB:
72  msg =
73  "The specified OpenGL profile and feature set are either invalid or not supported.\n";
74  break;
75 
76  case ERROR_INVALID_PIXEL_TYPE_ARB:
77  msg = "The specified pixel type is invalid.\n";
78  break;
79 
80  case ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB:
81  msg =
82  ("The device contexts specified are not compatible. "
83  "This can occur if the device contexts are managed by "
84  "different drivers or possibly on different graphics adapters.\n");
85  break;
86 
87 # ifdef WITH_GLEW_ES
88  case ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV:
89  msg = "The device context(s) and rendering context have non-matching affinity masks.\n";
90  break;
91 
92  case ERROR_MISSING_AFFINITY_MASK_NV:
93  msg = "The rendering context does not have an affinity mask set.\n";
94  break;
95 # endif
96 
97  case ERROR_PROFILE_DOES_NOT_MATCH_DEVICE:
98  msg =
99  ("The specified profile is intended for a device of a "
100  "different type than the specified device.\n");
101  break;
102 
103  default: {
104  count = FormatMessage((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
105  FORMAT_MESSAGE_IGNORE_INSERTS),
106  NULL,
107  error,
108  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
109  (LPTSTR)(&formattedMsg),
110  0,
111  NULL);
112 
113  msg = count > 0 ? formattedMsg : "<no system message>\n";
114  break;
115  }
116  }
117 
118 # ifndef NDEBUG
119  _ftprintf(stderr,
120  "%s(%d):[%s] -> Win32 Error# (%lu): %s",
121  file,
122  line,
123  text,
124  (unsigned long)error,
125  msg);
126 # else
127  _ftprintf(stderr, "Win32 Error# (%lu): %s", (unsigned long)error, msg);
128 # endif
129 
130  SetLastError(NO_ERROR);
131 
132  if (count != 0)
133  LocalFree(formattedMsg);
134  }
135 
136  return result;
137 }
138 
139 #endif // _WIN32
140 
142 {
143  GLEW_CHK(glewInit());
144 }
145 
147 {
148  glClearColor(0.294, 0.294, 0.294, 0.000);
149  glClear(GL_COLOR_BUFFER_BIT);
150  glClearColor(0.000, 0.000, 0.000, 0.000);
151 }
void initContextGLEW()
static void initClearGL()
FILE * file
#define GLEW_CHK(x)
Definition: glew-mx.h:64
int count
static void error(const char *str)
Definition: meshlaplacian.c:65