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
39 #include "bufferobj.h"
44 /*#define BOUNDS_CHECK*/
47 #ifdef FEATURE_OES_mapbuffer
48 #define DEFAULT_ACCESS GL_MAP_WRITE_BIT
50 #define DEFAULT_ACCESS (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)
55 * Get the buffer object bound to the specified target in a GL context.
57 * \param ctx GL context
58 * \param target Buffer object target to be retrieved. Currently this must
59 * be either \c GL_ARRAY_BUFFER or \c GL_ELEMENT_ARRAY_BUFFER.
60 * \return A pointer to the buffer object bound to \c target in the
61 * specified context or \c NULL if \c target is invalid.
63 static INLINE
struct gl_buffer_object
*
64 get_buffer(GLcontext
*ctx
, GLenum target
)
66 struct gl_buffer_object
* bufObj
= NULL
;
69 case GL_ARRAY_BUFFER_ARB
:
70 bufObj
= ctx
->Array
.ArrayBufferObj
;
72 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
73 bufObj
= ctx
->Array
.ElementArrayBufferObj
;
75 case GL_PIXEL_PACK_BUFFER_EXT
:
76 bufObj
= ctx
->Pack
.BufferObj
;
78 case GL_PIXEL_UNPACK_BUFFER_EXT
:
79 bufObj
= ctx
->Unpack
.BufferObj
;
81 case GL_COPY_READ_BUFFER
:
82 if (ctx
->Extensions
.ARB_copy_buffer
) {
83 bufObj
= ctx
->CopyReadBuffer
;
86 case GL_COPY_WRITE_BUFFER
:
87 if (ctx
->Extensions
.ARB_copy_buffer
) {
88 bufObj
= ctx
->CopyWriteBuffer
;
92 /* error must be recorded by caller */
96 /* bufObj should point to NullBufferObj or a user-created buffer object */
104 * Convert a GLbitfield describing the mapped buffer access flags
105 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
108 simplified_access_mode(GLbitfield access
)
110 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
111 if ((access
& rwFlags
) == rwFlags
)
112 return GL_READ_WRITE
;
113 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
115 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
116 return GL_WRITE_ONLY
;
117 return GL_READ_WRITE
; /* this should never happen, but no big deal */
122 * Tests the subdata range parameters and sets the GL error code for
123 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
125 * \param ctx GL context.
126 * \param target Buffer object target on which to operate.
127 * \param offset Offset of the first byte of the subdata range.
128 * \param size Size, in bytes, of the subdata range.
129 * \param caller Name of calling function for recording errors.
130 * \return A pointer to the buffer object bound to \c target in the
131 * specified context or \c NULL if any of the parameter or state
132 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
135 * \sa glBufferSubDataARB, glGetBufferSubDataARB
137 static struct gl_buffer_object
*
138 buffer_object_subdata_range_good( GLcontext
* ctx
, GLenum target
,
139 GLintptrARB offset
, GLsizeiptrARB size
,
142 struct gl_buffer_object
*bufObj
;
145 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
150 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
154 bufObj
= get_buffer(ctx
, target
);
156 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", caller
);
159 if (bufObj
->Name
== 0) {
160 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
163 if (offset
+ size
> bufObj
->Size
) {
164 _mesa_error(ctx
, GL_INVALID_VALUE
,
165 "%s(size + offset > buffer size)", caller
);
168 if (bufObj
->Pointer
) {
169 /* Buffer is currently mapped */
170 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
179 * Allocate and initialize a new buffer object.
181 * Default callback for the \c dd_function_table::NewBufferObject() hook.
183 struct gl_buffer_object
*
184 _mesa_new_buffer_object( GLcontext
*ctx
, GLuint name
, GLenum target
)
186 struct gl_buffer_object
*obj
;
190 obj
= MALLOC_STRUCT(gl_buffer_object
);
191 _mesa_initialize_buffer_object(obj
, name
, target
);
197 * Delete a buffer object.
199 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
202 _mesa_delete_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*bufObj
)
207 _mesa_free(bufObj
->Data
);
209 /* assign strange values here to help w/ debugging */
210 bufObj
->RefCount
= -1000;
219 * Set ptr to bufObj w/ reference counting.
222 _mesa_reference_buffer_object(GLcontext
*ctx
,
223 struct gl_buffer_object
**ptr
,
224 struct gl_buffer_object
*bufObj
)
230 /* Unreference the old buffer */
231 GLboolean deleteFlag
= GL_FALSE
;
232 struct gl_buffer_object
*oldObj
= *ptr
;
234 /*_glthread_LOCK_MUTEX(oldObj->Mutex);*/
235 ASSERT(oldObj
->RefCount
> 0);
238 printf("BufferObj %p %d DECR to %d\n",
239 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
241 deleteFlag
= (oldObj
->RefCount
== 0);
242 /*_glthread_UNLOCK_MUTEX(oldObj->Mutex);*/
246 /* some sanity checking: don't delete a buffer still in use */
248 /* unfortunately, these tests are invalid during context tear-down */
249 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
250 ASSERT(ctx
->Array
.ElementArrayBufferObj
!= bufObj
);
251 ASSERT(ctx
->Array
.ArrayObj
->Vertex
.BufferObj
!= bufObj
);
254 ASSERT(ctx
->Driver
.DeleteBuffer
);
255 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
263 /* reference new buffer */
264 /*_glthread_LOCK_MUTEX(tex->Mutex);*/
265 if (bufObj
->RefCount
== 0) {
266 /* this buffer's being deleted (look just above) */
267 /* Not sure this can every really happen. Warn if it does. */
268 _mesa_problem(NULL
, "referencing deleted buffer object");
274 printf("BufferObj %p %d INCR to %d\n",
275 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
279 /*_glthread_UNLOCK_MUTEX(tex->Mutex);*/
285 * Initialize a buffer object to default values.
288 _mesa_initialize_buffer_object( struct gl_buffer_object
*obj
,
289 GLuint name
, GLenum target
)
293 _mesa_bzero(obj
, sizeof(struct gl_buffer_object
));
296 obj
->Usage
= GL_STATIC_DRAW_ARB
;
297 obj
->AccessFlags
= DEFAULT_ACCESS
;
302 * Allocate space for and store data in a buffer object. Any data that was
303 * previously stored in the buffer object is lost. If \c data is \c NULL,
304 * memory will be allocated, but no copy will occur.
306 * This is the default callback for \c dd_function_table::BufferData()
307 * Note that all GL error checking will have been done already.
309 * \param ctx GL context.
310 * \param target Buffer object target on which to operate.
311 * \param size Size, in bytes, of the new data store.
312 * \param data Pointer to the data to store in the buffer object. This
313 * pointer may be \c NULL.
314 * \param usage Hints about how the data will be used.
315 * \param bufObj Object to be used.
317 * \sa glBufferDataARB, dd_function_table::BufferData.
320 _mesa_buffer_data( GLcontext
*ctx
, GLenum target
, GLsizeiptrARB size
,
321 const GLvoid
* data
, GLenum usage
,
322 struct gl_buffer_object
* bufObj
)
326 (void) ctx
; (void) target
;
328 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
330 bufObj
->Data
= (GLubyte
*) new_data
;
332 bufObj
->Usage
= usage
;
335 _mesa_memcpy( bufObj
->Data
, data
, size
);
342 * Replace data in a subrange of buffer object. If the data range
343 * specified by \c size + \c offset extends beyond the end of the buffer or
344 * if \c data is \c NULL, no copy is performed.
346 * This is the default callback for \c dd_function_table::BufferSubData()
347 * Note that all GL error checking will have been done already.
349 * \param ctx GL context.
350 * \param target Buffer object target on which to operate.
351 * \param offset Offset of the first byte to be modified.
352 * \param size Size, in bytes, of the data range.
353 * \param data Pointer to the data to store in the buffer object.
354 * \param bufObj Object to be used.
356 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
359 _mesa_buffer_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
360 GLsizeiptrARB size
, const GLvoid
* data
,
361 struct gl_buffer_object
* bufObj
)
363 (void) ctx
; (void) target
;
365 /* this should have been caught in _mesa_BufferSubData() */
366 ASSERT(size
+ offset
<= bufObj
->Size
);
369 _mesa_memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
375 * Retrieve data from a subrange of buffer object. If the data range
376 * specified by \c size + \c offset extends beyond the end of the buffer or
377 * if \c data is \c NULL, no copy is performed.
379 * This is the default callback for \c dd_function_table::GetBufferSubData()
380 * Note that all GL error checking will have been done already.
382 * \param ctx GL context.
383 * \param target Buffer object target on which to operate.
384 * \param offset Offset of the first byte to be fetched.
385 * \param size Size, in bytes, of the data range.
386 * \param data Destination for data
387 * \param bufObj Object to be used.
389 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
392 _mesa_buffer_get_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
393 GLsizeiptrARB size
, GLvoid
* data
,
394 struct gl_buffer_object
* bufObj
)
396 (void) ctx
; (void) target
;
398 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
399 _mesa_memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
405 * Default callback for \c dd_function_tabel::MapBuffer().
407 * The function parameters will have been already tested for errors.
409 * \param ctx GL context.
410 * \param target Buffer object target on which to operate.
411 * \param access Information about how the buffer will be accessed.
412 * \param bufObj Object to be mapped.
413 * \return A pointer to the object's internal data store that can be accessed
416 * \sa glMapBufferARB, dd_function_table::MapBuffer
419 _mesa_buffer_map( GLcontext
*ctx
, GLenum target
, GLenum access
,
420 struct gl_buffer_object
*bufObj
)
425 /* Just return a direct pointer to the data */
426 if (bufObj
->Pointer
) {
427 /* already mapped! */
430 bufObj
->Pointer
= bufObj
->Data
;
431 return bufObj
->Pointer
;
436 * Default fallback for \c dd_function_table::MapBufferRange().
437 * Called via glMapBufferRange().
440 _mesa_buffer_map_range( GLcontext
*ctx
, GLenum target
, GLintptr offset
,
441 GLsizeiptr length
, GLbitfield access
,
442 struct gl_buffer_object
*bufObj
)
448 assert(!bufObj
->Pointer
);
449 /* Just return a direct pointer to the data */
450 return bufObj
->Data
+ offset
;
455 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
456 * Called via glFlushMappedBufferRange().
459 _mesa_buffer_flush_mapped_range( GLcontext
*ctx
, GLenum target
,
460 GLintptr offset
, GLsizeiptr length
,
461 struct gl_buffer_object
*obj
)
473 * Default callback for \c dd_function_table::MapBuffer().
475 * The input parameters will have been already tested for errors.
477 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
480 _mesa_buffer_unmap( GLcontext
*ctx
, GLenum target
,
481 struct gl_buffer_object
*bufObj
)
485 /* XXX we might assert here that bufObj->Pointer is non-null */
486 bufObj
->Pointer
= NULL
;
492 * Default fallback for \c dd_function_table::CopyBufferSubData().
493 * Called via glCopyBuffserSubData().
496 _mesa_copy_buffer_subdata(GLcontext
*ctx
,
497 struct gl_buffer_object
*src
,
498 struct gl_buffer_object
*dst
,
499 GLintptr readOffset
, GLintptr writeOffset
,
502 GLubyte
*srcPtr
, *dstPtr
;
504 /* buffer should not already be mapped */
505 assert(!src
->Pointer
);
506 assert(!dst
->Pointer
);
508 srcPtr
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_COPY_READ_BUFFER
,
510 dstPtr
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_COPY_WRITE_BUFFER
,
513 if (srcPtr
&& dstPtr
)
514 _mesa_memcpy(dstPtr
+ writeOffset
, srcPtr
+ readOffset
, size
);
516 ctx
->Driver
.UnmapBuffer(ctx
, GL_COPY_READ_BUFFER
, src
);
517 ctx
->Driver
.UnmapBuffer(ctx
, GL_COPY_WRITE_BUFFER
, dst
);
523 * Initialize the state associated with buffer objects
526 _mesa_init_buffer_objects( GLcontext
*ctx
)
528 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
529 ctx
->Shared
->NullBufferObj
);
530 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ElementArrayBufferObj
,
531 ctx
->Shared
->NullBufferObj
);
533 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
534 ctx
->Shared
->NullBufferObj
);
535 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
536 ctx
->Shared
->NullBufferObj
);
541 * Bind the specified target to buffer for the specified context.
544 bind_buffer_object(GLcontext
*ctx
, GLenum target
, GLuint buffer
)
546 struct gl_buffer_object
*oldBufObj
;
547 struct gl_buffer_object
*newBufObj
= NULL
;
548 struct gl_buffer_object
**bindTarget
= NULL
;
551 case GL_ARRAY_BUFFER_ARB
:
552 bindTarget
= &ctx
->Array
.ArrayBufferObj
;
554 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
555 bindTarget
= &ctx
->Array
.ElementArrayBufferObj
;
557 case GL_PIXEL_PACK_BUFFER_EXT
:
558 bindTarget
= &ctx
->Pack
.BufferObj
;
560 case GL_PIXEL_UNPACK_BUFFER_EXT
:
561 bindTarget
= &ctx
->Unpack
.BufferObj
;
563 case GL_COPY_READ_BUFFER
:
564 if (ctx
->Extensions
.ARB_copy_buffer
) {
565 bindTarget
= &ctx
->CopyReadBuffer
;
568 case GL_COPY_WRITE_BUFFER
:
569 if (ctx
->Extensions
.ARB_copy_buffer
) {
570 bindTarget
= &ctx
->CopyWriteBuffer
;
574 ; /* no-op / we'll hit the follow error test next */
578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)");
582 /* Get pointer to old buffer object (to be unbound) */
583 oldBufObj
= get_buffer(ctx
, target
);
584 if (oldBufObj
&& oldBufObj
->Name
== buffer
)
585 return; /* rebinding the same buffer object- no change */
588 * Get pointer to new buffer object (newBufObj)
591 /* The spec says there's not a buffer object named 0, but we use
592 * one internally because it simplifies things.
594 newBufObj
= ctx
->Shared
->NullBufferObj
;
597 /* non-default buffer object */
598 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
600 /* if this is a new buffer object id, allocate a buffer object now */
601 ASSERT(ctx
->Driver
.NewBufferObject
);
602 newBufObj
= ctx
->Driver
.NewBufferObject(ctx
, buffer
, target
);
604 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindBufferARB");
607 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, newBufObj
);
611 /* bind new buffer */
612 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
614 /* Pass BindBuffer call to device driver */
615 if (ctx
->Driver
.BindBuffer
)
616 ctx
->Driver
.BindBuffer( ctx
, target
, newBufObj
);
621 * Update the default buffer objects in the given context to reference those
622 * specified in the shared state and release those referencing the old
626 _mesa_update_default_objects_buffer_objects(GLcontext
*ctx
)
628 /* Bind the NullBufferObj to remove references to those
629 * in the shared context hash table.
631 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
632 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
633 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
634 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
639 * When we're about to read pixel data out of a PBO (via glDrawPixels,
640 * glTexImage, etc) or write data into a PBO (via glReadPixels,
641 * glGetTexImage, etc) we call this function to check that we're not
642 * going to read out of bounds.
644 * XXX This would also be a convenient time to check that the PBO isn't
645 * currently mapped. Whoever calls this function should check for that.
646 * Remember, we can't use a PBO when it's mapped!
648 * \param width width of image to read/write
649 * \param height height of image to read/write
650 * \param depth depth of image to read/write
651 * \param format format of image to read/write
652 * \param type datatype of image to read/write
653 * \param ptr the user-provided pointer/offset
654 * \return GL_TRUE if the PBO access is OK, GL_FALSE if the access would
658 _mesa_validate_pbo_access(GLuint dimensions
,
659 const struct gl_pixelstore_attrib
*pack
,
660 GLsizei width
, GLsizei height
, GLsizei depth
,
661 GLenum format
, GLenum type
, const GLvoid
*ptr
)
664 const GLubyte
*sizeAddr
; /* buffer size, cast to a pointer */
666 ASSERT(pack
->BufferObj
->Name
!= 0);
668 if (pack
->BufferObj
->Size
== 0)
672 /* get address of first pixel we'll read */
673 start
= _mesa_image_address(dimensions
, pack
, ptr
, width
, height
,
674 format
, type
, 0, 0, 0);
676 /* get address just past the last pixel we'll read */
677 end
= _mesa_image_address(dimensions
, pack
, ptr
, width
, height
,
678 format
, type
, depth
-1, height
-1, width
);
681 sizeAddr
= ((const GLubyte
*) 0) + pack
->BufferObj
->Size
;
683 if ((const GLubyte
*) start
> sizeAddr
) {
684 /* This will catch negative values / wrap-around */
687 if ((const GLubyte
*) end
> sizeAddr
) {
688 /* Image read goes beyond end of buffer */
698 * If the source of glBitmap data is a PBO, check that we won't read out
699 * of buffer bounds, then map the buffer.
700 * If not sourcing from a PBO, just return the bitmap pointer.
701 * This is a helper function for (some) drivers.
702 * Return NULL if error.
703 * If non-null return, must call _mesa_unmap_bitmap_pbo() when done.
706 _mesa_map_bitmap_pbo(GLcontext
*ctx
,
707 const struct gl_pixelstore_attrib
*unpack
,
708 const GLubyte
*bitmap
)
712 if (unpack
->BufferObj
->Name
) {
713 /* unpack from PBO */
714 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
720 buf
= ADD_POINTERS(buf
, bitmap
);
723 /* unpack from normal memory */
732 * Counterpart to _mesa_map_bitmap_pbo()
733 * This is a helper function for (some) drivers.
736 _mesa_unmap_bitmap_pbo(GLcontext
*ctx
,
737 const struct gl_pixelstore_attrib
*unpack
)
739 if (unpack
->BufferObj
->Name
) {
740 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
747 * \sa _mesa_map_bitmap_pbo
750 _mesa_map_drawpix_pbo(GLcontext
*ctx
,
751 const struct gl_pixelstore_attrib
*unpack
,
752 const GLvoid
*pixels
)
756 if (unpack
->BufferObj
->Name
) {
757 /* unpack from PBO */
758 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
764 buf
= ADD_POINTERS(buf
, pixels
);
767 /* unpack from normal memory */
776 * \sa _mesa_unmap_bitmap_pbo
779 _mesa_unmap_drawpix_pbo(GLcontext
*ctx
,
780 const struct gl_pixelstore_attrib
*unpack
)
782 if (unpack
->BufferObj
->Name
) {
783 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
790 * If PBO is bound, map the buffer, return dest pointer in mapped buffer.
791 * Call _mesa_unmap_readpix_pbo() when finished
792 * \return NULL if error
795 _mesa_map_readpix_pbo(GLcontext
*ctx
,
796 const struct gl_pixelstore_attrib
*pack
,
801 if (pack
->BufferObj
->Name
) {
803 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
809 buf
= ADD_POINTERS(buf
, dest
);
812 /* pack to normal memory */
821 * Counterpart to _mesa_map_readpix_pbo()
824 _mesa_unmap_readpix_pbo(GLcontext
*ctx
,
825 const struct gl_pixelstore_attrib
*pack
)
827 if (pack
->BufferObj
->Name
) {
828 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
, pack
->BufferObj
);
835 * Return the gl_buffer_object for the given ID.
836 * Always return NULL for ID 0.
838 struct gl_buffer_object
*
839 _mesa_lookup_bufferobj(GLcontext
*ctx
, GLuint buffer
)
844 return (struct gl_buffer_object
*)
845 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
850 * If *ptr points to obj, set ptr = the Null/default buffer object.
851 * This is a helper for buffer object deletion.
852 * The GL spec says that deleting a buffer object causes it to get
853 * unbound from all arrays in the current context.
856 unbind(GLcontext
*ctx
,
857 struct gl_buffer_object
**ptr
,
858 struct gl_buffer_object
*obj
)
861 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
867 /**********************************************************************/
869 /**********************************************************************/
872 _mesa_BindBufferARB(GLenum target
, GLuint buffer
)
874 GET_CURRENT_CONTEXT(ctx
);
875 ASSERT_OUTSIDE_BEGIN_END(ctx
);
877 bind_buffer_object(ctx
, target
, buffer
);
882 * Delete a set of buffer objects.
884 * \param n Number of buffer objects to delete.
885 * \param ids Array of \c n buffer object IDs.
888 _mesa_DeleteBuffersARB(GLsizei n
, const GLuint
*ids
)
890 GET_CURRENT_CONTEXT(ctx
);
892 ASSERT_OUTSIDE_BEGIN_END(ctx
);
895 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
899 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
901 for (i
= 0; i
< n
; i
++) {
902 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
904 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
907 ASSERT(bufObj
->Name
== ids
[i
]);
909 if (bufObj
->Pointer
) {
910 /* if mapped, unmap it now */
911 ctx
->Driver
.UnmapBuffer(ctx
, 0, bufObj
);
912 bufObj
->AccessFlags
= DEFAULT_ACCESS
;
913 bufObj
->Pointer
= NULL
;
916 /* unbind any vertex pointers bound to this buffer */
917 unbind(ctx
, &arrayObj
->Vertex
.BufferObj
, bufObj
);
918 unbind(ctx
, &arrayObj
->Weight
.BufferObj
, bufObj
);
919 unbind(ctx
, &arrayObj
->Normal
.BufferObj
, bufObj
);
920 unbind(ctx
, &arrayObj
->Color
.BufferObj
, bufObj
);
921 unbind(ctx
, &arrayObj
->SecondaryColor
.BufferObj
, bufObj
);
922 unbind(ctx
, &arrayObj
->FogCoord
.BufferObj
, bufObj
);
923 unbind(ctx
, &arrayObj
->Index
.BufferObj
, bufObj
);
924 unbind(ctx
, &arrayObj
->EdgeFlag
.BufferObj
, bufObj
);
925 for (j
= 0; j
< Elements(arrayObj
->TexCoord
); j
++) {
926 unbind(ctx
, &arrayObj
->TexCoord
[j
].BufferObj
, bufObj
);
928 for (j
= 0; j
< Elements(arrayObj
->VertexAttrib
); j
++) {
929 unbind(ctx
, &arrayObj
->VertexAttrib
[j
].BufferObj
, bufObj
);
932 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
933 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB
, 0 );
935 if (ctx
->Array
.ElementArrayBufferObj
== bufObj
) {
936 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
939 /* unbind any pixel pack/unpack pointers bound to this buffer */
940 if (ctx
->Pack
.BufferObj
== bufObj
) {
941 _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
943 if (ctx
->Unpack
.BufferObj
== bufObj
) {
944 _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
947 /* The ID is immediately freed for re-use */
948 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, bufObj
->Name
);
949 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
953 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
958 * Generate a set of unique buffer object IDs and store them in \c buffer.
960 * \param n Number of IDs to generate.
961 * \param buffer Array of \c n locations to store the IDs.
964 _mesa_GenBuffersARB(GLsizei n
, GLuint
*buffer
)
966 GET_CURRENT_CONTEXT(ctx
);
969 ASSERT_OUTSIDE_BEGIN_END(ctx
);
972 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
981 * This must be atomic (generation and allocation of buffer object IDs)
983 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
985 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
987 /* Allocate new, empty buffer objects and return identifiers */
988 for (i
= 0; i
< n
; i
++) {
989 struct gl_buffer_object
*bufObj
;
990 GLuint name
= first
+ i
;
992 bufObj
= ctx
->Driver
.NewBufferObject( ctx
, name
, target
);
994 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
995 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenBuffersARB");
998 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
, bufObj
);
999 buffer
[i
] = first
+ i
;
1002 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1007 * Determine if ID is the name of a buffer object.
1009 * \param id ID of the potential buffer object.
1010 * \return \c GL_TRUE if \c id is the name of a buffer object,
1011 * \c GL_FALSE otherwise.
1013 GLboolean GLAPIENTRY
1014 _mesa_IsBufferARB(GLuint id
)
1016 struct gl_buffer_object
*bufObj
;
1017 GET_CURRENT_CONTEXT(ctx
);
1018 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1020 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1021 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1022 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1024 return bufObj
? GL_TRUE
: GL_FALSE
;
1029 _mesa_BufferDataARB(GLenum target
, GLsizeiptrARB size
,
1030 const GLvoid
* data
, GLenum usage
)
1032 GET_CURRENT_CONTEXT(ctx
);
1033 struct gl_buffer_object
*bufObj
;
1034 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1037 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1042 case GL_STREAM_DRAW_ARB
:
1043 case GL_STREAM_READ_ARB
:
1044 case GL_STREAM_COPY_ARB
:
1045 case GL_STATIC_DRAW_ARB
:
1046 case GL_STATIC_READ_ARB
:
1047 case GL_STATIC_COPY_ARB
:
1048 case GL_DYNAMIC_DRAW_ARB
:
1049 case GL_DYNAMIC_READ_ARB
:
1050 case GL_DYNAMIC_COPY_ARB
:
1054 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferDataARB(usage)");
1058 bufObj
= get_buffer(ctx
, target
);
1060 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferDataARB(target)" );
1063 if (bufObj
->Name
== 0) {
1064 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferDataARB(buffer 0)" );
1068 if (bufObj
->Pointer
) {
1069 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1070 ctx
->Driver
.UnmapBuffer(ctx
, target
, bufObj
);
1071 bufObj
->AccessFlags
= DEFAULT_ACCESS
;
1072 bufObj
->Pointer
= NULL
;
1075 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1077 ASSERT(ctx
->Driver
.BufferData
);
1079 bufObj
->Written
= GL_TRUE
;
1082 _mesa_printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1083 bufObj
->Name
, size
, data
, usage
);
1089 /* Give the buffer object to the driver! <data> may be null! */
1090 ctx
->Driver
.BufferData( ctx
, target
, size
, data
, usage
, bufObj
);
1095 _mesa_BufferSubDataARB(GLenum target
, GLintptrARB offset
,
1096 GLsizeiptrARB size
, const GLvoid
* data
)
1098 GET_CURRENT_CONTEXT(ctx
);
1099 struct gl_buffer_object
*bufObj
;
1100 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1102 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1103 "glBufferSubDataARB" );
1105 /* error already recorded */
1109 bufObj
->Written
= GL_TRUE
;
1111 ASSERT(ctx
->Driver
.BufferSubData
);
1112 ctx
->Driver
.BufferSubData( ctx
, target
, offset
, size
, data
, bufObj
);
1117 _mesa_GetBufferSubDataARB(GLenum target
, GLintptrARB offset
,
1118 GLsizeiptrARB size
, void * data
)
1120 GET_CURRENT_CONTEXT(ctx
);
1121 struct gl_buffer_object
*bufObj
;
1122 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1124 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1125 "glGetBufferSubDataARB" );
1127 /* error already recorded */
1131 ASSERT(ctx
->Driver
.GetBufferSubData
);
1132 ctx
->Driver
.GetBufferSubData( ctx
, target
, offset
, size
, data
, bufObj
);
1137 _mesa_MapBufferARB(GLenum target
, GLenum access
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 struct gl_buffer_object
* bufObj
;
1141 GLbitfield accessFlags
;
1142 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1145 case GL_READ_ONLY_ARB
:
1146 accessFlags
= GL_MAP_READ_BIT
;
1148 case GL_WRITE_ONLY_ARB
:
1149 accessFlags
= GL_MAP_WRITE_BIT
;
1151 case GL_READ_WRITE_ARB
:
1152 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1155 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1159 bufObj
= get_buffer(ctx
, target
);
1161 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(target)" );
1164 if (bufObj
->Name
== 0) {
1165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(buffer 0)" );
1168 if (bufObj
->Pointer
) {
1169 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1173 ASSERT(ctx
->Driver
.MapBuffer
);
1174 bufObj
->Pointer
= ctx
->Driver
.MapBuffer( ctx
, target
, access
, bufObj
);
1175 if (!bufObj
->Pointer
) {
1176 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(access)");
1179 bufObj
->AccessFlags
= accessFlags
;
1181 bufObj
->Length
= bufObj
->Size
;
1183 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1184 bufObj
->Written
= GL_TRUE
;
1187 _mesa_printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1188 bufObj
->Name
, bufObj
->Size
, access
);
1189 if (access
== GL_WRITE_ONLY_ARB
) {
1191 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1192 for (i
= 0; i
< bufObj
->Size
; i
++)
1199 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1201 /* buffer is 100 bytes larger than requested, fill with magic value */
1202 for (i
= 0; i
< 100; i
++) {
1203 buf
[bufObj
->Size
- i
- 1] = 123;
1208 return bufObj
->Pointer
;
1212 GLboolean GLAPIENTRY
1213 _mesa_UnmapBufferARB(GLenum target
)
1215 GET_CURRENT_CONTEXT(ctx
);
1216 struct gl_buffer_object
*bufObj
;
1217 GLboolean status
= GL_TRUE
;
1218 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1220 bufObj
= get_buffer(ctx
, target
);
1222 _mesa_error(ctx
, GL_INVALID_ENUM
, "glUnmapBufferARB(target)" );
1225 if (bufObj
->Name
== 0) {
1226 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB" );
1229 if (!bufObj
->Pointer
) {
1230 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1235 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1236 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1238 /* check that last 100 bytes are still = magic value */
1239 for (i
= 0; i
< 100; i
++) {
1240 GLuint pos
= bufObj
->Size
- i
- 1;
1241 if (buf
[pos
] != 123) {
1242 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1243 " at position %d (value = %u)\n",
1251 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1252 GLuint i
, unchanged
= 0;
1253 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1255 /* check which bytes changed */
1256 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1257 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1264 _mesa_printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1265 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1270 status
= ctx
->Driver
.UnmapBuffer( ctx
, target
, bufObj
);
1271 bufObj
->AccessFlags
= DEFAULT_ACCESS
;
1272 bufObj
->Pointer
= NULL
;
1281 _mesa_GetBufferParameterivARB(GLenum target
, GLenum pname
, GLint
*params
)
1283 GET_CURRENT_CONTEXT(ctx
);
1284 struct gl_buffer_object
*bufObj
;
1285 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1287 bufObj
= get_buffer(ctx
, target
);
1289 _mesa_error(ctx
, GL_INVALID_ENUM
, "GetBufferParameterivARB(target)" );
1292 if (bufObj
->Name
== 0) {
1293 _mesa_error(ctx
, GL_INVALID_OPERATION
, "GetBufferParameterivARB" );
1298 case GL_BUFFER_SIZE_ARB
:
1299 *params
= (GLint
) bufObj
->Size
;
1301 case GL_BUFFER_USAGE_ARB
:
1302 *params
= bufObj
->Usage
;
1304 case GL_BUFFER_ACCESS_ARB
:
1305 *params
= simplified_access_mode(bufObj
->AccessFlags
);
1307 case GL_BUFFER_MAPPED_ARB
:
1308 *params
= (bufObj
->Pointer
!= NULL
);
1311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname)");
1318 _mesa_GetBufferPointervARB(GLenum target
, GLenum pname
, GLvoid
**params
)
1320 GET_CURRENT_CONTEXT(ctx
);
1321 struct gl_buffer_object
* bufObj
;
1322 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1324 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1325 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1329 bufObj
= get_buffer(ctx
, target
);
1331 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(target)" );
1334 if (bufObj
->Name
== 0) {
1335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferPointervARB" );
1339 *params
= bufObj
->Pointer
;
1344 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1345 GLintptr readOffset
, GLintptr writeOffset
,
1348 GET_CURRENT_CONTEXT(ctx
);
1349 struct gl_buffer_object
*src
, *dst
;
1350 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1352 src
= get_buffer(ctx
, readTarget
);
1353 if (!src
|| src
->Name
== 0) {
1354 _mesa_error(ctx
, GL_INVALID_ENUM
,
1355 "glCopyBuffserSubData(readTarget = 0x%x)", readTarget
);
1359 dst
= get_buffer(ctx
, writeTarget
);
1360 if (!dst
|| dst
->Name
== 0) {
1361 _mesa_error(ctx
, GL_INVALID_ENUM
,
1362 "glCopyBuffserSubData(writeTarget = 0x%x)", writeTarget
);
1367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1368 "glCopyBuffserSubData(readBuffer is mapped)");
1373 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1374 "glCopyBuffserSubData(writeBuffer is mapped)");
1378 if (readOffset
< 0) {
1379 _mesa_error(ctx
, GL_INVALID_VALUE
,
1380 "glCopyBuffserSubData(readOffset = %d)", readOffset
);
1384 if (writeOffset
< 0) {
1385 _mesa_error(ctx
, GL_INVALID_VALUE
,
1386 "glCopyBuffserSubData(writeOffset = %d)", writeOffset
);
1390 if (readOffset
+ size
> src
->Size
) {
1391 _mesa_error(ctx
, GL_INVALID_VALUE
,
1392 "glCopyBuffserSubData(readOffset + size = %d)",
1397 if (writeOffset
+ size
> dst
->Size
) {
1398 _mesa_error(ctx
, GL_INVALID_VALUE
,
1399 "glCopyBuffserSubData(writeOffset + size = %d)",
1405 if (readOffset
+ size
<= writeOffset
) {
1408 else if (writeOffset
+ size
<= readOffset
) {
1412 /* overlapping src/dst is illegal */
1413 _mesa_error(ctx
, GL_INVALID_VALUE
,
1414 "glCopyBuffserSubData(overlapping src/dst)");
1419 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
1424 * See GL_ARB_map_buffer_range spec
1427 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
1430 GET_CURRENT_CONTEXT(ctx
);
1431 struct gl_buffer_object
*bufObj
;
1432 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1434 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1435 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1436 "glMapBufferRange(extension not supported)");
1441 _mesa_error(ctx
, GL_INVALID_VALUE
,
1442 "glMapBufferRange(offset = %ld)", offset
);
1447 _mesa_error(ctx
, GL_INVALID_VALUE
,
1448 "glMapBufferRange(length = %ld)", length
);
1452 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
1453 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1454 "glMapBufferRange(access indicates neither read or write)");
1458 if (access
& GL_MAP_READ_BIT
) {
1459 if ((access
& GL_MAP_INVALIDATE_RANGE_BIT
) ||
1460 (access
& GL_MAP_INVALIDATE_BUFFER_BIT
) ||
1461 (access
& GL_MAP_UNSYNCHRONIZED_BIT
)) {
1462 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1463 "glMapBufferRange(invalid access flags)");
1468 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
1469 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
1470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1471 "glMapBufferRange(invalid access flags)");
1475 bufObj
= get_buffer(ctx
, target
);
1476 if (!bufObj
|| bufObj
->Name
== 0) {
1477 _mesa_error(ctx
, GL_INVALID_ENUM
,
1478 "glMapBufferRange(target = 0x%x)", target
);
1482 if (offset
+ length
> bufObj
->Size
) {
1483 _mesa_error(ctx
, GL_INVALID_VALUE
,
1484 "glMapBufferRange(offset + length > size)");
1488 if (bufObj
->Pointer
) {
1489 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1490 "glMapBufferRange(buffer already mapped)");
1494 ASSERT(ctx
->Driver
.MapBufferRange
);
1495 bufObj
->Pointer
= ctx
->Driver
.MapBufferRange(ctx
, target
, offset
, length
,
1498 bufObj
->Offset
= offset
;
1499 bufObj
->Length
= length
;
1500 bufObj
->AccessFlags
= access
;
1502 return bufObj
->Pointer
;
1507 * See GL_ARB_map_buffer_range spec
1510 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
1512 GET_CURRENT_CONTEXT(ctx
);
1513 struct gl_buffer_object
*bufObj
;
1514 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1516 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1518 "glMapBufferRange(extension not supported)");
1523 _mesa_error(ctx
, GL_INVALID_VALUE
,
1524 "glMapBufferRange(offset = %ld)", offset
);
1529 _mesa_error(ctx
, GL_INVALID_VALUE
,
1530 "glMapBufferRange(length = %ld)", length
);
1534 bufObj
= get_buffer(ctx
, target
);
1536 _mesa_error(ctx
, GL_INVALID_ENUM
,
1537 "glMapBufferRange(target = 0x%x)", target
);
1541 if (bufObj
->Name
== 0) {
1542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1543 "glMapBufferRange(current buffer is 0)");
1547 if (!bufObj
->Pointer
) {
1548 /* buffer is not mapped */
1549 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1550 "glMapBufferRange(buffer is not mapped)");
1554 if ((bufObj
->AccessFlags
& GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
1555 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1556 "glMapBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1560 if (offset
+ length
> bufObj
->Length
) {
1561 _mesa_error(ctx
, GL_INVALID_VALUE
,
1562 "glMapBufferRange(offset %ld + length %ld > mapped length %ld)",
1563 offset
, length
, bufObj
->Length
);
1567 ASSERT(bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
);
1569 if (ctx
->Driver
.FlushMappedBufferRange
)
1570 ctx
->Driver
.FlushMappedBufferRange(ctx
, target
, offset
, length
, bufObj
);