2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
40 #include "bufferobj.h"
44 #include "transformfeedback.h"
50 /*#define BOUNDS_CHECK*/
54 * Used as a placeholder for buffer objects between glGenBuffers() and
55 * glBindBuffer() so that glIsBuffer() can work correctly.
57 static struct gl_buffer_object DummyBufferObject
;
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.
67 static inline struct gl_buffer_object
**
68 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
70 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
72 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
73 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
77 case GL_ARRAY_BUFFER_ARB
:
78 return &ctx
->Array
.ArrayBufferObj
;
79 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
80 return &ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
81 case GL_PIXEL_PACK_BUFFER_EXT
:
82 return &ctx
->Pack
.BufferObj
;
83 case GL_PIXEL_UNPACK_BUFFER_EXT
:
84 return &ctx
->Unpack
.BufferObj
;
85 case GL_COPY_READ_BUFFER
:
86 return &ctx
->CopyReadBuffer
;
87 case GL_COPY_WRITE_BUFFER
:
88 return &ctx
->CopyWriteBuffer
;
89 case GL_DRAW_INDIRECT_BUFFER
:
90 if (ctx
->API
== API_OPENGL_CORE
&&
91 ctx
->Extensions
.ARB_draw_indirect
) {
92 return &ctx
->DrawIndirectBuffer
;
95 case GL_TRANSFORM_FEEDBACK_BUFFER
:
96 if (ctx
->Extensions
.EXT_transform_feedback
) {
97 return &ctx
->TransformFeedback
.CurrentBuffer
;
100 case GL_TEXTURE_BUFFER
:
101 if (ctx
->API
== API_OPENGL_CORE
&&
102 ctx
->Extensions
.ARB_texture_buffer_object
) {
103 return &ctx
->Texture
.BufferObject
;
106 case GL_UNIFORM_BUFFER
:
107 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
108 return &ctx
->UniformBuffer
;
111 case GL_ATOMIC_COUNTER_BUFFER
:
112 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
113 return &ctx
->AtomicBuffer
;
124 * Get the buffer object bound to the specified target in a GL context.
125 * \param ctx the GL context
126 * \param target the buffer object target to be retrieved.
127 * \return pointer to the buffer object bound to \c target in the
128 * specified context or \c NULL if \c target is invalid.
130 static inline struct gl_buffer_object
*
131 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
)
133 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
136 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
140 if (!_mesa_is_bufferobj(*bufObj
)) {
141 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(buffer 0)", func
);
150 * Convert a GLbitfield describing the mapped buffer access flags
151 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
154 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
156 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
157 if ((access
& rwFlags
) == rwFlags
)
158 return GL_READ_WRITE
;
159 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
161 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
162 return GL_WRITE_ONLY
;
164 /* Otherwise, AccessFlags is zero (the default state).
166 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
168 * Name Type Initial Value Legal Values
170 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
173 * However, table 6.8 in the GL_OES_mapbuffer extension says:
175 * Get Value Type Get Command Value Description
176 * --------- ---- ----------- ----- -----------
177 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
179 * The difference is because GL_OES_mapbuffer only supports mapping buffers
184 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
189 * Tests the subdata range parameters and sets the GL error code for
190 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
192 * \param ctx GL context.
193 * \param target Buffer object target on which to operate.
194 * \param offset Offset of the first byte of the subdata range.
195 * \param size Size, in bytes, of the subdata range.
196 * \param caller Name of calling function for recording errors.
197 * \return A pointer to the buffer object bound to \c target in the
198 * specified context or \c NULL if any of the parameter or state
199 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
202 * \sa glBufferSubDataARB, glGetBufferSubDataARB
204 static struct gl_buffer_object
*
205 buffer_object_subdata_range_good( struct gl_context
* ctx
, GLenum target
,
206 GLintptrARB offset
, GLsizeiptrARB size
,
209 struct gl_buffer_object
*bufObj
;
212 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
217 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
221 bufObj
= get_buffer(ctx
, caller
, target
);
225 if (offset
+ size
> bufObj
->Size
) {
226 _mesa_error(ctx
, GL_INVALID_VALUE
,
227 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
228 (unsigned long) offset
,
229 (unsigned long) size
,
230 (unsigned long) bufObj
->Size
);
233 if (_mesa_bufferobj_mapped(bufObj
)) {
234 /* Buffer is currently mapped */
235 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
244 * Allocate and initialize a new buffer object.
246 * Default callback for the \c dd_function_table::NewBufferObject() hook.
248 static struct gl_buffer_object
*
249 _mesa_new_buffer_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
251 struct gl_buffer_object
*obj
;
255 obj
= MALLOC_STRUCT(gl_buffer_object
);
256 _mesa_initialize_buffer_object(ctx
, obj
, name
, target
);
262 * Delete a buffer object.
264 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
267 _mesa_delete_buffer_object(struct gl_context
*ctx
,
268 struct gl_buffer_object
*bufObj
)
274 /* assign strange values here to help w/ debugging */
275 bufObj
->RefCount
= -1000;
278 _glthread_DESTROY_MUTEX(bufObj
->Mutex
);
286 * Set ptr to bufObj w/ reference counting.
287 * This is normally only called from the _mesa_reference_buffer_object() macro
288 * when there's a real pointer change.
291 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
292 struct gl_buffer_object
**ptr
,
293 struct gl_buffer_object
*bufObj
)
296 /* Unreference the old buffer */
297 GLboolean deleteFlag
= GL_FALSE
;
298 struct gl_buffer_object
*oldObj
= *ptr
;
300 _glthread_LOCK_MUTEX(oldObj
->Mutex
);
301 ASSERT(oldObj
->RefCount
> 0);
304 printf("BufferObj %p %d DECR to %d\n",
305 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
307 deleteFlag
= (oldObj
->RefCount
== 0);
308 _glthread_UNLOCK_MUTEX(oldObj
->Mutex
);
312 /* some sanity checking: don't delete a buffer still in use */
314 /* unfortunately, these tests are invalid during context tear-down */
315 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
316 ASSERT(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
!= bufObj
);
317 ASSERT(ctx
->Array
.ArrayObj
->Vertex
.BufferObj
!= bufObj
);
320 ASSERT(ctx
->Driver
.DeleteBuffer
);
321 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
329 /* reference new buffer */
330 _glthread_LOCK_MUTEX(bufObj
->Mutex
);
331 if (bufObj
->RefCount
== 0) {
332 /* this buffer's being deleted (look just above) */
333 /* Not sure this can every really happen. Warn if it does. */
334 _mesa_problem(NULL
, "referencing deleted buffer object");
340 printf("BufferObj %p %d INCR to %d\n",
341 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
345 _glthread_UNLOCK_MUTEX(bufObj
->Mutex
);
351 * Initialize a buffer object to default values.
354 _mesa_initialize_buffer_object( struct gl_context
*ctx
,
355 struct gl_buffer_object
*obj
,
356 GLuint name
, GLenum target
)
360 memset(obj
, 0, sizeof(struct gl_buffer_object
));
361 _glthread_INIT_MUTEX(obj
->Mutex
);
364 obj
->Usage
= GL_STATIC_DRAW_ARB
;
365 obj
->AccessFlags
= 0;
371 * Callback called from _mesa_HashWalk()
374 count_buffer_size(GLuint key
, void *data
, void *userData
)
376 const struct gl_buffer_object
*bufObj
=
377 (const struct gl_buffer_object
*) data
;
378 GLuint
*total
= (GLuint
*) userData
;
380 *total
= *total
+ bufObj
->Size
;
385 * Compute total size (in bytes) of all buffer objects for the given context.
386 * For debugging purposes.
389 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
393 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
400 * Allocate space for and store data in a buffer object. Any data that was
401 * previously stored in the buffer object is lost. If \c data is \c NULL,
402 * memory will be allocated, but no copy will occur.
404 * This is the default callback for \c dd_function_table::BufferData()
405 * Note that all GL error checking will have been done already.
407 * \param ctx GL context.
408 * \param target Buffer object target on which to operate.
409 * \param size Size, in bytes, of the new data store.
410 * \param data Pointer to the data to store in the buffer object. This
411 * pointer may be \c NULL.
412 * \param usage Hints about how the data will be used.
413 * \param bufObj Object to be used.
415 * \return GL_TRUE for success, GL_FALSE for failure
416 * \sa glBufferDataARB, dd_function_table::BufferData.
419 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
420 const GLvoid
* data
, GLenum usage
,
421 struct gl_buffer_object
* bufObj
)
425 (void) ctx
; (void) target
;
427 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
429 bufObj
->Data
= (GLubyte
*) new_data
;
431 bufObj
->Usage
= usage
;
434 memcpy( bufObj
->Data
, data
, size
);
446 * Replace data in a subrange of buffer object. If the data range
447 * specified by \c size + \c offset extends beyond the end of the buffer or
448 * if \c data is \c NULL, no copy is performed.
450 * This is the default callback for \c dd_function_table::BufferSubData()
451 * Note that all GL error checking will have been done already.
453 * \param ctx GL context.
454 * \param offset Offset of the first byte to be modified.
455 * \param size Size, in bytes, of the data range.
456 * \param data Pointer to the data to store in the buffer object.
457 * \param bufObj Object to be used.
459 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
462 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
463 GLsizeiptrARB size
, const GLvoid
* data
,
464 struct gl_buffer_object
* bufObj
)
468 /* this should have been caught in _mesa_BufferSubData() */
469 ASSERT(size
+ offset
<= bufObj
->Size
);
472 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
478 * Retrieve data from a subrange of buffer object. If the data range
479 * specified by \c size + \c offset extends beyond the end of the buffer or
480 * if \c data is \c NULL, no copy is performed.
482 * This is the default callback for \c dd_function_table::GetBufferSubData()
483 * Note that all GL error checking will have been done already.
485 * \param ctx GL context.
486 * \param target Buffer object target on which to operate.
487 * \param offset Offset of the first byte to be fetched.
488 * \param size Size, in bytes, of the data range.
489 * \param data Destination for data
490 * \param bufObj Object to be used.
492 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
495 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
496 GLsizeiptrARB size
, GLvoid
* data
,
497 struct gl_buffer_object
* bufObj
)
501 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
502 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
508 * Default fallback for \c dd_function_table::MapBufferRange().
509 * Called via glMapBufferRange().
512 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
513 GLsizeiptr length
, GLbitfield access
,
514 struct gl_buffer_object
*bufObj
)
517 assert(!_mesa_bufferobj_mapped(bufObj
));
518 /* Just return a direct pointer to the data */
519 bufObj
->Pointer
= bufObj
->Data
+ offset
;
520 bufObj
->Length
= length
;
521 bufObj
->Offset
= offset
;
522 bufObj
->AccessFlags
= access
;
523 return bufObj
->Pointer
;
528 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
529 * Called via glFlushMappedBufferRange().
532 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
533 GLintptr offset
, GLsizeiptr length
,
534 struct gl_buffer_object
*obj
)
545 * Default callback for \c dd_function_table::MapBuffer().
547 * The input parameters will have been already tested for errors.
549 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
552 _mesa_buffer_unmap( struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
)
555 /* XXX we might assert here that bufObj->Pointer is non-null */
556 bufObj
->Pointer
= NULL
;
559 bufObj
->AccessFlags
= 0x0;
565 * Default fallback for \c dd_function_table::CopyBufferSubData().
566 * Called via glCopyBufferSubData().
569 _mesa_copy_buffer_subdata(struct gl_context
*ctx
,
570 struct gl_buffer_object
*src
,
571 struct gl_buffer_object
*dst
,
572 GLintptr readOffset
, GLintptr writeOffset
,
575 GLubyte
*srcPtr
, *dstPtr
;
577 /* the buffers should not be mapped */
578 assert(!_mesa_bufferobj_mapped(src
));
579 assert(!_mesa_bufferobj_mapped(dst
));
582 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
584 GL_MAP_WRITE_BIT
, src
);
589 srcPtr
+= readOffset
;
590 dstPtr
+= writeOffset
;
592 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
593 GL_MAP_READ_BIT
, src
);
594 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
596 GL_MAP_INVALIDATE_RANGE_BIT
), dst
);
599 /* Note: the src and dst regions will never overlap. Trying to do so
600 * would generate GL_INVALID_VALUE earlier.
602 if (srcPtr
&& dstPtr
)
603 memcpy(dstPtr
, srcPtr
, size
);
605 ctx
->Driver
.UnmapBuffer(ctx
, src
);
607 ctx
->Driver
.UnmapBuffer(ctx
, dst
);
613 * Initialize the state associated with buffer objects
616 _mesa_init_buffer_objects( struct gl_context
*ctx
)
620 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
621 _glthread_INIT_MUTEX(DummyBufferObject
.Mutex
);
622 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
624 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
625 ctx
->Shared
->NullBufferObj
);
627 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
628 ctx
->Shared
->NullBufferObj
);
629 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
630 ctx
->Shared
->NullBufferObj
);
632 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
633 ctx
->Shared
->NullBufferObj
);
635 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
636 ctx
->Shared
->NullBufferObj
);
638 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
639 _mesa_reference_buffer_object(ctx
,
640 &ctx
->UniformBufferBindings
[i
].BufferObject
,
641 ctx
->Shared
->NullBufferObj
);
642 ctx
->UniformBufferBindings
[i
].Offset
= -1;
643 ctx
->UniformBufferBindings
[i
].Size
= -1;
649 _mesa_free_buffer_objects( struct gl_context
*ctx
)
653 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
655 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
656 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
658 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
660 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
661 _mesa_reference_buffer_object(ctx
,
662 &ctx
->UniformBufferBindings
[i
].BufferObject
,
668 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
671 struct gl_buffer_object
**buf_handle
,
674 struct gl_buffer_object
*buf
= *buf_handle
;
676 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
677 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
681 if (!buf
|| buf
== &DummyBufferObject
) {
682 /* If this is a new buffer object id, or one which was generated but
683 * never used before, allocate a buffer object now.
685 ASSERT(ctx
->Driver
.NewBufferObject
);
686 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
, target
);
688 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
691 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
699 * Bind the specified target to buffer for the specified context.
700 * Called by glBindBuffer() and other functions.
703 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
705 struct gl_buffer_object
*oldBufObj
;
706 struct gl_buffer_object
*newBufObj
= NULL
;
707 struct gl_buffer_object
**bindTarget
= NULL
;
709 bindTarget
= get_buffer_target(ctx
, target
);
711 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
715 /* Get pointer to old buffer object (to be unbound) */
716 oldBufObj
= *bindTarget
;
717 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
718 return; /* rebinding the same buffer object- no change */
721 * Get pointer to new buffer object (newBufObj)
724 /* The spec says there's not a buffer object named 0, but we use
725 * one internally because it simplifies things.
727 newBufObj
= ctx
->Shared
->NullBufferObj
;
730 /* non-default buffer object */
731 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
732 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
733 &newBufObj
, "glBindBuffer"))
737 /* bind new buffer */
738 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
740 /* Pass BindBuffer call to device driver */
741 if (ctx
->Driver
.BindBuffer
)
742 ctx
->Driver
.BindBuffer( ctx
, target
, newBufObj
);
747 * Update the default buffer objects in the given context to reference those
748 * specified in the shared state and release those referencing the old
752 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
754 /* Bind the NullBufferObj to remove references to those
755 * in the shared context hash table.
757 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
758 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
759 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
760 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
766 * Return the gl_buffer_object for the given ID.
767 * Always return NULL for ID 0.
769 struct gl_buffer_object
*
770 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
775 return (struct gl_buffer_object
*)
776 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
781 * If *ptr points to obj, set ptr = the Null/default buffer object.
782 * This is a helper for buffer object deletion.
783 * The GL spec says that deleting a buffer object causes it to get
784 * unbound from all arrays in the current context.
787 unbind(struct gl_context
*ctx
,
788 struct gl_buffer_object
**ptr
,
789 struct gl_buffer_object
*obj
)
792 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
798 * Plug default/fallback buffer object functions into the device
802 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
804 /* GL_ARB_vertex/pixel_buffer_object */
805 driver
->NewBufferObject
= _mesa_new_buffer_object
;
806 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
807 driver
->BindBuffer
= NULL
;
808 driver
->BufferData
= _mesa_buffer_data
;
809 driver
->BufferSubData
= _mesa_buffer_subdata
;
810 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
811 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
813 /* GL_ARB_map_buffer_range */
814 driver
->MapBufferRange
= _mesa_buffer_map_range
;
815 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
817 /* GL_ARB_copy_buffer */
818 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
823 /**********************************************************************/
825 /**********************************************************************/
828 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
830 GET_CURRENT_CONTEXT(ctx
);
832 if (MESA_VERBOSE
& VERBOSE_API
)
833 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
834 _mesa_lookup_enum_by_nr(target
), buffer
);
836 bind_buffer_object(ctx
, target
, buffer
);
841 * Delete a set of buffer objects.
843 * \param n Number of buffer objects to delete.
844 * \param ids Array of \c n buffer object IDs.
847 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
849 GET_CURRENT_CONTEXT(ctx
);
851 FLUSH_VERTICES(ctx
, 0);
854 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
858 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
860 for (i
= 0; i
< n
; i
++) {
861 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
863 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
866 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
868 if (_mesa_bufferobj_mapped(bufObj
)) {
869 /* if mapped, unmap it now */
870 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
871 bufObj
->AccessFlags
= 0;
872 bufObj
->Pointer
= NULL
;
875 /* unbind any vertex pointers bound to this buffer */
876 for (j
= 0; j
< Elements(arrayObj
->VertexBinding
); j
++) {
877 unbind(ctx
, &arrayObj
->VertexBinding
[j
].BufferObj
, bufObj
);
880 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
881 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
883 if (arrayObj
->ElementArrayBufferObj
== bufObj
) {
884 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
887 /* unbind ARB_draw_indirect binding point */
888 if (ctx
->DrawIndirectBuffer
== bufObj
) {
889 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
892 /* unbind ARB_copy_buffer binding points */
893 if (ctx
->CopyReadBuffer
== bufObj
) {
894 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
896 if (ctx
->CopyWriteBuffer
== bufObj
) {
897 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
900 /* unbind transform feedback binding points */
901 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
902 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
904 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
905 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
906 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
910 /* unbind UBO binding points */
911 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
912 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
913 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
917 if (ctx
->UniformBuffer
== bufObj
) {
918 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
921 /* unbind any pixel pack/unpack pointers bound to this buffer */
922 if (ctx
->Pack
.BufferObj
== bufObj
) {
923 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
925 if (ctx
->Unpack
.BufferObj
== bufObj
) {
926 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
929 if (ctx
->Texture
.BufferObject
== bufObj
) {
930 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
933 /* The ID is immediately freed for re-use */
934 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
935 /* Make sure we do not run into the classic ABA problem on bind.
936 * We don't want to allow re-binding a buffer object that's been
937 * "deleted" by glDeleteBuffers().
939 * The explicit rebinding to the default object in the current context
940 * prevents the above in the current context, but another context
941 * sharing the same objects might suffer from this problem.
942 * The alternative would be to do the hash lookup in any case on bind
943 * which would introduce more runtime overhead than this.
945 bufObj
->DeletePending
= GL_TRUE
;
946 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
950 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
955 * Generate a set of unique buffer object IDs and store them in \c buffer.
957 * \param n Number of IDs to generate.
958 * \param buffer Array of \c n locations to store the IDs.
961 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
963 GET_CURRENT_CONTEXT(ctx
);
967 if (MESA_VERBOSE
& VERBOSE_API
)
968 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
971 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
980 * This must be atomic (generation and allocation of buffer object IDs)
982 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
984 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
986 /* Insert the ID and pointer to dummy buffer object into hash table */
987 for (i
= 0; i
< n
; i
++) {
988 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
990 buffer
[i
] = first
+ i
;
993 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
998 * Determine if ID is the name of a buffer object.
1000 * \param id ID of the potential buffer object.
1001 * \return \c GL_TRUE if \c id is the name of a buffer object,
1002 * \c GL_FALSE otherwise.
1004 GLboolean GLAPIENTRY
1005 _mesa_IsBuffer(GLuint id
)
1007 struct gl_buffer_object
*bufObj
;
1008 GET_CURRENT_CONTEXT(ctx
);
1009 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1011 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1012 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1013 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1015 return bufObj
&& bufObj
!= &DummyBufferObject
;
1020 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1021 const GLvoid
* data
, GLenum usage
)
1023 GET_CURRENT_CONTEXT(ctx
);
1024 struct gl_buffer_object
*bufObj
;
1027 if (MESA_VERBOSE
& VERBOSE_API
)
1028 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1029 _mesa_lookup_enum_by_nr(target
),
1030 (long int) size
, data
,
1031 _mesa_lookup_enum_by_nr(usage
));
1034 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1039 case GL_STREAM_DRAW_ARB
:
1040 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1043 case GL_STATIC_DRAW_ARB
:
1044 case GL_DYNAMIC_DRAW_ARB
:
1048 case GL_STREAM_READ_ARB
:
1049 case GL_STREAM_COPY_ARB
:
1050 case GL_STATIC_READ_ARB
:
1051 case GL_STATIC_COPY_ARB
:
1052 case GL_DYNAMIC_READ_ARB
:
1053 case GL_DYNAMIC_COPY_ARB
:
1054 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1058 valid_usage
= false;
1063 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1067 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
);
1071 if (_mesa_bufferobj_mapped(bufObj
)) {
1072 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1073 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
1074 bufObj
->AccessFlags
= 0;
1075 ASSERT(bufObj
->Pointer
== NULL
);
1078 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1080 bufObj
->Written
= GL_TRUE
;
1083 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1084 bufObj
->Name
, size
, data
, usage
);
1091 ASSERT(ctx
->Driver
.BufferData
);
1092 if (!ctx
->Driver
.BufferData( ctx
, target
, size
, data
, usage
, bufObj
)) {
1093 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
1099 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1100 GLsizeiptrARB size
, const GLvoid
* data
)
1102 GET_CURRENT_CONTEXT(ctx
);
1103 struct gl_buffer_object
*bufObj
;
1105 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1106 "glBufferSubDataARB" );
1108 /* error already recorded */
1115 bufObj
->Written
= GL_TRUE
;
1117 ASSERT(ctx
->Driver
.BufferSubData
);
1118 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1123 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1124 GLsizeiptrARB size
, void * data
)
1126 GET_CURRENT_CONTEXT(ctx
);
1127 struct gl_buffer_object
*bufObj
;
1129 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1130 "glGetBufferSubDataARB" );
1132 /* error already recorded */
1136 ASSERT(ctx
->Driver
.GetBufferSubData
);
1137 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1142 _mesa_MapBuffer(GLenum target
, GLenum access
)
1144 GET_CURRENT_CONTEXT(ctx
);
1145 struct gl_buffer_object
* bufObj
;
1146 GLbitfield accessFlags
;
1150 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1153 case GL_READ_ONLY_ARB
:
1154 accessFlags
= GL_MAP_READ_BIT
;
1155 valid_access
= _mesa_is_desktop_gl(ctx
);
1157 case GL_WRITE_ONLY_ARB
:
1158 accessFlags
= GL_MAP_WRITE_BIT
;
1159 valid_access
= true;
1161 case GL_READ_WRITE_ARB
:
1162 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1163 valid_access
= _mesa_is_desktop_gl(ctx
);
1166 valid_access
= false;
1170 if (!valid_access
) {
1171 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1175 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
);
1179 if (_mesa_bufferobj_mapped(bufObj
)) {
1180 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1184 if (!bufObj
->Size
) {
1185 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1186 "glMapBuffer(buffer size = 0)");
1190 ASSERT(ctx
->Driver
.MapBufferRange
);
1191 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
);
1193 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1197 /* The driver callback should have set these fields.
1198 * This is important because other modules (like VBO) might call
1199 * the driver function directly.
1201 ASSERT(bufObj
->Pointer
== map
);
1202 ASSERT(bufObj
->Length
== bufObj
->Size
);
1203 ASSERT(bufObj
->Offset
== 0);
1204 bufObj
->AccessFlags
= accessFlags
;
1207 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1208 bufObj
->Written
= GL_TRUE
;
1211 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1212 bufObj
->Name
, bufObj
->Size
, access
);
1213 if (access
== GL_WRITE_ONLY_ARB
) {
1215 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1216 for (i
= 0; i
< bufObj
->Size
; i
++)
1223 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1225 /* buffer is 100 bytes larger than requested, fill with magic value */
1226 for (i
= 0; i
< 100; i
++) {
1227 buf
[bufObj
->Size
- i
- 1] = 123;
1232 return bufObj
->Pointer
;
1236 GLboolean GLAPIENTRY
1237 _mesa_UnmapBuffer(GLenum target
)
1239 GET_CURRENT_CONTEXT(ctx
);
1240 struct gl_buffer_object
*bufObj
;
1241 GLboolean status
= GL_TRUE
;
1242 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1244 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
);
1248 if (!_mesa_bufferobj_mapped(bufObj
)) {
1249 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1254 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1255 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1257 /* check that last 100 bytes are still = magic value */
1258 for (i
= 0; i
< 100; i
++) {
1259 GLuint pos
= bufObj
->Size
- i
- 1;
1260 if (buf
[pos
] != 123) {
1261 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1262 " at position %d (value = %u)\n",
1270 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1271 GLuint i
, unchanged
= 0;
1272 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1274 /* check which bytes changed */
1275 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1276 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1283 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1284 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1289 status
= ctx
->Driver
.UnmapBuffer( ctx
, bufObj
);
1290 bufObj
->AccessFlags
= 0;
1291 ASSERT(bufObj
->Pointer
== NULL
);
1292 ASSERT(bufObj
->Offset
== 0);
1293 ASSERT(bufObj
->Length
== 0);
1300 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1302 GET_CURRENT_CONTEXT(ctx
);
1303 struct gl_buffer_object
*bufObj
;
1305 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
);
1310 case GL_BUFFER_SIZE_ARB
:
1311 *params
= (GLint
) bufObj
->Size
;
1313 case GL_BUFFER_USAGE_ARB
:
1314 *params
= bufObj
->Usage
;
1316 case GL_BUFFER_ACCESS_ARB
:
1317 *params
= simplified_access_mode(ctx
, bufObj
->AccessFlags
);
1319 case GL_BUFFER_MAPPED_ARB
:
1320 *params
= _mesa_bufferobj_mapped(bufObj
);
1322 case GL_BUFFER_ACCESS_FLAGS
:
1323 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1325 *params
= bufObj
->AccessFlags
;
1327 case GL_BUFFER_MAP_OFFSET
:
1328 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1330 *params
= (GLint
) bufObj
->Offset
;
1332 case GL_BUFFER_MAP_LENGTH
:
1333 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1335 *params
= (GLint
) bufObj
->Length
;
1338 ; /* fall-through */
1342 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1343 _mesa_lookup_enum_by_nr(pname
));
1349 * This is pretty much a duplicate of GetBufferParameteriv() but the
1350 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1353 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1355 GET_CURRENT_CONTEXT(ctx
);
1356 struct gl_buffer_object
*bufObj
;
1358 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
);
1363 case GL_BUFFER_SIZE_ARB
:
1364 *params
= bufObj
->Size
;
1366 case GL_BUFFER_USAGE_ARB
:
1367 *params
= bufObj
->Usage
;
1369 case GL_BUFFER_ACCESS_ARB
:
1370 *params
= simplified_access_mode(ctx
, bufObj
->AccessFlags
);
1372 case GL_BUFFER_ACCESS_FLAGS
:
1373 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1375 *params
= bufObj
->AccessFlags
;
1377 case GL_BUFFER_MAPPED_ARB
:
1378 *params
= _mesa_bufferobj_mapped(bufObj
);
1380 case GL_BUFFER_MAP_OFFSET
:
1381 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1383 *params
= bufObj
->Offset
;
1385 case GL_BUFFER_MAP_LENGTH
:
1386 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1388 *params
= bufObj
->Length
;
1391 ; /* fall-through */
1395 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1396 _mesa_lookup_enum_by_nr(pname
));
1401 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1403 GET_CURRENT_CONTEXT(ctx
);
1404 struct gl_buffer_object
* bufObj
;
1406 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1411 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
);
1415 *params
= bufObj
->Pointer
;
1420 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1421 GLintptr readOffset
, GLintptr writeOffset
,
1424 GET_CURRENT_CONTEXT(ctx
);
1425 struct gl_buffer_object
*src
, *dst
;
1427 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
);
1431 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
);
1435 if (_mesa_bufferobj_mapped(src
)) {
1436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1437 "glCopyBufferSubData(readBuffer is mapped)");
1441 if (_mesa_bufferobj_mapped(dst
)) {
1442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1443 "glCopyBufferSubData(writeBuffer is mapped)");
1447 if (readOffset
< 0) {
1448 _mesa_error(ctx
, GL_INVALID_VALUE
,
1449 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
1453 if (writeOffset
< 0) {
1454 _mesa_error(ctx
, GL_INVALID_VALUE
,
1455 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
1460 _mesa_error(ctx
, GL_INVALID_VALUE
,
1461 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
1465 if (readOffset
+ size
> src
->Size
) {
1466 _mesa_error(ctx
, GL_INVALID_VALUE
,
1467 "glCopyBufferSubData(readOffset + size = %d)",
1468 (int) (readOffset
+ size
));
1472 if (writeOffset
+ size
> dst
->Size
) {
1473 _mesa_error(ctx
, GL_INVALID_VALUE
,
1474 "glCopyBufferSubData(writeOffset + size = %d)",
1475 (int) (writeOffset
+ size
));
1480 if (readOffset
+ size
<= writeOffset
) {
1483 else if (writeOffset
+ size
<= readOffset
) {
1487 /* overlapping src/dst is illegal */
1488 _mesa_error(ctx
, GL_INVALID_VALUE
,
1489 "glCopyBufferSubData(overlapping src/dst)");
1494 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
1499 * See GL_ARB_map_buffer_range spec
1502 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
1505 GET_CURRENT_CONTEXT(ctx
);
1506 struct gl_buffer_object
*bufObj
;
1509 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1511 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1512 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1513 "glMapBufferRange(extension not supported)");
1518 _mesa_error(ctx
, GL_INVALID_VALUE
,
1519 "glMapBufferRange(offset = %ld)", (long)offset
);
1524 _mesa_error(ctx
, GL_INVALID_VALUE
,
1525 "glMapBufferRange(length = %ld)", (long)length
);
1529 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
1531 * "An INVALID_OPERATION error is generated for any of the following
1534 * * <length> is zero."
1536 if (_mesa_is_gles(ctx
) && length
== 0) {
1537 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1538 "glMapBufferRange(length = 0)");
1542 if (access
& ~(GL_MAP_READ_BIT
|
1544 GL_MAP_INVALIDATE_RANGE_BIT
|
1545 GL_MAP_INVALIDATE_BUFFER_BIT
|
1546 GL_MAP_FLUSH_EXPLICIT_BIT
|
1547 GL_MAP_UNSYNCHRONIZED_BIT
)) {
1548 /* generate an error if any undefind bit is set */
1549 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
1553 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
1554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1555 "glMapBufferRange(access indicates neither read or write)");
1559 if ((access
& GL_MAP_READ_BIT
) &&
1560 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
1561 GL_MAP_INVALIDATE_BUFFER_BIT
|
1562 GL_MAP_UNSYNCHRONIZED_BIT
))) {
1563 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1564 "glMapBufferRange(invalid access flags)");
1568 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
1569 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
1570 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1571 "glMapBufferRange(invalid access flags)");
1575 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
);
1579 if (offset
+ length
> bufObj
->Size
) {
1580 _mesa_error(ctx
, GL_INVALID_VALUE
,
1581 "glMapBufferRange(offset + length > size)");
1585 if (_mesa_bufferobj_mapped(bufObj
)) {
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1587 "glMapBufferRange(buffer already mapped)");
1591 if (!bufObj
->Size
) {
1592 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1593 "glMapBufferRange(buffer size = 0)");
1597 /* Mapping zero bytes should return a non-null pointer. */
1599 static long dummy
= 0;
1600 bufObj
->Pointer
= &dummy
;
1601 bufObj
->Length
= length
;
1602 bufObj
->Offset
= offset
;
1603 bufObj
->AccessFlags
= access
;
1604 return bufObj
->Pointer
;
1607 ASSERT(ctx
->Driver
.MapBufferRange
);
1608 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
);
1610 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1613 /* The driver callback should have set all these fields.
1614 * This is important because other modules (like VBO) might call
1615 * the driver function directly.
1617 ASSERT(bufObj
->Pointer
== map
);
1618 ASSERT(bufObj
->Length
== length
);
1619 ASSERT(bufObj
->Offset
== offset
);
1620 ASSERT(bufObj
->AccessFlags
== access
);
1628 * See GL_ARB_map_buffer_range spec
1631 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
1633 GET_CURRENT_CONTEXT(ctx
);
1634 struct gl_buffer_object
*bufObj
;
1636 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1637 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1638 "glFlushMappedBufferRange(extension not supported)");
1643 _mesa_error(ctx
, GL_INVALID_VALUE
,
1644 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
1649 _mesa_error(ctx
, GL_INVALID_VALUE
,
1650 "glFlushMappedBufferRange(length = %ld)", (long)length
);
1654 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
);
1658 if (!_mesa_bufferobj_mapped(bufObj
)) {
1659 /* buffer is not mapped */
1660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1661 "glFlushMappedBufferRange(buffer is not mapped)");
1665 if ((bufObj
->AccessFlags
& GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
1666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1667 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1671 if (offset
+ length
> bufObj
->Length
) {
1672 _mesa_error(ctx
, GL_INVALID_VALUE
,
1673 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
1674 (long)offset
, (long)length
, (long)bufObj
->Length
);
1678 ASSERT(bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
);
1680 if (ctx
->Driver
.FlushMappedBufferRange
)
1681 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
);
1686 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1688 struct gl_buffer_object
*bufObj
;
1691 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1693 _mesa_error(ctx
, GL_INVALID_VALUE
,
1694 "glObjectPurgeable(name = 0x%x)", name
);
1697 if (!_mesa_is_bufferobj(bufObj
)) {
1698 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
1702 if (bufObj
->Purgeable
) {
1703 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1704 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1705 return GL_VOLATILE_APPLE
;
1708 bufObj
->Purgeable
= GL_TRUE
;
1710 retval
= GL_VOLATILE_APPLE
;
1711 if (ctx
->Driver
.BufferObjectPurgeable
)
1712 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
1719 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1721 struct gl_renderbuffer
*bufObj
;
1724 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1726 _mesa_error(ctx
, GL_INVALID_VALUE
,
1727 "glObjectUnpurgeable(name = 0x%x)", name
);
1731 if (bufObj
->Purgeable
) {
1732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1733 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1734 return GL_VOLATILE_APPLE
;
1737 bufObj
->Purgeable
= GL_TRUE
;
1739 retval
= GL_VOLATILE_APPLE
;
1740 if (ctx
->Driver
.RenderObjectPurgeable
)
1741 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
1748 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1750 struct gl_texture_object
*bufObj
;
1753 bufObj
= _mesa_lookup_texture(ctx
, name
);
1755 _mesa_error(ctx
, GL_INVALID_VALUE
,
1756 "glObjectPurgeable(name = 0x%x)", name
);
1760 if (bufObj
->Purgeable
) {
1761 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1762 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1763 return GL_VOLATILE_APPLE
;
1766 bufObj
->Purgeable
= GL_TRUE
;
1768 retval
= GL_VOLATILE_APPLE
;
1769 if (ctx
->Driver
.TextureObjectPurgeable
)
1770 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
1777 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1781 GET_CURRENT_CONTEXT(ctx
);
1782 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1785 _mesa_error(ctx
, GL_INVALID_VALUE
,
1786 "glObjectPurgeable(name = 0x%x)", name
);
1791 case GL_VOLATILE_APPLE
:
1792 case GL_RELEASED_APPLE
:
1796 _mesa_error(ctx
, GL_INVALID_ENUM
,
1797 "glObjectPurgeable(name = 0x%x) invalid option: %d",
1802 switch (objectType
) {
1804 retval
= texture_object_purgeable(ctx
, name
, option
);
1806 case GL_RENDERBUFFER_EXT
:
1807 retval
= renderbuffer_purgeable(ctx
, name
, option
);
1809 case GL_BUFFER_OBJECT_APPLE
:
1810 retval
= buffer_object_purgeable(ctx
, name
, option
);
1813 _mesa_error(ctx
, GL_INVALID_ENUM
,
1814 "glObjectPurgeable(name = 0x%x) invalid type: %d",
1819 /* In strict conformance to the spec, we must only return VOLATILE when
1820 * when passed the VOLATILE option. Madness.
1822 * XXX First fix the spec, then fix me.
1824 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
1829 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1831 struct gl_buffer_object
*bufObj
;
1834 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1836 _mesa_error(ctx
, GL_INVALID_VALUE
,
1837 "glObjectUnpurgeable(name = 0x%x)", name
);
1841 if (! bufObj
->Purgeable
) {
1842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1843 "glObjectUnpurgeable(name = 0x%x) object is "
1844 " already \"unpurged\"", name
);
1848 bufObj
->Purgeable
= GL_FALSE
;
1851 if (ctx
->Driver
.BufferObjectUnpurgeable
)
1852 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
1859 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1861 struct gl_renderbuffer
*bufObj
;
1864 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1866 _mesa_error(ctx
, GL_INVALID_VALUE
,
1867 "glObjectUnpurgeable(name = 0x%x)", name
);
1871 if (! bufObj
->Purgeable
) {
1872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1873 "glObjectUnpurgeable(name = 0x%x) object is "
1874 " already \"unpurged\"", name
);
1878 bufObj
->Purgeable
= GL_FALSE
;
1881 if (ctx
->Driver
.RenderObjectUnpurgeable
)
1882 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
1889 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1891 struct gl_texture_object
*bufObj
;
1894 bufObj
= _mesa_lookup_texture(ctx
, name
);
1896 _mesa_error(ctx
, GL_INVALID_VALUE
,
1897 "glObjectUnpurgeable(name = 0x%x)", name
);
1901 if (! bufObj
->Purgeable
) {
1902 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1903 "glObjectUnpurgeable(name = 0x%x) object is"
1904 " already \"unpurged\"", name
);
1908 bufObj
->Purgeable
= GL_FALSE
;
1911 if (ctx
->Driver
.TextureObjectUnpurgeable
)
1912 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
1919 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1921 GET_CURRENT_CONTEXT(ctx
);
1922 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1925 _mesa_error(ctx
, GL_INVALID_VALUE
,
1926 "glObjectUnpurgeable(name = 0x%x)", name
);
1931 case GL_RETAINED_APPLE
:
1932 case GL_UNDEFINED_APPLE
:
1936 _mesa_error(ctx
, GL_INVALID_ENUM
,
1937 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
1942 switch (objectType
) {
1943 case GL_BUFFER_OBJECT_APPLE
:
1944 return buffer_object_unpurgeable(ctx
, name
, option
);
1946 return texture_object_unpurgeable(ctx
, name
, option
);
1947 case GL_RENDERBUFFER_EXT
:
1948 return renderbuffer_unpurgeable(ctx
, name
, option
);
1950 _mesa_error(ctx
, GL_INVALID_ENUM
,
1951 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
1959 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1960 GLenum pname
, GLint
*params
)
1962 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1964 _mesa_error(ctx
, GL_INVALID_VALUE
,
1965 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
1970 case GL_PURGEABLE_APPLE
:
1971 *params
= bufObj
->Purgeable
;
1974 _mesa_error(ctx
, GL_INVALID_ENUM
,
1975 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1983 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
1984 GLenum pname
, GLint
*params
)
1986 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
1988 _mesa_error(ctx
, GL_INVALID_VALUE
,
1989 "glObjectUnpurgeable(name = 0x%x)", name
);
1994 case GL_PURGEABLE_APPLE
:
1995 *params
= rb
->Purgeable
;
1998 _mesa_error(ctx
, GL_INVALID_ENUM
,
1999 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2007 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2008 GLenum pname
, GLint
*params
)
2010 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2012 _mesa_error(ctx
, GL_INVALID_VALUE
,
2013 "glObjectUnpurgeable(name = 0x%x)", name
);
2018 case GL_PURGEABLE_APPLE
:
2019 *params
= texObj
->Purgeable
;
2022 _mesa_error(ctx
, GL_INVALID_ENUM
,
2023 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2031 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2034 GET_CURRENT_CONTEXT(ctx
);
2037 _mesa_error(ctx
, GL_INVALID_VALUE
,
2038 "glGetObjectParameteriv(name = 0x%x)", name
);
2042 switch (objectType
) {
2044 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2046 case GL_BUFFER_OBJECT_APPLE
:
2047 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2049 case GL_RENDERBUFFER_EXT
:
2050 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2053 _mesa_error(ctx
, GL_INVALID_ENUM
,
2054 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2060 set_ubo_binding(struct gl_context
*ctx
,
2062 struct gl_buffer_object
*bufObj
,
2067 struct gl_uniform_buffer_binding
*binding
;
2069 binding
= &ctx
->UniformBufferBindings
[index
];
2070 if (binding
->BufferObject
== bufObj
&&
2071 binding
->Offset
== offset
&&
2072 binding
->Size
== size
&&
2073 binding
->AutomaticSize
== autoSize
) {
2077 FLUSH_VERTICES(ctx
, 0);
2078 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2080 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2081 binding
->Offset
= offset
;
2082 binding
->Size
= size
;
2083 binding
->AutomaticSize
= autoSize
;
2087 * Bind a region of a buffer object to a uniform block binding point.
2088 * \param index the uniform buffer binding point index
2089 * \param bufObj the buffer object
2090 * \param offset offset to the start of buffer object region
2091 * \param size size of the buffer object region
2094 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2096 struct gl_buffer_object
*bufObj
,
2100 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2101 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2105 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2106 _mesa_error(ctx
, GL_INVALID_VALUE
,
2107 "glBindBufferRange(offset misalgned %d/%d)", (int) offset
,
2108 ctx
->Const
.UniformBufferOffsetAlignment
);
2112 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2117 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2118 set_ubo_binding(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2123 * Bind a buffer object to a uniform block binding point.
2124 * As above, but offset = 0.
2127 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2129 struct gl_buffer_object
*bufObj
)
2131 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2132 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2136 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2137 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2138 set_ubo_binding(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2140 set_ubo_binding(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2144 set_atomic_buffer_binding(struct gl_context
*ctx
,
2146 struct gl_buffer_object
*bufObj
,
2151 struct gl_atomic_buffer_binding
*binding
;
2153 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2158 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2159 _mesa_error(ctx
, GL_INVALID_VALUE
,
2160 "%s(offset misalgned %d/%d)", name
, (int) offset
,
2161 ATOMIC_COUNTER_SIZE
);
2165 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2167 binding
= &ctx
->AtomicBufferBindings
[index
];
2168 if (binding
->BufferObject
== bufObj
&&
2169 binding
->Offset
== offset
&&
2170 binding
->Size
== size
) {
2174 FLUSH_VERTICES(ctx
, 0);
2175 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2177 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2179 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2180 binding
->Offset
= -1;
2183 binding
->Offset
= offset
;
2184 binding
->Size
= size
;
2189 _mesa_BindBufferRange(GLenum target
, GLuint index
,
2190 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
2192 GET_CURRENT_CONTEXT(ctx
);
2193 struct gl_buffer_object
*bufObj
;
2196 bufObj
= ctx
->Shared
->NullBufferObj
;
2198 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2200 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
2201 &bufObj
, "glBindBufferRange"))
2205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2206 "glBindBufferRange(invalid buffer=%u)", buffer
);
2212 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
2219 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2220 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
2223 case GL_UNIFORM_BUFFER
:
2224 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
2226 case GL_ATOMIC_COUNTER_BUFFER
:
2227 set_atomic_buffer_binding(ctx
, index
, bufObj
, offset
, size
,
2228 "glBindBufferRange");
2231 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
2237 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
2239 GET_CURRENT_CONTEXT(ctx
);
2240 struct gl_buffer_object
*bufObj
;
2243 bufObj
= ctx
->Shared
->NullBufferObj
;
2245 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2247 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
2248 &bufObj
, "glBindBufferBase"))
2252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2253 "glBindBufferBase(invalid buffer=%u)", buffer
);
2257 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
2258 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
2260 * "BindBufferBase is equivalent to calling BindBufferRange with offset
2261 * zero and size equal to the size of buffer."
2263 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
2265 * "If the parameter (starting offset or size) was not specified when the
2266 * buffer object was bound, zero is returned."
2268 * What happens if the size of the buffer changes? Does the size of the
2269 * buffer at the moment glBindBufferBase was called still play a role, like
2270 * the first quote would imply, or is the size meaningless in the
2271 * glBindBufferBase case like the second quote would suggest? The GL 4.1
2272 * core spec page 45 says:
2274 * "It is equivalent to calling BindBufferRange with offset zero, while
2275 * size is determined by the size of the bound buffer at the time the
2278 * My interpretation is that the GL 4.1 spec was a clarification of the
2279 * behavior, not a change. In particular, this choice will only make
2280 * rendering work in cases where it would have had undefined results.
2284 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2285 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
2287 case GL_UNIFORM_BUFFER
:
2288 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
2290 case GL_ATOMIC_COUNTER_BUFFER
:
2291 set_atomic_buffer_binding(ctx
, index
, bufObj
, 0, 0,
2292 "glBindBufferBase");
2295 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
2301 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
2304 GET_CURRENT_CONTEXT(ctx
);
2305 struct gl_buffer_object
*bufObj
;
2306 const GLintptr end
= offset
+ length
;
2308 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2310 _mesa_error(ctx
, GL_INVALID_VALUE
,
2311 "glInvalidateBufferSubData(name = 0x%x) invalid object",
2316 /* The GL_ARB_invalidate_subdata spec says:
2318 * "An INVALID_VALUE error is generated if <offset> or <length> is
2319 * negative, or if <offset> + <length> is greater than the value of
2322 if (end
< 0 || end
> bufObj
->Size
) {
2323 _mesa_error(ctx
, GL_INVALID_VALUE
,
2324 "glInvalidateBufferSubData(invalid offset or length)");
2328 /* The GL_ARB_invalidate_subdata spec says:
2330 * "An INVALID_OPERATION error is generated if the buffer is currently
2331 * mapped by MapBuffer, or if the invalidate range intersects the range
2332 * currently mapped by MapBufferRange."
2334 if (_mesa_bufferobj_mapped(bufObj
)) {
2335 const GLintptr mapEnd
= bufObj
->Offset
+ bufObj
->Length
;
2337 /* The regions do not overlap if and only if the end of the discard
2338 * region is before the mapped region or the start of the discard region
2339 * is after the mapped region.
2341 * Note that 'end' and 'mapEnd' are the first byte *after* the discard
2342 * region and the mapped region, repsectively. It is okay for that byte
2343 * to be mapped (for 'end') or discarded (for 'mapEnd').
2345 if (!(end
<= bufObj
->Offset
|| offset
>= mapEnd
)) {
2346 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2347 "glInvalidateBufferSubData(intersection with mapped "
2353 /* We don't actually do anything for this yet. Just return after
2354 * validating the parameters and generating the required errors.
2360 _mesa_InvalidateBufferData(GLuint buffer
)
2362 GET_CURRENT_CONTEXT(ctx
);
2363 struct gl_buffer_object
*bufObj
;
2365 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2367 _mesa_error(ctx
, GL_INVALID_VALUE
,
2368 "glInvalidateBufferData(name = 0x%x) invalid object",
2373 /* The GL_ARB_invalidate_subdata spec says:
2375 * "An INVALID_OPERATION error is generated if the buffer is currently
2376 * mapped by MapBuffer, or if the invalidate range intersects the range
2377 * currently mapped by MapBufferRange."
2379 if (_mesa_bufferobj_mapped(bufObj
)) {
2380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2381 "glInvalidateBufferData(intersection with mapped "
2386 /* We don't actually do anything for this yet. Just return after
2387 * validating the parameters and generating the required errors.