소스 검색

Split up color-bits into red-bits + green-bits + blue-bits

rdb 11 년 전
부모
커밋
bc24576b02

+ 1 - 2
panda/src/androiddisplay/androidGraphicsStateGuardian.cxx

@@ -117,10 +117,9 @@ get_properties(FrameBufferProperties &properties,
 
   properties.set_back_buffers(1);
   properties.set_rgb_color(1);
-  properties.set_color_bits(red_size+green_size+blue_size);
+  properties.set_rgba_bits(red_size, green_size, blue_size, alpha_size);
   properties.set_stencil_bits(stencil_size);
   properties.set_depth_bits(depth_size);
-  properties.set_alpha_bits(alpha_size);
   properties.set_multisamples(samples);
 
   // Set both hardware and software bits, indicating not-yet-known.

+ 7 - 5
panda/src/cocoadisplay/cocoaGraphicsStateGuardian.mm

@@ -71,13 +71,14 @@ get_properties(FrameBufferProperties &properties, NSOpenGLPixelFormat* pixel_for
   properties.clear();
 
   // Now update our framebuffer_mode and bit depth appropriately.
-  GLint double_buffer, stereo, aux_buffers, color_size, alpha_size,
-    depth_size, stencil_size, accum_size, sample_buffers, samples,
-    renderer_id, accelerated, window, pbuffer;
+  GLint double_buffer, stereo, aux_buffers, color_float, color_size,
+    alpha_size, depth_size, stencil_size, accum_size, sample_buffers,
+    samples, renderer_id, accelerated, window, pbuffer;
 
   [pixel_format getValues:&double_buffer  forAttribute:NSOpenGLPFADoubleBuffer  forVirtualScreen:screen];
   [pixel_format getValues:&stereo         forAttribute:NSOpenGLPFAStereo        forVirtualScreen:screen];
   [pixel_format getValues:&aux_buffers    forAttribute:NSOpenGLPFAAuxBuffers    forVirtualScreen:screen];
+  [pixel_format getValues:&color_float    forAttribute:NSOpenGLPFAColorFloat    forVirtualScreen:screen];
   [pixel_format getValues:&color_size     forAttribute:NSOpenGLPFAColorSize     forVirtualScreen:screen];
   [pixel_format getValues:&alpha_size     forAttribute:NSOpenGLPFAAlphaSize     forVirtualScreen:screen];
   [pixel_format getValues:&depth_size     forAttribute:NSOpenGLPFADepthSize     forVirtualScreen:screen];
@@ -93,6 +94,7 @@ get_properties(FrameBufferProperties &properties, NSOpenGLPixelFormat* pixel_for
   properties.set_back_buffers(double_buffer);
   properties.set_stereo(stereo);
   properties.set_rgb_color(1);
+  properties.set_float_color(color_float);
   properties.set_color_bits(color_size);
   properties.set_stencil_bits(stencil_size);
   properties.set_depth_bits(depth_size);
@@ -145,7 +147,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
 
   // Don't let it fall back to a different renderer.
   attribs.push_back(NSOpenGLPFANoRecovery);
-  
+
   // Consider pixel formats with properties equal
   // to or better than we requested.
   attribs.push_back(NSOpenGLPFAMinimumPolicy);
@@ -192,7 +194,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
     attribs.push_back(NSOpenGLPFARendererID);
     attribs.push_back(kCGLRendererGenericFloatID);
   }
-  
+
   if (properties.get_force_hardware()) {
     attribs.push_back(NSOpenGLPFAAccelerated);
   }

+ 12 - 1
panda/src/display/config_display.cxx

@@ -419,7 +419,18 @@ ConfigVariableInt depth_bits
  PRC_DESC("The minimum number of depth buffer bits requested."));
 ConfigVariableInt color_bits
 ("color-bits", 0,
- PRC_DESC("The minimum number of color buffer bits requested."));
+ PRC_DESC("The minimum number of total color buffer bits requested.  This "
+          "value is like red-bits + blue-bits + green-bits except Panda "
+          "won't care how the bits are divided up."));
+ConfigVariableInt red_bits
+("red-bits", 0,
+ PRC_DESC("The minimum number of red color buffer bits requested."));
+ConfigVariableInt green_bits
+("green-bits", 0,
+ PRC_DESC("The minimum number of green color buffer bits requested."));
+ConfigVariableInt blue_bits
+("blue-bits", 0,
+ PRC_DESC("The minimum number of blue color buffer bits requested."));
 ConfigVariableInt alpha_bits
 ("alpha-bits", 0,
  PRC_DESC("The minimum number of alpha buffer bits requested."));

+ 3 - 0
panda/src/display/config_display.h

@@ -96,6 +96,9 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableBool framebuffer_srgb;
 extern EXPCL_PANDA_DISPLAY ConfigVariableBool framebuffer_float;
 extern EXPCL_PANDA_DISPLAY ConfigVariableInt depth_bits;
 extern EXPCL_PANDA_DISPLAY ConfigVariableInt color_bits;
+extern EXPCL_PANDA_DISPLAY ConfigVariableInt red_bits;
+extern EXPCL_PANDA_DISPLAY ConfigVariableInt green_bits;
+extern EXPCL_PANDA_DISPLAY ConfigVariableInt blue_bits;
 extern EXPCL_PANDA_DISPLAY ConfigVariableInt alpha_bits;
 extern EXPCL_PANDA_DISPLAY ConfigVariableInt stencil_bits;
 extern EXPCL_PANDA_DISPLAY ConfigVariableInt accum_bits;

+ 123 - 38
panda/src/display/frameBufferProperties.I

