Multi-Sample AA + PixelFormat - Init failed on ATI

Hello,

I use multisample anti-aliasing. It is working on nVidia and ATI cards with a classical pixel format (attributes).
I am using an existing code and I wanted to use the same attributes with and without mutisample. Without mutisample I use an existing classical PIXELFORMATDESCRIPTOR. And with mutisample I use attributes that seems the same (<-- beginner approach…). This works well with nvidia but not with ATI.

Do you see something wrong in my attribute variable ?
Or what is the correct approach to obtain the same rendering (color, transparency…) with and without multisample AA ?

I post below the attribute variable and the pixelFormatDescriptor.

Thanks for your advices.

	int iAttributes[] =
	{
		WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
		WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
		WGL_SWAP_METHOD_ARB, WGL_SWAP_COPY_ARB,
		WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		WGL_COLOR_BITS_ARB,32,
		WGL_RED_BITS_ARB, 8,
		WGL_RED_SHIFT_ARB, 24,
		WGL_GREEN_BITS_ARB, 8,
		WGL_GREEN_SHIFT_ARB, 16,
		WGL_BLUE_BITS_ARB, 8,
		WGL_BLUE_SHIFT_ARB, 8,
		WGL_ALPHA_BITS_ARB,8,
		WGL_ALPHA_SHIFT_ARB, 0,
		WGL_ACCUM_BITS_ARB, 0,
		WGL_ACCUM_RED_BITS_ARB, 0,
		WGL_ACCUM_GREEN_BITS_ARB, 0,
		WGL_ACCUM_BLUE_BITS_ARB, 0,
		WGL_ACCUM_ALPHA_BITS_ARB, 0, 
		WGL_DEPTH_BITS_ARB,24,
		WGL_STENCIL_BITS_ARB,1,
		WGL_AUX_BUFFERS_ARB, 0,
		WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
		WGL_SAMPLES_ARB,(int)AASize,
		0,0
	};
	PIXELFORMATDESCRIPTOR pixelDescriptor;
	pixelDescriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR);
	pixelDescriptor.nVersion = 1;
	pixelDescriptor.dwFlags
		= PFD_DRAW_TO_WINDOW
		| PFD_SUPPORT_OPENGL 
		| PFD_DOUBLEBUFFER
		| PFD_SWAP_COPY
		| PFD_STEREO_DONTCARE
		;

	pixelDescriptor.iPixelType = PFD_TYPE_RGBA;
	pixelDescriptor.cColorBits = 32;
	pixelDescriptor.cRedBits = 8;
	pixelDescriptor.cRedShift = 24;
	pixelDescriptor.cGreenBits = 8;
	pixelDescriptor.cGreenShift = 16;
	pixelDescriptor.cBlueBits = 8;
	pixelDescriptor.cBlueShift = 8;
	pixelDescriptor.cAlphaBits = 8;
	pixelDescriptor.cAlphaShift = 0;
	pixelDescriptor.cAccumBits = 0;
	pixelDescriptor.cAccumRedBits = 0;
	pixelDescriptor.cAccumGreenBits = 0;
	pixelDescriptor.cAccumBlueBits = 0;
	pixelDescriptor.cAccumAlphaBits = 0;
	pixelDescriptor.cDepthBits = 24;
	pixelDescriptor.cStencilBits = 1;
	pixelDescriptor.cAuxBuffers = 0;
	pixelDescriptor.iLayerType = PFD_MAIN_PLANE;
	pixelDescriptor.bReserved = 0;
	pixelDescriptor.dwLayerMask = 0;
	pixelDescriptor.dwVisibleMask = 0;
	pixelDescriptor.dwDamageMask = 0;

Try getting rid of all of those shift attributes, and using WGL_STENCIL_BITS_ARB,8, instead of 1. Also, use 1 instead of GL_TRUE for the number of sample buffers.

Pilfering attribute setup code from something like FreeGLUT or GLFW can also be useful.

Get rid of any attributes you don’t care. You probably don’t care about shifts, accum or aux buffers, or even swap method.

