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