wgl: Note down the gallium pixel formats, instead of re-guessing them.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 10 Apr 2009 17:43:51 +0000 (18:43 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 10 Apr 2009 18:50:35 +0000 (19:50 +0100)
progs/wgl/wglinfo.c
src/gallium/state_trackers/wgl/shared/stw_context.c
src/gallium/state_trackers/wgl/shared/stw_context.h
src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
src/gallium/state_trackers/wgl/shared/stw_framebuffer.h
src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
src/gallium/state_trackers/wgl/shared/stw_pixelformat.h

index 5cf0e8bb25b7d8c1e079bc0336b2557b45de191f..881d35b297d4b7fa98cf41f7d2cc1204d102e7a4 100644 (file)
@@ -586,8 +586,8 @@ print_visual_info(HDC hdc, InfoMode mode)
       if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
         continue;
 
-      if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
-         continue;
+      //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
+      //   continue;
 
       ++numWglVisuals;
    }
@@ -603,8 +603,8 @@ print_visual_info(HDC hdc, InfoMode mode)
       if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
         continue;
 
-      if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
-         continue;
+      //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
+      //   continue;
 
       if (mode == Verbose)
         print_visual_attribs_verbose(i, &pfd);
index e6bb8e184721477d32ddc8d8c798a576dfb823ea..1e3bf103176f4605ce27cfeac2f46a71102ca5ff 100644 (file)
@@ -153,6 +153,7 @@ stw_create_layer_context(
       goto fail;
 
    ctx->st->ctx->DriverCtx = ctx;
+   ctx->pfi = pf;
 
    pipe_mutex_lock( stw_dev->mutex );
    hglrc = handle_table_add(stw_dev->ctx_table, ctx);
@@ -330,7 +331,7 @@ stw_make_current(
    if (fb == NULL && ctx != NULL && hdc != NULL) {
       GLvisual *visual = &ctx->st->ctx->Visual;
 
-      fb = stw_framebuffer_create( hdc, visual, width, height );
+      fb = stw_framebuffer_create( hdc, visual, ctx->pfi, width, height );
       if (fb == NULL)
          return FALSE;
    }
index b28961527244de9994f17f7c7b7d3280452529bc..bc3b1dc880dcd45fc8bc848562f570e95dea0474 100644 (file)
 #include <windows.h>
 
 struct st_context;
+struct stw_pixelformat_info;
 
 struct stw_context
 {
    struct st_context *st;
    HDC hdc;
    DWORD color_bits;
+   const struct stw_pixelformat_info *pfi;
 };
 
 #endif /* STW_CONTEXT_H */
index 55dc9d678c13665fbfb377877e82cb0c477c65e7..e70e20390e1742521a5fcbdad43be4ba2959f426 100644 (file)
@@ -93,21 +93,6 @@ stw_call_window_proc(
    return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam);
 }
 
-static INLINE boolean
-stw_is_supported_color(enum pipe_format format)
-{
-   struct pipe_screen *screen = stw_dev->screen;
-   return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 
-                                      PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
-}
-
-static INLINE boolean
-stw_is_supported_depth_stencil(enum pipe_format format)
-{
-   struct pipe_screen *screen = stw_dev->screen;
-   return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 
-                                      PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-}
 
 /* Create a new framebuffer object which will correspond to the given HDC.
  */
@@ -115,83 +100,26 @@ struct stw_framebuffer *
 stw_framebuffer_create(
    HDC hdc,
    GLvisual *visual,
+   const struct stw_pixelformat_info *pfi,
    GLuint width,
    GLuint height )
 {
-   struct stw_framebuffer *fb;
    enum pipe_format colorFormat, depthFormat, stencilFormat;
+   struct stw_framebuffer *fb;
 
-   /* Determine PIPE_FORMATs for buffers.
-    */
-
-   if(visual->alphaBits <= 0 && visual->redBits <= 5 && visual->blueBits <= 6 && visual->greenBits <= 5 && 
-      stw_is_supported_color(PIPE_FORMAT_R5G6B5_UNORM)) {
-      colorFormat = PIPE_FORMAT_R5G6B5_UNORM;
-   }
-   else if(visual->alphaBits <= 0 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && 
-      stw_is_supported_color(PIPE_FORMAT_X8R8G8B8_UNORM)) {
-      colorFormat = PIPE_FORMAT_X8R8G8B8_UNORM;
-   }
-   else if(visual->alphaBits <= 1 && visual->redBits <= 5 && visual->blueBits <= 5 && visual->greenBits <= 5 &&
-      stw_is_supported_color(PIPE_FORMAT_A1R5G5B5_UNORM)) {
-      colorFormat = PIPE_FORMAT_A1R5G5B5_UNORM;
-   }
-   else if(visual->alphaBits <= 4 && visual->redBits <= 4 && visual->blueBits <= 4 && visual->greenBits <= 4 && 
-      stw_is_supported_color(PIPE_FORMAT_A4R4G4B4_UNORM)) {
-      colorFormat = PIPE_FORMAT_A4R4G4B4_UNORM;
-   }
-   else if(visual->alphaBits <= 8 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && 
-      stw_is_supported_color(PIPE_FORMAT_A8R8G8B8_UNORM)) {
-      colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;
-   }
-   else {
-      assert(0);
-      return NULL;
-   }
+   colorFormat = pfi->color_format;
+   
+   assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
 
-   if (visual->depthBits == 0)
-      depthFormat = PIPE_FORMAT_NONE;
-   else if (visual->depthBits <= 16 &&
-            stw_is_supported_depth_stencil(PIPE_FORMAT_Z16_UNORM))
-      depthFormat = PIPE_FORMAT_Z16_UNORM;
-   else if (visual->depthBits <= 24 && visual->stencilBits != 8 &&
-            stw_is_supported_depth_stencil(PIPE_FORMAT_X8Z24_UNORM)) {
-      depthFormat = PIPE_FORMAT_X8Z24_UNORM;
-   }
-   else if (visual->depthBits <= 24 && visual->stencilBits != 8 && 
-            stw_is_supported_depth_stencil(PIPE_FORMAT_Z24X8_UNORM)) {
-      depthFormat = PIPE_FORMAT_Z24X8_UNORM;
-   }
-   else if (visual->depthBits <= 24 && visual->stencilBits == 8 && 
-            stw_is_supported_depth_stencil(PIPE_FORMAT_S8Z24_UNORM)) {
-      depthFormat = PIPE_FORMAT_S8Z24_UNORM;
-   }
-   else if (visual->depthBits <= 24 && visual->stencilBits == 8 && 
-            stw_is_supported_depth_stencil(PIPE_FORMAT_Z24S8_UNORM)) {
-      depthFormat = PIPE_FORMAT_Z24S8_UNORM;
-   }
-   else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_UNORM)) {
-      depthFormat = PIPE_FORMAT_Z32_UNORM;
-   }
-   else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_FLOAT)) {
-      depthFormat = PIPE_FORMAT_Z32_FLOAT;
-   }
-   else {
-      assert(0);
+   if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
+      depthFormat = pfi->depth_stencil_format;
+   else
       depthFormat = PIPE_FORMAT_NONE;
-   }
 
