2 * Copyright © 2010 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 * Shuang He <shuang.he@intel.com>
25 * Ian Romanick <ian.d.romanick@intel.com>
28 #include "piglit-util-gl.h"
29 #include "object_purgeable.h"
31 #define FAIL_ON_ERROR(string) \
33 const GLenum err = glGetError(); \
34 if (err != GL_NO_ERROR) { \
35 fprintf(stderr, "%s generated error 0x%04x\n", \
41 #define EXPECT_AN_ERROR(string, expected) \
43 const GLenum err = glGetError(); \
44 if (err != expected) { \
45 fprintf(stderr, "%s generated error 0x%04x, " \
46 "but error 0x%04x (%s) was expected\n", \
47 string, err, expected, # expected); \
53 init_ObjectPurgeableAPI(void)
55 piglit_require_extension("GL_APPLE_object_purgeable");
59 #define NO_ENUM 0xffffffff
61 print_result(const char *fname
, const GLenum option
, const GLenum result
,
62 const GLenum expected_1
, const GLenum expected_2
)
64 fprintf(stderr
, "%s:%s: ", fname
, piglit_get_gl_enum_name(option
));
65 fprintf(stderr
, "expected 0x%04x (%s)",
66 expected_1
, piglit_get_gl_enum_name(expected_1
));
67 if (expected_2
!= NO_ENUM
)
68 fprintf(stderr
, " or 0x%04x (%s), ",
69 expected_2
, piglit_get_gl_enum_name(expected_2
));
70 fprintf(stderr
, ", got 0x%04x (%s).",
71 result
, piglit_get_gl_enum_name(result
));
76 * Check the setting and querying purgeability on object 0 generates errors.
79 test_DefaultObject(GLenum objectType
)
81 GLboolean pass
= GL_TRUE
;
84 /* From the GL_APPLE_object_purgeable spec:
86 * "INVALID_VALUE is generated if the <name> parameter of
87 * ObjectUnpurgeableAPPLE or ObjectUnpurgeableAPPLE is zero."
89 glObjectPurgeableAPPLE(objectType
, 0, GL_VOLATILE_APPLE
);
90 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_VALUE
);
92 glObjectUnpurgeableAPPLE(objectType
, 0, GL_RETAINED_APPLE
);
93 EXPECT_AN_ERROR("glObjectUnpurgeableAPPLE", GL_INVALID_VALUE
);
95 /* From the GL_APPLE_object_purgeable spec:
97 * "INVALID_VALUE is generated if the <name> parameter of
98 * GetObjectParameterivAPPLE is zero."
100 glGetObjectParameterivAPPLE(objectType
, 0, GL_PURGEABLE_APPLE
,
102 EXPECT_AN_ERROR("glGetObjectParameterivAPPLE", GL_INVALID_VALUE
);
109 test_ObjectpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
111 GLboolean pass
= GL_TRUE
;
114 ret
= glObjectPurgeableAPPLE(objectType
, name
, option
);
115 FAIL_ON_ERROR("glObjectPurgeableAPPLE");
118 case GL_VOLATILE_APPLE
:
119 /* From the GL_APPLE_object_purgeable spec:
121 * "If ObjectPurgeableAPPLE is called with an <option> of
122 * VOLATILE_APPLE, then ObjectPurgeableAPPLE will also
123 * return the value VOLATILE_APPLE."
125 if (ret
!= GL_VOLATILE_APPLE
) {
126 print_result("glObjectPurgeableAPPLE", option
, ret
,
127 GL_VOLATILE_APPLE
, NO_ENUM
);
132 case GL_RELEASED_APPLE
:
133 /* From the GL_APPLE_object_purgeable spec:
135 * "If ObjectPurgeableAPPLE is called with an <option> of
136 * RELEASED_APPLE, then ObjectPurgeableAPPLE may return
137 * either the value RELEASED_APPLE or the value
140 if (ret
!= GL_VOLATILE_APPLE
&& ret
!= GL_RELEASED_APPLE
) {
141 print_result("glObjectPurgeableAPPLE", option
, ret
,
149 /* From the GL_APPLE_object_purgeable spec:
151 * "Calling ObjectPurgeableAPPLE with either option sets
152 * PURGEABLE_APPLE to TRUE..."
154 if (!test_GetObjectParameterivAPPLE(objectType
, name
, GL_TRUE
)) {
156 "Object marked purgeable is not set to purgeable\n");
160 /* From the GL_APPLE_object_purgeable spec:
162 * "If ObjectPurgeableAPPLE is called and PURGEABLE_APPLE is
163 * already TRUE, the error INVALID_OPERATION is generated."
165 glObjectPurgeableAPPLE(objectType
, name
, option
);
166 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION
);
173 test_ObjectunpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
175 GLboolean pass
= GL_TRUE
;
178 ret
= glObjectUnpurgeableAPPLE(objectType
, name
, option
);
179 FAIL_ON_ERROR("glObjectUnpurgeableAPPLE");
182 case GL_RETAINED_APPLE
:
183 /* From the GL_APPLE_object_purgeable spec:
185 * "If ObjectUnpurgeableAPPLE is called with an <option> of
186 * RETAINED_APPLE, then ObjectPurgeableAPPLE may return
187 * either the value RETAINED_APPLE or the value
190 if (ret
!= GL_RETAINED_APPLE
&& ret
!= GL_UNDEFINED_APPLE
) {
191 print_result("glObjectUnpurgeableAPPLE", option
, ret
,
198 case GL_UNDEFINED_APPLE
:
199 /* From the GL_APPLE_object_purgeable spec:
201 * "If ObjectUnpurgeableAPPLE is called with the <option>
202 * set to UNDEFINED_APPLE, then ObjectUnpurgeableAPPLE will
203 * return the value UNDEFINED_APPLE."
205 if (ret
!= GL_UNDEFINED_APPLE
) {
206 print_result("glObjectUnpurgeableAPPLE", option
, ret
,
207 GL_UNDEFINED_APPLE
, NO_ENUM
);
213 /* From the GL_APPLE_object_purgeable spec:
215 * "Calling ObjectUnpurgeableAPPLE with either option sets
216 * PURGEABLE_APPLE to FALSE..."
218 if (!test_GetObjectParameterivAPPLE(objectType
, name
, GL_FALSE
)) {
219 fprintf(stderr
, "Object marked unpurgeable is not set to "
224 /* From the GL_APPLE_object_purgeable spec:
226 * "If ObjectUnpurgeableAPPLE is called and PURGEABLE_APPLE is
227 * already FALSE, the error INVALID_OPERATION is returned."
229 glObjectUnpurgeableAPPLE(objectType
, name
, option
);
230 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION
);
237 test_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum expect
)
239 GLboolean pass
= GL_TRUE
;
242 glGetObjectParameterivAPPLE(objectType
, name
, GL_PURGEABLE_APPLE
,
244 FAIL_ON_ERROR("glGetObjectParameterivAPPLE");
246 if (param
!= expect
) {
247 print_result("glObjectParameterivAPPLE", GL_PURGEABLE_APPLE
,
248 param
, expect
, NO_ENUM
);
256 GLboolean
test_Purgeable(GLuint object
, GLenum type
)
258 GLboolean pass
= GL_TRUE
;
262 if (!test_DefaultObject(type
)) {
263 fprintf(stderr
, "Default object tests failed.\n");
267 if (!test_GetObjectParameterivAPPLE(type
, object
, GL_FALSE
)) {
268 fprintf(stderr
, "Default state test failed.\n");
272 if (!test_ObjectpurgeableAPPLE(type
, object
, GL_VOLATILE_APPLE
)) {
276 if (!test_ObjectunpurgeableAPPLE(type
, object
, GL_RETAINED_APPLE
)) {
280 if (!test_ObjectpurgeableAPPLE(type
, object
, GL_RELEASED_APPLE
)) {
284 if (!test_ObjectunpurgeableAPPLE(type
, object
, GL_UNDEFINED_APPLE
)) {