Package: mesa
Severity: normal

The following combination leads to a black border on the right hand side 
of the viewport which is wrong:
- glPixelZoom(1.0f, -1.0f)
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
- glDrawPixels with format GL_LUMINANCE

Any other combination or slightly different pixel zoom values work as 
expected. A sample program demonstrating the behaviour is attached.
Compile as follows: gcc -lglut mesa_bug.c -o mesa_bug

Note that the bug happens in both, accelerated (DRI) and non-accelerated 
modes and with different graphics drivers (Radeon 7500 & Matrox G550).

-- System Information:
Debian Release: 4.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
// demonstrates bug in Mesa where a black border appears on the right hand
// side of the window.
// Compile with:
//
// gcc -lglut mesa_bug.c -o mesa_bug
//

#include <stdlib.h> // for malloc
#include <GL/glut.h>

#define WIDTH 150
#define HEIGHT 150

unsigned char *pixels;

void reshapeFunc(int w, int h)
{
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0f, w, h, 0.0f, 0.0f, 1.0f);
	glMatrixMode(GL_MODELVIEW);
}

static void dispOpts(int align, int format, float zoomY)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glPixelZoom(1.0f, zoomY);
	glPixelStorei(GL_UNPACK_ALIGNMENT, align);
	glRasterPos2i(0, 0);
	glDrawPixels(WIDTH, HEIGHT, format, GL_UNSIGNED_BYTE, pixels);
	glutSwapBuffers();
}

// This combination exposes the bug
// (Unpack alignment 1, format Luminance, vertical pixel zoom -1.0f)
void dispFunc1(void)
{
	dispOpts(1, GL_LUMINANCE, -1.0f);
}

// Other format: works
void dispFunc2(void)
{
	dispOpts(1, GL_RED, -1.0f);
}

// Other pixel zoom value: works
void dispFunc3(void)
{
	dispOpts(1, GL_LUMINANCE, -1.0001f);
}

// Other alignment value: works
void dispFunc4(void)
{
	dispOpts(2, GL_LUMINANCE, -1.0f);
}


int main(int argc, char** argv)
{
	int i, j;
	unsigned char *ptr;

	glutInit(&argc, argv);

	pixels = (unsigned char *)malloc(WIDTH*HEIGHT);
	ptr = pixels;

	// create a simple gradient
	for (i=0; i < HEIGHT; i++)
		for (j=0; j < WIDTH; j++)
			*(ptr++) = j;

	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowSize(WIDTH, HEIGHT);

	// Window 1
	glutInitWindowPosition(100, 100);
	glutCreateWindow("BUG");
	glutDisplayFunc(dispFunc1);
	glutReshapeFunc(reshapeFunc);

	// Window 2
	glutInitWindowPosition(200+WIDTH, 100);
	glutCreateWindow("WORKS");
	glutDisplayFunc(dispFunc2);
	glutReshapeFunc(reshapeFunc);

	// Window 3
	glutInitWindowPosition(100, 200+HEIGHT);
	glutCreateWindow("WORKS");
	glutDisplayFunc(dispFunc3);
	glutReshapeFunc(reshapeFunc);

	// Window 4
	glutInitWindowPosition(200+WIDTH, 200+HEIGHT);
	glutCreateWindow("WORKS");
	glutDisplayFunc(dispFunc4);
	glutReshapeFunc(reshapeFunc);

	glutMainLoop();

	return 0;
}

Reply via email to