2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
27 * Code related to the GL_APPLE_object_purgeable extension.
36 #include "bufferobj.h"
39 #include "objectpurge.h"
45 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
47 struct gl_buffer_object
*bufObj
;
50 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
52 _mesa_error(ctx
, GL_INVALID_VALUE
,
53 "glObjectPurgeable(name = 0x%x)", name
);
56 if (!_mesa_is_bufferobj(bufObj
)) {
57 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
61 if (bufObj
->Purgeable
) {
62 _mesa_error(ctx
, GL_INVALID_OPERATION
,
63 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
64 return GL_VOLATILE_APPLE
;
67 bufObj
->Purgeable
= GL_TRUE
;
69 retval
= GL_VOLATILE_APPLE
;
70 if (ctx
->Driver
.BufferObjectPurgeable
)
71 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
78 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
80 struct gl_renderbuffer
*bufObj
;
83 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
85 _mesa_error(ctx
, GL_INVALID_VALUE
,
86 "glObjectUnpurgeable(name = 0x%x)", name
);
90 if (bufObj
->Purgeable
) {
91 _mesa_error(ctx
, GL_INVALID_OPERATION
,
92 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
93 return GL_VOLATILE_APPLE
;
96 bufObj
->Purgeable
= GL_TRUE
;
98 retval
= GL_VOLATILE_APPLE
;
99 if (ctx
->Driver
.RenderObjectPurgeable
)
100 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
107 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
109 struct gl_texture_object
*bufObj
;
112 bufObj
= _mesa_lookup_texture(ctx
, name
);
114 _mesa_error(ctx
, GL_INVALID_VALUE
,
115 "glObjectPurgeable(name = 0x%x)", name
);
119 if (bufObj
->Purgeable
) {
120 _mesa_error(ctx
, GL_INVALID_OPERATION
,
121 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
122 return GL_VOLATILE_APPLE
;
125 bufObj
->Purgeable
= GL_TRUE
;
127 retval
= GL_VOLATILE_APPLE
;
128 if (ctx
->Driver
.TextureObjectPurgeable
)
129 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
136 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
140 GET_CURRENT_CONTEXT(ctx
);
141 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
144 _mesa_error(ctx
, GL_INVALID_VALUE
,
145 "glObjectPurgeable(name = 0x%x)", name
);
150 case GL_VOLATILE_APPLE
:
151 case GL_RELEASED_APPLE
:
155 _mesa_error(ctx
, GL_INVALID_ENUM
,
156 "glObjectPurgeable(name = 0x%x) invalid option: %d",
161 switch (objectType
) {
163 retval
= texture_object_purgeable(ctx
, name
, option
);
165 case GL_RENDERBUFFER_EXT
:
166 retval
= renderbuffer_purgeable(ctx
, name
, option
);
168 case GL_BUFFER_OBJECT_APPLE
:
169 retval
= buffer_object_purgeable(ctx
, name
, option
);
172 _mesa_error(ctx
, GL_INVALID_ENUM
,
173 "glObjectPurgeable(name = 0x%x) invalid type: %d",
178 /* In strict conformance to the spec, we must only return VOLATILE when
179 * when passed the VOLATILE option. Madness.
181 * XXX First fix the spec, then fix me.
183 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
188 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
190 struct gl_buffer_object
*bufObj
;
193 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
195 _mesa_error(ctx
, GL_INVALID_VALUE
,
196 "glObjectUnpurgeable(name = 0x%x)", name
);
200 if (! bufObj
->Purgeable
) {
201 _mesa_error(ctx
, GL_INVALID_OPERATION
,
202 "glObjectUnpurgeable(name = 0x%x) object is "
203 " already \"unpurged\"", name
);
207 bufObj
->Purgeable
= GL_FALSE
;
210 if (ctx
->Driver
.BufferObjectUnpurgeable
)
211 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
218 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
220 struct gl_renderbuffer
*bufObj
;
223 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
225 _mesa_error(ctx
, GL_INVALID_VALUE
,
226 "glObjectUnpurgeable(name = 0x%x)", name
);
230 if (! bufObj
->Purgeable
) {
231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
232 "glObjectUnpurgeable(name = 0x%x) object is "
233 " already \"unpurged\"", name
);
237 bufObj
->Purgeable
= GL_FALSE
;
240 if (ctx
->Driver
.RenderObjectUnpurgeable
)
241 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
248 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
250 struct gl_texture_object
*bufObj
;
253 bufObj
= _mesa_lookup_texture(ctx
, name
);
255 _mesa_error(ctx
, GL_INVALID_VALUE
,
256 "glObjectUnpurgeable(name = 0x%x)", name
);
260 if (! bufObj
->Purgeable
) {
261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
262 "glObjectUnpurgeable(name = 0x%x) object is"
263 " already \"unpurged\"", name
);
267 bufObj
->Purgeable
= GL_FALSE
;
270 if (ctx
->Driver
.TextureObjectUnpurgeable
)
271 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
278 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
280 GET_CURRENT_CONTEXT(ctx
);
281 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
284 _mesa_error(ctx
, GL_INVALID_VALUE
,
285 "glObjectUnpurgeable(name = 0x%x)", name
);
290 case GL_RETAINED_APPLE
:
291 case GL_UNDEFINED_APPLE
:
295 _mesa_error(ctx
, GL_INVALID_ENUM
,
296 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
301 switch (objectType
) {
302 case GL_BUFFER_OBJECT_APPLE
:
303 return buffer_object_unpurgeable(ctx
, name
, option
);
305 return texture_object_unpurgeable(ctx
, name
, option
);
306 case GL_RENDERBUFFER_EXT
:
307 return renderbuffer_unpurgeable(ctx
, name
, option
);
309 _mesa_error(ctx
, GL_INVALID_ENUM
,
310 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
318 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
319 GLenum pname
, GLint
*params
)
321 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
323 _mesa_error(ctx
, GL_INVALID_VALUE
,
324 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
329 case GL_PURGEABLE_APPLE
:
330 *params
= bufObj
->Purgeable
;
333 _mesa_error(ctx
, GL_INVALID_ENUM
,
334 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
342 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
343 GLenum pname
, GLint
*params
)
345 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
347 _mesa_error(ctx
, GL_INVALID_VALUE
,
348 "glObjectUnpurgeable(name = 0x%x)", name
);
353 case GL_PURGEABLE_APPLE
:
354 *params
= rb
->Purgeable
;
357 _mesa_error(ctx
, GL_INVALID_ENUM
,
358 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
366 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
367 GLenum pname
, GLint
*params
)
369 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
371 _mesa_error(ctx
, GL_INVALID_VALUE
,
372 "glObjectUnpurgeable(name = 0x%x)", name
);
377 case GL_PURGEABLE_APPLE
:
378 *params
= texObj
->Purgeable
;
381 _mesa_error(ctx
, GL_INVALID_ENUM
,
382 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
390 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
393 GET_CURRENT_CONTEXT(ctx
);
396 _mesa_error(ctx
, GL_INVALID_VALUE
,
397 "glGetObjectParameteriv(name = 0x%x)", name
);
401 switch (objectType
) {
403 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
405 case GL_BUFFER_OBJECT_APPLE
:
406 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
408 case GL_RENDERBUFFER_EXT
:
409 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
412 _mesa_error(ctx
, GL_INVALID_ENUM
,
413 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",