2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
40 #include "bufferobj.h"
42 #include "mfeatures.h"
45 #include "transformfeedback.h"
51 /*#define BOUNDS_CHECK*/
55 * Used as a placeholder for buffer objects between glGenBuffers() and
56 * glBindBuffer() so that glIsBuffer() can work correctly.
58 static struct gl_buffer_object DummyBufferObject
;
62 * Return pointer to address of a buffer object target.
63 * \param ctx the GL context
64 * \param target the buffer object target to be retrieved.
65 * \return pointer to pointer to the buffer object bound to \c target in the
66 * specified context or \c NULL if \c target is invalid.
68 static inline struct gl_buffer_object
**
69 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
71 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
73 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
74 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
78 case GL_ARRAY_BUFFER_ARB
:
79 return &ctx
->Array
.ArrayBufferObj
;
80 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
81 return &ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
82 case GL_PIXEL_PACK_BUFFER_EXT
:
83 return &ctx
->Pack
.BufferObj
;
84 case GL_PIXEL_UNPACK_BUFFER_EXT
:
85 return &ctx
->Unpack
.BufferObj
;
86 case GL_COPY_READ_BUFFER
:
87 return &ctx
->CopyReadBuffer
;
88 case GL_COPY_WRITE_BUFFER
:
89 return &ctx
->CopyWriteBuffer
;
90 case GL_TRANSFORM_FEEDBACK_BUFFER
:
91 if (ctx
->Extensions
.EXT_transform_feedback
) {
92 return &ctx
->TransformFeedback
.CurrentBuffer
;
95 case GL_TEXTURE_BUFFER
:
96 if (_mesa_is_desktop_gl(ctx
)
97 && ctx
->Extensions
.ARB_texture_buffer_object
) {
98 return &ctx
->Texture
.BufferObject
;
101 case GL_UNIFORM_BUFFER
:
102 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
103 return &ctx
->UniformBuffer
;
114 * Get the buffer object bound to the specified target in a GL context.
115 * \param ctx the GL context
116 * \param target the buffer object target to be retrieved.
117 * \return pointer to the buffer object bound to \c target in the
118 * specified context or \c NULL if \c target is invalid.
120 static inline struct gl_buffer_object
*
121 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
)
123 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
126 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
130 if (!_mesa_is_bufferobj(*bufObj
)) {
131 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(buffer 0)", func
);
139 static inline GLbitfield
140 default_access_mode(const struct gl_context
*ctx
)
142 /* Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
144 * Name Type Initial Value Legal Values
146 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
149 * However, table 6.8 in the GL_OES_mapbuffer extension says:
151 * Get Value Type Get Command Value Description
152 * --------- ---- ----------- ----- -----------
153 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
155 * The difference is because GL_OES_mapbuffer only supports mapping buffers
158 return _mesa_is_gles(ctx
)
159 ? GL_MAP_WRITE_BIT
: (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
);
164 * Convert a GLbitfield describing the mapped buffer access flags
165 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
168 simplified_access_mode(GLbitfield access
)
170 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
171 if ((access
& rwFlags
) == rwFlags
)
172 return GL_READ_WRITE
;
173 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
175 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
176 return GL_WRITE_ONLY
;
177 return GL_READ_WRITE
; /* this should never happen, but no big deal */
182 * Tests the subdata range parameters and sets the GL error code for
183 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
185 * \param ctx GL context.
186 * \param target Buffer object target on which to operate.
187 * \param offset Offset of the first byte of the subdata range.
188 * \param size Size, in bytes, of the subdata range.
189 * \param caller Name of calling function for recording errors.
190 * \return A pointer to the buffer object bound to \c target in the
191 * specified context or \c NULL if any of the parameter or state
192 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
195 * \sa glBufferSubDataARB, glGetBufferSubDataARB
197 static struct gl_buffer_object
*
198 buffer_object_subdata_range_good( struct gl_context
* ctx
, GLenum target
,
199 GLintptrARB offset
, GLsizeiptrARB size
,
202 struct gl_buffer_object
*bufObj
;
205 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
210 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
214 bufObj
= get_buffer(ctx
, caller
, target
);
218 if (offset
+ size
> bufObj
->Size
) {
219 _mesa_error(ctx
, GL_INVALID_VALUE
,
220 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
221 (unsigned long) offset
,
222 (unsigned long) size
,
223 (unsigned long) bufObj
->Size
);
226 if (_mesa_bufferobj_mapped(bufObj
)) {
227 /* Buffer is currently mapped */
228 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
237 * Allocate and initialize a new buffer object.
239 * Default callback for the \c dd_function_table::NewBufferObject() hook.
241 static struct gl_buffer_object
*
242 _mesa_new_buffer_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
244 struct gl_buffer_object
*obj
;
248 obj
= MALLOC_STRUCT(gl_buffer_object
);
249 _mesa_initialize_buffer_object(ctx
, obj
, name
, target
);
255 * Delete a buffer object.
257 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
260 _mesa_delete_buffer_object(struct gl_context
*ctx
,
261 struct gl_buffer_object
*bufObj
)
267 /* assign strange values here to help w/ debugging */
268 bufObj
->RefCount
= -1000;
271 _glthread_DESTROY_MUTEX(bufObj
->Mutex
);
278 * Set ptr to bufObj w/ reference counting.
279 * This is normally only called from the _mesa_reference_buffer_object() macro
280 * when there's a real pointer change.
283 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
284 struct gl_buffer_object
**ptr
,
285 struct gl_buffer_object
*bufObj
)
288 /* Unreference the old buffer */
289 GLboolean deleteFlag
= GL_FALSE
;
290 struct gl_buffer_object
*oldObj
= *ptr
;
292 _glthread_LOCK_MUTEX(oldObj
->Mutex
);
293 ASSERT(oldObj
->RefCount
> 0);
296 printf("BufferObj %p %d DECR to %d\n",
297 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
299 deleteFlag
= (oldObj
->RefCount
== 0);
300 _glthread_UNLOCK_MUTEX(oldObj
->Mutex
);
304 /* some sanity checking: don't delete a buffer still in use */
306 /* unfortunately, these tests are invalid during context tear-down */
307 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
308 ASSERT(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
!= bufObj
);
309 ASSERT(ctx
->Array
.ArrayObj
->Vertex
.BufferObj
!= bufObj
);
312 ASSERT(ctx
->Driver
.DeleteBuffer
);
313 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
321 /* reference new buffer */
322 _glthread_LOCK_MUTEX(bufObj
->Mutex
);
323 if (bufObj
->RefCount
== 0) {
324 /* this buffer's being deleted (look just above) */
325 /* Not sure this can every really happen. Warn if it does. */
326 _mesa_problem(NULL
, "referencing deleted buffer object");
332 printf("BufferObj %p %d INCR to %d\n",
333 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
337 _glthread_UNLOCK_MUTEX(bufObj
->Mutex
);
343 * Initialize a buffer object to default values.
346 _mesa_initialize_buffer_object( struct gl_context
*ctx
,
347 struct gl_buffer_object
*obj
,
348 GLuint name
, GLenum target
)
352 memset(obj
, 0, sizeof(struct gl_buffer_object
));
353 _glthread_INIT_MUTEX(obj
->Mutex
);
356 obj
->Usage
= GL_STATIC_DRAW_ARB
;
357 obj
->AccessFlags
= default_access_mode(ctx
);
363 * Callback called from _mesa_HashWalk()
366 count_buffer_size(GLuint key
, void *data
, void *userData
)
368 const struct gl_buffer_object
*bufObj
=
369 (const struct gl_buffer_object
*) data
;
370 GLuint
*total
= (GLuint
*) userData
;
372 *total
= *total
+ bufObj
->Size
;
377 * Compute total size (in bytes) of all buffer objects for the given context.
378 * For debugging purposes.
381 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
385 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
392 * Allocate space for and store data in a buffer object. Any data that was
393 * previously stored in the buffer object is lost. If \c data is \c NULL,
394 * memory will be allocated, but no copy will occur.
396 * This is the default callback for \c dd_function_table::BufferData()
397 * Note that all GL error checking will have been done already.
399 * \param ctx GL context.
400 * \param target Buffer object target on which to operate.
401 * \param size Size, in bytes, of the new data store.
402 * \param data Pointer to the data to store in the buffer object. This
403 * pointer may be \c NULL.
404 * \param usage Hints about how the data will be used.
405 * \param bufObj Object to be used.
407 * \return GL_TRUE for success, GL_FALSE for failure
408 * \sa glBufferDataARB, dd_function_table::BufferData.
411 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
412 const GLvoid
* data
, GLenum usage
,
413 struct gl_buffer_object
* bufObj
)
417 (void) ctx
; (void) target
;
419 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
421 bufObj
->Data
= (GLubyte
*) new_data
;
423 bufObj
->Usage
= usage
;
426 memcpy( bufObj
->Data
, data
, size
);
438 * Replace data in a subrange of buffer object. If the data range
439 * specified by \c size + \c offset extends beyond the end of the buffer or
440 * if \c data is \c NULL, no copy is performed.
442 * This is the default callback for \c dd_function_table::BufferSubData()
443 * Note that all GL error checking will have been done already.
445 * \param ctx GL context.
446 * \param target Buffer object target on which to operate.
447 * \param offset Offset of the first byte to be modified.
448 * \param size Size, in bytes, of the data range.
449 * \param data Pointer to the data to store in the buffer object.
450 * \param bufObj Object to be used.
452 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
455 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
456 GLsizeiptrARB size
, const GLvoid
* data
,
457 struct gl_buffer_object
* bufObj
)
461 /* this should have been caught in _mesa_BufferSubData() */
462 ASSERT(size
+ offset
<= bufObj
->Size
);
465 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
471 * Retrieve data from a subrange of buffer object. If the data range
472 * specified by \c size + \c offset extends beyond the end of the buffer or
473 * if \c data is \c NULL, no copy is performed.
475 * This is the default callback for \c dd_function_table::GetBufferSubData()
476 * Note that all GL error checking will have been done already.
478 * \param ctx GL context.
479 * \param target Buffer object target on which to operate.
480 * \param offset Offset of the first byte to be fetched.
481 * \param size Size, in bytes, of the data range.
482 * \param data Destination for data
483 * \param bufObj Object to be used.
485 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
488 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
489 GLsizeiptrARB size
, GLvoid
* data
,
490 struct gl_buffer_object
* bufObj
)
494 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
495 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
501 * Default fallback for \c dd_function_table::MapBufferRange().
502 * Called via glMapBufferRange().
505 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
506 GLsizeiptr length
, GLbitfield access
,
507 struct gl_buffer_object
*bufObj
)
510 assert(!_mesa_bufferobj_mapped(bufObj
));
511 /* Just return a direct pointer to the data */
512 bufObj
->Pointer
= bufObj
->Data
+ offset
;
513 bufObj
->Length
= length
;
514 bufObj
->Offset
= offset
;
515 bufObj
->AccessFlags
= access
;
516 return bufObj
->Pointer
;
521 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
522 * Called via glFlushMappedBufferRange().
525 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
526 GLintptr offset
, GLsizeiptr length
,
527 struct gl_buffer_object
*obj
)
538 * Default callback for \c dd_function_table::MapBuffer().
540 * The input parameters will have been already tested for errors.
542 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
545 _mesa_buffer_unmap( struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
)
548 /* XXX we might assert here that bufObj->Pointer is non-null */
549 bufObj
->Pointer
= NULL
;
552 bufObj
->AccessFlags
= 0x0;
558 * Default fallback for \c dd_function_table::CopyBufferSubData().
559 * Called via glCopyBufferSubData().
562 _mesa_copy_buffer_subdata(struct gl_context
*ctx
,
563 struct gl_buffer_object
*src
,
564 struct gl_buffer_object
*dst
,
565 GLintptr readOffset
, GLintptr writeOffset
,
568 GLubyte
*srcPtr
, *dstPtr
;
570 /* the buffers should not be mapped */
571 assert(!_mesa_bufferobj_mapped(src
));
572 assert(!_mesa_bufferobj_mapped(dst
));
575 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
577 GL_MAP_WRITE_BIT
, src
);
582 srcPtr
+= readOffset
;
583 dstPtr
+= writeOffset
;
585 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
586 GL_MAP_READ_BIT
, src
);
587 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
589 GL_MAP_INVALIDATE_RANGE_BIT
), dst
);
592 /* Note: the src and dst regions will never overlap. Trying to do so
593 * would generate GL_INVALID_VALUE earlier.
595 if (srcPtr
&& dstPtr
)
596 memcpy(dstPtr
, srcPtr
, size
);
598 ctx
->Driver
.UnmapBuffer(ctx
, src
);
600 ctx
->Driver
.UnmapBuffer(ctx
, dst
);
606 * Initialize the state associated with buffer objects
609 _mesa_init_buffer_objects( struct gl_context
*ctx
)
613 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
614 _glthread_INIT_MUTEX(DummyBufferObject
.Mutex
);
615 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
617 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
618 ctx
->Shared
->NullBufferObj
);
620 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
621 ctx
->Shared
->NullBufferObj
);
622 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
623 ctx
->Shared
->NullBufferObj
);
625 ctx
->UniformBufferBindings
= calloc(ctx
->Const
.MaxUniformBufferBindings
,
626 sizeof(*ctx
->UniformBufferBindings
));
628 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
629 ctx
->Shared
->NullBufferObj
);
631 for (i
= 0; i
< ctx
->Const
.MaxUniformBufferBindings
; i
++) {
632 _mesa_reference_buffer_object(ctx
,
633 &ctx
->UniformBufferBindings
[i
].BufferObject
,
634 ctx
->Shared
->NullBufferObj
);
635 ctx
->UniformBufferBindings
[i
].Offset
= -1;
636 ctx
->UniformBufferBindings
[i
].Size
= -1;
642 _mesa_free_buffer_objects( struct gl_context
*ctx
)
646 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
648 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
649 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
651 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
653 for (i
= 0; i
< ctx
->Const
.MaxUniformBufferBindings
; i
++) {
654 _mesa_reference_buffer_object(ctx
,
655 &ctx
->UniformBufferBindings
[i
].BufferObject
,
659 free(ctx
->UniformBufferBindings
);
660 ctx
->UniformBufferBindings
= NULL
;
664 handle_bind_buffer_gen(struct gl_context
*ctx
,
667 struct gl_buffer_object
**buf_handle
)
669 struct gl_buffer_object
*buf
= *buf_handle
;
671 if (!buf
|| buf
== &DummyBufferObject
) {
672 /* If this is a new buffer object id, or one which was generated but
673 * never used before, allocate a buffer object now.
675 ASSERT(ctx
->Driver
.NewBufferObject
);
676 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
, target
);
678 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindBufferARB");
681 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
687 * Bind the specified target to buffer for the specified context.
688 * Called by glBindBuffer() and other functions.
691 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
693 struct gl_buffer_object
*oldBufObj
;
694 struct gl_buffer_object
*newBufObj
= NULL
;
695 struct gl_buffer_object
**bindTarget
= NULL
;
697 bindTarget
= get_buffer_target(ctx
, target
);
699 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
703 /* Get pointer to old buffer object (to be unbound) */
704 oldBufObj
= *bindTarget
;
705 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
706 return; /* rebinding the same buffer object- no change */
709 * Get pointer to new buffer object (newBufObj)
712 /* The spec says there's not a buffer object named 0, but we use
713 * one internally because it simplifies things.
715 newBufObj
= ctx
->Shared
->NullBufferObj
;
718 /* non-default buffer object */
719 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
720 if (newBufObj
== NULL
&& ctx
->API
== API_OPENGL_CORE
) {
721 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindBuffer(non-gen name)");
724 handle_bind_buffer_gen(ctx
, target
, buffer
, &newBufObj
);
727 /* bind new buffer */
728 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
730 /* Pass BindBuffer call to device driver */
731 if (ctx
->Driver
.BindBuffer
)
732 ctx
->Driver
.BindBuffer( ctx
, target
, newBufObj
);
737 * Update the default buffer objects in the given context to reference those
738 * specified in the shared state and release those referencing the old
742 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
744 /* Bind the NullBufferObj to remove references to those
745 * in the shared context hash table.
747 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
748 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
749 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
750 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
756 * Return the gl_buffer_object for the given ID.
757 * Always return NULL for ID 0.
759 struct gl_buffer_object
*
760 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
765 return (struct gl_buffer_object
*)
766 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
771 * If *ptr points to obj, set ptr = the Null/default buffer object.
772 * This is a helper for buffer object deletion.
773 * The GL spec says that deleting a buffer object causes it to get
774 * unbound from all arrays in the current context.
777 unbind(struct gl_context
*ctx
,
778 struct gl_buffer_object
**ptr
,
779 struct gl_buffer_object
*obj
)
782 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
788 * Plug default/fallback buffer object functions into the device
792 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
794 /* GL_ARB_vertex/pixel_buffer_object */
795 driver
->NewBufferObject
= _mesa_new_buffer_object
;
796 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
797 driver
->BindBuffer
= NULL
;
798 driver
->BufferData
= _mesa_buffer_data
;
799 driver
->BufferSubData
= _mesa_buffer_subdata
;
800 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
801 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
803 /* GL_ARB_map_buffer_range */
804 driver
->MapBufferRange
= _mesa_buffer_map_range
;
805 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
807 /* GL_ARB_copy_buffer */
808 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
813 /**********************************************************************/
815 /**********************************************************************/
818 _mesa_BindBufferARB(GLenum target
, GLuint buffer
)
820 GET_CURRENT_CONTEXT(ctx
);
821 ASSERT_OUTSIDE_BEGIN_END(ctx
);
823 if (MESA_VERBOSE
& VERBOSE_API
)
824 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
825 _mesa_lookup_enum_by_nr(target
), buffer
);
827 bind_buffer_object(ctx
, target
, buffer
);
832 * Delete a set of buffer objects.
834 * \param n Number of buffer objects to delete.
835 * \param ids Array of \c n buffer object IDs.
838 _mesa_DeleteBuffersARB(GLsizei n
, const GLuint
*ids
)
840 GET_CURRENT_CONTEXT(ctx
);
842 ASSERT_OUTSIDE_BEGIN_END(ctx
);
843 FLUSH_VERTICES(ctx
, 0);
846 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
850 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
852 for (i
= 0; i
< n
; i
++) {
853 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
855 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
858 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
860 if (_mesa_bufferobj_mapped(bufObj
)) {
861 /* if mapped, unmap it now */
862 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
863 bufObj
->AccessFlags
= default_access_mode(ctx
);
864 bufObj
->Pointer
= NULL
;
867 /* unbind any vertex pointers bound to this buffer */
868 for (j
= 0; j
< Elements(arrayObj
->VertexAttrib
); j
++) {
869 unbind(ctx
, &arrayObj
->VertexAttrib
[j
].BufferObj
, bufObj
);
872 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
873 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB
, 0 );
875 if (arrayObj
->ElementArrayBufferObj
== bufObj
) {
876 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
879 /* unbind ARB_copy_buffer binding points */
880 if (ctx
->CopyReadBuffer
== bufObj
) {
881 _mesa_BindBufferARB( GL_COPY_READ_BUFFER
, 0 );
883 if (ctx
->CopyWriteBuffer
== bufObj
) {
884 _mesa_BindBufferARB( GL_COPY_WRITE_BUFFER
, 0 );
887 /* unbind transform feedback binding points */
888 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
889 _mesa_BindBufferARB( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
891 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
892 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
893 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
897 /* unbind UBO binding points */
898 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
899 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
900 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
904 if (ctx
->UniformBuffer
== bufObj
) {
905 _mesa_BindBufferARB( GL_UNIFORM_BUFFER
, 0 );
908 /* unbind any pixel pack/unpack pointers bound to this buffer */
909 if (ctx
->Pack
.BufferObj
== bufObj
) {
910 _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
912 if (ctx
->Unpack
.BufferObj
== bufObj
) {
913 _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
916 if (ctx
->Texture
.BufferObject
== bufObj
) {
917 _mesa_BindBufferARB( GL_TEXTURE_BUFFER
, 0 );
920 /* The ID is immediately freed for re-use */
921 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
922 /* Make sure we do not run into the classic ABA problem on bind.
923 * We don't want to allow re-binding a buffer object that's been
924 * "deleted" by glDeleteBuffers().
926 * The explicit rebinding to the default object in the current context
927 * prevents the above in the current context, but another context
928 * sharing the same objects might suffer from this problem.
929 * The alternative would be to do the hash lookup in any case on bind
930 * which would introduce more runtime overhead than this.
932 bufObj
->DeletePending
= GL_TRUE
;
933 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
937 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
942 * Generate a set of unique buffer object IDs and store them in \c buffer.
944 * \param n Number of IDs to generate.
945 * \param buffer Array of \c n locations to store the IDs.
948 _mesa_GenBuffersARB(GLsizei n
, GLuint
*buffer
)
950 GET_CURRENT_CONTEXT(ctx
);
953 ASSERT_OUTSIDE_BEGIN_END(ctx
);
955 if (MESA_VERBOSE
& VERBOSE_API
)
956 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
959 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
968 * This must be atomic (generation and allocation of buffer object IDs)
970 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
972 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
974 /* Insert the ID and pointer to dummy buffer object into hash table */
975 for (i
= 0; i
< n
; i
++) {
976 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
978 buffer
[i
] = first
+ i
;
981 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
986 * Determine if ID is the name of a buffer object.
988 * \param id ID of the potential buffer object.
989 * \return \c GL_TRUE if \c id is the name of a buffer object,
990 * \c GL_FALSE otherwise.
993 _mesa_IsBufferARB(GLuint id
)
995 struct gl_buffer_object
*bufObj
;
996 GET_CURRENT_CONTEXT(ctx
);
997 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
999 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1000 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1001 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1003 return bufObj
&& bufObj
!= &DummyBufferObject
;
1008 _mesa_BufferDataARB(GLenum target
, GLsizeiptrARB size
,
1009 const GLvoid
* data
, GLenum usage
)
1011 GET_CURRENT_CONTEXT(ctx
);
1012 struct gl_buffer_object
*bufObj
;
1014 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1016 if (MESA_VERBOSE
& VERBOSE_API
)
1017 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1018 _mesa_lookup_enum_by_nr(target
),
1019 (long int) size
, data
,
1020 _mesa_lookup_enum_by_nr(usage
));
1023 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1028 case GL_STREAM_DRAW_ARB
:
1029 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1032 case GL_STATIC_DRAW_ARB
:
1033 case GL_DYNAMIC_DRAW_ARB
:
1037 case GL_STREAM_READ_ARB
:
1038 case GL_STREAM_COPY_ARB
:
1039 case GL_STATIC_READ_ARB
:
1040 case GL_STATIC_COPY_ARB
:
1041 case GL_DYNAMIC_READ_ARB
:
1042 case GL_DYNAMIC_COPY_ARB
:
1043 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1047 valid_usage
= false;
1052 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1056 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
);
1060 if (_mesa_bufferobj_mapped(bufObj
)) {
1061 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1062 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
1063 bufObj
->AccessFlags
= default_access_mode(ctx
);
1064 ASSERT(bufObj
->Pointer
== NULL
);
1067 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1069 bufObj
->Written
= GL_TRUE
;
1072 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1073 bufObj
->Name
, size
, data
, usage
);
1080 ASSERT(ctx
->Driver
.BufferData
);
1081 if (!ctx
->Driver
.BufferData( ctx
, target
, size
, data
, usage
, bufObj
)) {
1082 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
1088 _mesa_BufferSubDataARB(GLenum target
, GLintptrARB offset
,
1089 GLsizeiptrARB size
, const GLvoid
* data
)
1091 GET_CURRENT_CONTEXT(ctx
);
1092 struct gl_buffer_object
*bufObj
;
1093 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1095 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1096 "glBufferSubDataARB" );
1098 /* error already recorded */
1105 bufObj
->Written
= GL_TRUE
;
1107 ASSERT(ctx
->Driver
.BufferSubData
);
1108 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1113 _mesa_GetBufferSubDataARB(GLenum target
, GLintptrARB offset
,
1114 GLsizeiptrARB size
, void * data
)
1116 GET_CURRENT_CONTEXT(ctx
);
1117 struct gl_buffer_object
*bufObj
;
1118 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1120 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1121 "glGetBufferSubDataARB" );
1123 /* error already recorded */
1127 ASSERT(ctx
->Driver
.GetBufferSubData
);
1128 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1133 _mesa_MapBufferARB(GLenum target
, GLenum access
)
1135 GET_CURRENT_CONTEXT(ctx
);
1136 struct gl_buffer_object
* bufObj
;
1137 GLbitfield accessFlags
;
1141 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1144 case GL_READ_ONLY_ARB
:
1145 accessFlags
= GL_MAP_READ_BIT
;
1146 valid_access
= _mesa_is_desktop_gl(ctx
);
1148 case GL_WRITE_ONLY_ARB
:
1149 accessFlags
= GL_MAP_WRITE_BIT
;
1150 valid_access
= true;
1152 case GL_READ_WRITE_ARB
:
1153 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1154 valid_access
= _mesa_is_desktop_gl(ctx
);
1157 valid_access
= false;
1161 if (!valid_access
) {
1162 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1166 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
);
1170 if (_mesa_bufferobj_mapped(bufObj
)) {
1171 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1175 if (!bufObj
->Size
) {
1176 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1177 "glMapBuffer(buffer size = 0)");
1181 ASSERT(ctx
->Driver
.MapBufferRange
);
1182 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
);
1184 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1188 /* The driver callback should have set these fields.
1189 * This is important because other modules (like VBO) might call
1190 * the driver function directly.
1192 ASSERT(bufObj
->Pointer
== map
);
1193 ASSERT(bufObj
->Length
== bufObj
->Size
);
1194 ASSERT(bufObj
->Offset
== 0);
1195 bufObj
->AccessFlags
= accessFlags
;
1198 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1199 bufObj
->Written
= GL_TRUE
;
1202 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1203 bufObj
->Name
, bufObj
->Size
, access
);
1204 if (access
== GL_WRITE_ONLY_ARB
) {
1206 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1207 for (i
= 0; i
< bufObj
->Size
; i
++)
1214 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1216 /* buffer is 100 bytes larger than requested, fill with magic value */
1217 for (i
= 0; i
< 100; i
++) {
1218 buf
[bufObj
->Size
- i
- 1] = 123;
1223 return bufObj
->Pointer
;
1227 GLboolean GLAPIENTRY
1228 _mesa_UnmapBufferARB(GLenum target
)
1230 GET_CURRENT_CONTEXT(ctx
);
1231 struct gl_buffer_object
*bufObj
;
1232 GLboolean status
= GL_TRUE
;
1233 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1235 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
);
1239 if (!_mesa_bufferobj_mapped(bufObj
)) {
1240 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1245 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1246 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1248 /* check that last 100 bytes are still = magic value */
1249 for (i
= 0; i
< 100; i
++) {
1250 GLuint pos
= bufObj
->Size
- i
- 1;
1251 if (buf
[pos
] != 123) {
1252 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1253 " at position %d (value = %u)\n",
1261 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1262 GLuint i
, unchanged
= 0;
1263 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1265 /* check which bytes changed */
1266 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1267 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1274 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1275 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1280 status
= ctx
->Driver
.UnmapBuffer( ctx
, bufObj
);
1281 bufObj
->AccessFlags
= default_access_mode(ctx
);
1282 ASSERT(bufObj
->Pointer
== NULL
);
1283 ASSERT(bufObj
->Offset
== 0);
1284 ASSERT(bufObj
->Length
== 0);
1291 _mesa_GetBufferParameterivARB(GLenum target
, GLenum pname
, GLint
*params
)
1293 GET_CURRENT_CONTEXT(ctx
);
1294 struct gl_buffer_object
*bufObj
;
1295 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1297 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
);
1302 case GL_BUFFER_SIZE_ARB
:
1303 *params
= (GLint
) bufObj
->Size
;
1305 case GL_BUFFER_USAGE_ARB
:
1306 *params
= bufObj
->Usage
;
1308 case GL_BUFFER_ACCESS_ARB
:
1309 *params
= simplified_access_mode(bufObj
->AccessFlags
);
1311 case GL_BUFFER_MAPPED_ARB
:
1312 *params
= _mesa_bufferobj_mapped(bufObj
);
1314 case GL_BUFFER_ACCESS_FLAGS
:
1315 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_map_buffer_range
)
1316 && !_mesa_is_gles3(ctx
))
1318 *params
= bufObj
->AccessFlags
;
1320 case GL_BUFFER_MAP_OFFSET
:
1321 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_map_buffer_range
)
1322 && !_mesa_is_gles3(ctx
))
1324 *params
= (GLint
) bufObj
->Offset
;
1326 case GL_BUFFER_MAP_LENGTH
:
1327 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_map_buffer_range
)
1328 && !_mesa_is_gles3(ctx
))
1330 *params
= (GLint
) bufObj
->Length
;
1333 ; /* fall-through */
1337 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1338 _mesa_lookup_enum_by_nr(pname
));
1344 * This is pretty much a duplicate of GetBufferParameteriv() but the
1345 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1348 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1350 GET_CURRENT_CONTEXT(ctx
);
1351 struct gl_buffer_object
*bufObj
;
1352 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1354 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
);
1359 case GL_BUFFER_SIZE_ARB
:
1360 *params
= bufObj
->Size
;
1362 case GL_BUFFER_USAGE_ARB
:
1363 *params
= bufObj
->Usage
;
1365 case GL_BUFFER_ACCESS_ARB
:
1366 *params
= simplified_access_mode(bufObj
->AccessFlags
);
1368 case GL_BUFFER_ACCESS_FLAGS
:
1369 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1371 *params
= bufObj
->AccessFlags
;
1373 case GL_BUFFER_MAPPED_ARB
:
1374 *params
= _mesa_bufferobj_mapped(bufObj
);
1376 case GL_BUFFER_MAP_OFFSET
:
1377 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1379 *params
= bufObj
->Offset
;
1381 case GL_BUFFER_MAP_LENGTH
:
1382 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1384 *params
= bufObj
->Length
;
1387 ; /* fall-through */
1391 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1392 _mesa_lookup_enum_by_nr(pname
));
1397 _mesa_GetBufferPointervARB(GLenum target
, GLenum pname
, GLvoid
**params
)
1399 GET_CURRENT_CONTEXT(ctx
);
1400 struct gl_buffer_object
* bufObj
;
1401 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1403 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1404 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1408 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
);
1412 *params
= bufObj
->Pointer
;
1417 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1418 GLintptr readOffset
, GLintptr writeOffset
,
1421 GET_CURRENT_CONTEXT(ctx
);
1422 struct gl_buffer_object
*src
, *dst
;
1423 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1425 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
);
1429 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
);
1433 if (_mesa_bufferobj_mapped(src
)) {
1434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1435 "glCopyBufferSubData(readBuffer is mapped)");
1439 if (_mesa_bufferobj_mapped(dst
)) {
1440 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1441 "glCopyBufferSubData(writeBuffer is mapped)");
1445 if (readOffset
< 0) {
1446 _mesa_error(ctx
, GL_INVALID_VALUE
,
1447 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
1451 if (writeOffset
< 0) {
1452 _mesa_error(ctx
, GL_INVALID_VALUE
,
1453 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
1458 _mesa_error(ctx
, GL_INVALID_VALUE
,
1459 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
1463 if (readOffset
+ size
> src
->Size
) {
1464 _mesa_error(ctx
, GL_INVALID_VALUE
,
1465 "glCopyBufferSubData(readOffset + size = %d)",
1466 (int) (readOffset
+ size
));
1470 if (writeOffset
+ size
> dst
->Size
) {
1471 _mesa_error(ctx
, GL_INVALID_VALUE
,
1472 "glCopyBufferSubData(writeOffset + size = %d)",
1473 (int) (writeOffset
+ size
));
1478 if (readOffset
+ size
<= writeOffset
) {
1481 else if (writeOffset
+ size
<= readOffset
) {
1485 /* overlapping src/dst is illegal */
1486 _mesa_error(ctx
, GL_INVALID_VALUE
,
1487 "glCopyBufferSubData(overlapping src/dst)");
1492 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
1497 * See GL_ARB_map_buffer_range spec
1500 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
1503 GET_CURRENT_CONTEXT(ctx
);
1504 struct gl_buffer_object
*bufObj
;
1507 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1509 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1510 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1511 "glMapBufferRange(extension not supported)");
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glMapBufferRange(offset = %ld)", (long)offset
);
1522 _mesa_error(ctx
, GL_INVALID_VALUE
,
1523 "glMapBufferRange(length = %ld)", (long)length
);
1527 if (access
& ~(GL_MAP_READ_BIT
|
1529 GL_MAP_INVALIDATE_RANGE_BIT
|
1530 GL_MAP_INVALIDATE_BUFFER_BIT
|
1531 GL_MAP_FLUSH_EXPLICIT_BIT
|
1532 GL_MAP_UNSYNCHRONIZED_BIT
)) {
1533 /* generate an error if any undefind bit is set */
1534 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
1538 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
1539 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1540 "glMapBufferRange(access indicates neither read or write)");
1544 if ((access
& GL_MAP_READ_BIT
) &&
1545 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
1546 GL_MAP_INVALIDATE_BUFFER_BIT
|
1547 GL_MAP_UNSYNCHRONIZED_BIT
))) {
1548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1549 "glMapBufferRange(invalid access flags)");
1553 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
1554 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
1555 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1556 "glMapBufferRange(invalid access flags)");
1560 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
);
1564 if (offset
+ length
> bufObj
->Size
) {
1565 _mesa_error(ctx
, GL_INVALID_VALUE
,
1566 "glMapBufferRange(offset + length > size)");
1570 if (_mesa_bufferobj_mapped(bufObj
)) {
1571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1572 "glMapBufferRange(buffer already mapped)");
1576 if (!bufObj
->Size
) {
1577 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1578 "glMapBufferRange(buffer size = 0)");
1582 /* Mapping zero bytes should return a non-null pointer. */
1584 static long dummy
= 0;
1585 bufObj
->Pointer
= &dummy
;
1586 bufObj
->Length
= length
;
1587 bufObj
->Offset
= offset
;
1588 bufObj
->AccessFlags
= access
;
1589 return bufObj
->Pointer
;
1592 ASSERT(ctx
->Driver
.MapBufferRange
);
1593 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
);
1595 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1598 /* The driver callback should have set all these fields.
1599 * This is important because other modules (like VBO) might call
1600 * the driver function directly.
1602 ASSERT(bufObj
->Pointer
== map
);
1603 ASSERT(bufObj
->Length
== length
);
1604 ASSERT(bufObj
->Offset
== offset
);
1605 ASSERT(bufObj
->AccessFlags
== access
);
1613 * See GL_ARB_map_buffer_range spec
1616 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
1618 GET_CURRENT_CONTEXT(ctx
);
1619 struct gl_buffer_object
*bufObj
;
1620 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1622 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1623 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1624 "glFlushMappedBufferRange(extension not supported)");
1629 _mesa_error(ctx
, GL_INVALID_VALUE
,
1630 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
1635 _mesa_error(ctx
, GL_INVALID_VALUE
,
1636 "glFlushMappedBufferRange(length = %ld)", (long)length
);
1640 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
);
1644 if (!_mesa_bufferobj_mapped(bufObj
)) {
1645 /* buffer is not mapped */
1646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1647 "glFlushMappedBufferRange(buffer is not mapped)");
1651 if ((bufObj
->AccessFlags
& GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1657 if (offset
+ length
> bufObj
->Length
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
,
1659 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
1660 (long)offset
, (long)length
, (long)bufObj
->Length
);
1664 ASSERT(bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
);
1666 if (ctx
->Driver
.FlushMappedBufferRange
)
1667 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
);
1671 #if FEATURE_APPLE_object_purgeable
1673 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1675 struct gl_buffer_object
*bufObj
;
1678 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1680 _mesa_error(ctx
, GL_INVALID_VALUE
,
1681 "glObjectPurgeable(name = 0x%x)", name
);
1684 if (!_mesa_is_bufferobj(bufObj
)) {
1685 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
1689 if (bufObj
->Purgeable
) {
1690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1691 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1692 return GL_VOLATILE_APPLE
;
1695 bufObj
->Purgeable
= GL_TRUE
;
1697 retval
= GL_VOLATILE_APPLE
;
1698 if (ctx
->Driver
.BufferObjectPurgeable
)
1699 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
1706 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1708 struct gl_renderbuffer
*bufObj
;
1711 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1713 _mesa_error(ctx
, GL_INVALID_VALUE
,
1714 "glObjectUnpurgeable(name = 0x%x)", name
);
1718 if (bufObj
->Purgeable
) {
1719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1720 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1721 return GL_VOLATILE_APPLE
;
1724 bufObj
->Purgeable
= GL_TRUE
;
1726 retval
= GL_VOLATILE_APPLE
;
1727 if (ctx
->Driver
.RenderObjectPurgeable
)
1728 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
1735 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1737 struct gl_texture_object
*bufObj
;
1740 bufObj
= _mesa_lookup_texture(ctx
, name
);
1742 _mesa_error(ctx
, GL_INVALID_VALUE
,
1743 "glObjectPurgeable(name = 0x%x)", name
);
1747 if (bufObj
->Purgeable
) {
1748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1749 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1750 return GL_VOLATILE_APPLE
;
1753 bufObj
->Purgeable
= GL_TRUE
;
1755 retval
= GL_VOLATILE_APPLE
;
1756 if (ctx
->Driver
.TextureObjectPurgeable
)
1757 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
1764 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1768 GET_CURRENT_CONTEXT(ctx
);
1769 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1772 _mesa_error(ctx
, GL_INVALID_VALUE
,
1773 "glObjectPurgeable(name = 0x%x)", name
);
1778 case GL_VOLATILE_APPLE
:
1779 case GL_RELEASED_APPLE
:
1783 _mesa_error(ctx
, GL_INVALID_ENUM
,
1784 "glObjectPurgeable(name = 0x%x) invalid option: %d",
1789 switch (objectType
) {
1791 retval
= texture_object_purgeable(ctx
, name
, option
);
1793 case GL_RENDERBUFFER_EXT
:
1794 retval
= renderbuffer_purgeable(ctx
, name
, option
);
1796 case GL_BUFFER_OBJECT_APPLE
:
1797 retval
= buffer_object_purgeable(ctx
, name
, option
);
1800 _mesa_error(ctx
, GL_INVALID_ENUM
,
1801 "glObjectPurgeable(name = 0x%x) invalid type: %d",
1806 /* In strict conformance to the spec, we must only return VOLATILE when
1807 * when passed the VOLATILE option. Madness.
1809 * XXX First fix the spec, then fix me.
1811 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
1816 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1818 struct gl_buffer_object
*bufObj
;
1821 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1823 _mesa_error(ctx
, GL_INVALID_VALUE
,
1824 "glObjectUnpurgeable(name = 0x%x)", name
);
1828 if (! bufObj
->Purgeable
) {
1829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1830 "glObjectUnpurgeable(name = 0x%x) object is "
1831 " already \"unpurged\"", name
);
1835 bufObj
->Purgeable
= GL_FALSE
;
1838 if (ctx
->Driver
.BufferObjectUnpurgeable
)
1839 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
1846 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1848 struct gl_renderbuffer
*bufObj
;
1851 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1853 _mesa_error(ctx
, GL_INVALID_VALUE
,
1854 "glObjectUnpurgeable(name = 0x%x)", name
);
1858 if (! bufObj
->Purgeable
) {
1859 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1860 "glObjectUnpurgeable(name = 0x%x) object is "
1861 " already \"unpurged\"", name
);
1865 bufObj
->Purgeable
= GL_FALSE
;
1868 if (ctx
->Driver
.RenderObjectUnpurgeable
)
1869 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
1876 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1878 struct gl_texture_object
*bufObj
;
1881 bufObj
= _mesa_lookup_texture(ctx
, name
);
1883 _mesa_error(ctx
, GL_INVALID_VALUE
,
1884 "glObjectUnpurgeable(name = 0x%x)", name
);
1888 if (! bufObj
->Purgeable
) {
1889 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1890 "glObjectUnpurgeable(name = 0x%x) object is"
1891 " already \"unpurged\"", name
);
1895 bufObj
->Purgeable
= GL_FALSE
;
1898 if (ctx
->Driver
.TextureObjectUnpurgeable
)
1899 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
1906 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1908 GET_CURRENT_CONTEXT(ctx
);
1909 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1912 _mesa_error(ctx
, GL_INVALID_VALUE
,
1913 "glObjectUnpurgeable(name = 0x%x)", name
);
1918 case GL_RETAINED_APPLE
:
1919 case GL_UNDEFINED_APPLE
:
1923 _mesa_error(ctx
, GL_INVALID_ENUM
,
1924 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
1929 switch (objectType
) {
1930 case GL_BUFFER_OBJECT_APPLE
:
1931 return buffer_object_unpurgeable(ctx
, name
, option
);
1933 return texture_object_unpurgeable(ctx
, name
, option
);
1934 case GL_RENDERBUFFER_EXT
:
1935 return renderbuffer_unpurgeable(ctx
, name
, option
);
1937 _mesa_error(ctx
, GL_INVALID_ENUM
,
1938 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
1946 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1947 GLenum pname
, GLint
*params
)
1949 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1951 _mesa_error(ctx
, GL_INVALID_VALUE
,
1952 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
1957 case GL_PURGEABLE_APPLE
:
1958 *params
= bufObj
->Purgeable
;
1961 _mesa_error(ctx
, GL_INVALID_ENUM
,
1962 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1970 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
1971 GLenum pname
, GLint
*params
)
1973 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
1975 _mesa_error(ctx
, GL_INVALID_VALUE
,
1976 "glObjectUnpurgeable(name = 0x%x)", name
);
1981 case GL_PURGEABLE_APPLE
:
1982 *params
= rb
->Purgeable
;
1985 _mesa_error(ctx
, GL_INVALID_ENUM
,
1986 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1994 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1995 GLenum pname
, GLint
*params
)
1997 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
1999 _mesa_error(ctx
, GL_INVALID_VALUE
,
2000 "glObjectUnpurgeable(name = 0x%x)", name
);
2005 case GL_PURGEABLE_APPLE
:
2006 *params
= texObj
->Purgeable
;
2009 _mesa_error(ctx
, GL_INVALID_ENUM
,
2010 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2018 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2021 GET_CURRENT_CONTEXT(ctx
);
2024 _mesa_error(ctx
, GL_INVALID_VALUE
,
2025 "glGetObjectParameteriv(name = 0x%x)", name
);
2029 switch (objectType
) {
2031 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2033 case GL_BUFFER_OBJECT_APPLE
:
2034 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2036 case GL_RENDERBUFFER_EXT
:
2037 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2040 _mesa_error(ctx
, GL_INVALID_ENUM
,
2041 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2046 #endif /* FEATURE_APPLE_object_purgeable */
2049 set_ubo_binding(struct gl_context
*ctx
,
2051 struct gl_buffer_object
*bufObj
,
2056 struct gl_uniform_buffer_binding
*binding
;
2058 binding
= &ctx
->UniformBufferBindings
[index
];
2059 if (binding
->BufferObject
== bufObj
&&
2060 binding
->Offset
== offset
&&
2061 binding
->Size
== size
&&
2062 binding
->AutomaticSize
== autoSize
) {
2066 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
2068 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2069 binding
->Offset
= offset
;
2070 binding
->Size
= size
;
2071 binding
->AutomaticSize
= autoSize
;
2075 * Bind a region of a buffer object to a uniform block binding point.
2076 * \param index the uniform buffer binding point index
2077 * \param bufObj the buffer object
2078 * \param offset offset to the start of buffer object region
2079 * \param size size of the buffer object region
2082 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2084 struct gl_buffer_object
*bufObj
,
2088 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2089 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2093 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2094 _mesa_error(ctx
, GL_INVALID_VALUE
,
2095 "glBindBufferRange(offset misalgned %d/%d)", (int) offset
,
2096 ctx
->Const
.UniformBufferOffsetAlignment
);
2100 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2105 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2106 set_ubo_binding(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2111 * Bind a buffer object to a uniform block binding point.
2112 * As above, but offset = 0.
2115 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2117 struct gl_buffer_object
*bufObj
)
2119 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2120 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2124 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2125 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2126 set_ubo_binding(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2128 set_ubo_binding(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2132 _mesa_BindBufferRange(GLenum target
, GLuint index
,
2133 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
2135 GET_CURRENT_CONTEXT(ctx
);
2136 struct gl_buffer_object
*bufObj
;
2139 bufObj
= ctx
->Shared
->NullBufferObj
;
2141 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2143 handle_bind_buffer_gen(ctx
, target
, buffer
, &bufObj
);
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2147 "glBindBufferRange(invalid buffer=%u)", buffer
);
2152 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
2157 if (offset
+ size
> bufObj
->Size
) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glBindBufferRange(offset + size %d > buffer size %d)",
2160 (int) (offset
+ size
), (int) (bufObj
->Size
));
2165 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2166 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
2169 case GL_UNIFORM_BUFFER
:
2170 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
2173 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
2179 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
2181 GET_CURRENT_CONTEXT(ctx
);
2182 struct gl_buffer_object
*bufObj
;
2185 bufObj
= ctx
->Shared
->NullBufferObj
;
2187 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2189 handle_bind_buffer_gen(ctx
, target
, buffer
, &bufObj
);
2192 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2193 "glBindBufferBase(invalid buffer=%u)", buffer
);
2197 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
2198 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
2200 * "BindBufferBase is equivalent to calling BindBufferRange with offset
2201 * zero and size equal to the size of buffer."
2203 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
2205 * "If the parameter (starting offset or size) was not specified when the
2206 * buffer object was bound, zero is returned."
2208 * What happens if the size of the buffer changes? Does the size of the
2209 * buffer at the moment glBindBufferBase was called still play a role, like
2210 * the first quote would imply, or is the size meaningless in the
2211 * glBindBufferBase case like the second quote would suggest? The GL 4.1
2212 * core spec page 45 says:
2214 * "It is equivalent to calling BindBufferRange with offset zero, while
2215 * size is determined by the size of the bound buffer at the time the
2218 * My interpretation is that the GL 4.1 spec was a clarification of the
2219 * behavior, not a change. In particular, this choice will only make
2220 * rendering work in cases where it would have had undefined results.
2224 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2225 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
2227 case GL_UNIFORM_BUFFER
:
2228 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
2231 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
2236 static void GLAPIENTRY
2237 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
2240 GET_CURRENT_CONTEXT(ctx
);
2241 struct gl_buffer_object
*bufObj
;
2242 const GLintptr end
= offset
+ length
;
2244 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2246 _mesa_error(ctx
, GL_INVALID_VALUE
,
2247 "glInvalidateBufferSubData(name = 0x%x) invalid object",
2252 /* The GL_ARB_invalidate_subdata spec says:
2254 * "An INVALID_VALUE error is generated if <offset> or <length> is
2255 * negative, or if <offset> + <length> is greater than the value of
2258 if (end
< 0 || end
> bufObj
->Size
) {
2259 _mesa_error(ctx
, GL_INVALID_VALUE
,
2260 "glInvalidateBufferSubData(invalid offset or length)");
2264 /* The GL_ARB_invalidate_subdata spec says:
2266 * "An INVALID_OPERATION error is generated if the buffer is currently
2267 * mapped by MapBuffer, or if the invalidate range intersects the range
2268 * currently mapped by MapBufferRange."
2270 if (_mesa_bufferobj_mapped(bufObj
)) {
2271 const GLintptr mapEnd
= bufObj
->Offset
+ bufObj
->Length
;
2273 /* The regions do not overlap if and only if the end of the discard
2274 * region is before the mapped region or the start of the discard region
2275 * is after the mapped region.
2277 * Note that 'end' and 'mapEnd' are the first byte *after* the discard
2278 * region and the mapped region, repsectively. It is okay for that byte
2279 * to be mapped (for 'end') or discarded (for 'mapEnd').
2281 if (!(end
<= bufObj
->Offset
|| offset
>= mapEnd
)) {
2282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2283 "glInvalidateBufferSubData(intersection with mapped "
2289 /* We don't actually do anything for this yet. Just return after
2290 * validating the parameters and generating the required errors.
2295 static void GLAPIENTRY
2296 _mesa_InvalidateBufferData(GLuint buffer
)
2298 GET_CURRENT_CONTEXT(ctx
);
2299 struct gl_buffer_object
*bufObj
;
2301 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2303 _mesa_error(ctx
, GL_INVALID_VALUE
,
2304 "glInvalidateBufferData(name = 0x%x) invalid object",
2309 /* The GL_ARB_invalidate_subdata spec says:
2311 * "An INVALID_OPERATION error is generated if the buffer is currently
2312 * mapped by MapBuffer, or if the invalidate range intersects the range
2313 * currently mapped by MapBufferRange."
2315 if (_mesa_bufferobj_mapped(bufObj
)) {
2316 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2317 "glInvalidateBufferData(intersection with mapped "
2322 /* We don't actually do anything for this yet. Just return after
2323 * validating the parameters and generating the required errors.
2329 _mesa_init_bufferobj_dispatch(struct gl_context
*ctx
, struct _glapi_table
*disp
)
2331 SET_BindBufferARB(disp
, _mesa_BindBufferARB
);
2332 SET_BufferDataARB(disp
, _mesa_BufferDataARB
);
2333 SET_BufferSubDataARB(disp
, _mesa_BufferSubDataARB
);
2334 SET_DeleteBuffersARB(disp
, _mesa_DeleteBuffersARB
);
2335 SET_GenBuffersARB(disp
, _mesa_GenBuffersARB
);
2336 SET_GetBufferParameterivARB(disp
, _mesa_GetBufferParameterivARB
);
2337 SET_GetBufferPointervARB(disp
, _mesa_GetBufferPointervARB
);
2338 SET_GetBufferSubDataARB(disp
, _mesa_GetBufferSubDataARB
);
2339 SET_IsBufferARB(disp
, _mesa_IsBufferARB
);
2340 SET_MapBufferARB(disp
, _mesa_MapBufferARB
);
2341 SET_UnmapBufferARB(disp
, _mesa_UnmapBufferARB
);
2343 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
)) {
2344 SET_BindBufferRangeEXT(disp
, _mesa_BindBufferRange
);
2345 SET_BindBufferBaseEXT(disp
, _mesa_BindBufferBase
);
2348 if (_mesa_is_desktop_gl(ctx
)) {
2349 SET_InvalidateBufferData(disp
, _mesa_InvalidateBufferData
);
2350 SET_InvalidateBufferSubData(disp
, _mesa_InvalidateBufferSubData
);