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.h"
29 #include "object_purgeable.h"
31 PFNGLOBJECTPURGEABLEAPPLEPROC pglObjectPurgeableAPPLE
= NULL
;
32 PFNGLOBJECTUNPURGEABLEAPPLEPROC pglObjectUnpurgeableAPPLE
= NULL
;
33 PFNGLGETOBJECTPARAMETERIVAPPLEPROC pglGetObjectParameterivAPPLE
= NULL
;
35 #define FAIL_ON_ERROR(string) \
37 const GLenum err = glGetError(); \
38 if (err != GL_NO_ERROR) { \
39 fprintf(stderr, "%s generated error 0x%04x\n", \
45 #define EXPECT_AN_ERROR(string, expected) \
47 const GLenum err = glGetError(); \
48 if (err != expected) { \
49 fprintf(stderr, "%s generated error 0x%04x, " \
50 "but error 0x%04x (%s) was expected\n", \
51 string, err, expected, # expected); \
57 init_ObjectPurgeableAPI(void)
59 piglit_require_extension("GL_APPLE_object_purgeable");
61 pglObjectPurgeableAPPLE
= (PFNGLOBJECTPURGEABLEAPPLEPROC
)
62 piglit_get_proc_address("glObjectPurgeableAPPLE");
63 pglObjectUnpurgeableAPPLE
= (PFNGLOBJECTUNPURGEABLEAPPLEPROC
)
64 piglit_get_proc_address("glObjectUnpurgeableAPPLE");
65 pglGetObjectParameterivAPPLE
= (PFNGLGETOBJECTPARAMETERIVAPPLEPROC
)
66 piglit_get_proc_address("glGetObjectParameterivAPPLE");
71 * Format for error messages when an unexpected value is received.
73 static const char expected_fmt
[] =
74 "%s:%s: expected 0x%04x (%s), got 0x%04x\n";
78 * Check the setting and querying purgeability on object 0 generates errors.
81 test_DefaultObject(GLenum objectType
)
83 GLboolean pass
= GL_TRUE
;
86 /* From the GL_APPLE_object_purgeable spec:
88 * "INVALID_VALUE is generated if the <name> parameter of
89 * ObjectUnpurgeableAPPLE or ObjectUnpurgeableAPPLE is zero."
91 (void) (*pglObjectPurgeableAPPLE
)(objectType
, 0, GL_VOLATILE_APPLE
);
92 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_VALUE
);
94 (void) (*pglObjectUnpurgeableAPPLE
)(objectType
, 0, GL_RETAINED_APPLE
);
95 EXPECT_AN_ERROR("glObjectUnpurgeableAPPLE", GL_INVALID_VALUE
);
97 /* From the GL_APPLE_object_purgeable spec:
99 * "INVALID_VALUE is generated if the <name> parameter of
100 * GetObjectParameterivAPPLE is zero."
102 (*pglGetObjectParameterivAPPLE
)(objectType
, 0, GL_PURGEABLE_APPLE
,
104 EXPECT_AN_ERROR("glGetObjectParameterivAPPLE", GL_INVALID_VALUE
);
111 test_ObjectpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
113 GLboolean pass
= GL_TRUE
;
116 ret
= (*pglObjectPurgeableAPPLE
)(objectType
, name
, option
);
117 FAIL_ON_ERROR("glObjectPurgeableAPPLE");
120 case GL_VOLATILE_APPLE
:
121 /* From the GL_APPLE_object_purgeable spec:
123 * "If ObjectPurgeableAPPLE is called with an <option> of
124 * VOLATILE_APPLE, then ObjectPurgeableAPPLE will also
125 * return the value VOLATILE_APPLE."
127 if (ret
!= GL_VOLATILE_APPLE
) {
128 fprintf(stderr
, expected_fmt
,
129 "glObjectPurgeableAPPLE", "GL_VOLATILE_APPLE",
130 GL_VOLATILE_APPLE
, "GL_VOLATILE_APPLE",
136 case GL_RELEASED_APPLE
:
137 /* From the GL_APPLE_object_purgeable spec:
139 * "If ObjectPurgeableAPPLE is called with an <option> of
140 * RELEASED_APPLE, then ObjectPurgeableAPPLE may return
141 * either the value RELEASED_APPLE or the value
144 if (ret
!= GL_VOLATILE_APPLE
&& ret
!= GL_RELEASED_APPLE
) {
145 fprintf(stderr
, expected_fmt
,
146 "glObjectPurgeableAPPLE", "GL_RELEASED_APPLE",
148 "GL_VOLATILE_APPLE or GL_RELEASED_APPLE",
155 /* From the GL_APPLE_object_purgeable spec:
157 * "Calling ObjectPurgeableAPPLE with either option sets
158 * PURGEABLE_APPLE to TRUE..."
160 if (!test_GetObjectParameterivAPPLE(objectType
, name
, GL_TRUE
)) {
162 "Object marked purgeable is not set to purgeable\n");
166 /* From the GL_APPLE_object_purgeable spec:
168 * "If ObjectPurgeableAPPLE is called and PURGEABLE_APPLE is
169 * already TRUE, the error INVALID_OPERATION is generated."
171 (void) (*pglObjectPurgeableAPPLE
)(objectType
, name
, option
);
172 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION
);
179 test_ObjectunpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
181 GLboolean pass
= GL_TRUE
;
184 ret
= (*pglObjectUnpurgeableAPPLE
)(objectType
, name
, option
);
185 FAIL_ON_ERROR("glObjectUnpurgeableAPPLE");
188 case GL_RETAINED_APPLE
:
189 /* From the GL_APPLE_object_purgeable spec:
191 * "If ObjectUnpurgeableAPPLE is called with an <option> of
192 * RETAINED_APPLE, then ObjectPurgeableAPPLE may return
193 * either the value RETAINED_APPLE or the value
196 if (ret
!= GL_RETAINED_APPLE
&& ret
!= GL_UNDEFINED_APPLE
) {
197 fprintf(stderr
, expected_fmt
,
198 "glObjectUnpurgeableAPPLE", "GL_RETAINED_APPLE",
200 "GL_RETAINED_APPLE or GL_UNDEFINED_APPLE",
206 case GL_UNDEFINED_APPLE
:
207 /* From the GL_APPLE_object_purgeable spec:
209 * "If ObjectUnpurgeableAPPLE is called with the <option>
210 * set to UNDEFINED_APPLE, then ObjectUnpurgeableAPPLE will
211 * return the value UNDEFINED_APPLE."
213 if (ret
!= GL_UNDEFINED_APPLE
) {
214 fprintf(stderr
, expected_fmt
,
215 "glObjectUnpurgeableAPPLE", "GL_UNDEFINED_APPLE",
216 GL_UNDEFINED_APPLE
, "GL_UNDEFINED_APPLE",
223 /* From the GL_APPLE_object_purgeable spec:
225 * "Calling ObjectUnpurgeableAPPLE with either option sets
226 * PURGEABLE_APPLE to FALSE..."
228 if (!test_GetObjectParameterivAPPLE(objectType
, name
, GL_FALSE
)) {
229 fprintf(stderr
, "Object marked unpurgeable is not set to "
234 /* From the GL_APPLE_object_purgeable spec:
236 * "If ObjectUnpurgeableAPPLE is called and PURGEABLE_APPLE is
237 * already FALSE, the error INVALID_OPERATION is returned."
239 (void) (*pglObjectUnpurgeableAPPLE
)(objectType
, name
, option
);
240 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION
);
247 test_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum expect
)
249 GLboolean pass
= GL_TRUE
;
252 (*pglGetObjectParameterivAPPLE
)(objectType
, name
, GL_PURGEABLE_APPLE
,
254 FAIL_ON_ERROR("glGetObjectParameterivAPPLE");
256 if (param
!= expect
) {
257 fprintf(stderr
, expected_fmt
,
258 "glGetObjectParameterivAPPLE", "GL_PURGEABLE_APPLE",
259 expect
, expect
? "GL_TRUE" : "GL_FALSE",
268 GLboolean
test_Purgeable(GLuint object
, GLenum type
)
270 GLboolean pass
= GL_TRUE
;
274 if (!test_DefaultObject(type
)) {
275 fprintf(stderr
, "Default object tests failed.\n");
279 if (!test_GetObjectParameterivAPPLE(type
, object
, GL_FALSE
)) {
280 fprintf(stderr
, "Default state test failed.\n");
284 if (!test_ObjectpurgeableAPPLE(type
, object
, GL_VOLATILE_APPLE
)) {
288 if (!test_ObjectunpurgeableAPPLE(type
, object
, GL_RETAINED_APPLE
)) {
292 if (!test_ObjectpurgeableAPPLE(type
, object
, GL_RELEASED_APPLE
)) {
296 if (!test_ObjectunpurgeableAPPLE(type
, object
, GL_UNDEFINED_APPLE
)) {