mesa: Add indexed binding points for uniform buffer objects.
[mesa.git] / src / mesa / main / bufferobj.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
24 */
25
26
27 /**
28 * \file bufferobj.c
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
31 */
32
33
34 #include "glheader.h"
35 #include "enums.h"
36 #include "hash.h"
37 #include "imports.h"
38 #include "image.h"
39 #include "context.h"
40 #include "bufferobj.h"
41 #include "fbobject.h"
42 #include "mfeatures.h"
43 #include "mtypes.h"
44 #include "texobj.h"
45 #include "transformfeedback.h"
46
47
48 /* Debug flags */
49 /*#define VBO_DEBUG*/
50 /*#define BOUNDS_CHECK*/
51
52
53 /**
54 * Used as a placeholder for buffer objects between glGenBuffers() and
55 * glBindBuffer() so that glIsBuffer() can work correctly.
56 */
57 static struct gl_buffer_object DummyBufferObject;
58
59
60 /**
61 * Return pointer to address of a buffer object target.
62 * \param ctx the GL context
63 * \param target the buffer object target to be retrieved.
64 * \return pointer to pointer to the buffer object bound to \c target in the
65 * specified context or \c NULL if \c target is invalid.
66 */
67 static inline struct gl_buffer_object **
68 get_buffer_target(struct gl_context *ctx, GLenum target)
69 {
70 switch (target) {
71 case GL_ARRAY_BUFFER_ARB:
72 return &ctx->Array.ArrayBufferObj;
73 case GL_ELEMENT_ARRAY_BUFFER_ARB:
74 return &ctx->Array.ArrayObj->ElementArrayBufferObj;
75 case GL_PIXEL_PACK_BUFFER_EXT:
76 return &ctx->Pack.BufferObj;
77 case GL_PIXEL_UNPACK_BUFFER_EXT:
78 return &ctx->Unpack.BufferObj;
79 case GL_COPY_READ_BUFFER:
80 return &ctx->CopyReadBuffer;
81 case GL_COPY_WRITE_BUFFER:
82 return &ctx->CopyWriteBuffer;
83 #if FEATURE_EXT_transform_feedback
84 case GL_TRANSFORM_FEEDBACK_BUFFER:
85 if (ctx->Extensions.EXT_transform_feedback) {
86 return &ctx->TransformFeedback.CurrentBuffer;
87 }
88 break;
89 #endif
90 case GL_TEXTURE_BUFFER:
91 if (ctx->Extensions.ARB_texture_buffer_object) {
92 return &ctx->Texture.BufferObject;
93 }
94 break;
95 case GL_UNIFORM_BUFFER:
96 if (ctx->Extensions.ARB_uniform_buffer_object) {
97 return &ctx->UniformBuffer;
98 }
99 break;
100 default:
101 return NULL;
102 }
103 return NULL;
104 }
105
106
107 /**
108 * Get the buffer object bound to the specified target in a GL context.
109 * \param ctx the GL context
110 * \param target the buffer object target to be retrieved.
111 * \return pointer to the buffer object bound to \c target in the
112 * specified context or \c NULL if \c target is invalid.
113 */
114 static inline struct gl_buffer_object *
115 get_buffer(struct gl_context *ctx, const char *func, GLenum target)
116 {
117 struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
118
119 if (!bufObj) {
120 _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
121 return NULL;
122 }
123
124 if (!_mesa_is_bufferobj(*bufObj)) {
125 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(buffer 0)", func);
126 return NULL;
127 }
128
129 return *bufObj;
130 }
131
132
133 static inline GLenum
134 default_access_mode(const struct gl_context *ctx)
135 {
136 /* Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
137 *
138 * Name Type Initial Value Legal Values
139 * ... ... ... ...
140 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
141 * READ_WRITE
142 *
143 * However, table 6.8 in the GL_OES_mapbuffer extension says:
144 *
145 * Get Value Type Get Command Value Description
146 * --------- ---- ----------- ----- -----------
147 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
148 *
149 * The difference is because GL_OES_mapbuffer only supports mapping buffers
150 * write-only.
151 */
152 return (ctx->API == API_OPENGLES)
153 ? GL_MAP_WRITE_BIT : (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
154 }
155
156
157 /**
158 * Convert a GLbitfield describing the mapped buffer access flags
159 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
160 */
161 static GLenum
162 simplified_access_mode(GLbitfield access)
163 {
164 const GLbitfield rwFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
165 if ((access & rwFlags) == rwFlags)
166 return GL_READ_WRITE;
167 if ((access & GL_MAP_READ_BIT) == GL_MAP_READ_BIT)
168 return GL_READ_ONLY;
169 if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT)
170 return GL_WRITE_ONLY;
171 return GL_READ_WRITE; /* this should never happen, but no big deal */
172 }
173
174
175 /**
176 * Tests the subdata range parameters and sets the GL error code for
177 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
178 *
179 * \param ctx GL context.
180 * \param target Buffer object target on which to operate.
181 * \param offset Offset of the first byte of the subdata range.
182 * \param size Size, in bytes, of the subdata range.
183 * \param caller Name of calling function for recording errors.
184 * \return A pointer to the buffer object bound to \c target in the
185 * specified context or \c NULL if any of the parameter or state
186 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
187 * are invalid.
188 *
189 * \sa glBufferSubDataARB, glGetBufferSubDataARB
190 */
191 static struct gl_buffer_object *
192 buffer_object_subdata_range_good( struct gl_context * ctx, GLenum target,
193 GLintptrARB offset, GLsizeiptrARB size,
194 const char *caller )
195 {
196 struct gl_buffer_object *bufObj;
197
198 if (size < 0) {
199 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", caller);
200 return NULL;
201 }
202
203 if (offset < 0) {
204 _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset < 0)", caller);
205 return NULL;
206 }
207
208 bufObj = get_buffer(ctx, caller, target);
209 if (!bufObj)
210 return NULL;
211
212 if (offset + size > bufObj->Size) {
213 _mesa_error(ctx, GL_INVALID_VALUE,
214 "%s(offset %lu + size %lu > buffer size %lu)", caller,
215 (unsigned long) offset,
216 (unsigned long) size,
217 (unsigned long) bufObj->Size);
218 return NULL;
219 }
220 if (_mesa_bufferobj_mapped(bufObj)) {
221 /* Buffer is currently mapped */
222 _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
223 return NULL;
224 }
225
226 return bufObj;
227 }
228
229
230 /**
231 * Allocate and initialize a new buffer object.
232 *
233 * Default callback for the \c dd_function_table::NewBufferObject() hook.
234 */
235 static struct gl_buffer_object *
236 _mesa_new_buffer_object( struct gl_context *ctx, GLuint name, GLenum target )
237 {
238 struct gl_buffer_object *obj;
239
240 (void) ctx;
241
242 obj = MALLOC_STRUCT(gl_buffer_object);
243 _mesa_initialize_buffer_object(ctx, obj, name, target);
244 return obj;
245 }
246
247
248 /**
249 * Delete a buffer object.
250 *
251 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
252 */
253 static void
254 _mesa_delete_buffer_object(struct gl_context *ctx,
255 struct gl_buffer_object *bufObj)
256 {
257 (void) ctx;
258
259 if (bufObj->Data)
260 free(bufObj->Data);
261
262 /* assign strange values here to help w/ debugging */
263 bufObj->RefCount = -1000;
264 bufObj->Name = ~0;
265
266 _glthread_DESTROY_MUTEX(bufObj->Mutex);
267 free(bufObj);
268 }
269
270
271
272 /**
273 * Set ptr to bufObj w/ reference counting.
274 * This is normally only called from the _mesa_reference_buffer_object() macro
275 * when there's a real pointer change.
276 */
277 void
278 _mesa_reference_buffer_object_(struct gl_context *ctx,
279 struct gl_buffer_object **ptr,
280 struct gl_buffer_object *bufObj)
281 {
282 if (*ptr) {
283 /* Unreference the old buffer */
284 GLboolean deleteFlag = GL_FALSE;
285 struct gl_buffer_object *oldObj = *ptr;
286
287 _glthread_LOCK_MUTEX(oldObj->Mutex);
288 ASSERT(oldObj->RefCount > 0);
289 oldObj->RefCount--;
290 #if 0
291 printf("BufferObj %p %d DECR to %d\n",
292 (void *) oldObj, oldObj->Name, oldObj->RefCount);
293 #endif
294 deleteFlag = (oldObj->RefCount == 0);
295 _glthread_UNLOCK_MUTEX(oldObj->Mutex);
296
297 if (deleteFlag) {
298
299 /* some sanity checking: don't delete a buffer still in use */
300 #if 0
301 /* unfortunately, these tests are invalid during context tear-down */
302 ASSERT(ctx->Array.ArrayBufferObj != bufObj);
303 ASSERT(ctx->Array.ArrayObj->ElementArrayBufferObj != bufObj);
304 ASSERT(ctx->Array.ArrayObj->Vertex.BufferObj != bufObj);
305 #endif
306
307 ASSERT(ctx->Driver.DeleteBuffer);
308 ctx->Driver.DeleteBuffer(ctx, oldObj);
309 }
310
311 *ptr = NULL;
312 }
313 ASSERT(!*ptr);
314
315 if (bufObj) {
316 /* reference new buffer */
317 _glthread_LOCK_MUTEX(bufObj->Mutex);
318 if (bufObj->RefCount == 0) {
319 /* this buffer's being deleted (look just above) */
320 /* Not sure this can every really happen. Warn if it does. */
321 _mesa_problem(NULL, "referencing deleted buffer object");
322 *ptr = NULL;
323 }
324 else {
325 bufObj->RefCount++;
326 #if 0
327 printf("BufferObj %p %d INCR to %d\n",
328 (void *) bufObj, bufObj->Name, bufObj->RefCount);
329 #endif
330 *ptr = bufObj;
331 }
332 _glthread_UNLOCK_MUTEX(bufObj->Mutex);
333 }
334 }
335
336
337 /**
338 * Initialize a buffer object to default values.
339 */
340 void
341 _mesa_initialize_buffer_object( struct gl_context *ctx,
342 struct gl_buffer_object *obj,
343 GLuint name, GLenum target )
344 {
345 (void) target;
346
347 memset(obj, 0, sizeof(struct gl_buffer_object));
348 _glthread_INIT_MUTEX(obj->Mutex);
349 obj->RefCount = 1;
350 obj->Name = name;
351 obj->Usage = GL_STATIC_DRAW_ARB;
352 obj->AccessFlags = default_access_mode(ctx);
353 }
354
355
356
357 /**
358 * Callback called from _mesa_HashWalk()
359 */
360 static void
361 count_buffer_size(GLuint key, void *data, void *userData)
362 {
363 const struct gl_buffer_object *bufObj =
364 (const struct gl_buffer_object *) data;
365 GLuint *total = (GLuint *) userData;
366
367 *total = *total + bufObj->Size;
368 }
369
370
371 /**
372 * Compute total size (in bytes) of all buffer objects for the given context.
373 * For debugging purposes.
374 */
375 GLuint
376 _mesa_total_buffer_object_memory(struct gl_context *ctx)
377 {
378 GLuint total = 0;
379
380 _mesa_HashWalk(ctx->Shared->BufferObjects, count_buffer_size, &total);
381
382 return total;
383 }
384
385
386 /**
387 * Allocate space for and store data in a buffer object. Any data that was
388 * previously stored in the buffer object is lost. If \c data is \c NULL,
389 * memory will be allocated, but no copy will occur.
390 *
391 * This is the default callback for \c dd_function_table::BufferData()
392 * Note that all GL error checking will have been done already.
393 *
394 * \param ctx GL context.
395 * \param target Buffer object target on which to operate.
396 * \param size Size, in bytes, of the new data store.
397 * \param data Pointer to the data to store in the buffer object. This
398 * pointer may be \c NULL.
399 * \param usage Hints about how the data will be used.
400 * \param bufObj Object to be used.
401 *
402 * \return GL_TRUE for success, GL_FALSE for failure
403 * \sa glBufferDataARB, dd_function_table::BufferData.
404 */
405 static GLboolean
406 _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
407 const GLvoid * data, GLenum usage,
408 struct gl_buffer_object * bufObj )
409 {
410 void * new_data;
411
412 (void) ctx; (void) target;
413
414 new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
415 if (new_data) {
416 bufObj->Data = (GLubyte *) new_data;
417 bufObj->Size = size;
418 bufObj->Usage = usage;
419
420 if (data) {
421 memcpy( bufObj->Data, data, size );
422 }
423
424 return GL_TRUE;
425 }
426 else {
427 return GL_FALSE;
428 }
429 }
430
431
432 /**
433 * Replace data in a subrange of buffer object. If the data range
434 * specified by \c size + \c offset extends beyond the end of the buffer or
435 * if \c data is \c NULL, no copy is performed.
436 *
437 * This is the default callback for \c dd_function_table::BufferSubData()
438 * Note that all GL error checking will have been done already.
439 *
440 * \param ctx GL context.
441 * \param target Buffer object target on which to operate.
442 * \param offset Offset of the first byte to be modified.
443 * \param size Size, in bytes, of the data range.
444 * \param data Pointer to the data to store in the buffer object.
445 * \param bufObj Object to be used.
446 *
447 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
448 */
449 static void
450 _mesa_buffer_subdata( struct gl_context *ctx, GLintptrARB offset,
451 GLsizeiptrARB size, const GLvoid * data,
452 struct gl_buffer_object * bufObj )
453 {
454 (void) ctx;
455
456 /* this should have been caught in _mesa_BufferSubData() */
457 ASSERT(size + offset <= bufObj->Size);
458
459 if (bufObj->Data) {
460 memcpy( (GLubyte *) bufObj->Data + offset, data, size );
461 }
462 }
463
464
465 /**
466 * Retrieve data from a subrange of buffer object. If the data range
467 * specified by \c size + \c offset extends beyond the end of the buffer or
468 * if \c data is \c NULL, no copy is performed.
469 *
470 * This is the default callback for \c dd_function_table::GetBufferSubData()
471 * Note that all GL error checking will have been done already.
472 *
473 * \param ctx GL context.
474 * \param target Buffer object target on which to operate.
475 * \param offset Offset of the first byte to be fetched.
476 * \param size Size, in bytes, of the data range.
477 * \param data Destination for data
478 * \param bufObj Object to be used.
479 *
480 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
481 */
482 static void
483 _mesa_buffer_get_subdata( struct gl_context *ctx, GLintptrARB offset,
484 GLsizeiptrARB size, GLvoid * data,
485 struct gl_buffer_object * bufObj )
486 {
487 (void) ctx;
488
489 if (bufObj->Data && ((GLsizeiptrARB) (size + offset) <= bufObj->Size)) {
490 memcpy( data, (GLubyte *) bufObj->Data + offset, size );
491 }
492 }
493
494
495 /**
496 * Default fallback for \c dd_function_table::MapBufferRange().
497 * Called via glMapBufferRange().
498 */
499 static void *
500 _mesa_buffer_map_range( struct gl_context *ctx, GLintptr offset,
501 GLsizeiptr length, GLbitfield access,
502 struct gl_buffer_object *bufObj )
503 {
504 (void) ctx;
505 assert(!_mesa_bufferobj_mapped(bufObj));
506 /* Just return a direct pointer to the data */
507 bufObj->Pointer = bufObj->Data + offset;
508 bufObj->Length = length;
509 bufObj->Offset = offset;
510 bufObj->AccessFlags = access;
511 return bufObj->Pointer;
512 }
513
514
515 /**
516 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
517 * Called via glFlushMappedBufferRange().
518 */
519 static void
520 _mesa_buffer_flush_mapped_range( struct gl_context *ctx,
521 GLintptr offset, GLsizeiptr length,
522 struct gl_buffer_object *obj )
523 {
524 (void) ctx;
525 (void) offset;
526 (void) length;
527 (void) obj;
528 /* no-op */
529 }
530
531
532 /**
533 * Default callback for \c dd_function_table::MapBuffer().
534 *
535 * The input parameters will have been already tested for errors.
536 *
537 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
538 */
539 static GLboolean
540 _mesa_buffer_unmap( struct gl_context *ctx, struct gl_buffer_object *bufObj )
541 {
542 (void) ctx;
543 /* XXX we might assert here that bufObj->Pointer is non-null */
544 bufObj->Pointer = NULL;
545 bufObj->Length = 0;
546 bufObj->Offset = 0;
547 bufObj->AccessFlags = 0x0;
548 return GL_TRUE;
549 }
550
551
552 /**
553 * Default fallback for \c dd_function_table::CopyBufferSubData().
554 * Called via glCopyBufferSubData().
555 */
556 static void
557 _mesa_copy_buffer_subdata(struct gl_context *ctx,
558 struct gl_buffer_object *src,
559 struct gl_buffer_object *dst,
560 GLintptr readOffset, GLintptr writeOffset,
561 GLsizeiptr size)
562 {
563 GLubyte *srcPtr, *dstPtr;
564
565 /* the buffers should not be mapped */
566 assert(!_mesa_bufferobj_mapped(src));
567 assert(!_mesa_bufferobj_mapped(dst));
568
569 if (src == dst) {
570 srcPtr = dstPtr = ctx->Driver.MapBufferRange(ctx, 0, src->Size,
571 GL_MAP_READ_BIT |
572 GL_MAP_WRITE_BIT, src);
573
574 if (!srcPtr)
575 return;
576
577 srcPtr += readOffset;
578 dstPtr += writeOffset;
579 } else {
580 srcPtr = ctx->Driver.MapBufferRange(ctx, readOffset, size,
581 GL_MAP_READ_BIT, src);
582 dstPtr = ctx->Driver.MapBufferRange(ctx, writeOffset, size,
583 (GL_MAP_WRITE_BIT |
584 GL_MAP_INVALIDATE_RANGE_BIT), dst);
585 }
586
587 /* Note: the src and dst regions will never overlap. Trying to do so
588 * would generate GL_INVALID_VALUE earlier.
589 */
590 if (srcPtr && dstPtr)
591 memcpy(dstPtr, srcPtr, size);
592
593 ctx->Driver.UnmapBuffer(ctx, src);
594 if (dst != src)
595 ctx->Driver.UnmapBuffer(ctx, dst);
596 }
597
598
599
600 /**
601 * Initialize the state associated with buffer objects
602 */
603 void
604 _mesa_init_buffer_objects( struct gl_context *ctx )
605 {
606 GLuint i;
607
608 memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
609 _glthread_INIT_MUTEX(DummyBufferObject.Mutex);
610 DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
611
612 _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj,
613 ctx->Shared->NullBufferObj);
614
615 _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer,
616 ctx->Shared->NullBufferObj);
617 _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
618 ctx->Shared->NullBufferObj);
619
620 ctx->UniformBufferBindings = calloc(ctx->Const.MaxUniformBufferBindings,
621 sizeof(*ctx->UniformBufferBindings));
622
623 _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer,
624 ctx->Shared->NullBufferObj);
625
626 for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
627 _mesa_reference_buffer_object(ctx,
628 &ctx->UniformBufferBindings[i].BufferObject,
629 ctx->Shared->NullBufferObj);
630 ctx->UniformBufferBindings[i].Offset = -1;
631 ctx->UniformBufferBindings[i].Size = -1;
632 }
633 }
634
635
636 void
637 _mesa_free_buffer_objects( struct gl_context *ctx )
638 {
639 GLuint i;
640
641 _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL);
642
643 _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer, NULL);
644 _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer, NULL);
645
646 _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, NULL);
647
648 for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
649 _mesa_reference_buffer_object(ctx,
650 &ctx->UniformBufferBindings[i].BufferObject,
651 NULL);
652 }
653
654 free(ctx->UniformBufferBindings);
655 ctx->UniformBufferBindings = NULL;
656 }
657
658
659 /**
660 * Bind the specified target to buffer for the specified context.
661 * Called by glBindBuffer() and other functions.
662 */
663 static void
664 bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
665 {
666 struct gl_buffer_object *oldBufObj;
667 struct gl_buffer_object *newBufObj = NULL;
668 struct gl_buffer_object **bindTarget = NULL;
669
670 bindTarget = get_buffer_target(ctx, target);
671 if (!bindTarget) {
672 _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target 0x%x)", target);
673 return;
674 }
675
676 /* Get pointer to old buffer object (to be unbound) */
677 oldBufObj = *bindTarget;
678 if (oldBufObj && oldBufObj->Name == buffer && !oldBufObj->DeletePending)
679 return; /* rebinding the same buffer object- no change */
680
681 /*
682 * Get pointer to new buffer object (newBufObj)
683 */
684 if (buffer == 0) {
685 /* The spec says there's not a buffer object named 0, but we use
686 * one internally because it simplifies things.
687 */
688 newBufObj = ctx->Shared->NullBufferObj;
689 }
690 else {
691 /* non-default buffer object */
692 newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
693 if (!newBufObj || newBufObj == &DummyBufferObject) {
694 /* If this is a new buffer object id, or one which was generated but
695 * never used before, allocate a buffer object now.
696 */
697 ASSERT(ctx->Driver.NewBufferObject);
698 newBufObj = ctx->Driver.NewBufferObject(ctx, buffer, target);
699 if (!newBufObj) {
700 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindBufferARB");
701 return;
702 }
703 _mesa_HashInsert(ctx->Shared->BufferObjects, buffer, newBufObj);
704 }
705 }
706
707 /* bind new buffer */
708 _mesa_reference_buffer_object(ctx, bindTarget, newBufObj);
709
710 /* Pass BindBuffer call to device driver */
711 if (ctx->Driver.BindBuffer)
712 ctx->Driver.BindBuffer( ctx, target, newBufObj );
713 }
714
715
716 /**
717 * Update the default buffer objects in the given context to reference those
718 * specified in the shared state and release those referencing the old
719 * shared state.
720 */
721 void
722 _mesa_update_default_objects_buffer_objects(struct gl_context *ctx)
723 {
724 /* Bind the NullBufferObj to remove references to those
725 * in the shared context hash table.
726 */
727 bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0);
728 bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
729 bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0);
730 bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0);
731 }
732
733
734
735 /**
736 * Return the gl_buffer_object for the given ID.
737 * Always return NULL for ID 0.
738 */
739 struct gl_buffer_object *
740 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer)
741 {
742 if (buffer == 0)
743 return NULL;
744 else
745 return (struct gl_buffer_object *)
746 _mesa_HashLookup(ctx->Shared->BufferObjects, buffer);
747 }
748
749
750 /**
751 * If *ptr points to obj, set ptr = the Null/default buffer object.
752 * This is a helper for buffer object deletion.
753 * The GL spec says that deleting a buffer object causes it to get
754 * unbound from all arrays in the current context.
755 */
756 static void
757 unbind(struct gl_context *ctx,
758 struct gl_buffer_object **ptr,
759 struct gl_buffer_object *obj)
760 {
761 if (*ptr == obj) {
762 _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
763 }
764 }
765
766
767 /**
768 * Plug default/fallback buffer object functions into the device
769 * driver hooks.
770 */
771 void
772 _mesa_init_buffer_object_functions(struct dd_function_table *driver)
773 {
774 /* GL_ARB_vertex/pixel_buffer_object */
775 driver->NewBufferObject = _mesa_new_buffer_object;
776 driver->DeleteBuffer = _mesa_delete_buffer_object;
777 driver->BindBuffer = NULL;
778 driver->BufferData = _mesa_buffer_data;
779 driver->BufferSubData = _mesa_buffer_subdata;
780 driver->GetBufferSubData = _mesa_buffer_get_subdata;
781 driver->UnmapBuffer = _mesa_buffer_unmap;
782
783 /* GL_ARB_map_buffer_range */
784 driver->MapBufferRange = _mesa_buffer_map_range;
785 driver->FlushMappedBufferRange = _mesa_buffer_flush_mapped_range;
786
787 /* GL_ARB_copy_buffer */
788 driver->CopyBufferSubData = _mesa_copy_buffer_subdata;
789 }
790
791
792
793 /**********************************************************************/
794 /* API Functions */
795 /**********************************************************************/
796
797 void GLAPIENTRY
798 _mesa_BindBufferARB(GLenum target, GLuint buffer)
799 {
800 GET_CURRENT_CONTEXT(ctx);
801 ASSERT_OUTSIDE_BEGIN_END(ctx);
802
803 if (MESA_VERBOSE & VERBOSE_API)
804 _mesa_debug(ctx, "glBindBuffer(%s, %u)\n",
805 _mesa_lookup_enum_by_nr(target), buffer);
806
807 bind_buffer_object(ctx, target, buffer);
808 }
809
810
811 /**
812 * Delete a set of buffer objects.
813 *
814 * \param n Number of buffer objects to delete.
815 * \param ids Array of \c n buffer object IDs.
816 */
817 void GLAPIENTRY
818 _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
819 {
820 GET_CURRENT_CONTEXT(ctx);
821 GLsizei i;
822 ASSERT_OUTSIDE_BEGIN_END(ctx);
823 FLUSH_VERTICES(ctx, 0);
824
825 if (n < 0) {
826 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteBuffersARB(n)");
827 return;
828 }
829
830 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
831
832 for (i = 0; i < n; i++) {
833 struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
834 if (bufObj) {
835 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
836 GLuint j;
837
838 ASSERT(bufObj->Name == ids[i] || bufObj == &DummyBufferObject);
839
840 if (_mesa_bufferobj_mapped(bufObj)) {
841 /* if mapped, unmap it now */
842 ctx->Driver.UnmapBuffer(ctx, bufObj);
843 bufObj->AccessFlags = default_access_mode(ctx);
844 bufObj->Pointer = NULL;
845 }
846
847 /* unbind any vertex pointers bound to this buffer */
848 for (j = 0; j < Elements(arrayObj->VertexAttrib); j++) {
849 unbind(ctx, &arrayObj->VertexAttrib[j].BufferObj, bufObj);
850 }
851
852 if (ctx->Array.ArrayBufferObj == bufObj) {
853 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
854 }
855 if (arrayObj->ElementArrayBufferObj == bufObj) {
856 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
857 }
858
859 /* unbind ARB_copy_buffer binding points */
860 if (ctx->CopyReadBuffer == bufObj) {
861 _mesa_BindBufferARB( GL_COPY_READ_BUFFER, 0 );
862 }
863 if (ctx->CopyWriteBuffer == bufObj) {
864 _mesa_BindBufferARB( GL_COPY_WRITE_BUFFER, 0 );
865 }
866
867 /* unbind transform feedback binding points */
868 if (ctx->TransformFeedback.CurrentBuffer == bufObj) {
869 _mesa_BindBufferARB( GL_TRANSFORM_FEEDBACK_BUFFER, 0 );
870 }
871 for (j = 0; j < MAX_FEEDBACK_ATTRIBS; j++) {
872 if (ctx->TransformFeedback.CurrentObject->Buffers[j] == bufObj) {
873 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, j, 0 );
874 }
875 }
876
877 if (ctx->UniformBuffer == bufObj) {
878 _mesa_BindBufferARB( GL_UNIFORM_BUFFER, 0 );
879 }
880
881 /* unbind any pixel pack/unpack pointers bound to this buffer */
882 if (ctx->Pack.BufferObj == bufObj) {
883 _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );
884 }
885 if (ctx->Unpack.BufferObj == bufObj) {
886 _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, 0 );
887 }
888
889 if (ctx->Texture.BufferObject == bufObj) {
890 _mesa_BindBufferARB( GL_TEXTURE_BUFFER, 0 );
891 }
892
893 /* The ID is immediately freed for re-use */
894 _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
895 /* Make sure we do not run into the classic ABA problem on bind.
896 * We don't want to allow re-binding a buffer object that's been
897 * "deleted" by glDeleteBuffers().
898 *
899 * The explicit rebinding to the default object in the current context
900 * prevents the above in the current context, but another context
901 * sharing the same objects might suffer from this problem.
902 * The alternative would be to do the hash lookup in any case on bind
903 * which would introduce more runtime overhead than this.
904 */
905 bufObj->DeletePending = GL_TRUE;
906 _mesa_reference_buffer_object(ctx, &bufObj, NULL);
907 }
908 }
909
910 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
911 }
912
913
914 /**
915 * Generate a set of unique buffer object IDs and store them in \c buffer.
916 *
917 * \param n Number of IDs to generate.
918 * \param buffer Array of \c n locations to store the IDs.
919 */
920 void GLAPIENTRY
921 _mesa_GenBuffersARB(GLsizei n, GLuint *buffer)
922 {
923 GET_CURRENT_CONTEXT(ctx);
924 GLuint first;
925 GLint i;
926 ASSERT_OUTSIDE_BEGIN_END(ctx);
927
928 if (MESA_VERBOSE & VERBOSE_API)
929 _mesa_debug(ctx, "glGenBuffers(%d)\n", n);
930
931 if (n < 0) {
932 _mesa_error(ctx, GL_INVALID_VALUE, "glGenBuffersARB");
933 return;
934 }
935
936 if (!buffer) {
937 return;
938 }
939
940 /*
941 * This must be atomic (generation and allocation of buffer object IDs)
942 */
943 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
944
945 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
946
947 /* Insert the ID and pointer to dummy buffer object into hash table */
948 for (i = 0; i < n; i++) {
949 _mesa_HashInsert(ctx->Shared->BufferObjects, first + i,
950 &DummyBufferObject);
951 buffer[i] = first + i;
952 }
953
954 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
955 }
956
957
958 /**
959 * Determine if ID is the name of a buffer object.
960 *
961 * \param id ID of the potential buffer object.
962 * \return \c GL_TRUE if \c id is the name of a buffer object,
963 * \c GL_FALSE otherwise.
964 */
965 GLboolean GLAPIENTRY
966 _mesa_IsBufferARB(GLuint id)
967 {
968 struct gl_buffer_object *bufObj;
969 GET_CURRENT_CONTEXT(ctx);
970 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
971
972 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
973 bufObj = _mesa_lookup_bufferobj(ctx, id);
974 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
975
976 return bufObj && bufObj != &DummyBufferObject;
977 }
978
979
980 void GLAPIENTRY
981 _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
982 const GLvoid * data, GLenum usage)
983 {
984 GET_CURRENT_CONTEXT(ctx);
985 struct gl_buffer_object *bufObj;
986 ASSERT_OUTSIDE_BEGIN_END(ctx);
987
988 if (MESA_VERBOSE & VERBOSE_API)
989 _mesa_debug(ctx, "glBufferData(%s, %ld, %p, %s)\n",
990 _mesa_lookup_enum_by_nr(target),
991 (long int) size, data,
992 _mesa_lookup_enum_by_nr(usage));
993
994 if (size < 0) {
995 _mesa_error(ctx, GL_INVALID_VALUE, "glBufferDataARB(size < 0)");
996 return;
997 }
998
999 switch (usage) {
1000 case GL_STREAM_DRAW_ARB:
1001 case GL_STREAM_READ_ARB:
1002 case GL_STREAM_COPY_ARB:
1003 case GL_STATIC_DRAW_ARB:
1004 case GL_STATIC_READ_ARB:
1005 case GL_STATIC_COPY_ARB:
1006 case GL_DYNAMIC_DRAW_ARB:
1007 case GL_DYNAMIC_READ_ARB:
1008 case GL_DYNAMIC_COPY_ARB:
1009 /* OK */
1010 break;
1011 default:
1012 _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(usage)");
1013 return;
1014 }
1015
1016 bufObj = get_buffer(ctx, "glBufferDataARB", target);
1017 if (!bufObj)
1018 return;
1019
1020 if (_mesa_bufferobj_mapped(bufObj)) {
1021 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1022 ctx->Driver.UnmapBuffer(ctx, bufObj);
1023 bufObj->AccessFlags = default_access_mode(ctx);
1024 ASSERT(bufObj->Pointer == NULL);
1025 }
1026
1027 FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
1028
1029 bufObj->Written = GL_TRUE;
1030
1031 #ifdef VBO_DEBUG
1032 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1033 bufObj->Name, size, data, usage);
1034 #endif
1035
1036 #ifdef BOUNDS_CHECK
1037 size += 100;
1038 #endif
1039
1040 ASSERT(ctx->Driver.BufferData);
1041 if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) {
1042 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB()");
1043 }
1044 }
1045
1046
1047 void GLAPIENTRY
1048 _mesa_BufferSubDataARB(GLenum target, GLintptrARB offset,
1049 GLsizeiptrARB size, const GLvoid * data)
1050 {
1051 GET_CURRENT_CONTEXT(ctx);
1052 struct gl_buffer_object *bufObj;
1053 ASSERT_OUTSIDE_BEGIN_END(ctx);
1054
1055 bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
1056 "glBufferSubDataARB" );
1057 if (!bufObj) {
1058 /* error already recorded */
1059 return;
1060 }
1061
1062 if (size == 0)
1063 return;
1064
1065 bufObj->Written = GL_TRUE;
1066
1067 ASSERT(ctx->Driver.BufferSubData);
1068 ctx->Driver.BufferSubData( ctx, offset, size, data, bufObj );
1069 }
1070
1071
1072 void GLAPIENTRY
1073 _mesa_GetBufferSubDataARB(GLenum target, GLintptrARB offset,
1074 GLsizeiptrARB size, void * data)
1075 {
1076 GET_CURRENT_CONTEXT(ctx);
1077 struct gl_buffer_object *bufObj;
1078 ASSERT_OUTSIDE_BEGIN_END(ctx);
1079
1080 bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
1081 "glGetBufferSubDataARB" );
1082 if (!bufObj) {
1083 /* error already recorded */
1084 return;
1085 }
1086
1087 ASSERT(ctx->Driver.GetBufferSubData);
1088 ctx->Driver.GetBufferSubData( ctx, offset, size, data, bufObj );
1089 }
1090
1091
1092 void * GLAPIENTRY
1093 _mesa_MapBufferARB(GLenum target, GLenum access)
1094 {
1095 GET_CURRENT_CONTEXT(ctx);
1096 struct gl_buffer_object * bufObj;
1097 GLbitfield accessFlags;
1098 void *map;
1099
1100 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
1101
1102 switch (access) {
1103 case GL_READ_ONLY_ARB:
1104 accessFlags = GL_MAP_READ_BIT;
1105 break;
1106 case GL_WRITE_ONLY_ARB:
1107 accessFlags = GL_MAP_WRITE_BIT;
1108 break;
1109 case GL_READ_WRITE_ARB:
1110 accessFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
1111 break;
1112 default:
1113 _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(access)");
1114 return NULL;
1115 }
1116
1117 bufObj = get_buffer(ctx, "glMapBufferARB", target);
1118 if (!bufObj)
1119 return NULL;
1120
1121 if (_mesa_bufferobj_mapped(bufObj)) {
1122 _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(already mapped)");
1123 return NULL;
1124 }
1125
1126 if (!bufObj->Size) {
1127 _mesa_error(ctx, GL_OUT_OF_MEMORY,
1128 "glMapBuffer(buffer size = 0)");
1129 return NULL;
1130 }
1131
1132 ASSERT(ctx->Driver.MapBufferRange);
1133 map = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size, accessFlags, bufObj);
1134 if (!map) {
1135 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
1136 return NULL;
1137 }
1138 else {
1139 /* The driver callback should have set these fields.
1140 * This is important because other modules (like VBO) might call
1141 * the driver function directly.
1142 */
1143 ASSERT(bufObj->Pointer == map);
1144 ASSERT(bufObj->Length == bufObj->Size);
1145 ASSERT(bufObj->Offset == 0);
1146 bufObj->AccessFlags = accessFlags;
1147 }
1148
1149 if (access == GL_WRITE_ONLY_ARB || access == GL_READ_WRITE_ARB)
1150 bufObj->Written = GL_TRUE;
1151
1152 #ifdef VBO_DEBUG
1153 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1154 bufObj->Name, bufObj->Size, access);
1155 if (access == GL_WRITE_ONLY_ARB) {
1156 GLuint i;
1157 GLubyte *b = (GLubyte *) bufObj->Pointer;
1158 for (i = 0; i < bufObj->Size; i++)
1159 b[i] = i & 0xff;
1160 }
1161 #endif
1162
1163 #ifdef BOUNDS_CHECK
1164 {
1165 GLubyte *buf = (GLubyte *) bufObj->Pointer;
1166 GLuint i;
1167 /* buffer is 100 bytes larger than requested, fill with magic value */
1168 for (i = 0; i < 100; i++) {
1169 buf[bufObj->Size - i - 1] = 123;
1170 }
1171 }
1172 #endif
1173
1174 return bufObj->Pointer;
1175 }
1176
1177
1178 GLboolean GLAPIENTRY
1179 _mesa_UnmapBufferARB(GLenum target)
1180 {
1181 GET_CURRENT_CONTEXT(ctx);
1182 struct gl_buffer_object *bufObj;
1183 GLboolean status = GL_TRUE;
1184 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1185
1186 bufObj = get_buffer(ctx, "glUnmapBufferARB", target);
1187 if (!bufObj)
1188 return GL_FALSE;
1189
1190 if (!_mesa_bufferobj_mapped(bufObj)) {
1191 _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB");
1192 return GL_FALSE;
1193 }
1194
1195 #ifdef BOUNDS_CHECK
1196 if (bufObj->Access != GL_READ_ONLY_ARB) {
1197 GLubyte *buf = (GLubyte *) bufObj->Pointer;
1198 GLuint i;
1199 /* check that last 100 bytes are still = magic value */
1200 for (i = 0; i < 100; i++) {
1201 GLuint pos = bufObj->Size - i - 1;
1202 if (buf[pos] != 123) {
1203 _mesa_warning(ctx, "Out of bounds buffer object write detected"
1204 " at position %d (value = %u)\n",
1205 pos, buf[pos]);
1206 }
1207 }
1208 }
1209 #endif
1210
1211 #ifdef VBO_DEBUG
1212 if (bufObj->AccessFlags & GL_MAP_WRITE_BIT) {
1213 GLuint i, unchanged = 0;
1214 GLubyte *b = (GLubyte *) bufObj->Pointer;
1215 GLint pos = -1;
1216 /* check which bytes changed */
1217 for (i = 0; i < bufObj->Size - 1; i++) {
1218 if (b[i] == (i & 0xff) && b[i+1] == ((i+1) & 0xff)) {
1219 unchanged++;
1220 if (pos == -1)
1221 pos = i;
1222 }
1223 }
1224 if (unchanged) {
1225 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1226 bufObj->Name, unchanged, bufObj->Size, pos);
1227 }
1228 }
1229 #endif
1230
1231 status = ctx->Driver.UnmapBuffer( ctx, bufObj );
1232 bufObj->AccessFlags = default_access_mode(ctx);
1233 ASSERT(bufObj->Pointer == NULL);
1234 ASSERT(bufObj->Offset == 0);
1235 ASSERT(bufObj->Length == 0);
1236
1237 return status;
1238 }
1239
1240
1241 void GLAPIENTRY
1242 _mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
1243 {
1244 GET_CURRENT_CONTEXT(ctx);
1245 struct gl_buffer_object *bufObj;
1246 ASSERT_OUTSIDE_BEGIN_END(ctx);
1247
1248 bufObj = get_buffer(ctx, "glGetBufferParameterivARB", target);
1249 if (!bufObj)
1250 return;
1251
1252 switch (pname) {
1253 case GL_BUFFER_SIZE_ARB:
1254 *params = (GLint) bufObj->Size;
1255 return;
1256 case GL_BUFFER_USAGE_ARB:
1257 *params = bufObj->Usage;
1258 return;
1259 case GL_BUFFER_ACCESS_ARB:
1260 *params = simplified_access_mode(bufObj->AccessFlags);
1261 return;
1262 case GL_BUFFER_MAPPED_ARB:
1263 *params = _mesa_bufferobj_mapped(bufObj);
1264 return;
1265 case GL_BUFFER_ACCESS_FLAGS:
1266 if (!ctx->Extensions.ARB_map_buffer_range)
1267 goto invalid_pname;
1268 *params = bufObj->AccessFlags;
1269 return;
1270 case GL_BUFFER_MAP_OFFSET:
1271 if (!ctx->Extensions.ARB_map_buffer_range)
1272 goto invalid_pname;
1273 *params = (GLint) bufObj->Offset;
1274 return;
1275 case GL_BUFFER_MAP_LENGTH:
1276 if (!ctx->Extensions.ARB_map_buffer_range)
1277 goto invalid_pname;
1278 *params = (GLint) bufObj->Length;
1279 return;
1280 default:
1281 ; /* fall-through */
1282 }
1283
1284 invalid_pname:
1285 _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(pname=%s)",
1286 _mesa_lookup_enum_by_nr(pname));
1287 }
1288
1289
1290 /**
1291 * New in GL 3.2
1292 * This is pretty much a duplicate of GetBufferParameteriv() but the
1293 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1294 */
1295 void GLAPIENTRY
1296 _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
1297 {
1298 GET_CURRENT_CONTEXT(ctx);
1299 struct gl_buffer_object *bufObj;
1300 ASSERT_OUTSIDE_BEGIN_END(ctx);
1301
1302 bufObj = get_buffer(ctx, "glGetBufferParameteri64v", target);
1303 if (!bufObj)
1304 return;
1305
1306 switch (pname) {
1307 case GL_BUFFER_SIZE_ARB:
1308 *params = bufObj->Size;
1309 return;
1310 case GL_BUFFER_USAGE_ARB:
1311 *params = bufObj->Usage;
1312 return;
1313 case GL_BUFFER_ACCESS_ARB:
1314 *params = simplified_access_mode(bufObj->AccessFlags);
1315 return;
1316 case GL_BUFFER_ACCESS_FLAGS:
1317 if (!ctx->Extensions.ARB_map_buffer_range)
1318 goto invalid_pname;
1319 *params = bufObj->AccessFlags;
1320 return;
1321 case GL_BUFFER_MAPPED_ARB:
1322 *params = _mesa_bufferobj_mapped(bufObj);
1323 return;
1324 case GL_BUFFER_MAP_OFFSET:
1325 if (!ctx->Extensions.ARB_map_buffer_range)
1326 goto invalid_pname;
1327 *params = bufObj->Offset;
1328 return;
1329 case GL_BUFFER_MAP_LENGTH:
1330 if (!ctx->Extensions.ARB_map_buffer_range)
1331 goto invalid_pname;
1332 *params = bufObj->Length;
1333 return;
1334 default:
1335 ; /* fall-through */
1336 }
1337
1338 invalid_pname:
1339 _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(pname=%s)",
1340 _mesa_lookup_enum_by_nr(pname));
1341 }
1342
1343
1344 void GLAPIENTRY
1345 _mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
1346 {
1347 GET_CURRENT_CONTEXT(ctx);
1348 struct gl_buffer_object * bufObj;
1349 ASSERT_OUTSIDE_BEGIN_END(ctx);
1350
1351 if (pname != GL_BUFFER_MAP_POINTER_ARB) {
1352 _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
1353 return;
1354 }
1355
1356 bufObj = get_buffer(ctx, "glGetBufferPointervARB", target);
1357 if (!bufObj)
1358 return;
1359
1360 *params = bufObj->Pointer;
1361 }
1362
1363
1364 void GLAPIENTRY
1365 _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
1366 GLintptr readOffset, GLintptr writeOffset,
1367 GLsizeiptr size)
1368 {
1369 GET_CURRENT_CONTEXT(ctx);
1370 struct gl_buffer_object *src, *dst;
1371 ASSERT_OUTSIDE_BEGIN_END(ctx);
1372
1373 src = get_buffer(ctx, "glCopyBufferSubData", readTarget);
1374 if (!src)
1375 return;
1376
1377 dst = get_buffer(ctx, "glCopyBufferSubData", writeTarget);
1378 if (!dst)
1379 return;
1380
1381 if (_mesa_bufferobj_mapped(src)) {
1382 _mesa_error(ctx, GL_INVALID_OPERATION,
1383 "glCopyBufferSubData(readBuffer is mapped)");
1384 return;
1385 }
1386
1387 if (_mesa_bufferobj_mapped(dst)) {
1388 _mesa_error(ctx, GL_INVALID_OPERATION,
1389 "glCopyBufferSubData(writeBuffer is mapped)");
1390 return;
1391 }
1392
1393 if (readOffset < 0) {
1394 _mesa_error(ctx, GL_INVALID_VALUE,
1395 "glCopyBufferSubData(readOffset = %d)", (int) readOffset);
1396 return;
1397 }
1398
1399 if (writeOffset < 0) {
1400 _mesa_error(ctx, GL_INVALID_VALUE,
1401 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset);
1402 return;
1403 }
1404
1405 if (size < 0) {
1406 _mesa_error(ctx, GL_INVALID_VALUE,
1407 "glCopyBufferSubData(writeOffset = %d)", (int) size);
1408 return;
1409 }
1410
1411 if (readOffset + size > src->Size) {
1412 _mesa_error(ctx, GL_INVALID_VALUE,
1413 "glCopyBufferSubData(readOffset + size = %d)",
1414 (int) (readOffset + size));
1415 return;
1416 }
1417
1418 if (writeOffset + size > dst->Size) {
1419 _mesa_error(ctx, GL_INVALID_VALUE,
1420 "glCopyBufferSubData(writeOffset + size = %d)",
1421 (int) (writeOffset + size));
1422 return;
1423 }
1424
1425 if (src == dst) {
1426 if (readOffset + size <= writeOffset) {
1427 /* OK */
1428 }
1429 else if (writeOffset + size <= readOffset) {
1430 /* OK */
1431 }
1432 else {
1433 /* overlapping src/dst is illegal */
1434 _mesa_error(ctx, GL_INVALID_VALUE,
1435 "glCopyBufferSubData(overlapping src/dst)");
1436 return;
1437 }
1438 }
1439
1440 ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset, size);
1441 }
1442
1443
1444 /**
1445 * See GL_ARB_map_buffer_range spec
1446 */
1447 void * GLAPIENTRY
1448 _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
1449 GLbitfield access)
1450 {
1451 GET_CURRENT_CONTEXT(ctx);
1452 struct gl_buffer_object *bufObj;
1453 void *map;
1454
1455 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
1456
1457 if (!ctx->Extensions.ARB_map_buffer_range) {
1458 _mesa_error(ctx, GL_INVALID_OPERATION,
1459 "glMapBufferRange(extension not supported)");
1460 return NULL;
1461 }
1462
1463 if (offset < 0) {
1464 _mesa_error(ctx, GL_INVALID_VALUE,
1465 "glMapBufferRange(offset = %ld)", (long)offset);
1466 return NULL;
1467 }
1468
1469 if (length < 0) {
1470 _mesa_error(ctx, GL_INVALID_VALUE,
1471 "glMapBufferRange(length = %ld)", (long)length);
1472 return NULL;
1473 }
1474
1475 if (access & ~(GL_MAP_READ_BIT |
1476 GL_MAP_WRITE_BIT |
1477 GL_MAP_INVALIDATE_RANGE_BIT |
1478 GL_MAP_INVALIDATE_BUFFER_BIT |
1479 GL_MAP_FLUSH_EXPLICIT_BIT |
1480 GL_MAP_UNSYNCHRONIZED_BIT)) {
1481 /* generate an error if any undefind bit is set */
1482 _mesa_error(ctx, GL_INVALID_VALUE, "glMapBufferRange(access)");
1483 return NULL;
1484 }
1485
1486 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) {
1487 _mesa_error(ctx, GL_INVALID_OPERATION,
1488 "glMapBufferRange(access indicates neither read or write)");
1489 return NULL;
1490 }
1491
1492 if ((access & GL_MAP_READ_BIT) &&
1493 (access & (GL_MAP_INVALIDATE_RANGE_BIT |
1494 GL_MAP_INVALIDATE_BUFFER_BIT |
1495 GL_MAP_UNSYNCHRONIZED_BIT))) {
1496 _mesa_error(ctx, GL_INVALID_OPERATION,
1497 "glMapBufferRange(invalid access flags)");
1498 return NULL;
1499 }
1500
1501 if ((access & GL_MAP_FLUSH_EXPLICIT_BIT) &&
1502 ((access & GL_MAP_WRITE_BIT) == 0)) {
1503 _mesa_error(ctx, GL_INVALID_OPERATION,
1504 "glMapBufferRange(invalid access flags)");
1505 return NULL;
1506 }
1507
1508 bufObj = get_buffer(ctx, "glMapBufferRange", target);
1509 if (!bufObj)
1510 return NULL;
1511
1512 if (offset + length > bufObj->Size) {
1513 _mesa_error(ctx, GL_INVALID_VALUE,
1514 "glMapBufferRange(offset + length > size)");
1515 return NULL;
1516 }
1517
1518 if (_mesa_bufferobj_mapped(bufObj)) {
1519 _mesa_error(ctx, GL_INVALID_OPERATION,
1520 "glMapBufferRange(buffer already mapped)");
1521 return NULL;
1522 }
1523
1524 if (!bufObj->Size) {
1525 _mesa_error(ctx, GL_OUT_OF_MEMORY,
1526 "glMapBufferRange(buffer size = 0)");
1527 return NULL;
1528 }
1529
1530 /* Mapping zero bytes should return a non-null pointer. */
1531 if (!length) {
1532 static long dummy = 0;
1533 bufObj->Pointer = &dummy;
1534 bufObj->Length = length;
1535 bufObj->Offset = offset;
1536 bufObj->AccessFlags = access;
1537 return bufObj->Pointer;
1538 }
1539
1540 ASSERT(ctx->Driver.MapBufferRange);
1541 map = ctx->Driver.MapBufferRange(ctx, offset, length, access, bufObj);
1542 if (!map) {
1543 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(map failed)");
1544 }
1545 else {
1546 /* The driver callback should have set all these fields.
1547 * This is important because other modules (like VBO) might call
1548 * the driver function directly.
1549 */
1550 ASSERT(bufObj->Pointer == map);
1551 ASSERT(bufObj->Length == length);
1552 ASSERT(bufObj->Offset == offset);
1553 ASSERT(bufObj->AccessFlags == access);
1554 }
1555
1556 return map;
1557 }
1558
1559
1560 /**
1561 * See GL_ARB_map_buffer_range spec
1562 */
1563 void GLAPIENTRY
1564 _mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
1565 {
1566 GET_CURRENT_CONTEXT(ctx);
1567 struct gl_buffer_object *bufObj;
1568 ASSERT_OUTSIDE_BEGIN_END(ctx);
1569
1570 if (!ctx->Extensions.ARB_map_buffer_range) {
1571 _mesa_error(ctx, GL_INVALID_OPERATION,
1572 "glFlushMappedBufferRange(extension not supported)");
1573 return;
1574 }
1575
1576 if (offset < 0) {
1577 _mesa_error(ctx, GL_INVALID_VALUE,
1578 "glFlushMappedBufferRange(offset = %ld)", (long)offset);
1579 return;
1580 }
1581
1582 if (length < 0) {
1583 _mesa_error(ctx, GL_INVALID_VALUE,
1584 "glFlushMappedBufferRange(length = %ld)", (long)length);
1585 return;
1586 }
1587
1588 bufObj = get_buffer(ctx, "glFlushMappedBufferRange", target);
1589 if (!bufObj)
1590 return;
1591
1592 if (!_mesa_bufferobj_mapped(bufObj)) {
1593 /* buffer is not mapped */
1594 _mesa_error(ctx, GL_INVALID_OPERATION,
1595 "glFlushMappedBufferRange(buffer is not mapped)");
1596 return;
1597 }
1598
1599 if ((bufObj->AccessFlags & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) {
1600 _mesa_error(ctx, GL_INVALID_OPERATION,
1601 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1602 return;
1603 }
1604
1605 if (offset + length > bufObj->Length) {
1606 _mesa_error(ctx, GL_INVALID_VALUE,
1607 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
1608 (long)offset, (long)length, (long)bufObj->Length);
1609 return;
1610 }
1611
1612 ASSERT(bufObj->AccessFlags & GL_MAP_WRITE_BIT);
1613
1614 if (ctx->Driver.FlushMappedBufferRange)
1615 ctx->Driver.FlushMappedBufferRange(ctx, offset, length, bufObj);
1616 }
1617
1618
1619 #if FEATURE_APPLE_object_purgeable
1620 static GLenum
1621 buffer_object_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
1622 {
1623 struct gl_buffer_object *bufObj;
1624 GLenum retval;
1625
1626 bufObj = _mesa_lookup_bufferobj(ctx, name);
1627 if (!bufObj) {
1628 _mesa_error(ctx, GL_INVALID_VALUE,
1629 "glObjectPurgeable(name = 0x%x)", name);
1630 return 0;
1631 }
1632 if (!_mesa_is_bufferobj(bufObj)) {
1633 _mesa_error(ctx, GL_INVALID_OPERATION, "glObjectPurgeable(buffer 0)" );
1634 return 0;
1635 }
1636
1637 if (bufObj->Purgeable) {
1638 _mesa_error(ctx, GL_INVALID_OPERATION,
1639 "glObjectPurgeable(name = 0x%x) is already purgeable", name);
1640 return GL_VOLATILE_APPLE;
1641 }
1642
1643 bufObj->Purgeable = GL_TRUE;
1644
1645 retval = GL_VOLATILE_APPLE;
1646 if (ctx->Driver.BufferObjectPurgeable)
1647 retval = ctx->Driver.BufferObjectPurgeable(ctx, bufObj, option);
1648
1649 return retval;
1650 }
1651
1652
1653 static GLenum
1654 renderbuffer_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
1655 {
1656 struct gl_renderbuffer *bufObj;
1657 GLenum retval;
1658
1659 bufObj = _mesa_lookup_renderbuffer(ctx, name);
1660 if (!bufObj) {
1661 _mesa_error(ctx, GL_INVALID_VALUE,
1662 "glObjectUnpurgeable(name = 0x%x)", name);
1663 return 0;
1664 }
1665
1666 if (bufObj->Purgeable) {
1667 _mesa_error(ctx, GL_INVALID_OPERATION,
1668 "glObjectPurgeable(name = 0x%x) is already purgeable", name);
1669 return GL_VOLATILE_APPLE;
1670 }
1671
1672 bufObj->Purgeable = GL_TRUE;
1673
1674 retval = GL_VOLATILE_APPLE;
1675 if (ctx->Driver.RenderObjectPurgeable)
1676 retval = ctx->Driver.RenderObjectPurgeable(ctx, bufObj, option);
1677
1678 return retval;
1679 }
1680
1681
1682 static GLenum
1683 texture_object_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
1684 {
1685 struct gl_texture_object *bufObj;
1686 GLenum retval;
1687
1688 bufObj = _mesa_lookup_texture(ctx, name);
1689 if (!bufObj) {
1690 _mesa_error(ctx, GL_INVALID_VALUE,
1691 "glObjectPurgeable(name = 0x%x)", name);
1692 return 0;
1693 }
1694
1695 if (bufObj->Purgeable) {
1696 _mesa_error(ctx, GL_INVALID_OPERATION,
1697 "glObjectPurgeable(name = 0x%x) is already purgeable", name);
1698 return GL_VOLATILE_APPLE;
1699 }
1700
1701 bufObj->Purgeable = GL_TRUE;
1702
1703 retval = GL_VOLATILE_APPLE;
1704 if (ctx->Driver.TextureObjectPurgeable)
1705 retval = ctx->Driver.TextureObjectPurgeable(ctx, bufObj, option);
1706
1707 return retval;
1708 }
1709
1710
1711 GLenum GLAPIENTRY
1712 _mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
1713 {
1714 GLenum retval;
1715
1716 GET_CURRENT_CONTEXT(ctx);
1717 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1718
1719 if (name == 0) {
1720 _mesa_error(ctx, GL_INVALID_VALUE,
1721 "glObjectPurgeable(name = 0x%x)", name);
1722 return 0;
1723 }
1724
1725 switch (option) {
1726 case GL_VOLATILE_APPLE:
1727 case GL_RELEASED_APPLE:
1728 /* legal */
1729 break;
1730 default:
1731 _mesa_error(ctx, GL_INVALID_ENUM,
1732 "glObjectPurgeable(name = 0x%x) invalid option: %d",
1733 name, option);
1734 return 0;
1735 }
1736
1737 switch (objectType) {
1738 case GL_TEXTURE:
1739 retval = texture_object_purgeable(ctx, name, option);
1740 break;
1741 case GL_RENDERBUFFER_EXT:
1742 retval = renderbuffer_purgeable(ctx, name, option);
1743 break;
1744 case GL_BUFFER_OBJECT_APPLE:
1745 retval = buffer_object_purgeable(ctx, name, option);
1746 break;
1747 default:
1748 _mesa_error(ctx, GL_INVALID_ENUM,
1749 "glObjectPurgeable(name = 0x%x) invalid type: %d",
1750 name, objectType);
1751 return 0;
1752 }
1753
1754 /* In strict conformance to the spec, we must only return VOLATILE when
1755 * when passed the VOLATILE option. Madness.
1756 *
1757 * XXX First fix the spec, then fix me.
1758 */
1759 return option == GL_VOLATILE_APPLE ? GL_VOLATILE_APPLE : retval;
1760 }
1761
1762
1763 static GLenum
1764 buffer_object_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
1765 {
1766 struct gl_buffer_object *bufObj;
1767 GLenum retval;
1768
1769 bufObj = _mesa_lookup_bufferobj(ctx, name);
1770 if (!bufObj) {
1771 _mesa_error(ctx, GL_INVALID_VALUE,
1772 "glObjectUnpurgeable(name = 0x%x)", name);
1773 return 0;
1774 }
1775
1776 if (! bufObj->Purgeable) {
1777 _mesa_error(ctx, GL_INVALID_OPERATION,
1778 "glObjectUnpurgeable(name = 0x%x) object is "
1779 " already \"unpurged\"", name);
1780 return 0;
1781 }
1782
1783 bufObj->Purgeable = GL_FALSE;
1784
1785 retval = option;
1786 if (ctx->Driver.BufferObjectUnpurgeable)
1787 retval = ctx->Driver.BufferObjectUnpurgeable(ctx, bufObj, option);
1788
1789 return retval;
1790 }
1791
1792
1793 static GLenum
1794 renderbuffer_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
1795 {
1796 struct gl_renderbuffer *bufObj;
1797 GLenum retval;
1798
1799 bufObj = _mesa_lookup_renderbuffer(ctx, name);
1800 if (!bufObj) {
1801 _mesa_error(ctx, GL_INVALID_VALUE,
1802 "glObjectUnpurgeable(name = 0x%x)", name);
1803 return 0;
1804 }
1805
1806 if (! bufObj->Purgeable) {
1807 _mesa_error(ctx, GL_INVALID_OPERATION,
1808 "glObjectUnpurgeable(name = 0x%x) object is "
1809 " already \"unpurged\"", name);
1810 return 0;
1811 }
1812
1813 bufObj->Purgeable = GL_FALSE;
1814
1815 retval = option;
1816 if (ctx->Driver.RenderObjectUnpurgeable)
1817 retval = ctx->Driver.RenderObjectUnpurgeable(ctx, bufObj, option);
1818
1819 return retval;
1820 }
1821
1822
1823 static GLenum
1824 texture_object_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
1825 {
1826 struct gl_texture_object *bufObj;
1827 GLenum retval;
1828
1829 bufObj = _mesa_lookup_texture(ctx, name);
1830 if (!bufObj) {
1831 _mesa_error(ctx, GL_INVALID_VALUE,
1832 "glObjectUnpurgeable(name = 0x%x)", name);
1833 return 0;
1834 }
1835
1836 if (! bufObj->Purgeable) {
1837 _mesa_error(ctx, GL_INVALID_OPERATION,
1838 "glObjectUnpurgeable(name = 0x%x) object is"
1839 " already \"unpurged\"", name);
1840 return 0;
1841 }
1842
1843 bufObj->Purgeable = GL_FALSE;
1844
1845 retval = option;
1846 if (ctx->Driver.TextureObjectUnpurgeable)
1847 retval = ctx->Driver.TextureObjectUnpurgeable(ctx, bufObj, option);
1848
1849 return retval;
1850 }
1851
1852
1853 GLenum GLAPIENTRY
1854 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
1855 {
1856 GET_CURRENT_CONTEXT(ctx);
1857 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1858
1859 if (name == 0) {
1860 _mesa_error(ctx, GL_INVALID_VALUE,
1861 "glObjectUnpurgeable(name = 0x%x)", name);
1862 return 0;
1863 }
1864
1865 switch (option) {
1866 case GL_RETAINED_APPLE:
1867 case GL_UNDEFINED_APPLE:
1868 /* legal */
1869 break;
1870 default:
1871 _mesa_error(ctx, GL_INVALID_ENUM,
1872 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
1873 name, option);
1874 return 0;
1875 }
1876
1877 switch (objectType) {
1878 case GL_BUFFER_OBJECT_APPLE:
1879 return buffer_object_unpurgeable(ctx, name, option);
1880 case GL_TEXTURE:
1881 return texture_object_unpurgeable(ctx, name, option);
1882 case GL_RENDERBUFFER_EXT:
1883 return renderbuffer_unpurgeable(ctx, name, option);
1884 default:
1885 _mesa_error(ctx, GL_INVALID_ENUM,
1886 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
1887 name, objectType);
1888 return 0;
1889 }
1890 }
1891
1892
1893 static void
1894 get_buffer_object_parameteriv(struct gl_context *ctx, GLuint name,
1895 GLenum pname, GLint *params)
1896 {
1897 struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, name);
1898 if (!bufObj) {
1899 _mesa_error(ctx, GL_INVALID_VALUE,
1900 "glGetObjectParameteriv(name = 0x%x) invalid object", name);
1901 return;
1902 }
1903
1904 switch (pname) {
1905 case GL_PURGEABLE_APPLE:
1906 *params = bufObj->Purgeable;
1907 break;
1908 default:
1909 _mesa_error(ctx, GL_INVALID_ENUM,
1910 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1911 name, pname);
1912 break;
1913 }
1914 }
1915
1916
1917 static void
1918 get_renderbuffer_parameteriv(struct gl_context *ctx, GLuint name,
1919 GLenum pname, GLint *params)
1920 {
1921 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, name);
1922 if (!rb) {
1923 _mesa_error(ctx, GL_INVALID_VALUE,
1924 "glObjectUnpurgeable(name = 0x%x)", name);
1925 return;
1926 }
1927
1928 switch (pname) {
1929 case GL_PURGEABLE_APPLE:
1930 *params = rb->Purgeable;
1931 break;
1932 default:
1933 _mesa_error(ctx, GL_INVALID_ENUM,
1934 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1935 name, pname);
1936 break;
1937 }
1938 }
1939
1940
1941 static void
1942 get_texture_object_parameteriv(struct gl_context *ctx, GLuint name,
1943 GLenum pname, GLint *params)
1944 {
1945 struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, name);
1946 if (!texObj) {
1947 _mesa_error(ctx, GL_INVALID_VALUE,
1948 "glObjectUnpurgeable(name = 0x%x)", name);
1949 return;
1950 }
1951
1952 switch (pname) {
1953 case GL_PURGEABLE_APPLE:
1954 *params = texObj->Purgeable;
1955 break;
1956 default:
1957 _mesa_error(ctx, GL_INVALID_ENUM,
1958 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1959 name, pname);
1960 break;
1961 }
1962 }
1963
1964
1965 void GLAPIENTRY
1966 _mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname,
1967 GLint *params)
1968 {
1969 GET_CURRENT_CONTEXT(ctx);
1970
1971 if (name == 0) {
1972 _mesa_error(ctx, GL_INVALID_VALUE,
1973 "glGetObjectParameteriv(name = 0x%x)", name);
1974 return;
1975 }
1976
1977 switch (objectType) {
1978 case GL_TEXTURE:
1979 get_texture_object_parameteriv(ctx, name, pname, params);
1980 break;
1981 case GL_BUFFER_OBJECT_APPLE:
1982 get_buffer_object_parameteriv(ctx, name, pname, params);
1983 break;
1984 case GL_RENDERBUFFER_EXT:
1985 get_renderbuffer_parameteriv(ctx, name, pname, params);
1986 break;
1987 default:
1988 _mesa_error(ctx, GL_INVALID_ENUM,
1989 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
1990 name, objectType);
1991 }
1992 }
1993
1994 #endif /* FEATURE_APPLE_object_purgeable */