108#ifdef USE_GLXEW_INIT_WORKAROUND
109 const GLubyte *extStart = (GLubyte *)
"";
110 const GLubyte *extEnd;
111 if (glXQueryExtension(display_,
nullptr,
nullptr)) {
112 extStart = (
const GLubyte *)glXGetClientString(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 = context_profile_mask_ & GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
154 int profileBitCompat = context_profile_mask_ & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
157 int profileBitES = context_profile_mask_ & 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 && context_major_version_ == 1) {
169 fprintf(stderr,
"Warning! OpenGL ES profile not available.\n");
172 if (!GLXEW_EXT_create_context_es2_profile && profileBitES && context_major_version_ == 2) {
173 fprintf(stderr,
"Warning! OpenGL ES2 profile not available.\n");
179 if (GLXEW_ARB_create_context_profile && profileBitCore) {
180 profileMask |= profileBitCore;
182 if (GLXEW_ARB_create_context_profile && profileBitCompat) {
183 profileMask |= profileBitCompat;
187 if (GLXEW_EXT_create_context_es_profile && profileBitES) {
188 profileMask |= profileBitES;
192 if (profileMask != context_profile_mask_) {
193 fprintf(stderr,
"Warning! Ignoring untested OpenGL context profile mask bits.");
200 attribs[
i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
201 attribs[
i++] = profileMask;
204 if (context_major_version_ != 0) {
205 attribs[
i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
206 attribs[
i++] = context_major_version_;
207 attribs[
i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
208 attribs[
i++] = context_minor_version_;
211 if (context_flags_ != 0) {
212 attribs[
i++] = GLX_CONTEXT_FLAGS_ARB;
213 attribs[
i++] = context_flags_;
216 if (context_reset_notification_strategy_ != 0) {
217 if (GLXEW_ARB_create_context_robustness) {
218 attribs[
i++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
219 attribs[
i++] = context_reset_notification_strategy_;
222 fprintf(stderr,
"Warning! Cannot set the reset notification strategy.");
230 int pbuffer_attribs[] = {GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1,
None};
234 context_ = glXCreateContextAttribsARB(display_, fbconfig_, s_sharedContext,
true, attribs);
237 window_ = (
Window)glXCreatePbuffer(display_, fbconfig_, pbuffer_attribs);
241 GLXFBConfig *framebuffer_config =
nullptr;
248 framebuffer_config = glXChooseFBConfig(
249 display_, DefaultScreen(display_), glx_attribs, &fbcount);
252 if (framebuffer_config) {
253 context_ = glXCreateContextAttribsARB(
254 display_, framebuffer_config[0], s_sharedContext, True, attribs);
257 window_ = (
Window)glXCreatePbuffer(display_, framebuffer_config[0], pbuffer_attribs);
260 fbconfig_ = framebuffer_config[0];
261 XFree(framebuffer_config);
267 fprintf(stderr,
"Error! GLX_ARB_create_context not available.\n");
272 if (context_ !=
nullptr) {
273 const uchar *version;
275 if (!s_sharedContext) {
276 s_sharedContext = context_;
280 glXMakeCurrent(display_, window_, context_);
292 ::glXSwapBuffers(display_, window_);
295 version = glGetString(GL_VERSION);
297 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_ContextGLX(const GHOST_ContextParams &context_params, Window window, Display *display, GLXFBConfig fbconfig, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
GHOST_TSuccess releaseDrawingContext() override
GHOST_TSuccess activateDrawingContext() override
GHOST_TSuccess getSwapInterval(int &interval_out) override
GHOST_TSuccess swapBufferRelease() override
GHOST_TSuccess setSwapInterval(int interval) override
GHOST_TSuccess initializeDrawingContext() override
GHOST_Context(const GHOST_ContextParams &context_params)
static GHOST_Context * active_context_
virtual GHOST_TVSyncModes getVSync()
GHOST_ContextParams context_params_