-   if (depthFormat == PIPE_FORMAT_S8Z24_UNORM || 
-       depthFormat == PIPE_FORMAT_Z24S8_UNORM) {
-      stencilFormat = depthFormat;
-   }
-   else if (visual->stencilBits == 8 && 
-            stw_is_supported_depth_stencil(PIPE_FORMAT_S8_UNORM)) {
-      stencilFormat = PIPE_FORMAT_S8_UNORM;
-   }
-   else {
+   if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
+      stencilFormat = pfi->depth_stencil_format;
+   else
       stencilFormat = PIPE_FORMAT_NONE;
-   }
 
    fb = CALLOC_STRUCT( stw_framebuffer );
    if (fb == NULL)
index ea3bf6f8fc7b6140c000d8ee845bdfc559e9e607..607b7f0ef2a3e9039dfdc2e74d1dce1ab5652b6c 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "main/mtypes.h"
 
+struct stw_pixelformat_info;
+
 /**
  * Windows framebuffer, derived from gl_framebuffer.
  */
@@ -45,6 +47,7 @@ struct stw_framebuffer *
 stw_framebuffer_create(
    HDC hdc,
    GLvisual *visual,
+   const struct stw_pixelformat_info *pfi,
    GLuint width,
    GLuint height );
 
index 897478e0f5b39f543653cea9a143c2bb1d8caef4..67a92d3d8ecfe6be380c6a6321694630e2436057 100644 (file)
@@ -128,11 +128,23 @@ stw_pixelformat_add(
    assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS);
    if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS)
       return;
+
+   assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
+   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red );
+   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green );
+   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue );
+   assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha );
+   assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
+   assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth );
+   assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil );
    
    pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count];
    
    memset(pfi, 0, sizeof *pfi);
    
+   pfi->color_format = color->format;
+   pfi->depth_stencil_format = depth->format;
+   
    pfi->pfd.nSize = sizeof pfi->pfd;
    pfi->pfd.nVersion = 1;
 
index acfb230d9d0636a801cccce3fae6f6ec2ec960c6..34522ebef38078876035bd7f2e981a3b2226e41f 100644 (file)
 #include <windows.h>
 
 #include "pipe/p_compiler.h"
+#include "pipe/p_format.h"
 
 struct stw_pixelformat_info
 {
+   enum pipe_format color_format;
+   enum pipe_format depth_stencil_format;
+   
    PIXELFORMATDESCRIPTOR pfd;
    
    unsigned numSampleBuffers;