diff --git a/panda/src/glgsg/glGraphicsStateGuardian.I b/panda/src/glgsg/glGraphicsStateGuardian.I index 93bad23f74..b107358900 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.I +++ b/panda/src/glgsg/glGraphicsStateGuardian.I @@ -69,7 +69,7 @@ INLINE void GLGraphicsStateGuardian:: call_glClearDepth(GLclampd depth) { if (depth != _clear_depth) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glClearDepth(" << (double)depth << ")" << endl; #endif glClearDepth(depth); @@ -120,37 +120,37 @@ INLINE void GLGraphicsStateGuardian:: call_glDrawBuffer(GLenum mode) { if (mode != _draw_buffer_mode) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glDrawBuffer("; + glgsg_cat.spam() << "glDrawBuffer("; switch (mode) { case GL_FRONT: - glgsg_cat.debug(false) << "GL_FRONT)"; + glgsg_cat.spam(false) << "GL_FRONT)"; break; case GL_BACK: - glgsg_cat.debug(false) << "GL_BACK)"; + glgsg_cat.spam(false) << "GL_BACK)"; break; case GL_RIGHT: - glgsg_cat.debug(false) << "GL_RIGHT)"; + glgsg_cat.spam(false) << "GL_RIGHT)"; break; case GL_LEFT: - glgsg_cat.debug(false) << "GL_LEFT)"; + glgsg_cat.spam(false) << "GL_LEFT)"; break; case GL_FRONT_RIGHT: - glgsg_cat.debug(false) << "GL_FRONT_RIGHT)"; + glgsg_cat.spam(false) << "GL_FRONT_RIGHT)"; break; case GL_FRONT_LEFT: - glgsg_cat.debug(false) << "GL_FRONT_LEFT)"; + glgsg_cat.spam(false) << "GL_FRONT_LEFT)"; break; case GL_BACK_RIGHT: - glgsg_cat.debug(false) << "GL_BACK_RIGHT)"; + glgsg_cat.spam(false) << "GL_BACK_RIGHT)"; break; case GL_BACK_LEFT: - glgsg_cat.debug(false) << "GL_BACK_LEFT)"; + glgsg_cat.spam(false) << "GL_BACK_LEFT)"; break; case GL_FRONT_AND_BACK: - glgsg_cat.debug(false) << "GL_FRONT_AND_BACK)"; + glgsg_cat.spam(false) << "GL_FRONT_AND_BACK)"; break; } - glgsg_cat.debug(false) << endl; + glgsg_cat.spam(false) << endl; #endif glDrawBuffer(mode); _draw_buffer_mode = mode; @@ -244,7 +244,7 @@ call_glLightModelTwoSide(GLboolean twoside) if (_lmodel_twoside != twoside) { _lmodel_twoside = twoside; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glLightModel(GL_LIGHT_MODEL_TWO_SIDE, " << (int)twoside << ")" << endl; #endif glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, twoside); @@ -260,37 +260,37 @@ INLINE void GLGraphicsStateGuardian:: call_glStencilFunc(GLenum func,GLint ref,GLuint mask) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glStencilFunc("; + glgsg_cat.spam() << "glStencilFunc("; switch (func) { case GL_NEVER: - glgsg_cat.debug(false) << "GL_NEVER, "; + glgsg_cat.spam(false) << "GL_NEVER, "; break; case GL_LESS: - glgsg_cat.debug(false) << "GL_LESS, "; + glgsg_cat.spam(false) << "GL_LESS, "; break; case GL_EQUAL: - glgsg_cat.debug(false) << "GL_EQUAL, "; + glgsg_cat.spam(false) << "GL_EQUAL, "; break; case GL_LEQUAL: - glgsg_cat.debug(false) << "GL_LEQUAL, "; + glgsg_cat.spam(false) << "GL_LEQUAL, "; break; case GL_GREATER: - glgsg_cat.debug(false) << "GL_GREATER, "; + glgsg_cat.spam(false) << "GL_GREATER, "; break; case GL_NOTEQUAL: - glgsg_cat.debug(false) << "GL_NOTEQUAL, "; + glgsg_cat.spam(false) << "GL_NOTEQUAL, "; break; case GL_GEQUAL: - glgsg_cat.debug(false) << "GL_GEQUAL, "; + glgsg_cat.spam(false) << "GL_GEQUAL, "; break; case GL_ALWAYS: - glgsg_cat.debug(false) << "GL_ALWAYS, "; + glgsg_cat.spam(false) << "GL_ALWAYS, "; break; default: - glgsg_cat.debug(false) << "unknown, "; + glgsg_cat.spam(false) << "unknown, "; break; } - glgsg_cat.debug(false) << (int)ref << (unsigned int)mask << ")\n"; + glgsg_cat.spam(false) << (int)ref << (unsigned int)mask << ")\n"; #endif glStencilFunc(func, ref, mask); } @@ -303,31 +303,31 @@ call_glStencilFunc(GLenum func,GLint ref,GLuint mask) { INLINE void GLGraphicsStateGuardian:: call_glStencilOp(GLenum fail,GLenum zfail,GLenum zpass) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glStencilOp(fail, zfail, "; + glgsg_cat.spam() << "glStencilOp(fail, zfail, "; switch (zpass) { case GL_KEEP: - glgsg_cat.debug(false) << "GL_KEEP)"; + glgsg_cat.spam(false) << "GL_KEEP)"; break; case GL_ZERO: - glgsg_cat.debug(false) << "GL_ZERO)"; + glgsg_cat.spam(false) << "GL_ZERO)"; break; case GL_REPLACE: - glgsg_cat.debug(false) << "GL_REPLACE)"; + glgsg_cat.spam(false) << "GL_REPLACE)"; break; case GL_INCR: - glgsg_cat.debug(false) << "GL_INCR)"; + glgsg_cat.spam(false) << "GL_INCR)"; break; case GL_DECR: - glgsg_cat.debug(false) << "GL_DECR)"; + glgsg_cat.spam(false) << "GL_DECR)"; break; case GL_INVERT: - glgsg_cat.debug(false) << "GL_INVERT)"; + glgsg_cat.spam(false) << "GL_INVERT)"; break; default: - glgsg_cat.debug(false) << "unknown)"; + glgsg_cat.spam(false) << "unknown)"; break; } - glgsg_cat.debug(false) << endl; + glgsg_cat.spam(false) << endl; #endif glStencilOp(fail,zfail,zpass); } @@ -342,7 +342,7 @@ call_glLineWidth(GLfloat width) { if (_line_width != width) { _line_width = width; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glLineWidth(" << width << ")" << endl; #endif glLineWidth(width); @@ -359,7 +359,7 @@ call_glPointSize(GLfloat size) { if (_point_size != size) { _point_size = size; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glPointSize(" << size << ")" << endl; #endif glPointSize(size); @@ -377,70 +377,70 @@ call_glBlendFunc(GLenum sfunc, GLenum dfunc) { _blend_source_func = sfunc; _blend_dest_func = dfunc; #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glBlendFunc("; + glgsg_cat.spam() << "glBlendFunc("; switch (sfunc) { case GL_ZERO: - glgsg_cat.debug(false) << "GL_ZERO, "; + glgsg_cat.spam(false) << "GL_ZERO, "; break; case GL_ONE: - glgsg_cat.debug(false) << "GL_ONE, "; + glgsg_cat.spam(false) << "GL_ONE, "; break; case GL_DST_COLOR: - glgsg_cat.debug(false) << "GL_DST_COLOR, "; + glgsg_cat.spam(false) << "GL_DST_COLOR, "; break; 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; case GL_SRC_ALPHA: - glgsg_cat.debug(false) << "GL_SRC_ALPHA, "; + glgsg_cat.spam(false) << "GL_SRC_ALPHA, "; break; 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; case GL_DST_ALPHA: - glgsg_cat.debug(false) << "GL_DST_ALPHA, "; + glgsg_cat.spam(false) << "GL_DST_ALPHA, "; break; 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; case GL_SRC_ALPHA_SATURATE: - glgsg_cat.debug(false) << "GL_SRC_ALPHA_SATURATE, "; + glgsg_cat.spam(false) << "GL_SRC_ALPHA_SATURATE, "; break; default: - glgsg_cat.debug(false) << "unknown, "; + glgsg_cat.spam(false) << "unknown, "; break; } switch (dfunc) { case GL_ZERO: - glgsg_cat.debug(false) << "GL_ZERO)"; + glgsg_cat.spam(false) << "GL_ZERO)"; break; case GL_ONE: - glgsg_cat.debug(false) << "GL_ONE)"; + glgsg_cat.spam(false) << "GL_ONE)"; break; case GL_SRC_COLOR: - glgsg_cat.debug(false) << "GL_SRC_COLOR)"; + glgsg_cat.spam(false) << "GL_SRC_COLOR)"; break; 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; case GL_SRC_ALPHA: - glgsg_cat.debug(false) << "GL_SRC_ALPHA)"; + glgsg_cat.spam(false) << "GL_SRC_ALPHA)"; break; 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; case GL_DST_ALPHA: - glgsg_cat.debug(false) << "GL_DST_ALPHA)"; + glgsg_cat.spam(false) << "GL_DST_ALPHA)"; break; 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; default: - glgsg_cat.debug(false) << "unknown)"; + glgsg_cat.spam(false) << "unknown)"; break; } - glgsg_cat.debug(false) << endl; + glgsg_cat.spam(false) << endl; #endif glBlendFunc(sfunc, dfunc); } @@ -456,24 +456,24 @@ call_glFogMode(GLint mode) { if (_fog_mode != mode) { _fog_mode = mode; #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glFog(GL_FOG_MODE, "; + glgsg_cat.spam() << "glFog(GL_FOG_MODE, "; switch(mode) { case GL_LINEAR: - glgsg_cat.debug(false) << "GL_LINEAR)" << endl; + glgsg_cat.spam(false) << "GL_LINEAR)" << endl; break; case GL_EXP: - glgsg_cat.debug(false) << "GL_EXP)" << endl; + glgsg_cat.spam(false) << "GL_EXP)" << endl; break; case GL_EXP2: - glgsg_cat.debug(false) << "GL_EXP2)" << endl; + glgsg_cat.spam(false) << "GL_EXP2)" << endl; break; #ifdef 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; #endif default: - glgsg_cat.debug(false) << "unknown)" << endl; + glgsg_cat.spam(false) << "unknown)" << endl; break; } #endif @@ -491,7 +491,7 @@ call_glFogStart(GLfloat start) { if (_fog_start != start) { _fog_start = start; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glFog(GL_FOG_START, " << start << ")" << endl; #endif glFogf(GL_FOG_START, start); @@ -508,7 +508,7 @@ call_glFogEnd(GLfloat end) { if (_fog_end != end) { _fog_end = end; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glFog(GL_FOG_END, " << end << ")" << endl; #endif glFogf(GL_FOG_END, end); @@ -525,7 +525,7 @@ call_glFogDensity(GLfloat density) { if (_fog_density != density) { _fog_density = density; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glFog(GL_FOG_DENSITY, " << density << ")" << endl; #endif glFogf(GL_FOG_DENSITY, density); @@ -542,7 +542,7 @@ call_glFogColor(const Colorf &color) { if (_fog_color != color) { _fog_color = color; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glFog(GL_FOG_COLOR, " << color << ")" << endl; #endif glFogfv(GL_FOG_COLOR, color.get_data()); @@ -560,34 +560,34 @@ call_glAlphaFunc(GLenum func, GLclampf ref) { _alpha_func = func; _alpha_func_ref = ref; #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glAlphaFunc("; + glgsg_cat.spam() << "glAlphaFunc("; switch (func) { case GL_NEVER: - glgsg_cat.debug(false) << "GL_NEVER, "; + glgsg_cat.spam(false) << "GL_NEVER, "; break; case GL_LESS: - glgsg_cat.debug(false) << "GL_LESS, "; + glgsg_cat.spam(false) << "GL_LESS, "; break; case GL_EQUAL: - glgsg_cat.debug(false) << "GL_EQUAL, "; + glgsg_cat.spam(false) << "GL_EQUAL, "; break; case GL_LEQUAL: - glgsg_cat.debug(false) << "GL_LEQUAL, "; + glgsg_cat.spam(false) << "GL_LEQUAL, "; break; case GL_GREATER: - glgsg_cat.debug(false) << "GL_GREATER, "; + glgsg_cat.spam(false) << "GL_GREATER, "; break; case GL_NOTEQUAL: - glgsg_cat.debug(false) << "GL_NOTEQUAL, "; + glgsg_cat.spam(false) << "GL_NOTEQUAL, "; break; case GL_GEQUAL: - glgsg_cat.debug(false) << "GL_GEQUAL, "; + glgsg_cat.spam(false) << "GL_GEQUAL, "; break; case GL_ALWAYS: - glgsg_cat.debug(false) << "GL_ALWAYS, "; + glgsg_cat.spam(false) << "GL_ALWAYS, "; break; } - glgsg_cat.debug() << ref << ")" << endl; + glgsg_cat.spam() << ref << ")" << endl; #endif glAlphaFunc(func, ref); } @@ -603,16 +603,16 @@ call_glPolygonMode(GLenum mode) { if (_polygon_mode != mode) { _polygon_mode = mode; #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glPolygonMode(GL_BACK_AND_FRONT, "; + glgsg_cat.spam() << "glPolygonMode(GL_BACK_AND_FRONT, "; switch (mode) { case GL_POINT: - glgsg_cat.debug(false) << "GL_POINT)" << endl; + glgsg_cat.spam(false) << "GL_POINT)" << endl; break; case GL_LINE: - glgsg_cat.debug(false) << "GL_LINE)" << endl; + glgsg_cat.spam(false) << "GL_LINE)" << endl; break; case GL_FILL: - glgsg_cat.debug(false) << "GL_FILL)" << endl; + glgsg_cat.spam(false) << "GL_FILL)" << endl; break; } #endif @@ -717,13 +717,13 @@ enable_stencil_test(bool val) { _stencil_test_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_STENCIL_TEST)" << endl; #endif glEnable(GL_STENCIL_TEST); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_STENCIL_TEST)" << endl; #endif glDisable(GL_STENCIL_TEST); @@ -742,13 +742,13 @@ enable_texturing(bool val) { _texturing_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_TEXTURE_2D)" << endl; #endif glEnable(GL_TEXTURE_2D); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_TEXTURE_2D)" << endl; #endif glDisable(GL_TEXTURE_2D); @@ -785,13 +785,13 @@ enable_multisample_alpha_one(bool val) { #ifdef GL_SAMPLE_ALPHA_TO_ONE_SGIS if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl; #endif glEnable(GL_SAMPLE_ALPHA_TO_ONE_SGIS); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS)" << endl; #endif glDisable(GL_SAMPLE_ALPHA_TO_ONE_SGIS); @@ -812,13 +812,13 @@ enable_multisample_alpha_mask(bool val) { #ifdef GL_SAMPLE_ALPHA_TO_MASK_SGIS if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl; #endif glEnable(GL_SAMPLE_ALPHA_TO_MASK_SGIS); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS)" << endl; #endif glDisable(GL_SAMPLE_ALPHA_TO_MASK_SGIS); @@ -838,13 +838,13 @@ enable_blend(bool val) { _blend_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_BLEND)" << endl; #endif glEnable(GL_BLEND); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_BLEND)" << endl; #endif glDisable(GL_BLEND); @@ -863,13 +863,13 @@ enable_depth_test(bool val) { _depth_test_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_DEPTH_TEST)" << endl; #endif glEnable(GL_DEPTH_TEST); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_DEPTH_TEST)" << endl; #endif glDisable(GL_DEPTH_TEST); @@ -888,13 +888,13 @@ enable_fog(bool val) { _fog_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_FOG)" << endl; #endif glEnable(GL_FOG); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_FOG)" << endl; #endif glDisable(GL_FOG); @@ -913,13 +913,13 @@ enable_alpha_test(bool val) { _alpha_test_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_ALPHA_TEST)" << endl; #endif glEnable(GL_ALPHA_TEST); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_ALPHA_TEST)" << endl; #endif glDisable(GL_ALPHA_TEST); @@ -939,13 +939,13 @@ enable_polygon_offset(bool val) { _polygon_offset_enabled = val; if (val) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glEnable(GL_POLYGON_OFFSET_*)" << endl; #endif glEnable(GL_POLYGON_OFFSET_FILL); } else { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glDisable(GL_POLYGON_OFFSET_*)" << endl; #endif glDisable(GL_POLYGON_OFFSET_FILL); diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index c987576c3a..f49c1a10c7 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -86,7 +86,7 @@ static void issue_vertex_gl(const Geom *geom, Geom::VertexIterator &viterator, GraphicsStateGuardianBase *) { 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()); } @@ -94,7 +94,7 @@ static void issue_normal_gl(const Geom *geom, Geom::NormalIterator &niterator, GraphicsStateGuardianBase *) { 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()); } @@ -102,7 +102,7 @@ static void issue_texcoord_gl(const Geom *geom, Geom::TexCoordIterator &tciterator, GraphicsStateGuardianBase *) { 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()); } @@ -110,7 +110,7 @@ static void issue_color_gl(const Geom *geom, Geom::ColorIterator &citerator, GraphicsStateGuardianBase *) { 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()); } @@ -122,6 +122,41 @@ issue_transformed_color_gl(const Geom *geom, Geom::ColorIterator &citerator, 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 // Access: Public @@ -360,20 +395,20 @@ do_clear(const RenderBuffer &buffer) { } #ifdef GSG_VERBOSE - glgsg_cat.debug() << "glClear("; + glgsg_cat.spam() << "glClear("; 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) { - glgsg_cat.debug(false) << "GL_DEPTH_BUFFER_BIT|"; + glgsg_cat.spam(false) << "GL_DEPTH_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) { - 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 modify_state(state); @@ -449,7 +484,7 @@ prepare_lens() { projection_mat; #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glMatrixMode(GL_PROJECTION): " << new_projection_mat << endl; #endif glMatrixMode(GL_PROJECTION); @@ -503,7 +538,7 @@ end_frame() { void GLGraphicsStateGuardian:: draw_point(GeomPoint *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_point()" << endl; + glgsg_cat.spam() << "draw_point()" << endl; #endif #ifdef DO_PSTATS PStatTimer timer(_draw_primitive_pcollector); @@ -563,7 +598,7 @@ draw_point(GeomPoint *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_line(GeomLine *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_line()" << endl; + glgsg_cat.spam() << "draw_line()" << endl; #endif #ifdef DO_PSTATS PStatTimer timer(_draw_primitive_pcollector); @@ -634,7 +669,7 @@ draw_line(GeomLine *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_linestrip(GeomLinestrip *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_linestrip()" << endl; + glgsg_cat.spam() << "draw_linestrip()" << endl; #endif #ifdef DO_PSTATS @@ -764,7 +799,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) { // by hand and apply the inverse frustum to the transformed point. // For some cracked out reason, this actually works. #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_sprite()" << endl; + glgsg_cat.spam() << "draw_sprite()" << endl; #endif // get the array traversal set up. @@ -1005,7 +1040,7 @@ draw_sprite(GeomSprite *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_polygon(GeomPolygon *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_polygon()" << endl; + glgsg_cat.spam() << "draw_polygon()" << endl; #endif #ifdef DO_PSTATS @@ -1084,7 +1119,7 @@ draw_polygon(GeomPolygon *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_tri(GeomTri *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_tri()" << endl; + glgsg_cat.spam() << "draw_tri()" << endl; #endif #ifdef DO_PSTATS @@ -1160,7 +1195,7 @@ draw_tri(GeomTri *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_quad(GeomQuad *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_quad()" << endl; + glgsg_cat.spam() << "draw_quad()" << endl; #endif #ifdef DO_PSTATS @@ -1234,7 +1269,7 @@ draw_quad(GeomQuad *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_tristrip(GeomTristrip *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_tristrip()" << endl; + glgsg_cat.spam() << "draw_tristrip()" << endl; #endif #ifdef DO_PSTATS @@ -1330,7 +1365,7 @@ draw_tristrip(GeomTristrip *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_trifan(GeomTrifan *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_trifan()" << endl; + glgsg_cat.spam() << "draw_trifan()" << endl; #endif #ifdef DO_PSTATS @@ -1427,7 +1462,7 @@ draw_trifan(GeomTrifan *geom, GeomContext *) { void GLGraphicsStateGuardian:: draw_sphere(GeomSphere *geom, GeomContext *) { #ifdef GSG_VERBOSE - glgsg_cat.debug() << "draw_sphere()" << endl; + glgsg_cat.spam() << "draw_sphere()" << endl; #endif #ifdef DO_PSTATS @@ -1918,12 +1953,14 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { int 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 glgsg_cat.debug() << "glReadPixels(" << pb->get_xorg() << ", " << pb->get_yorg() << ", " << pb->get_xsize() << ", " << pb->get_ysize() << ", "; - switch (get_external_image_format(pb->get_format())) { + switch (external_format) { case GL_DEPTH_COMPONENT: glgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; break; @@ -1965,10 +2002,23 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { nassertv(!pb->_image.empty()); glReadPixels(pb->get_xorg() + xo, pb->get_yorg() + yo, pb->get_xsize(), pb->get_ysize(), - get_external_image_format(pb->get_format()), + external_format, get_image_type(pb->get_image_type()), 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(); } @@ -2063,7 +2113,7 @@ apply_fog(Fog *fog) { void GLGraphicsStateGuardian:: issue_transform(const TransformState *transform) { #ifdef GSG_VERBOSE - glgsg_cat.debug() + glgsg_cat.spam() << "glLoadMatrix(GL_MODELVIEW): " << transform->get_mat() << endl; #endif glMatrixMode(GL_MODELVIEW); @@ -2640,7 +2690,7 @@ bind_texture(TextureContext *tc) { #ifdef GSG_VERBOSE Texture *tex = tc->_texture; - glgsg_cat.debug() + glgsg_cat.spam() << "glBindTexture(): " << tex->get_name() << "(" << (int)gtc->_index << ")" << endl; #endif @@ -2742,41 +2792,6 @@ compute_gl_image_size(int xsize, int ysize, int external_format, int type) { } #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 // 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_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_DITHER " << _dither_enabled << " " << (bool)glIsEnabled(GL_DITHER) << "\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_DEPTH_TEST " << _depth_test_enabled << " " << (bool)glIsEnabled(GL_DEPTH_TEST) << "\n";