106#ifdef USE_GLXEW_INIT_WORKAROUND
107 const GLubyte *extStart = (GLubyte *)
"";
108 const GLubyte *extEnd;
109 if (glXQueryExtension(m_display,
nullptr,
nullptr)) {
110 extStart = (
const GLubyte *)glXGetClientString(m_display, GLX_EXTENSIONS);
111 if ((extStart ==
nullptr) ||
112 (glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)glXGetProcAddressARB(
113 (
const GLubyte *)
"glXChooseFBConfig")) ==
nullptr ||
114 (glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB(
115 (
const GLubyte *)
"glXCreateContextAttribsARB")) ==
nullptr ||
116 (glXCreatePbuffer = (PFNGLXCREATEPBUFFERPROC)glXGetProcAddressARB(
117 (
const GLubyte *)
"glXCreatePbuffer")) ==
nullptr)
119 extStart = (GLubyte *)
"";
124# undef GLXEW_ARB_create_context
126 "GLX_ARB_create_context", extStart, extEnd);
127# undef GLXEW_ARB_create_context_profile
129 "GLX_ARB_create_context_profile", extStart, extEnd);
130# undef GLXEW_ARB_create_context_robustness
132 "GLX_ARB_create_context_robustness", extStart, extEnd);
134# undef GLXEW_EXT_create_context_es_profile
136 "GLX_EXT_create_context_es_profile", extStart, extEnd);
137# undef GLXEW_EXT_create_context_es2_profile
139 "GLX_EXT_create_context_es2_profile", extStart, extEnd);
150 if (GLXEW_ARB_create_context) {
151 int profileBitCore = m_contextProfileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
152 int profileBitCompat = m_contextProfileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
155 int profileBitES = m_contextProfileMask & GLX_CONTEXT_ES_PROFILE_BIT_EXT;
158 if (!GLXEW_ARB_create_context_profile && profileBitCore) {
159 fprintf(stderr,
"Warning! OpenGL core profile not available.\n");
161 if (!GLXEW_ARB_create_context_profile && profileBitCompat) {
162 fprintf(stderr,
"Warning! OpenGL compatibility profile not available.\n");
166 if (!GLXEW_EXT_create_context_es_profile && profileBitES && m_contextMajorVersion == 1)
167 fprintf(stderr,
"Warning! OpenGL ES profile not available.\n");
169 if (!GLXEW_EXT_create_context_es2_profile && profileBitES && m_contextMajorVersion == 2)
170 fprintf(stderr,
"Warning! OpenGL ES2 profile not available.\n");
175 if (GLXEW_ARB_create_context_profile && profileBitCore) {
176 profileMask |= profileBitCore;
178 if (GLXEW_ARB_create_context_profile && profileBitCompat) {
179 profileMask |= profileBitCompat;
183 if (GLXEW_EXT_create_context_es_profile && profileBitES)
184 profileMask |= profileBitES;
187 if (profileMask != m_contextProfileMask) {
188 fprintf(stderr,
"Warning! Ignoring untested OpenGL context profile mask bits.");
195 attribs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
196 attribs[i++] = profileMask;
199 if (m_contextMajorVersion != 0) {
200 attribs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
201 attribs[i++] = m_contextMajorVersion;
202 attribs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
203 attribs[i++] = m_contextMinorVersion;
206 if (m_contextFlags != 0) {
207 attribs[i++] = GLX_CONTEXT_FLAGS_ARB;
208 attribs[i++] = m_contextFlags;
211 if (m_contextResetNotificationStrategy != 0) {
212 if (GLXEW_ARB_create_context_robustness) {
213 attribs[i++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
214 attribs[i++] = m_contextResetNotificationStrategy;
217 fprintf(stderr,
"Warning! Cannot set the reset notification strategy.");
225 int pbuffer_attribs[] = {GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1,
None};
229 m_context = glXCreateContextAttribsARB(
230 m_display, m_fbconfig, s_sharedContext,
true, attribs);
233 m_window = (
Window)glXCreatePbuffer(m_display, m_fbconfig, pbuffer_attribs);
237 GLXFBConfig *framebuffer_config =
nullptr;
244 framebuffer_config = glXChooseFBConfig(
245 m_display, DefaultScreen(m_display), glx_attribs, &fbcount);
248 if (framebuffer_config) {
249 m_context = glXCreateContextAttribsARB(
250 m_display, framebuffer_config[0], s_sharedContext, True, attribs);
253 m_window = (
Window)glXCreatePbuffer(m_display, framebuffer_config[0], pbuffer_attribs);
256 m_fbconfig = framebuffer_config[0];
257 XFree(framebuffer_config);
263 fprintf(stderr,
"Error! GLX_ARB_create_context not available.\n");
268 if (m_context !=
nullptr) {
269 const uchar *version;
271 if (!s_sharedContext) {
272 s_sharedContext = m_context;
276 glXMakeCurrent(m_display, m_window, m_context);
280 ::glXSwapBuffers(m_display, m_window);
283 version = glGetString(GL_VERSION);
285 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 getSwapInterval(int &intervalOut) override
GHOST_TSuccess setSwapInterval(int interval) override
GHOST_ContextGLX(bool stereoVisual, Window window, Display *display, GLXFBConfig fbconfig, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)