[Mesa-dev] [PATCH 2/2] wglinfo: query and report multisample information

Jose Fonseca jfonseca at vmware.com
Mon Jun 9 07:22:12 PDT 2014


I don't think that OpenGL ICD should advertise multi-sample formats via the standard DescribePixelFormat.  http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt states:

    Indices are assigned to pixel formats in the following order:

    1. Accelerated pixel formats that are displayable

    2. Accelerated pixel formats that are displayable and which have
       extended attributes

    3. Generic pixel formats

    4. Accelerated pixel formats that are non displayable

    ChoosePixelFormat will never select pixel formats from either group
    2 or group 4. Each pixel format in group 2 is required to appear
    identical to some pixel format in group 1 when queried by
    DescribePixelFormat. Consequently, ChoosePixelFormat will always
    select a format from group 1 when it might otherwise have selected a
    format from group 2. Pixel formats in group 4 cannot be accessed by
    ChoosePixelFormat at all.

That is, IIUC, in order to discover multi-sampled formats one must get the the number of pixel formats via wglGetPixelFormatAttribivARB(WGL_NUMBER_PIXEL_FORMATS_ARB) instead of 

   numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
   if (numVisuals == 0)
      return;

And I'm not even sure if it is OK to call DescribePixelFormat() with extended pixel formats or if one must use exclusively wglGetPixelFormatAttribivARB/wglGetPixelFormatAttribivARB.  You can see how GLFW does it on https://github.com/glfw/glfw/blob/master/src/wgl_context.c#L144

Jose


