ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_direct_state_access / texture-params.c
blob22f33dd5af88788b28ea22712f611a6c18d20b56
1 /*
2 * Copyright 2014 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.
24 /** @file texture-params.c
26 * Trivially validates all the TextureParameter and GetTextureParameter entry
27 * points by setting something, then getting it.
30 #include "piglit-util-gl.h"
31 #include <math.h>
33 /* Copied from Mesa. TODO: How do other drivers do this? */
34 /* a close approximation: */
35 #define FLOAT_TO_INT(X) ( (GLint) (2147483647.0 * (X)) )
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_core_version = 31;
40 config.supports_gl_compat_version = 20;
42 config.window_visual = PIGLIT_GL_VISUAL_RGBA |
43 PIGLIT_GL_VISUAL_DOUBLE;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 void
49 piglit_init(int argc, char **argv)
51 piglit_require_extension("GL_ARB_direct_state_access");
54 enum piglit_result
55 piglit_display(void)
57 bool pass = true;
58 int i;
59 GLuint name;
60 GLfloat scalarf = -100.0f;
61 GLfloat paramf;
62 GLfloat colorfv[4] = { 1.0f, 0.2f, 0.3f, 0.4f };
63 GLfloat paramfv[4];
64 GLint scalari = 5;
65 GLint parami;
66 GLenum scalare = GL_NEAREST;
67 GLenum parame;
68 GLint coloriv[4];
69 GLint colorIiv[4] = {256, 50, -75, 100};
70 GLint paramIiv[4];
71 GLuint colorIuiv[4] = {256, 50, 75, 100};
72 GLuint paramIuiv[4];
73 GLenum swizzle[4] = {GL_RED, GL_BLUE, GL_RED, GL_BLUE};
74 GLenum paramse[4];
76 glCreateTextures(GL_TEXTURE_2D, 1, &name);
78 /* f case */
79 glTextureParameterf(name, GL_TEXTURE_MIN_LOD, scalarf);
80 glGetTextureParameterfv(name, GL_TEXTURE_MIN_LOD, &paramf);
81 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
82 if (paramf != scalarf) {
83 printf("glTextureParameterf did not correctly set "
84 "GL_TEXTURE_MIN_LOD.\n\tValue returned by "
85 "glGetTextureParameterfv was %.2f (expected %.2f).\n",
86 paramf, scalarf);
87 pass = false;
90 /* fv case */
91 glTextureParameterfv(name, GL_TEXTURE_BORDER_COLOR, colorfv);
92 glGetTextureParameterfv(name, GL_TEXTURE_BORDER_COLOR, &paramfv[0]);
93 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
94 for (i = 0; i < 4; ++i) {
95 if (paramfv[i] != colorfv[i]) {
96 printf("glTextureParameterfv did not correctly set "
97 "GL_TEXTURE_BORDER_COLOR.\n\tValue %i "
98 "returned by "
99 "glGetTextureParameterfv was %.2f "
100 "(expected %.2f).\n",
101 i, paramfv[i], colorfv[i]);
102 pass = false;
106 /* i case */
107 glTextureParameteri(name, GL_TEXTURE_MAX_LEVEL, scalari);
108 glGetTextureParameteriv(name, GL_TEXTURE_MAX_LEVEL, &parami);
109 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
110 if (parami != scalari) {
111 printf("glTextureParameteri did not correctly set "
112 "GL_TEXTURE_MAX_LEVEL.\n\tValue returned by "
113 "glGetTextureParameteriv was %i "
114 "(expected %i).\n",
115 parami, scalari);
116 pass = false;
119 /* i (enum) case */
120 glTextureParameteri(name, GL_TEXTURE_MIN_FILTER, scalare);
121 glGetTextureParameterIuiv(name, GL_TEXTURE_MIN_FILTER, &parame);
122 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
123 if (parame != scalare) {
124 printf("glTextureParameteri did not correctly set "
125 "GL_TEXTURE_MIN_FILTER.\n\tValue returned by "
126 "glGetTextureParameterIuiv was %s "
127 "(expected %s).\n",
128 piglit_get_gl_enum_name(parame),
129 piglit_get_gl_enum_name(scalare));
130 pass = false;
133 /* iv case */
134 for (i = 0; i < 4; ++i) {
135 coloriv[i] = FLOAT_TO_INT(colorfv[i]);
137 glTextureParameteriv(name, GL_TEXTURE_BORDER_COLOR, coloriv);
138 glGetTextureParameterfv(name, GL_TEXTURE_BORDER_COLOR, &paramfv[0]);
139 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
140 for (i = 0; i < 4; ++i) {
141 if (fabs(paramfv[i] - colorfv[i]) >= piglit_tolerance[i]) {
142 printf("glTextureParameteriv did not correctly set "
143 "GL_TEXTURE_BORDER_COLOR.\n\tValue %i "
144 "returned by "
145 "glGetTextureParameterfv was %.2f "
146 "(expected %.2f).\n",
147 i, paramfv[i], colorfv[i]);
148 pass = false;
152 /* Iiv case */
153 glTextureParameterIiv(name, GL_TEXTURE_BORDER_COLOR, colorIiv);
154 glGetTextureParameterIiv(name, GL_TEXTURE_BORDER_COLOR, &paramIiv[0]);
155 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
156 for (i = 0; i < 4; ++i) {
157 if (paramIiv[i] != colorIiv[i]) {
158 printf("glTextureParameterIiv did not correctly set "
159 "GL_TEXTURE_BORDER_COLOR.\n\tValue %i "
160 "returned by "
161 "glGetTextureParameterIiv was %i "
162 "(expected %i).\n",
163 i, paramIiv[i], colorIiv[i]);
164 pass = false;
168 /* Iuiv case */
169 glTextureParameterIuiv(name, GL_TEXTURE_BORDER_COLOR, colorIuiv);
170 glGetTextureParameterIuiv(name, GL_TEXTURE_BORDER_COLOR,
171 &paramIuiv[0]);
172 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
173 for (i = 0; i < 4; ++i) {
174 if (paramIuiv[i] != colorIuiv[i]) {
175 printf("glTextureParameterIuiv did not correctly set "
176 "GL_TEXTURE_BORDER_COLOR.\n\tValue %i "
177 "returned by "
178 "glGetTextureParameterIuiv was %i "
179 "(expected %i).\n",
180 i, paramIuiv[i], colorIuiv[i]);
181 pass = false;
185 /* Iuiv (enum) case */
186 glTextureParameterIuiv(name, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
187 glGetTextureParameterIuiv(name, GL_TEXTURE_SWIZZLE_RGBA, &paramse[0]);
188 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
189 for (i = 0; i < 4; ++i) {
190 if (paramse[i] != swizzle[i]) {
191 printf("glTextureParameterIuiv did not correctly set "
192 "GL_TEXTURE_SWIZZLE_RGBA.\n\tValue %i "
193 "returned by "
194 "glGetTextureParameterIuiv was %s "
195 "(expected %s).\n",
197 piglit_get_gl_enum_name(paramse[i]),
198 piglit_get_gl_enum_name(swizzle[i]));
199 pass = false;
204 return pass ? PIGLIT_PASS : PIGLIT_FAIL;