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
);
57 if (bufObj
->Purgeable
) {
58 _mesa_error(ctx
, GL_INVALID_OPERATION
,
59 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
60 return GL_VOLATILE_APPLE
;
63 bufObj
->Purgeable
= GL_TRUE
;
65 retval
= GL_VOLATILE_APPLE
;
66 if (ctx
->Driver
.BufferObjectPurgeable
)
67 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
74 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
76 struct gl_renderbuffer
*bufObj
;
79 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
81 _mesa_error(ctx
, GL_INVALID_VALUE
,
82 "glObjectUnpurgeable(name = 0x%x)", name
);
86 if (bufObj
->Purgeable
) {
87 _mesa_error(ctx
, GL_INVALID_OPERATION
,
88 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
89 return GL_VOLATILE_APPLE
;
92 bufObj
->Purgeable
= GL_TRUE
;
94 retval
= GL_VOLATILE_APPLE
;
95 if (ctx
->Driver
.RenderObjectPurgeable
)
96 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
103 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
105 struct gl_texture_object
*bufObj
;
108 bufObj
= _mesa_lookup_texture(ctx
, name
);
110 _mesa_error(ctx
, GL_INVALID_VALUE
,
111 "glObjectPurgeable(name = 0x%x)", name
);
115 if (bufObj
->Purgeable
) {
116 _mesa_error(ctx
, GL_INVALID_OPERATION
,
117 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
118 return GL_VOLATILE_APPLE
;
121 bufObj
->Purgeable
= GL_TRUE
;
123 retval
= GL_VOLATILE_APPLE
;
124 if (ctx
->Driver
.TextureObjectPurgeable
)
125 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
132 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
136 GET_CURRENT_CONTEXT(ctx
);
137 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
140 _mesa_error(ctx
, GL_INVALID_VALUE
,
141 "glObjectPurgeable(name = 0x%x)", name
);
146 case GL_VOLATILE_APPLE
:
147 case GL_RELEASED_APPLE
:
151 _mesa_error(ctx
, GL_INVALID_ENUM
,
152 "glObjectPurgeable(name = 0x%x) invalid option: %d",
157 switch (objectType
) {
159 retval
= texture_object_purgeable(ctx
, name
, option
);
161 case GL_RENDERBUFFER_EXT
:
162 retval
= renderbuffer_purgeable(ctx
, name
, option
);
164 case GL_BUFFER_OBJECT_APPLE
:
165 retval
= buffer_object_purgeable(ctx
, name
, option
);
168 _mesa_error(ctx
, GL_INVALID_ENUM
,
169 "glObjectPurgeable(name = 0x%x) invalid type: %d",
174 /* In strict conformance to the spec, we must only return VOLATILE when
175 * when passed the VOLATILE option. Madness.
177 * XXX First fix the spec, then fix me.
179 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
184 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
186 struct gl_buffer_object
*bufObj
;
189 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
191 _mesa_error(ctx
, GL_INVALID_VALUE
,
192 "glObjectUnpurgeable(name = 0x%x)", name
);
196 if (! bufObj
->Purgeable
) {
197 _mesa_error(ctx
, GL_INVALID_OPERATION
,
198 "glObjectUnpurgeable(name = 0x%x) object is "
199 " already \"unpurged\"", name
);
203 bufObj
->Purgeable
= GL_FALSE
;
206 if (ctx
->Driver
.BufferObjectUnpurgeable
)
207 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
214 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
216 struct gl_renderbuffer
*bufObj
;
219 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
221 _mesa_error(ctx
, GL_INVALID_VALUE
,
222 "glObjectUnpurgeable(name = 0x%x)", name
);
226 if (! bufObj
->Purgeable
) {
227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
228 "glObjectUnpurgeable(name = 0x%x) object is "
229 " already \"unpurged\"", name
);
233 bufObj
->Purgeable
= GL_FALSE
;
236 if (ctx
->Driver
.RenderObjectUnpurgeable
)
237 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
244 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
246 struct gl_texture_object
*bufObj
;
249 bufObj
= _mesa_lookup_texture(ctx
, name
);
251 _mesa_error(ctx
, GL_INVALID_VALUE
,
252 "glObjectUnpurgeable(name = 0x%x)", name
);
256 if (! bufObj
->Purgeable
) {
257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
258 "glObjectUnpurgeable(name = 0x%x) object is"
259 " already \"unpurged\"", name
);
263 bufObj
->Purgeable
= GL_FALSE
;
266 if (ctx
->Driver
.TextureObjectUnpurgeable
)
267 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
274 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
276 GET_CURRENT_CONTEXT(ctx
);
277 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
280 _mesa_error(ctx
, GL_INVALID_VALUE
,
281 "glObjectUnpurgeable(name = 0x%x)", name
);
286 case GL_RETAINED_APPLE
:
287 case GL_UNDEFINED_APPLE
:
291 _mesa_error(ctx
, GL_INVALID_ENUM
,
292 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
297 switch (objectType
) {
298 case GL_BUFFER_OBJECT_APPLE
:
299 return buffer_object_unpurgeable(ctx
, name
, option
);
301 return texture_object_unpurgeable(ctx
, name
, option
);
302 case GL_RENDERBUFFER_EXT
:
303 return renderbuffer_unpurgeable(ctx
, name
, option
);
305 _mesa_error(ctx
, GL_INVALID_ENUM
,
306 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
314 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
315 GLenum pname
, GLint
*params
)
317 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
319 _mesa_error(ctx
, GL_INVALID_VALUE
,
320 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
325 case GL_PURGEABLE_APPLE
:
326 *params
= bufObj
->Purgeable
;
329 _mesa_error(ctx
, GL_INVALID_ENUM
,
330 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
338 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
339 GLenum pname
, GLint
*params
)
341 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
343 _mesa_error(ctx
, GL_INVALID_VALUE
,
344 "glObjectUnpurgeable(name = 0x%x)", name
);
349 case GL_PURGEABLE_APPLE
:
350 *params
= rb
->Purgeable
;
353 _mesa_error(ctx
, GL_INVALID_ENUM
,
354 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
362 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
363 GLenum pname
, GLint
*params
)
365 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
367 _mesa_error(ctx
, GL_INVALID_VALUE
,
368 "glObjectUnpurgeable(name = 0x%x)", name
);
373 case GL_PURGEABLE_APPLE
:
374 *params
= texObj
->Purgeable
;
377 _mesa_error(ctx
, GL_INVALID_ENUM
,
378 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
386 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
389 GET_CURRENT_CONTEXT(ctx
);
392 _mesa_error(ctx
, GL_INVALID_VALUE
,
393 "glGetObjectParameteriv(name = 0x%x)", name
);
397 switch (objectType
) {
399 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
401 case GL_BUFFER_OBJECT_APPLE
:
402 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
404 case GL_RENDERBUFFER_EXT
:
405 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
408 _mesa_error(ctx
, GL_INVALID_ENUM
,
409 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",