----- Original Message -----
> Before, we always reported zeros in the multisample columns of the
> format list.  Since PIXELFORMATDESCRIPTOR doesn't have fields for
> multisample, we use a new format_info structure to extend that type.
> ---
>  src/wgl/wglinfo.c |  145
>  +++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 91 insertions(+), 54 deletions(-)
> 
> diff --git a/src/wgl/wglinfo.c b/src/wgl/wglinfo.c
> index 2b2c921..76478e2 100644
> --- a/src/wgl/wglinfo.c
> +++ b/src/wgl/wglinfo.c
> @@ -50,6 +50,18 @@ typedef enum
>  } InfoMode;
>  
>  
> +static GLboolean have_WGL_ARB_pixel_format;
> +static GLboolean have_WGL_ARB_multisample;
> +
> +
> +/**
> + * An extension of PIXELFORMATDESCRIPTOR to handle multisample, etc.
> + */
> +struct format_info {
> +   PIXELFORMATDESCRIPTOR pfd;
> +   unsigned sampleBuffers, numSamples;
> +};
> +
>  
>  static LRESULT CALLBACK
>  WndProc(HWND hWnd,
> @@ -159,6 +171,12 @@ print_screen_info(HDC _hdc, GLboolean limits, GLboolean
> singleLine)
>              printf("WGL extensions:\n");
>              print_extension_list(wglExtensions, singleLine);
>           }
> +         if (extension_supported("WGL_ARB_pixel_format", wglExtensions)) {
> +            have_WGL_ARB_pixel_format = GL_TRUE;
> +         }
> +         if (extension_supported("WGL_ARB_multisample", wglExtensions)) {
> +            have_WGL_ARB_multisample = GL_TRUE;
> +         }
>        }
>  #endif
>        printf("OpenGL vendor string: %s\n", glVendor);
> @@ -208,27 +226,27 @@ visual_render_type_name(BYTE iPixelType)
>  }
>  
>  static void
> -print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
> +print_visual_attribs_verbose(int iPixelFormat, const struct format_info
> *info)
>  {
>     printf("Visual ID: %x  generic=%d  native=%d\n",
>            iPixelFormat,
> -          ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> -          ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0);
> +          info->pfd.dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> +          info->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0);
>     printf("    bufferSize=%d level=%d renderType=%s doubleBuffer=%d
>     stereo=%d\n",
> -          0 /* ppfd->bufferSize */, 0 /* ppfd->level */,
> -	  visual_render_type_name(ppfd->iPixelType),
> -          ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
> -          ppfd->dwFlags & PFD_STEREO ? 1 : 0);
> +          0 /* info->pfd.bufferSize */, 0 /* info->pfd.level */,
> +	  visual_render_type_name(info->pfd.iPixelType),
> +          info->pfd.dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
> +          info->pfd.dwFlags & PFD_STEREO ? 1 : 0);
>     printf("    rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d
>     cAlphaBits=%d\n",
> -          ppfd->cRedBits, ppfd->cGreenBits,
> -          ppfd->cBlueBits, ppfd->cAlphaBits);
> +          info->pfd.cRedBits, info->pfd.cGreenBits,
> +          info->pfd.cBlueBits, info->pfd.cAlphaBits);
>     printf("    cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n",
> -          ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits);
> +          info->pfd.cAuxBuffers, info->pfd.cDepthBits,
> info->pfd.cStencilBits);
>     printf("    accum: cRedBits=%d cGreenBits=%d cBlueBits=%d
>     cAlphaBits=%d\n",
> -          ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
> -          ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits);
> +          info->pfd.cAccumRedBits, info->pfd.cAccumGreenBits,
> +          info->pfd.cAccumBlueBits, info->pfd.cAccumAlphaBits);
>     printf("    multiSample=%d  multiSampleBuffers=%d\n",
> -          0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */);
> +          info->numSamples, info->sampleBuffers);
>  }
>  
>  
> @@ -242,32 +260,32 @@ print_visual_attribs_short_header(void)
>  
>  
>  static void
> -print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
> +print_visual_attribs_short(int iPixelFormat, const struct format_info *info)
>  {
>     char *caveat = "None";
>  
>     printf("0x%02x %2d  %2d %2d %2d %2d %c%c %c  %c %2d %2d %2d %2d %2d %2d
>     %2d",
>            iPixelFormat,
> -          ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> -          ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
> +          info->pfd.dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> +          info->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
>            0,
> -          0 /* ppfd->bufferSize */,
> -          0 /* ppfd->level */,
> -          ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ',
> -          ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ',
> -          ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.',
> -          ppfd->dwFlags & PFD_STEREO ? 'y' : '.',
> -          ppfd->cRedBits, ppfd->cGreenBits,
> -          ppfd->cBlueBits, ppfd->cAlphaBits,
> -          ppfd->cAuxBuffers,
> -          ppfd->cDepthBits,
> -          ppfd->cStencilBits
> +          0 /* info->pfd.bufferSize */,
> +          0 /* info->pfd.level */,
> +          info->pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : ' ',
> +          info->pfd.iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ',
> +          info->pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.',
> +          info->pfd.dwFlags & PFD_STEREO ? 'y' : '.',
> +          info->pfd.cRedBits, info->pfd.cGreenBits,
> +          info->pfd.cBlueBits, info->pfd.cAlphaBits,
> +          info->pfd.cAuxBuffers,
> +          info->pfd.cDepthBits,
> +          info->pfd.cStencilBits
>            );
>  
>     printf(" %2d %2d %2d %2d %2d %1d %s\n",
> -          ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
> -          ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
> -          0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */,
> +          info->pfd.cAccumRedBits, info->pfd.cAccumGreenBits,
> +          info->pfd.cAccumBlueBits, info->pfd.cAccumAlphaBits,
> +          info->sampleBuffers, info->numSamples,
>            caveat
>            );
>  }
> @@ -283,29 +301,29 @@ print_visual_attribs_long_header(void)
>  
>  
>  static void
> -print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
> +print_visual_attribs_long(int iPixelFormat, const struct format_info *info)
>  {
>     printf("0x%2x %2d %11d %2d     %2d %2d  %4s %3d %3d %3d %3d %3d %3d",
>            iPixelFormat,
> -          ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> -          ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
> +          info->pfd.dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
> +          info->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
>            0,
> -          0 /* ppfd->bufferSize */,
> -          0 /* ppfd->level */,
> -          visual_render_type_name(ppfd->iPixelType),
> -          ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
> -          ppfd->dwFlags & PFD_STEREO ? 1 : 0,
> -          ppfd->cRedBits, ppfd->cGreenBits,
> -          ppfd->cBlueBits, ppfd->cAlphaBits
> +          0 /* info->pfd.bufferSize */,
> +          0 /* info->pfd.level */,
> +          visual_render_type_name(info->pfd.iPixelType),
> +          info->pfd.dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
> +          info->pfd.dwFlags & PFD_STEREO ? 1 : 0,
> +          info->pfd.cRedBits, info->pfd.cGreenBits,
> +          info->pfd.cBlueBits, info->pfd.cAlphaBits
>            );
>  
>     printf(" %3d %4d %2d %3d %3d %3d %3d  %2d  %2d\n",
> -          ppfd->cAuxBuffers,
> -          ppfd->cDepthBits,
> -          ppfd->cStencilBits,
> -          ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
> -          ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
> -          0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */
> +          info->pfd.cAuxBuffers,
> +          info->pfd.cDepthBits,
> +          info->pfd.cStencilBits,
> +          info->pfd.cAccumRedBits, info->pfd.cAccumGreenBits,
> +          info->pfd.cAccumBlueBits, info->pfd.cAccumAlphaBits,
> +          info->sampleBuffers, info->numSamples
>            );
>  }
>  
> @@ -313,20 +331,25 @@ print_visual_attribs_long(int iPixelFormat,
> LPPIXELFORMATDESCRIPTOR ppfd)
>  static void
>  print_visual_info(HDC hdc, InfoMode mode)
>  {
> -   PIXELFORMATDESCRIPTOR pfd;
> +   PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB_func;
> +   struct format_info info;
>     int numVisuals, numWglVisuals;
>     int i;
>  
> +   wglGetPixelFormatAttribivARB_func =
> +      (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
> +      wglGetProcAddress("wglGetPixelFormatAttribivARB");
> +
>     numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR),
>     NULL);
>     if (numVisuals == 0)
>        return;
>  
>     numWglVisuals = 0;
>     for (i = 0; i < numVisuals; i++) {
> -      if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
> +      if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR),
> &info.pfd))
>  	 continue;
>  
> -      //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
> +      //if(!(info.pfd.dwFlags & PFD_SUPPORT_OPENGL))
>        //   continue;
>  
>        ++numWglVisuals;
> @@ -340,18 +363,32 @@ print_visual_info(HDC hdc, InfoMode mode)
>        print_visual_attribs_long_header();
>  
>     for (i = 0; i < numVisuals; i++) {
> -      if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
> +      if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR),
> &info.pfd))
>  	 continue;
>  
> -      //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
> +      //if(!(info.pfd.dwFlags & PFD_SUPPORT_OPENGL))
>        //   continue;
>  
> +      if (have_WGL_ARB_pixel_format && have_WGL_ARB_multisample) {
> +         int attribs[] = { WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB };
> +         int values[2], layer = 0;
> +         if (wglGetPixelFormatAttribivARB_func(hdc, i, layer,
> +                                               2, attribs, values)) {
> +            info.sampleBuffers = values[0];
> +            info.numSamples = values[1];
> +         }
> +         else {
> +            info.sampleBuffers = 0;
> +            info.numSamples = 0;
> +         }
> +      }
> +
>        if (mode == Verbose)
> -	 print_visual_attribs_verbose(i, &pfd);
> +	 print_visual_attribs_verbose(i, &info);
>        else if (mode == Normal)
> -         print_visual_attribs_short(i, &pfd);
> +         print_visual_attribs_short(i, &info);
>        else if (mode == Wide)
> -         print_visual_attribs_long(i, &pfd);
> +         print_visual_attribs_long(i, &info);
>     }
>     printf("\n");
>  }
> --
> 1.7.10.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=mIR8V6P%2FYoxEbnhUZudn2DC8YBTiHYlMkU%2FRwIHNl6I%3D%0A&s=62e7dd68a5ab08412f68fbcd48475f3f35c3aa10cd4290d53f30b4632ab3b800
> 

Series is

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>


More information about the mesa-dev mailing list