Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / common / utils.c
index c723dfdeb00a4f73938e4c26ef0f93203f5cc065..2a1ded3871ded9899a16ab5f3fa4ee02e8c7f763 100644 (file)
 
 #include <string.h>
 #include <stdlib.h>
-#include "mtypes.h"
-#include "extensions.h"
+#include "main/mtypes.h"
+#include "main/extensions.h"
+#include "glapi/dispatch.h"
 #include "utils.h"
-#include "dispatch.h"
 
 int driDispatchRemapTable[ driDispatchRemapTable_size ];
 
@@ -310,8 +310,10 @@ void driInitSingleExtension( GLcontext * ctx,
             */
            offset = _glapi_add_dispatch( functions, parameter_signature );
            if (offset == -1) {
+#if 0 /* this causes noise with egl */
                fprintf(stderr, "DISPATCH ERROR! _glapi_add_dispatch failed "
                        "to add %s!\n", functions[0]);
+#endif
            }
            else if (ext->functions[i].remap_index != -1) {
                driDispatchRemapTable[ ext->functions[i].remap_index ] = 
@@ -504,6 +506,9 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
  *                      \c GLX_SWAP_UNDEFINED_OML.  See the
  *                      GLX_OML_swap_method extension spec for more details.
  * \param num_db_modes  Number of entries in \c db_modes.
+ * \param msaa_samples  Array of msaa sample count. 0 represents a visual
+ *                      without a multisample buffer.
+ * \param num_msaa_modes Number of entries in \c msaa_samples.
  * \param visType       GLX visual type.  Usually either \c GLX_TRUE_COLOR or
  *                      \c GLX_DIRECT_COLOR.
  * 
@@ -521,11 +526,12 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
  */
 __DRIconfig **
 driCreateConfigs(GLenum fb_format, GLenum fb_type,
-                const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
+                const uint8_t * depth_bits, const uint8_t * stencil_bits,
                 unsigned num_depth_stencil_bits,
-                const GLenum * db_modes, unsigned num_db_modes)
+                const GLenum * db_modes, unsigned num_db_modes,
+                const u_int8_t * msaa_samples, unsigned num_msaa_modes)
 {
-   static const u_int8_t bits_table[4][4] = {
+   static const uint8_t bits_table[4][4] = {
      /* R  G  B  A */
       { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
       { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
@@ -533,7 +539,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 8, 8, 8, 8 }  /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
    };
 
-   static const u_int32_t masks_table_rgb[6][4] = {
+   static const uint32_t masks_table_rgb[6][4] = {
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
@@ -542,7 +548,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_rgba[6][4] = {
+   static const uint32_t masks_table_rgba[6][4] = {
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
@@ -551,7 +557,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_bgr[6][4] = {
+   static const uint32_t masks_table_bgr[6][4] = {
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
@@ -560,7 +566,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_bgra[6][4] = {
+   static const uint32_t masks_table_bgra[6][4] = {
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
@@ -569,7 +575,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int8_t bytes_per_pixel[6] = {
+   static const uint8_t bytes_per_pixel[6] = {
       1, /* 3_3_2       */
       1, /* 2_3_3_REV   */
       2, /* 5_6_5       */
@@ -578,14 +584,12 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       4  /* 8_8_8_8_REV */
    };
 
-   const u_int8_t  * bits;
-   const u_int32_t * masks;
+   const uint8_t  * bits;
+   const uint32_t * masks;
    int index;
    __DRIconfig **configs, **c;
    __GLcontextModes *modes;
-   unsigned i;
-   unsigned j;
-   unsigned k;
+   unsigned i, j, k, h;
    unsigned num_modes;
    unsigned num_accum_bits = 2;
 
@@ -658,7 +662,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
         break;
    }
 
-   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits;
+   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes;
    configs = _mesa_calloc((num_modes + 1) * sizeof *configs);
    if (configs == NULL)
        return NULL;
@@ -666,66 +670,72 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
     c = configs;
     for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
        for ( i = 0 ; i < num_db_modes ; i++ ) {
-           for ( j = 0 ; j < num_accum_bits ; j++ ) {
-               *c = _mesa_malloc (sizeof **c);
-               modes = &(*c)->modes;
-               c++;
-
-               memset(modes, 0, sizeof *modes);
-               modes->redBits   = bits[0];
-               modes->greenBits = bits[1];
-               modes->blueBits  = bits[2];
-               modes->alphaBits = bits[3];
-               modes->redMask   = masks[0];
-               modes->greenMask = masks[1];
-               modes->blueMask  = masks[2];
-               modes->alphaMask = masks[3];
-               modes->rgbBits   = modes->redBits + modes->greenBits
-                   + modes->blueBits + modes->alphaBits;
-
-               modes->accumRedBits   = 16 * j;
-               modes->accumGreenBits = 16 * j;
-               modes->accumBlueBits  = 16 * j;
-               modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
-               modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
-
-               modes->stencilBits = stencil_bits[k];
-               modes->depthBits = depth_bits[k];
-
-               modes->transparentPixel = GLX_NONE;
-               modes->transparentRed = GLX_DONT_CARE;
-               modes->transparentGreen = GLX_DONT_CARE;
-               modes->transparentBlue = GLX_DONT_CARE;
-               modes->transparentAlpha = GLX_DONT_CARE;
-               modes->transparentIndex = GLX_DONT_CARE;
-               modes->visualType = GLX_DONT_CARE;
-               modes->renderType = GLX_RGBA_BIT;
-               modes->drawableType = GLX_WINDOW_BIT;
-               modes->rgbMode = GL_TRUE;
-
-               if ( db_modes[i] == GLX_NONE ) {
-                   modes->doubleBufferMode = GL_FALSE;
-               }
-               else {
-                   modes->doubleBufferMode = GL_TRUE;
-                   modes->swapMethod = db_modes[i];
-               }
-
-               modes->haveAccumBuffer = ((modes->accumRedBits +
+           for ( h = 0 ; h < num_msaa_modes; h++ ) {
+               for ( j = 0 ; j < num_accum_bits ; j++ ) {
+                   *c = _mesa_malloc (sizeof **c);
+                   modes = &(*c)->modes;
+                   c++;
+
+                   memset(modes, 0, sizeof *modes);
+                   modes->redBits   = bits[0];
+                   modes->greenBits = bits[1];
+                   modes->blueBits  = bits[2];
+                   modes->alphaBits = bits[3];
+                   modes->redMask   = masks[0];
+                   modes->greenMask = masks[1];
+                   modes->blueMask  = masks[2];
+                   modes->alphaMask = masks[3];
+                   modes->rgbBits   = modes->redBits + modes->greenBits
+                       + modes->blueBits + modes->alphaBits;
+
+                   modes->accumRedBits   = 16 * j;
+                   modes->accumGreenBits = 16 * j;
+                   modes->accumBlueBits  = 16 * j;
+                   modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
+                   modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
+
+                   modes->stencilBits = stencil_bits[k];
+                   modes->depthBits = depth_bits[k];
+
+                   modes->transparentPixel = GLX_NONE;
+                   modes->transparentRed = GLX_DONT_CARE;
+                   modes->transparentGreen = GLX_DONT_CARE;
+                   modes->transparentBlue = GLX_DONT_CARE;
+                   modes->transparentAlpha = GLX_DONT_CARE;
+                   modes->transparentIndex = GLX_DONT_CARE;
+                   modes->visualType = GLX_DONT_CARE;
+                   modes->renderType = GLX_RGBA_BIT;
+                   modes->drawableType = GLX_WINDOW_BIT;
+                   modes->rgbMode = GL_TRUE;
+
+                   if ( db_modes[i] == GLX_NONE ) {
+                       modes->doubleBufferMode = GL_FALSE;
+                   }
+                   else {
+                       modes->doubleBufferMode = GL_TRUE;
+                       modes->swapMethod = db_modes[i];
+                   }
+
+                   modes->samples = msaa_samples[h];
+                   modes->sampleBuffers = modes->samples ? 1 : 0;
+
+
+                   modes->haveAccumBuffer = ((modes->accumRedBits +
                                           modes->accumGreenBits +
                                           modes->accumBlueBits +
                                           modes->accumAlphaBits) > 0);
-               modes->haveDepthBuffer = (modes->depthBits > 0);
-               modes->haveStencilBuffer = (modes->stencilBits > 0);
-
-               modes->bindToTextureRgb = GL_TRUE;
-               modes->bindToTextureRgba = GL_TRUE;
-               modes->bindToMipmapTexture = GL_FALSE;
-               modes->bindToTextureTargets = modes->rgbMode ?
-                   __DRI_ATTRIB_TEXTURE_1D_BIT |
-                   __DRI_ATTRIB_TEXTURE_2D_BIT |
-                   __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT :
-                   0;
+                   modes->haveDepthBuffer = (modes->depthBits > 0);
+                   modes->haveStencilBuffer = (modes->stencilBits > 0);
+
+                   modes->bindToTextureRgb = GL_TRUE;
+                   modes->bindToTextureRgba = GL_TRUE;
+                   modes->bindToMipmapTexture = GL_FALSE;
+                   modes->bindToTextureTargets = modes->rgbMode ?
+                       __DRI_ATTRIB_TEXTURE_1D_BIT |
+                       __DRI_ATTRIB_TEXTURE_2D_BIT |
+                       __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT :
+                       0;
+               }
            }
        }
     }