mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 11:18:08 +02:00
progs/tests: re-indent mipmap_limits.c
This commit is contained in:
parent
9871521b30
commit
c8de476189
1 changed files with 119 additions and 105 deletions
|
|
@ -77,15 +77,16 @@ InitValues(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void MakeImage(int level, int width, int height, const GLubyte color[4])
|
static void
|
||||||
|
MakeImage(int level, int width, int height, const GLubyte color[4])
|
||||||
{
|
{
|
||||||
const int makeStripes = 0;
|
const int makeStripes = 0;
|
||||||
GLubyte img[512*512*3];
|
GLubyte img[512 * 512 * 3];
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < height; i++) {
|
for (i = 0; i < height; i++) {
|
||||||
for (j = 0; j < width; j++) {
|
for (j = 0; j < width; j++) {
|
||||||
int k = (i * width + j) * 3;
|
int k = (i * width + j) * 3;
|
||||||
int p = (i/8) & makeStripes;
|
int p = (i / 8) & makeStripes;
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
img[k + 0] = color[0];
|
img[k + 0] = color[0];
|
||||||
img[k + 1] = color[1];
|
img[k + 1] = color[1];
|
||||||
|
|
@ -104,7 +105,8 @@ static void MakeImage(int level, int width, int height, const GLubyte color[4])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void makeImages(int image)
|
static void
|
||||||
|
makeImages(int image)
|
||||||
{
|
{
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
|
|
@ -121,19 +123,20 @@ static void makeImages(int image)
|
||||||
if (width != WIDTH || height != HEIGHT) {
|
if (width != WIDTH || height != HEIGHT) {
|
||||||
GLubyte *newImage = malloc(WIDTH * HEIGHT * 4);
|
GLubyte *newImage = malloc(WIDTH * HEIGHT * 4);
|
||||||
gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image,
|
gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image,
|
||||||
WIDTH, HEIGHT, GL_UNSIGNED_BYTE, newImage);
|
WIDTH, HEIGHT, GL_UNSIGNED_BYTE, newImage);
|
||||||
free(image);
|
free(image);
|
||||||
image = newImage;
|
image = newImage;
|
||||||
}
|
}
|
||||||
printf("Using GL_SGIS_generate_mipmap\n");
|
printf("Using GL_SGIS_generate_mipmap\n");
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, format, WIDTH, HEIGHT, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, format, WIDTH, HEIGHT, 0,
|
||||||
format, GL_UNSIGNED_BYTE, image);
|
format, GL_UNSIGNED_BYTE, image);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
|
||||||
free(image);
|
free(image);
|
||||||
|
|
||||||
/* make sure mipmap was really generated correctly */
|
/* make sure mipmap was really generated correctly */
|
||||||
width = WIDTH; height = HEIGHT;
|
width = WIDTH;
|
||||||
|
height = HEIGHT;
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
GLint w, h;
|
GLint w, h;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
|
||||||
|
|
@ -142,18 +145,19 @@ static void makeImages(int image)
|
||||||
width /= 2;
|
width /= 2;
|
||||||
height /= 2;
|
height /= 2;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
static const GLubyte colors[10][3] = {
|
static const GLubyte colors[10][3] = {
|
||||||
{128, 128, 128 },
|
{128, 128, 128},
|
||||||
{ 0, 255, 255 },
|
{0, 255, 255},
|
||||||
{ 255, 255, 0 },
|
{255, 255, 0},
|
||||||
{ 255, 0, 255 },
|
{255, 0, 255},
|
||||||
{ 255, 0, 0 },
|
{255, 0, 0},
|
||||||
{ 0, 255, 0 },
|
{0, 255, 0},
|
||||||
{ 0, 0, 255 },
|
{0, 0, 255},
|
||||||
{ 0, 255, 255 },
|
{0, 255, 255},
|
||||||
{ 255, 255, 0 },
|
{255, 255, 0},
|
||||||
{ 255, 255, 255 }
|
{255, 255, 255}
|
||||||
};
|
};
|
||||||
int i, sz = 512;
|
int i, sz = 512;
|
||||||
|
|
||||||
|
|
@ -165,7 +169,8 @@ static void makeImages(int image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void myinit(void)
|
static void
|
||||||
|
myinit(void)
|
||||||
{
|
{
|
||||||
InitValues();
|
InitValues();
|
||||||
|
|
||||||
|
|
@ -191,14 +196,16 @@ static void myinit(void)
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display(void)
|
static void
|
||||||
|
display(void)
|
||||||
{
|
{
|
||||||
GLfloat tcm = 1.0;
|
GLfloat tcm = 1.0;
|
||||||
glBindTexture(GL_TEXTURE_2D, texCurrent);
|
glBindTexture(GL_TEXTURE_2D, texCurrent);
|
||||||
|
|
||||||
printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n",
|
printf
|
||||||
BaseLevel, MaxLevel, MinLod, MaxLod, LodBias,
|
("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n",
|
||||||
NearestFilter ? "NEAREST" : "LINEAR");
|
BaseLevel, MaxLevel, MinLod, MaxLod, LodBias,
|
||||||
|
NearestFilter ? "NEAREST" : "LINEAR");
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
|
||||||
|
|
||||||
|
|
@ -208,32 +215,37 @@ static void display(void)
|
||||||
if (NearestFilter) {
|
if (NearestFilter) {
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||||
GL_NEAREST_MIPMAP_NEAREST);
|
GL_NEAREST_MIPMAP_NEAREST);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||||
GL_LINEAR_MIPMAP_LINEAR);
|
GL_LINEAR_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
|
glTexCoord2f(0.0, 0.0);
|
||||||
glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0);
|
glVertex3f(-2.0, -1.0, 0.0);
|
||||||
glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0);
|
glTexCoord2f(0.0, tcm);
|
||||||
glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
|
glVertex3f(-2.0, 1.0, 0.0);
|
||||||
|
glTexCoord2f(tcm * 3000.0, tcm);
|
||||||
|
glVertex3f(3000.0, 1.0, -6000.0);
|
||||||
|
glTexCoord2f(tcm * 3000.0, 0.0);
|
||||||
|
glVertex3f(3000.0, -1.0, -6000.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
glFlush();
|
glFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void myReshape(int w, int h)
|
static void
|
||||||
|
myReshape(int w, int h)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
|
gluPerspective(60.0, 1.0 * (GLfloat) w / (GLfloat) h, 1.0, 30000.0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
@ -241,70 +253,71 @@ static void myReshape(int w, int h)
|
||||||
static void
|
static void
|
||||||
key(unsigned char k, int x, int y)
|
key(unsigned char k, int x, int y)
|
||||||
{
|
{
|
||||||
(void) x;
|
(void) x;
|
||||||
(void) y;
|
(void) y;
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case 'b':
|
case 'b':
|
||||||
BaseLevel--;
|
BaseLevel--;
|
||||||
if (BaseLevel < 0)
|
if (BaseLevel < 0)
|
||||||
BaseLevel = 0;
|
BaseLevel = 0;
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
BaseLevel++;
|
BaseLevel++;
|
||||||
if (BaseLevel > 10)
|
if (BaseLevel > 10)
|
||||||
BaseLevel = 10;
|
BaseLevel = 10;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
MaxLevel--;
|
MaxLevel--;
|
||||||
if (MaxLevel < 0)
|
if (MaxLevel < 0)
|
||||||
MaxLevel = 0;
|
MaxLevel = 0;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
MaxLevel++;
|
MaxLevel++;
|
||||||
if (MaxLevel > 10)
|
if (MaxLevel > 10)
|
||||||
MaxLevel = 10;
|
MaxLevel = 10;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
LodBias -= 0.25;
|
LodBias -= 0.25;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
LodBias += 0.25;
|
LodBias += 0.25;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
MinLod -= 0.25;
|
MinLod -= 0.25;
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
MinLod += 0.25;
|
MinLod += 0.25;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
MaxLod -= 0.25;
|
MaxLod -= 0.25;
|
||||||
break;
|
break;
|
||||||
case 'X':
|
case 'X':
|
||||||
MaxLod += 0.25;
|
MaxLod += 0.25;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
NearestFilter = !NearestFilter;
|
NearestFilter = !NearestFilter;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if (texCurrent == texColor)
|
if (texCurrent == texColor)
|
||||||
texCurrent = texImage;
|
texCurrent = texImage;
|
||||||
else
|
else
|
||||||
texCurrent = texColor;
|
texCurrent = texColor;
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
InitValues();
|
InitValues();
|
||||||
break;
|
break;
|
||||||
case 27: /* Escape */
|
case 27: /* Escape */
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void usage(void)
|
static void
|
||||||
|
usage(void)
|
||||||
{
|
{
|
||||||
printf("usage:\n");
|
printf("usage:\n");
|
||||||
printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
|
printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n");
|
||||||
|
|
@ -318,18 +331,19 @@ static void usage(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
|
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
|
||||||
glutInitWindowSize (600, 600);
|
glutInitWindowSize(600, 600);
|
||||||
glutCreateWindow (argv[0]);
|
glutCreateWindow(argv[0]);
|
||||||
glewInit();
|
glewInit();
|
||||||
myinit();
|
myinit();
|
||||||
glutReshapeFunc (myReshape);
|
glutReshapeFunc(myReshape);
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutKeyboardFunc(key);
|
glutKeyboardFunc(key);
|
||||||
usage();
|
usage();
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
return 0; /* ANSI C requires main to return int. */
|
return 0; /* ANSI C requires main to return int. */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue