st/wgl: refactor stw_pixelformat_init()
authorBrian Paul <brianp@vmware.com>
Wed, 8 Feb 2012 17:06:21 +0000 (10:06 -0700)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 10 Feb 2012 16:23:27 +0000 (16:23 +0000)
Replace duplicated code with add_color_format_variants() helper.

src/gallium/state_trackers/wgl/stw_pixelformat.c

index a9667a36981b37bb0ac7970fdf178f1ce5c4137b..b74b71b1ba69467f4896854eaaedb49f4e4ff433 100644 (file)
@@ -210,80 +210,73 @@ stw_pixelformat_add(
    }
 }
 
-void
-stw_pixelformat_init( void )
+
+/**
+ * Add the depth/stencil/accum/ms variants for a particular color format.
+ */
+static void
+add_color_format_variants(const struct stw_pf_color_info *color,
+                          boolean extended)
 {
    struct pipe_screen *screen = stw_dev->screen;
-   unsigned i, j, k, l;
-   
-   assert( !stw_dev->pixelformat_count );
-   assert( !stw_dev->pixelformat_extended_count );
+   unsigned ms, db, ds, acc;
+   unsigned bind_flags = PIPE_BIND_RENDER_TARGET;
 
-   for(i = 0; i < Elements(stw_pf_multisample); ++i) {
-      unsigned samples = stw_pf_multisample[i];
-      
-      /* FIXME: re-enabled MSAA when we can query it */
-      if(samples)
-         continue;
+   if (!extended) {
+      bind_flags |= PIPE_BIND_DISPLAY_TARGET;
+   }
 
-      for(j = 0; j < Elements(stw_pf_color); ++j) {
-         const struct stw_pf_color_info *color = &stw_pf_color[j];
-         
-         if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D,
-                                         0, PIPE_BIND_RENDER_TARGET |
-                                         PIPE_BIND_DISPLAY_TARGET))
-            continue;
-         
-         for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) {
-            unsigned doublebuffer = stw_pf_doublebuffer[k];
-            
-            for(l = 0; l < Elements(stw_pf_depth_stencil); ++l) {
-               const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l];
-               
-               if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, 
-                                               0, PIPE_BIND_DEPTH_STENCIL))
-                  continue;
-
-               stw_pixelformat_add( stw_dev, FALSE, color, depth,  0, doublebuffer, samples );
-               stw_pixelformat_add( stw_dev, FALSE, color, depth, 16, doublebuffer, samples );
-            }
-         }
-      }
+   if (!screen->is_format_supported(screen, color->format,
+                                    PIPE_TEXTURE_2D, 0, bind_flags)) {
+      return;
    }
-   
-   /*
-    * Same as above, but for the extended color formats (e.g, float) and without PIPE_BIND_DISPLAY_TARGET bit.
-    */
-   for(i = 0; i < Elements(stw_pf_multisample); ++i) {
-      unsigned samples = stw_pf_multisample[i];
+
+   for (ms = 0; ms < Elements(stw_pf_multisample); ms++) {
+      unsigned samples = stw_pf_multisample[ms];
 
       /* FIXME: re-enabled MSAA when we can query it */
-      if(samples)
+      if (samples)
          continue;
 
-      for(j = 0; j < Elements(stw_pf_color_extended); ++j) {
-         const struct stw_pf_color_info *color = &stw_pf_color_extended[j];
-
-         if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D,
-                                         0, PIPE_BIND_RENDER_TARGET))
-            continue;
+      for (db = 0; db < Elements(stw_pf_doublebuffer); db++) {
+         unsigned doublebuffer = stw_pf_doublebuffer[db];
 
-         for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) {
-            unsigned doublebuffer = stw_pf_doublebuffer[k];
+         for (ds = 0; ds < Elements(stw_pf_depth_stencil); ds++) {
+            const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[ds];
 
-            for(l = 0; l < Elements(stw_pf_depth_stencil); ++l) {
-               const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l];
-
-               if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D,
-                                               0, PIPE_BIND_DEPTH_STENCIL))
-                  continue;
+            if (!screen->is_format_supported(screen, depth->format,
+                                             PIPE_TEXTURE_2D, 0,
+                                             PIPE_BIND_DEPTH_STENCIL)) {
+               continue;
+            }
 
-               stw_pixelformat_add( stw_dev, TRUE, color, depth,  0, doublebuffer, samples );
-               stw_pixelformat_add( stw_dev, TRUE, color, depth, 16, doublebuffer, samples );
+            for (acc = 0; acc < 2; acc++) {
+               stw_pixelformat_add(stw_dev, extended, color, depth,
+                                   acc * 16, doublebuffer, samples);
             }
          }
       }
    }
+}
+
+
+void
+stw_pixelformat_init( void )
+{
+   unsigned i;
+
+   assert( !stw_dev->pixelformat_count );
+   assert( !stw_dev->pixelformat_extended_count );
+
+   /* normal, displayable formats */
+   for (i = 0; i < Elements(stw_pf_color); i++) {
+      add_color_format_variants(&stw_pf_color[i], FALSE);
+   }
+
+   /* extended, pbuffer-only formats */
+   for (i = 0; i < Elements(stw_pf_color_extended); i++) {
+      add_color_format_variants(&stw_pf_color_extended[i], TRUE);
+   }
 
    assert( stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count );
    assert( stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS );