2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
37 /*#define BOUNDS_CHECK*/
41 * Used as a placeholder for buffer objects between glGenBuffers() and
42 * glBindBuffer() so that glIsBuffer() can work correctly.
44 static struct gl_buffer_object DummyBufferObject
;
48 * Return pointer to address of a buffer object target.
49 * \param ctx the GL context
50 * \param target the buffer object target to be retrieved.
51 * \return pointer to pointer to the buffer object bound to \c target in the
52 * specified context or \c NULL if \c target is invalid.
54 static inline struct gl_buffer_object
**
55 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
58 case GL_ARRAY_BUFFER_ARB
:
59 return &ctx
->Array
.ArrayBufferObj
;
60 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
61 return &ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
70 * Get the buffer object bound to the specified target in a GL context.
71 * \param ctx the GL context
72 * \param target the buffer object target to be retrieved.
73 * \return pointer to the buffer object bound to \c target in the
74 * specified context or \c NULL if \c target is invalid.
76 static inline struct gl_buffer_object
*
77 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
)
79 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
82 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
86 if (!_mesa_is_bufferobj(*bufObj
)) {
87 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(buffer 0)", func
);
96 default_access_mode(const struct gl_context
*ctx
)
99 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
104 * Convert a GLbitfield describing the mapped buffer access flags
105 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
108 simplified_access_mode(GLbitfield access
)
110 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
111 if ((access
& rwFlags
) == rwFlags
)
112 return GL_READ_WRITE
;
113 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
115 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
116 return GL_WRITE_ONLY
;
117 return GL_READ_WRITE
; /* this should never happen, but no big deal */
122 * Tests the subdata range parameters and sets the GL error code for
123 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
125 * \param ctx GL context.
126 * \param target Buffer object target on which to operate.
127 * \param offset Offset of the first byte of the subdata range.
128 * \param size Size, in bytes, of the subdata range.
129 * \param caller Name of calling function for recording errors.
130 * \return A pointer to the buffer object bound to \c target in the
131 * specified context or \c NULL if any of the parameter or state
132 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
135 * \sa glBufferSubDataARB, glGetBufferSubDataARB
137 static struct gl_buffer_object
*
138 buffer_object_subdata_range_good( struct gl_context
* ctx
, GLenum target
,
139 GLintptrARB offset
, GLsizeiptrARB size
,
142 struct gl_buffer_object
*bufObj
;
145 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
150 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
154 bufObj
= get_buffer(ctx
, caller
, target
);
158 if (offset
+ size
> bufObj
->Size
) {
159 _mesa_error(ctx
, GL_INVALID_VALUE
,
160 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
161 (unsigned long) offset
,
162 (unsigned long) size
,
163 (unsigned long) bufObj
->Size
);
166 if (_mesa_bufferobj_mapped(bufObj
)) {
167 /* Buffer is currently mapped */
168 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
177 * Allocate and initialize a new buffer object.
179 * Default callback for the \c dd_function_table::NewBufferObject() hook.
181 static struct gl_buffer_object
*
182 _mesa_new_buffer_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
184 struct gl_buffer_object
*obj
;
188 obj
= MALLOC_STRUCT(gl_buffer_object
);
189 _mesa_initialize_buffer_object(ctx
, obj
, name
, target
);
195 * Delete a buffer object.
197 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
200 _mesa_delete_buffer_object(struct gl_context
*ctx
,
201 struct gl_buffer_object
*bufObj
)
208 /* assign strange values here to help w/ debugging */
209 bufObj
->RefCount
= -1000;
212 _glthread_DESTROY_MUTEX(bufObj
->Mutex
);
219 * Set ptr to bufObj w/ reference counting.
220 * This is normally only called from the _mesa_reference_buffer_object() macro
221 * when there's a real pointer change.
224 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
225 struct gl_buffer_object
**ptr
,
226 struct gl_buffer_object
*bufObj
)
229 /* Unreference the old buffer */
230 GLboolean deleteFlag
= GL_FALSE
;
231 struct gl_buffer_object
*oldObj
= *ptr
;
233 _glthread_LOCK_MUTEX(oldObj
->Mutex
);
234 ASSERT(oldObj
->RefCount
> 0);
237 printf("BufferObj %p %d DECR to %d\n",
238 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
240 deleteFlag
= (oldObj
->RefCount
== 0);
241 _glthread_UNLOCK_MUTEX(oldObj
->Mutex
);
245 /* some sanity checking: don't delete a buffer still in use */
247 /* unfortunately, these tests are invalid during context tear-down */
248 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
249 ASSERT(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
!= bufObj
);
250 ASSERT(ctx
->Array
.ArrayObj
->Vertex
.BufferObj
!= bufObj
);
253 ASSERT(ctx
->Driver
.DeleteBuffer
);
254 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
262 /* reference new buffer */
263 _glthread_LOCK_MUTEX(bufObj
->Mutex
);
264 if (bufObj
->RefCount
== 0) {
265 /* this buffer's being deleted (look just above) */
266 /* Not sure this can every really happen. Warn if it does. */
267 _mesa_problem(NULL
, "referencing deleted buffer object");
273 printf("BufferObj %p %d INCR to %d\n",
274 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
278 _glthread_UNLOCK_MUTEX(bufObj
->Mutex
);
284 * Initialize a buffer object to default values.
287 _mesa_initialize_buffer_object( struct gl_context
*ctx
,
288 struct gl_buffer_object
*obj
,
289 GLuint name
, GLenum target
)
293 memset(obj
, 0, sizeof(struct gl_buffer_object
));
294 _glthread_INIT_MUTEX(obj
->Mutex
);
297 obj
->Usage
= GL_STATIC_DRAW_ARB
;
298 obj
->AccessFlags
= default_access_mode(ctx
);
303 * Allocate space for and store data in a buffer object. Any data that was
304 * previously stored in the buffer object is lost. If \c data is \c NULL,
305 * memory will be allocated, but no copy will occur.
307 * This is the default callback for \c dd_function_table::BufferData()
308 * Note that all GL error checking will have been done already.
310 * \param ctx GL context.
311 * \param target Buffer object target on which to operate.
312 * \param size Size, in bytes, of the new data store.
313 * \param data Pointer to the data to store in the buffer object. This
314 * pointer may be \c NULL.
315 * \param usage Hints about how the data will be used.
316 * \param bufObj Object to be used.
318 * \return GL_TRUE for success, GL_FALSE for failure
319 * \sa glBufferDataARB, dd_function_table::BufferData.
322 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
323 const GLvoid
* data
, GLenum usage
,
324 struct gl_buffer_object
* bufObj
)
328 (void) ctx
; (void) target
;
330 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
332 bufObj
->Data
= (GLubyte
*) new_data
;
334 bufObj
->Usage
= usage
;
337 memcpy( bufObj
->Data
, data
, size
);
349 * Replace data in a subrange of buffer object. If the data range
350 * specified by \c size + \c offset extends beyond the end of the buffer or
351 * if \c data is \c NULL, no copy is performed.
353 * This is the default callback for \c dd_function_table::BufferSubData()
354 * Note that all GL error checking will have been done already.
356 * \param ctx GL context.
357 * \param target Buffer object target on which to operate.
358 * \param offset Offset of the first byte to be modified.
359 * \param size Size, in bytes, of the data range.
360 * \param data Pointer to the data to store in the buffer object.
361 * \param bufObj Object to be used.
363 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
366 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
367 GLsizeiptrARB size
, const GLvoid
* data
,
368 struct gl_buffer_object
* bufObj
)
372 /* this should have been caught in _mesa_BufferSubData() */
373 ASSERT(size
+ offset
<= bufObj
->Size
);
376 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
382 * Retrieve data from a subrange of buffer object. If the data range
383 * specified by \c size + \c offset extends beyond the end of the buffer or
384 * if \c data is \c NULL, no copy is performed.
386 * This is the default callback for \c dd_function_table::GetBufferSubData()
387 * Note that all GL error checking will have been done already.
389 * \param ctx GL context.
390 * \param target Buffer object target on which to operate.
391 * \param offset Offset of the first byte to be fetched.
392 * \param size Size, in bytes, of the data range.
393 * \param data Destination for data
394 * \param bufObj Object to be used.
396 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
399 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
400 GLsizeiptrARB size
, GLvoid
* data
,
401 struct gl_buffer_object
* bufObj
)
405 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
406 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
412 * Default fallback for \c dd_function_table::MapBufferRange().
413 * Called via glMapBufferRange().
416 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
417 GLsizeiptr length
, GLbitfield access
,
418 struct gl_buffer_object
*bufObj
)
421 assert(!_mesa_bufferobj_mapped(bufObj
));
422 /* Just return a direct pointer to the data */
423 bufObj
->Pointer
= bufObj
->Data
+ offset
;
424 bufObj
->Length
= length
;
425 bufObj
->Offset
= offset
;
426 bufObj
->AccessFlags
= access
;
427 return bufObj
->Pointer
;
432 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
433 * Called via glFlushMappedBufferRange().
436 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
437 GLintptr offset
, GLsizeiptr length
,
438 struct gl_buffer_object
*obj
)
449 * Default callback for \c dd_function_table::MapBuffer().
451 * The input parameters will have been already tested for errors.
453 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
456 _mesa_buffer_unmap( struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
)
459 /* XXX we might assert here that bufObj->Pointer is non-null */
460 bufObj
->Pointer
= NULL
;
463 bufObj
->AccessFlags
= 0x0;
469 * Initialize the state associated with buffer objects
472 _mesa_init_buffer_objects( struct gl_context
*ctx
)
474 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
475 _glthread_INIT_MUTEX(DummyBufferObject
.Mutex
);
476 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
478 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
479 ctx
->Shared
->NullBufferObj
);
484 _mesa_free_buffer_objects( struct gl_context
*ctx
)
486 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
491 * Bind the specified target to buffer for the specified context.
492 * Called by glBindBuffer() and other functions.
495 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
497 struct gl_buffer_object
*oldBufObj
;
498 struct gl_buffer_object
*newBufObj
= NULL
;
499 struct gl_buffer_object
**bindTarget
= NULL
;
501 bindTarget
= get_buffer_target(ctx
, target
);
503 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
507 /* Get pointer to old buffer object (to be unbound) */
508 oldBufObj
= *bindTarget
;
509 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
510 return; /* rebinding the same buffer object- no change */
513 * Get pointer to new buffer object (newBufObj)
516 /* The spec says there's not a buffer object named 0, but we use
517 * one internally because it simplifies things.
519 newBufObj
= ctx
->Shared
->NullBufferObj
;
522 /* non-default buffer object */
523 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
524 if (!newBufObj
|| newBufObj
== &DummyBufferObject
) {
525 /* If this is a new buffer object id, or one which was generated but
526 * never used before, allocate a buffer object now.
528 ASSERT(ctx
->Driver
.NewBufferObject
);
529 newBufObj
= ctx
->Driver
.NewBufferObject(ctx
, buffer
, target
);
531 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindBufferARB");
534 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, newBufObj
);
538 /* bind new buffer */
539 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
541 /* Pass BindBuffer call to device driver */
542 if (ctx
->Driver
.BindBuffer
)
543 ctx
->Driver
.BindBuffer( ctx
, target
, newBufObj
);
548 * Update the default buffer objects in the given context to reference those
549 * specified in the shared state and release those referencing the old
553 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
555 /* Bind the NullBufferObj to remove references to those
556 * in the shared context hash table.
558 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
559 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
565 * Return the gl_buffer_object for the given ID.
566 * Always return NULL for ID 0.
568 struct gl_buffer_object
*
569 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
574 return (struct gl_buffer_object
*)
575 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
580 * If *ptr points to obj, set ptr = the Null/default buffer object.
581 * This is a helper for buffer object deletion.
582 * The GL spec says that deleting a buffer object causes it to get
583 * unbound from all arrays in the current context.
586 unbind(struct gl_context
*ctx
,
587 struct gl_buffer_object
**ptr
,
588 struct gl_buffer_object
*obj
)
591 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
597 * Plug default/fallback buffer object functions into the device
601 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
603 /* GL_ARB_vertex/pixel_buffer_object */
604 driver
->NewBufferObject
= _mesa_new_buffer_object
;
605 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
606 driver
->BindBuffer
= NULL
;
607 driver
->BufferData
= _mesa_buffer_data
;
608 driver
->BufferSubData
= _mesa_buffer_subdata
;
609 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
610 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
612 /* GL_ARB_map_buffer_range */
613 driver
->MapBufferRange
= _mesa_buffer_map_range
;
614 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
619 /**********************************************************************/
621 /**********************************************************************/
624 _mesa_BindBufferARB(GLenum target
, GLuint buffer
)
626 GET_CURRENT_CONTEXT(ctx
);
627 ASSERT_OUTSIDE_BEGIN_END(ctx
);
629 if (MESA_VERBOSE
& VERBOSE_API
)
630 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
631 _mesa_lookup_enum_by_nr(target
), buffer
);
633 bind_buffer_object(ctx
, target
, buffer
);
638 * Delete a set of buffer objects.
640 * \param n Number of buffer objects to delete.
641 * \param ids Array of \c n buffer object IDs.
644 _mesa_DeleteBuffersARB(GLsizei n
, const GLuint
*ids
)
646 GET_CURRENT_CONTEXT(ctx
);
648 ASSERT_OUTSIDE_BEGIN_END(ctx
);
649 FLUSH_VERTICES(ctx
, 0);
652 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
656 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
658 for (i
= 0; i
< n
; i
++) {
659 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
661 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
664 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
666 if (_mesa_bufferobj_mapped(bufObj
)) {
667 /* if mapped, unmap it now */
668 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
669 bufObj
->AccessFlags
= default_access_mode(ctx
);
670 bufObj
->Pointer
= NULL
;
673 /* unbind any vertex pointers bound to this buffer */
674 for (j
= 0; j
< Elements(arrayObj
->VertexAttrib
); j
++) {
675 unbind(ctx
, &arrayObj
->VertexAttrib
[j
].BufferObj
, bufObj
);
678 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
679 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB
, 0 );
681 if (arrayObj
->ElementArrayBufferObj
== bufObj
) {
682 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
685 /* The ID is immediately freed for re-use */
686 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
687 /* Make sure we do not run into the classic ABA problem on bind.
688 * We don't want to allow re-binding a buffer object that's been
689 * "deleted" by glDeleteBuffers().
691 * The explicit rebinding to the default object in the current context
692 * prevents the above in the current context, but another context
693 * sharing the same objects might suffer from this problem.
694 * The alternative would be to do the hash lookup in any case on bind
695 * which would introduce more runtime overhead than this.
697 bufObj
->DeletePending
= GL_TRUE
;
698 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
702 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
707 * Generate a set of unique buffer object IDs and store them in \c buffer.
709 * \param n Number of IDs to generate.
710 * \param buffer Array of \c n locations to store the IDs.
713 _mesa_GenBuffersARB(GLsizei n
, GLuint
*buffer
)
715 GET_CURRENT_CONTEXT(ctx
);
718 ASSERT_OUTSIDE_BEGIN_END(ctx
);
720 if (MESA_VERBOSE
& VERBOSE_API
)
721 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
724 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
733 * This must be atomic (generation and allocation of buffer object IDs)
735 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
737 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
739 /* Insert the ID and pointer to dummy buffer object into hash table */
740 for (i
= 0; i
< n
; i
++) {
741 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
743 buffer
[i
] = first
+ i
;
746 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
751 * Determine if ID is the name of a buffer object.
753 * \param id ID of the potential buffer object.
754 * \return \c GL_TRUE if \c id is the name of a buffer object,
755 * \c GL_FALSE otherwise.
758 _mesa_IsBufferARB(GLuint id
)
760 struct gl_buffer_object
*bufObj
;
761 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
764 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
765 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
766 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
768 return bufObj
&& bufObj
!= &DummyBufferObject
;
773 _mesa_BufferDataARB(GLenum target
, GLsizeiptrARB size
,
774 const GLvoid
* data
, GLenum usage
)
776 GET_CURRENT_CONTEXT(ctx
);
777 struct gl_buffer_object
*bufObj
;
778 ASSERT_OUTSIDE_BEGIN_END(ctx
);
780 if (MESA_VERBOSE
& VERBOSE_API
)
781 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
782 _mesa_lookup_enum_by_nr(target
),
783 (long int) size
, data
,
784 _mesa_lookup_enum_by_nr(usage
));
787 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
792 case GL_STREAM_DRAW_ARB
:
793 case GL_STREAM_READ_ARB
:
794 case GL_STREAM_COPY_ARB
:
795 case GL_STATIC_DRAW_ARB
:
796 case GL_STATIC_READ_ARB
:
797 case GL_STATIC_COPY_ARB
:
798 case GL_DYNAMIC_DRAW_ARB
:
799 case GL_DYNAMIC_READ_ARB
:
800 case GL_DYNAMIC_COPY_ARB
:
804 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferDataARB(usage)");
808 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
);
812 if (_mesa_bufferobj_mapped(bufObj
)) {
813 /* Unmap the existing buffer. We'll replace it now. Not an error. */
814 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
815 bufObj
->AccessFlags
= default_access_mode(ctx
);
816 ASSERT(bufObj
->Pointer
== NULL
);
819 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
821 bufObj
->Written
= GL_TRUE
;
824 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
825 bufObj
->Name
, size
, data
, usage
);
832 ASSERT(ctx
->Driver
.BufferData
);
833 if (!ctx
->Driver
.BufferData( ctx
, target
, size
, data
, usage
, bufObj
)) {
834 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
840 _mesa_BufferSubDataARB(GLenum target
, GLintptrARB offset
,
841 GLsizeiptrARB size
, const GLvoid
* data
)
843 GET_CURRENT_CONTEXT(ctx
);
844 struct gl_buffer_object
*bufObj
;
845 ASSERT_OUTSIDE_BEGIN_END(ctx
);
847 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
848 "glBufferSubDataARB" );
850 /* error already recorded */
857 bufObj
->Written
= GL_TRUE
;
859 ASSERT(ctx
->Driver
.BufferSubData
);
860 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
865 _mesa_GetBufferSubDataARB(GLenum target
, GLintptrARB offset
,
866 GLsizeiptrARB size
, void * data
)
868 GET_CURRENT_CONTEXT(ctx
);
869 struct gl_buffer_object
*bufObj
;
870 ASSERT_OUTSIDE_BEGIN_END(ctx
);
872 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
873 "glGetBufferSubDataARB" );
875 /* error already recorded */
879 ASSERT(ctx
->Driver
.GetBufferSubData
);
880 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
885 _mesa_MapBufferARB(GLenum target
, GLenum access
)
887 GET_CURRENT_CONTEXT(ctx
);
888 struct gl_buffer_object
* bufObj
;
889 GLbitfield accessFlags
;
892 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
895 case GL_READ_ONLY_ARB
:
896 accessFlags
= GL_MAP_READ_BIT
;
898 case GL_WRITE_ONLY_ARB
:
899 accessFlags
= GL_MAP_WRITE_BIT
;
901 case GL_READ_WRITE_ARB
:
902 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
909 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
);
913 if (_mesa_bufferobj_mapped(bufObj
)) {
914 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
919 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
920 "glMapBuffer(buffer size = 0)");
924 ASSERT(ctx
->Driver
.MapBufferRange
);
925 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
);
927 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
931 /* The driver callback should have set these fields.
932 * This is important because other modules (like VBO) might call
933 * the driver function directly.
935 ASSERT(bufObj
->Pointer
== map
);
936 ASSERT(bufObj
->Length
== bufObj
->Size
);
937 ASSERT(bufObj
->Offset
== 0);
938 bufObj
->AccessFlags
= accessFlags
;
941 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
942 bufObj
->Written
= GL_TRUE
;
945 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
946 bufObj
->Name
, bufObj
->Size
, access
);
947 if (access
== GL_WRITE_ONLY_ARB
) {
949 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
950 for (i
= 0; i
< bufObj
->Size
; i
++)
957 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
959 /* buffer is 100 bytes larger than requested, fill with magic value */
960 for (i
= 0; i
< 100; i
++) {
961 buf
[bufObj
->Size
- i
- 1] = 123;
966 return bufObj
->Pointer
;
971 _mesa_UnmapBufferARB(GLenum target
)
973 GET_CURRENT_CONTEXT(ctx
);
974 struct gl_buffer_object
*bufObj
;
975 GLboolean status
= GL_TRUE
;
976 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
978 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
);
982 if (!_mesa_bufferobj_mapped(bufObj
)) {
983 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
988 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
989 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
991 /* check that last 100 bytes are still = magic value */
992 for (i
= 0; i
< 100; i
++) {
993 GLuint pos
= bufObj
->Size
- i
- 1;
994 if (buf
[pos
] != 123) {
995 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
996 " at position %d (value = %u)\n",
1004 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1005 GLuint i
, unchanged
= 0;
1006 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1008 /* check which bytes changed */
1009 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1010 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1017 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1018 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1023 status
= ctx
->Driver
.UnmapBuffer( ctx
, bufObj
);
1024 bufObj
->AccessFlags
= default_access_mode(ctx
);
1025 ASSERT(bufObj
->Pointer
== NULL
);
1026 ASSERT(bufObj
->Offset
== 0);
1027 ASSERT(bufObj
->Length
== 0);
1034 _mesa_GetBufferParameterivARB(GLenum target
, GLenum pname
, GLint
*params
)
1036 GET_CURRENT_CONTEXT(ctx
);
1037 struct gl_buffer_object
*bufObj
;
1038 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1040 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
);
1045 case GL_BUFFER_SIZE_ARB
:
1046 *params
= (GLint
) bufObj
->Size
;
1048 case GL_BUFFER_USAGE_ARB
:
1049 *params
= bufObj
->Usage
;
1051 case GL_BUFFER_ACCESS_ARB
:
1052 *params
= simplified_access_mode(bufObj
->AccessFlags
);
1054 case GL_BUFFER_MAPPED_ARB
:
1055 *params
= _mesa_bufferobj_mapped(bufObj
);
1057 case GL_BUFFER_ACCESS_FLAGS
:
1058 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1060 *params
= bufObj
->AccessFlags
;
1062 case GL_BUFFER_MAP_OFFSET
:
1063 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1065 *params
= (GLint
) bufObj
->Offset
;
1067 case GL_BUFFER_MAP_LENGTH
:
1068 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1070 *params
= (GLint
) bufObj
->Length
;
1073 ; /* fall-through */
1077 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1078 _mesa_lookup_enum_by_nr(pname
));
1084 * This is pretty much a duplicate of GetBufferParameteriv() but the
1085 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1088 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1090 GET_CURRENT_CONTEXT(ctx
);
1091 struct gl_buffer_object
*bufObj
;
1092 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1094 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
);
1099 case GL_BUFFER_SIZE_ARB
:
1100 *params
= bufObj
->Size
;
1102 case GL_BUFFER_USAGE_ARB
:
1103 *params
= bufObj
->Usage
;
1105 case GL_BUFFER_ACCESS_ARB
:
1106 *params
= simplified_access_mode(bufObj
->AccessFlags
);
1108 case GL_BUFFER_ACCESS_FLAGS
:
1109 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1111 *params
= bufObj
->AccessFlags
;
1113 case GL_BUFFER_MAPPED_ARB
:
1114 *params
= _mesa_bufferobj_mapped(bufObj
);
1116 case GL_BUFFER_MAP_OFFSET
:
1117 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1119 *params
= bufObj
->Offset
;
1121 case GL_BUFFER_MAP_LENGTH
:
1122 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1124 *params
= bufObj
->Length
;
1127 ; /* fall-through */
1131 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1132 _mesa_lookup_enum_by_nr(pname
));
1137 _mesa_GetBufferPointervARB(GLenum target
, GLenum pname
, GLvoid
**params
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 struct gl_buffer_object
* bufObj
;
1141 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1143 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1144 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1148 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
);
1152 *params
= bufObj
->Pointer
;
1156 * See GL_ARB_map_buffer_range spec
1159 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
1162 GET_CURRENT_CONTEXT(ctx
);
1163 struct gl_buffer_object
*bufObj
;
1166 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1168 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1169 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1170 "glMapBufferRange(extension not supported)");
1175 _mesa_error(ctx
, GL_INVALID_VALUE
,
1176 "glMapBufferRange(offset = %ld)", (long)offset
);
1181 _mesa_error(ctx
, GL_INVALID_VALUE
,
1182 "glMapBufferRange(length = %ld)", (long)length
);
1186 if (access
& ~(GL_MAP_READ_BIT
|
1188 GL_MAP_INVALIDATE_RANGE_BIT
|
1189 GL_MAP_INVALIDATE_BUFFER_BIT
|
1190 GL_MAP_FLUSH_EXPLICIT_BIT
|
1191 GL_MAP_UNSYNCHRONIZED_BIT
)) {
1192 /* generate an error if any undefind bit is set */
1193 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
1197 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
1198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1199 "glMapBufferRange(access indicates neither read or write)");
1203 if ((access
& GL_MAP_READ_BIT
) &&
1204 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
1205 GL_MAP_INVALIDATE_BUFFER_BIT
|
1206 GL_MAP_UNSYNCHRONIZED_BIT
))) {
1207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1208 "glMapBufferRange(invalid access flags)");
1212 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
1213 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
1214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1215 "glMapBufferRange(invalid access flags)");
1219 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
);
1223 if (offset
+ length
> bufObj
->Size
) {
1224 _mesa_error(ctx
, GL_INVALID_VALUE
,
1225 "glMapBufferRange(offset + length > size)");
1229 if (_mesa_bufferobj_mapped(bufObj
)) {
1230 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1231 "glMapBufferRange(buffer already mapped)");
1235 if (!bufObj
->Size
) {
1236 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1237 "glMapBufferRange(buffer size = 0)");
1241 /* Mapping zero bytes should return a non-null pointer. */
1243 static long dummy
= 0;
1244 bufObj
->Pointer
= &dummy
;
1245 bufObj
->Length
= length
;
1246 bufObj
->Offset
= offset
;
1247 bufObj
->AccessFlags
= access
;
1248 return bufObj
->Pointer
;
1251 ASSERT(ctx
->Driver
.MapBufferRange
);
1252 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
);
1254 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1257 /* The driver callback should have set all these fields.
1258 * This is important because other modules (like VBO) might call
1259 * the driver function directly.
1261 ASSERT(bufObj
->Pointer
== map
);
1262 ASSERT(bufObj
->Length
== length
);
1263 ASSERT(bufObj
->Offset
== offset
);
1264 ASSERT(bufObj
->AccessFlags
== access
);
1272 * See GL_ARB_map_buffer_range spec
1275 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
1277 GET_CURRENT_CONTEXT(ctx
);
1278 struct gl_buffer_object
*bufObj
;
1279 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1281 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1283 "glFlushMappedBufferRange(extension not supported)");
1288 _mesa_error(ctx
, GL_INVALID_VALUE
,
1289 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
1294 _mesa_error(ctx
, GL_INVALID_VALUE
,
1295 "glFlushMappedBufferRange(length = %ld)", (long)length
);
1299 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
);
1303 if (!_mesa_bufferobj_mapped(bufObj
)) {
1304 /* buffer is not mapped */
1305 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1306 "glFlushMappedBufferRange(buffer is not mapped)");
1310 if ((bufObj
->AccessFlags
& GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
1311 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1312 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1316 if (offset
+ length
> bufObj
->Length
) {
1317 _mesa_error(ctx
, GL_INVALID_VALUE
,
1318 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
1319 (long)offset
, (long)length
, (long)bufObj
->Length
);
1323 ASSERT(bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
);
1325 if (ctx
->Driver
.FlushMappedBufferRange
)
1326 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
);
1330 #if FEATURE_APPLE_object_purgeable
1332 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1334 struct gl_buffer_object
*bufObj
;
1337 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1339 _mesa_error(ctx
, GL_INVALID_VALUE
,
1340 "glObjectPurgeable(name = 0x%x)", name
);
1343 if (!_mesa_is_bufferobj(bufObj
)) {
1344 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
1348 if (bufObj
->Purgeable
) {
1349 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1350 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1351 return GL_VOLATILE_APPLE
;
1354 bufObj
->Purgeable
= GL_TRUE
;
1356 retval
= GL_VOLATILE_APPLE
;
1357 if (ctx
->Driver
.BufferObjectPurgeable
)
1358 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
1364 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1366 struct gl_texture_object
*bufObj
;
1369 bufObj
= _mesa_lookup_texture(ctx
, name
);
1371 _mesa_error(ctx
, GL_INVALID_VALUE
,
1372 "glObjectPurgeable(name = 0x%x)", name
);
1376 if (bufObj
->Purgeable
) {
1377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1378 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1379 return GL_VOLATILE_APPLE
;
1382 bufObj
->Purgeable
= GL_TRUE
;
1384 retval
= GL_VOLATILE_APPLE
;
1385 if (ctx
->Driver
.TextureObjectPurgeable
)
1386 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
1393 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1397 GET_CURRENT_CONTEXT(ctx
);
1398 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1401 _mesa_error(ctx
, GL_INVALID_VALUE
,
1402 "glObjectPurgeable(name = 0x%x)", name
);
1407 case GL_VOLATILE_APPLE
:
1408 case GL_RELEASED_APPLE
:
1412 _mesa_error(ctx
, GL_INVALID_ENUM
,
1413 "glObjectPurgeable(name = 0x%x) invalid option: %d",
1418 switch (objectType
) {
1420 retval
= texture_object_purgeable(ctx
, name
, option
);
1422 case GL_BUFFER_OBJECT_APPLE
:
1423 retval
= buffer_object_purgeable(ctx
, name
, option
);
1426 _mesa_error(ctx
, GL_INVALID_ENUM
,
1427 "glObjectPurgeable(name = 0x%x) invalid type: %d",
1432 /* In strict conformance to the spec, we must only return VOLATILE when
1433 * when passed the VOLATILE option. Madness.
1435 * XXX First fix the spec, then fix me.
1437 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
1442 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1444 struct gl_buffer_object
*bufObj
;
1447 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1449 _mesa_error(ctx
, GL_INVALID_VALUE
,
1450 "glObjectUnpurgeable(name = 0x%x)", name
);
1454 if (! bufObj
->Purgeable
) {
1455 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1456 "glObjectUnpurgeable(name = 0x%x) object is "
1457 " already \"unpurged\"", name
);
1461 bufObj
->Purgeable
= GL_FALSE
;
1464 if (ctx
->Driver
.BufferObjectUnpurgeable
)
1465 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
1471 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1473 struct gl_texture_object
*bufObj
;
1476 bufObj
= _mesa_lookup_texture(ctx
, name
);
1478 _mesa_error(ctx
, GL_INVALID_VALUE
,
1479 "glObjectUnpurgeable(name = 0x%x)", name
);
1483 if (! bufObj
->Purgeable
) {
1484 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1485 "glObjectUnpurgeable(name = 0x%x) object is"
1486 " already \"unpurged\"", name
);
1490 bufObj
->Purgeable
= GL_FALSE
;
1493 if (ctx
->Driver
.TextureObjectUnpurgeable
)
1494 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
1501 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1503 GET_CURRENT_CONTEXT(ctx
);
1504 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1507 _mesa_error(ctx
, GL_INVALID_VALUE
,
1508 "glObjectUnpurgeable(name = 0x%x)", name
);
1513 case GL_RETAINED_APPLE
:
1514 case GL_UNDEFINED_APPLE
:
1518 _mesa_error(ctx
, GL_INVALID_ENUM
,
1519 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
1524 switch (objectType
) {
1525 case GL_BUFFER_OBJECT_APPLE
:
1526 return buffer_object_unpurgeable(ctx
, name
, option
);
1528 return texture_object_unpurgeable(ctx
, name
, option
);
1530 _mesa_error(ctx
, GL_INVALID_ENUM
,
1531 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
1539 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1540 GLenum pname
, GLint
*params
)
1542 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
1550 case GL_PURGEABLE_APPLE
:
1551 *params
= bufObj
->Purgeable
;
1554 _mesa_error(ctx
, GL_INVALID_ENUM
,
1555 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1562 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1563 GLenum pname
, GLint
*params
)
1565 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
1567 _mesa_error(ctx
, GL_INVALID_VALUE
,
1568 "glObjectUnpurgeable(name = 0x%x)", name
);
1573 case GL_PURGEABLE_APPLE
:
1574 *params
= texObj
->Purgeable
;
1577 _mesa_error(ctx
, GL_INVALID_ENUM
,
1578 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1586 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
1589 GET_CURRENT_CONTEXT(ctx
);
1592 _mesa_error(ctx
, GL_INVALID_VALUE
,
1593 "glGetObjectParameteriv(name = 0x%x)", name
);
1597 switch (objectType
) {
1599 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
1601 case GL_BUFFER_OBJECT_APPLE
:
1602 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
1605 _mesa_error(ctx
, GL_INVALID_ENUM
,
1606 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
1611 #endif /* FEATURE_APPLE_object_purgeable */