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