2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
40 #include "bufferobj.h"
44 #include "transformfeedback.h"
50 /*#define BOUNDS_CHECK*/
54 * Used as a placeholder for buffer objects between glGenBuffers() and
55 * glBindBuffer() so that glIsBuffer() can work correctly.
57 static struct gl_buffer_object DummyBufferObject
;
61 * Return pointer to address of a buffer object target.
62 * \param ctx the GL context
63 * \param target the buffer object target to be retrieved.
64 * \return pointer to pointer to the buffer object bound to \c target in the
65 * specified context or \c NULL if \c target is invalid.
67 static inline struct gl_buffer_object
**
68 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
70 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
72 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
73 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
77 case GL_ARRAY_BUFFER_ARB
:
78 return &ctx
->Array
.ArrayBufferObj
;
79 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
80 return &ctx
->Array
.ArrayObj
->ElementArrayBufferObj
;
81 case GL_PIXEL_PACK_BUFFER_EXT
:
82 return &ctx
->Pack
.BufferObj
;
83 case GL_PIXEL_UNPACK_BUFFER_EXT
:
84 return &ctx
->Unpack
.BufferObj
;
85 case GL_COPY_READ_BUFFER
:
86 return &ctx
->CopyReadBuffer
;
87 case GL_COPY_WRITE_BUFFER
:
88 return &ctx
->CopyWriteBuffer
;
89 case GL_TRANSFORM_FEEDBACK_BUFFER
:
90 if (ctx
->Extensions
.EXT_transform_feedback
) {
91 return &ctx
->TransformFeedback
.CurrentBuffer
;
94 case GL_TEXTURE_BUFFER
:
95 if (ctx
->API
== API_OPENGL_CORE
&&
96 ctx
->Extensions
.ARB_texture_buffer_object
) {
97 return &ctx
->Texture
.BufferObject
;
100 case GL_UNIFORM_BUFFER
:
101 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
102 return &ctx
->UniformBuffer
;
105 case GL_ATOMIC_COUNTER_BUFFER
:
106 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
107 return &ctx
->AtomicBuffer
;
118 * Get the buffer object bound to the specified target in a GL context.
119 * \param ctx the GL context
120 * \param target the buffer object target to be retrieved.
121 * \return pointer to the buffer object bound to \c target in the
122 * specified context or \c NULL if \c target is invalid.
124 static inline struct gl_buffer_object
*
125 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
)
127 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
130 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
134 if (!_mesa_is_bufferobj(*bufObj
)) {
135 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(buffer 0)", func
);
144 * Convert a GLbitfield describing the mapped buffer access flags
145 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
148 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
150 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
151 if ((access
& rwFlags
) == rwFlags
)
152 return GL_READ_WRITE
;
153 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
155 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
156 return GL_WRITE_ONLY
;
158 /* Otherwise, AccessFlags is zero (the default state).
160 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
162 * Name Type Initial Value Legal Values
164 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
167 * However, table 6.8 in the GL_OES_mapbuffer extension says:
169 * Get Value Type Get Command Value Description
170 * --------- ---- ----------- ----- -----------
171 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
173 * The difference is because GL_OES_mapbuffer only supports mapping buffers
178 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
183 * Tests the subdata range parameters and sets the GL error code for
184 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
186 * \param ctx GL context.
187 * \param target Buffer object target on which to operate.
188 * \param offset Offset of the first byte of the subdata range.
189 * \param size Size, in bytes, of the subdata range.
190 * \param caller Name of calling function for recording errors.
191 * \return A pointer to the buffer object bound to \c target in the
192 * specified context or \c NULL if any of the parameter or state
193 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
196 * \sa glBufferSubDataARB, glGetBufferSubDataARB
198 static struct gl_buffer_object
*
199 buffer_object_subdata_range_good( struct gl_context
* ctx
, GLenum target
,
200 GLintptrARB offset
, GLsizeiptrARB size
,
203 struct gl_buffer_object
*bufObj
;
206 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
211 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
215 bufObj
= get_buffer(ctx
, caller
, target
);
219 if (offset
+ size
> bufObj
->Size
) {
220 _mesa_error(ctx
, GL_INVALID_VALUE
,
221 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
222 (unsigned long) offset
,
223 (unsigned long) size
,
224 (unsigned long) bufObj
->Size
);
227 if (_mesa_bufferobj_mapped(bufObj
)) {
228 /* Buffer is currently mapped */
229 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
238 * Allocate and initialize a new buffer object.
240 * Default callback for the \c dd_function_table::NewBufferObject() hook.
242 static struct gl_buffer_object
*
243 _mesa_new_buffer_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
245 struct gl_buffer_object
*obj
;
249 obj
= MALLOC_STRUCT(gl_buffer_object
);
250 _mesa_initialize_buffer_object(ctx
, obj
, name
, target
);
256 * Delete a buffer object.
258 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
261 _mesa_delete_buffer_object(struct gl_context
*ctx
,
262 struct gl_buffer_object
*bufObj
)
268 /* assign strange values here to help w/ debugging */
269 bufObj
->RefCount
= -1000;
272 _glthread_DESTROY_MUTEX(bufObj
->Mutex
);
280 * Set ptr to bufObj w/ reference counting.
281 * This is normally only called from the _mesa_reference_buffer_object() macro
282 * when there's a real pointer change.
285 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
286 struct gl_buffer_object
**ptr
,
287 struct gl_buffer_object
*bufObj
)
290 /* Unreference the old buffer */
291 GLboolean deleteFlag
= GL_FALSE
;
292 struct gl_buffer_object
*oldObj
= *ptr
;
294 _glthread_LOCK_MUTEX(oldObj
->Mutex
);
295 ASSERT(oldObj
->RefCount
> 0);
298 printf("BufferObj %p %d DECR to %d\n",
299 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
301 deleteFlag
= (oldObj
->RefCount
== 0);
302 _glthread_UNLOCK_MUTEX(oldObj
->Mutex
);
306 /* some sanity checking: don't delete a buffer still in use */
308 /* unfortunately, these tests are invalid during context tear-down */
309 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
310 ASSERT(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
!= bufObj
);
311 ASSERT(ctx
->Array
.ArrayObj
->Vertex
.BufferObj
!= bufObj
);
314 ASSERT(ctx
->Driver
.DeleteBuffer
);
315 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
323 /* reference new buffer */
324 _glthread_LOCK_MUTEX(bufObj
->Mutex
);
325 if (bufObj
->RefCount
== 0) {
326 /* this buffer's being deleted (look just above) */
327 /* Not sure this can every really happen. Warn if it does. */
328 _mesa_problem(NULL
, "referencing deleted buffer object");
334 printf("BufferObj %p %d INCR to %d\n",
335 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
339 _glthread_UNLOCK_MUTEX(bufObj
->Mutex
);
345 * Initialize a buffer object to default values.
348 _mesa_initialize_buffer_object( struct gl_context
*ctx
,
349 struct gl_buffer_object
*obj
,
350 GLuint name
, GLenum target
)
354 memset(obj
, 0, sizeof(struct gl_buffer_object
));
355 _glthread_INIT_MUTEX(obj
->Mutex
);
358 obj
->Usage
= GL_STATIC_DRAW_ARB
;
359 obj
->AccessFlags
= 0;
365 * Callback called from _mesa_HashWalk()
368 count_buffer_size(GLuint key
, void *data
, void *userData
)
370 const struct gl_buffer_object
*bufObj
=
371 (const struct gl_buffer_object
*) data
;
372 GLuint
*total
= (GLuint
*) userData
;
374 *total
= *total
+ bufObj
->Size
;
379 * Compute total size (in bytes) of all buffer objects for the given context.
380 * For debugging purposes.
383 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
387 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
394 * Allocate space for and store data in a buffer object. Any data that was
395 * previously stored in the buffer object is lost. If \c data is \c NULL,
396 * memory will be allocated, but no copy will occur.
398 * This is the default callback for \c dd_function_table::BufferData()
399 * Note that all GL error checking will have been done already.
401 * \param ctx GL context.
402 * \param target Buffer object target on which to operate.
403 * \param size Size, in bytes, of the new data store.
404 * \param data Pointer to the data to store in the buffer object. This
405 * pointer may be \c NULL.
406 * \param usage Hints about how the data will be used.
407 * \param bufObj Object to be used.
409 * \return GL_TRUE for success, GL_FALSE for failure
410 * \sa glBufferDataARB, dd_function_table::BufferData.
413 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
414 const GLvoid
* data
, GLenum usage
,
415 struct gl_buffer_object
* bufObj
)
419 (void) ctx
; (void) target
;
421 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
423 bufObj
->Data
= (GLubyte
*) new_data
;
425 bufObj
->Usage
= usage
;
428 memcpy( bufObj
->Data
, data
, size
);
440 * Replace data in a subrange of buffer object. If the data range
441 * specified by \c size + \c offset extends beyond the end of the buffer or
442 * if \c data is \c NULL, no copy is performed.
444 * This is the default callback for \c dd_function_table::BufferSubData()
445 * Note that all GL error checking will have been done already.
447 * \param ctx GL context.
448 * \param offset Offset of the first byte to be modified.
449 * \param size Size, in bytes, of the data range.
450 * \param data Pointer to the data to store in the buffer object.
451 * \param bufObj Object to be used.
453 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
456 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
457 GLsizeiptrARB size
, const GLvoid
* data
,
458 struct gl_buffer_object
* bufObj
)
462 /* this should have been caught in _mesa_BufferSubData() */
463 ASSERT(size
+ offset
<= bufObj
->Size
);
466 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
472 * Retrieve data from a subrange of buffer object. If the data range
473 * specified by \c size + \c offset extends beyond the end of the buffer or
474 * if \c data is \c NULL, no copy is performed.
476 * This is the default callback for \c dd_function_table::GetBufferSubData()
477 * Note that all GL error checking will have been done already.
479 * \param ctx GL context.
480 * \param target Buffer object target on which to operate.
481 * \param offset Offset of the first byte to be fetched.
482 * \param size Size, in bytes, of the data range.
483 * \param data Destination for data
484 * \param bufObj Object to be used.
486 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
489 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
490 GLsizeiptrARB size
, GLvoid
* data
,
491 struct gl_buffer_object
* bufObj
)
495 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
496 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
502 * Default fallback for \c dd_function_table::MapBufferRange().
503 * Called via glMapBufferRange().
506 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
507 GLsizeiptr length
, GLbitfield access
,
508 struct gl_buffer_object
*bufObj
)
511 assert(!_mesa_bufferobj_mapped(bufObj
));
512 /* Just return a direct pointer to the data */
513 bufObj
->Pointer
= bufObj
->Data
+ offset
;
514 bufObj
->Length
= length
;
515 bufObj
->Offset
= offset
;
516 bufObj
->AccessFlags
= access
;
517 return bufObj
->Pointer
;
522 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
523 * Called via glFlushMappedBufferRange().
526 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
527 GLintptr offset
, GLsizeiptr length
,
528 struct gl_buffer_object
*obj
)
539 * Default callback for \c dd_function_table::MapBuffer().
541 * The input parameters will have been already tested for errors.
543 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
546 _mesa_buffer_unmap( struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
)
549 /* XXX we might assert here that bufObj->Pointer is non-null */
550 bufObj
->Pointer
= NULL
;
553 bufObj
->AccessFlags
= 0x0;
559 * Default fallback for \c dd_function_table::CopyBufferSubData().
560 * Called via glCopyBufferSubData().
563 _mesa_copy_buffer_subdata(struct gl_context
*ctx
,
564 struct gl_buffer_object
*src
,
565 struct gl_buffer_object
*dst
,
566 GLintptr readOffset
, GLintptr writeOffset
,
569 GLubyte
*srcPtr
, *dstPtr
;
571 /* the buffers should not be mapped */
572 assert(!_mesa_bufferobj_mapped(src
));
573 assert(!_mesa_bufferobj_mapped(dst
));
576 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
578 GL_MAP_WRITE_BIT
, src
);
583 srcPtr
+= readOffset
;
584 dstPtr
+= writeOffset
;
586 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
587 GL_MAP_READ_BIT
, src
);
588 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
590 GL_MAP_INVALIDATE_RANGE_BIT
), dst
);
593 /* Note: the src and dst regions will never overlap. Trying to do so
594 * would generate GL_INVALID_VALUE earlier.
596 if (srcPtr
&& dstPtr
)
597 memcpy(dstPtr
, srcPtr
, size
);
599 ctx
->Driver
.UnmapBuffer(ctx
, src
);
601 ctx
->Driver
.UnmapBuffer(ctx
, dst
);
607 * Initialize the state associated with buffer objects
610 _mesa_init_buffer_objects( struct gl_context
*ctx
)
614 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
615 _glthread_INIT_MUTEX(DummyBufferObject
.Mutex
);
616 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
618 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
619 ctx
->Shared
->NullBufferObj
);
621 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
622 ctx
->Shared
->NullBufferObj
);
623 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
624 ctx
->Shared
->NullBufferObj
);
626 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
627 ctx
->Shared
->NullBufferObj
);
629 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
630 _mesa_reference_buffer_object(ctx
,
631 &ctx
->UniformBufferBindings
[i
].BufferObject
,
632 ctx
->Shared
->NullBufferObj
);
633 ctx
->UniformBufferBindings
[i
].Offset
= -1;
634 ctx
->UniformBufferBindings
[i
].Size
= -1;
640 _mesa_free_buffer_objects( struct gl_context
*ctx
)
644 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
646 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
647 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
649 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
651 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
652 _mesa_reference_buffer_object(ctx
,
653 &ctx
->UniformBufferBindings
[i
].BufferObject
,
659 handle_bind_buffer_gen(struct gl_context
*ctx
,
662 struct gl_buffer_object
**buf_handle
)
664 struct gl_buffer_object
*buf
= *buf_handle
;
666 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
667 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindBuffer(non-gen name)");
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
);
689 * Bind the specified target to buffer for the specified context.
690 * Called by glBindBuffer() and other functions.
693 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
695 struct gl_buffer_object
*oldBufObj
;
696 struct gl_buffer_object
*newBufObj
= NULL
;
697 struct gl_buffer_object
**bindTarget
= NULL
;
699 bindTarget
= get_buffer_target(ctx
, target
);
701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
705 /* Get pointer to old buffer object (to be unbound) */
706 oldBufObj
= *bindTarget
;
707 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
708 return; /* rebinding the same buffer object- no change */
711 * Get pointer to new buffer object (newBufObj)
714 /* The spec says there's not a buffer object named 0, but we use
715 * one internally because it simplifies things.
717 newBufObj
= ctx
->Shared
->NullBufferObj
;
720 /* non-default buffer object */
721 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
722 if (!handle_bind_buffer_gen(ctx
, target
, buffer
, &newBufObj
))
726 /* bind new buffer */
727 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
729 /* Pass BindBuffer call to device driver */
730 if (ctx
->Driver
.BindBuffer
)
731 ctx
->Driver
.BindBuffer( ctx
, target
, newBufObj
);
736 * Update the default buffer objects in the given context to reference those
737 * specified in the shared state and release those referencing the old
741 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
743 /* Bind the NullBufferObj to remove references to those
744 * in the shared context hash table.
746 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
747 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
748 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
749 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
755 * Return the gl_buffer_object for the given ID.
756 * Always return NULL for ID 0.
758 struct gl_buffer_object
*
759 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
764 return (struct gl_buffer_object
*)
765 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
770 * If *ptr points to obj, set ptr = the Null/default buffer object.
771 * This is a helper for buffer object deletion.
772 * The GL spec says that deleting a buffer object causes it to get
773 * unbound from all arrays in the current context.
776 unbind(struct gl_context
*ctx
,
777 struct gl_buffer_object
**ptr
,
778 struct gl_buffer_object
*obj
)
781 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
787 * Plug default/fallback buffer object functions into the device
791 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
793 /* GL_ARB_vertex/pixel_buffer_object */
794 driver
->NewBufferObject
= _mesa_new_buffer_object
;
795 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
796 driver
->BindBuffer
= NULL
;
797 driver
->BufferData
= _mesa_buffer_data
;
798 driver
->BufferSubData
= _mesa_buffer_subdata
;
799 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
800 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
802 /* GL_ARB_map_buffer_range */
803 driver
->MapBufferRange
= _mesa_buffer_map_range
;
804 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
806 /* GL_ARB_copy_buffer */
807 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
812 /**********************************************************************/
814 /**********************************************************************/
817 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
819 GET_CURRENT_CONTEXT(ctx
);
821 if (MESA_VERBOSE
& VERBOSE_API
)
822 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
823 _mesa_lookup_enum_by_nr(target
), buffer
);
825 bind_buffer_object(ctx
, target
, buffer
);
830 * Delete a set of buffer objects.
832 * \param n Number of buffer objects to delete.
833 * \param ids Array of \c n buffer object IDs.
836 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
838 GET_CURRENT_CONTEXT(ctx
);
840 FLUSH_VERTICES(ctx
, 0);
843 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
847 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
849 for (i
= 0; i
< n
; i
++) {
850 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
852 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
855 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
857 if (_mesa_bufferobj_mapped(bufObj
)) {
858 /* if mapped, unmap it now */
859 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
860 bufObj
->AccessFlags
= 0;
861 bufObj
->Pointer
= NULL
;
864 /* unbind any vertex pointers bound to this buffer */
865 for (j
= 0; j
< Elements(arrayObj
->_VertexAttrib
); j
++) {
866 unbind(ctx
, &arrayObj
->_VertexAttrib
[j
].BufferObj
, bufObj
);
869 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
870 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
872 if (arrayObj
->ElementArrayBufferObj
== bufObj
) {
873 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
876 /* unbind ARB_copy_buffer binding points */
877 if (ctx
->CopyReadBuffer
== bufObj
) {
878 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
880 if (ctx
->CopyWriteBuffer
== bufObj
) {
881 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
884 /* unbind transform feedback binding points */
885 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
886 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
888 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
889 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
890 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
894 /* unbind UBO binding points */
895 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
896 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
897 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
901 if (ctx
->UniformBuffer
== bufObj
) {
902 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
905 /* unbind any pixel pack/unpack pointers bound to this buffer */
906 if (ctx
->Pack
.BufferObj
== bufObj
) {
907 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
909 if (ctx
->Unpack
.BufferObj
== bufObj
) {
910 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
913 if (ctx
->Texture
.BufferObject
== bufObj
) {
914 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
917 /* The ID is immediately freed for re-use */
918 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
919 /* Make sure we do not run into the classic ABA problem on bind.
920 * We don't want to allow re-binding a buffer object that's been
921 * "deleted" by glDeleteBuffers().
923 * The explicit rebinding to the default object in the current context
924 * prevents the above in the current context, but another context
925 * sharing the same objects might suffer from this problem.
926 * The alternative would be to do the hash lookup in any case on bind
927 * which would introduce more runtime overhead than this.
929 bufObj
->DeletePending
= GL_TRUE
;
930 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
934 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
939 * Generate a set of unique buffer object IDs and store them in \c buffer.
941 * \param n Number of IDs to generate.
942 * \param buffer Array of \c n locations to store the IDs.
945 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
947 GET_CURRENT_CONTEXT(ctx
);
951 if (MESA_VERBOSE
& VERBOSE_API
)
952 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
955 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
964 * This must be atomic (generation and allocation of buffer object IDs)
966 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
968 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
970 /* Insert the ID and pointer to dummy buffer object into hash table */
971 for (i
= 0; i
< n
; i
++) {
972 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
974 buffer
[i
] = first
+ i
;
977 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
982 * Determine if ID is the name of a buffer object.
984 * \param id ID of the potential buffer object.
985 * \return \c GL_TRUE if \c id is the name of a buffer object,
986 * \c GL_FALSE otherwise.
989 _mesa_IsBuffer(GLuint id
)
991 struct gl_buffer_object
*bufObj
;
992 GET_CURRENT_CONTEXT(ctx
);
993 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
995 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
996 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
997 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
999 return bufObj
&& bufObj
!= &DummyBufferObject
;
1004 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1005 const GLvoid
* data
, GLenum usage
)
1007 GET_CURRENT_CONTEXT(ctx
);
1008 struct gl_buffer_object
*bufObj
;
1011 if (MESA_VERBOSE
& VERBOSE_API
)
1012 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1013 _mesa_lookup_enum_by_nr(target
),
1014 (long int) size
, data
,
1015 _mesa_lookup_enum_by_nr(usage
));
1018 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1023 case GL_STREAM_DRAW_ARB
:
1024 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1027 case GL_STATIC_DRAW_ARB
:
1028 case GL_DYNAMIC_DRAW_ARB
:
1032 case GL_STREAM_READ_ARB
:
1033 case GL_STREAM_COPY_ARB
:
1034 case GL_STATIC_READ_ARB
:
1035 case GL_STATIC_COPY_ARB
:
1036 case GL_DYNAMIC_READ_ARB
:
1037 case GL_DYNAMIC_COPY_ARB
:
1038 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1042 valid_usage
= false;
1047 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1051 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
);
1055 if (_mesa_bufferobj_mapped(bufObj
)) {
1056 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1057 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
);
1058 bufObj
->AccessFlags
= 0;
1059 ASSERT(bufObj
->Pointer
== NULL
);
1062 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1064 bufObj
->Written
= GL_TRUE
;
1067 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1068 bufObj
->Name
, size
, data
, usage
);
1075 ASSERT(ctx
->Driver
.BufferData
);
1076 if (!ctx
->Driver
.BufferData( ctx
, target
, size
, data
, usage
, bufObj
)) {
1077 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
1083 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1084 GLsizeiptrARB size
, const GLvoid
* data
)
1086 GET_CURRENT_CONTEXT(ctx
);
1087 struct gl_buffer_object
*bufObj
;
1089 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1090 "glBufferSubDataARB" );
1092 /* error already recorded */
1099 bufObj
->Written
= GL_TRUE
;
1101 ASSERT(ctx
->Driver
.BufferSubData
);
1102 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1107 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1108 GLsizeiptrARB size
, void * data
)
1110 GET_CURRENT_CONTEXT(ctx
);
1111 struct gl_buffer_object
*bufObj
;
1113 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1114 "glGetBufferSubDataARB" );
1116 /* error already recorded */
1120 ASSERT(ctx
->Driver
.GetBufferSubData
);
1121 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1126 _mesa_MapBuffer(GLenum target
, GLenum access
)
1128 GET_CURRENT_CONTEXT(ctx
);
1129 struct gl_buffer_object
* bufObj
;
1130 GLbitfield accessFlags
;
1134 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1137 case GL_READ_ONLY_ARB
:
1138 accessFlags
= GL_MAP_READ_BIT
;
1139 valid_access
= _mesa_is_desktop_gl(ctx
);
1141 case GL_WRITE_ONLY_ARB
:
1142 accessFlags
= GL_MAP_WRITE_BIT
;
1143 valid_access
= true;
1145 case GL_READ_WRITE_ARB
:
1146 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1147 valid_access
= _mesa_is_desktop_gl(ctx
);
1150 valid_access
= false;
1154 if (!valid_access
) {
1155 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1159 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
);
1163 if (_mesa_bufferobj_mapped(bufObj
)) {
1164 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1168 if (!bufObj
->Size
) {
1169 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1170 "glMapBuffer(buffer size = 0)");
1174 ASSERT(ctx
->Driver
.MapBufferRange
);
1175 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
);
1177 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1181 /* The driver callback should have set these fields.
1182 * This is important because other modules (like VBO) might call
1183 * the driver function directly.
1185 ASSERT(bufObj
->Pointer
== map
);
1186 ASSERT(bufObj
->Length
== bufObj
->Size
);
1187 ASSERT(bufObj
->Offset
== 0);
1188 bufObj
->AccessFlags
= accessFlags
;
1191 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1192 bufObj
->Written
= GL_TRUE
;
1195 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1196 bufObj
->Name
, bufObj
->Size
, access
);
1197 if (access
== GL_WRITE_ONLY_ARB
) {
1199 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1200 for (i
= 0; i
< bufObj
->Size
; i
++)
1207 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1209 /* buffer is 100 bytes larger than requested, fill with magic value */
1210 for (i
= 0; i
< 100; i
++) {
1211 buf
[bufObj
->Size
- i
- 1] = 123;
1216 return bufObj
->Pointer
;
1220 GLboolean GLAPIENTRY
1221 _mesa_UnmapBuffer(GLenum target
)
1223 GET_CURRENT_CONTEXT(ctx
);
1224 struct gl_buffer_object
*bufObj
;
1225 GLboolean status
= GL_TRUE
;
1226 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1228 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
);
1232 if (!_mesa_bufferobj_mapped(bufObj
)) {
1233 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1238 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1239 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1241 /* check that last 100 bytes are still = magic value */
1242 for (i
= 0; i
< 100; i
++) {
1243 GLuint pos
= bufObj
->Size
- i
- 1;
1244 if (buf
[pos
] != 123) {
1245 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1246 " at position %d (value = %u)\n",
1254 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1255 GLuint i
, unchanged
= 0;
1256 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1258 /* check which bytes changed */
1259 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1260 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1267 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1268 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1273 status
= ctx
->Driver
.UnmapBuffer( ctx
, bufObj
);
1274 bufObj
->AccessFlags
= 0;
1275 ASSERT(bufObj
->Pointer
== NULL
);
1276 ASSERT(bufObj
->Offset
== 0);
1277 ASSERT(bufObj
->Length
== 0);
1284 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1286 GET_CURRENT_CONTEXT(ctx
);
1287 struct gl_buffer_object
*bufObj
;
1289 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
);
1294 case GL_BUFFER_SIZE_ARB
:
1295 *params
= (GLint
) bufObj
->Size
;
1297 case GL_BUFFER_USAGE_ARB
:
1298 *params
= bufObj
->Usage
;
1300 case GL_BUFFER_ACCESS_ARB
:
1301 *params
= simplified_access_mode(ctx
, bufObj
->AccessFlags
);
1303 case GL_BUFFER_MAPPED_ARB
:
1304 *params
= _mesa_bufferobj_mapped(bufObj
);
1306 case GL_BUFFER_ACCESS_FLAGS
:
1307 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1309 *params
= bufObj
->AccessFlags
;
1311 case GL_BUFFER_MAP_OFFSET
:
1312 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1314 *params
= (GLint
) bufObj
->Offset
;
1316 case GL_BUFFER_MAP_LENGTH
:
1317 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1319 *params
= (GLint
) bufObj
->Length
;
1322 ; /* fall-through */
1326 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1327 _mesa_lookup_enum_by_nr(pname
));
1333 * This is pretty much a duplicate of GetBufferParameteriv() but the
1334 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1337 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1339 GET_CURRENT_CONTEXT(ctx
);
1340 struct gl_buffer_object
*bufObj
;
1342 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
);
1347 case GL_BUFFER_SIZE_ARB
:
1348 *params
= bufObj
->Size
;
1350 case GL_BUFFER_USAGE_ARB
:
1351 *params
= bufObj
->Usage
;
1353 case GL_BUFFER_ACCESS_ARB
:
1354 *params
= simplified_access_mode(ctx
, bufObj
->AccessFlags
);
1356 case GL_BUFFER_ACCESS_FLAGS
:
1357 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1359 *params
= bufObj
->AccessFlags
;
1361 case GL_BUFFER_MAPPED_ARB
:
1362 *params
= _mesa_bufferobj_mapped(bufObj
);
1364 case GL_BUFFER_MAP_OFFSET
:
1365 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1367 *params
= bufObj
->Offset
;
1369 case GL_BUFFER_MAP_LENGTH
:
1370 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1372 *params
= bufObj
->Length
;
1375 ; /* fall-through */
1379 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1380 _mesa_lookup_enum_by_nr(pname
));
1385 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1387 GET_CURRENT_CONTEXT(ctx
);
1388 struct gl_buffer_object
* bufObj
;
1390 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1391 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1395 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
);
1399 *params
= bufObj
->Pointer
;
1404 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1405 GLintptr readOffset
, GLintptr writeOffset
,
1408 GET_CURRENT_CONTEXT(ctx
);
1409 struct gl_buffer_object
*src
, *dst
;
1411 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
);
1415 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
);
1419 if (_mesa_bufferobj_mapped(src
)) {
1420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1421 "glCopyBufferSubData(readBuffer is mapped)");
1425 if (_mesa_bufferobj_mapped(dst
)) {
1426 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1427 "glCopyBufferSubData(writeBuffer is mapped)");
1431 if (readOffset
< 0) {
1432 _mesa_error(ctx
, GL_INVALID_VALUE
,
1433 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
1437 if (writeOffset
< 0) {
1438 _mesa_error(ctx
, GL_INVALID_VALUE
,
1439 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
1444 _mesa_error(ctx
, GL_INVALID_VALUE
,
1445 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
1449 if (readOffset
+ size
> src
->Size
) {
1450 _mesa_error(ctx
, GL_INVALID_VALUE
,
1451 "glCopyBufferSubData(readOffset + size = %d)",
1452 (int) (readOffset
+ size
));
1456 if (writeOffset
+ size
> dst
->Size
) {
1457 _mesa_error(ctx
, GL_INVALID_VALUE
,
1458 "glCopyBufferSubData(writeOffset + size = %d)",
1459 (int) (writeOffset
+ size
));
1464 if (readOffset
+ size
<= writeOffset
) {
1467 else if (writeOffset
+ size
<= readOffset
) {
1471 /* overlapping src/dst is illegal */
1472 _mesa_error(ctx
, GL_INVALID_VALUE
,
1473 "glCopyBufferSubData(overlapping src/dst)");
1478 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
1483 * See GL_ARB_map_buffer_range spec
1486 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
1489 GET_CURRENT_CONTEXT(ctx
);
1490 struct gl_buffer_object
*bufObj
;
1493 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1495 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1496 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1497 "glMapBufferRange(extension not supported)");
1502 _mesa_error(ctx
, GL_INVALID_VALUE
,
1503 "glMapBufferRange(offset = %ld)", (long)offset
);
1508 _mesa_error(ctx
, GL_INVALID_VALUE
,
1509 "glMapBufferRange(length = %ld)", (long)length
);
1513 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
1515 * "An INVALID_OPERATION error is generated for any of the following
1518 * * <length> is zero."
1520 if (_mesa_is_gles(ctx
) && length
== 0) {
1521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1522 "glMapBufferRange(length = 0)");
1526 if (access
& ~(GL_MAP_READ_BIT
|
1528 GL_MAP_INVALIDATE_RANGE_BIT
|
1529 GL_MAP_INVALIDATE_BUFFER_BIT
|
1530 GL_MAP_FLUSH_EXPLICIT_BIT
|
1531 GL_MAP_UNSYNCHRONIZED_BIT
)) {
1532 /* generate an error if any undefind bit is set */
1533 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
1537 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
1538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1539 "glMapBufferRange(access indicates neither read or write)");
1543 if ((access
& GL_MAP_READ_BIT
) &&
1544 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
1545 GL_MAP_INVALIDATE_BUFFER_BIT
|
1546 GL_MAP_UNSYNCHRONIZED_BIT
))) {
1547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1548 "glMapBufferRange(invalid access flags)");
1552 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
1553 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
1554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1555 "glMapBufferRange(invalid access flags)");
1559 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
);
1563 if (offset
+ length
> bufObj
->Size
) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
,
1565 "glMapBufferRange(offset + length > size)");
1569 if (_mesa_bufferobj_mapped(bufObj
)) {
1570 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1571 "glMapBufferRange(buffer already mapped)");
1575 if (!bufObj
->Size
) {
1576 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1577 "glMapBufferRange(buffer size = 0)");
1581 /* Mapping zero bytes should return a non-null pointer. */
1583 static long dummy
= 0;
1584 bufObj
->Pointer
= &dummy
;
1585 bufObj
->Length
= length
;
1586 bufObj
->Offset
= offset
;
1587 bufObj
->AccessFlags
= access
;
1588 return bufObj
->Pointer
;
1591 ASSERT(ctx
->Driver
.MapBufferRange
);
1592 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
);
1594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1597 /* The driver callback should have set all these fields.
1598 * This is important because other modules (like VBO) might call
1599 * the driver function directly.
1601 ASSERT(bufObj
->Pointer
== map
);
1602 ASSERT(bufObj
->Length
== length
);
1603 ASSERT(bufObj
->Offset
== offset
);
1604 ASSERT(bufObj
->AccessFlags
== access
);
1612 * See GL_ARB_map_buffer_range spec
1615 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
1617 GET_CURRENT_CONTEXT(ctx
);
1618 struct gl_buffer_object
*bufObj
;
1620 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
1621 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1622 "glFlushMappedBufferRange(extension not supported)");
1627 _mesa_error(ctx
, GL_INVALID_VALUE
,
1628 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
1633 _mesa_error(ctx
, GL_INVALID_VALUE
,
1634 "glFlushMappedBufferRange(length = %ld)", (long)length
);
1638 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
);
1642 if (!_mesa_bufferobj_mapped(bufObj
)) {
1643 /* buffer is not mapped */
1644 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1645 "glFlushMappedBufferRange(buffer is not mapped)");
1649 if ((bufObj
->AccessFlags
& GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
1650 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1651 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
1655 if (offset
+ length
> bufObj
->Length
) {
1656 _mesa_error(ctx
, GL_INVALID_VALUE
,
1657 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
1658 (long)offset
, (long)length
, (long)bufObj
->Length
);
1662 ASSERT(bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
);
1664 if (ctx
->Driver
.FlushMappedBufferRange
)
1665 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
);
1670 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1672 struct gl_buffer_object
*bufObj
;
1675 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1677 _mesa_error(ctx
, GL_INVALID_VALUE
,
1678 "glObjectPurgeable(name = 0x%x)", name
);
1681 if (!_mesa_is_bufferobj(bufObj
)) {
1682 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
1686 if (bufObj
->Purgeable
) {
1687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1688 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1689 return GL_VOLATILE_APPLE
;
1692 bufObj
->Purgeable
= GL_TRUE
;
1694 retval
= GL_VOLATILE_APPLE
;
1695 if (ctx
->Driver
.BufferObjectPurgeable
)
1696 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
1703 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1705 struct gl_renderbuffer
*bufObj
;
1708 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1710 _mesa_error(ctx
, GL_INVALID_VALUE
,
1711 "glObjectUnpurgeable(name = 0x%x)", name
);
1715 if (bufObj
->Purgeable
) {
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1718 return GL_VOLATILE_APPLE
;
1721 bufObj
->Purgeable
= GL_TRUE
;
1723 retval
= GL_VOLATILE_APPLE
;
1724 if (ctx
->Driver
.RenderObjectPurgeable
)
1725 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
1732 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1734 struct gl_texture_object
*bufObj
;
1737 bufObj
= _mesa_lookup_texture(ctx
, name
);
1739 _mesa_error(ctx
, GL_INVALID_VALUE
,
1740 "glObjectPurgeable(name = 0x%x)", name
);
1744 if (bufObj
->Purgeable
) {
1745 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1746 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
1747 return GL_VOLATILE_APPLE
;
1750 bufObj
->Purgeable
= GL_TRUE
;
1752 retval
= GL_VOLATILE_APPLE
;
1753 if (ctx
->Driver
.TextureObjectPurgeable
)
1754 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
1761 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1765 GET_CURRENT_CONTEXT(ctx
);
1766 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1769 _mesa_error(ctx
, GL_INVALID_VALUE
,
1770 "glObjectPurgeable(name = 0x%x)", name
);
1775 case GL_VOLATILE_APPLE
:
1776 case GL_RELEASED_APPLE
:
1780 _mesa_error(ctx
, GL_INVALID_ENUM
,
1781 "glObjectPurgeable(name = 0x%x) invalid option: %d",
1786 switch (objectType
) {
1788 retval
= texture_object_purgeable(ctx
, name
, option
);
1790 case GL_RENDERBUFFER_EXT
:
1791 retval
= renderbuffer_purgeable(ctx
, name
, option
);
1793 case GL_BUFFER_OBJECT_APPLE
:
1794 retval
= buffer_object_purgeable(ctx
, name
, option
);
1797 _mesa_error(ctx
, GL_INVALID_ENUM
,
1798 "glObjectPurgeable(name = 0x%x) invalid type: %d",
1803 /* In strict conformance to the spec, we must only return VOLATILE when
1804 * when passed the VOLATILE option. Madness.
1806 * XXX First fix the spec, then fix me.
1808 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
1813 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1815 struct gl_buffer_object
*bufObj
;
1818 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1820 _mesa_error(ctx
, GL_INVALID_VALUE
,
1821 "glObjectUnpurgeable(name = 0x%x)", name
);
1825 if (! bufObj
->Purgeable
) {
1826 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1827 "glObjectUnpurgeable(name = 0x%x) object is "
1828 " already \"unpurged\"", name
);
1832 bufObj
->Purgeable
= GL_FALSE
;
1835 if (ctx
->Driver
.BufferObjectUnpurgeable
)
1836 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
1843 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1845 struct gl_renderbuffer
*bufObj
;
1848 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
1850 _mesa_error(ctx
, GL_INVALID_VALUE
,
1851 "glObjectUnpurgeable(name = 0x%x)", name
);
1855 if (! bufObj
->Purgeable
) {
1856 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1857 "glObjectUnpurgeable(name = 0x%x) object is "
1858 " already \"unpurged\"", name
);
1862 bufObj
->Purgeable
= GL_FALSE
;
1865 if (ctx
->Driver
.RenderObjectUnpurgeable
)
1866 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
1873 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
1875 struct gl_texture_object
*bufObj
;
1878 bufObj
= _mesa_lookup_texture(ctx
, name
);
1880 _mesa_error(ctx
, GL_INVALID_VALUE
,
1881 "glObjectUnpurgeable(name = 0x%x)", name
);
1885 if (! bufObj
->Purgeable
) {
1886 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1887 "glObjectUnpurgeable(name = 0x%x) object is"
1888 " already \"unpurged\"", name
);
1892 bufObj
->Purgeable
= GL_FALSE
;
1895 if (ctx
->Driver
.TextureObjectUnpurgeable
)
1896 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
1903 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
1905 GET_CURRENT_CONTEXT(ctx
);
1906 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1909 _mesa_error(ctx
, GL_INVALID_VALUE
,
1910 "glObjectUnpurgeable(name = 0x%x)", name
);
1915 case GL_RETAINED_APPLE
:
1916 case GL_UNDEFINED_APPLE
:
1920 _mesa_error(ctx
, GL_INVALID_ENUM
,
1921 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
1926 switch (objectType
) {
1927 case GL_BUFFER_OBJECT_APPLE
:
1928 return buffer_object_unpurgeable(ctx
, name
, option
);
1930 return texture_object_unpurgeable(ctx
, name
, option
);
1931 case GL_RENDERBUFFER_EXT
:
1932 return renderbuffer_unpurgeable(ctx
, name
, option
);
1934 _mesa_error(ctx
, GL_INVALID_ENUM
,
1935 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
1943 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1944 GLenum pname
, GLint
*params
)
1946 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
1948 _mesa_error(ctx
, GL_INVALID_VALUE
,
1949 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
1954 case GL_PURGEABLE_APPLE
:
1955 *params
= bufObj
->Purgeable
;
1958 _mesa_error(ctx
, GL_INVALID_ENUM
,
1959 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1967 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
1968 GLenum pname
, GLint
*params
)
1970 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
1972 _mesa_error(ctx
, GL_INVALID_VALUE
,
1973 "glObjectUnpurgeable(name = 0x%x)", name
);
1978 case GL_PURGEABLE_APPLE
:
1979 *params
= rb
->Purgeable
;
1982 _mesa_error(ctx
, GL_INVALID_ENUM
,
1983 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
1991 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
1992 GLenum pname
, GLint
*params
)
1994 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glObjectUnpurgeable(name = 0x%x)", name
);
2002 case GL_PURGEABLE_APPLE
:
2003 *params
= texObj
->Purgeable
;
2006 _mesa_error(ctx
, GL_INVALID_ENUM
,
2007 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2015 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2018 GET_CURRENT_CONTEXT(ctx
);
2021 _mesa_error(ctx
, GL_INVALID_VALUE
,
2022 "glGetObjectParameteriv(name = 0x%x)", name
);
2026 switch (objectType
) {
2028 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2030 case GL_BUFFER_OBJECT_APPLE
:
2031 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2033 case GL_RENDERBUFFER_EXT
:
2034 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2037 _mesa_error(ctx
, GL_INVALID_ENUM
,
2038 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2044 set_ubo_binding(struct gl_context
*ctx
,
2046 struct gl_buffer_object
*bufObj
,
2051 struct gl_uniform_buffer_binding
*binding
;
2053 binding
= &ctx
->UniformBufferBindings
[index
];
2054 if (binding
->BufferObject
== bufObj
&&
2055 binding
->Offset
== offset
&&
2056 binding
->Size
== size
&&
2057 binding
->AutomaticSize
== autoSize
) {
2061 FLUSH_VERTICES(ctx
, 0);
2062 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2064 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2065 binding
->Offset
= offset
;
2066 binding
->Size
= size
;
2067 binding
->AutomaticSize
= autoSize
;
2071 * Bind a region of a buffer object to a uniform block binding point.
2072 * \param index the uniform buffer binding point index
2073 * \param bufObj the buffer object
2074 * \param offset offset to the start of buffer object region
2075 * \param size size of the buffer object region
2078 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2080 struct gl_buffer_object
*bufObj
,
2084 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2085 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2089 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2090 _mesa_error(ctx
, GL_INVALID_VALUE
,
2091 "glBindBufferRange(offset misalgned %d/%d)", (int) offset
,
2092 ctx
->Const
.UniformBufferOffsetAlignment
);
2096 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2101 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2102 set_ubo_binding(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2107 * Bind a buffer object to a uniform block binding point.
2108 * As above, but offset = 0.
2111 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2113 struct gl_buffer_object
*bufObj
)
2115 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2116 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2120 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2121 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2122 set_ubo_binding(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2124 set_ubo_binding(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2128 set_atomic_buffer_binding(struct gl_context
*ctx
,
2130 struct gl_buffer_object
*bufObj
,
2135 struct gl_atomic_buffer_binding
*binding
;
2137 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2138 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2142 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2143 _mesa_error(ctx
, GL_INVALID_VALUE
,
2144 "%s(offset misalgned %d/%d)", name
, (int) offset
,
2145 ATOMIC_COUNTER_SIZE
);
2149 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2151 binding
= &ctx
->AtomicBufferBindings
[index
];
2152 if (binding
->BufferObject
== bufObj
&&
2153 binding
->Offset
== offset
&&
2154 binding
->Size
== size
) {
2158 FLUSH_VERTICES(ctx
, 0);
2159 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2161 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2163 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2164 binding
->Offset
= -1;
2167 binding
->Offset
= offset
;
2168 binding
->Size
= size
;
2173 _mesa_BindBufferRange(GLenum target
, GLuint index
,
2174 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
2176 GET_CURRENT_CONTEXT(ctx
);
2177 struct gl_buffer_object
*bufObj
;
2180 bufObj
= ctx
->Shared
->NullBufferObj
;
2182 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2184 if (!handle_bind_buffer_gen(ctx
, target
, buffer
, &bufObj
))
2188 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2189 "glBindBufferRange(invalid buffer=%u)", buffer
);
2195 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
2202 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2203 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
2206 case GL_UNIFORM_BUFFER
:
2207 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
2209 case GL_ATOMIC_COUNTER_BUFFER
:
2210 set_atomic_buffer_binding(ctx
, index
, bufObj
, offset
, size
,
2211 "glBindBufferRange");
2214 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
2220 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
2222 GET_CURRENT_CONTEXT(ctx
);
2223 struct gl_buffer_object
*bufObj
;
2226 bufObj
= ctx
->Shared
->NullBufferObj
;
2228 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2230 if (!handle_bind_buffer_gen(ctx
, target
, buffer
, &bufObj
))
2234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2235 "glBindBufferBase(invalid buffer=%u)", buffer
);
2239 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
2240 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
2242 * "BindBufferBase is equivalent to calling BindBufferRange with offset
2243 * zero and size equal to the size of buffer."
2245 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
2247 * "If the parameter (starting offset or size) was not specified when the
2248 * buffer object was bound, zero is returned."
2250 * What happens if the size of the buffer changes? Does the size of the
2251 * buffer at the moment glBindBufferBase was called still play a role, like
2252 * the first quote would imply, or is the size meaningless in the
2253 * glBindBufferBase case like the second quote would suggest? The GL 4.1
2254 * core spec page 45 says:
2256 * "It is equivalent to calling BindBufferRange with offset zero, while
2257 * size is determined by the size of the bound buffer at the time the
2260 * My interpretation is that the GL 4.1 spec was a clarification of the
2261 * behavior, not a change. In particular, this choice will only make
2262 * rendering work in cases where it would have had undefined results.
2266 case GL_TRANSFORM_FEEDBACK_BUFFER
:
2267 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
2269 case GL_UNIFORM_BUFFER
:
2270 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
2272 case GL_ATOMIC_COUNTER_BUFFER
:
2273 set_atomic_buffer_binding(ctx
, index
, bufObj
, 0, 0,
2274 "glBindBufferBase");
2277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
2283 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
2286 GET_CURRENT_CONTEXT(ctx
);
2287 struct gl_buffer_object
*bufObj
;
2288 const GLintptr end
= offset
+ length
;
2290 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2292 _mesa_error(ctx
, GL_INVALID_VALUE
,
2293 "glInvalidateBufferSubData(name = 0x%x) invalid object",
2298 /* The GL_ARB_invalidate_subdata spec says:
2300 * "An INVALID_VALUE error is generated if <offset> or <length> is
2301 * negative, or if <offset> + <length> is greater than the value of
2304 if (end
< 0 || end
> bufObj
->Size
) {
2305 _mesa_error(ctx
, GL_INVALID_VALUE
,
2306 "glInvalidateBufferSubData(invalid offset or length)");
2310 /* The GL_ARB_invalidate_subdata spec says:
2312 * "An INVALID_OPERATION error is generated if the buffer is currently
2313 * mapped by MapBuffer, or if the invalidate range intersects the range
2314 * currently mapped by MapBufferRange."
2316 if (_mesa_bufferobj_mapped(bufObj
)) {
2317 const GLintptr mapEnd
= bufObj
->Offset
+ bufObj
->Length
;
2319 /* The regions do not overlap if and only if the end of the discard
2320 * region is before the mapped region or the start of the discard region
2321 * is after the mapped region.
2323 * Note that 'end' and 'mapEnd' are the first byte *after* the discard
2324 * region and the mapped region, repsectively. It is okay for that byte
2325 * to be mapped (for 'end') or discarded (for 'mapEnd').
2327 if (!(end
<= bufObj
->Offset
|| offset
>= mapEnd
)) {
2328 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2329 "glInvalidateBufferSubData(intersection with mapped "
2335 /* We don't actually do anything for this yet. Just return after
2336 * validating the parameters and generating the required errors.
2342 _mesa_InvalidateBufferData(GLuint buffer
)
2344 GET_CURRENT_CONTEXT(ctx
);
2345 struct gl_buffer_object
*bufObj
;
2347 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2349 _mesa_error(ctx
, GL_INVALID_VALUE
,
2350 "glInvalidateBufferData(name = 0x%x) invalid object",
2355 /* The GL_ARB_invalidate_subdata spec says:
2357 * "An INVALID_OPERATION error is generated if the buffer is currently
2358 * mapped by MapBuffer, or if the invalidate range intersects the range
2359 * currently mapped by MapBufferRange."
2361 if (_mesa_bufferobj_mapped(bufObj
)) {
2362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2363 "glInvalidateBufferData(intersection with mapped "
2368 /* We don't actually do anything for this yet. Just return after
2369 * validating the parameters and generating the required errors.