108#ifdef USE_GLXEW_INIT_WORKAROUND
109 const GLubyte *extStart = (GLubyte *)
"";
110 const GLubyte *extEnd;
111 if (glXQueryExtension(m_display,
nullptr,
nullptr)) {
112 extStart = (
const GLubyte *)glXGetClientString(m_display, GLX_EXTENSIONS);
113 if ((extStart ==
nullptr) ||
114 (glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddressARB(
115 (
const GLubyte *)
"glXChooseFBConfig")) ==
nullptr ||
116 (glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB(
117 (
const GLubyte *)
"glXCreateContextAttribsARB")) ==
nullptr ||
118 (glXCreatePbuffer = (PFNGLXCREATEPBUFFERPROC)glXGetProcAddressARB(
119 (
const GLubyte *)
"glXCreatePbuffer")) ==
nullptr)
121 extStart = (GLubyte *)
"";
126# undef GLXEW_ARB_create_context
128 "GLX_ARB_create_context", extStart, extEnd);
129# undef GLXEW_ARB_create_context_profile
131 "GLX_ARB_create_context_profile", extStart, extEnd);
132# undef GLXEW_ARB_create_context_robustness
134 "GLX_ARB_create_context_robustness", extStart, extEnd);
136# undef GLXEW_EXT_create_context_es_profile
138 "GLX_EXT_create_context_es_profile", extStart, extEnd);
139# undef GLXEW_EXT_create_context_es2_profile
141 "GLX_EXT_create_context_es2_profile", extStart, extEnd);
152 if (GLXEW_ARB_create_context) {
153 int profileBitCore = m_contextProfileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
154 int profileBitCompat = m_contextProfileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
157 int profileBitES = m_contextProfileMask & GLX_CONTEXT_ES_PROFILE_BIT_EXT;
160 if (!GLXEW_ARB_create_context_profile && profileBitCore) {
161 fprintf(stderr,
"Warning! OpenGL core profile not available.\n");
163 if (!GLXEW_ARB_create_context_profile && profileBitCompat) {
164 fprintf(stderr,
"Warning! OpenGL compatibility profile not available.\n");
168 if (!GLXEW_EXT_create_context_es_profile && profileBitES && m_contextMajorVersion == 1)
169 fprintf(stderr,
"Warning! OpenGL ES profile not available.\n");
171 if (!GLXEW_EXT_create_context_es2_profile && profileBitES && m_contextMajorVersion == 2)
172 fprintf(stderr,
"Warning! OpenGL ES2 profile not available.\n");
177 if (GLXEW_ARB_create_context_profile && profileBitCore) {
178 profileMask |= profileBitCore;
180 if (GLXEW_ARB_create_context_profile && profileBitCompat) {
181 profileMask |= profileBitCompat;
185 if (GLXEW_EXT_create_context_es_profile && profileBitES)
186 profileMask |= profileBitES;
189 if (profileMask != m_contextProfileMask) {
190 fprintf(stderr,
"Warning! Ignoring untested OpenGL context profile mask bits.");
197 attribs[
i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
198 attribs[
i++] = profileMask;
201 if (m_contextMajorVersion != 0) {
202 attribs[
i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
203 attribs[
i++] = m_contextMajorVersion;
204 attribs[
i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
205 attribs[
i++] = m_contextMinorVersion;
208 if (m_contextFlags != 0) {
209 attribs[
i++] = GLX_CONTEXT_FLAGS_ARB;
210 attribs[
i++] = m_contextFlags;
213 if (m_contextResetNotificationStrategy != 0) {
214 if (GLXEW_ARB_create_context_robustness) {
215 attribs[
i++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
216 attribs[
i++] = m_contextResetNotificationStrategy;
219 fprintf(stderr,
"Warning! Cannot set the reset notification strategy.");
227 int pbuffer_attribs[] = {GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1,
None};
231 m_context = glXCreateContextAttribsARB(
232 m_display, m_fbconfig, s_sharedContext,
true, attribs);
235 m_window = (
Window)glXCreatePbuffer(m_display, m_fbconfig, pbuffer_attribs);
239 GLXFBConfig *framebuffer_config =
nullptr;
246 framebuffer_config = glXChooseFBConfig(
247 m_display, DefaultScreen(m_display), glx_attribs, &fbcount);
250 if (framebuffer_config) {
251 m_context = glXCreateContextAttribsARB(
252 m_display, framebuffer_config[0], s_sharedContext, True, attribs);
255 m_window = (
Window)glXCreatePbuffer(m_display, framebuffer_config[0], pbuffer_attribs);
258 m_fbconfig = framebuffer_config[0];
259 XFree(framebuffer_config);
265 fprintf(stderr,
"Error! GLX_ARB_create_context not available.\n");
270 if (m_context !=
nullptr) {
271 const uchar *version;
273 if (!s_sharedContext) {
274 s_sharedContext = m_context;
278 glXMakeCurrent(m_display, m_window, m_context);
282 ::glXSwapBuffers(m_display, m_window);
285 version = glGetString(GL_VERSION);
287 if (!version || version[0] <
'3' || ((version[0] ==
'3') && (version[2] <
'3'))) {
int GHOST_X11_GL_GetAttributes(int *attribs, int attribs_max, bool is_stereo_visual, bool need_alpha, bool for_fb_config)
static GLboolean _glewSearchExtension(const char *name, const GLubyte *start, const GLubyte *end)
static GLboolean _glewStrSame(const GLubyte *a, const GLubyte *b, GLuint n)
static GLuint _glewStrLen(const GLubyte *s)
static GLuint _glewStrCLen(const GLubyte *s, GLubyte c)
int GHOST_X11_GL_GetAttributes(int *attribs, int attribs_max, bool is_stereo_visual, bool need_alpha, bool for_fb_config)
GHOST_TSuccess releaseNativeHandles() override
GHOST_TSuccess releaseDrawingContext() override
GHOST_TSuccess getSwapInterval(int &intervalOut) override
GHOST_TSuccess activateDrawingContext() override
GHOST_TSuccess setSwapInterval(int interval) override
GHOST_TSuccess swapBuffers() override
GHOST_ContextGLX(bool stereoVisual, Window window, Display *display, GLXFBConfig fbconfig, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
GHOST_TSuccess initializeDrawingContext() override
static GHOST_Context * active_context_