fix the spelling in whole piglit
[piglit.git] / tests / general / bgra-vert-attrib-pointer.c
blob96fee867d83b3c9b52cc66e2085b64bfb1ccaf15
1 /*
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
13 * Software.
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.
23 * Authors:
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
44 static GLint prog;
45 static GLint fs;
46 static GLint vs;
49 static GLfloat verts[12] = {225.0, 175.0, 0.0,
50 225.0, 225.0, 0.0,
51 175.0, 175.0, 0.0,
52 175.0, 225.0, 0.0};
55 static GLubyte colors[16] = {255, 0, 0, 127,
56 255, 0, 0, 127,
57 255, 0, 0, 127,
58 255, 0, 0, 127};
61 static const char *vertShaderText =
62 "attribute vec2 textureCoords;\n"
63 "attribute vec4 vColor;\n"
64 "varying vec4 vertColor;\n"
65 "void main()\n"
66 "{ \n"
67 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
68 " vertColor = vColor;\n"
69 "} \n";
71 static const char *fragShaderText =
72 "varying vec4 vertColor;\n"
73 "void main()\n"
74 "{ \n"
75 " gl_FragColor = vertColor;\n"
76 "} \n";
79 static void
80 compileLinkProg(void)
82 GLint stat;
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);
88 glCompileShader(vs);
89 glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
90 if (!stat) {
91 printf("error compiling vertex shader!\n");
92 exit(1);
94 glCompileShader(fs);
95 glGetShaderiv(fs, GL_COMPILE_STATUS, &stat);
96 if (!stat) {
97 printf("error compiling fragment shader!\n");
98 exit(1);
101 prog = glCreateProgram();
102 glAttachShader(prog, vs);
103 glAttachShader(prog, fs);
104 glBindAttribLocation(prog, 1, "vColor");
105 glLinkProgram(prog);
106 glUseProgram(prog);
108 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat),
109 verts);
111 glEnableVertexAttribArray(0);
115 void
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);
126 compileLinkProg();
130 enum piglit_result
131 piglit_display(void)
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);
148 glPushMatrix();
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);
158 glPopMatrix();
160 glEnable(GL_BLEND);
161 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
163 glPushMatrix();
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);
173 glPushMatrix();
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);
183 glPopMatrix();
184 glPopMatrix();
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);
191 glFinish();
192 piglit_present_results();
194 glDisable(GL_BLEND);
196 return pass ? PIGLIT_PASS : PIGLIT_FAIL;