Greg McGarragh wrote:
Hello,

I think I found two bugs in src/glu/sgi/libutil/mipmap.c.  They are
actually two bugs that show up in several places.  I've attached a patch
that fixes them.  I realize that the GLU used in Mesa is from SGI so I
am not sure if reporting the bug on this list is appropriate.  If not
could somebody please tell me where to report it.

Reporting it here is fine. I've send GLU fixes upstream to SGI in the past but they seem to go into a black hole.


The first bug emerges when calling gluBuild2DMipmaps when the texture
dimensions are both powers of two and GL_UNPACK_ROW_LENGTH is larger
than the width of the input image (as would be the case if one is
building a texture from a subimage of a larger image).  The problem is
in the halveImage_*() functions where the pointer 't' is not properly
positioned to the beginning of each row before looping over the pixels
in a row.  Interestingly this is handled correctly in the functions
halve1Dimage_*(), halveImageSlice(), and halveImage3D().

The second bug emerges when calling gluBuild3DMipmaps when the texture
dimensions are all powers of two and GL_PACK_IMAGE_HEIGHT is larger than
the height of the input image.  The problem is in halveImageSlice() and
halveImage3D() where the pointer 't' is not properly positioned to the
beginning of each image before looping over the rows in an image.

I think there's at least one more bug. The attached test program builds a 256x256 texture image within a 500x500 image buffer. The row stride seems to be miscomputed.

Could you look into fixing that too? Otherwise, I probably can in a day or two.

-Brian
/* Test glPixelStore unpack params with gluBuild2DMipmaps */


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>

static int Win;


static void
Draw(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glPushMatrix();

   glBegin( GL_POLYGON );
   glTexCoord2f( 0.0, 0.0 );   glVertex2f( -1.0, -1.0 );
   glTexCoord2f( 1.0, 0.0 );   glVertex2f(  1.0, -1.0 );
   glTexCoord2f( 1.0, 1.0 );   glVertex2f(  1.0,  1.0 );
   glTexCoord2f( 0.0, 1.0 );   glVertex2f( -1.0,  1.0 );
   glEnd();

   glPopMatrix();

   glutSwapBuffers();
}


static void
Reshape(int width, int height)
{
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(-1.2, 1.2, -1.2, 1.2, 5, 25);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0, 0.0, -15.0);
}


static void
Key(unsigned char key, int x, int y)
{
   (void) x;
   (void) y;
   switch (key) {
      case 27:
         glutDestroyWindow(Win);
         exit(0);
         break;
   }
   glutPostRedisplay();
}


#define MIPMAP 1

static void
Init(void)
{
   const int skipRows = 20, skipPixels = 12;
   GLushort image[500][500][4];
   int i, j;

   /* 256x256 image inside 500x500 buffer at skipPixels, skipRows offset */
   for (i = 0; i < 256; i++) {
      for (j = 0; j < 256; j++) {
         image[i+skipRows][j+skipPixels][0] = (i << 8) | i;
         image[i+skipRows][j+skipPixels][1] = (j << 8) | j;
         image[i+skipRows][j+skipPixels][2] = 0xffff/2;
         image[i+skipRows][j+skipPixels][3] = 0xffff;
      }
   }

   glPixelStorei(GL_UNPACK_ROW_LENGTH, 500);
   glPixelStorei(GL_UNPACK_SKIP_ROWS, skipRows);
   glPixelStorei(GL_UNPACK_SKIP_PIXELS, skipPixels);

#if MIPMAP
   gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 256, 256,
                     GL_RGBA, GL_UNSIGNED_SHORT, image);
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
#else
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,
                GL_RGBA, GL_UNSIGNED_SHORT, image);
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
#endif
   glEnable(GL_TEXTURE_2D);
   glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
}


int
main(int argc, char *argv[])
{
   glutInit(&argc, argv);
   glutInitWindowPosition(0, 0);
   glutInitWindowSize(400, 400);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   Win = glutCreateWindow(argv[0]);
   glutReshapeFunc(Reshape);
   glutKeyboardFunc(Key);
   glutDisplayFunc(Draw);
   Init();
   glutMainLoop();
   return 0;
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to