summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>1999-09-14 00:30:28 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>1999-09-14 00:30:28 +0000
commitde37ce3e22ad33cae84c8aa461a12660625297b5 (patch)
treeffa3b804f95f1ed2799dc5f43b14b6b5e57e1b51
parenta96e8ad9788c5c4aa2ff62b87d9e3f86be21513d (diff)
fixed pixel packing/unpacking code in gluBuild2DMipmaps()
-rw-r--r--src/glu/mesa/mipmap.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/glu/mesa/mipmap.c b/src/glu/mesa/mipmap.c
index 24af0ba33c..63246f3958 100644
--- a/src/glu/mesa/mipmap.c
+++ b/src/glu/mesa/mipmap.c
@@ -1,4 +1,4 @@
-/* $Id: mipmap.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */
+/* $Id: mipmap.c,v 1.2 1999/09/14 00:30:28 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -23,8 +23,11 @@
/*
* $Log: mipmap.c,v $
- * Revision 1.1 1999/08/19 00:55:42 jtg
- * Initial revision
+ * Revision 1.2 1999/09/14 00:30:28 brianp
+ * fixed pixel packing/unpacking code in gluBuild2DMipmaps()
+ *
+ * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
+ * Imported sources
*
* Revision 1.13 1999/03/05 17:49:06 brianp
* added support for GL_EXT_abgr (devernay@istar.fr)
@@ -715,6 +718,10 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
void *image, *newimage;
GLint neww, newh, level, bpp;
int error;
+ GLboolean done;
+ GLint retval = 0;
+ GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels;
+ GLint packrowlength, packalignment, packskiprows, packskippixels;
if (width < 1 || height < 1)
return GLU_INVALID_VALUE;
@@ -736,6 +743,24 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
return GLU_INVALID_ENUM;
}
+ /* Get current glPixelStore values */
+ glGetIntegerv( GL_UNPACK_ROW_LENGTH, &unpackrowlength );
+ glGetIntegerv( GL_UNPACK_ALIGNMENT, &unpackalignment );
+ glGetIntegerv( GL_UNPACK_SKIP_ROWS, &unpackskiprows );
+ glGetIntegerv( GL_UNPACK_SKIP_PIXELS, &unpackskippixels );
+ glGetIntegerv( GL_PACK_ROW_LENGTH, &packrowlength );
+ glGetIntegerv( GL_PACK_ALIGNMENT, &packalignment );
+ glGetIntegerv( GL_PACK_SKIP_ROWS, &packskiprows );
+ glGetIntegerv( GL_PACK_SKIP_PIXELS, &packskippixels );
+
+ /* set pixel packing */
+ glPixelStorei( GL_PACK_ROW_LENGTH, 0 );
+ glPixelStorei( GL_PACK_ALIGNMENT, 1 );
+ glPixelStorei( GL_PACK_SKIP_ROWS, 0 );
+ glPixelStorei( GL_PACK_SKIP_PIXELS, 0 );
+
+ done = GL_FALSE;
+
if (w!=width || h!=height) {
/* must rescale image to get "top" mipmap texture image */
image = malloc( (w+4) * h * bpp );
@@ -745,7 +770,8 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
error = gluScaleImage( format, width, height, type, data,
w, h, type, image );
if (error) {
- return error;
+ retval = error;
+ done = GL_TRUE;
}
}
else {
@@ -753,7 +779,15 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
}
level = 0;
- while (1) {
+ while (!done) {
+ if (image != data) {
+ /* set pixel unpacking */
+ glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+ glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
+ glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
+ }
+
glTexImage2D( target, level, components, w, h, 0, format, type, image );
if (w==1 && h==1) break;
@@ -768,7 +802,8 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
error = gluScaleImage( format, w, h, type, image,
neww, newh, type, newimage );
if (error) {
- return error;
+ retval = error;
+ done = GL_TRUE;
}
if (image!=data) {
@@ -785,6 +820,16 @@ GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
free( image );
}
- return 0;
+ /* Restore original glPixelStore state */
+ glPixelStorei( GL_UNPACK_ROW_LENGTH, unpackrowlength );
+ glPixelStorei( GL_UNPACK_ALIGNMENT, unpackalignment );
+ glPixelStorei( GL_UNPACK_SKIP_ROWS, unpackskiprows );
+ glPixelStorei( GL_UNPACK_SKIP_PIXELS, unpackskippixels );
+ glPixelStorei( GL_PACK_ROW_LENGTH, packrowlength );
+ glPixelStorei( GL_PACK_ALIGNMENT, packalignment );
+ glPixelStorei( GL_PACK_SKIP_ROWS, packskiprows );
+ glPixelStorei( GL_PACK_SKIP_PIXELS, packskippixels );
+
+ return retval;
}