@@ -153,22 +153,20 @@ class OpenGLHook : LibraryHook, public GLPlatform
153153 bool is_direct = false ;
154154
155155 PFNGLXISDIRECTPROC glXIsDirectProc = (PFNGLXISDIRECTPROC)dlsym (RTLD_NEXT, " glXIsDirect" );
156- PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfigProc =
157- (PFNGLXCHOOSEFBCONFIGPROC)dlsym (RTLD_NEXT, " glXChooseFBConfig" );
158156 PFNGLXCREATEPBUFFERPROC glXCreatePbufferProc =
159157 (PFNGLXCREATEPBUFFERPROC)dlsym (RTLD_NEXT, " glXCreatePbuffer" );
160158
161159 if (glXIsDirectProc)
162160 is_direct = glXIsDirectProc (share.dpy , share.ctx );
163161
164- if (glXChooseFBConfigProc && glXCreatePbufferProc)
162+ if (glXChooseFBConfig_real && glXCreatePbufferProc)
165163 {
166164 // don't need to care about the fb config as we won't be using the default framebuffer
167165 // (backbuffer)
168166 int visAttribs[] = {0 };
169167 int numCfgs = 0 ;
170168 GLXFBConfig *fbcfg =
171- glXChooseFBConfigProc (share.dpy , DefaultScreen (share.dpy ), visAttribs, &numCfgs);
169+ glXChooseFBConfig_real (share.dpy , DefaultScreen (share.dpy ), visAttribs, &numCfgs);
172170
173171 // don't care about pbuffer properties as we won't render directly to this
174172 int pbAttribs[] = {GLX_PBUFFER_WIDTH, 32 , GLX_PBUFFER_HEIGHT, 32 , 0 };
@@ -197,6 +195,157 @@ class OpenGLHook : LibraryHook, public GLPlatform
197195 glXDestroyContext_real (context.dpy , context.ctx );
198196 }
199197
198+ void DeleteReplayContext (GLWindowingData context)
199+ {
200+ if (glXDestroyContext_real)
201+ {
202+ glXMakeContextCurrent_real (context.dpy , 0L , 0L , NULL );
203+ glXDestroyContext_real (context.dpy , context.ctx );
204+ }
205+ }
206+
207+ void SwapBuffers (GLWindowingData context) { glXSwapBuffers_real (context.dpy , context.wnd ); }
208+ void GetOutputWindowDimensions (GLWindowingData context, int32_t &w, int32_t &h)
209+ {
210+ glXQueryDrawable_real (context.dpy , context.wnd , GLX_WIDTH, (unsigned int *)&w);
211+ glXQueryDrawable_real (context.dpy , context.wnd , GLX_HEIGHT, (unsigned int *)&h);
212+ }
213+
214+ bool IsOutputWindowVisible (GLWindowingData context)
215+ {
216+ GLNOTIMP (" Optimisation missing - output window always returning true" );
217+
218+ return true ;
219+ }
220+
221+ GLWindowingData MakeOutputWindow (WindowingSystem system, void *data, bool depth,
222+ GLWindowingData share_context)
223+ {
224+ GLWindowingData ret;
225+
226+ Display *dpy = NULL ;
227+ Drawable draw = 0 ;
228+
229+ if (system == eWindowingSystem_Xlib)
230+ {
231+ #if ENABLED(RDOC_XLIB)
232+ XlibWindowData *xlib = (XlibWindowData *)data;
233+
234+ dpy = xlib->display ;
235+ draw = xlib->window ;
236+ #else
237+ RDCERR (
238+ " Xlib windowing system data passed in, but support is not compiled in. GL must have xlib "
239+ " support compiled in" );
240+ #endif
241+ }
242+ else if (system == eWindowingSystem_Unknown)
243+ {
244+ // allow undefined so that internally we can create a window-less context
245+ dpy = XOpenDisplay (NULL );
246+
247+ if (dpy == NULL )
248+ return ret;
249+ }
250+ else
251+ {
252+ RDCERR (" Unexpected window system %u" , system);
253+ }
254+
255+ static int visAttribs[] = {GLX_X_RENDERABLE,
256+ True,
257+ GLX_DRAWABLE_TYPE,
258+ GLX_WINDOW_BIT,
259+ GLX_RENDER_TYPE,
260+ GLX_RGBA_BIT,
261+ GLX_X_VISUAL_TYPE,
262+ GLX_TRUE_COLOR,
263+ GLX_RED_SIZE,
264+ 8 ,
265+ GLX_GREEN_SIZE,
266+ 8 ,
267+ GLX_BLUE_SIZE,
268+ 8 ,
269+ GLX_DOUBLEBUFFER,
270+ True,
271+ GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB,
272+ True,
273+ 0 };
274+ int numCfgs = 0 ;
275+ GLXFBConfig *fbcfg = glXChooseFBConfig_real (dpy, DefaultScreen (dpy), visAttribs, &numCfgs);
276+
277+ if (fbcfg == NULL )
278+ {
279+ XCloseDisplay (dpy);
280+ RDCERR (" Couldn't choose default framebuffer config" );
281+ return ret;
282+ }
283+
284+ if (draw != 0 )
285+ {
286+ // Choose FB config with a GLX_VISUAL_ID that matches the X screen.
287+ VisualID visualid_correct = DefaultVisual (dpy, DefaultScreen (dpy))->visualid ;
288+ for (int i = 0 ; i < numCfgs; i++)
289+ {
290+ int visualid;
291+ glXGetFBConfigAttrib (dpy, fbcfg[i], GLX_VISUAL_ID, &visualid);
292+ if ((VisualID)visualid == visualid_correct)
293+ {
294+ fbcfg[0 ] = fbcfg[i];
295+ break ;
296+ }
297+ }
298+ }
299+
300+ int attribs[64 ] = {0 };
301+ int i = 0 ;
302+
303+ attribs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
304+ attribs[i++] = GLCoreVersion / 10 ;
305+ attribs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
306+ attribs[i++] = GLCoreVersion % 10 ;
307+ attribs[i++] = GLX_CONTEXT_FLAGS_ARB;
308+ #if ENABLED(RDOC_DEVEL)
309+ attribs[i++] = GLX_CONTEXT_DEBUG_BIT_ARB;
310+ #else
311+ attribs[i++] = 0 ;
312+ #endif
313+ attribs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
314+ attribs[i++] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
315+
316+ GLXContext ctx = glXCreateContextAttribsARB_real (dpy, fbcfg[0 ], share_context.ctx , true , attribs);
317+
318+ if (ctx == NULL )
319+ {
320+ XCloseDisplay (dpy);
321+ RDCERR (" Couldn't create %d.%d context - something changed since creation" , GLCoreVersion / 10 ,
322+ GLCoreVersion % 10 );
323+ return ret;
324+ }
325+
326+ GLXDrawable wnd = 0 ;
327+
328+ if (draw == 0 )
329+ {
330+ // don't care about pbuffer properties as we won't render directly to this
331+ int pbAttribs[] = {GLX_PBUFFER_WIDTH, 32 , GLX_PBUFFER_HEIGHT, 32 , 0 };
332+
333+ wnd = glXCreatePbuffer (dpy, fbcfg[0 ], pbAttribs);
334+ }
335+ else
336+ {
337+ wnd = glXCreateWindow (dpy, fbcfg[0 ], draw, 0 );
338+ }
339+
340+ XFree (fbcfg);
341+
342+ ret.dpy = dpy;
343+ ret.ctx = ctx;
344+ ret.wnd = wnd;
345+
346+ return ret;
347+ }
348+
200349 bool DrawQuads (float width, float height, const std::vector<Vec4f> &vertices);
201350
202351 WrappedOpenGL *GetDriver ()
@@ -218,6 +367,8 @@ class OpenGLHook : LibraryHook, public GLPlatform
218367 PFNGLXGETVISUALFROMFBCONFIGPROC glXGetVisualFromFBConfig_real;
219368 PFNGLXCREATEWINDOWPROC glXCreateWindow_real;
220369 PFNGLXDESTROYWINDOWPROC glXDestroyWindow_real;
370+ PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig_real;
371+ PFNGLXQUERYDRAWABLEPROC glXQueryDrawable_real;
221372
222373 set<GLXContext> m_Contexts;
223374
@@ -258,6 +409,11 @@ class OpenGLHook : LibraryHook, public GLPlatform
258409 glXCreateWindow_real = (PFNGLXCREATEWINDOWPROC)dlsym (libGLdlsymHandle, " glXCreateWindow" );
259410 if (glXDestroyWindow_real == NULL )
260411 glXDestroyWindow_real = (PFNGLXDESTROYWINDOWPROC)dlsym (libGLdlsymHandle, " glXDestroyWindow" );
412+ if (glXChooseFBConfig_real == NULL )
413+ glXChooseFBConfig_real =
414+ (PFNGLXCHOOSEFBCONFIGPROC)dlsym (libGLdlsymHandle, " glXChooseFBConfig" );
415+ if (glXQueryDrawable_real == NULL )
416+ glXQueryDrawable_real = (PFNGLXQUERYDRAWABLEPROC)dlsym (RTLD_NEXT, " glXQueryDrawable" );
261417
262418 return success;
263419 }
0 commit comments