2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Ben Holmes <shranzel@hotmail.com>
28 * this test draws quads with RGBA and BGRA using glVertexAttribArray.
29 * two quads are drawn without blending and two are drawn with alpha blending.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_width
= 400;
39 config
.window_height
= 300;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 PIGLIT_GL_TEST_CONFIG_END
49 static GLfloat verts
[12] = {225.0, 175.0, 0.0,
55 static GLubyte colors
[16] = {255, 0, 0, 127,
61 static const char *vertShaderText
=
62 "attribute vec2 textureCoords;\n"
63 "attribute vec4 vColor;\n"
64 "varying vec4 vertColor;\n"
67 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
68 " vertColor = vColor;\n"
71 static const char *fragShaderText
=
72 "varying vec4 vertColor;\n"
75 " gl_FragColor = vertColor;\n"
84 vs
= glCreateShader(GL_VERTEX_SHADER
);
85 fs
= glCreateShader(GL_FRAGMENT_SHADER
);
86 glShaderSource(vs
, 1, (const GLchar
**) &vertShaderText
, NULL
);
87 glShaderSource(fs
, 1, (const GLchar
**) &fragShaderText
, NULL
);
89 glGetShaderiv(vs
, GL_COMPILE_STATUS
, &stat
);
91 printf("error compiling vertex shader!\n");
95 glGetShaderiv(fs
, GL_COMPILE_STATUS
, &stat
);
97 printf("error compiling fragment shader!\n");
101 prog
= glCreateProgram();
102 glAttachShader(prog
, vs
);
103 glAttachShader(prog
, fs
);
104 glBindAttribLocation(prog
, 1, "vColor");
108 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, 3*sizeof(GLfloat
),
111 glEnableVertexAttribArray(0);
116 piglit_init(int argc
, char **argv
)
118 piglit_require_gl_version(20);
120 piglit_require_extension("GL_EXT_vertex_array_bgra");
122 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
124 glClearColor(0.6, 0.6, 0.6, 1.0);
133 GLboolean pass
= GL_TRUE
;
134 GLfloat red
[3]={1.0, 0.0, 0.0};
135 GLfloat blue
[3]={0.0, 0.0, 1.0};
136 GLfloat greyRed
[3]={1.0, 0.6, 0.6};
137 GLfloat greyBlue
[3]={0.6, 0.6, 1.0};
139 glClear(GL_COLOR_BUFFER_BIT
);
141 glDisableVertexAttribArray(1);
142 glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE
, GL_TRUE
,
143 4*sizeof(GLubyte
), colors
);
144 glEnableVertexAttribArray(1);
146 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
149 glTranslatef(75.0, 0.0, 0.0);
151 glDisableVertexAttribArray(1);
152 glVertexAttribPointer(1, GL_BGRA
, GL_UNSIGNED_BYTE
, GL_TRUE
,
153 4*sizeof(GLubyte
), colors
);
154 glEnableVertexAttribArray(1);
156 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
161 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
164 glTranslatef(0.0, -75.0, 0.0);
166 glDisableVertexAttribArray(1);
167 glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE
, GL_TRUE
,
168 4*sizeof(GLubyte
), colors
);
169 glEnableVertexAttribArray(1);
171 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
174 glTranslatef(75.0, 0.0, 0.0);
176 glDisableVertexAttribArray(1);
177 glVertexAttribPointer(1, GL_BGRA
, GL_UNSIGNED_BYTE
, GL_TRUE
,
178 4*sizeof(GLubyte
), colors
);
179 glEnableVertexAttribArray(1);
181 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
186 pass
= pass
&& piglit_probe_pixel_rgb(200, 200, red
);
187 pass
= pass
&& piglit_probe_pixel_rgb(275, 200, blue
);
188 pass
= pass
&& piglit_probe_pixel_rgb(200, 125, greyRed
);
189 pass
= pass
&& piglit_probe_pixel_rgb(275, 125, greyBlue
);
192 piglit_present_results();
196 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;