Commit b8b124e7 authored by Nicolai Hähnle's avatar Nicolai Hähnle

Add fragment program / vertex program helper code to piglit-util

parent c5cf79d6
......@@ -76,15 +76,6 @@ 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;
/**
* Draw four quadrilaterals, one for each fragment program:
......@@ -269,11 +260,11 @@ static int DoTest( void )
int i;
/*
printf("ReadPixels at %d, %d\n",
printf("ReadPixels at %d, %d\n",
(int)(Probes[idx].x*Width/2),
(int)(Probes[idx].y*Height/2));
*/
glReadPixels((int)(Probes[idx].x*Width/2),
(int)(Probes[idx].y*Height/2),
1, 1,
......@@ -354,39 +345,7 @@ 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);
piglit_require_fragment_program();
/*
* Fragment programs
......
......@@ -154,12 +154,6 @@ static struct testcase Testcase;
static GLuint FragProg;
static PFNGLGENPROGRAMSARBPROC pglGenProgramsARB;
static PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB;
static PFNGLBINDPROGRAMARBPROC pglBindProgramARB;
static PFNGLISPROGRAMARBPROC pglIsProgramARB;
static PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB;
static void TestInstance(struct testinstance* instance)
{
......@@ -224,25 +218,7 @@ static void Reshape(int width, int height)
static void Init(void)
{
piglit_require_extension("GL_ARB_fragment_program");
/*
* Get extension function pointers.
*/
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
......
......@@ -33,6 +33,8 @@
#include <math.h>
#include <GL/glut.h>
#include "piglit-util.h"
static void CheckFail(const char* cond);
#define check(cond) do { if (!(cond)) CheckFail(#cond); } while(0)
......@@ -68,16 +70,6 @@ static int Automatic = 0;
static int Width = 300, 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;
......@@ -244,39 +236,7 @@ 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);
piglit_require_fragment_program();
/*
* Fragment programs
......
......@@ -61,15 +61,6 @@ static int Automatic = 0;
static int Width = 200, Height = 200; // space for more tests
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)
{
......@@ -320,39 +311,7 @@ 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);
piglit_require_fragment_program();
/*
* Fragment programs
......
......@@ -50,9 +50,6 @@ static int automatic = 0;
#define WIN_WIDTH 128
#define WIN_HEIGHT 128
static PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB;
static PFNGLBINDPROGRAMARBPROC pglBindProgramARB;
static void
display(void)
{
......@@ -153,13 +150,7 @@ main(int argc, char**argv)
glutCreateWindow("vp-bad-program");
glutDisplayFunc(display);
piglit_require_extension("GL_ARB_vertex_program");
pglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) glutGetProcAddress("glProgramStringARB");
assert(pglProgramStringARB);
pglBindProgramARB = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB");
assert(pglBindProgramARB);
piglit_require_vertex_program();
glutMainLoop();
return 0;
......
......@@ -21,9 +21,11 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "GL/glut.h"
......@@ -96,3 +98,150 @@ int piglit_probe_pixel_rgba(int x, int y, const float* expected)
return 0;
}
/**
* Read a pixel from the given location and compare its RGB value to the
* given expected values.
*
* Print a log message if the color value deviates from the expected value.
* \return true if the color values match, false otherwise
*/
int piglit_probe_pixel_rgb(int x, int y, const float* expected)
{
GLfloat probe[3];
GLfloat delta[3];
GLfloat deltamax;
int i;
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, probe);
deltamax = 0.0;
for(i = 0; i < 3; ++i) {
delta[i] = probe[i] - expected[i];
if (fabs(delta[i]) > deltamax)
deltamax = fabs(delta[i]);
}
if (deltamax < 0.01)
return 1;
printf("Probe at (%i,%i)\n", x, y);
printf(" Expected: %f %f %f %f\n", expected[0], expected[1], expected[2]);
printf(" Observed: %f %f %f %f\n", probe[0], probe[1], probe[2]);
return 0;
}
PFNGLGENPROGRAMSARBPROC pglGenProgramsARB = 0;
PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB = 0;
PFNGLBINDPROGRAMARBPROC pglBindProgramARB = 0;
PFNGLISPROGRAMARBPROC pglIsProgramARB = 0;
PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB = 0;
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB = 0;
PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB = 0;
PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB = 0;
static void get_program_functions()
{
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);
pglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) glutGetProcAddress("glProgramLocalParameter4fvARB");
assert(pglProgramLocalParameter4fvARB);
pglProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) glutGetProcAddress("glProgramLocalParameter4dARB");
assert(pglProgramLocalParameter4dARB);
pglGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB");
assert(pglGetProgramLocalParameterdvARB);
}
int piglit_use_fragment_program()
{
if (!glutExtensionSupported("GL_ARB_fragment_program"))
return 0;
get_program_functions();
return 1;
}
void piglit_require_fragment_program()
{
if (!piglit_use_fragment_program()) {
printf("GL_ARB_fragment_program not supported.\n");
piglit_report_result(PIGLIT_SKIP);
exit(1);
}
}
int piglit_use_vertex_program()
{
if (!glutExtensionSupported("GL_ARB_vertex_program"))
return 0;
get_program_functions();
return 1;
}
void piglit_require_vertex_program()
{
if (!piglit_use_vertex_program()) {
printf("GL_ARB_vertex_program not supported.\n");
piglit_report_result(PIGLIT_SKIP);
exit(1);
}
}
GLuint piglit_compile_program(GLenum target, const char* text)
{
GLuint program;
GLint errorPos;
pglGenProgramsARB(1, &program);
pglBindProgramARB(target, program);
pglProgramStringARB(
target,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(text),
(const GLubyte *)text);
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError() != GL_NO_ERROR || errorPos != -1) {
int l = FindLine(text, errorPos);
int a;
fprintf(stderr, "Compiler Error (pos=%d line=%d): %s\n",
errorPos, l,
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
for (a=-10; a<10; a++)
{
if (errorPos+a < 0)
continue;
if (errorPos+a >= strlen(text))
break;
fprintf(stderr, "%c", text[errorPos+a]);
}
fprintf(stderr, "\nin program:\n%s", text);
piglit_report_result(PIGLIT_FAILURE);
}
if (!pglIsProgramARB(program)) {
fprintf(stderr, "pglIsProgramARB failed\n");
piglit_report_result(PIGLIT_FAILURE);
}
return program;
}
......@@ -32,4 +32,20 @@ enum piglit_result {
int FindLine(const char *program, int position);
void piglit_report_result(enum piglit_result result);
void piglit_require_extension(const char *name);
int piglit_probe_pixel_rgb(int x, int y, const float* expected);
int piglit_probe_pixel_rgba(int x, int y, const float* expected);
extern PFNGLGENPROGRAMSARBPROC pglGenProgramsARB;
extern PFNGLPROGRAMSTRINGARBPROC pglProgramStringARB;
extern PFNGLBINDPROGRAMARBPROC pglBindProgramARB;
extern PFNGLISPROGRAMARBPROC pglIsProgramARB;
extern PFNGLDELETEPROGRAMSARBPROC pglDeleteProgramsARB;
extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC pglProgramLocalParameter4fvARB;
extern PFNGLPROGRAMLOCALPARAMETER4DARBPROC pglProgramLocalParameter4dARB;
extern PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC pglGetProgramLocalParameterdvARB;
int piglit_use_fragment_program();
int piglit_use_vertex_program();
void piglit_require_fragment_program();
void piglit_require_vertex_program();
GLuint piglit_compile_program(GLenum target, const char* text);
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