aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/extras/Mesa_6.4.2/progs/tests/fptest1.c
blob: d0bcdaa226de1f9f6fb51ba9542f01e58ada9854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* Test GL_NV_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 Init( void )
{
   static const char *prog0 =
      "!!FP1.0\n"
      "MUL   o[COLR], R0, f[WPOS]; \n"
      "ADD   o[COLH], H3, f[TEX0]; \n"
      "ADD_SAT o[COLH], H3, f[TEX0]; \n"
      "ADDX o[COLH], H3, f[TEX0]; \n"
      "ADDHC o[COLH], H3, f[TEX0]; \n"
      "ADDXC o[COLH], H3, f[TEX0]; \n"
      "ADDXC_SAT o[COLH], H30, f[TEX0]; \n"
      "MUL   o[COLR].xy, R0.wzyx, f[WPOS]; \n"
      "MUL   o[COLR], H0, f[WPOS]; \n"
      "MUL   o[COLR], -H0, f[WPOS]; \n"
      "MOV   RC, H1; \n"
      "MOV   HC, H2; \n"
      "END \n"
      ;

   /* masked updates, defines, declarations */
   static const char *prog1 =
      "!!FP1.0\n"
      "DEFINE foo = {1, 2, 3, 4}; \n"
      "DEFINE foo2 = 5; \n"
      "DECLARE foo3 = {5, 6, 7, 8}; \n"
      "DECLARE bar = 3; \n"
      "DECLARE bar2; \n"
      "DECLARE bar3 = bar; \n"
      "#DECLARE bar4 = { a, b, c, d }; \n"
      "MOV o[COLR].xy,   R0; \n"
      "MOV o[COLR] (NE), R0; \n"
      "MOV o[COLR] (NE.wzyx), R0; \n"
      "MOV o[COLR].xy (NE.wzyx), R0; \n"
      "MOV RC.x (EQ), R1.x; \n"
      "KIL NE; \n"
      "KIL EQ.xyxy; \n"
      "END \n"
      ;

   /* texture instructions */
   static const char *prog2 =
      "!!FP1.0\n"
      "TEX R0, f[TEX0], TEX0, 2D; \n"
      "TEX R1, f[TEX1], TEX1, CUBE; \n"
      "TEX R2, f[TEX2], TEX2, 3D; \n"
      "TXP R3, f[TEX3], TEX3, RECT; \n"
      "TXD R3, R2, R1, f[TEX3], TEX3, RECT; \n"
      "MUL o[COLR], R0, f[COL0]; \n"
      "END \n"
      ;

   /* test negation, absolute value */
   static const char *prog3 =
      "!!FP1.0\n"
      "MOV R0, -R1; \n"
      "MOV R0, +R1; \n"
      "MOV R0, |-R1|; \n"
      "MOV R0, |+R1|; \n"
      "MOV R0, -|R1|; \n"
      "MOV R0, +|R1|; \n"
      "MOV R0, -|-R1|; \n"
      "MOV R0, -|+R1|; \n"
      "MOV o[COLR], R0; \n"
      "END \n"
      ;

   /* literal constant sources */
   static const char *prog4 =
      "!!FP1.0\n"
      "DEFINE 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 o[COLR], R0; \n"
      "END \n"
      ;

   /* change the fragment color in a simple way */
   static const char *prog10 =
      "!!FP1.0\n"
      "DEFINE blue = {0, 0, 1, 0};\n"
      "DECLARE color; \n"
      "MOV R0, f[COL0]; \n"
      "#ADD o[COLR], R0, f[COL0]; \n"
      "#ADD o[COLR], blue, f[COL0]; \n"
      "#ADD o[COLR], {1, 0, 0, 0}, f[COL0]; \n"
      "ADD o[COLR], color, f[COL0]; \n"
      "END \n"
      ;

   GLuint progs[20];

   glGenProgramsNV(20, progs);
   assert(progs[0]);
   assert(progs[1]);
   assert(progs[0] != progs[1]);

#if 0
   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[0],
                   strlen(prog0),
                   (const GLubyte *) prog0);
   assert(glIsProgramNV(progs[0]));
#endif

   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[1],
                   strlen(prog1),
                   (const GLubyte *) prog1);
   assert(glIsProgramNV(progs[1]));

   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[2],
                   strlen(prog2),
                   (const GLubyte *) prog2);
   assert(glIsProgramNV(progs[2]));
   glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[2]);

   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[3],
                   strlen(prog3),
                   (const GLubyte *) prog3);
   assert(glIsProgramNV(progs[3]));
   glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[3]);

   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[4],
                   strlen(prog4),
                   (const GLubyte *) prog4);
   assert(glIsProgramNV(progs[4]));
   glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[4]);


   /* a real program */
   glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[10],
                   strlen(prog10),
                   (const GLubyte *) prog10);
   assert(glIsProgramNV(progs[10]));
   glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[10]);

   glProgramNamedParameter4fNV(progs[10],
                               strlen("color"), (const GLubyte *) "color",
                               1, 0, 0, 1);

   glEnable(GL_FRAGMENT_PROGRAM_NV);
   glEnable(GL_ALPHA_TEST);
   glAlphaFunc(GL_ALWAYS, 0.0);

   printf("glGetError = %d\n", (int) glGetError());
}


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;
}