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