diff options
author | Karl Rasche <[email protected]> | 2003-11-24 13:29:54 +0000 |
---|---|---|
committer | Karl Rasche <[email protected]> | 2003-11-24 13:29:54 +0000 |
commit | dda09a61548218f3769f50ad7f901395ef5d0e96 (patch) | |
tree | 153689ec11cdc3a1c3a23ef6fb6354a5451fb19a /progs/tests | |
parent | 79e0dad79e24668fbb35aad970cb2b7b629a11fa (diff) |
Moving NV_fragment_program tests to ARB_fragment_program
Diffstat (limited to 'progs/tests')
-rw-r--r-- | progs/tests/Makefile.X11 | 4 | ||||
-rw-r--r-- | progs/tests/arbfptest1.c | 210 | ||||
-rw-r--r-- | progs/tests/arbfptexture.c | 152 |
3 files changed, 365 insertions, 1 deletions
diff --git a/progs/tests/Makefile.X11 b/progs/tests/Makefile.X11 index ff2e040301f..8388a1afb9f 100644 --- a/progs/tests/Makefile.X11 +++ b/progs/tests/Makefile.X11 @@ -9,7 +9,9 @@ LIBDIR = $(TOP)/lib LIBS = -L$(LIBDIR) $(APP_LIB_DEPS) SOURCES = antialias.c \ - arbvptest1.c \ + arbfptest1.c \ + arbfptexture.c \ + arbvptest1.c \ arbvptest3.c \ arbvptorus.c \ arbvpwarpmesh.c \ diff --git a/progs/tests/arbfptest1.c b/progs/tests/arbfptest1.c new file mode 100644 index 00000000000..ed1ed01652e --- /dev/null +++ b/progs/tests/arbfptest1.c @@ -0,0 +1,210 @@ +/* Test GL_ARB_fragment_program */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + + glColor4f(0, 0.5, 0, 1); + glColor4f(0, 1, 0, 1); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 0, 1); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + +static void load_program(const char *prog, GLuint prognum) +{ + int a; + GLint errorpos, errno; + + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prognum); + glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog), (const GLubyte *) prog); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + + for (a=-10; a<10; a++) + { + if ((errorpos+a < 0) || (errorpos+a >= strlen(prog))) continue; + printf("%c", prog[errorpos+a]); + } + printf("\n"); + exit(1); + } +} + +static void Init( void ) +{ + static const char *prog0 = + "!!ARBfp1.0\n" + "TEMP R0, RC, HC, H0, H1, H2, H3, H30 ;\n" + "MUL result.color, R0, fragment.position; \n" + "ADD result.color, H3, fragment.texcoord; \n" + "ADD_SAT result.color, H3, fragment.texcoord; \n" + "MUL result.color.xy, R0.wzyx, fragment.position; \n" + "MUL result.color, H0, fragment.position; \n" + "MUL result.color, -H0, fragment.position; \n" + "MOV RC, H1; \n" + "MOV HC, H2; \n" + "END \n" + ; + /* masked updates, defines, declarations */ + static const char *prog1 = + "!!ARBfp1.0\n" + "PARAM foo = {1., 2., 3., 4.}; \n" + "PARAM foo2 = 5.; \n" + "PARAM foo3 = {5., 6., 7., 8.}; \n" + "PARAM bar = 3.; \n" + "TEMP R0, R1, RC, EQ, NE, bar2; \n" + "ALIAS bar3 = bar; \n" + "MOV result.color.xy, R0; \n" + "MOV result.color, R0; \n" + "MOV result.color.xyzw, R0; \n" + "MOV result.color.xy, R0; \n" + "MOV RC.x, R1.x; \n" + "KIL NE; \n" + "KIL EQ.xyxy; \n" + "END \n" + ; + + /* texture instructions */ + static const char *prog2 = + "!!ARBfp1.0\n" + "TEMP R0, R1, R2, R3;\n" + "TEX R0, fragment.texcoord, texture[1], 2D; \n" + "TEX R1, fragment.texcoord[1], texture[1], CUBE; \n" + "TEX R2, fragment.texcoord[2], texture[2], 3D; \n" + "TXP R3, fragment.texcoord[3], texture[3], RECT; \n" + "MUL result.color, R0, fragment.color; \n" + "END \n" + ; + + /* test negation, absolute value */ + static const char *prog3 = + "!!ARBfp1.0\n" + "TEMP R0, R1;\n" + "MOV R0, R1; \n" + "MOV R0, -R1; \n" + "MOV result.color, R0; \n" + "END \n" + ; + + /* literal constant sources */ + static const char *prog4 = + "!!ARBfp1.0\n" + "TEMP R0, R1;\n" + "PARAM Pi = 3.14159; \n" + "MOV R0, {1., -2., +3., 4.}; \n" + "MOV R0, 5.; \n" + "MOV R0, -5.; \n" + "MOV R0, 5.; \n" + "MOV R0, Pi; \n" + "MOV result.color, R0; \n" + "END \n" + ; + + /* change the fragment color in a simple way */ + static const char *prog10 = + "!!ARBfp1.0\n" + "PARAM blue = {0., 0., 1., 0.};\n" + "PARAM color = {1., 0., 0., 1.};\n" + "TEMP R0; \n" + "MOV R0, fragment.color; \n" + "#ADD result.color, R0, fragment.color; \n" + "#ADD result.color, blue, fragment.color; \n" + "#ADD result.color, {1., 0., 0., 0.}, fragment.color; \n" + "ADD result.color, color, fragment.color; \n" + "END \n" + ; + + GLuint progs[20]; + + glGenProgramsARB(20, progs); + assert(progs[0]); + assert(progs[1]); + assert(progs[0] != progs[1]); + + + printf("program 0:\n"); + load_program(prog0, progs[0]); + printf("program 1:\n"); + load_program(prog1, progs[1]); + printf("program 2:\n"); + load_program(prog2, progs[2]); + printf("program 3:\n"); + load_program(prog3, progs[3]); + printf("program 4:\n"); + load_program(prog4, progs[4]); + printf("program 10:\n"); + load_program(prog10, progs[5]); + + + glEnable(GL_FRAGMENT_PROGRAM_ARB); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_ALWAYS, 0.0); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/arbfptexture.c b/progs/tests/arbfptexture.c new file mode 100644 index 00000000000..cee8bfa659a --- /dev/null +++ b/progs/tests/arbfptexture.c @@ -0,0 +1,152 @@ +/* GL_ARB_fragment_program texture test */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + +#include "readtex.c" + + +#define TEXTURE_FILE "../images/girl.rgb" + +static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1.0, 0.0, 0.0); + glRotatef(Yrot, 0.0, 1.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + + glBegin(GL_POLYGON); + glColor4f(1.0, 1.0, 1.0, 1); glTexCoord2f(0, 0); glVertex2f(-1, -1); + glColor4f(0.2, 0.2, 1.0, 1); glTexCoord2f(1, 0); glVertex2f( 1, -1); + glColor4f(0.2, 1.0, 0.2, 1); glTexCoord2f(1, 1); glVertex2f( 1, 1); + glColor4f(1.0, 0.2, 0.2, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -8.0 ); +} + + +static void SpecialKey( int key, int x, int y ) +{ + float step = 3.0; + (void) x; + (void) y; + + switch (key) { + case GLUT_KEY_UP: + Xrot += step; + break; + case GLUT_KEY_DOWN: + Xrot -= step; + break; + case GLUT_KEY_LEFT: + Yrot += step; + break; + case GLUT_KEY_RIGHT: + Yrot -= step; + break; + } + glutPostRedisplay(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + static const char *modulate2D = + "!!ARBfp1.0\n" + "TEMP R0;\n" + "TEX R0, fragment.texcoord[0], texture[0], 2D; \n" + "MUL result.color, R0, fragment.color; \n" + "END" + ; + GLuint modulateProg; + GLuint Texture; + + if (!glutExtensionSupported("GL_ARB_fragment_program")) { + printf("Error: GL_ARB_fragment_program not supported!\n"); + exit(1); + } + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* Setup the fragment program */ + glGenProgramsARB(1, &modulateProg); + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg); + glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(modulate2D), (const GLubyte *)modulate2D); + + printf("glGetError = 0x%x\n", (int) glGetError()); + printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n", + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + assert(glIsProgramARB(modulateProg)); + + glEnable(GL_FRAGMENT_PROGRAM_ARB); + + /* Load texture */ + glGenTextures(1, &Texture); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + /* XXX this enable shouldn't really be needed!!! */ + glEnable(GL_TEXTURE_2D); + + glClearColor(.3, .3, .3, 0); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} |