Commit 4cfbe82b authored by Eric Anholt's avatar Eric Anholt

Move most piglit tests to using the framework.

This saves a giant pile of code, and should encourage cleaner testcases
from people writing tests in the future.
parent e144c21b
...@@ -40,7 +40,7 @@ int piglit_width = 16; ...@@ -40,7 +40,7 @@ int piglit_width = 16;
int piglit_height = 16; int piglit_height = 16;
int piglit_display() enum piglit_result piglit_display()
{ {
return PIGLIT_SUCCESS; return PIGLIT_SUCCESS;
} }
......
...@@ -29,15 +29,21 @@ ...@@ -29,15 +29,21 @@
*/ */
#include "piglit-util.h" #include "piglit-util.h"
#include "piglit-framework.h"
int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
int piglit_width = 400;
int piglit_height = 300;
static GLboolean Automatic = GL_FALSE;
static float maxSize = 0.0f; static float maxSize = 0.0f;
static GLuint tex; static GLuint tex;
static void static void
Init(void) loadTex(void);
void
piglit_init(int argc, char **argv)
{ {
glewInit();
piglit_require_extension("GL_ARB_point_sprite"); piglit_require_extension("GL_ARB_point_sprite");
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
...@@ -58,10 +64,11 @@ Init(void) ...@@ -58,10 +64,11 @@ Init(void)
glClearColor(0.2, 0.2, 0.2, 1.0); glClearColor(0.2, 0.2, 0.2, 1.0);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
loadTex();
} }
static void enum piglit_result
display(void) piglit_display(void)
{ {
static const GLfloat black[3] = {0.0, 0.0, 0.0}; static const GLfloat black[3] = {0.0, 0.0, 0.0};
GLboolean pass; GLboolean pass;
...@@ -112,11 +119,9 @@ display(void) ...@@ -112,11 +119,9 @@ display(void)
white); white);
} }
if (Automatic)
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
glutSwapBuffers(); glutSwapBuffers();
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
} }
...@@ -158,23 +163,3 @@ loadTex(void) ...@@ -158,23 +163,3 @@ loadTex(void)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_FLOAT, texData); GL_FLOAT, texData);
} }
int main(int argc, char **argv)
{
glutInit(&argc, argv);
if(argc==2 && !strncmp(argv[1],"-auto",5))
Automatic = GL_TRUE;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 300);
glutCreateWindow("point_sprite");
glutDisplayFunc(display);
glutKeyboardFunc(piglit_escape_exit_key);
Init();
loadTex();
glutMainLoop();
return 0;
}
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
*/ */
#include "piglit-util.h" #include "piglit-util.h"
#include "piglit-framework.h"
static int Width = 100, Height = 100; int piglit_width = 100, piglit_height = 100;
int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA;
static GLfloat colors[8][3] = { static GLfloat colors[8][3] = {
{ 1.0, 1.0, 1.0 }, { 1.0, 1.0, 1.0 },
...@@ -30,7 +32,7 @@ static GLfloat colors[8][3] = { ...@@ -30,7 +32,7 @@ static GLfloat colors[8][3] = {
{ 0.0, 0.0, 0.0 } { 0.0, 0.0, 0.0 }
}; };
static void Display(void) enum piglit_result piglit_display(void)
{ {
int x, y, color, i, comp; int x, y, color, i, comp;
/* x and y range chosen to cover a wide range of memory; /* x and y range chosen to cover a wide range of memory;
...@@ -57,7 +59,7 @@ static void Display(void) ...@@ -57,7 +59,7 @@ static void Display(void)
x, y, color, x, y, color,
colors[color][0], colors[color][1], colors[color][2], colors[color][0], colors[color][1], colors[color][2],
result[0], result[1], result[2]); result[0], result[1], result[2]);
piglit_report_result(PIGLIT_FAILURE); return PIGLIT_FAILURE;
} }
} }
} }
...@@ -65,23 +67,12 @@ static void Display(void) ...@@ -65,23 +67,12 @@ static void Display(void)
} }
} }
piglit_report_result(PIGLIT_SUCCESS); return PIGLIT_SUCCESS;
} }
static void init(void) void piglit_init(int argc, char **argv)
{ {
glViewport(0, 0, Width, Height); piglit_automatic = GL_TRUE;
}
int main(int argc, char**argv) glViewport(0, 0, piglit_width, piglit_height);
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(Width, Height);
glutCreateWindow(argv[0]);
glutDisplayFunc(Display);
init();
glutMainLoop();
return 0;
} }
...@@ -31,14 +31,15 @@ ...@@ -31,14 +31,15 @@
*/ */
#include "piglit-util.h" #include "piglit-util.h"
#include "piglit-framework.h"
static int Width = 256, Height = 128; int piglit_width = 256, piglit_height = 128;
static int Automatic = 0; int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
static const GLfloat TextureColor[3] = { 1.0, 0.5, 0.0 }; static const GLfloat TextureColor[3] = { 1.0, 0.5, 0.0 };
static void test(GLenum wrapt, int cellx, int celly) static GLboolean test(GLenum wrapt, int cellx, int celly)
{ {
int sx, sy; int sx, sy;
...@@ -59,59 +60,48 @@ static void test(GLenum wrapt, int cellx, int celly) ...@@ -59,59 +60,48 @@ static void test(GLenum wrapt, int cellx, int celly)
/* Take more than one sample, just to be sure */ /* Take more than one sample, just to be sure */
for(sy = 0; sy < 4; ++sy) { for(sy = 0; sy < 4; ++sy) {
for(sx = 0; sx < 4; ++sx) { for(sx = 0; sx < 4; ++sx) {
int x = (cellx*5 + sx + 1)*Width/20; int x = (cellx*5 + sx + 1)*piglit_width/20;
int y = (celly*5 + sy + 1)*Height/10; int y = (celly*5 + sy + 1)*piglit_height/10;
if (!piglit_probe_pixel_rgb(x, y, TextureColor)) { if (!piglit_probe_pixel_rgb(x, y, TextureColor)) {
fprintf(stderr, "Fail in cell %i,%i (texwrap = 0x%x)\n", cellx, celly, wrapt); fprintf(stderr, "Fail in cell %i,%i (texwrap = 0x%x)\n", cellx, celly, wrapt);
if (Automatic) return GL_FALSE;
piglit_report_result(PIGLIT_FAILURE);
} }
} }
} }
return GL_TRUE;
} }
static void Redisplay(void) enum piglit_result
piglit_display(void)
{ {
GLboolean pass = GL_TRUE;
glClearColor(0.5, 0.5, 0.5, 1.0); glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
/* Draw eight tiles, each with a different tex wrap mode. /* Draw eight tiles, each with a different tex wrap mode.
* They should all look the same. * They should all look the same.
*/ */
test(GL_REPEAT, 0, 0); pass &= test(GL_REPEAT, 0, 0);
test(GL_CLAMP, 1, 0); pass &= test(GL_CLAMP, 1, 0);
test(GL_CLAMP_TO_EDGE, 2, 0); pass &= test(GL_CLAMP_TO_EDGE, 2, 0);
test(GL_CLAMP_TO_BORDER, 3, 0); pass &= test(GL_CLAMP_TO_BORDER, 3, 0);
test(GL_MIRRORED_REPEAT, 0, 1); pass &= test(GL_MIRRORED_REPEAT, 0, 1);
if (glutExtensionSupported("GL_EXT_texture_mirror_clamp")) { if (glutExtensionSupported("GL_EXT_texture_mirror_clamp")) {
test(GL_MIRROR_CLAMP_EXT, 1, 1); pass &= test(GL_MIRROR_CLAMP_EXT, 1, 1);
test(GL_MIRROR_CLAMP_TO_EDGE_EXT, 2, 1); pass &= test(GL_MIRROR_CLAMP_TO_EDGE_EXT, 2, 1);
test(GL_MIRROR_CLAMP_TO_BORDER_EXT, 3, 1); pass &= test(GL_MIRROR_CLAMP_TO_BORDER_EXT, 3, 1);
} }
glutSwapBuffers(); glutSwapBuffers();
if (Automatic) return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
piglit_report_result(PIGLIT_SUCCESS);
}
static void Reshape(int width, int height)
{
Width = width;
Height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} }
void piglit_init(int argc, char **argv)
static void Init(void)
{ {
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
...@@ -119,38 +109,8 @@ static void Init(void) ...@@ -119,38 +109,8 @@ static void Init(void)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_RGB, GL_FLOAT, TextureColor); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_RGB, GL_FLOAT, TextureColor);
glEnable(GL_TEXTURE_1D); glEnable(GL_TEXTURE_1D);
Reshape(Width,Height); piglit_ortho_projection(1.0, 1.0, GL_FALSE);
}
static void Key(unsigned char key, int x, int y) if (!piglit_automatic)
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
if (argc == 2 && !strcmp(argv[1], "-auto"))
Automatic = 1;
glutInitWindowPosition(0, 0);
glutInitWindowSize(Width, Height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
glutDisplayFunc(Redisplay);
if (!Automatic) {
printf("You should see a flat orange color\n"); printf("You should see a flat orange color\n");
glutKeyboardFunc(Key);
}
Init();
glutMainLoop();
return 0;
} }
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
#include "piglit-util.h" #include "piglit-util.h"
static GLboolean Automatic = GL_FALSE; int piglit_width = 400, piglit_height = 300;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
static GLfloat verts[12] = {225.0, 175.0, 0.0, static GLfloat verts[12] = {225.0, 175.0, 0.0,
225.0, 225.0, 0.0, 225.0, 225.0, 0.0,
...@@ -46,23 +47,13 @@ static GLubyte colors[16] = {255, 0, 0, 127, ...@@ -46,23 +47,13 @@ static GLubyte colors[16] = {255, 0, 0, 127,
255, 0, 0, 127}; 255, 0, 0, 127};
static void void
Init(void) piglit_init(int argc, char **argv)
{ {
glewInit();
piglit_require_extension("GL_EXT_secondary_color"); piglit_require_extension("GL_EXT_secondary_color");
piglit_require_extension("GL_EXT_vertex_array_bgra"); piglit_require_extension("GL_EXT_vertex_array_bgra");
glMatrixMode(GL_PROJECTION); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 400, 0, 300, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable(GL_COLOR_SUM); glEnable(GL_COLOR_SUM);
glColor3f(0.0, 0.0, 0.0); glColor3f(0.0, 0.0, 0.0);
...@@ -70,8 +61,8 @@ Init(void) ...@@ -70,8 +61,8 @@ Init(void)
glClearColor(0.6, 0.6, 0.6, 1.0); glClearColor(0.6, 0.6, 0.6, 1.0);
} }
static void enum piglit_result
display(void) piglit_display(void)
{ {
GLboolean pass = GL_TRUE; GLboolean pass = GL_TRUE;
GLfloat red[3]={1.0, 0.0, 0.0}; GLfloat red[3]={1.0, 0.0, 0.0};
...@@ -119,35 +110,12 @@ display(void) ...@@ -119,35 +110,12 @@ display(void)
pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed); pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed);
pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue); pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue);
if(Automatic) {
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
exit(pass ? 0 : 1);
}
glFinish(); glFinish();
glutSwapBuffers(); glutSwapBuffers();
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY); glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
}
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
int main(int argc, char **argv)
{
glutInit(&argc, argv);
if(argc==2 && !strncmp(argv[1], "-auto", 5))
Automatic=GL_TRUE;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 300);
glutCreateWindow("bgra-sec-color-pointer");
glutDisplayFunc(display);
glutKeyboardFunc(piglit_escape_exit_key);
Init();
glutMainLoop();
return 0;
} }
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
#include "piglit-util.h" #include "piglit-util.h"
static GLboolean Automatic = GL_FALSE; int piglit_width = 400, piglit_height = 300;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
static GLint prog; static GLint prog;
static GLint fs; static GLint fs;
static GLint vs; static GLint vs;
...@@ -103,26 +105,17 @@ compileLinkProg(void) ...@@ -103,26 +105,17 @@ compileLinkProg(void)
} }
static void void
Init(void) piglit_init(int argc, char **argv)
{ {
glewInit();
if (!GLEW_VERSION_2_0) { if (!GLEW_VERSION_2_0) {
printf("Requires OpenGL 2.0\n"); printf("Requires OpenGL 2.0\n");
piglit_report_result(PIGLIT_SKIP); piglit_report_result(PIGLIT_SKIP);
} }
piglit_require_extension("GL_EXT_vertex_array_bgra");
glMatrixMode(GL_PROJECTION); piglit_require_extension("GL_EXT_vertex_array_bgra");
glPushMatrix();
glLoadIdentity();
glOrtho(0, 400, 0, 300, -1, 1);
glMatrixMode(GL_MODELVIEW); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
glPushMatrix();
glLoadIdentity();
glClearColor(0.6, 0.6, 0.6, 1.0); glClearColor(0.6, 0.6, 0.6, 1.0);
...@@ -130,8 +123,8 @@ Init(void) ...@@ -130,8 +123,8 @@ Init(void)
} }
static void enum piglit_result
display(void) piglit_display(void)
{ {
GLboolean pass = GL_TRUE; GLboolean pass = GL_TRUE;
GLfloat red[3]={1.0, 0.0, 0.0}; GLfloat red[3]={1.0, 0.0, 0.0};
...@@ -191,33 +184,10 @@ display(void) ...@@ -191,33 +184,10 @@ display(void)
pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed); pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed);
pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue); pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue);
if(Automatic) {
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
exit(pass ? 0 : 1);
}
glFinish(); glFinish();
glutSwapBuffers(); glutSwapBuffers();
glDisable(GL_BLEND); glDisable(GL_BLEND);
}
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
int main(int argc, char **argv)
{
glutInit(&argc, argv);
if(argc==2 && !strncmp(argv[1], "-auto", 5))
Automatic=GL_TRUE;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 300);
glutCreateWindow("bgra-vert-attrib-pointer");
glutDisplayFunc(display);
glutKeyboardFunc(piglit_escape_exit_key);
Init();
glutMainLoop();
return 0;
} }
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
#include "piglit-util.h" #include "piglit-util.h"
#define WIN_WIDTH 200 int piglit_width = 200, piglit_height = 100;
#define WIN_HEIGHT 100 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
/* apply MVP and set the color to blue. */ /* apply MVP and set the color to blue. */
static const GLchar *const vp_code = static const GLchar *const vp_code =
...@@ -55,10 +55,8 @@ static const GLchar *const fp_code = ...@@ -55,10 +55,8 @@ static const GLchar *const fp_code =
"END" "END"
; ;
static GLboolean Automatic = GL_FALSE; enum piglit_result
piglit_display(void)
static void
display(void)
{ {
GLboolean pass = GL_TRUE; GLboolean pass = GL_TRUE;
float vertices[4][4]; float vertices[4][4];
...@@ -115,29 +113,29 @@ display(void) ...@@ -115,29 +113,29 @@ display(void)
glutSwapBuffers(); glutSwapBuffers();
if (Automatic) { return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
printf("PIGLIT: {'result': '%s' }\n",
pass ? "pass" : "fail");
exit(pass ? 0 : 1);
}
} }
static void reshape(int width, int height) static void reshape(int width, int height)
{ {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); piglit_ortho_projection(width, height, GL_FALSE);
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} }
static void void
init(void) piglit_init(int argc, char **argv)
{ {
GLuint vert_prog, frag_prog; GLuint vert_prog, frag_prog;
reshape(WIN_WIDTH, WIN_HEIGHT); if (!GLEW_VERSION_2_0) {
printf("Requires OpenGL 2.0\n");
piglit_report_result(PIGLIT_SKIP);
}
reshape(piglit_width, piglit_height);