@@ -65,7 +65,7 @@ is_stereo() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::operator <<
 //       Access: Public
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE ostream &
 operator << (ostream &out, const FrameBufferProperties &properties) {
@@ -76,7 +76,7 @@ operator << (ostream &out, const FrameBufferProperties &properties) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_depth_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_depth_bits() const {
@@ -86,17 +86,50 @@ get_depth_bits() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_color_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_color_bits() const {
-  return _property[FBP_color_bits];
+  return max(_property[FBP_color_bits],
+             _property[FBP_red_bits] +
+             _property[FBP_green_bits] +
+             _property[FBP_blue_bits]);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::get_red_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE int FrameBufferProperties::
+get_red_bits() const {
+  return _property[FBP_red_bits];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::get_green_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE int FrameBufferProperties::
+get_green_bits() const {
+  return _property[FBP_green_bits];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::get_blue_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE int FrameBufferProperties::
+get_blue_bits() const {
+  return _property[FBP_blue_bits];
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_alpha_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_alpha_bits() const {
@@ -106,7 +139,7 @@ get_alpha_bits() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_stencil_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_stencil_bits() const {
@@ -116,7 +149,7 @@ get_stencil_bits() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_accum_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_accum_bits() const {
@@ -126,7 +159,7 @@ get_accum_bits() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_aux_rgba
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_aux_rgba() const {
@@ -136,7 +169,7 @@ get_aux_rgba() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_aux_hrgba
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_aux_hrgba() const {
@@ -146,7 +179,7 @@ get_aux_hrgba() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_aux_float
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_aux_float() const {
@@ -156,7 +189,7 @@ get_aux_float() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_multisamples
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_multisamples() const {
@@ -177,7 +210,7 @@ get_coverage_samples() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_back_buffers
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int FrameBufferProperties::
 get_back_buffers() const {
@@ -187,7 +220,7 @@ get_back_buffers() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_indexed_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_indexed_color() const {
@@ -197,7 +230,7 @@ get_indexed_color() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_rgb_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_rgb_color() const {
@@ -207,7 +240,7 @@ get_rgb_color() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_stereo
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_stereo() const {
@@ -217,7 +250,7 @@ get_stereo() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_force_hardware
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_force_hardware() const {
@@ -227,7 +260,7 @@ get_force_hardware() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_force_software
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_force_software() const {
@@ -237,7 +270,7 @@ get_force_software() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_srgb_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_srgb_color() const {
@@ -247,7 +280,7 @@ get_srgb_color() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_float_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_float_color() const {
@@ -257,7 +290,7 @@ get_float_color() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::get_float_depth
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool FrameBufferProperties::
 get_float_depth() const {
@@ -267,7 +300,7 @@ get_float_depth() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_depth_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_depth_bits(int n) {
@@ -278,7 +311,7 @@ set_depth_bits(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_color_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_color_bits(int n) {
@@ -286,10 +319,62 @@ set_color_bits(int n) {
   _specified[FBP_color_bits] = true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::set_rgba_bits
+//       Access: Published
+//  Description: Sets all color bit requirements separately.
+////////////////////////////////////////////////////////////////////
+INLINE void FrameBufferProperties::
+set_rgba_bits(int r, int g, int b, int a) {
+  _property[FBP_red_bits] = r;
+  _specified[FBP_red_bits] = true;
+  _property[FBP_green_bits] = g;
+  _specified[FBP_green_bits] = true;
+  _property[FBP_blue_bits] = b;
+  _specified[FBP_blue_bits] = true;
+  _property[FBP_alpha_bits] = a;
+  _specified[FBP_alpha_bits] = true;
+  _property[FBP_color_bits] = r + g + b;
+  _specified[FBP_color_bits] = true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::set_red_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void FrameBufferProperties::
+set_red_bits(int n) {
+  _property[FBP_red_bits] = n;
+  _specified[FBP_red_bits] = true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::set_green_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void FrameBufferProperties::
+set_green_bits(int n) {
+  _property[FBP_green_bits] = n;
+  _specified[FBP_green_bits] = true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::set_blue_bits
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE void FrameBufferProperties::
+set_blue_bits(int n) {
+  _property[FBP_blue_bits] = n;
+  _specified[FBP_blue_bits] = true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_alpha_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_alpha_bits(int n) {
@@ -300,7 +385,7 @@ set_alpha_bits(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_stencil_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_stencil_bits(int n) {
@@ -311,7 +396,7 @@ set_stencil_bits(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_accum_bits
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_accum_bits(int n) {
@@ -322,7 +407,7 @@ set_accum_bits(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_aux_rgba
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_aux_rgba(int n) {
@@ -334,7 +419,7 @@ set_aux_rgba(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_aux_hrgba
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_aux_hrgba(int n) {
@@ -346,7 +431,7 @@ set_aux_hrgba(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_aux_float
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_aux_float(int n) {
@@ -358,7 +443,7 @@ set_aux_float(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_multisamples
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_multisamples(int n) {
@@ -381,7 +466,7 @@ set_coverage_samples(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_back_buffers
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_back_buffers(int n) {
@@ -392,7 +477,7 @@ set_back_buffers(int n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_indexed_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_indexed_color(bool n) {
@@ -407,7 +492,7 @@ set_indexed_color(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_rgb_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_rgb_color(bool n) {
@@ -422,7 +507,7 @@ set_rgb_color(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_stereo
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_stereo(bool n) {
@@ -437,7 +522,7 @@ set_stereo(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_force_hardware
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_force_hardware(bool n) {
@@ -452,7 +537,7 @@ set_force_hardware(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_force_software
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_force_software(bool n) {
@@ -467,7 +552,7 @@ set_force_software(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_srgb_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_srgb_color(bool n) {
@@ -482,7 +567,7 @@ set_srgb_color(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_float_color
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_float_color(bool n) {
@@ -497,7 +582,7 @@ set_float_color(bool n) {
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::set_float_depth
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE void FrameBufferProperties::
 set_float_depth(bool n) {

+ 149 - 1
panda/src/display/frameBufferProperties.cxx

@@ -16,6 +16,7 @@
 #include "string_utils.h"
 #include "renderBuffer.h"
 #include "config_display.h"
+#include "texture.h"
 
 ////////////////////////////////////////////////////////////////////
 //     Function: FrameBufferProperties::Constructor
@@ -100,6 +101,9 @@ get_default() {
     display_cat.error() << "  framebuffer-stereo #t\n";
     display_cat.error() << "  depth-bits N\n";
     display_cat.error() << "  color-bits N\n";
+    display_cat.error() << "  red-bits N\n";
+    display_cat.error() << "  green-bits N\n";
+    display_cat.error() << "  blue-bits N\n";
     display_cat.error() << "  alpha-bits N\n";
     display_cat.error() << "  stencil-bits N\n";
     display_cat.error() << "  multisamples N\n";
@@ -143,6 +147,15 @@ get_default() {
   if (color_bits > 0) {
     default_props.set_color_bits(color_bits);
   }
+  if (red_bits > 0) {
+    default_props.set_red_bits(red_bits);
+  }
+  if (green_bits > 0) {
+    default_props.set_green_bits(green_bits);
+  }
+  if (blue_bits > 0) {
+    default_props.set_blue_bits(blue_bits);
+  }
   if (alpha_bits > 0) {
     default_props.set_alpha_bits(alpha_bits);
   }
@@ -166,7 +179,7 @@ get_default() {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: FrameBufferProperties::operator == 
+//     Function: FrameBufferProperties::operator ==
 //       Access: Published
 //  Description:
 ////////////////////////////////////////////////////////////////////
@@ -251,6 +264,15 @@ output(ostream &out) const {
   if (_property[FBP_color_bits] > 0) {
     out << "color_bits=" << _property[FBP_color_bits] << " ";
   }
+  if (_property[FBP_red_bits] > 0) {
+    out << "red_bits=" << _property[FBP_red_bits] << " ";
+  }
+  if (_property[FBP_green_bits] > 0) {
+    out << "green_bits=" << _property[FBP_green_bits] << " ";
+  }
+  if (_property[FBP_blue_bits] > 0) {
+    out << "blue_bits=" << _property[FBP_blue_bits] << " ";
+  }
   if (_property[FBP_alpha_bits] > 0) {
     out << "alpha_bits=" << _property[FBP_alpha_bits] << " ";
   }
@@ -384,6 +406,15 @@ is_basic() const {
   if (_property[FBP_color_bits] > 1) {
     return false;
   }
+  if (_property[FBP_red_bits] > 1) {
+    return false;
+  }
+  if (_property[FBP_green_bits] > 1) {
+    return false;
+  }
+  if (_property[FBP_blue_bits] > 1) {
+    return false;
+  }
   if (_property[FBP_alpha_bits] > 1) {
     return false;
   }
@@ -662,3 +693,120 @@ verify_hardware_software(const FrameBufferProperties &props, const string &rende
 
   return true;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::setup_color_texture
+//       Access: Public
+//  Description: Sets the texture up for render-to-texture matching
+//               these framebuffer properties.
+//
+//               Returns true if there was a format that had enough
+//               bits, false otherwise.  Of course, this is no
+//               guarantee that a particular graphics back-end
+//               supports rendering to textures of that format.
+////////////////////////////////////////////////////////////////////
+bool FrameBufferProperties::
+setup_color_texture(Texture *tex) const {
+  // Note by rdb: I'm not entirely happy about this system.  I'd
+  // eventually like to move to a system in which framebuffer color
+  // formats and texture formats are unified (like in Direct3D and
+  // OpenGL) and where a table such as the below one would be
+  // generated dynamically by the GSG to reflect the formats that
+  // are supported for render-to-texture.
+
+  static const int num_formats = 12;
+  static const struct {
+    unsigned char color_bits, red_bits, green_bits, blue_bits, alpha_bits;
+    bool has_float;
+    Texture::Format format;
+  } formats[num_formats] = {
+  //{  1,  1,  0,  0,  0, F_red},
+    {  1,  1,  1,  1,  0, false, Texture::F_rgb },
+    {  1,  1,  1,  1,  1, false, Texture::F_rgba },
+    { 24,  8,  8,  8,  0, false, Texture::F_rgb8 },
+    { 24,  8,  8,  8,  8, false, Texture::F_rgba8 },
+    { 16, 16,  0,  0,  0,  true, Texture::F_r16 },
+    { 32, 16, 16,  0,  0,  true, Texture::F_rg16 },
+    { 48, 16, 16, 16,  0,  true, Texture::F_rgb16 },
+    { 48, 16, 16, 16, 16,  true, Texture::F_rgba16 },
+    { 32, 32,  0,  0,  0,  true, Texture::F_r32 },
+    { 64, 32, 32,  0,  0,  true, Texture::F_rg32 },
+    { 96, 32, 32, 32,  0,  true, Texture::F_rgb32 },
+    { 96, 32, 32, 32, 32,  true, Texture::F_rgba32 },
+  };
+
+  if (get_srgb_color()) {
+    // These are the only sRGB formats.  Deal with it.
+    if (get_alpha_bits() == 0) {
+      tex->set_format(Texture::F_srgb);
+    } else {
+      tex->set_format(Texture::F_srgb_alpha);
+    }
+
+    return (get_color_bits() <= 24 &&
+            get_red_bits() <= 8 &&
+            get_green_bits() <= 8 &&
+            get_blue_bits() <= 8 &&
+            get_alpha_bits() <= 8);
+
+  } else {
+    if (get_float_color()) {
+      tex->set_component_type(Texture::T_float);
+    }
+
+    for (int i = 0; i < num_formats; ++i) {
+      if (get_color_bits() <= (int)formats[i].color_bits &&
+          get_red_bits() <= (int)formats[i].red_bits &&
+          get_blue_bits() <= (int)formats[i].blue_bits &&
+          get_alpha_bits() <= (int)formats[i].alpha_bits &&
+          get_float_color() <= formats[i].has_float) {
+
+        tex->set_format(formats[i].format);
+        return true;
+      }
+    }
+
+    // Can't get requested bits.  Choose a generic format and return.
+    tex->set_format((get_alpha_bits() == 0) ? Texture::F_rgb : Texture::F_rgba);
+    return false;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FrameBufferProperties::setup_depth_texture
+//       Access: Public
+//  Description: Sets the texture up for render-to-texture matching
+//               these framebuffer properties.
+//
+//               Returns true if there was a format that had enough
+//               bits, false otherwise.  Of course, this is no
+//               guarantee that a particular graphics back-end
+//               supports rendering to textures of that format.
+////////////////////////////////////////////////////////////////////
+bool FrameBufferProperties::
+setup_depth_texture(Texture *tex) const {
+  if (get_float_depth()) {
+    tex->set_component_type(Texture::T_float);
+    tex->set_format(Texture::F_depth_component32);
+    return (get_depth_bits() <= 32);
+
+  } else if (get_depth_bits() <= 1) {
+    tex->set_format(Texture::F_depth_component);
+    return true;
+
+  } else if (get_depth_bits() <= 16) {
+    tex->set_format(Texture::F_depth_component16);
+    return true;
+
+  } else if (get_depth_bits() <= 24) {
+    tex->set_format(Texture::F_depth_component24);
+    return true;
+
+  } else if (get_depth_bits() <= 32) {
+    tex->set_format(Texture::F_depth_component32);
+    return true;
+  }
+
+  tex->set_format(Texture::F_depth_component);
+  return false;
+}

+ 15 - 0
panda/src/display/frameBufferProperties.h

@@ -18,6 +18,8 @@
 #include "pandabase.h"
 #include "pnotify.h"
 
+class Texture;
+
 ////////////////////////////////////////////////////////////////////
 //       Class : FrameBufferProperties
 // Description : A container for the various kinds of properties we
@@ -31,6 +33,9 @@ private:
     // This section has to start with "depth" and end with "accum"
     FBP_depth_bits,
     FBP_color_bits,
+    FBP_red_bits,
+    FBP_green_bits,
+    FBP_blue_bits,
     FBP_alpha_bits,
     FBP_stencil_bits,
     FBP_accum_bits,
@@ -72,6 +77,9 @@ PUBLISHED:
   // Individual queries.
   INLINE int get_depth_bits() const;
   INLINE int get_color_bits() const;
+  INLINE int get_red_bits() const;
+  INLINE int get_green_bits() const;
+  INLINE int get_blue_bits() const;
   INLINE int get_alpha_bits() const;
   INLINE int get_stencil_bits() const;
   INLINE int get_accum_bits() const;
@@ -93,6 +101,10 @@ PUBLISHED:
   // Individual assigners.
   INLINE void set_depth_bits(int n);
   INLINE void set_color_bits(int n);
+  INLINE void set_rgba_bits(int r, int g, int b, int a);
+  INLINE void set_red_bits(int n);
+  INLINE void set_green_bits(int n);
+  INLINE void set_blue_bits(int n);
   INLINE void set_alpha_bits(int n);
   INLINE void set_stencil_bits(int n);
   INLINE void set_accum_bits(int n);
@@ -136,6 +148,9 @@ PUBLISHED:
   int get_aux_mask() const;
   int get_buffer_mask() const;
   bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const;
+
+  bool setup_color_texture(Texture *tex) const;
+  bool setup_depth_texture(Texture *tex) const;
 };
 
 INLINE ostream &operator << (ostream &out, const FrameBufferProperties &properties);

+ 56 - 53
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -303,7 +303,7 @@ upload_texture(DXTextureContext8 *dtc, bool force) {
   dtc->delete_texture();
   dtc->update_data_size_bytes(0);
   dtc->mark_unloaded();
-  
+
   if (_effective_incomplete_render && !force) {
     bool has_image = _supports_compressed_texture ? tex->has_ram_image() : tex->has_uncompressed_ram_image();
     if (!has_image && tex->might_have_ram_image() &&
@@ -321,7 +321,7 @@ upload_texture(DXTextureContext8 *dtc, bool force) {
       }
     }
   }
-  
+
   return dtc->create_texture(*_screen);
 }
 
@@ -634,7 +634,7 @@ clear(DrawableRegion *clearable) {
         }
       }
     }
-    
+
     if (FAILED(hr)) {
       dxgsg8_cat.error()
         << "clear_buffer failed:  Clear returned " << D3DERRORSTRING(hr);
@@ -1025,7 +1025,7 @@ draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) {
         (D3DPT_TRIANGLELIST,
          min_vertex, max_vertex,
          reader->get_num_primitives(),
-         index_pointer, index_type, vertex_pointer, 
+         index_pointer, index_type, vertex_pointer,
          _data_reader->get_format()->get_array(0)->get_stride());
     }
   } else {
@@ -2465,7 +2465,7 @@ set_state_and_transform(const RenderState *target,
     do_issue_depth_write();
     _state_mask.set_bit(depth_write_slot);
   }
-     
+
   int fog_slot = FogAttrib::get_class_slot();
   if (_target_rs->get_attrib(fog_slot) != _state_rs->get_attrib(fog_slot) ||
       !_state_mask.get_bit(fog_slot)) {
@@ -2647,22 +2647,22 @@ bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) {
     const LMatrix4 &light_mat = transform->get_mat();
     LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
     LVector3f dir = LCAST(float, light_obj->get_direction() * rel_mat);
-    
+
     D3DCOLORVALUE black;
     black.r = black.g = black.b = black.a = 0.0f;
-    
+
     ZeroMemory(&fdata, sizeof(D3DLIGHT8));
-    
+
     fdata.Type =  D3DLIGHT_DIRECTIONAL;
     fdata.Ambient  =  black ;
     LColorf color = LCAST(float, light_obj->get_specular_color());
     fdata.Specular = *(D3DCOLORVALUE *)(color.get_data());
-    
+
     fdata.Direction = *(D3DVECTOR *)dir.get_data();
-    
+
     fdata.Range =  __D3DLIGHT_RANGE_MAX;
     fdata.Falloff =  1.0f;
-    
+
     fdata.Attenuation0 = 1.0f;       // constant
     fdata.Attenuation1 = 0.0f;       // linear
     fdata.Attenuation2 = 0.0f;       // quadratic
@@ -2980,12 +2980,12 @@ do_issue_texture() {
       // that there are 3-d texture coordinates, because of the
       // 3-component texture coordinate in get_constant_value().
       {
-        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX, 
+        _d3d_device->SetTextureStageState(si, D3DTSS_TEXCOORDINDEX,
                                           texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
         texcoord_dimensions = 3;
 
         const LTexCoord3 &v = _target_tex_gen->get_constant_value(stage);
-        CPT(TransformState) squash = 
+        CPT(TransformState) squash =
           TransformState::make_pos_hpr_scale(v, LVecBase3::zero(),
                                              LVecBase3::zero());
         tex_mat = tex_mat->compose(squash);
@@ -4003,7 +4003,7 @@ create_swap_chain(DXScreenData *new_context) {
 bool DXGraphicsStateGuardian8::
 release_swap_chain(DXScreenData *new_context) {
   HRESULT hr;
-  wdxdisplay8_cat.debug() 
+  wdxdisplay8_cat.debug()
     << "Releasing swap chain " << new_context->_swap_chain << "\n";
   if (new_context->_swap_chain) {
     hr = new_context->_swap_chain->Release();
@@ -4398,7 +4398,7 @@ get_d3d_device() {
 ////////////////////////////////////////////////////////////////////
 //     Function: dxGraphicsStateGuardian8::do_issue_scissor
 //       Access: Protected
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian8::
 do_issue_scissor() {
@@ -4435,7 +4435,7 @@ set_scissor(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat
     dxgsg8_cat.error()
       << "SetViewport(" << vp.X << ", " << vp.Y << ", " << vp.Width << ", " << vp.Height
       << ") failed" << D3DERRORSTRING(hr);
-    
+
     D3DVIEWPORT8 vp_old;
     _d3d_device->GetViewport(&vp_old);
     dxgsg8_cat.error()
@@ -4476,32 +4476,34 @@ FrameBufferProperties DXGraphicsStateGuardian8::
 calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype) {
   FrameBufferProperties props;
   int index=0;
-  int alpha=0;
-  int color=0;
+  int r=0, g=0, b=0, a=0;
   switch (cformat) {
-  case D3DFMT_R8G8B8:      index=0; color=24; alpha=0; break;
-  case D3DFMT_A8R8G8B8:    index=0; color=24; alpha=8; break;
-  case D3DFMT_X8R8G8B8:    index=0; color=24; alpha=0; break;
-  case D3DFMT_R5G6B5:      index=0; color=16; alpha=0; break;
-  case D3DFMT_X1R5G5B5:    index=0; color=15; alpha=0; break;
-  case D3DFMT_A1R5G5B5:    index=0; color=15; alpha=1; break;
-  case D3DFMT_A4R4G4B4:    index=0; color=12; alpha=4; break;
-  case D3DFMT_R3G3B2:      index=0; color= 8; alpha=0; break;
-  case D3DFMT_A8R3G3B2:    index=0; color= 8; alpha=8; break;
-  case D3DFMT_X4R4G4B4:    index=0; color=12; alpha=0; break;
-  case D3DFMT_A2B10G10R10: index=0; color=30; alpha=2; break;
-  case D3DFMT_A8P8:        index=1; color= 8; alpha=8; break;
-  case D3DFMT_P8:          index=1; color= 8; alpha=0; break;
-  }
-  props.set_color_bits(color);
-  props.set_alpha_bits(alpha);
-  if (index) {
+  case D3DFMT_R8G8B8:      r=8; g=8; b=8; a=0; break;
+  case D3DFMT_A8R8G8B8:    r=8; g=8; b=8; a=8; break;
+  case D3DFMT_X8R8G8B8:    r=8; g=8; b=8; a=0; break;
+  case D3DFMT_R5G6B5:      r=5; g=6; b=5; a=0; break;
+  case D3DFMT_X1R5G5B5:    r=5; g=5; b=5; a=0; break;
+  case D3DFMT_A1R5G5B5:    r=5; g=5; b=5; a=1; break;
+  case D3DFMT_A4R4G4B4:    r=4; g=4; b=4; a=4; break;
+  case D3DFMT_R3G3B2:      r=3; g=3; b=2; a=0; break;
+  case D3DFMT_A8R3G3B2:    r=3; g=3; b=2; a=8; break;
+  case D3DFMT_X4R4G4B4:    r=4; g=4; b=4; a=0; break;
+  case D3DFMT_A2B10G10R10: r=10;g=10;b=10;a=2; break;
+  case D3DFMT_A8P8:        index=8; a=8; break;
+  case D3DFMT_P8:          index=8; a=0; break;
+  default: break;
+  }
+  if (index > 0) {
     props.set_rgb_color(0);
     props.set_indexed_color(1);
-  } else if (color) {
+    props.set_color_bits(index);
+  } else if (r + g + b > 0) {
     props.set_rgb_color(1);
     props.set_indexed_color(0);
+    props.set_rgba_bits(r, g, b, a);
   }
+  props.set_alpha_bits(a);
+
   int depth=0;
   int stencil=0;
   switch (dformat) {
@@ -4511,6 +4513,7 @@ calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype) {
   case D3DFMT_D16:     depth=16; stencil=0; break;
   case D3DFMT_D24X8:   depth=24; stencil=0; break;
   case D3DFMT_D24X4S4: depth=24; stencil=4; break;
+  default: break;
   }
   props.set_depth_bits(depth);
   props.set_stencil_bits(stencil);
@@ -4531,8 +4534,8 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
     // avoid divide by zero and negative exponents
     gamma = 1.0;
   }
-  gamma_correction = 1.0 / (double) gamma;    
-  
+  gamma_correction = 1.0 / (double) gamma;
+
   for (i = 0; i < 256; i++) {
     double r;
     double g;
@@ -4543,11 +4546,11 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
       g = (double) original_green_table [i] / GAMMA_1;
       b = (double) original_blue_table [i] / GAMMA_1;
     }
-    else {    
+    else {
       r = ((double) i / 255.0);
       g = r;
       b = r;
-    }    
+    }
 
     r = pow (r, gamma_correction);
     g = pow (g, gamma_correction);
@@ -4563,14 +4566,14 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
       b = 1.0;
     }
 
-    r = r * GAMMA_1;    
-    g = g * GAMMA_1;    
-    b = b * GAMMA_1;    
+    r = r * GAMMA_1;
+    g = g * GAMMA_1;
+    b = b * GAMMA_1;
 
     red_table [i] = r;
     green_table [i] = g;
     blue_table [i] = b;
-  }    
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -4580,13 +4583,13 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
 ////////////////////////////////////////////////////////////////////
 bool DXGraphicsStateGuardian8::
 get_gamma_table(void) {
-  bool get;  
+  bool get;
 
   get = false;
   if (_gamma_table_initialized == false) {
     HDC hdc = GetDC(NULL);
 
-    if (hdc) {   
+    if (hdc) {
       if (GetDeviceGammaRamp (hdc, (LPVOID) _orignial_gamma_table)) {
         _gamma_table_initialized = true;
         get = true;
@@ -4595,26 +4598,26 @@ get_gamma_table(void) {
       ReleaseDC (NULL, hdc);
     }
   }
-  
+
   return get;
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::static_set_gamma
 //       Access: Public, Static
-//  Description: Static function for setting gamma which is needed 
+//  Description: Static function for setting gamma which is needed
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool DXGraphicsStateGuardian8::
 static_set_gamma(bool restore, PN_stdfloat gamma) {
-  bool set;  
+  bool set;
   HDC hdc = GetDC(NULL);
 
   set = false;
-  if (hdc) {   
+  if (hdc) {
     unsigned short ramp [256 * 3];
 
-    if (restore && _gamma_table_initialized) {    
+    if (restore && _gamma_table_initialized) {
       _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
     }
     else {
@@ -4624,7 +4627,7 @@ static_set_gamma(bool restore, PN_stdfloat gamma) {
     if (SetDeviceGammaRamp (hdc, ramp)) {
       set = true;
     }
-    
+
     ReleaseDC (NULL, hdc);
   }
 
@@ -4643,7 +4646,7 @@ set_gamma(PN_stdfloat gamma) {
 
   set = static_set_gamma(false, gamma);
   if (set) {
-    _gamma = gamma;  
+    _gamma = gamma;
   }
 
   return set;

+ 23 - 20
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -5403,32 +5403,34 @@ calc_fb_properties(DWORD cformat, DWORD dformat,
                    DWORD multisampletype, DWORD multisamplequality) {
   FrameBufferProperties props;
   int index=0;
-  int alpha=0;
-  int color=0;
+  int r=0, g=0, b=0, a=0;
   switch (cformat) {
-  case D3DFMT_R8G8B8:      index=0; color=24; alpha=0; break;
-  case D3DFMT_A8R8G8B8:    index=0; color=24; alpha=8; break;
-  case D3DFMT_X8R8G8B8:    index=0; color=24; alpha=0; break;
-  case D3DFMT_R5G6B5:      index=0; color=16; alpha=0; break;
-  case D3DFMT_X1R5G5B5:    index=0; color=15; alpha=0; break;
-  case D3DFMT_A1R5G5B5:    index=0; color=15; alpha=1; break;
-  case D3DFMT_A4R4G4B4:    index=0; color=12; alpha=4; break;
-  case D3DFMT_R3G3B2:      index=0; color= 8; alpha=0; break;
-  case D3DFMT_A8R3G3B2:    index=0; color= 8; alpha=8; break;
-  case D3DFMT_X4R4G4B4:    index=0; color=12; alpha=0; break;
-  case D3DFMT_A2B10G10R10: index=0; color=30; alpha=2; break;
-  case D3DFMT_A8P8:        index=1; color= 8; alpha=8; break;
-  case D3DFMT_P8:          index=1; color= 8; alpha=0; break;
-  }
-  props.set_color_bits(color);
-  props.set_alpha_bits(alpha);
-  if (index) {
+  case D3DFMT_R8G8B8:      r=8; g=8; b=8; a=0; break;
+  case D3DFMT_A8R8G8B8:    r=8; g=8; b=8; a=8; break;
+  case D3DFMT_X8R8G8B8:    r=8; g=8; b=8; a=0; break;
+  case D3DFMT_R5G6B5:      r=5; g=6; b=5; a=0; break;
+  case D3DFMT_X1R5G5B5:    r=5; g=5; b=5; a=0; break;
+  case D3DFMT_A1R5G5B5:    r=5; g=5; b=5; a=1; break;
+  case D3DFMT_A4R4G4B4:    r=4; g=4; b=4; a=4; break;
+  case D3DFMT_R3G3B2:      r=3; g=3; b=2; a=0; break;
+  case D3DFMT_A8R3G3B2:    r=3; g=3; b=2; a=8; break;
+  case D3DFMT_X4R4G4B4:    r=4; g=4; b=4; a=0; break;
+  case D3DFMT_A2B10G10R10: r=10;g=10;b=10;a=2; break;
+  case D3DFMT_A8P8:        index=8; a=8; break;
+  case D3DFMT_P8:          index=8; a=0; break;
+  default: break;
+  }
+  if (index > 0) {
     props.set_rgb_color(0);
     props.set_indexed_color(1);
-  } else if (color) {
+    props.set_color_bits(index);
+  } else if (r + g + b > 0) {
     props.set_rgb_color(1);
     props.set_indexed_color(0);
+    props.set_rgba_bits(r, g, b, a);
   }
+  props.set_alpha_bits(a);
+
   int depth=0;
   int stencil=0;
   switch (dformat) {
@@ -5438,6 +5440,7 @@ calc_fb_properties(DWORD cformat, DWORD dformat,
   case D3DFMT_D16:     depth=16; stencil=0; break;
   case D3DFMT_D24X8:   depth=24; stencil=0; break;
   case D3DFMT_D24X4S4: depth=24; stencil=4; break;
+  default: break;
   }
   props.set_depth_bits(depth);
   props.set_stencil_bits(stencil);

+ 1 - 2
panda/src/egldisplay/eglGraphicsStateGuardian.cxx

@@ -123,10 +123,9 @@ get_properties(FrameBufferProperties &properties,
 
   properties.set_back_buffers(1);
   properties.set_rgb_color(1);
-  properties.set_color_bits(red_size+green_size+blue_size);
+  properties.set_rgba_bits(red_size, green_size, blue_size, alpha_size);
   properties.set_stencil_bits(stencil_size);
   properties.set_depth_bits(depth_size);
-  properties.set_alpha_bits(alpha_size);
   properties.set_multisamples(samples);
 
   // Set both hardware and software bits, indicating not-yet-known.

+ 2 - 40
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -626,18 +626,7 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
     // Adjust the texture format based on the requested framebuffer settings.
     switch (slot) {
     case RTP_depth:
-      if (_fb_properties.get_float_depth()) {
-        tex->set_format(Texture::F_depth_component32);
-        tex->set_component_type(Texture::T_float);
-      } else if (_fb_properties.get_depth_bits() > 24) {
-        tex->set_format(Texture::F_depth_component32);
-      } else if (_fb_properties.get_depth_bits() > 16) {
-        tex->set_format(Texture::F_depth_component24);
-      } else if (_fb_properties.get_depth_bits() > 8) {
-        tex->set_format(Texture::F_depth_component16);
-      } else {
-        tex->set_format(Texture::F_depth_component);
-      }
+      _fb_properties.setup_depth_texture(tex);
       break;
     case RTP_depth_stencil:
       tex->set_format(Texture::F_depth_stencil);
@@ -663,34 +652,7 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
       tex->set_component_type(Texture::T_float);
       break;
     default:
-      if (_fb_properties.get_srgb_color()) {
-        if (_fb_properties.get_alpha_bits() == 0) {
-          tex->set_format(Texture::F_srgb);
-        } else {
-          tex->set_format(Texture::F_srgb_alpha);
-        }
-      } else {
-        if (_fb_properties.get_float_color()) {
-          tex->set_component_type(Texture::T_float);
-        }
-        if (_fb_properties.get_alpha_bits() == 0) {
-          if (_fb_properties.get_color_bits() > 16 * 3) {
-            tex->set_format(Texture::F_rgb32);
-          } else if (_fb_properties.get_color_bits() > 8 * 3) {
-            tex->set_format(Texture::F_rgb16);
-          } else {
-            tex->set_format(Texture::F_rgb);
-          }
-        } else {
-          if (_fb_properties.get_color_bits() > 16 * 3) {
-            tex->set_format(Texture::F_rgba32);
-          } else if (_fb_properties.get_color_bits() > 8 * 3) {
-            tex->set_format(Texture::F_rgba16);
-          } else {
-            tex->set_format(Texture::F_rgba);
-          }
-        }
-      }
+      _fb_properties.setup_color_texture(tex);
     }
 
 #ifndef OPENGLES

+ 9 - 10
panda/src/glxdisplay/glxGraphicsStateGuardian.cxx

@@ -47,12 +47,12 @@ glxGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
   _supports_fbconfig = false;
   _supports_pbuffer = false;
   _uses_sgix_pbuffer = false;
-  
+
   if (share_with != (glxGraphicsStateGuardian *)NULL) {
     _prepared_objects = share_with->get_prepared_objects();
     _share_context = share_with->_context;
   }
-  
+
   _checked_get_proc_address = false;
   _glXGetProcAddress = NULL;
   _temp_context = (GLXContext)NULL;
@@ -126,10 +126,10 @@ get_properties(FrameBufferProperties &properties, XVisualInfo *visual) {
   } else {
     properties.set_indexed_color(1);
   }
-  properties.set_color_bits(red_size+green_size+blue_size);
+
+  properties.set_rgba_bits(red_size, green_size, blue_size, alpha_size);
   properties.set_stencil_bits(stencil_size);
   properties.set_depth_bits(depth_size);
-  properties.set_alpha_bits(alpha_size);
   properties.set_accum_bits(ared_size+agreen_size+ablue_size+aalpha_size);
 
   // Set both hardware and software bits, indicating not-yet-known.
@@ -144,7 +144,7 @@ get_properties(FrameBufferProperties &properties, XVisualInfo *visual) {
 //               indicated GLXFBConfig
 ////////////////////////////////////////////////////////////////////
 void glxGraphicsStateGuardian::
-get_properties_advanced(FrameBufferProperties &properties, 
+get_properties_advanced(FrameBufferProperties &properties,
                         bool &context_has_pbuffer, bool &context_has_pixmap,
                         bool &slow, GLXFBConfig config) {
   properties.clear();
@@ -212,10 +212,9 @@ get_properties_advanced(FrameBufferProperties &properties,
       properties.set_indexed_color(true);
     }
 
-    properties.set_color_bits(red_size+green_size+blue_size);
+    properties.set_rgba_bits(red_size, green_size, blue_size, alpha_size);
     properties.set_stencil_bits(stencil_size);
     properties.set_depth_bits(depth_size);
-    properties.set_alpha_bits(alpha_size);
     properties.set_accum_bits(ared_size+agreen_size+ablue_size+aalpha_size);
     properties.set_multisamples(samples);
 
@@ -488,7 +487,7 @@ query_gl_version() {
   // two of these together.
   if (glgsg_cat.is_debug()) {
     glgsg_cat.debug()
-      << "GLX_VERSION = " << _glx_version_major << "." << _glx_version_minor 
+      << "GLX_VERSION = " << _glx_version_major << "." << _glx_version_minor
       << "\n";
   }
 }
@@ -583,7 +582,7 @@ query_glx_extensions() {
   _supports_swap_control = has_extension("GLX_SGI_swap_control");
 
   if (_supports_swap_control) {
-    _glXSwapIntervalSGI = 
+    _glXSwapIntervalSGI =
       (PFNGLXSWAPINTERVALSGIPROC)get_extension_func("glXSwapIntervalSGI");
     if (_glXSwapIntervalSGI == NULL) {
       glxdisplay_cat.error()
@@ -689,7 +688,7 @@ query_glx_extensions() {
     }
 
     if (has_extension("GLX_ARB_create_context")) {
-      _glXCreateContextAttribs = 
+      _glXCreateContextAttribs =
         (PFNGLXCREATECONTEXTATTRIBSARBPROC)get_extension_func("glXCreateContextAttribsARB");
     } else {
       _glXCreateContextAttribs = NULL;

+ 28 - 25
panda/src/osxdisplay/osxGraphicsStateGuardian.cxx

@@ -87,7 +87,7 @@ osxGraphicsStateGuardian::
 //  Description: Resets all internal state as if the gsg were newly
 //               created.
 ////////////////////////////////////////////////////////////////////
-void osxGraphicsStateGuardian::reset() 
+void osxGraphicsStateGuardian::reset()
 {
 /*
   if(_aglcontext != (AGLContext)NULL)
@@ -153,7 +153,7 @@ draw_resize_box() {
   // viewport size.
   PN_stdfloat inner_x = 1.0f - (15.0f * 2.0f / _viewport_width);
   PN_stdfloat inner_y = (15.0f * 2.0f / _viewport_height) - 1.0f;
-  
+
   // Draw the quad.  We just use the slow, simple immediate mode calls
   // here.  It's just one quad, after all.
   glBegin(GL_QUADS);
@@ -177,7 +177,7 @@ draw_resize_box() {
 ////////////////////////////////////////////////////////////////////
 //     Function: osxGraphicsStateGuardian::build_gl
 //       Access: Public, Virtual
-//  Description: This function will build up a context for a gsg..  
+//  Description: This function will build up a context for a gsg..
 ////////////////////////////////////////////////////////////////////
 OSStatus osxGraphicsStateGuardian::
 build_gl(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
@@ -187,9 +187,9 @@ build_gl(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
   }
 
   OSStatus err = noErr;
-        
+
   GDHandle display = GetMainDevice();
-        
+
   pvector<GLint> attrib;
   if (!fb_props.get_indexed_color()) {
     attrib.push_back(AGL_RGBA);
@@ -200,11 +200,11 @@ build_gl(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
     attrib.push_back(AGL_PIXEL_SIZE);
     attrib.push_back(color_bits);
     attrib.push_back(AGL_RED_SIZE);
-    attrib.push_back(color_bits / 3);
+    attrib.push_back(fb_props.get_red_bits());
     attrib.push_back(AGL_GREEN_SIZE);
-    attrib.push_back(color_bits / 3);
+    attrib.push_back(fb_props.get_green_bits());
     attrib.push_back(AGL_BLUE_SIZE);
-    attrib.push_back(color_bits / 3);
+    attrib.push_back(fb_props.get_blue_bits());
     attrib.push_back(AGL_ALPHA_SIZE);
     attrib.push_back(alpha_bits);
   }
@@ -265,10 +265,10 @@ build_gl(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
         err = -1;
       }
     } else {
-      aglSetInteger(_aglcontext, AGL_BUFFER_NAME, &_shared_buffer);      
-      err = report_agl_error("aglSetInteger AGL_BUFFER_NAME");          
+      aglSetInteger(_aglcontext, AGL_BUFFER_NAME, &_shared_buffer);
+      err = report_agl_error("aglSetInteger AGL_BUFFER_NAME");
     }
-        
+
   } else {
     osxdisplay_cat.error()
       << "osxGraphicsStateGuardian::build_gl Error Getting Pixel Format\n" ;
@@ -282,10 +282,10 @@ build_gl(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
   if (err == noErr) {
     describe_pixel_format(fb_props);
   }
-        
+
   if (osxdisplay_cat.is_debug()) {
     osxdisplay_cat.debug()
-      << "osxGraphicsStateGuardian::build_gl Returning :" << err << "\n"; 
+      << "osxGraphicsStateGuardian::build_gl Returning :" << err << "\n";
     osxdisplay_cat.debug()
       << fb_props << "\n";
   }
@@ -314,12 +314,15 @@ describe_pixel_format(FrameBufferProperties &fb_props) {
   }
   int color_bits = 0;
   if (aglDescribePixelFormat(_aglPixFmt, AGL_RED_SIZE, &value)) {
+    fb_props.set_red_bits(value);
     color_bits += value;
   }
   if (aglDescribePixelFormat(_aglPixFmt, AGL_GREEN_SIZE, &value)) {
+    fb_props.set_green_bits(value);
     color_bits += value;
   }
   if (aglDescribePixelFormat(_aglPixFmt, AGL_BLUE_SIZE, &value)) {
+    fb_props.set_blue_bits(value);
     color_bits += value;
   }
   fb_props.set_color_bits(color_bits);
@@ -399,13 +402,13 @@ get_gamma_table() {
 ////////////////////////////////////////////////////////////////////
 //     Function: osxGraphicsStateGuardian::static_set_gamma
 //       Access: Public, Static
-//  Description: Static function for setting gamma which is needed 
+//  Description: Static function for setting gamma which is needed
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool osxGraphicsStateGuardian::
 static_set_gamma(bool restore, PN_stdfloat gamma) {
-  bool set;  
-        
+  bool set;
+
   set = false;
 
   if (restore) {
@@ -414,23 +417,23 @@ static_set_gamma(bool restore, PN_stdfloat gamma) {
     return set;
   }
   // CGDisplayRestoreColorSyncSettings();
-  
+
   // CGGammaValue gOriginalRedTable[ 256 ];
   // CGGammaValue gOriginalGreenTable[ 256 ];
   // CGGammaValue gOriginalBlueTable[ 256 ];
-  
+
   // CGTableCount sampleCount;
   // CGDisplayErr cgErr;
-  
+
   // cgErr = CGGetDisplayTransferByTable( 0, 256, _gOriginalRedTable, _gOriginalGreenTable, _gOriginalBlueTable, &_sampleCount);
-  
+
   CGGammaValue redTable[ 256 ];
   CGGammaValue greenTable[ 256 ];
   CGGammaValue blueTable[ 256 ];
-  
+
   short j, i;
   short y[3];
-  
+
   for (j = 0; j < 3; j++) {
     y[j] = 255;
   }
@@ -438,18 +441,18 @@ static_set_gamma(bool restore, PN_stdfloat gamma) {
   y[0] = 256 * gamma;
   y[1] = 256 * gamma;
   y[2] = 256 * gamma;
-  
+
   for (i = 0; i < 256; i++) {
     redTable[i] = _gOriginalRedTable[ i ] * (y[ 0 ] ) / 256;
     greenTable[ i ] = _gOriginalGreenTable[ i ] * (y[ 1 ] ) / 256;
     blueTable[ i ] = _gOriginalBlueTable[ i ] * (y[ 2 ] ) / 256;
   }
   _cgErr = CGSetDisplayTransferByTable( 0, 256, redTable, greenTable, blueTable);
-  
+
   if (_cgErr == 0) {
     set = true;
   }
-  
+
   return set;
 }
 

+ 72 - 70
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -28,7 +28,7 @@ bool wglGraphicsStateGuardian::_twindow_class_registered = false;
 ////////////////////////////////////////////////////////////////////
 wglGraphicsStateGuardian::
 wglGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
-                         wglGraphicsStateGuardian *share_with) : 
+                         wglGraphicsStateGuardian *share_with) :
   GLGraphicsStateGuardian(engine, pipe),
   _share_with(share_with)
 {
@@ -41,12 +41,12 @@ wglGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
   _pfnum = -1;
   _pfnum_supports_pbuffer = false;
   _pfnum_properties.clear();
-  
+
   _supports_pbuffer = false;
   _supports_pixel_format = false;
   _supports_wgl_multisample = false;
   _supports_wgl_render_texture = false;
-  
+
   get_gamma_table();
   atexit(atexit_function);
 }
@@ -103,7 +103,7 @@ fail_pfnum() {
 ////////////////////////////////////////////////////////////////////
 void wglGraphicsStateGuardian::
 get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum) {
-  
+
   PIXELFORMATDESCRIPTOR pfd;
   ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
@@ -113,7 +113,7 @@ get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum) {
 
   properties.clear();
   properties.set_all_specified();
-  
+
   if (((pfd.dwFlags & PFD_SUPPORT_OPENGL) == 0)||
       ((pfd.dwFlags & PFD_DRAW_TO_WINDOW) == 0)) {
     // Return without setting either RGB or Indexed Color.
@@ -123,8 +123,12 @@ get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum) {
 
   if (pfd.iPixelType == PFD_TYPE_COLORINDEX) {
     properties.set_indexed_color(1);
+    properties.set_color_bits(pfd.cColorBits);
+    properties.set_alpha_bits(pfd.cAlphaBits);
   } else {
     properties.set_rgb_color(1);
+    properties.set_rgba_bits(pfd.cRedBits, pfd.cGreenBits,
+                             pfd.cBlueBits, pfd.cAlphaBits);
   }
 
   int mode = 0;
@@ -139,13 +143,7 @@ get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum) {
   } else {
     properties.set_force_hardware(1);
   }
-  
-  if (pfd.cColorBits != 0) {
-    properties.set_color_bits(pfd.cColorBits);
-  }
-  if (pfd.cAlphaBits != 0) {
-    properties.set_alpha_bits(pfd.cAlphaBits);
-  }
+
   if (pfd.cDepthBits != 0) {
     properties.set_depth_bits(pfd.cDepthBits);
   }
@@ -164,23 +162,27 @@ get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum) {
 //               extensions.
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsStateGuardian::
-get_properties_advanced(FrameBufferProperties &properties, 
+get_properties_advanced(FrameBufferProperties &properties,
                         HDC window_dc, int pfnum) {
-  
+
   static const int max_attrib_list = 32;
   int iattrib_list[max_attrib_list];
   int ivalue_list[max_attrib_list];
   int ni = 0;
 
   int acceleration_i, pixel_type_i, double_buffer_i, stereo_i,
-    color_bits_i, alpha_bits_i, accum_bits_i, depth_bits_i, 
-    stencil_bits_i, multisamples_i, srgb_capable_i;
+    color_bits_i, red_bits_i, green_bits_i, blue_bits_i, alpha_bits_i,
+    accum_bits_i, depth_bits_i, stencil_bits_i, multisamples_i,
+    srgb_capable_i;
 
   iattrib_list[acceleration_i = ni++] = WGL_ACCELERATION_ARB;
   iattrib_list[pixel_type_i = ni++] = WGL_PIXEL_TYPE_ARB;
   iattrib_list[double_buffer_i = ni++] = WGL_DOUBLE_BUFFER_ARB;
   iattrib_list[stereo_i = ni++] = WGL_STEREO_ARB;
   iattrib_list[color_bits_i = ni++] = WGL_COLOR_BITS_ARB;
+  iattrib_list[red_bits_i = ni++] = WGL_RED_BITS_ARB;
+  iattrib_list[green_bits_i = ni++] = WGL_GREEN_BITS_ARB;
+  iattrib_list[blue_bits_i = ni++] = WGL_BLUE_BITS_ARB;
   iattrib_list[alpha_bits_i = ni++] = WGL_ALPHA_BITS_ARB;
   iattrib_list[accum_bits_i = ni++] = WGL_ACCUM_BITS_ARB;
   iattrib_list[depth_bits_i = ni++] = WGL_DEPTH_BITS_ARB;
@@ -211,8 +213,14 @@ get_properties_advanced(FrameBufferProperties &properties,
 
   if (ivalue_list[pixel_type_i] == WGL_TYPE_COLORINDEX_ARB) {
     properties.set_indexed_color(true);
+    properties.set_color_bits(ivalue_list[color_bits_i]);
+    properties.set_alpha_bits(ivalue_list[alpha_bits_i]);
   } else {
     properties.set_rgb_color(true);
+    properties.set_rgba_bits(ivalue_list[red_bits_i],
+                             ivalue_list[green_bits_i],
+                             ivalue_list[blue_bits_i],
+                             ivalue_list[alpha_bits_i]);
   }
 
   if (ivalue_list[double_buffer_i]) {
@@ -227,10 +235,6 @@ get_properties_advanced(FrameBufferProperties &properties,
     properties.set_srgb_color(true);
   }
 
-  if (ivalue_list[alpha_bits_i] != 0) {
-    properties.set_alpha_bits(ivalue_list[alpha_bits_i]);
-  }
-
   if (ivalue_list[accum_bits_i] != 0) {
     properties.set_accum_bits(ivalue_list[accum_bits_i]);
   }
@@ -249,8 +253,6 @@ get_properties_advanced(FrameBufferProperties &properties,
     }
   }
 
-  properties.set_color_bits(ivalue_list[color_bits_i]);
-
   return true;
 }
 
@@ -271,22 +273,22 @@ choose_pixel_format(const FrameBufferProperties &properties,
 
   if (gl_force_pixfmt.has_value()) {
     wgldisplay_cat.info()
-      << "overriding pixfmt choice with gl-force-pixfmt(" 
+      << "overriding pixfmt choice with gl-force-pixfmt("
       << gl_force_pixfmt << ")\n";
     _pfnum = gl_force_pixfmt;
     _pfnum_properties = properties;
     _pfnum_supports_pbuffer = true;
     return;
   }
-  
+
   int  best_pfnum = 0;
   int  best_quality = 0;
   FrameBufferProperties best_prop;
-  
+
   HDC hdc = GetDC(NULL);
 
   int max_pfnum = DescribePixelFormat(hdc, 1, 0, NULL);
-  
+
   for (int pfnum = 0; pfnum<max_pfnum; ++pfnum) {
     FrameBufferProperties pfprop;
     get_properties(pfprop, hdc, pfnum);
@@ -297,7 +299,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
       best_prop = pfprop;
     }
   }
-  
+
   ReleaseDC(NULL, hdc);
 
   _pfnum = best_pfnum;
@@ -305,7 +307,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
   _pfnum_properties = best_prop;
   _pre_pfnum = _pfnum;
   _pre_pfnum_properties = _pfnum_properties;
-  
+
   if (best_quality == 0) {
     wgldisplay_cat.error()
       << "Could not find a usable pixel format.\n";
@@ -314,7 +316,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
 
   if (wgldisplay_cat.is_debug()) {
     wgldisplay_cat.debug()
-      << "Preliminary pixfmt #" << _pfnum << " = " 
+      << "Preliminary pixfmt #" << _pfnum << " = "
       << _pfnum_properties << "\n";
   }
 
@@ -325,7 +327,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
   // fetch the extensions temporarily, get the few extensions
   // we need, then clear the extensions list again in preparation
   // for the reset.
-  
+
   HDC twindow_dc = get_twindow_dc();
   if (twindow_dc == 0) {
     return;
@@ -368,13 +370,13 @@ choose_pixel_format(const FrameBufferProperties &properties,
 
   //// Use the wgl extensions to find a better format.
   //
-  
+
   static const int max_attrib_list = 64;
   int iattrib_list[max_attrib_list];
   float fattrib_list[max_attrib_list];
   int ni = 0;
   int nf = 0;
-  
+
   iattrib_list[ni++] = WGL_SUPPORT_OPENGL_ARB;
   iattrib_list[ni++] = true;
   iattrib_list[ni++] = WGL_PIXEL_TYPE_ARB;
@@ -395,18 +397,18 @@ choose_pixel_format(const FrameBufferProperties &properties,
   nassertv(ni < max_attrib_list && nf < max_attrib_list);
   iattrib_list[ni] = 0;
   fattrib_list[nf] = 0;
-  
+
   static const int max_pformats = 1024;
   int pformat[max_pformats];
   memset(pformat, 0, sizeof(pformat));
   int nformats = 0;
-  
+
   if (!_wglChoosePixelFormatARB(twindow_dc, iattrib_list, fattrib_list,
                                 max_pformats, pformat, (unsigned int *)&nformats)) {
     nformats = 0;
   }
   nformats = min(nformats, max_pformats);
-  
+
   if (wgldisplay_cat.is_debug()) {
     wgldisplay_cat.debug()
       << "Found " << nformats << " advanced formats: [";
@@ -417,7 +419,7 @@ choose_pixel_format(const FrameBufferProperties &properties,
     wgldisplay_cat.debug(false)
       << " ]\n";
   }
-  
+
   if (nformats > 0) {
     if (need_pbuffer) {
       best_quality = 0;
@@ -445,11 +447,11 @@ choose_pixel_format(const FrameBufferProperties &properties,
 
     if (wgldisplay_cat.is_debug()) {
       wgldisplay_cat.debug()
-        << "Selected advanced pixfmt #" << _pfnum << " = " 
+        << "Selected advanced pixfmt #" << _pfnum << " = "
         << _pfnum_properties << "\n";
     }
   }
-  
+
   wglDeleteContext(twindow_ctx);
   release_twindow();
 }
@@ -467,7 +469,7 @@ reset() {
   _supports_swap_control = has_extension("WGL_EXT_swap_control");
 
   if (_supports_swap_control) {
-    _wglSwapIntervalEXT = 
+    _wglSwapIntervalEXT =
       (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
     if (_wglSwapIntervalEXT == NULL) {
       wgldisplay_cat.error()
@@ -485,17 +487,17 @@ reset() {
   _supports_pbuffer = has_extension("WGL_ARB_pbuffer");
 
   if (_supports_pbuffer) {
-    _wglCreatePbufferARB = 
+    _wglCreatePbufferARB =
       (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
-    _wglGetPbufferDCARB = 
+    _wglGetPbufferDCARB =
       (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
-    _wglReleasePbufferDCARB = 
+    _wglReleasePbufferDCARB =
       (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
-    _wglDestroyPbufferARB = 
+    _wglDestroyPbufferARB =
       (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
-    _wglQueryPbufferARB = 
+    _wglQueryPbufferARB =
       (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
-    
+
     if (_wglCreatePbufferARB == NULL ||
         _wglGetPbufferDCARB == NULL ||
         _wglReleasePbufferDCARB == NULL ||
@@ -531,11 +533,11 @@ reset() {
   _supports_wgl_render_texture = has_extension("WGL_ARB_render_texture");
 
   if (_supports_wgl_render_texture) {
-    _wglBindTexImageARB = 
+    _wglBindTexImageARB =
       (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
-    _wglReleaseTexImageARB = 
+    _wglReleaseTexImageARB =
       (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
-    _wglSetPbufferAttribARB = 
+    _wglSetPbufferAttribARB =
       (PFNWGLSETPBUFFERATTRIBARBPROC)wglGetProcAddress("wglSetPbufferAttribARB");
     if (_wglBindTexImageARB == NULL ||
         _wglReleaseTexImageARB == NULL ||
@@ -562,7 +564,7 @@ get_extra_extensions() {
 
   // Look for the ARB flavor first, which wants one parameter, the HDC
   // of the drawing context.
-  PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 
+  PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB =
     (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
   if (wglGetExtensionsStringARB != NULL) {
     HDC hdc = wglGetCurrentDC();
@@ -574,7 +576,7 @@ get_extra_extensions() {
 
   // If that failed, look for the EXT flavor, which wants no
   // parameters.
-  PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT = 
+  PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT =
     (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT");
   if (wglGetExtensionsStringEXT != NULL) {
     save_extensions((const char *)wglGetExtensionsStringEXT());
@@ -709,9 +711,9 @@ make_twindow() {
 
   register_twindow_class();
   HINSTANCE hinstance = GetModuleHandle(NULL);
-  _twindow = CreateWindow(_twindow_class_name, "twindow", window_style, 
+  _twindow = CreateWindow(_twindow_class_name, "twindow", window_style,
                           0, 0, 1, 1, NULL, NULL, hinstance, 0);
-  
+
   if (!_twindow) {
     wgldisplay_cat.error()
       << "CreateWindow() failed!" << endl;
@@ -775,7 +777,7 @@ register_twindow_class() {
   wc.lpfnWndProc = DefWindowProc;
   wc.hInstance = instance;
   wc.lpszClassName = _twindow_class_name;
-  
+
   if (!RegisterClass(&wc)) {
     wgldisplay_cat.error()
       << "could not register window class!" << endl;
@@ -797,8 +799,8 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
     // avoid divide by zero and negative exponents
     gamma = 1.0;
   }
-  gamma_correction = 1.0 / (double) gamma;    
-  
+  gamma_correction = 1.0 / (double) gamma;
+
   for (i = 0; i < 256; i++) {
     double r;
     double g;
@@ -809,11 +811,11 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
       g = (double) original_green_table [i] / GAMMA_1;
       b = (double) original_blue_table [i] / GAMMA_1;
     }
-    else {    
+    else {
       r = ((double) i / 255.0);
       g = r;
       b = r;
-    }    
+    }
 
     r = pow (r, gamma_correction);
     g = pow (g, gamma_correction);
@@ -829,14 +831,14 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
       b = 1.0;
     }
 
-    r = r * GAMMA_1;    
-    g = g * GAMMA_1;    
-    b = b * GAMMA_1;    
+    r = r * GAMMA_1;
+    g = g * GAMMA_1;
+    b = b * GAMMA_1;
 
     red_table [i] = r;
     green_table [i] = g;
     blue_table [i] = b;
-  }    
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -846,13 +848,13 @@ void _create_gamma_table (PN_stdfloat gamma, unsigned short *original_red_table,
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsStateGuardian::
 get_gamma_table(void) {
-  bool get;  
+  bool get;
 
   get = false;
   if (_gamma_table_initialized == false) {
     HDC hdc = GetDC(NULL);
 
-    if (hdc) {   
+    if (hdc) {
       if (GetDeviceGammaRamp (hdc, (LPVOID) _orignial_gamma_table)) {
         _gamma_table_initialized = true;
         get = true;
@@ -861,26 +863,26 @@ get_gamma_table(void) {
       ReleaseDC (NULL, hdc);
     }
   }
-  
+
   return get;
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsStateGuardian::static_set_gamma
 //       Access: Public, Static
-//  Description: Static function for setting gamma which is needed 
+//  Description: Static function for setting gamma which is needed
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsStateGuardian::
 static_set_gamma(bool restore, PN_stdfloat gamma) {
-  bool set;  
+  bool set;
   HDC hdc = GetDC(NULL);
 
   set = false;
-  if (hdc) {   
+  if (hdc) {
     unsigned short ramp [256 * 3];
 
-    if (restore && _gamma_table_initialized) {    
+    if (restore && _gamma_table_initialized) {
       _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
     }
     else {
@@ -890,7 +892,7 @@ static_set_gamma(bool restore, PN_stdfloat gamma) {
     if (SetDeviceGammaRamp (hdc, ramp)) {
       set = true;
     }
-    
+
     ReleaseDC (NULL, hdc);
   }
 
@@ -909,7 +911,7 @@ set_gamma(PN_stdfloat gamma) {
 
   set = static_set_gamma(false, gamma);
   if (set) {
-    _gamma = gamma;  
+    _gamma = gamma;
   }
 
   return set;