Browse Source

fix red/blue reversal on gl screenshots

David Rose 23 years ago
parent
commit
c4caabf006
2 changed files with 173 additions and 159 deletions
  1. 98 98
      panda/src/glgsg/glGraphicsStateGuardian.I
  2. 75 61
      panda/src/glgsg/glGraphicsStateGuardian.cxx

+ 98 - 98
panda/src/glgsg/glGraphicsStateGuardian.I

@@ -69,7 +69,7 @@ INLINE void GLGraphicsStateGuardian::
 call_glClearDepth(GLclampd depth) {
 call_glClearDepth(GLclampd depth) {
   if (depth != _clear_depth) {
   if (depth != _clear_depth) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug()
+    glgsg_cat.spam()
       << "glClearDepth(" << (double)depth << ")" << endl;
       << "glClearDepth(" << (double)depth << ")" << endl;
 #endif
 #endif
     glClearDepth(depth);
     glClearDepth(depth);
@@ -120,37 +120,37 @@ INLINE void GLGraphicsStateGuardian::
 call_glDrawBuffer(GLenum mode) {
 call_glDrawBuffer(GLenum mode) {
   if (mode != _draw_buffer_mode) {
   if (mode != _draw_buffer_mode) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glDrawBuffer(";
+    glgsg_cat.spam() << "glDrawBuffer(";
     switch (mode) {
     switch (mode) {
     case GL_FRONT:
     case GL_FRONT:
-      glgsg_cat.debug(false) << "GL_FRONT)";
+      glgsg_cat.spam(false) << "GL_FRONT)";
       break;
       break;
     case GL_BACK:
     case GL_BACK:
-      glgsg_cat.debug(false) << "GL_BACK)";
+      glgsg_cat.spam(false) << "GL_BACK)";
       break;
       break;
     case GL_RIGHT:
     case GL_RIGHT:
-      glgsg_cat.debug(false) << "GL_RIGHT)";
+      glgsg_cat.spam(false) << "GL_RIGHT)";
       break;
       break;
     case GL_LEFT:
     case GL_LEFT:
-      glgsg_cat.debug(false) << "GL_LEFT)";
+      glgsg_cat.spam(false) << "GL_LEFT)";
       break;
       break;
     case GL_FRONT_RIGHT:
     case GL_FRONT_RIGHT:
-      glgsg_cat.debug(false) << "GL_FRONT_RIGHT)";
+      glgsg_cat.spam(false) << "GL_FRONT_RIGHT)";
       break;
       break;
     case GL_FRONT_LEFT:
     case GL_FRONT_LEFT:
-      glgsg_cat.debug(false) << "GL_FRONT_LEFT)";
+      glgsg_cat.spam(false) << "GL_FRONT_LEFT)";
       break;
       break;
     case GL_BACK_RIGHT:
     case GL_BACK_RIGHT:
-      glgsg_cat.debug(false) << "GL_BACK_RIGHT)";
+      glgsg_cat.spam(false) << "GL_BACK_RIGHT)";
       break;
       break;
     case GL_BACK_LEFT:
     case GL_BACK_LEFT:
-      glgsg_cat.debug(false) << "GL_BACK_LEFT)";
+      glgsg_cat.spam(false) << "GL_BACK_LEFT)";
       break;
       break;
     case GL_FRONT_AND_BACK:
     case GL_FRONT_AND_BACK:
-      glgsg_cat.debug(false) << "GL_FRONT_AND_BACK)";
+      glgsg_cat.spam(false) << "GL_FRONT_AND_BACK)";
       break;
       break;
     }
     }
-    glgsg_cat.debug(false) << endl;
+    glgsg_cat.spam(false) << endl;
 #endif
 #endif
     glDrawBuffer(mode);
     glDrawBuffer(mode);
     _draw_buffer_mode = mode;
     _draw_buffer_mode = mode;
@@ -244,7 +244,7 @@ call_glLightModelTwoSide(GLboolean twoside)
   if (_lmodel_twoside != twoside) {
   if (_lmodel_twoside != twoside) {
     _lmodel_twoside = twoside;
     _lmodel_twoside = twoside;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug()
+    glgsg_cat.spam()
       << "glLightModel(GL_LIGHT_MODEL_TWO_SIDE, " << (int)twoside << ")" << endl;
       << "glLightModel(GL_LIGHT_MODEL_TWO_SIDE, " << (int)twoside << ")" << endl;
 #endif
 #endif
     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, twoside);
     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, twoside);
@@ -260,37 +260,37 @@ INLINE void GLGraphicsStateGuardian::
 call_glStencilFunc(GLenum func,GLint ref,GLuint mask) {
 call_glStencilFunc(GLenum func,GLint ref,GLuint mask) {
 
 
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glStencilFunc(";
+    glgsg_cat.spam() << "glStencilFunc(";
     switch (func) {
     switch (func) {
     case GL_NEVER:
     case GL_NEVER:
-      glgsg_cat.debug(false) << "GL_NEVER, ";
+      glgsg_cat.spam(false) << "GL_NEVER, ";
       break;
       break;
     case GL_LESS:
     case GL_LESS:
-      glgsg_cat.debug(false) << "GL_LESS, ";
+      glgsg_cat.spam(false) << "GL_LESS, ";
       break;
       break;
     case GL_EQUAL:
     case GL_EQUAL:
-      glgsg_cat.debug(false) << "GL_EQUAL, ";
+      glgsg_cat.spam(false) << "GL_EQUAL, ";
       break;
       break;
     case GL_LEQUAL:
     case GL_LEQUAL:
-      glgsg_cat.debug(false) << "GL_LEQUAL, ";
+      glgsg_cat.spam(false) << "GL_LEQUAL, ";
       break;
       break;
     case GL_GREATER:
     case GL_GREATER:
-      glgsg_cat.debug(false) << "GL_GREATER, ";
+      glgsg_cat.spam(false) << "GL_GREATER, ";
       break;
       break;
     case GL_NOTEQUAL:
     case GL_NOTEQUAL:
-      glgsg_cat.debug(false) << "GL_NOTEQUAL, ";
+      glgsg_cat.spam(false) << "GL_NOTEQUAL, ";
       break;
       break;
     case GL_GEQUAL:
     case GL_GEQUAL:
-      glgsg_cat.debug(false) << "GL_GEQUAL, ";
+      glgsg_cat.spam(false) << "GL_GEQUAL, ";
       break;
       break;
     case GL_ALWAYS:
     case GL_ALWAYS:
-      glgsg_cat.debug(false) << "GL_ALWAYS, ";
+      glgsg_cat.spam(false) << "GL_ALWAYS, ";
       break;
       break;
     default:
     default:
-      glgsg_cat.debug(false) << "unknown, ";
+      glgsg_cat.spam(false) << "unknown, ";
       break;
       break;
     }
     }
-    glgsg_cat.debug(false) << (int)ref << (unsigned int)mask << ")\n";
+    glgsg_cat.spam(false) << (int)ref << (unsigned int)mask << ")\n";
 #endif
 #endif
     glStencilFunc(func, ref, mask);
     glStencilFunc(func, ref, mask);
 }
 }
@@ -303,31 +303,31 @@ call_glStencilFunc(GLenum func,GLint ref,GLuint mask) {
 INLINE void GLGraphicsStateGuardian::
 INLINE void GLGraphicsStateGuardian::
 call_glStencilOp(GLenum fail,GLenum zfail,GLenum zpass) {
 call_glStencilOp(GLenum fail,GLenum zfail,GLenum zpass) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glStencilOp(fail, zfail, ";
+    glgsg_cat.spam() << "glStencilOp(fail, zfail, ";
     switch (zpass) {
     switch (zpass) {
     case GL_KEEP:
     case GL_KEEP:
-      glgsg_cat.debug(false) << "GL_KEEP)";
+      glgsg_cat.spam(false) << "GL_KEEP)";
       break;
       break;
     case GL_ZERO:
     case GL_ZERO:
-      glgsg_cat.debug(false) << "GL_ZERO)";
+      glgsg_cat.spam(false) << "GL_ZERO)";
       break;
       break;
     case GL_REPLACE:
     case GL_REPLACE:
-      glgsg_cat.debug(false) << "GL_REPLACE)";
+      glgsg_cat.spam(false) << "GL_REPLACE)";
       break;
       break;
     case GL_INCR:
     case GL_INCR:
-      glgsg_cat.debug(false) << "GL_INCR)";
+      glgsg_cat.spam(false) << "GL_INCR)";
       break;
       break;
     case GL_DECR:
     case GL_DECR:
-      glgsg_cat.debug(false) << "GL_DECR)";
+      glgsg_cat.spam(false) << "GL_DECR)";
       break;
       break;
     case GL_INVERT:
     case GL_INVERT:
-      glgsg_cat.debug(false) << "GL_INVERT)";
+      glgsg_cat.spam(false) << "GL_INVERT)";
       break;
       break;
     default:
     default:
-      glgsg_cat.debug(false) << "unknown)";
+      glgsg_cat.spam(false) << "unknown)";
       break;
       break;
     }
     }
-    glgsg_cat.debug(false) << endl;
+    glgsg_cat.spam(false) << endl;
 #endif
 #endif
     glStencilOp(fail,zfail,zpass);
     glStencilOp(fail,zfail,zpass);
 }
 }
@@ -342,7 +342,7 @@ call_glLineWidth(GLfloat width) {
   if (_line_width != width) {
   if (_line_width != width) {
     _line_width = width;
     _line_width = width;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glLineWidth(" << width << ")" << endl;
     << "glLineWidth(" << width << ")" << endl;
 #endif
 #endif
     glLineWidth(width);
     glLineWidth(width);
@@ -359,7 +359,7 @@ call_glPointSize(GLfloat size) {
   if (_point_size != size) {
   if (_point_size != size) {
     _point_size = size;
     _point_size = size;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glPointSize(" << size << ")" << endl;
     << "glPointSize(" << size << ")" << endl;
 #endif
 #endif
     glPointSize(size);
     glPointSize(size);
@@ -377,70 +377,70 @@ call_glBlendFunc(GLenum sfunc, GLenum dfunc) {
     _blend_source_func = sfunc;
     _blend_source_func = sfunc;
     _blend_dest_func = dfunc;
     _blend_dest_func = dfunc;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glBlendFunc(";
+    glgsg_cat.spam() << "glBlendFunc(";
     switch (sfunc) {
     switch (sfunc) {
     case GL_ZERO:
     case GL_ZERO:
-      glgsg_cat.debug(false) << "GL_ZERO, ";
+      glgsg_cat.spam(false) << "GL_ZERO, ";
       break;
       break;
     case GL_ONE:
     case GL_ONE:
-      glgsg_cat.debug(false) << "GL_ONE, ";
+      glgsg_cat.spam(false) << "GL_ONE, ";
       break;
       break;
     case GL_DST_COLOR:
     case GL_DST_COLOR:
-      glgsg_cat.debug(false) << "GL_DST_COLOR, ";
+      glgsg_cat.spam(false) << "GL_DST_COLOR, ";
       break;
       break;
     case GL_ONE_MINUS_DST_COLOR:
     case GL_ONE_MINUS_DST_COLOR:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_DST_COLOR, ";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_DST_COLOR, ";
       break;
       break;
     case GL_SRC_ALPHA:
     case GL_SRC_ALPHA:
-      glgsg_cat.debug(false) << "GL_SRC_ALPHA, ";
+      glgsg_cat.spam(false) << "GL_SRC_ALPHA, ";
       break;
       break;
     case GL_ONE_MINUS_SRC_ALPHA:
     case GL_ONE_MINUS_SRC_ALPHA:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_SRC_ALPHA, ";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_SRC_ALPHA, ";
       break;
       break;
     case GL_DST_ALPHA:
     case GL_DST_ALPHA:
-      glgsg_cat.debug(false) << "GL_DST_ALPHA, ";
+      glgsg_cat.spam(false) << "GL_DST_ALPHA, ";
       break;
       break;
     case GL_ONE_MINUS_DST_ALPHA:
     case GL_ONE_MINUS_DST_ALPHA:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_DST_ALPHA, ";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_DST_ALPHA, ";
       break;
       break;
     case GL_SRC_ALPHA_SATURATE:
     case GL_SRC_ALPHA_SATURATE:
 
 
-      glgsg_cat.debug(false) << "GL_SRC_ALPHA_SATURATE, ";
+      glgsg_cat.spam(false) << "GL_SRC_ALPHA_SATURATE, ";
       break;
       break;
     default:
     default:
-      glgsg_cat.debug(false) << "unknown, ";
+      glgsg_cat.spam(false) << "unknown, ";
       break;
       break;
     }
     }
     switch (dfunc) {
     switch (dfunc) {
     case GL_ZERO:
     case GL_ZERO:
-      glgsg_cat.debug(false) << "GL_ZERO)";
+      glgsg_cat.spam(false) << "GL_ZERO)";
       break;
       break;
     case GL_ONE:
     case GL_ONE:
-      glgsg_cat.debug(false) << "GL_ONE)";
+      glgsg_cat.spam(false) << "GL_ONE)";
       break;
       break;
     case GL_SRC_COLOR:
     case GL_SRC_COLOR:
-      glgsg_cat.debug(false) << "GL_SRC_COLOR)";
+      glgsg_cat.spam(false) << "GL_SRC_COLOR)";
       break;
       break;
     case GL_ONE_MINUS_SRC_COLOR:
     case GL_ONE_MINUS_SRC_COLOR:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_SRC_COLOR)";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_SRC_COLOR)";
       break;
       break;
     case GL_SRC_ALPHA:
     case GL_SRC_ALPHA:
-      glgsg_cat.debug(false) << "GL_SRC_ALPHA)";
+      glgsg_cat.spam(false) << "GL_SRC_ALPHA)";
       break;
       break;
     case GL_ONE_MINUS_SRC_ALPHA:
     case GL_ONE_MINUS_SRC_ALPHA:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_SRC_ALPHA)";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_SRC_ALPHA)";
       break;
       break;
     case GL_DST_ALPHA:
     case GL_DST_ALPHA:
-      glgsg_cat.debug(false) << "GL_DST_ALPHA)";
+      glgsg_cat.spam(false) << "GL_DST_ALPHA)";
       break;
       break;
     case GL_ONE_MINUS_DST_ALPHA:
     case GL_ONE_MINUS_DST_ALPHA:
-      glgsg_cat.debug(false) << "GL_ONE_MINUS_DST_ALPHA)";
+      glgsg_cat.spam(false) << "GL_ONE_MINUS_DST_ALPHA)";
       break;
       break;
     default:
     default:
-      glgsg_cat.debug(false) << "unknown)";
+      glgsg_cat.spam(false) << "unknown)";
       break;
       break;
     }
     }
-    glgsg_cat.debug(false) << endl;
+    glgsg_cat.spam(false) << endl;
 #endif
 #endif
     glBlendFunc(sfunc, dfunc);
     glBlendFunc(sfunc, dfunc);
   }
   }
@@ -456,24 +456,24 @@ call_glFogMode(GLint mode) {
   if (_fog_mode != mode) {
   if (_fog_mode != mode) {
     _fog_mode = mode;
     _fog_mode = mode;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glFog(GL_FOG_MODE, ";
+    glgsg_cat.spam() << "glFog(GL_FOG_MODE, ";
     switch(mode) {
     switch(mode) {
     case GL_LINEAR:
     case GL_LINEAR:
-      glgsg_cat.debug(false) << "GL_LINEAR)" << endl;
+      glgsg_cat.spam(false) << "GL_LINEAR)" << endl;
       break;
       break;
     case GL_EXP:
     case GL_EXP:
-      glgsg_cat.debug(false) << "GL_EXP)" << endl;
+      glgsg_cat.spam(false) << "GL_EXP)" << endl;
       break;
       break;
     case GL_EXP2:
     case GL_EXP2:
-      glgsg_cat.debug(false) << "GL_EXP2)" << endl;
+      glgsg_cat.spam(false) << "GL_EXP2)" << endl;
       break;
       break;
 #ifdef GL_FOG_FUNC_SGIS
 #ifdef GL_FOG_FUNC_SGIS
     case GL_FOG_FUNC_SGIS:
     case GL_FOG_FUNC_SGIS:
-      glgsg_cat.debug(false) << "GL_FOG_FUNC_SGIS)" << endl;
+      glgsg_cat.spam(false) << "GL_FOG_FUNC_SGIS)" << endl;
       break;
       break;
 #endif
 #endif
     default:
     default:
-      glgsg_cat.debug(false) << "unknown)" << endl;
+      glgsg_cat.spam(false) << "unknown)" << endl;
       break;
       break;
     }
     }
 #endif
 #endif
@@ -491,7 +491,7 @@ call_glFogStart(GLfloat start) {
   if (_fog_start != start) {
   if (_fog_start != start) {
     _fog_start = start;
     _fog_start = start;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glFog(GL_FOG_START, " << start << ")" << endl;
     << "glFog(GL_FOG_START, " << start << ")" << endl;
 #endif
 #endif
     glFogf(GL_FOG_START, start);
     glFogf(GL_FOG_START, start);
@@ -508,7 +508,7 @@ call_glFogEnd(GLfloat end) {
   if (_fog_end != end) {
   if (_fog_end != end) {
     _fog_end = end;
     _fog_end = end;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glFog(GL_FOG_END, " << end << ")" << endl;
     << "glFog(GL_FOG_END, " << end << ")" << endl;
 #endif
 #endif
     glFogf(GL_FOG_END, end);
     glFogf(GL_FOG_END, end);
@@ -525,7 +525,7 @@ call_glFogDensity(GLfloat density) {
   if (_fog_density != density) {
   if (_fog_density != density) {
     _fog_density = density;
     _fog_density = density;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glFog(GL_FOG_DENSITY, " << density << ")" << endl;
     << "glFog(GL_FOG_DENSITY, " << density << ")" << endl;
 #endif
 #endif
     glFogf(GL_FOG_DENSITY, density);
     glFogf(GL_FOG_DENSITY, density);
@@ -542,7 +542,7 @@ call_glFogColor(const Colorf &color) {
   if (_fog_color != color) {
   if (_fog_color != color) {
     _fog_color = color;
     _fog_color = color;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glFog(GL_FOG_COLOR, " << color << ")" << endl;
     << "glFog(GL_FOG_COLOR, " << color << ")" << endl;
 #endif
 #endif
     glFogfv(GL_FOG_COLOR, color.get_data());
     glFogfv(GL_FOG_COLOR, color.get_data());
@@ -560,34 +560,34 @@ call_glAlphaFunc(GLenum func, GLclampf ref) {
     _alpha_func = func;
     _alpha_func = func;
     _alpha_func_ref = ref;
     _alpha_func_ref = ref;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glAlphaFunc(";
+    glgsg_cat.spam() << "glAlphaFunc(";
     switch (func) {
     switch (func) {
     case GL_NEVER:
     case GL_NEVER:
-      glgsg_cat.debug(false) << "GL_NEVER, ";
+      glgsg_cat.spam(false) << "GL_NEVER, ";
       break;
       break;
     case GL_LESS:
     case GL_LESS:
-      glgsg_cat.debug(false) << "GL_LESS, ";
+      glgsg_cat.spam(false) << "GL_LESS, ";
       break;
       break;
     case GL_EQUAL:
     case GL_EQUAL:
-      glgsg_cat.debug(false) << "GL_EQUAL, ";
+      glgsg_cat.spam(false) << "GL_EQUAL, ";
       break;
       break;
     case GL_LEQUAL:
     case GL_LEQUAL:
-      glgsg_cat.debug(false) << "GL_LEQUAL, ";
+      glgsg_cat.spam(false) << "GL_LEQUAL, ";
       break;
       break;
     case GL_GREATER:
     case GL_GREATER:
-      glgsg_cat.debug(false) << "GL_GREATER, ";
+      glgsg_cat.spam(false) << "GL_GREATER, ";
       break;
       break;
     case GL_NOTEQUAL:
     case GL_NOTEQUAL:
-      glgsg_cat.debug(false) << "GL_NOTEQUAL, ";
+      glgsg_cat.spam(false) << "GL_NOTEQUAL, ";
       break;
       break;
     case GL_GEQUAL:
     case GL_GEQUAL:
-      glgsg_cat.debug(false) << "GL_GEQUAL, ";
+      glgsg_cat.spam(false) << "GL_GEQUAL, ";
       break;
       break;
     case GL_ALWAYS:
     case GL_ALWAYS:
-      glgsg_cat.debug(false) << "GL_ALWAYS, ";
+      glgsg_cat.spam(false) << "GL_ALWAYS, ";
       break;
       break;
     }
     }
-    glgsg_cat.debug() << ref << ")" << endl;
+    glgsg_cat.spam() << ref << ")" << endl;
 #endif
 #endif
     glAlphaFunc(func, ref);
     glAlphaFunc(func, ref);
   }
   }
@@ -603,16 +603,16 @@ call_glPolygonMode(GLenum mode) {
   if (_polygon_mode != mode) {
   if (_polygon_mode != mode) {
     _polygon_mode = mode;
     _polygon_mode = mode;
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-    glgsg_cat.debug() << "glPolygonMode(GL_BACK_AND_FRONT, ";
+    glgsg_cat.spam() << "glPolygonMode(GL_BACK_AND_FRONT, ";
     switch (mode) {
     switch (mode) {
     case GL_POINT:
     case GL_POINT:
-      glgsg_cat.debug(false) << "GL_POINT)" << endl;
+      glgsg_cat.spam(false) << "GL_POINT)" << endl;
       break;
       break;
     case GL_LINE:
     case GL_LINE:
-      glgsg_cat.debug(false) << "GL_LINE)" << endl;
+      glgsg_cat.spam(false) << "GL_LINE)" << endl;
       break;
       break;
     case GL_FILL:
     case GL_FILL:
-      glgsg_cat.debug(false) << "GL_FILL)" << endl;
+      glgsg_cat.spam(false) << "GL_FILL)" << endl;
       break;
       break;
     }
     }
 #endif
 #endif
@@ -717,13 +717,13 @@ enable_stencil_test(bool val) {
     _stencil_test_enabled = val;
     _stencil_test_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_STENCIL_TEST)" << endl;
         << "glEnable(GL_STENCIL_TEST)" << endl;
 #endif
 #endif
       glEnable(GL_STENCIL_TEST);
       glEnable(GL_STENCIL_TEST);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_STENCIL_TEST)" << endl;
         << "glDisable(GL_STENCIL_TEST)" << endl;
 #endif
 #endif
       glDisable(GL_STENCIL_TEST);
       glDisable(GL_STENCIL_TEST);
@@ -742,13 +742,13 @@ enable_texturing(bool val) {
     _texturing_enabled = val;
     _texturing_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_TEXTURE_2D)" << endl;
         << "glEnable(GL_TEXTURE_2D)" << endl;
 #endif
 #endif
       glEnable(GL_TEXTURE_2D);
       glEnable(GL_TEXTURE_2D);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_TEXTURE_2D)" << endl;
         << "glDisable(GL_TEXTURE_2D)" << endl;
 #endif
 #endif
       glDisable(GL_TEXTURE_2D);
       glDisable(GL_TEXTURE_2D);
@@ -785,13 +785,13 @@ enable_multisample_alpha_one(bool val) {
 #ifdef GL_SAMPLE_ALPHA_TO_ONE_SGIS
 #ifdef GL_SAMPLE_ALPHA_TO_ONE_SGIS
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl;
         << "glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl;
 #endif
 #endif
       glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS);
       glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl;
         << "glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl;
 #endif
 #endif
       glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS);
       glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS);
@@ -812,13 +812,13 @@ enable_multisample_alpha_mask(bool val) {
 #ifdef GL_SAMPLE_ALPHA_TO_MASK_SGIS
 #ifdef GL_SAMPLE_ALPHA_TO_MASK_SGIS
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl;
         << "glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl;
 #endif
 #endif
       glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS);
       glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl;
         << "glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl;
 #endif
 #endif
       glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS);
       glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS);
@@ -838,13 +838,13 @@ enable_blend(bool val) {
     _blend_enabled = val;
     _blend_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_BLEND)" << endl;
         << "glEnable(GL_BLEND)" << endl;
 #endif
 #endif
       glEnable(GL_BLEND);
       glEnable(GL_BLEND);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_BLEND)" << endl;
         << "glDisable(GL_BLEND)" << endl;
 #endif
 #endif
       glDisable(GL_BLEND);
       glDisable(GL_BLEND);
@@ -863,13 +863,13 @@ enable_depth_test(bool val) {
     _depth_test_enabled = val;
     _depth_test_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_DEPTH_TEST)" << endl;
         << "glEnable(GL_DEPTH_TEST)" << endl;
 #endif
 #endif
       glEnable(GL_DEPTH_TEST);
       glEnable(GL_DEPTH_TEST);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_DEPTH_TEST)" << endl;
         << "glDisable(GL_DEPTH_TEST)" << endl;
 #endif
 #endif
       glDisable(GL_DEPTH_TEST);
       glDisable(GL_DEPTH_TEST);
@@ -888,13 +888,13 @@ enable_fog(bool val) {
     _fog_enabled = val;
     _fog_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_FOG)" << endl;
         << "glEnable(GL_FOG)" << endl;
 #endif
 #endif
       glEnable(GL_FOG);
       glEnable(GL_FOG);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_FOG)" << endl;
         << "glDisable(GL_FOG)" << endl;
 #endif
 #endif
       glDisable(GL_FOG);
       glDisable(GL_FOG);
@@ -913,13 +913,13 @@ enable_alpha_test(bool val) {
     _alpha_test_enabled = val;
     _alpha_test_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_ALPHA_TEST)" << endl;
         << "glEnable(GL_ALPHA_TEST)" << endl;
 #endif
 #endif
       glEnable(GL_ALPHA_TEST);
       glEnable(GL_ALPHA_TEST);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_ALPHA_TEST)" << endl;
         << "glDisable(GL_ALPHA_TEST)" << endl;
 #endif
 #endif
       glDisable(GL_ALPHA_TEST);
       glDisable(GL_ALPHA_TEST);
@@ -939,13 +939,13 @@ enable_polygon_offset(bool val) {
     _polygon_offset_enabled = val;
     _polygon_offset_enabled = val;
     if (val) {
     if (val) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glEnable(GL_POLYGON_OFFSET_*)" << endl;
         << "glEnable(GL_POLYGON_OFFSET_*)" << endl;
 #endif
 #endif
       glEnable(GL_POLYGON_OFFSET_FILL);
       glEnable(GL_POLYGON_OFFSET_FILL);
     } else {
     } else {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-      glgsg_cat.debug()
+      glgsg_cat.spam()
         << "glDisable(GL_POLYGON_OFFSET_*)" << endl;
         << "glDisable(GL_POLYGON_OFFSET_*)" << endl;
 #endif
 #endif
       glDisable(GL_POLYGON_OFFSET_FILL);
       glDisable(GL_POLYGON_OFFSET_FILL);

+ 75 - 61
panda/src/glgsg/glGraphicsStateGuardian.cxx

@@ -86,7 +86,7 @@ static void
 issue_vertex_gl(const Geom *geom, Geom::VertexIterator &viterator, 
 issue_vertex_gl(const Geom *geom, Geom::VertexIterator &viterator, 
                 GraphicsStateGuardianBase *) {
                 GraphicsStateGuardianBase *) {
   const Vertexf &vertex = geom->get_next_vertex(viterator);
   const Vertexf &vertex = geom->get_next_vertex(viterator);
-  // glgsg_cat.debug() << "Issuing vertex " << vertex << "\n";
+  // glgsg_cat.spam() << "Issuing vertex " << vertex << "\n";
   glVertex3fv(vertex.get_data());
   glVertex3fv(vertex.get_data());
 }
 }
 
 
@@ -94,7 +94,7 @@ static void
 issue_normal_gl(const Geom *geom, Geom::NormalIterator &niterator, 
 issue_normal_gl(const Geom *geom, Geom::NormalIterator &niterator, 
                 GraphicsStateGuardianBase *) {
                 GraphicsStateGuardianBase *) {
   const Normalf &normal = geom->get_next_normal(niterator);
   const Normalf &normal = geom->get_next_normal(niterator);
-  // glgsg_cat.debug() << "Issuing normal " << normal << "\n";
+  // glgsg_cat.spam() << "Issuing normal " << normal << "\n";
   glNormal3fv(normal.get_data());
   glNormal3fv(normal.get_data());
 }
 }
 
 
@@ -102,7 +102,7 @@ static void
 issue_texcoord_gl(const Geom *geom, Geom::TexCoordIterator &tciterator, 
 issue_texcoord_gl(const Geom *geom, Geom::TexCoordIterator &tciterator, 
                 GraphicsStateGuardianBase *) {
                 GraphicsStateGuardianBase *) {
   const TexCoordf &texcoord = geom->get_next_texcoord(tciterator);
   const TexCoordf &texcoord = geom->get_next_texcoord(tciterator);
-  //  glgsg_cat.debug() << "Issuing texcoord " << texcoord << "\n";
+  //  glgsg_cat.spam() << "Issuing texcoord " << texcoord << "\n";
   glTexCoord2fv(texcoord.get_data());
   glTexCoord2fv(texcoord.get_data());
 }
 }
 
 
@@ -110,7 +110,7 @@ static void
 issue_color_gl(const Geom *geom, Geom::ColorIterator &citerator,
 issue_color_gl(const Geom *geom, Geom::ColorIterator &citerator,
                GraphicsStateGuardianBase *) {
                GraphicsStateGuardianBase *) {
   const Colorf &color = geom->get_next_color(citerator);
   const Colorf &color = geom->get_next_color(citerator);
-  //  glgsg_cat.debug() << "Issuing color " << color << "\n";
+  //  glgsg_cat.spam() << "Issuing color " << color << "\n";
   glColor4fv(color.get_data());
   glColor4fv(color.get_data());
 }
 }
 
 
@@ -122,6 +122,41 @@ issue_transformed_color_gl(const Geom *geom, Geom::ColorIterator &citerator,
   glgsg->issue_transformed_color(color);
   glgsg->issue_transformed_color(color);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::uchar_bgr_to_rgb
+//  Description: Recopies the given array of pixels, converting from
+//               BGR to RGB arrangement.
+////////////////////////////////////////////////////////////////////
+static void
+uchar_bgr_to_rgb(unsigned char *dest, const unsigned char *source, 
+                 int num_pixels) {
+  for (int i = 0; i < num_pixels; i++) {
+    dest[0] = source[2];
+    dest[1] = source[1];
+    dest[2] = source[0];
+    dest += 3;
+    source += 3;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::uchar_bgra_to_rgba
+//  Description: Recopies the given array of pixels, converting from
+//               BGRA to RGBA arrangement.
+////////////////////////////////////////////////////////////////////
+static void
+uchar_bgra_to_rgba(unsigned char *dest, const unsigned char *source, 
+                   int num_pixels) {
+  for (int i = 0; i < num_pixels; i++) {
+    dest[0] = source[2];
+    dest[1] = source[1];
+    dest[2] = source[0];
+    dest[3] = source[3];
+    dest += 4;
+    source += 4;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::Constructor
 //     Function: GLGraphicsStateGuardian::Constructor
 //       Access: Public
 //       Access: Public
@@ -360,20 +395,20 @@ do_clear(const RenderBuffer &buffer) {
   }
   }
 
 
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "glClear(";
+  glgsg_cat.spam() << "glClear(";
   if (mask & GL_COLOR_BUFFER_BIT) {
   if (mask & GL_COLOR_BUFFER_BIT) {
-    glgsg_cat.debug(false) << "GL_COLOR_BUFFER_BIT|";
+    glgsg_cat.spam(false) << "GL_COLOR_BUFFER_BIT|";
   }
   }
   if (mask & GL_DEPTH_BUFFER_BIT) {
   if (mask & GL_DEPTH_BUFFER_BIT) {
-    glgsg_cat.debug(false) << "GL_DEPTH_BUFFER_BIT|";
+    glgsg_cat.spam(false) << "GL_DEPTH_BUFFER_BIT|";
   }
   }
   if (mask & GL_STENCIL_BUFFER_BIT) {
   if (mask & GL_STENCIL_BUFFER_BIT) {
-    glgsg_cat.debug(false) << "GL_STENCIL_BUFFER_BIT|";
+    glgsg_cat.spam(false) << "GL_STENCIL_BUFFER_BIT|";
   }
   }
   if (mask & GL_ACCUM_BUFFER_BIT) {
   if (mask & GL_ACCUM_BUFFER_BIT) {
-    glgsg_cat.debug(false) << "GL_ACCUM_BUFFER_BIT|";
+    glgsg_cat.spam(false) << "GL_ACCUM_BUFFER_BIT|";
   }
   }
-  glgsg_cat.debug(false) << ")" << endl;
+  glgsg_cat.spam(false) << ")" << endl;
 #endif
 #endif
 
 
   modify_state(state);
   modify_state(state);
@@ -449,7 +484,7 @@ prepare_lens() {
     projection_mat;
     projection_mat;
 
 
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glMatrixMode(GL_PROJECTION): " << new_projection_mat << endl;
     << "glMatrixMode(GL_PROJECTION): " << new_projection_mat << endl;
 #endif
 #endif
   glMatrixMode(GL_PROJECTION);
   glMatrixMode(GL_PROJECTION);
@@ -503,7 +538,7 @@ end_frame() {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_point(GeomPoint *geom, GeomContext *) {
 draw_point(GeomPoint *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_point()" << endl;
+  glgsg_cat.spam() << "draw_point()" << endl;
 #endif
 #endif
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
   PStatTimer timer(_draw_primitive_pcollector);
   PStatTimer timer(_draw_primitive_pcollector);
@@ -563,7 +598,7 @@ draw_point(GeomPoint *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_line(GeomLine *geom, GeomContext *) {
 draw_line(GeomLine *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_line()" << endl;
+  glgsg_cat.spam() << "draw_line()" << endl;
 #endif
 #endif
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
   PStatTimer timer(_draw_primitive_pcollector);
   PStatTimer timer(_draw_primitive_pcollector);
@@ -634,7 +669,7 @@ draw_line(GeomLine *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_linestrip(GeomLinestrip *geom, GeomContext *) {
 draw_linestrip(GeomLinestrip *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_linestrip()" << endl;
+  glgsg_cat.spam() << "draw_linestrip()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -764,7 +799,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) {
   // by hand and apply the inverse frustum to the transformed point.
   // by hand and apply the inverse frustum to the transformed point.
   // For some cracked out reason, this actually works.
   // For some cracked out reason, this actually works.
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_sprite()" << endl;
+  glgsg_cat.spam() << "draw_sprite()" << endl;
 #endif
 #endif
 
 
   // get the array traversal set up.
   // get the array traversal set up.
@@ -1005,7 +1040,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_polygon(GeomPolygon *geom, GeomContext *) {
 draw_polygon(GeomPolygon *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_polygon()" << endl;
+  glgsg_cat.spam() << "draw_polygon()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1084,7 +1119,7 @@ draw_polygon(GeomPolygon *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_tri(GeomTri *geom, GeomContext *) {
 draw_tri(GeomTri *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_tri()" << endl;
+  glgsg_cat.spam() << "draw_tri()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1160,7 +1195,7 @@ draw_tri(GeomTri *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_quad(GeomQuad *geom, GeomContext *) {
 draw_quad(GeomQuad *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_quad()" << endl;
+  glgsg_cat.spam() << "draw_quad()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1234,7 +1269,7 @@ draw_quad(GeomQuad *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_tristrip(GeomTristrip *geom, GeomContext *) {
 draw_tristrip(GeomTristrip *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_tristrip()" << endl;
+  glgsg_cat.spam() << "draw_tristrip()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1330,7 +1365,7 @@ draw_tristrip(GeomTristrip *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_trifan(GeomTrifan *geom, GeomContext *) {
 draw_trifan(GeomTrifan *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_trifan()" << endl;
+  glgsg_cat.spam() << "draw_trifan()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1427,7 +1462,7 @@ draw_trifan(GeomTrifan *geom, GeomContext *) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 draw_sphere(GeomSphere *geom, GeomContext *) {
 draw_sphere(GeomSphere *geom, GeomContext *) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug() << "draw_sphere()" << endl;
+  glgsg_cat.spam() << "draw_sphere()" << endl;
 #endif
 #endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
@@ -1918,12 +1953,14 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
   int xo, yo, w, h;
   int xo, yo, w, h;
   dr->get_region_pixels(xo, yo, w, h);
   dr->get_region_pixels(xo, yo, w, h);
 
 
+  GLenum external_format = get_external_image_format(pb->get_format());
+
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
   glgsg_cat.debug()
   glgsg_cat.debug()
     << "glReadPixels(" << pb->get_xorg() << ", " << pb->get_yorg()
     << "glReadPixels(" << pb->get_xorg() << ", " << pb->get_yorg()
     << ", " << pb->get_xsize() << ", " << pb->get_ysize()
     << ", " << pb->get_xsize() << ", " << pb->get_ysize()
     << ", ";
     << ", ";
-  switch (get_external_image_format(pb->get_format())) {
+  switch (external_format) {
   case GL_DEPTH_COMPONENT:
   case GL_DEPTH_COMPONENT:
     glgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, ";
     glgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, ";
     break;
     break;
@@ -1965,10 +2002,23 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
   nassertv(!pb->_image.empty());
   nassertv(!pb->_image.empty());
   glReadPixels(pb->get_xorg() + xo, pb->get_yorg() + yo,
   glReadPixels(pb->get_xorg() + xo, pb->get_yorg() + yo,
                pb->get_xsize(), pb->get_ysize(),
                pb->get_xsize(), pb->get_ysize(),
-               get_external_image_format(pb->get_format()),
+               external_format,
                get_image_type(pb->get_image_type()),
                get_image_type(pb->get_image_type()),
                pb->_image.p());
                pb->_image.p());
 
 
+  // We may have to reverse the byte ordering of the image if GL
+  // didn't do it for us.
+  if (external_format == GL_RGB && pb->get_image_type() == PixelBuffer::T_unsigned_byte) {
+    PTA_uchar new_image = PTA_uchar::empty_array(pb->_image.size());
+    uchar_bgr_to_rgb(new_image, pb->_image, pb->_image.size() / 3);
+    pb->_image = new_image;
+
+  } else if (external_format == GL_RGBA && pb->get_image_type() == PixelBuffer::T_unsigned_byte) {
+    PTA_uchar new_image = PTA_uchar::empty_array(pb->_image.size());
+    uchar_bgra_to_rgba(new_image, pb->_image, pb->_image.size() / 4);
+    pb->_image = new_image;
+  }
+
   report_gl_errors();
   report_gl_errors();
 }
 }
 
 
@@ -2063,7 +2113,7 @@ apply_fog(Fog *fog) {
 void GLGraphicsStateGuardian::
 void GLGraphicsStateGuardian::
 issue_transform(const TransformState *transform) {
 issue_transform(const TransformState *transform) {
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glLoadMatrix(GL_MODELVIEW): " << transform->get_mat() << endl;
     << "glLoadMatrix(GL_MODELVIEW): " << transform->get_mat() << endl;
 #endif
 #endif
   glMatrixMode(GL_MODELVIEW);
   glMatrixMode(GL_MODELVIEW);
@@ -2640,7 +2690,7 @@ bind_texture(TextureContext *tc) {
 
 
 #ifdef GSG_VERBOSE
 #ifdef GSG_VERBOSE
   Texture *tex = tc->_texture;
   Texture *tex = tc->_texture;
-  glgsg_cat.debug()
+  glgsg_cat.spam()
     << "glBindTexture(): " << tex->get_name() << "(" << (int)gtc->_index
     << "glBindTexture(): " << tex->get_name() << "(" << (int)gtc->_index
     << ")" << endl;
     << ")" << endl;
 #endif
 #endif
@@ -2742,41 +2792,6 @@ compute_gl_image_size(int xsize, int ysize, int external_format, int type) {
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::uchar_bgr_to_rgb
-//  Description: Recopies the given array of pixels, converting from
-//               BGR to RGB arrangement.
-////////////////////////////////////////////////////////////////////
-static void
-uchar_bgr_to_rgb(unsigned char *dest, const unsigned char *source, 
-                 int num_pixels) {
-  for (int i = 0; i < num_pixels; i++) {
-    dest[0] = source[2];
-    dest[1] = source[1];
-    dest[2] = source[0];
-    dest += 3;
-    source += 3;
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: GLGraphicsStateGuardian::uchar_bgra_to_rgba
-//  Description: Recopies the given array of pixels, converting from
-//               BGRA to RGBA arrangement.
-////////////////////////////////////////////////////////////////////
-static void
-uchar_bgra_to_rgba(unsigned char *dest, const unsigned char *source, 
-                   int num_pixels) {
-  for (int i = 0; i < num_pixels; i++) {
-    dest[0] = source[2];
-    dest[1] = source[1];
-    dest[2] = source[0];
-    dest[3] = source[3];
-    dest += 4;
-    source += 4;
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GLGraphicsStateGuardian::apply_texture_immediate
 //     Function: GLGraphicsStateGuardian::apply_texture_immediate
 //       Access: Protected
 //       Access: Protected
@@ -4001,7 +4016,6 @@ dump_state(void)
       dump << "\t\t" << "GL_LIGHTING " << _lighting_enabled << " " << (bool)glIsEnabled(GL_LIGHTING) << "\n";
       dump << "\t\t" << "GL_LIGHTING " << _lighting_enabled << " " << (bool)glIsEnabled(GL_LIGHTING) << "\n";
       dump << "\t\t" << "GL_SCISSOR_TEST " << _scissor_enabled << " " << (bool)glIsEnabled(GL_SCISSOR_TEST) << "\n";
       dump << "\t\t" << "GL_SCISSOR_TEST " << _scissor_enabled << " " << (bool)glIsEnabled(GL_SCISSOR_TEST) << "\n";
       dump << "\t\t" << "GL_TEXTURE_2D " << _texturing_enabled << " " << (bool)glIsEnabled(GL_TEXTURE_2D) << "\n";
       dump << "\t\t" << "GL_TEXTURE_2D " << _texturing_enabled << " " << (bool)glIsEnabled(GL_TEXTURE_2D) << "\n";
-      dump << "\t\t" << "GL_DITHER " << _dither_enabled << " " << (bool)glIsEnabled(GL_DITHER) << "\n";
       dump << "\t\t" << "GL_STENCIL_TEST " << " " << (bool)glIsEnabled(GL_STENCIL_TEST) << "\n";
       dump << "\t\t" << "GL_STENCIL_TEST " << " " << (bool)glIsEnabled(GL_STENCIL_TEST) << "\n";
       dump << "\t\t" << "GL_BLEND " << _blend_enabled << " " << (bool)glIsEnabled(GL_BLEND) << "\n";
       dump << "\t\t" << "GL_BLEND " << _blend_enabled << " " << (bool)glIsEnabled(GL_BLEND) << "\n";
       dump << "\t\t" << "GL_DEPTH_TEST " << _depth_test_enabled << " " << (bool)glIsEnabled(GL_DEPTH_TEST) << "\n";
       dump << "\t\t" << "GL_DEPTH_TEST " << _depth_test_enabled << " " << (bool)glIsEnabled(GL_DEPTH_TEST) << "\n";