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;
int piglit_height = 16;
int piglit_display()
enum piglit_result piglit_display()
{
return PIGLIT_SUCCESS;
}
......
......@@ -29,15 +29,21 @@
*/
#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 GLuint tex;
static void
Init(void)
loadTex(void);
void
piglit_init(int argc, char **argv)
{
glewInit();
piglit_require_extension("GL_ARB_point_sprite");
glMatrixMode(GL_PROJECTION);
......@@ -58,10 +64,11 @@ Init(void)
glClearColor(0.2, 0.2, 0.2, 1.0);
glColor3f(1.0, 1.0, 1.0);
loadTex();
}
static void
display(void)
enum piglit_result
piglit_display(void)
{
static const GLfloat black[3] = {0.0, 0.0, 0.0};
GLboolean pass;
......@@ -112,11 +119,9 @@ display(void)
white);
}
if (Automatic)
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
glutSwapBuffers();
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
......@@ -158,23 +163,3 @@ loadTex(void)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
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 @@
*/
#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] = {
{ 1.0, 1.0, 1.0 },
......@@ -30,7 +32,7 @@ static GLfloat colors[8][3] = {
{ 0.0, 0.0, 0.0 }
};
static void Display(void)
enum piglit_result piglit_display(void)
{
int x, y, color, i, comp;
/* x and y range chosen to cover a wide range of memory;
......@@ -57,7 +59,7 @@ static void Display(void)
x, y, color,
colors[color][0], colors[color][1], colors[color][2],
result[0], result[1], result[2]);
piglit_report_result(PIGLIT_FAILURE);
return PIGLIT_FAILURE;
}
}
}
......@@ -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)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(Width, Height);
glutCreateWindow(argv[0]);
glutDisplayFunc(Display);
init();
glutMainLoop();
return 0;
glViewport(0, 0, piglit_width, piglit_height);
}
......@@ -31,14 +31,15 @@
*/
#include "piglit-util.h"
#include "piglit-framework.h"
static int Width = 256, Height = 128;
static int Automatic = 0;
int piglit_width = 256, piglit_height = 128;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
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;
......@@ -59,59 +60,48 @@ static void test(GLenum wrapt, int cellx, int celly)
/* Take more than one sample, just to be sure */
for(sy = 0; sy < 4; ++sy) {
for(sx = 0; sx < 4; ++sx) {
int x = (cellx*5 + sx + 1)*Width/20;
int y = (celly*5 + sy + 1)*Height/10;
int x = (cellx*5 + sx + 1)*piglit_width/20;
int y = (celly*5 + sy + 1)*piglit_height/10;
if (!piglit_probe_pixel_rgb(x, y, TextureColor)) {
fprintf(stderr, "Fail in cell %i,%i (texwrap = 0x%x)\n", cellx, celly, wrapt);
if (Automatic)
piglit_report_result(PIGLIT_FAILURE);
return GL_FALSE;
}
}
}
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);
glClear(GL_COLOR_BUFFER_BIT);
/* Draw eight tiles, each with a different tex wrap mode.
* They should all look the same.
*/
test(GL_REPEAT, 0, 0);
test(GL_CLAMP, 1, 0);
test(GL_CLAMP_TO_EDGE, 2, 0);
test(GL_CLAMP_TO_BORDER, 3, 0);
test(GL_MIRRORED_REPEAT, 0, 1);
pass &= test(GL_REPEAT, 0, 0);
pass &= test(GL_CLAMP, 1, 0);
pass &= test(GL_CLAMP_TO_EDGE, 2, 0);
pass &= test(GL_CLAMP_TO_BORDER, 3, 0);
pass &= test(GL_MIRRORED_REPEAT, 0, 1);
if (glutExtensionSupported("GL_EXT_texture_mirror_clamp")) {
test(GL_MIRROR_CLAMP_EXT, 1, 1);
test(GL_MIRROR_CLAMP_TO_EDGE_EXT, 2, 1);
test(GL_MIRROR_CLAMP_TO_BORDER_EXT, 3, 1);
pass &= test(GL_MIRROR_CLAMP_EXT, 1, 1);
pass &= test(GL_MIRROR_CLAMP_TO_EDGE_EXT, 2, 1);
pass &= test(GL_MIRROR_CLAMP_TO_BORDER_EXT, 3, 1);
}
glutSwapBuffers();
if (Automatic)
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();
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
static void Init(void)
void piglit_init(int argc, char **argv)
{
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
......@@ -119,38 +109,8 @@ static void Init(void)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_RGB, GL_FLOAT, TextureColor);
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)
{
(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) {
if (!piglit_automatic)
printf("You should see a flat orange color\n");
glutKeyboardFunc(Key);
}
Init();
glutMainLoop();
return 0;
}
......@@ -32,7 +32,8 @@
#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,
225.0, 225.0, 0.0,
......@@ -46,23 +47,13 @@ static GLubyte colors[16] = {255, 0, 0, 127,
255, 0, 0, 127};
static void
Init(void)
void
piglit_init(int argc, char **argv)
{
glewInit();
piglit_require_extension("GL_EXT_secondary_color");
piglit_require_extension("GL_EXT_vertex_array_bgra");
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 400, 0, 300, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
glEnable(GL_COLOR_SUM);
glColor3f(0.0, 0.0, 0.0);
......@@ -70,8 +61,8 @@ Init(void)
glClearColor(0.6, 0.6, 0.6, 1.0);
}
static void
display(void)
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
GLfloat red[3]={1.0, 0.0, 0.0};
......@@ -119,35 +110,12 @@ display(void)
pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed);
pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue);
if(Automatic) {
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
exit(pass ? 0 : 1);
}
glFinish();
glutSwapBuffers();
glDisable(GL_BLEND);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
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;
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
......@@ -31,7 +31,9 @@
#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 fs;
static GLint vs;
......@@ -103,26 +105,17 @@ compileLinkProg(void)
}
static void
Init(void)
void
piglit_init(int argc, char **argv)
{
glewInit();
if (!GLEW_VERSION_2_0) {
printf("Requires OpenGL 2.0\n");
piglit_report_result(PIGLIT_SKIP);
}
piglit_require_extension("GL_EXT_vertex_array_bgra");
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 400, 0, 300, -1, 1);
piglit_require_extension("GL_EXT_vertex_array_bgra");
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
glClearColor(0.6, 0.6, 0.6, 1.0);
......@@ -130,8 +123,8 @@ Init(void)
}
static void
display(void)
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
GLfloat red[3]={1.0, 0.0, 0.0};
......@@ -191,33 +184,10 @@ display(void)
pass = pass && piglit_probe_pixel_rgb(200, 125, greyRed);
pass = pass && piglit_probe_pixel_rgb(275, 125, greyBlue);
if(Automatic) {
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
exit(pass ? 0 : 1);
}
glFinish();
glutSwapBuffers();
glDisable(GL_BLEND);
}
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;
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
......@@ -34,8 +34,8 @@
#include "piglit-util.h"
#define WIN_WIDTH 200
#define WIN_HEIGHT 100
int piglit_width = 200, piglit_height = 100;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
/* apply MVP and set the color to blue. */
static const GLchar *const vp_code =
......@@ -55,10 +55,8 @@ static const GLchar *const fp_code =
"END"
;
static GLboolean Automatic = GL_FALSE;
static void
display(void)
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
float vertices[4][4];
......@@ -115,29 +113,29 @@ display(void)
glutSwapBuffers();
if (Automatic) {
printf("PIGLIT: {'result': '%s' }\n",
pass ? "pass" : "fail");
exit(pass ? 0 : 1);
}
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
static void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
piglit_ortho_projection(width, height, GL_FALSE);
}
static void
init(void)
void
piglit_init(int argc, char **argv)
{
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);
piglit_require_extension("GL_ARB_fragment_program");
piglit_require_extension("GL_ARB_vertex_program");
glGenProgramsARB(1, &vert_prog);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog);
......@@ -152,31 +150,3 @@ init(void)
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
if (argc == 2 && !strcmp(argv[1], "-auto"))
Automatic = 1;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutCreateWindow("clear-varray-2.0");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(piglit_escape_exit_key);
glewInit();
init();
if (!GLEW_VERSION_2_0) {
printf("Requires OpenGL 2.0\n");
piglit_report_result(PIGLIT_SKIP);
}
piglit_require_extension("GL_ARB_fragment_program");
piglit_require_extension("GL_ARB_vertex_program");
glutMainLoop();
return 0;
}
......@@ -36,34 +36,24 @@
#include "piglit-util.h"
int piglit_width = 100, piglit_height = 150;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
/* In case the headers have the old enum name but not the new */
#ifndef GL_DEPTH_CLAMP
#define GL_DEPTH_CLAMP GL_DEPTH_CLAMP_NV
#endif
static GLboolean Automatic = GL_FALSE;
#define WIN_WIDTH 100
#define WIN_HEIGHT 150
static void
init(void)
void
piglit_init(int argc, char **argv)
{
glewInit();
piglit_require_extension("GL_ARB_depth_clamp");
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, WIN_WIDTH, 0, WIN_HEIGHT, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
}
static void
display(void)
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
float white[3] = {1.0, 1.0, 1.0};
......@@ -160,25 +150,5 @@ display(void)
glutSwapBuffers();
if (Automatic)
piglit_report_result(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 | GLUT_DEPTH);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutCreateWindow("depth_clamp");
glutDisplayFunc(display);
glutKeyboardFunc(piglit_escape_exit_key);
init();
glutMainLoop();
return 0;
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
......@@ -33,11 +33,8 @@
#include "piglit-util.h"
#define WIN_WIDTH 100
#define WIN_HEIGHT 100
static GLboolean Automatic = GL_FALSE;
static int win_width, win_height;
int piglit_width = 100, piglit_height = 100;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
/**
* Convenience function to draw an axis-aligned rectangle.
......@@ -81,7 +78,8 @@ draw_rect_set(int y)
draw_rect(70, y, 10, 10, .75);
}
static void display(void)
enum piglit_result
piglit_display(void)
{
GLboolean pass = GL_TRUE;
int x, y;
......@@ -127,52 +125,21 @@ static void display(void)
glutSwapBuffers();
if (Automatic) {
piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE);
}
return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
}
static void reshape(int width, int height)
{
win_width = width;
win_height = height;
piglit_width = width;
piglit_height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
static void
init(void)
{
reshape(WIN_WIDTH, WIN_HEIGHT);
piglit_ortho_projection(width, height, GL_FALSE);
}
int main(int argc, char**argv)
void
piglit_init(int argc, char **argv)
{
int i;
glutInit(&argc, argv);
for(i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-auto"))
Automatic = 1;
else
printf("Unknown option: %s\n", argv[i]);
}
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutInitWindowPosition(100, 100);
glutCreateWindow("depthrange-clear");
glutKeyboardFunc(piglit_escape_exit_key);