Resent resync patch with little correction

Regards,
Raphael

On Thursday 15 December 2005 23:59, Raphael wrote:
> Hi,
>
> Thix patch should fix last wgl patch regression
> anyway i don't understand why ATI drivers don't support older GLX 1.3 specs
> (as 1.4 is already here).
>
> For glXGetFBConfigs i don't plan to support a compatibility code,
> it should be too buggy (on pixel format selection) as was older opengl code
> as we can't query visuals
>
> Changelog:
>  - fix wgl regression: test glx server version and extensions to use (and
> not use glXQueryDrawable on older glx implementations)
>
> Regards,
> Raphael

? opengl32.dll.dbg.c
? opengl32.spec.def
Index: wgl.c
===================================================================
RCS file: /home/wine/wine/dlls/opengl32/wgl.c,v
retrieving revision 1.71
diff -u -r1.71 wgl.c
--- wgl.c	8 Dec 2005 13:09:37 -0000	1.71
+++ wgl.c	15 Dec 2005 22:48:33 -0000
@@ -39,6 +39,9 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
 
+/** global glx object */
+wine_glx_t wine_glx;
+
 /* x11drv GDI escapes */
 #define X11DRV_ESCAPE 6789
 enum x11drv_escape_codes
@@ -191,7 +194,7 @@
     GLXFBConfig* cfgs_fmt = NULL;
     int value;
     int gl_test = 0;
-    cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
+    cfgs_fmt = wine_glx.p_glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
     if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
       ERR("Cannot get FB Configs, expect problems.\n");
       SetLastError(ERROR_INVALID_PIXEL_FORMAT);
@@ -203,7 +206,7 @@
       return NULL;
     }
     cur_cfg = cfgs_fmt[hdcPF - 1];
-    gl_test = glXGetFBConfigAttrib(display, cur_cfg, GLX_FBCONFIG_ID, &value);
+    gl_test = wine_glx.p_glXGetFBConfigAttrib(display, cur_cfg, GLX_FBCONFIG_ID, &value);
     if (gl_test) {
       ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
       SetLastError(ERROR_INVALID_PIXEL_FORMAT);
@@ -220,7 +223,7 @@
   ret->display = display;
   ret->fb_conf = cur_cfg;
   /*ret->vis = vis;*/
-  ret->vis = glXGetVisualFromFBConfig(display, cur_cfg);
+  ret->vis = wine_glx.p_glXGetVisualFromFBConfig(display, cur_cfg);
 
   TRACE(" creating context %p (GL context creation delayed)\n", ret);
   return (HGLRC) ret;
@@ -463,6 +466,38 @@
   }
 }
 
+static int describeContext(Wine_GLContext* ctx) {
+  int tmp;
+  int ctx_vis_id;
+  TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
+  wine_glx.p_glXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
+  TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
+  wine_glx.p_glXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
+  TRACE(" - VISUAL_ID 0x%x\n", tmp);
+  ctx_vis_id = tmp;
+  return ctx_vis_id;
+}
+
+static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
+  int tmp;
+  int draw_vis_id;
+  if (3 > wine_glx.version || NULL == wine_glx.p_glXQueryDrawable)  {
+    /** glXQueryDrawable not available so returns not supported */
+    return -1;
+  }
+  TRACE(" Drawable %p have :\n", (void*) drawable);
+  wine_glx.p_glXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
+  TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
+  wine_glx.p_glXQueryDrawable(ctx->display, drawable, GLX_VISUAL_ID, (unsigned int*) &tmp);
+  TRACE(" - VISUAL_ID as 0x%x\n", tmp);
+  draw_vis_id = tmp;
+  wine_glx.p_glXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
+  TRACE(" - WIDTH as %d\n", tmp);
+  wine_glx.p_glXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
+  TRACE(" - HEIGHT as %d\n", tmp);
+  return draw_vis_id;
+}
+
 /***********************************************************************
  *		wglMakeCurrent (OPENGL32.@)
  */
