2 * (C) Copyright IBM Corporation 2005
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Simple test of GL_ARB_texture_env_crossbar functionality. Several squares
29 * are drawn with different texture combine modes, but all should be rendered
30 * with the same final color.
32 * \author Ian Romanick <idr@us.ibm.com>
40 static const GLint tests
[][8] = {
41 { 1, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
42 2, GL_REPLACE
, GL_TEXTURE
, GL_PRIMARY_COLOR
},
43 { 3, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
44 2, GL_SUBTRACT
, GL_TEXTURE0
, GL_TEXTURE1
},
45 { 2, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
46 2, GL_REPLACE
, GL_TEXTURE0
, GL_TEXTURE0
},
47 { 2, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
48 1, GL_SUBTRACT
, GL_TEXTURE0
, GL_TEXTURE1
},
49 { 3, GL_ADD
, GL_TEXTURE1
, GL_TEXTURE1
,
50 2, GL_MODULATE
, GL_TEXTURE1
, GL_PREVIOUS
},
51 { 3, GL_ADD
, GL_TEXTURE1
, GL_TEXTURE1
,
52 4, GL_MODULATE
, GL_TEXTURE0
, GL_PREVIOUS
},
55 #define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
57 static int Width
= 100 * (NUM_TESTS
+ 1);
58 static int Height
= 100;
59 static int Interactive
= 1;
62 static void DoFrame( void )
66 glClearColor(0.0, 0.0, 1.0, 0);
67 glClear( GL_COLOR_BUFFER_BIT
);
71 /* This is the "reference" square.
74 glActiveTexture( GL_TEXTURE0
);
75 glDisable( GL_TEXTURE_2D
);
76 glActiveTexture( GL_TEXTURE1
);
77 glDisable( GL_TEXTURE_2D
);
79 glTranslatef(1.5, 0.0, 0.0);
81 glColor3f( 0.5, 0.5, 0.5 );
88 for ( i
= 0 ; i
< NUM_TESTS
; i
++ ) {
89 glActiveTexture( GL_TEXTURE0
);
90 glEnable( GL_TEXTURE_2D
);
91 glBindTexture( GL_TEXTURE_2D
, tests
[i
][0] );
92 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
93 glTexEnvi( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, tests
[i
][1] );
94 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, tests
[i
][2] );
95 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE1_RGB
, tests
[i
][3] );
97 glActiveTexture( GL_TEXTURE1
);
98 glEnable( GL_TEXTURE_2D
);
99 glBindTexture( GL_TEXTURE_2D
, tests
[i
][4] );
100 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
101 glTexEnvi( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, tests
[i
][5] );
102 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, tests
[i
][6] );
103 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE1_RGB
, tests
[i
][7] );
112 static int DoTest( void )
115 GLfloat probe
[NUM_TESTS
+1][4];
119 glReadBuffer( GL_BACK
);
122 for( i
= 0; i
<= NUM_TESTS
; ++i
) {
123 glReadPixels(Width
*(2*i
+1)/((NUM_TESTS
+1)*2), Height
/2, 1, 1, GL_RGBA
, GL_FLOAT
, probe
[i
]);
124 printf("Probe %i: %f,%f,%f\n", i
, probe
[i
][0], probe
[i
][1], probe
[i
][2]);
125 dr
= probe
[i
][0] - 0.5f
;
126 dg
= probe
[i
][1] - 0.5f
;
127 db
= probe
[i
][2] - 0.5f
;
128 printf(" Delta: %f,%f,%f\n", dr
, dg
, db
);
129 if (dr
> dmax
) dmax
= dr
;
130 else if (-dr
> dmax
) dmax
= -dr
;
131 if (dg
> dmax
) dmax
= dg
;
132 else if (-dg
> dmax
) dmax
= -dg
;
133 if (db
> dmax
) dmax
= db
;
134 else if (-db
> dmax
) dmax
= -db
;
137 printf("Max delta: %f\n", dmax
);
139 if (dmax
>= 0.07) // roughly 1/128
145 static void Display( void )
153 printf("\nFirst frame\n-----------\n");
158 printf("\nSecond frame\n------------\n");
159 glMatrixMode( GL_PROJECTION
);
161 glOrtho( 0, 3*(NUM_TESTS
+1), -1.5, 1.5, -1, 1 );
162 glMatrixMode( GL_MODELVIEW
);
169 if (retry
&& success
) {
170 printf("\nPIGLIT: { 'result': 'pass' }\n");
171 } else if (retry
|| success
) {
172 printf("\nPIGLIT: { 'result': 'warn', 'note': 'Inconsistent results in first and second frame' }\n");
174 printf("\nPIGLIT: { 'result': 'fail' }\n");
182 static void Reshape( int width
, int height
)
186 glViewport( 0, 0, width
, height
);
187 glMatrixMode( GL_PROJECTION
);
189 glOrtho( 0, 3*(NUM_TESTS
+1), -1.5, 1.5, -1, 1 );
190 glMatrixMode( GL_MODELVIEW
);
195 static void Key( unsigned char key
, int x
, int y
)
208 static void Init( void )
210 const char * const ver_string
= (const char * const)
211 glGetString( GL_VERSION
);
212 float ver
= strtof( ver_string
, NULL
);
217 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
218 printf("GL_VERSION = %s\n", ver_string
);
220 if ( (!glutExtensionSupported("GL_ARB_multitexture")
222 || (!glutExtensionSupported("GL_ARB_texture_env_combine")
223 && !glutExtensionSupported("GL_EXT_texture_env_combine")
225 || (!glutExtensionSupported("GL_ARB_texture_env_crossbar")
226 && !glutExtensionSupported("GL_NV_texture_env_combine4")
228 printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
229 "GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
230 "Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
231 "OpenGL 1.4) are also required.\n");
233 printf("PIGLIT: {'result': 'fail' }\n");
237 glGetIntegerv( GL_MAX_TEXTURE_UNITS
, & tex_units
);
238 if ( tex_units
< 2 ) {
239 printf("\nSorry, this program requires at least 2 texture units.\n");
241 printf("PIGLIT: {'result': 'fail' }\n");
246 printf("\nAll %u squares should be the same color.\n", NUM_TESTS
+ 1);
248 (void) memset( temp
, 0x00, sizeof( temp
) );
249 glBindTexture( GL_TEXTURE_2D
, 1 );
250 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
251 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
252 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
253 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
255 (void) memset( temp
, 0x7f, sizeof( temp
) );
256 glBindTexture( GL_TEXTURE_2D
, 2 );
257 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
258 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
259 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
260 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
262 (void) memset( temp
, 0xff, sizeof( temp
) );
263 glBindTexture( GL_TEXTURE_2D
, 3 );
264 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
265 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
266 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
267 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
269 (void) memset( temp
, 0x3f, sizeof( temp
) );
270 glBindTexture( GL_TEXTURE_2D
, 4 );
271 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
272 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
273 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
274 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
277 glNewList( 1, GL_COMPILE
);
278 glTranslatef(3.0, 0, 0);
280 glColor3f( 0.9, 0.0, 0.0 );
281 glMultiTexCoord2f( GL_TEXTURE0
, 0.5, 0.5 );
282 glMultiTexCoord2f( GL_TEXTURE1
, 0.5, 0.5 );
290 Reshape(Width
, Height
);
294 int main( int argc
, char *argv
[] )
296 glutInit( &argc
, argv
);
297 if (argc
== 2 && !strcmp(argv
[1], "-auto"))
299 glutInitWindowPosition( 0, 0 );
300 glutInitWindowSize( Width
, Height
);
301 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
302 glutCreateWindow( "GL_ARB_texture_env_crossbar test" );
303 glutReshapeFunc( Reshape
);
304 glutKeyboardFunc( Key
);
305 glutDisplayFunc( Display
);