ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_texture_swizzle / api.c
blob3ead58e026b433e254bbfd2b63e52f402786c4fb
1 /*
2 * Copyright © 2014 VMware, Inc.
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.
25 * Test GL_EXT_texture_swizzle API functions.
26 * Brian Paul
27 * 24 April 2014
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 12;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
37 PIGLIT_GL_TEST_CONFIG_END
40 static bool
41 test_get(GLenum pname, GLint expected)
43 GLint val;
45 glGetTexParameteriv(GL_TEXTURE_2D, pname, &val);
47 if (val != expected) {
48 printf("glGetTexParameteriv(%s) returned %s instead of %s\n",
49 piglit_get_gl_enum_name(pname),
50 piglit_get_gl_enum_name(val),
51 piglit_get_gl_enum_name(expected));
52 return false;
55 return true;
59 static bool
60 test_api(void)
62 static const GLint swz[4] = { GL_BLUE, GL_GREEN, GL_ALPHA, GL_ZERO };
63 GLint swzOut[4];
65 if (!piglit_khr_no_error) {
66 /* test bad param value */
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R_EXT, GL_RGBA);
68 if (!piglit_check_gl_error(GL_INVALID_ENUM))
69 return false;
72 /* test good param values */
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R_EXT, GL_ONE);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G_EXT, GL_ZERO);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B_EXT, GL_RED);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A_EXT, GL_BLUE);
78 if (!piglit_check_gl_error(GL_NO_ERROR))
79 return false;
81 if (!test_get(GL_TEXTURE_SWIZZLE_R_EXT, GL_ONE))
82 return false;
84 if (!test_get(GL_TEXTURE_SWIZZLE_G_EXT, GL_ZERO))
85 return false;
87 if (!test_get(GL_TEXTURE_SWIZZLE_B_EXT, GL_RED))
88 return false;
90 if (!test_get(GL_TEXTURE_SWIZZLE_A_EXT, GL_BLUE))
91 return false;
93 /* set all at once */
94 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA_EXT, swz);
96 if (!piglit_check_gl_error(GL_NO_ERROR))
97 return false;
99 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA_EXT, swzOut);
100 if (swzOut[0] != swz[0] ||
101 swzOut[1] != swz[1] ||
102 swzOut[2] != swz[2] ||
103 swzOut[3] != swz[3]) {
104 printf("glGetTexParameteriv(GL_TEXTURE_SWIZZLE_RGBA_EXT) failed\n");
105 return false;
108 return true;
112 enum piglit_result
113 piglit_display(void)
115 /* UNREACHED */
116 return PIGLIT_FAIL;
120 void
121 piglit_init(int argc, char **argv)
123 bool p;
125 piglit_require_extension("GL_EXT_texture_swizzle");
127 p = test_api();
128 piglit_report_result(p ? PIGLIT_PASS : PIGLIT_FAIL);