Commit 7a7fcc23 authored by Nicolai Hähnle's avatar Nicolai Hähnle

Cleanup/Code sharing: Use piglit-util functions in a number of places

parent 8900a6f0
......@@ -347,52 +347,8 @@ static void Init(void)
piglit_require_fragment_program();
/*
* Fragment programs
*/
pglGenProgramsARB(NUM_PROGRAMS, FragProg);
for(i = 0; i < NUM_PROGRAMS; ++i) {
GLint errorPos;
check(FragProg[i]);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[i]);
pglProgramStringARB(
GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(ProgramText[i]),
(const GLubyte *)ProgramText[i]);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(ProgramText[i], errorPos);
int a;
fprintf(stderr, "%i: Fragment Program Error (pos=%d line=%d): %s\n",
i, errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
for (a=-10; a<10; a++)
{
if (errorPos+a < 0)
continue;
if (errorPos+a >= strlen(ProgramText[i]))
break;
fprintf(stderr, "%c", ProgramText[i][errorPos+a]);
}
fprintf(stderr, "\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg[i])) {
fprintf(stderr, "pglIsProgramARB failed\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
}
for(i = 0; i < NUM_PROGRAMS; ++i)
FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
/*
* Texture unit 0: 200x200 RECTANGLE texture
......
......@@ -219,33 +219,7 @@ static void Reshape(int width, int height)
static void Init(void)
{
piglit_require_fragment_program();
/*
* Fragment programs
*/
pglGenProgramsARB(1, &FragProg);
GLint errorPos;
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg);
pglProgramStringARB(
GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(Testcase.programtext),
(const GLubyte *)Testcase.programtext);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(Testcase.programtext, errorPos);
fprintf(stderr, "Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg)) {
fprintf(stderr, "pglIsProgramARB failed\n");
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
FragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, Testcase.programtext);
Reshape(Width,Height);
}
......
......@@ -238,50 +238,8 @@ static void Init(void)
piglit_require_fragment_program();
/*
* Fragment programs
*/
pglGenProgramsARB(NUM_PROGRAMS, FragProg);
for(i = 0; i < NUM_PROGRAMS; ++i) {
GLint errorPos;
check(FragProg[i]);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[i]);
pglProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(ProgramText[i]),
(const GLubyte *)ProgramText[i]);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(ProgramText[i], errorPos);
int a;
fprintf(stderr, "%i: Fragment Program Error (pos=%d line=%d): %s\n",
i, errorPos, l,
(char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
for (a=-10; a<10; a++)
{
if (errorPos+a < 0)
continue;
if (errorPos+a >= strlen(ProgramText[i]))
break;
fprintf(stderr, "%c", ProgramText[i][errorPos+a]);
}
fprintf(stderr, "\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg[i])) {
fprintf(stderr, "pglIsProgramARB failed\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
}
for(i = 0; i < NUM_PROGRAMS; ++i)
FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
Reshape(Width,Height);
}
......
......@@ -316,49 +316,8 @@ static void Init(void)
/*
* Fragment programs
*/
pglGenProgramsARB(NUM_PROGRAMS, FragProg);
for(i = 0; i < NUM_PROGRAMS; ++i) {
GLint errorPos;
check(FragProg[i]);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[i]);
pglProgramStringARB(
GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(ProgramText[i]),
(const GLubyte *)ProgramText[i]);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(ProgramText[i], errorPos);
int a;
fprintf(stderr, "%i: Fragment Program Error (pos=%d line=%d): %s\n",
i, errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
for (a=-10; a<10; a++)
{
if (errorPos+a < 0)
continue;
if (errorPos+a >= strlen(ProgramText[i]))
break;
fprintf(stderr, "%c", ProgramText[i][errorPos+a]);
}
fprintf(stderr, "\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg[i])) {
fprintf(stderr, "pglIsProgramARB failed\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
}
for(i = 0; i < NUM_PROGRAMS; ++i)
FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
/*
* Textures
......
......@@ -32,6 +32,7 @@
#include <math.h>
#include <GL/glut.h>
#include "piglit-util.h"
static GLuint FragProg[15];
......@@ -48,23 +49,14 @@ static int Automatic = 0;
static int Width = 200, Height = 200;
static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB;
static PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB;
static PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB;
static PFNGLGENPROGRAMSARBPROC pglGenProgramsARB;
static PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB;
static PFNGLBINDPROGRAMARBPROC pglBindProgramARB;
static PFNGLISPROGRAMARBPROC pglIsProgramARB;
static PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB;
static void DoFrame(void)
{
int mask;
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_FRAGMENT_PROGRAM_ARB);
for(mask = 1; mask < 16; ++mask) {
......@@ -89,10 +81,10 @@ static int DoTest( void )
{
int mask;
GLfloat dmax;
glReadBuffer( GL_FRONT );
dmax = 0;
for(mask = 1; mask < 16; ++mask) {
GLfloat probe[4];
GLfloat delta[4];
......@@ -100,19 +92,19 @@ static int DoTest( void )
glReadPixels(Width*(2*(mask%4)+1)/8, Height*(2*(mask/4)+1)/8, 1, 1,
GL_RGBA, GL_FLOAT, probe);
printf("Probe %i: %f,%f,%f,%f\n", mask, probe[0], probe[1], probe[2], probe[3]);
for(i = 0; i < 4; ++i) {
if (mask & (1 << i))
delta[i] = probe[i] - LitExpected[i];
else
delta[i] = probe[i] - 0.8;
if (delta[i] > dmax) dmax = delta[i];
else if (-delta[i] > dmax) dmax = -delta[i];
}
printf(" Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
}
......@@ -128,10 +120,10 @@ static int DoTest( void )
static void Redisplay(void)
{
int succ;
DoFrame();
succ = DoTest();
if (Automatic) {
printf("\nPIGLIT: { 'result': '%s' }\n", succ ? "pass" : "fail");
exit(0);
......@@ -169,84 +161,29 @@ static void Key(unsigned char key, int x, int y)
static void Init(void)
{
int mask;
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
if (!glutExtensionSupported("GL_ARB_fragment_program")) {
fprintf(stderr, "Sorry, this demo requires GL_ARB_fragment_program\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
/*
* Get extension function pointers.
*/
pglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) glutGetProcAddress("glProgramLocalParameter4fvARB");
assert(pglProgramLocalParameter4fvARB);
pglProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) glutGetProcAddress("glProgramLocalParameter4dARB");
assert(pglProgramLocalParameter4dARB);
pglGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB");
assert(pglGetProgramLocalParameterdvARB);
pglGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) glutGetProcAddress("glGenProgramsARB");
assert(pglGenProgramsARB);
pglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) glutGetProcAddress("glProgramStringARB");
assert(pglProgramStringARB);
pglBindProgramARB = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB");
assert(pglBindProgramARB);
pglIsProgramARB = (PFNGLISPROGRAMARBPROC) glutGetProcAddress("glIsProgramARB");
assert(pglIsProgramARB);
pglDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB");
assert(pglDeleteProgramsARB);
piglit_require_fragment_program();
/*
* Fragment programs
*/
pglGenProgramsARB(15, FragProg);
for(mask = 1; mask < 16; ++mask) {
GLint errorPos;
char programText[1024];
char maskstring[5];
maskstring[0] = 0;
if (mask & 1) strcat(maskstring, "x");
if (mask & 2) strcat(maskstring, "y");
if (mask & 4) strcat(maskstring, "z");
if (mask & 8) strcat(maskstring, "w");
sprintf(programText, fragProgramTemplate, maskstring);
assert(FragProg[mask-1] > 0);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[mask-1]);
pglProgramStringARB(
GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(programText),
(const GLubyte *)programText);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(programText, errorPos);
fprintf(stderr, "Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg[mask-1])) {
fprintf(stderr, "pglIsProgramARB failed\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
FragProg[mask-1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, programText);
}
Reshape(Width,Height);
}
......
......@@ -33,6 +33,7 @@
#include <math.h>
#include <GL/glut.h>
#include "piglit-util.h"
static GLuint TexDiffuse = 1;
static GLuint TexNormal = 2;
......@@ -45,15 +46,6 @@ static int Automatic = 0;
static int Width = 200, Height = 100;
static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB;
static PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB;
static PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB;
static PFNGLGENPROGRAMSARBPROC pglGenProgramsARB;
static PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB;
static PFNGLBINDPROGRAMARBPROC pglBindProgramARB;
static PFNGLISPROGRAMARBPROC pglIsProgramARB;
static PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB;
static void DoFrame(void)
{
......@@ -280,66 +272,8 @@ static void Init(void)
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
if (!glutExtensionSupported("GL_ARB_fragment_program")) {
fprintf(stderr, "Sorry, this demo requires GL_ARB_fragment_program\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
/*
* Get extension function pointers.
*/
pglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) glutGetProcAddress("glProgramLocalParameter4fvARB");
assert(pglProgramLocalParameter4fvARB);
pglProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) glutGetProcAddress("glProgramLocalParameter4dARB");
assert(pglProgramLocalParameter4dARB);
pglGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB");
assert(pglGetProgramLocalParameterdvARB);
pglGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) glutGetProcAddress("glGenProgramsARB");
assert(pglGenProgramsARB);
pglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) glutGetProcAddress("glProgramStringARB");
assert(pglProgramStringARB);
pglBindProgramARB = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB");
assert(pglBindProgramARB);
pglIsProgramARB = (PFNGLISPROGRAMARBPROC) glutGetProcAddress("glIsProgramARB");
assert(pglIsProgramARB);
pglDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB");
assert(pglDeleteProgramsARB);
/*
* Fragment program
*/
pglGenProgramsARB(1, &FragProg);
assert(FragProg > 0);
pglBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg);
pglProgramStringARB(
GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(fragProgramText),
(const GLubyte *) fragProgramText);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(fragProgramText, errorPos);
fprintf(stderr, "Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (!pglIsProgramARB(FragProg)) {
fprintf(stderr, "pglIsProgramARB failed\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
piglit_require_fragment_program();
FragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragProgramText);
/*
* Initialize textures
......
......@@ -370,13 +370,7 @@ static void Key(unsigned char key, int x, int y)
static void init()
{
if (!glutExtensionSupported("GL_ARB_texture_cube_map")) {
fprintf(stderr,
"Sorry, this demo requires GL_ARB_texture_cube_map\n");
if (Automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
piglit_require_extension("GL_ARB_texture_cube_map");
/* Set up projection matrix so we can just draw using window
* coordinates.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment