4 * Copyright © 2009 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Ben Holmes <shranzel@hotmail.com>
30 * this test draws 256 quads utilizing every permutation of texture
31 * swizzling available.
34 #include "piglit-util.h"
36 #ifndef GL_TEXTURE_SWIZZLE_RGBA_EXT
37 #define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46
40 int piglit_width
= 400, piglit_height
= 300;
41 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
45 static GLfloat verts
[12] = {17.0, 1.0, 0.0,
50 static GLfloat texCoords
[8] = {1.0, 0.0,
65 GLfloat texData
[width
][height
][4];
66 for (i
= 0; i
< width
; ++i
) {
67 for (j
= 0; j
< height
; ++j
) {
69 texData
[i
][j
][0] = 1.0;
70 texData
[i
][j
][1] = 0.0;
71 texData
[i
][j
][2] = 1.0;
72 texData
[i
][j
][3] = 0.0;
75 texData
[i
][j
][0] = 0.0;
76 texData
[i
][j
][1] = 1.0;
77 texData
[i
][j
][2] = 0.0;
78 texData
[i
][j
][3] = 1.0;
83 glGenTextures(1, tex
);
84 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
85 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP
, GL_FALSE
);
86 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
87 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
88 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
89 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
90 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, width
, height
, 0, GL_RGBA
,
100 piglit_init(int argc
, char **argv
)
103 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
105 piglit_require_extension("GL_EXT_texture_swizzle");
107 glEnable(GL_TEXTURE_2D
);
109 glBlendFunc(GL_ONE
, GL_SRC_ALPHA
);
110 glClearColor(0.6, 0.6, 0.6, 1.0);
118 GLenum rgba
[4] = {GL_RED
, GL_GREEN
, GL_BLUE
, GL_ALPHA
};
120 GLboolean pass
= GL_TRUE
;
122 glClear(GL_COLOR_BUFFER_BIT
);
123 glEnableClientState(GL_VERTEX_ARRAY
);
124 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
126 glVertexPointer(3, GL_FLOAT
, 0, verts
);
127 glTexCoordPointer(2, GL_FLOAT
, 0, texCoords
);
129 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
133 glTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_SWIZZLE_RGBA_EXT
, (GLint
*) rgba
);
135 for(k
= 0; k
< 4; ++k
) {
137 for(j
= 0; j
< 4; ++j
) {
138 for(i
= 0; i
< 4; ++i
) {
141 glTexParameteriv(GL_TEXTURE_2D
,
142 GL_TEXTURE_SWIZZLE_RGBA_EXT
,
145 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
147 glTranslatef(17.0, 0.0, 0.0);
149 glTexParameteriv(GL_TEXTURE_2D
,
150 GL_TEXTURE_SWIZZLE_RGBA_EXT
,
153 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
155 glTranslatef(17.0, 0.0, 0.0);
157 glTexParameteriv(GL_TEXTURE_2D
,
158 GL_TEXTURE_SWIZZLE_RGBA_EXT
,
161 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
163 glTranslatef(17.0, 0.0, 0.0);
165 glTexParameteriv(GL_TEXTURE_2D
,
166 GL_TEXTURE_SWIZZLE_RGBA_EXT
,
169 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
183 glTranslatef(0.0, 17.0, 0.0);
201 glTranslatef(85.0, 0.0, 0.0);
225 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
228 //probing is done left-to-right, bottom-to-top, by column
229 //and two probes are done per quad
236 static const GLfloat greyGreen
[3] = {0.6, 1.0, 0.6};
237 static const GLfloat green
[3] = {0.0, 1.0, 0.0};
238 static const GLfloat greyPink
[3] = {1.0, 0.6, 1.0};
239 static const GLfloat pink
[3] = {1.0, 0.0, 1.0};
240 static const GLfloat greyBlueGreen
[3] = {0.6, 1.0, 1.0};
241 static const GLfloat red
[3] = {1.0, 0.0, 0.0};
242 static const GLfloat blueGreen
[3] = {0.0, 1.0, 1.0};
243 static const GLfloat greyRed
[3] = {1.0, 0.6, 0.6};
244 static const GLfloat grey
[3] = {0.6, 0.6, 0.6};
245 static const GLfloat white
[3] = {1.0, 1.0, 1.0};
246 static const GLfloat black
[3] = {0.0, 0.0, 0.0};
247 static const GLfloat blue
[3] = {0.0, 0.0, 1.0};
248 static const GLfloat yellow
[3] = {1.0, 1.0, 0.0};
249 static const GLfloat greyYellow
[3] = {1.0, 1.0, 0.6};
250 static const GLfloat greyBlue
[3] = {0.6, 0.6, 1.0};
252 GLboolean pass
= GL_TRUE
;
254 static const struct {
256 const GLfloat
*color
;
278 {2,36,greyBlueGreen
},
282 {38,36,greyBlueGreen
},
287 {2,53,greyBlueGreen
},
291 {38,53,greyBlueGreen
},
386 {2,240,greyBlueGreen
},
390 {38,240,greyBlueGreen
},
395 {2,257,greyBlueGreen
},
399 {38,257,greyBlueGreen
},
444 {113,70,greyBlueGreen
},
448 {149,70,greyBlueGreen
},
453 {113,87,greyBlueGreen
},
457 {149,87,greyBlueGreen
},
480 {113,138,greyBlueGreen
},
484 {149,138,greyBlueGreen
},
489 {113,155,greyBlueGreen
},
493 {149,155,greyBlueGreen
},
517 {123,206,greyYellow
},
526 {123,223,greyYellow
},
568 {172,36,greyBlueGreen
},
572 {208,36,greyBlueGreen
},
577 {172,53,greyBlueGreen
},
581 {208,53,greyBlueGreen
},
607 {198,104,greyYellow
},
611 {234,104,greyYellow
},
616 {198,121,greyYellow
},
620 {234,121,greyYellow
},
643 {198,172,greyYellow
},
647 {234,172,greyYellow
},
652 {198,189,greyYellow
},
656 {234,189,greyYellow
},
676 {172,240,greyBlueGreen
},
680 {208,240,greyBlueGreen
},
685 {172,257,greyBlueGreen
},
689 {208,257,greyBlueGreen
},
734 {283,70,greyBlueGreen
},
738 {319,70,greyBlueGreen
},
743 {283,87,greyBlueGreen
},
747 {319,87,greyBlueGreen
},
770 {283,138,greyBlueGreen
},
774 {319,138,greyBlueGreen
},
779 {283,155,greyBlueGreen
},
783 {319,155,greyBlueGreen
},
803 {257,206,greyYellow
},
807 {293,206,greyYellow
},
812 {257,223,greyYellow
},
816 {293,223,greyYellow
},
842 for(i
= 0; pass
&& (expect
[i
].color
!= NULL
); ++i
) {
843 pass
= pass
&& piglit_probe_pixel_rgb(expect
[i
].x
,