It can be very useful to iterate all WGL pixel formats and query and dump their attributes. That way you see what pixel formats there really are and you will understand why you are not getting what you are asking for - because it is not there. Then you can improve your pixel format request. If you do not need something, do not specify the attribute at all. Asking for specific attribute values for WGL_SAMPLE_BUFFERS_ARB and WGL_SAMPLES_ARB can prevent you from getting a pixel format you could perfectly well use.

Edit: Here is some WGL pixel format debug code. It is far for complete but shows the interesting bits:

void platform_window::debug_pixel_format(int i)
{
    int attributes[17] = {
        WGL_DRAW_TO_WINDOW_ARB,             /*  0  */
        WGL_ACCELERATION_ARB,               /*  1  */
        WGL_SWAP_METHOD_ARB,                /*  2  */
        WGL_SUPPORT_OPENGL_ARB,             /*  3  */
        WGL_DOUBLE_BUFFER_ARB,              /*  4  */
        WGL_STEREO_ARB,                     /*  5  */
        WGL_PIXEL_TYPE_ARB,                 /*  6  */
        WGL_COLOR_BITS_ARB,                 /*  7  */
        WGL_RED_BITS_ARB,                   /*  8  */
        WGL_GREEN_BITS_ARB,                 /*  9  */
        WGL_BLUE_BITS_ARB,                  /* 10  */
        WGL_ALPHA_BITS_ARB,                 /* 11  */
        WGL_DEPTH_BITS_ARB,                 /* 12  */
        WGL_STENCIL_BITS_ARB,               /* 13  */
        WGL_SAMPLE_BUFFERS_ARB,             /* 14  */
        WGL_SAMPLES_ARB,                    /* 15  */
        WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB    /* 16  */
    };
    int values[18];
    wglGetPixelFormatAttribivARB(
        m_hdc,
        i,
        0,
        17,
        attributes,
        values
    );
    char t = ' ';
    switch(values[6])
    {
        case WGL_TYPE_RGBA_ARB:                 t = 'x'; break;
        case WGL_TYPE_RGBA_FLOAT_ARB:           t = 'f'; break;
        case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:  t = 'u'; break;
        case WGL_TYPE_COLORINDEX_ARB:           t = 'i'; break;
        default: t = '?'; break;
    }
    char a = ' ';
    switch(values[1])
    {
        case WGL_NO_ACCELERATION_ARB     : a = '-'; break;
        case WGL_GENERIC_ACCELERATION_ARB: a = 'g'; break;
        case WGL_FULL_ACCELERATION_ARB   : a = 'A'; break;
        default: a = '?'; break;
    }
    char s = ' ';
    switch(values[2])
    {
        case WGL_SWAP_EXCHANGE_ARB  : s = 'f'; break;
        case WGL_SWAP_COPY_ARB      : s = 'b'; break;
        case WGL_SWAP_UNDEFINED_ARB : s = 'u'; break;
        default: s = '?'; break;
    }
    printf(
        "format %2d: %d%d%d%d d/s:%d/%d ms:%d/%d srgb:%d pix: %c ste: %d db: %d a: %c w: %d s: %c o: %d
",
        i,
        values[8], values[9], values[10], values[11],   /* rgba */
        values[12], values[13],                         /* d/s  */
        values[14], values[15],                         /* ms   */
        values[16],                                     /* srgb */
        t,                                              /* pixel_type       */
        values[5],                                      /* stereo           */
        values[4],                                      /* double buffer    */
        a,                                              /* accelerated      */
        values[0],                                      /* draw to window   */
        s,                                              /* swap method      */
        values[3]
    );
}

    {
        int count_attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
        int count = 0;

        wglGetPixelFormatAttribivARB(
            m_hdc,
            0,
            0,
            1,
            &count_attribute,
            &count
        );

        for(int i = 1; i <= count; ++i)
        {
            debug_pixel_format(i);
        }
    }

Hello,

Thanks for your answers and for the code.
I will do what you advise : remove unnecessary attributes and test the attributes available on the ATI cards.

Thanks.

Hello,

You were right : it was the shift attributes that cause the problem. And I will remove the accum attributs too.

Tksuoran, I was unable to use your code : the function wglGetPixelFormatAttribivARB throws an access violation exception when called with WGL_NUMBER_PIXEL_FORMATS_ARB. I did not find why.
But it does not matter: I found the problem anyway.

Thanks for your help.