@@ -479,31 +514,13 @@
       Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
       Drawable drawable = get_drawable( hdc );
       if (ctx->ctx == NULL) {
-	int tmp;
 	int draw_vis_id, ctx_vis_id;
         VisualID visualid = (VisualID)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
+	TRACE(" Wine desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid);
+	draw_vis_id = describeDrawable(ctx, drawable);
+	ctx_vis_id = describeContext(ctx);
 
-	TRACE(" desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid);
-
-	TRACE(" drawable %p have :\n", (void*) drawable);
-	glXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
-	TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
-	glXQueryDrawable(ctx->display, drawable, GLX_VISUAL_ID, (unsigned int*) &tmp);
-	TRACE(" - VISUAL_ID as 0x%x\n", tmp);
-	draw_vis_id = tmp;
-	glXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
-	TRACE(" - WIDTH as %d\n", tmp);
-	glXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
-	TRACE(" - HEIGHT as %d\n", tmp);
-
-	TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
-	glXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
-	TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
-	glXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
-	TRACE(" - VISUAL_ID 0x%x\n", tmp);
-	ctx_vis_id = tmp;
-
-	if (draw_vis_id == visualid && draw_vis_id != ctx_vis_id) {
+	if (-1 == draw_vis_id || (draw_vis_id == visualid && draw_vis_id != ctx_vis_id)) {
 	  /**
 	   * Inherits from root window so reuse desktop visual
 	   */
@@ -539,17 +556,21 @@
 
   ENTER_GL();
   if (hglrc == NULL) {
-      ret = glXMakeCurrent(default_display, None, NULL);
+    ret = glXMakeCurrent(default_display, None, NULL);
   } else {
-    Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
-    Drawable d_draw = get_drawable( hDrawDC );
-    Drawable d_read = get_drawable( hReadDC );
-
-    if (ctx->ctx == NULL) {
-      ctx->ctx = glXCreateContext(ctx->display, ctx->vis, NULL, True);
-      TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
+    if (NULL == wine_glx.p_glXMakeContextCurrent) {
+      ret = FALSE;
+    } else {
+      Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
+      Drawable d_draw = get_drawable( hDrawDC );
+      Drawable d_read = get_drawable( hReadDC );
+      
+      if (ctx->ctx == NULL) {
+	ctx->ctx = glXCreateContext(ctx->display, ctx->vis, NULL, True);
+	TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
+      }
+      ret = wine_glx.p_glXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
     }
-    ret = glXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
   }
   LEAVE_GL();
   
@@ -618,12 +639,14 @@
   } else {
     if (org->ctx == NULL) {
       ENTER_GL();
+      describeContext(org);
       org->ctx = glXCreateContext(org->display, org->vis, NULL, True);
       LEAVE_GL();
       TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
     }
     if (NULL != dest) {
       ENTER_GL();
+      describeContext(dest);
       /* Create the destination context with display lists shared */
       dest->ctx = glXCreateContext(org->display, dest->vis, org->ctx, True);
       LEAVE_GL();
@@ -875,7 +898,21 @@
 }
 
 void internal_glGetIntegerv(GLenum pname, GLint* params) {
-  glGetIntegerv(pname, params); 
+  glGetIntegerv(pname, params);
+  if (pname == GL_DEPTH_BITS) { 
+    GLXContext gl_ctx = glXGetCurrentContext();
+    Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
+    /*TRACE("returns Wine Ctx as %p\n", ret);*/
+    /** 
+     * if we cannot find a Wine Context
+     * we only have the default wine desktop context, 
+     * so if we have only a 24 depth say we have 32
+     */
+    if (NULL == ret && 24 == *params) { 
+      *params = 32;
+    }
+    TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
+  }
   if (pname == GL_ALPHA_BITS) {
     GLint tmp;
     GLXContext gl_ctx = glXGetCurrentContext();
@@ -894,6 +931,45 @@
 #define SONAME_LIBGL "libGL.so"
 #endif
 
+static void wgl_initialize_glx(Display *display, int screen, glXGetProcAddressARB_t proc) 
+{
+  const char *server_glx_version = glXQueryServerString(display, screen, GLX_VERSION);
+  const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
+  /*
+  const char *client_glx_version = glXGetClientString(display, GLX_VERSION);
+  const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
+  const char *glx_extensions = glXQueryExtensionsString(display, screen);
+  */
+
+  memset(&wine_glx, 0, sizeof(wine_glx));
+
+  if (!strcmp("1.2", server_glx_version)) {
+    wine_glx.version = 2;
+  } else {
+    wine_glx.version = 3;
+  }
+
+  if (2 < wine_glx.version) {
+    wine_glx.p_glXChooseFBConfig = proc( (const GLubyte *) "glXChooseFBConfig");
+    wine_glx.p_glXGetFBConfigAttrib = proc( (const GLubyte *) "glXGetFBConfigAttrib");
+    wine_glx.p_glXGetVisualFromFBConfig = proc( (const GLubyte *) "glXGetVisualFromFBConfig");
+
+    /*wine_glx.p_glXGetFBConfigs = proc( (const GLubyte *) "glXGetFBConfigs");*/
+    wine_glx.p_glXQueryDrawable = proc( (const GLubyte *) "glXQueryDrawable");
+  } else {
+    if (NULL != strstr(server_glx_extensions, "GLX_SGIX_fbconfig")) {
+      wine_glx.p_glXChooseFBConfig = proc( (const GLubyte *) "glXChooseFBConfigSGIX");
+      wine_glx.p_glXGetFBConfigAttrib = proc( (const GLubyte *) "glXGetFBConfigAttribSGIX");
+      wine_glx.p_glXGetVisualFromFBConfig = proc( (const GLubyte *) "glXGetVisualFromFBConfigSGIX");
+    } else {
+      ERR(" glx_version as %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", server_glx_version);
+    }
+  }
+  /** try anyway to retrieve that calls, maybe they works using glx client tricks */
+  wine_glx.p_glXGetFBConfigs = proc( (const GLubyte *) "glXGetFBConfigs");
+  wine_glx.p_glXMakeContextCurrent = proc( (const GLubyte *) "glXMakeContextCurrent");
+}
+
 /* This is for brain-dead applications that use OpenGL functions before even
    creating a rendering context.... */
 static BOOL process_attach(void)
@@ -975,6 +1051,7 @@
   else
   {
     /* After context initialize also the list of supported WGL extensions. */
+    wgl_initialize_glx(default_display, DefaultScreen(default_display), p_glXGetProcAddressARB);
     wgl_ext_initialize_extensions(default_display, DefaultScreen(default_display), p_glXGetProcAddressARB, internal_gl_disabled_extensions);
   }
   return TRUE;
Index: wgl_ext.c
===================================================================
RCS file: /home/wine/wine/dlls/opengl32/wgl_ext.c,v
retrieving revision 1.15
diff -u -r1.15 wgl_ext.c
--- wgl_ext.c	8 Dec 2005 13:09:37 -0000	1.15
+++ wgl_ext.c	15 Dec 2005 22:48:33 -0000
@@ -1342,14 +1342,17 @@
     const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
     const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
     const char *gl_version = (const char *) glGetString(GL_VERSION);
+    const char *server_glx_version = glXQueryServerString(display, screen, GLX_VERSION);
     const char *glx_version = glXGetClientString(display, GLX_VERSION);
     int i;
 
-    TRACE("GL version      : %s.\n", debugstr_a(gl_version));
-    TRACE("GL exts         : %s.\n", debugstr_a(gl_extensions));
-    TRACE("GLX exts        : %s.\n", debugstr_a(glx_extensions));
-    TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
-    TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
+    TRACE("GL version         : %s.\n", debugstr_a(gl_version));
+    TRACE("GL exts            : %s.\n", debugstr_a(gl_extensions));
+    TRACE("GLX exts           : %s.\n", debugstr_a(glx_extensions));
+    TRACE("Server GLX version : %s.\n", debugstr_a(server_glx_version));
+    TRACE("Client GLX version : %s.\n", debugstr_a(glx_version));
+    TRACE("Server GLX exts    : %s.\n", debugstr_a(server_glx_extensions));
+    TRACE("Client GLX exts    : %s.\n", debugstr_a(client_glx_extensions));
 
     for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
         if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
Index: wgl_ext.h
===================================================================
RCS file: /home/wine/wine/dlls/opengl32/wgl_ext.h,v
retrieving revision 1.3
diff -u -r1.3 wgl_ext.h
--- wgl_ext.h	28 Apr 2005 18:31:15 -0000	1.3
+++ wgl_ext.h	15 Dec 2005 22:48:33 -0000
@@ -39,4 +39,17 @@
 extern WGL_extension wgl_extension_registry[];
 extern int wgl_extension_registry_size;
 
+typedef struct wine_glx_s {
+  unsigned     version;
+  /** SGIX / 1.3 */
+  GLXFBConfig* (*p_glXChooseFBConfig) (Display *dpy, int screen, const int *attrib_list, int *nelements);
+  int          (*p_glXGetFBConfigAttrib) (Display *dpy, GLXFBConfig config, int attribute, int *value);
+  XVisualInfo* (*p_glXGetVisualFromFBConfig) (Display *dpy, GLXFBConfig config); 
+  /** 1.3 */
+  GLXFBConfig* (*p_glXGetFBConfigs) (Display *dpy, int screen, int *nelements);
+  void         (*p_glXQueryDrawable) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);
+  Bool         (*p_glXMakeContextCurrent) (Display *, GLXDrawable, GLXDrawable, GLXContext);
+} wine_glx_t;
+extern wine_glx_t wine_glx;
+
 #endif /* __DLLS_OPENGL32_WGL_EXT_H */

Attachment: pgpSuuvrjWoUe.pgp
Description: PGP signature



Reply via email to