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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/*
* (C) Copyright IBM Corporation 2005
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \file crossbar.c
*
* Simple test of GL_ARB_texture_env_crossbar functionality. Several squares
* are drawn with different texture combine modes, but all should be rendered
* with the same final color.
*
* \author Ian Romanick <idr@us.ibm.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "piglit-util-gl-common.h"
static const GLint tests[][8] = {
{ 1, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
2, GL_REPLACE, GL_TEXTURE, GL_PRIMARY_COLOR },
{ 3, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
2, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
{ 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
2, GL_REPLACE, GL_TEXTURE0, GL_TEXTURE0 },
{ 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
1, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
{ 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
2, GL_MODULATE, GL_TEXTURE1, GL_PREVIOUS },
{ 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
4, GL_MODULATE, GL_TEXTURE0, GL_PREVIOUS },
};
#define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
PIGLIT_GL_TEST_MAIN(
100 * (NUM_TESTS + 1) /*window_width*/,
100 /*window_height*/,
GLUT_RGB | GLUT_DOUBLE)
static void DoFrame( void )
{
unsigned i;
glClearColor(0.0, 0.0, 1.0, 0);
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
/* This is the "reference" square.
*/
glActiveTexture( GL_TEXTURE0 );
glDisable( GL_TEXTURE_2D );
glActiveTexture( GL_TEXTURE1 );
glDisable( GL_TEXTURE_2D );
glTranslatef(1.5, 0.0, 0.0);
glBegin(GL_QUADS);
glColor3f( 0.5, 0.5, 0.5 );
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
glVertex2f(-1, 1);
glEnd();
for ( i = 0 ; i < NUM_TESTS ; i++ ) {
glActiveTexture( GL_TEXTURE0 );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, tests[i][0] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][1] );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][2] );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][3] );
glActiveTexture( GL_TEXTURE1 );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, tests[i][4] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][5] );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][6] );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][7] );
glCallList(1);
}
glPopMatrix();
}
static int DoTest( void )
{
int i;
GLfloat probe[NUM_TESTS+1][4];
GLfloat dr, dg, db;
GLfloat dmax;
glReadBuffer( GL_BACK );
dmax = 0;
for( i = 0; i <= NUM_TESTS; ++i ) {
glReadPixels(piglit_width*(2*i+1)/((NUM_TESTS+1)*2), piglit_height/2, 1, 1, GL_RGBA, GL_FLOAT, probe[i]);
printf("Probe %i: %f,%f,%f\n", i, probe[i][0], probe[i][1], probe[i][2]);
dr = probe[i][0] - 0.5f;
dg = probe[i][1] - 0.5f;
db = probe[i][2] - 0.5f;
printf(" Delta: %f,%f,%f\n", dr, dg, db);
if (dr > dmax) dmax = dr;
else if (-dr > dmax) dmax = -dr;
if (dg > dmax) dmax = dg;
else if (-dg > dmax) dmax = -dg;
if (db > dmax) dmax = db;
else if (-db > dmax) dmax = -db;
}
printf("Max delta: %f\n", dmax);
if (dmax >= 0.07) // roughly 1/128
return 0;
else
return 1;
}
enum piglit_result
piglit_display(void)
{
if (piglit_automatic) {
DoFrame();
piglit_present_results();
return PIGLIT_PASS;
} else {
int success, retry;
printf("\nFirst frame\n-----------\n");
DoFrame();
success = DoTest();
piglit_present_results();
printf("\nSecond frame\n------------\n");
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 3*(NUM_TESTS+1), -1.5, 1.5, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
DoFrame();
retry = DoTest();
piglit_present_results();
if (retry && success)
return PIGLIT_PASS;
else
return PIGLIT_FAIL;
}
}
static void Reshape( int width, int height )
{
piglit_width = width;
piglit_height = height;
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 3*(NUM_TESTS+1), -1.5, 1.5, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
void piglit_init(int argc, char **argv)
{
const char * const ver_string = (const char * const)
glGetString( GL_VERSION );
float ver = strtof( ver_string, NULL );
GLint tex_units;
GLint temp[ 256 ];
glutReshapeFunc(Reshape);
if ( (!piglit_is_extension_supported("GL_ARB_multitexture")
&& (ver < 1.3))
|| (!piglit_is_extension_supported("GL_ARB_texture_env_combine")
&& !piglit_is_extension_supported("GL_EXT_texture_env_combine")
&& (ver < 1.3))
|| (!piglit_is_extension_supported("GL_ARB_texture_env_crossbar")
&& !piglit_is_extension_supported("GL_NV_texture_env_combine4")
&& (ver < 1.4)) ) {
printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
"GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
"Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
"OpenGL 1.4) are also required.\n");
if (!piglit_automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
glGetIntegerv( GL_MAX_TEXTURE_UNITS, & tex_units );
if ( tex_units < 2 ) {
printf("\nSorry, this program requires at least 2 texture units.\n");
if (!piglit_automatic)
printf("PIGLIT: {'result': 'fail' }\n");
exit(1);
}
if (piglit_automatic)
printf("\nAll %lu squares should be the same color.\n", (unsigned long) NUM_TESTS + 1);
(void) memset( temp, 0x00, sizeof( temp ) );
glBindTexture( GL_TEXTURE_2D, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
GL_RGBA, GL_UNSIGNED_BYTE, temp );
(void) memset( temp, 0x7f, sizeof( temp ) );
glBindTexture( GL_TEXTURE_2D, 2 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
GL_RGBA, GL_UNSIGNED_BYTE, temp );
(void) memset( temp, 0xff, sizeof( temp ) );
glBindTexture( GL_TEXTURE_2D, 3 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
GL_RGBA, GL_UNSIGNED_BYTE, temp );
(void) memset( temp, 0x3f, sizeof( temp ) );
glBindTexture( GL_TEXTURE_2D, 4 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
GL_RGBA, GL_UNSIGNED_BYTE, temp );
glNewList( 1, GL_COMPILE );
glTranslatef(3.0, 0, 0);
glBegin(GL_QUADS);
glColor3f( 0.9, 0.0, 0.0 );
glMultiTexCoord2f( GL_TEXTURE0, 0.5, 0.5 );
glMultiTexCoord2f( GL_TEXTURE1, 0.5, 0.5 );
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
glVertex2f(-1, 1);
glEnd();
glEndList();
}
|