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
34 #include <inttypes.h> /* for PRId64 macro */
41 #include "bufferobj.h"
46 #include "glformats.h"
48 #include "transformfeedback.h"
54 /*#define BOUNDS_CHECK*/
58 * Used as a placeholder for buffer objects between glGenBuffers() and
59 * glBindBuffer() so that glIsBuffer() can work correctly.
61 static struct gl_buffer_object DummyBufferObject
;
65 * Return pointer to address of a buffer object target.
66 * \param ctx the GL context
67 * \param target the buffer object target to be retrieved.
68 * \return pointer to pointer to the buffer object bound to \c target in the
69 * specified context or \c NULL if \c target is invalid.
71 static inline struct gl_buffer_object
**
72 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
74 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
76 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
77 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
81 case GL_ARRAY_BUFFER_ARB
:
82 return &ctx
->Array
.ArrayBufferObj
;
83 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
84 return &ctx
->Array
.VAO
->IndexBufferObj
;
85 case GL_PIXEL_PACK_BUFFER_EXT
:
86 return &ctx
->Pack
.BufferObj
;
87 case GL_PIXEL_UNPACK_BUFFER_EXT
:
88 return &ctx
->Unpack
.BufferObj
;
89 case GL_COPY_READ_BUFFER
:
90 return &ctx
->CopyReadBuffer
;
91 case GL_COPY_WRITE_BUFFER
:
92 return &ctx
->CopyWriteBuffer
;
93 case GL_DRAW_INDIRECT_BUFFER
:
94 if (ctx
->API
== API_OPENGL_CORE
&&
95 ctx
->Extensions
.ARB_draw_indirect
) {
96 return &ctx
->DrawIndirectBuffer
;
99 case GL_TRANSFORM_FEEDBACK_BUFFER
:
100 if (ctx
->Extensions
.EXT_transform_feedback
) {
101 return &ctx
->TransformFeedback
.CurrentBuffer
;
104 case GL_TEXTURE_BUFFER
:
105 if (ctx
->API
== API_OPENGL_CORE
&&
106 ctx
->Extensions
.ARB_texture_buffer_object
) {
107 return &ctx
->Texture
.BufferObject
;
110 case GL_UNIFORM_BUFFER
:
111 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
112 return &ctx
->UniformBuffer
;
115 case GL_ATOMIC_COUNTER_BUFFER
:
116 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
117 return &ctx
->AtomicBuffer
;
128 * Get the buffer object bound to the specified target in a GL context.
129 * \param ctx the GL context
130 * \param target the buffer object target to be retrieved.
131 * \param error the GL error to record if target is illegal.
132 * \return pointer to the buffer object bound to \c target in the
133 * specified context or \c NULL if \c target is invalid.
135 static inline struct gl_buffer_object
*
136 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
139 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
142 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
146 if (!_mesa_is_bufferobj(*bufObj
)) {
147 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
156 * Convert a GLbitfield describing the mapped buffer access flags
157 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
160 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
162 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
163 if ((access
& rwFlags
) == rwFlags
)
164 return GL_READ_WRITE
;
165 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
167 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
168 return GL_WRITE_ONLY
;
170 /* Otherwise, AccessFlags is zero (the default state).
172 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
174 * Name Type Initial Value Legal Values
176 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
179 * However, table 6.8 in the GL_OES_mapbuffer extension says:
181 * Get Value Type Get Command Value Description
182 * --------- ---- ----------- ----- -----------
183 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
185 * The difference is because GL_OES_mapbuffer only supports mapping buffers
190 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
195 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
197 * The regions do not overlap if and only if the end of the given
198 * region is before the mapped region or the start of the given region
199 * is after the mapped region.
201 * \param obj Buffer object target on which to operate.
202 * \param offset Offset of the first byte of the subdata range.
203 * \param size Size, in bytes, of the subdata range.
204 * \return true if ranges overlap, false otherwise
208 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
209 GLintptr offset
, GLsizeiptr size
)
211 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
212 const GLintptr end
= offset
+ size
;
213 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
214 obj
->Mappings
[MAP_USER
].Length
;
216 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
225 * Tests the subdata range parameters and sets the GL error code for
226 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
227 * \c glClearBufferSubData.
229 * \param ctx GL context.
230 * \param target Buffer object target on which to operate.
231 * \param offset Offset of the first byte of the subdata range.
232 * \param size Size, in bytes, of the subdata range.
233 * \param mappedRange If true, checks if an overlapping range is mapped.
234 * If false, checks if buffer is mapped.
235 * \param errorNoBuffer Error code if no buffer is bound to target.
236 * \param caller Name of calling function for recording errors.
237 * \return A pointer to the buffer object bound to \c target in the
238 * specified context or \c NULL if any of the parameter or state
239 * conditions are invalid.
241 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
243 static struct gl_buffer_object
*
244 buffer_object_subdata_range_good(struct gl_context
* ctx
, GLenum target
,
245 GLintptrARB offset
, GLsizeiptrARB size
,
246 bool mappedRange
, GLenum errorNoBuffer
,
249 struct gl_buffer_object
*bufObj
;
252 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
257 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
261 bufObj
= get_buffer(ctx
, caller
, target
, errorNoBuffer
);
265 if (offset
+ size
> bufObj
->Size
) {
266 _mesa_error(ctx
, GL_INVALID_VALUE
,
267 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
268 (unsigned long) offset
,
269 (unsigned long) size
,
270 (unsigned long) bufObj
->Size
);
274 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
278 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
279 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
284 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
285 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
295 * Test the format and type parameters and set the GL error code for
296 * \c glClearBufferData and \c glClearBufferSubData.
298 * \param ctx GL context.
299 * \param internalformat Format to which the data is to be converted.
300 * \param format Format of the supplied data.
301 * \param type Type of the supplied data.
302 * \param caller Name of calling function for recording errors.
303 * \return If internalformat, format and type are legal the mesa_format
304 * corresponding to internalformat, otherwise MESA_FORMAT_NONE.
306 * \sa glClearBufferData and glClearBufferSubData
309 validate_clear_buffer_format(struct gl_context
*ctx
,
310 GLenum internalformat
,
311 GLenum format
, GLenum type
,
314 mesa_format mesaFormat
;
315 GLenum errorFormatType
;
317 mesaFormat
= _mesa_validate_texbuffer_format(ctx
, internalformat
);
318 if (mesaFormat
== MESA_FORMAT_NONE
) {
319 _mesa_error(ctx
, GL_INVALID_ENUM
,
320 "%s(invalid internalformat)", caller
);
321 return MESA_FORMAT_NONE
;
324 /* NOTE: not mentioned in ARB_clear_buffer_object but according to
325 * EXT_texture_integer there is no conversion between integer and
326 * non-integer formats
328 if (_mesa_is_enum_format_signed_int(format
) !=
329 _mesa_is_format_integer_color(mesaFormat
)) {
330 _mesa_error(ctx
, GL_INVALID_OPERATION
,
331 "%s(integer vs non-integer)", caller
);
332 return MESA_FORMAT_NONE
;
335 if (!_mesa_is_color_format(format
)) {
336 _mesa_error(ctx
, GL_INVALID_ENUM
,
337 "%s(format is not a color format)", caller
);
338 return MESA_FORMAT_NONE
;
341 errorFormatType
= _mesa_error_check_format_and_type(ctx
, format
, type
);
342 if (errorFormatType
!= GL_NO_ERROR
) {
343 _mesa_error(ctx
, GL_INVALID_ENUM
,
344 "%s(invalid format or type)", caller
);
345 return MESA_FORMAT_NONE
;
353 * Convert user-specified clear value to the specified internal format.
355 * \param ctx GL context.
356 * \param internalformat Format to which the data is converted.
357 * \param clearValue Points to the converted clear value.
358 * \param format Format of the supplied data.
359 * \param type Type of the supplied data.
360 * \param data Data which is to be converted to internalformat.
361 * \param caller Name of calling function for recording errors.
362 * \return true if data could be converted, false otherwise.
364 * \sa glClearBufferData, glClearBufferSubData
367 convert_clear_buffer_data(struct gl_context
*ctx
,
368 mesa_format internalformat
,
369 GLubyte
*clearValue
, GLenum format
, GLenum type
,
370 const GLvoid
*data
, const char *caller
)
372 GLenum internalformatBase
= _mesa_get_format_base_format(internalformat
);
374 if (_mesa_texstore(ctx
, 1, internalformatBase
, internalformat
,
375 0, &clearValue
, 1, 1, 1,
376 format
, type
, data
, &ctx
->Unpack
)) {
380 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
387 * Allocate and initialize a new buffer object.
389 * Default callback for the \c dd_function_table::NewBufferObject() hook.
391 static struct gl_buffer_object
*
392 _mesa_new_buffer_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
394 struct gl_buffer_object
*obj
;
398 obj
= MALLOC_STRUCT(gl_buffer_object
);
399 _mesa_initialize_buffer_object(ctx
, obj
, name
, target
);
405 * Delete a buffer object.
407 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
410 _mesa_delete_buffer_object(struct gl_context
*ctx
,
411 struct gl_buffer_object
*bufObj
)
415 _mesa_align_free(bufObj
->Data
);
417 /* assign strange values here to help w/ debugging */
418 bufObj
->RefCount
= -1000;
421 mtx_destroy(&bufObj
->Mutex
);
429 * Set ptr to bufObj w/ reference counting.
430 * This is normally only called from the _mesa_reference_buffer_object() macro
431 * when there's a real pointer change.
434 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
435 struct gl_buffer_object
**ptr
,
436 struct gl_buffer_object
*bufObj
)
439 /* Unreference the old buffer */
440 GLboolean deleteFlag
= GL_FALSE
;
441 struct gl_buffer_object
*oldObj
= *ptr
;
443 mtx_lock(&oldObj
->Mutex
);
444 ASSERT(oldObj
->RefCount
> 0);
447 printf("BufferObj %p %d DECR to %d\n",
448 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
450 deleteFlag
= (oldObj
->RefCount
== 0);
451 mtx_unlock(&oldObj
->Mutex
);
455 /* some sanity checking: don't delete a buffer still in use */
457 /* unfortunately, these tests are invalid during context tear-down */
458 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
459 ASSERT(ctx
->Array
.VAO
->IndexBufferObj
!= bufObj
);
460 ASSERT(ctx
->Array
.VAO
->Vertex
.BufferObj
!= bufObj
);
463 ASSERT(ctx
->Driver
.DeleteBuffer
);
464 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
472 /* reference new buffer */
473 mtx_lock(&bufObj
->Mutex
);
474 if (bufObj
->RefCount
== 0) {
475 /* this buffer's being deleted (look just above) */
476 /* Not sure this can every really happen. Warn if it does. */
477 _mesa_problem(NULL
, "referencing deleted buffer object");
483 printf("BufferObj %p %d INCR to %d\n",
484 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
488 mtx_unlock(&bufObj
->Mutex
);
494 * Initialize a buffer object to default values.
497 _mesa_initialize_buffer_object( struct gl_context
*ctx
,
498 struct gl_buffer_object
*obj
,
499 GLuint name
, GLenum target
)
503 memset(obj
, 0, sizeof(struct gl_buffer_object
));
504 mtx_init(&obj
->Mutex
, mtx_plain
);
507 obj
->Usage
= GL_STATIC_DRAW_ARB
;
513 * Callback called from _mesa_HashWalk()
516 count_buffer_size(GLuint key
, void *data
, void *userData
)
518 const struct gl_buffer_object
*bufObj
=
519 (const struct gl_buffer_object
*) data
;
520 GLuint
*total
= (GLuint
*) userData
;
522 *total
= *total
+ bufObj
->Size
;
527 * Compute total size (in bytes) of all buffer objects for the given context.
528 * For debugging purposes.
531 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
535 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
542 * Allocate space for and store data in a buffer object. Any data that was
543 * previously stored in the buffer object is lost. If \c data is \c NULL,
544 * memory will be allocated, but no copy will occur.
546 * This is the default callback for \c dd_function_table::BufferData()
547 * Note that all GL error checking will have been done already.
549 * \param ctx GL context.
550 * \param target Buffer object target on which to operate.
551 * \param size Size, in bytes, of the new data store.
552 * \param data Pointer to the data to store in the buffer object. This
553 * pointer may be \c NULL.
554 * \param usage Hints about how the data will be used.
555 * \param bufObj Object to be used.
557 * \return GL_TRUE for success, GL_FALSE for failure
558 * \sa glBufferDataARB, dd_function_table::BufferData.
561 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
562 const GLvoid
* data
, GLenum usage
, GLenum storageFlags
,
563 struct gl_buffer_object
* bufObj
)
569 _mesa_align_free( bufObj
->Data
);
571 new_data
= _mesa_align_malloc( size
, ctx
->Const
.MinMapBufferAlignment
);
573 bufObj
->Data
= (GLubyte
*) new_data
;
575 bufObj
->Usage
= usage
;
576 bufObj
->StorageFlags
= storageFlags
;
579 memcpy( bufObj
->Data
, data
, size
);
591 * Replace data in a subrange of buffer object. If the data range
592 * specified by \c size + \c offset extends beyond the end of the buffer or
593 * if \c data is \c NULL, no copy is performed.
595 * This is the default callback for \c dd_function_table::BufferSubData()
596 * Note that all GL error checking will have been done already.
598 * \param ctx GL context.
599 * \param offset Offset of the first byte to be modified.
600 * \param size Size, in bytes, of the data range.
601 * \param data Pointer to the data to store in the buffer object.
602 * \param bufObj Object to be used.
604 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
607 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
608 GLsizeiptrARB size
, const GLvoid
* data
,
609 struct gl_buffer_object
* bufObj
)
613 /* this should have been caught in _mesa_BufferSubData() */
614 ASSERT(size
+ offset
<= bufObj
->Size
);
617 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
623 * Retrieve data from a subrange of buffer object. If the data range
624 * specified by \c size + \c offset extends beyond the end of the buffer or
625 * if \c data is \c NULL, no copy is performed.
627 * This is the default callback for \c dd_function_table::GetBufferSubData()
628 * Note that all GL error checking will have been done already.
630 * \param ctx GL context.
631 * \param target Buffer object target on which to operate.
632 * \param offset Offset of the first byte to be fetched.
633 * \param size Size, in bytes, of the data range.
634 * \param data Destination for data
635 * \param bufObj Object to be used.
637 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
640 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
641 GLsizeiptrARB size
, GLvoid
* data
,
642 struct gl_buffer_object
* bufObj
)
646 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
647 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
653 * Clear a subrange of the buffer object with copies of the supplied data.
654 * If data is NULL the buffer is filled with zeros.
656 * This is the default callback for \c dd_function_table::ClearBufferSubData()
657 * Note that all GL error checking will have been done already.
659 * \param ctx GL context.
660 * \param offset Offset of the first byte to be cleared.
661 * \param size Size, in bytes, of the to be cleared range.
662 * \param clearValue Source of the data.
663 * \param clearValueSize Size, in bytes, of the supplied data.
664 * \param bufObj Object to be cleared.
666 * \sa glClearBufferSubData, glClearBufferData and
667 * dd_function_table::ClearBufferSubData.
670 _mesa_buffer_clear_subdata(struct gl_context
*ctx
,
671 GLintptr offset
, GLsizeiptr size
,
672 const GLvoid
*clearValue
,
673 GLsizeiptr clearValueSize
,
674 struct gl_buffer_object
*bufObj
)
679 ASSERT(ctx
->Driver
.MapBufferRange
);
680 dest
= ctx
->Driver
.MapBufferRange(ctx
, offset
, size
,
682 GL_MAP_INVALIDATE_RANGE_BIT
,
683 bufObj
, MAP_INTERNAL
);
686 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearBuffer[Sub]Data");
690 if (clearValue
== NULL
) {
691 /* Clear with zeros, per the spec */
692 memset(dest
, 0, size
);
693 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
697 for (i
= 0; i
< size
/clearValueSize
; ++i
) {
698 memcpy(dest
, clearValue
, clearValueSize
);
699 dest
+= clearValueSize
;
702 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
707 * Default fallback for \c dd_function_table::MapBufferRange().
708 * Called via glMapBufferRange().
711 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
712 GLsizeiptr length
, GLbitfield access
,
713 struct gl_buffer_object
*bufObj
,
714 gl_map_buffer_index index
)
717 assert(!_mesa_bufferobj_mapped(bufObj
, index
));
718 /* Just return a direct pointer to the data */
719 bufObj
->Mappings
[index
].Pointer
= bufObj
->Data
+ offset
;
720 bufObj
->Mappings
[index
].Length
= length
;
721 bufObj
->Mappings
[index
].Offset
= offset
;
722 bufObj
->Mappings
[index
].AccessFlags
= access
;
723 return bufObj
->Mappings
[index
].Pointer
;
728 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
729 * Called via glFlushMappedBufferRange().
732 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
733 GLintptr offset
, GLsizeiptr length
,
734 struct gl_buffer_object
*obj
,
735 gl_map_buffer_index index
)
746 * Default callback for \c dd_function_table::MapBuffer().
748 * The input parameters will have been already tested for errors.
750 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
753 _mesa_buffer_unmap(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
754 gl_map_buffer_index index
)
757 /* XXX we might assert here that bufObj->Pointer is non-null */
758 bufObj
->Mappings
[index
].Pointer
= NULL
;
759 bufObj
->Mappings
[index
].Length
= 0;
760 bufObj
->Mappings
[index
].Offset
= 0;
761 bufObj
->Mappings
[index
].AccessFlags
= 0x0;
767 * Default fallback for \c dd_function_table::CopyBufferSubData().
768 * Called via glCopyBufferSubData().
771 _mesa_copy_buffer_subdata(struct gl_context
*ctx
,
772 struct gl_buffer_object
*src
,
773 struct gl_buffer_object
*dst
,
774 GLintptr readOffset
, GLintptr writeOffset
,
777 GLubyte
*srcPtr
, *dstPtr
;
780 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
782 GL_MAP_WRITE_BIT
, src
,
788 srcPtr
+= readOffset
;
789 dstPtr
+= writeOffset
;
791 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
792 GL_MAP_READ_BIT
, src
,
794 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
796 GL_MAP_INVALIDATE_RANGE_BIT
), dst
,
800 /* Note: the src and dst regions will never overlap. Trying to do so
801 * would generate GL_INVALID_VALUE earlier.
803 if (srcPtr
&& dstPtr
)
804 memcpy(dstPtr
, srcPtr
, size
);
806 ctx
->Driver
.UnmapBuffer(ctx
, src
, MAP_INTERNAL
);
808 ctx
->Driver
.UnmapBuffer(ctx
, dst
, MAP_INTERNAL
);
814 * Initialize the state associated with buffer objects
817 _mesa_init_buffer_objects( struct gl_context
*ctx
)
821 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
822 mtx_init(&DummyBufferObject
.Mutex
, mtx_plain
);
823 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
825 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
826 ctx
->Shared
->NullBufferObj
);
828 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
829 ctx
->Shared
->NullBufferObj
);
830 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
831 ctx
->Shared
->NullBufferObj
);
833 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
834 ctx
->Shared
->NullBufferObj
);
836 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
,
837 ctx
->Shared
->NullBufferObj
);
839 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
840 ctx
->Shared
->NullBufferObj
);
842 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
843 _mesa_reference_buffer_object(ctx
,
844 &ctx
->UniformBufferBindings
[i
].BufferObject
,
845 ctx
->Shared
->NullBufferObj
);
846 ctx
->UniformBufferBindings
[i
].Offset
= -1;
847 ctx
->UniformBufferBindings
[i
].Size
= -1;
850 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
851 _mesa_reference_buffer_object(ctx
,
852 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
853 ctx
->Shared
->NullBufferObj
);
854 ctx
->AtomicBufferBindings
[i
].Offset
= -1;
855 ctx
->AtomicBufferBindings
[i
].Size
= -1;
861 _mesa_free_buffer_objects( struct gl_context
*ctx
)
865 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
867 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
868 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
870 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
872 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
874 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
876 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
877 _mesa_reference_buffer_object(ctx
,
878 &ctx
->UniformBufferBindings
[i
].BufferObject
,
882 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
883 _mesa_reference_buffer_object(ctx
,
884 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
891 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
894 struct gl_buffer_object
**buf_handle
,
897 struct gl_buffer_object
*buf
= *buf_handle
;
899 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
900 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
904 if (!buf
|| buf
== &DummyBufferObject
) {
905 /* If this is a new buffer object id, or one which was generated but
906 * never used before, allocate a buffer object now.
908 ASSERT(ctx
->Driver
.NewBufferObject
);
909 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
, target
);
911 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
914 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
922 * Bind the specified target to buffer for the specified context.
923 * Called by glBindBuffer() and other functions.
926 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
928 struct gl_buffer_object
*oldBufObj
;
929 struct gl_buffer_object
*newBufObj
= NULL
;
930 struct gl_buffer_object
**bindTarget
= NULL
;
932 bindTarget
= get_buffer_target(ctx
, target
);
934 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
938 /* Get pointer to old buffer object (to be unbound) */
939 oldBufObj
= *bindTarget
;
940 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
941 return; /* rebinding the same buffer object- no change */
944 * Get pointer to new buffer object (newBufObj)
947 /* The spec says there's not a buffer object named 0, but we use
948 * one internally because it simplifies things.
950 newBufObj
= ctx
->Shared
->NullBufferObj
;
953 /* non-default buffer object */
954 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
955 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
956 &newBufObj
, "glBindBuffer"))
960 /* bind new buffer */
961 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
966 * Update the default buffer objects in the given context to reference those
967 * specified in the shared state and release those referencing the old
971 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
973 /* Bind the NullBufferObj to remove references to those
974 * in the shared context hash table.
976 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
977 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
978 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
979 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
985 * Return the gl_buffer_object for the given ID.
986 * Always return NULL for ID 0.
988 struct gl_buffer_object
*
989 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
994 return (struct gl_buffer_object
*)
995 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
999 struct gl_buffer_object
*
1000 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1002 return (struct gl_buffer_object
*)
1003 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1008 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1010 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1015 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1017 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1022 * Look up a buffer object for a multi-bind function.
1024 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1025 * of generating an error if the buffer ID is not zero or the name
1026 * of an existing buffer object.
1028 * If the buffer ID refers to an existing buffer object, a pointer
1029 * to the buffer object is returned. If the ID is zero, a pointer
1030 * to the shared NullBufferObj is returned. If the ID is not zero
1031 * and does not refer to a valid buffer object, this function
1034 * This function assumes that the caller has already locked the
1035 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1037 struct gl_buffer_object
*
1038 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1039 const GLuint
*buffers
,
1040 GLuint index
, const char *caller
)
1042 struct gl_buffer_object
*bufObj
;
1044 if (buffers
[index
] != 0) {
1045 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1047 /* The multi-bind functions don't create the buffer objects
1048 when they don't exist. */
1049 if (bufObj
== &DummyBufferObject
)
1052 bufObj
= ctx
->Shared
->NullBufferObj
;
1055 /* The ARB_multi_bind spec says:
1057 * "An INVALID_OPERATION error is generated if any value
1058 * in <buffers> is not zero or the name of an existing
1059 * buffer object (per binding)."
1061 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1062 "%s(buffers[%u]=%u is not zero or the name "
1063 "of an existing buffer object)",
1064 caller
, index
, buffers
[index
]);
1072 * If *ptr points to obj, set ptr = the Null/default buffer object.
1073 * This is a helper for buffer object deletion.
1074 * The GL spec says that deleting a buffer object causes it to get
1075 * unbound from all arrays in the current context.
1078 unbind(struct gl_context
*ctx
,
1079 struct gl_buffer_object
**ptr
,
1080 struct gl_buffer_object
*obj
)
1083 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1089 * Plug default/fallback buffer object functions into the device
1093 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1095 /* GL_ARB_vertex/pixel_buffer_object */
1096 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1097 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1098 driver
->BufferData
= _mesa_buffer_data
;
1099 driver
->BufferSubData
= _mesa_buffer_subdata
;
1100 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1101 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
1103 /* GL_ARB_clear_buffer_object */
1104 driver
->ClearBufferSubData
= _mesa_buffer_clear_subdata
;
1106 /* GL_ARB_map_buffer_range */
1107 driver
->MapBufferRange
= _mesa_buffer_map_range
;
1108 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
1110 /* GL_ARB_copy_buffer */
1111 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
1116 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1117 struct gl_buffer_object
*bufObj
)
1121 for (i
= 0; i
< MAP_COUNT
; i
++) {
1122 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1123 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1124 ASSERT(bufObj
->Mappings
[i
].Pointer
== NULL
);
1125 bufObj
->Mappings
[i
].AccessFlags
= 0;
1131 /**********************************************************************/
1133 /**********************************************************************/
1136 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1138 GET_CURRENT_CONTEXT(ctx
);
1140 if (MESA_VERBOSE
& VERBOSE_API
)
1141 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1142 _mesa_lookup_enum_by_nr(target
), buffer
);
1144 bind_buffer_object(ctx
, target
, buffer
);
1149 * Delete a set of buffer objects.
1151 * \param n Number of buffer objects to delete.
1152 * \param ids Array of \c n buffer object IDs.
1155 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1157 GET_CURRENT_CONTEXT(ctx
);
1159 FLUSH_VERTICES(ctx
, 0);
1162 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1166 mtx_lock(&ctx
->Shared
->Mutex
);
1168 for (i
= 0; i
< n
; i
++) {
1169 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1171 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1174 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1176 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1178 /* unbind any vertex pointers bound to this buffer */
1179 for (j
= 0; j
< Elements(vao
->VertexBinding
); j
++) {
1180 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1183 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1184 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1186 if (vao
->IndexBufferObj
== bufObj
) {
1187 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1190 /* unbind ARB_draw_indirect binding point */
1191 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1192 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1195 /* unbind ARB_copy_buffer binding points */
1196 if (ctx
->CopyReadBuffer
== bufObj
) {
1197 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1199 if (ctx
->CopyWriteBuffer
== bufObj
) {
1200 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1203 /* unbind transform feedback binding points */
1204 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1205 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1207 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1208 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1209 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1213 /* unbind UBO binding points */
1214 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1215 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1216 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1220 if (ctx
->UniformBuffer
== bufObj
) {
1221 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1224 /* unbind Atomci Buffer binding points */
1225 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1226 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1227 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1231 if (ctx
->UniformBuffer
== bufObj
) {
1232 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1235 /* unbind any pixel pack/unpack pointers bound to this buffer */
1236 if (ctx
->Pack
.BufferObj
== bufObj
) {
1237 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1239 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1240 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1243 if (ctx
->Texture
.BufferObject
== bufObj
) {
1244 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1247 /* The ID is immediately freed for re-use */
1248 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1249 /* Make sure we do not run into the classic ABA problem on bind.
1250 * We don't want to allow re-binding a buffer object that's been
1251 * "deleted" by glDeleteBuffers().
1253 * The explicit rebinding to the default object in the current context
1254 * prevents the above in the current context, but another context
1255 * sharing the same objects might suffer from this problem.
1256 * The alternative would be to do the hash lookup in any case on bind
1257 * which would introduce more runtime overhead than this.
1259 bufObj
->DeletePending
= GL_TRUE
;
1260 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1264 mtx_unlock(&ctx
->Shared
->Mutex
);
1269 * Generate a set of unique buffer object IDs and store them in \c buffer.
1271 * \param n Number of IDs to generate.
1272 * \param buffer Array of \c n locations to store the IDs.
1275 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
1277 GET_CURRENT_CONTEXT(ctx
);
1281 if (MESA_VERBOSE
& VERBOSE_API
)
1282 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
1285 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
1294 * This must be atomic (generation and allocation of buffer object IDs)
1296 mtx_lock(&ctx
->Shared
->Mutex
);
1298 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1300 /* Insert the ID and pointer to dummy buffer object into hash table */
1301 for (i
= 0; i
< n
; i
++) {
1302 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
1303 &DummyBufferObject
);
1304 buffer
[i
] = first
+ i
;
1307 mtx_unlock(&ctx
->Shared
->Mutex
);
1312 * Determine if ID is the name of a buffer object.
1314 * \param id ID of the potential buffer object.
1315 * \return \c GL_TRUE if \c id is the name of a buffer object,
1316 * \c GL_FALSE otherwise.
1318 GLboolean GLAPIENTRY
1319 _mesa_IsBuffer(GLuint id
)
1321 struct gl_buffer_object
*bufObj
;
1322 GET_CURRENT_CONTEXT(ctx
);
1323 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1325 mtx_lock(&ctx
->Shared
->Mutex
);
1326 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1327 mtx_unlock(&ctx
->Shared
->Mutex
);
1329 return bufObj
&& bufObj
!= &DummyBufferObject
;
1334 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1337 GET_CURRENT_CONTEXT(ctx
);
1338 struct gl_buffer_object
*bufObj
;
1341 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(size <= 0)");
1345 if (flags
& ~(GL_MAP_READ_BIT
|
1347 GL_MAP_PERSISTENT_BIT
|
1348 GL_MAP_COHERENT_BIT
|
1349 GL_DYNAMIC_STORAGE_BIT
|
1350 GL_CLIENT_STORAGE_BIT
)) {
1351 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags)");
1355 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1356 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1357 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=READ/WRITE)");
1361 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1362 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=PERSISTENT)");
1366 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1370 if (bufObj
->Immutable
) {
1371 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage(immutable)");
1375 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1376 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1378 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1380 bufObj
->Written
= GL_TRUE
;
1381 bufObj
->Immutable
= GL_TRUE
;
1383 ASSERT(ctx
->Driver
.BufferData
);
1384 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1386 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferStorage()");
1392 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1393 const GLvoid
* data
, GLenum usage
)
1395 GET_CURRENT_CONTEXT(ctx
);
1396 struct gl_buffer_object
*bufObj
;
1399 if (MESA_VERBOSE
& VERBOSE_API
)
1400 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1401 _mesa_lookup_enum_by_nr(target
),
1402 (long int) size
, data
,
1403 _mesa_lookup_enum_by_nr(usage
));
1406 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1411 case GL_STREAM_DRAW_ARB
:
1412 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1415 case GL_STATIC_DRAW_ARB
:
1416 case GL_DYNAMIC_DRAW_ARB
:
1420 case GL_STREAM_READ_ARB
:
1421 case GL_STREAM_COPY_ARB
:
1422 case GL_STATIC_READ_ARB
:
1423 case GL_STATIC_COPY_ARB
:
1424 case GL_DYNAMIC_READ_ARB
:
1425 case GL_DYNAMIC_COPY_ARB
:
1426 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1430 valid_usage
= false;
1435 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1439 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
, GL_INVALID_OPERATION
);
1443 if (bufObj
->Immutable
) {
1444 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData(immutable)");
1448 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1449 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1451 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1453 bufObj
->Written
= GL_TRUE
;
1456 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1457 bufObj
->Name
, size
, data
, usage
);
1464 ASSERT(ctx
->Driver
.BufferData
);
1465 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1468 GL_DYNAMIC_STORAGE_BIT
,
1470 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
1476 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1477 GLsizeiptrARB size
, const GLvoid
* data
)
1479 GET_CURRENT_CONTEXT(ctx
);
1480 struct gl_buffer_object
*bufObj
;
1482 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1483 false, GL_INVALID_OPERATION
,
1484 "glBufferSubDataARB" );
1486 /* error already recorded */
1490 if (bufObj
->Immutable
&&
1491 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1492 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubData");
1499 bufObj
->Written
= GL_TRUE
;
1501 ASSERT(ctx
->Driver
.BufferSubData
);
1502 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1507 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1508 GLsizeiptrARB size
, void * data
)
1510 GET_CURRENT_CONTEXT(ctx
);
1511 struct gl_buffer_object
*bufObj
;
1513 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1514 false, GL_INVALID_OPERATION
,
1515 "glGetBufferSubDataARB");
1517 /* error already recorded */
1521 ASSERT(ctx
->Driver
.GetBufferSubData
);
1522 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1527 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1528 GLenum type
, const GLvoid
* data
)
1530 GET_CURRENT_CONTEXT(ctx
);
1531 struct gl_buffer_object
* bufObj
;
1532 mesa_format mesaFormat
;
1533 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1534 GLsizeiptr clearValueSize
;
1536 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1541 if (_mesa_check_disallowed_mapping(bufObj
)) {
1542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1543 "glClearBufferData(buffer currently mapped)");
1547 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1549 "glClearBufferData");
1550 if (mesaFormat
== MESA_FORMAT_NONE
) {
1554 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1555 if (bufObj
->Size
% clearValueSize
!= 0) {
1556 _mesa_error(ctx
, GL_INVALID_VALUE
,
1557 "glClearBufferData(size is not a multiple of "
1558 "internalformat size)");
1563 /* clear to zeros, per the spec */
1564 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1565 NULL
, clearValueSize
, bufObj
);
1569 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1570 format
, type
, data
, "glClearBufferData")) {
1574 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1575 clearValue
, clearValueSize
, bufObj
);
1580 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1581 GLintptr offset
, GLsizeiptr size
,
1582 GLenum format
, GLenum type
,
1585 GET_CURRENT_CONTEXT(ctx
);
1586 struct gl_buffer_object
* bufObj
;
1587 mesa_format mesaFormat
;
1588 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1589 GLsizeiptr clearValueSize
;
1591 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1592 true, GL_INVALID_VALUE
,
1593 "glClearBufferSubData");
1598 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1600 "glClearBufferSubData");
1601 if (mesaFormat
== MESA_FORMAT_NONE
) {
1605 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1606 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1607 _mesa_error(ctx
, GL_INVALID_VALUE
,
1608 "glClearBufferSubData(offset or size is not a multiple of "
1609 "internalformat size)");
1614 /* clear to zeros, per the spec */
1616 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1617 NULL
, clearValueSize
, bufObj
);
1622 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1624 "glClearBufferSubData")) {
1629 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1630 clearValue
, clearValueSize
, bufObj
);
1636 _mesa_MapBuffer(GLenum target
, GLenum access
)
1638 GET_CURRENT_CONTEXT(ctx
);
1639 struct gl_buffer_object
* bufObj
;
1640 GLbitfield accessFlags
;
1644 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1647 case GL_READ_ONLY_ARB
:
1648 accessFlags
= GL_MAP_READ_BIT
;
1649 valid_access
= _mesa_is_desktop_gl(ctx
);
1651 case GL_WRITE_ONLY_ARB
:
1652 accessFlags
= GL_MAP_WRITE_BIT
;
1653 valid_access
= true;
1655 case GL_READ_WRITE_ARB
:
1656 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1657 valid_access
= _mesa_is_desktop_gl(ctx
);
1660 valid_access
= false;
1664 if (!valid_access
) {
1665 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1669 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
, GL_INVALID_OPERATION
);
1673 if (accessFlags
& GL_MAP_READ_BIT
&&
1674 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
1675 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1676 "glMapBuffer(invalid read flag)");
1680 if (accessFlags
& GL_MAP_WRITE_BIT
&&
1681 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
1682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1683 "glMapBuffer(invalid write flag)");
1687 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1688 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1692 if (!bufObj
->Size
) {
1693 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1694 "glMapBuffer(buffer size = 0)");
1698 ASSERT(ctx
->Driver
.MapBufferRange
);
1699 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
,
1702 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1706 /* The driver callback should have set these fields.
1707 * This is important because other modules (like VBO) might call
1708 * the driver function directly.
1710 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
1711 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== bufObj
->Size
);
1712 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1713 bufObj
->Mappings
[MAP_USER
].AccessFlags
= accessFlags
;
1716 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1717 bufObj
->Written
= GL_TRUE
;
1720 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1721 bufObj
->Name
, bufObj
->Size
, access
);
1722 if (access
== GL_WRITE_ONLY_ARB
) {
1724 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1725 for (i
= 0; i
< bufObj
->Size
; i
++)
1732 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1734 /* buffer is 100 bytes larger than requested, fill with magic value */
1735 for (i
= 0; i
< 100; i
++) {
1736 buf
[bufObj
->Size
- i
- 1] = 123;
1741 return bufObj
->Mappings
[MAP_USER
].Pointer
;
1745 GLboolean GLAPIENTRY
1746 _mesa_UnmapBuffer(GLenum target
)
1748 GET_CURRENT_CONTEXT(ctx
);
1749 struct gl_buffer_object
*bufObj
;
1750 GLboolean status
= GL_TRUE
;
1751 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1753 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
, GL_INVALID_OPERATION
);
1757 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1758 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1763 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1764 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1766 /* check that last 100 bytes are still = magic value */
1767 for (i
= 0; i
< 100; i
++) {
1768 GLuint pos
= bufObj
->Size
- i
- 1;
1769 if (buf
[pos
] != 123) {
1770 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1771 " at position %d (value = %u)\n",
1779 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1780 GLuint i
, unchanged
= 0;
1781 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1783 /* check which bytes changed */
1784 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1785 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1792 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1793 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1798 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1799 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1800 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1801 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1802 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1809 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1811 GET_CURRENT_CONTEXT(ctx
);
1812 struct gl_buffer_object
*bufObj
;
1814 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
,
1815 GL_INVALID_OPERATION
);
1820 case GL_BUFFER_SIZE_ARB
:
1821 *params
= (GLint
) bufObj
->Size
;
1823 case GL_BUFFER_USAGE_ARB
:
1824 *params
= bufObj
->Usage
;
1826 case GL_BUFFER_ACCESS_ARB
:
1827 *params
= simplified_access_mode(ctx
,
1828 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1830 case GL_BUFFER_MAPPED_ARB
:
1831 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1833 case GL_BUFFER_ACCESS_FLAGS
:
1834 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1836 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1838 case GL_BUFFER_MAP_OFFSET
:
1839 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1841 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Offset
;
1843 case GL_BUFFER_MAP_LENGTH
:
1844 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1846 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Length
;
1848 case GL_BUFFER_IMMUTABLE_STORAGE
:
1849 if (!ctx
->Extensions
.ARB_buffer_storage
)
1851 *params
= bufObj
->Immutable
;
1853 case GL_BUFFER_STORAGE_FLAGS
:
1854 if (!ctx
->Extensions
.ARB_buffer_storage
)
1856 *params
= bufObj
->StorageFlags
;
1859 ; /* fall-through */
1863 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1864 _mesa_lookup_enum_by_nr(pname
));
1870 * This is pretty much a duplicate of GetBufferParameteriv() but the
1871 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1874 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1876 GET_CURRENT_CONTEXT(ctx
);
1877 struct gl_buffer_object
*bufObj
;
1879 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
1880 GL_INVALID_OPERATION
);
1885 case GL_BUFFER_SIZE_ARB
:
1886 *params
= bufObj
->Size
;
1888 case GL_BUFFER_USAGE_ARB
:
1889 *params
= bufObj
->Usage
;
1891 case GL_BUFFER_ACCESS_ARB
:
1892 *params
= simplified_access_mode(ctx
,
1893 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1895 case GL_BUFFER_ACCESS_FLAGS
:
1896 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1898 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1900 case GL_BUFFER_MAPPED_ARB
:
1901 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1903 case GL_BUFFER_MAP_OFFSET
:
1904 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1906 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
1908 case GL_BUFFER_MAP_LENGTH
:
1909 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1911 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
1913 case GL_BUFFER_IMMUTABLE_STORAGE
:
1914 if (!ctx
->Extensions
.ARB_buffer_storage
)
1916 *params
= bufObj
->Immutable
;
1918 case GL_BUFFER_STORAGE_FLAGS
:
1919 if (!ctx
->Extensions
.ARB_buffer_storage
)
1921 *params
= bufObj
->StorageFlags
;
1924 ; /* fall-through */
1928 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1929 _mesa_lookup_enum_by_nr(pname
));
1934 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1936 GET_CURRENT_CONTEXT(ctx
);
1937 struct gl_buffer_object
* bufObj
;
1939 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1940 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1944 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
,
1945 GL_INVALID_OPERATION
);
1949 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
1954 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1955 GLintptr readOffset
, GLintptr writeOffset
,
1958 GET_CURRENT_CONTEXT(ctx
);
1959 struct gl_buffer_object
*src
, *dst
;
1961 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
1962 GL_INVALID_OPERATION
);
1966 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
1967 GL_INVALID_OPERATION
);
1971 if (_mesa_check_disallowed_mapping(src
)) {
1972 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1973 "glCopyBufferSubData(readBuffer is mapped)");
1977 if (_mesa_check_disallowed_mapping(dst
)) {
1978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1979 "glCopyBufferSubData(writeBuffer is mapped)");
1983 if (readOffset
< 0) {
1984 _mesa_error(ctx
, GL_INVALID_VALUE
,
1985 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
1989 if (writeOffset
< 0) {
1990 _mesa_error(ctx
, GL_INVALID_VALUE
,
1991 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
2001 if (readOffset
+ size
> src
->Size
) {
2002 _mesa_error(ctx
, GL_INVALID_VALUE
,
2003 "glCopyBufferSubData(readOffset + size = %d)",
2004 (int) (readOffset
+ size
));
2008 if (writeOffset
+ size
> dst
->Size
) {
2009 _mesa_error(ctx
, GL_INVALID_VALUE
,
2010 "glCopyBufferSubData(writeOffset + size = %d)",
2011 (int) (writeOffset
+ size
));
2016 if (readOffset
+ size
<= writeOffset
) {
2019 else if (writeOffset
+ size
<= readOffset
) {
2023 /* overlapping src/dst is illegal */
2024 _mesa_error(ctx
, GL_INVALID_VALUE
,
2025 "glCopyBufferSubData(overlapping src/dst)");
2030 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2035 * See GL_ARB_map_buffer_range spec
2038 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2041 GET_CURRENT_CONTEXT(ctx
);
2042 struct gl_buffer_object
*bufObj
;
2044 GLbitfield allowed_access
;
2046 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2048 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2049 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2050 "glMapBufferRange(extension not supported)");
2055 _mesa_error(ctx
, GL_INVALID_VALUE
,
2056 "glMapBufferRange(offset = %ld)", (long)offset
);
2061 _mesa_error(ctx
, GL_INVALID_VALUE
,
2062 "glMapBufferRange(length = %ld)", (long)length
);
2066 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2068 * "An INVALID_OPERATION error is generated for any of the following
2071 * * <length> is zero."
2073 if (_mesa_is_gles(ctx
) && length
== 0) {
2074 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2075 "glMapBufferRange(length = 0)");
2079 allowed_access
= GL_MAP_READ_BIT
|
2081 GL_MAP_INVALIDATE_RANGE_BIT
|
2082 GL_MAP_INVALIDATE_BUFFER_BIT
|
2083 GL_MAP_FLUSH_EXPLICIT_BIT
|
2084 GL_MAP_UNSYNCHRONIZED_BIT
;
2086 if (ctx
->Extensions
.ARB_buffer_storage
) {
2087 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2088 GL_MAP_COHERENT_BIT
;
2091 if (access
& ~allowed_access
) {
2092 /* generate an error if any other than allowed bit is set */
2093 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
2097 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2098 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2099 "glMapBufferRange(access indicates neither read or write)");
2103 if ((access
& GL_MAP_READ_BIT
) &&
2104 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2105 GL_MAP_INVALIDATE_BUFFER_BIT
|
2106 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2107 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2108 "glMapBufferRange(invalid access flags)");
2112 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2113 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2114 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2115 "glMapBufferRange(invalid access flags)");
2119 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2123 if (access
& GL_MAP_READ_BIT
&&
2124 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2126 "glMapBufferRange(invalid read flag)");
2130 if (access
& GL_MAP_WRITE_BIT
&&
2131 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2133 "glMapBufferRange(invalid write flag)");
2137 if (access
& GL_MAP_COHERENT_BIT
&&
2138 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2139 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2140 "glMapBufferRange(invalid coherent flag)");
2144 if (access
& GL_MAP_PERSISTENT_BIT
&&
2145 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2147 "glMapBufferRange(invalid persistent flag)");
2151 if (offset
+ length
> bufObj
->Size
) {
2152 _mesa_error(ctx
, GL_INVALID_VALUE
,
2153 "glMapBufferRange(offset + length > size)");
2157 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2159 "glMapBufferRange(buffer already mapped)");
2163 if (!bufObj
->Size
) {
2164 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2165 "glMapBufferRange(buffer size = 0)");
2169 /* Mapping zero bytes should return a non-null pointer. */
2171 static long dummy
= 0;
2172 bufObj
->Mappings
[MAP_USER
].Pointer
= &dummy
;
2173 bufObj
->Mappings
[MAP_USER
].Length
= length
;
2174 bufObj
->Mappings
[MAP_USER
].Offset
= offset
;
2175 bufObj
->Mappings
[MAP_USER
].AccessFlags
= access
;
2176 return bufObj
->Mappings
[MAP_USER
].Pointer
;
2179 ASSERT(ctx
->Driver
.MapBufferRange
);
2180 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2183 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
2186 /* The driver callback should have set all these fields.
2187 * This is important because other modules (like VBO) might call
2188 * the driver function directly.
2190 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2191 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2192 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2193 ASSERT(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2201 * See GL_ARB_map_buffer_range spec
2204 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
2206 GET_CURRENT_CONTEXT(ctx
);
2207 struct gl_buffer_object
*bufObj
;
2209 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2210 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2211 "glFlushMappedBufferRange(extension not supported)");
2216 _mesa_error(ctx
, GL_INVALID_VALUE
,
2217 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
2222 _mesa_error(ctx
, GL_INVALID_VALUE
,
2223 "glFlushMappedBufferRange(length = %ld)", (long)length
);
2227 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2228 GL_INVALID_OPERATION
);
2232 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2233 /* buffer is not mapped */
2234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2235 "glFlushMappedBufferRange(buffer is not mapped)");
2239 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2240 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2242 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
2246 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2247 _mesa_error(ctx
, GL_INVALID_VALUE
,
2248 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
2249 (long)offset
, (long)length
,
2250 (long)bufObj
->Mappings
[MAP_USER
].Length
);
2254 ASSERT(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2256 if (ctx
->Driver
.FlushMappedBufferRange
)
2257 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2263 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2265 struct gl_buffer_object
*bufObj
;
2268 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2270 _mesa_error(ctx
, GL_INVALID_VALUE
,
2271 "glObjectPurgeable(name = 0x%x)", name
);
2274 if (!_mesa_is_bufferobj(bufObj
)) {
2275 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2279 if (bufObj
->Purgeable
) {
2280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2281 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2282 return GL_VOLATILE_APPLE
;
2285 bufObj
->Purgeable
= GL_TRUE
;
2287 retval
= GL_VOLATILE_APPLE
;
2288 if (ctx
->Driver
.BufferObjectPurgeable
)
2289 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2296 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2298 struct gl_renderbuffer
*bufObj
;
2301 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2303 _mesa_error(ctx
, GL_INVALID_VALUE
,
2304 "glObjectUnpurgeable(name = 0x%x)", name
);
2308 if (bufObj
->Purgeable
) {
2309 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2310 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2311 return GL_VOLATILE_APPLE
;
2314 bufObj
->Purgeable
= GL_TRUE
;
2316 retval
= GL_VOLATILE_APPLE
;
2317 if (ctx
->Driver
.RenderObjectPurgeable
)
2318 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2325 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2327 struct gl_texture_object
*bufObj
;
2330 bufObj
= _mesa_lookup_texture(ctx
, name
);
2332 _mesa_error(ctx
, GL_INVALID_VALUE
,
2333 "glObjectPurgeable(name = 0x%x)", name
);
2337 if (bufObj
->Purgeable
) {
2338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2339 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2340 return GL_VOLATILE_APPLE
;
2343 bufObj
->Purgeable
= GL_TRUE
;
2345 retval
= GL_VOLATILE_APPLE
;
2346 if (ctx
->Driver
.TextureObjectPurgeable
)
2347 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2354 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2358 GET_CURRENT_CONTEXT(ctx
);
2359 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2362 _mesa_error(ctx
, GL_INVALID_VALUE
,
2363 "glObjectPurgeable(name = 0x%x)", name
);
2368 case GL_VOLATILE_APPLE
:
2369 case GL_RELEASED_APPLE
:
2373 _mesa_error(ctx
, GL_INVALID_ENUM
,
2374 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2379 switch (objectType
) {
2381 retval
= texture_object_purgeable(ctx
, name
, option
);
2383 case GL_RENDERBUFFER_EXT
:
2384 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2386 case GL_BUFFER_OBJECT_APPLE
:
2387 retval
= buffer_object_purgeable(ctx
, name
, option
);
2390 _mesa_error(ctx
, GL_INVALID_ENUM
,
2391 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2396 /* In strict conformance to the spec, we must only return VOLATILE when
2397 * when passed the VOLATILE option. Madness.
2399 * XXX First fix the spec, then fix me.
2401 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2406 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2408 struct gl_buffer_object
*bufObj
;
2411 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2413 _mesa_error(ctx
, GL_INVALID_VALUE
,
2414 "glObjectUnpurgeable(name = 0x%x)", name
);
2418 if (! bufObj
->Purgeable
) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glObjectUnpurgeable(name = 0x%x) object is "
2421 " already \"unpurged\"", name
);
2425 bufObj
->Purgeable
= GL_FALSE
;
2428 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2429 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2436 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2438 struct gl_renderbuffer
*bufObj
;
2441 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2443 _mesa_error(ctx
, GL_INVALID_VALUE
,
2444 "glObjectUnpurgeable(name = 0x%x)", name
);
2448 if (! bufObj
->Purgeable
) {
2449 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2450 "glObjectUnpurgeable(name = 0x%x) object is "
2451 " already \"unpurged\"", name
);
2455 bufObj
->Purgeable
= GL_FALSE
;
2458 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2459 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2466 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2468 struct gl_texture_object
*bufObj
;
2471 bufObj
= _mesa_lookup_texture(ctx
, name
);
2473 _mesa_error(ctx
, GL_INVALID_VALUE
,
2474 "glObjectUnpurgeable(name = 0x%x)", name
);
2478 if (! bufObj
->Purgeable
) {
2479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2480 "glObjectUnpurgeable(name = 0x%x) object is"
2481 " already \"unpurged\"", name
);
2485 bufObj
->Purgeable
= GL_FALSE
;
2488 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2489 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2496 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2498 GET_CURRENT_CONTEXT(ctx
);
2499 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2502 _mesa_error(ctx
, GL_INVALID_VALUE
,
2503 "glObjectUnpurgeable(name = 0x%x)", name
);
2508 case GL_RETAINED_APPLE
:
2509 case GL_UNDEFINED_APPLE
:
2513 _mesa_error(ctx
, GL_INVALID_ENUM
,
2514 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2519 switch (objectType
) {
2520 case GL_BUFFER_OBJECT_APPLE
:
2521 return buffer_object_unpurgeable(ctx
, name
, option
);
2523 return texture_object_unpurgeable(ctx
, name
, option
);
2524 case GL_RENDERBUFFER_EXT
:
2525 return renderbuffer_unpurgeable(ctx
, name
, option
);
2527 _mesa_error(ctx
, GL_INVALID_ENUM
,
2528 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2536 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2537 GLenum pname
, GLint
*params
)
2539 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2541 _mesa_error(ctx
, GL_INVALID_VALUE
,
2542 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2547 case GL_PURGEABLE_APPLE
:
2548 *params
= bufObj
->Purgeable
;
2551 _mesa_error(ctx
, GL_INVALID_ENUM
,
2552 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2560 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2561 GLenum pname
, GLint
*params
)
2563 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2565 _mesa_error(ctx
, GL_INVALID_VALUE
,
2566 "glObjectUnpurgeable(name = 0x%x)", name
);
2571 case GL_PURGEABLE_APPLE
:
2572 *params
= rb
->Purgeable
;
2575 _mesa_error(ctx
, GL_INVALID_ENUM
,
2576 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2584 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2585 GLenum pname
, GLint
*params
)
2587 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2589 _mesa_error(ctx
, GL_INVALID_VALUE
,
2590 "glObjectUnpurgeable(name = 0x%x)", name
);
2595 case GL_PURGEABLE_APPLE
:
2596 *params
= texObj
->Purgeable
;
2599 _mesa_error(ctx
, GL_INVALID_ENUM
,
2600 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2608 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2611 GET_CURRENT_CONTEXT(ctx
);
2614 _mesa_error(ctx
, GL_INVALID_VALUE
,
2615 "glGetObjectParameteriv(name = 0x%x)", name
);
2619 switch (objectType
) {
2621 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2623 case GL_BUFFER_OBJECT_APPLE
:
2624 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2626 case GL_RENDERBUFFER_EXT
:
2627 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2630 _mesa_error(ctx
, GL_INVALID_ENUM
,
2631 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2637 * Binds a buffer object to a uniform buffer binding point.
2639 * The caller is responsible for flushing vertices and updating
2643 set_ubo_binding(struct gl_context
*ctx
,
2644 struct gl_uniform_buffer_binding
*binding
,
2645 struct gl_buffer_object
*bufObj
,
2650 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2652 binding
->Offset
= offset
;
2653 binding
->Size
= size
;
2654 binding
->AutomaticSize
= autoSize
;
2658 * Binds a buffer object to a uniform buffer binding point.
2660 * Unlike set_ubo_binding(), this function also flushes vertices
2661 * and updates NewDriverState. It also checks if the binding
2662 * has actually changed before updating it.
2665 bind_uniform_buffer(struct gl_context
*ctx
,
2667 struct gl_buffer_object
*bufObj
,
2672 struct gl_uniform_buffer_binding
*binding
=
2673 &ctx
->UniformBufferBindings
[index
];
2675 if (binding
->BufferObject
== bufObj
&&
2676 binding
->Offset
== offset
&&
2677 binding
->Size
== size
&&
2678 binding
->AutomaticSize
== autoSize
) {
2682 FLUSH_VERTICES(ctx
, 0);
2683 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2685 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
2689 * Bind a region of a buffer object to a uniform block binding point.
2690 * \param index the uniform buffer binding point index
2691 * \param bufObj the buffer object
2692 * \param offset offset to the start of buffer object region
2693 * \param size size of the buffer object region
2696 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2698 struct gl_buffer_object
*bufObj
,
2702 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2703 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2707 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2708 _mesa_error(ctx
, GL_INVALID_VALUE
,
2709 "glBindBufferRange(offset misalgned %d/%d)", (int) offset
,
2710 ctx
->Const
.UniformBufferOffsetAlignment
);
2714 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2719 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2720 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2725 * Bind a buffer object to a uniform block binding point.
2726 * As above, but offset = 0.
2729 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2731 struct gl_buffer_object
*bufObj
)
2733 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2734 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2738 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2740 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2741 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2743 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2747 * Binds a buffer object to an atomic buffer binding point.
2749 * The caller is responsible for validating the offset,
2750 * flushing the vertices and updating NewDriverState.
2753 set_atomic_buffer_binding(struct gl_context
*ctx
,
2754 struct gl_atomic_buffer_binding
*binding
,
2755 struct gl_buffer_object
*bufObj
,
2759 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2761 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2762 binding
->Offset
= -1;
2765 binding
->Offset
= offset
;
2766 binding
->Size
= size
;
2771 * Binds a buffer object to an atomic buffer binding point.
2773 * Unlike set_atomic_buffer_binding(), this function also validates the
2774 * index and offset, flushes vertices, and updates NewDriverState.
2775 * It also checks if the binding has actually changing before
2779 bind_atomic_buffer(struct gl_context
*ctx
,
2781 struct gl_buffer_object
*bufObj
,
2786 struct gl_atomic_buffer_binding
*binding
;
2788 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2789 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2793 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2794 _mesa_error(ctx
, GL_INVALID_VALUE
,
2795 "%s(offset misalgned %d/%d)", name
, (int) offset
,
2796 ATOMIC_COUNTER_SIZE
);
2800 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2802 binding
= &ctx
->AtomicBufferBindings
[index
];
2803 if (binding
->BufferObject
== bufObj
&&
2804 binding
->Offset
== offset
&&
2805 binding
->Size
== size
) {
2809 FLUSH_VERTICES(ctx
, 0);
2810 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2812 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
2816 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
2818 const GLintptr
*offsets
,
2819 const GLsizeiptr
*sizes
)
2821 if (offsets
[index
] < 0) {
2822 /* The ARB_multi_bind spec says:
2824 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2825 * value in <offsets> is less than zero (per binding)."
2827 _mesa_error(ctx
, GL_INVALID_VALUE
,
2828 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
2829 index
, (int64_t) offsets
[index
]);
2833 if (sizes
[index
] <= 0) {
2834 /* The ARB_multi_bind spec says:
2836 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2837 * value in <sizes> is less than or equal to zero (per binding)."
2839 _mesa_error(ctx
, GL_INVALID_VALUE
,
2840 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
2841 index
, (int64_t) sizes
[index
]);
2849 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
2850 GLuint first
, GLsizei count
,
2853 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
2854 _mesa_error(ctx
, GL_INVALID_ENUM
,
2855 "%s(target=GL_UNIFORM_BUFFER)", caller
);
2859 /* The ARB_multi_bind_spec says:
2861 * "An INVALID_OPERATION error is generated if <first> + <count> is
2862 * greater than the number of target-specific indexed binding points,
2863 * as described in section 6.7.1."
2865 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
2866 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2867 "%s(first=%u + count=%d > the value of "
2868 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
2869 caller
, first
, count
,
2870 ctx
->Const
.MaxUniformBufferBindings
);
2878 * Unbind all uniform buffers in the range
2879 * <first> through <first>+<count>-1
2882 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
2884 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
2887 for (i
= 0; i
< count
; i
++)
2888 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
2889 bufObj
, -1, -1, GL_TRUE
);
2893 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2894 const GLuint
*buffers
)
2898 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
2901 /* Assume that at least one binding will be changed */
2902 FLUSH_VERTICES(ctx
, 0);
2903 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2906 /* The ARB_multi_bind spec says:
2908 * "If <buffers> is NULL, all bindings from <first> through
2909 * <first>+<count>-1 are reset to their unbound (zero) state."
2911 unbind_uniform_buffers(ctx
, first
, count
);
2915 /* Note that the error semantics for multi-bind commands differ from
2916 * those of other GL commands.
2918 * The Issues section in the ARB_multi_bind spec says:
2920 * "(11) Typically, OpenGL specifies that if an error is generated by a
2921 * command, that command has no effect. This is somewhat
2922 * unfortunate for multi-bind commands, because it would require a
2923 * first pass to scan the entire list of bound objects for errors
2924 * and then a second pass to actually perform the bindings.
2925 * Should we have different error semantics?
2927 * RESOLVED: Yes. In this specification, when the parameters for
2928 * one of the <count> binding points are invalid, that binding point
2929 * is not updated and an error will be generated. However, other
2930 * binding points in the same command will be updated if their
2931 * parameters are valid and no other error occurs."
2934 _mesa_begin_bufferobj_lookups(ctx
);
2936 for (i
= 0; i
< count
; i
++) {
2937 struct gl_uniform_buffer_binding
*binding
=
2938 &ctx
->UniformBufferBindings
[first
+ i
];
2939 struct gl_buffer_object
*bufObj
;
2941 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
2942 bufObj
= binding
->BufferObject
;
2944 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
2945 "glBindBuffersBase");
2948 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2949 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
2951 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
2955 _mesa_end_bufferobj_lookups(ctx
);
2959 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2960 const GLuint
*buffers
,
2961 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
2965 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
2966 "glBindBuffersRange"))
2969 /* Assume that at least one binding will be changed */
2970 FLUSH_VERTICES(ctx
, 0);
2971 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2974 /* The ARB_multi_bind spec says:
2976 * "If <buffers> is NULL, all bindings from <first> through
2977 * <first>+<count>-1 are reset to their unbound (zero) state.
2978 * In this case, the offsets and sizes associated with the
2979 * binding points are set to default values, ignoring
2980 * <offsets> and <sizes>."
2982 unbind_uniform_buffers(ctx
, first
, count
);
2986 /* Note that the error semantics for multi-bind commands differ from
2987 * those of other GL commands.
2989 * The Issues section in the ARB_multi_bind spec says:
2991 * "(11) Typically, OpenGL specifies that if an error is generated by a
2992 * command, that command has no effect. This is somewhat
2993 * unfortunate for multi-bind commands, because it would require a
2994 * first pass to scan the entire list of bound objects for errors
2995 * and then a second pass to actually perform the bindings.
2996 * Should we have different error semantics?
2998 * RESOLVED: Yes. In this specification, when the parameters for
2999 * one of the <count> binding points are invalid, that binding point
3000 * is not updated and an error will be generated. However, other
3001 * binding points in the same command will be updated if their
3002 * parameters are valid and no other error occurs."
3005 _mesa_begin_bufferobj_lookups(ctx
);
3007 for (i
= 0; i
< count
; i
++) {
3008 struct gl_uniform_buffer_binding
*binding
=
3009 &ctx
->UniformBufferBindings
[first
+ i
];
3010 struct gl_buffer_object
*bufObj
;
3012 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3015 /* The ARB_multi_bind spec says:
3017 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3018 * pair of values in <offsets> and <sizes> does not respectively
3019 * satisfy the constraints described for those parameters for the
3020 * specified target, as described in section 6.7.1 (per binding)."
3022 * Section 6.7.1 refers to table 6.5, which says:
3024 * "┌───────────────────────────────────────────────────────────────┐
3025 * │ Uniform buffer array bindings (see sec. 7.6) │
3026 * ├─────────────────────┬─────────────────────────────────────────┤
3028 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3029 * │ │ OFFSET_ALIGNMENT │
3031 * │ size restriction │ none │
3032 * └─────────────────────┴─────────────────────────────────────────┘"
3034 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3035 _mesa_error(ctx
, GL_INVALID_VALUE
,
3036 "glBindBuffersRange(offsets[%u]=%" PRId64
3037 " is misaligned; it must be a multiple of the value of "
3038 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3039 "target=GL_UNIFORM_BUFFER)",
3040 i
, (int64_t) offsets
[i
],
3041 ctx
->Const
.UniformBufferOffsetAlignment
);
3045 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3046 bufObj
= binding
->BufferObject
;
3048 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3049 "glBindBuffersRange");
3052 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3053 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3055 set_ubo_binding(ctx
, binding
, bufObj
,
3056 offsets
[i
], sizes
[i
], GL_FALSE
);
3060 _mesa_end_bufferobj_lookups(ctx
);
3064 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3065 struct gl_transform_feedback_object
*tfObj
,
3066 GLuint first
, GLsizei count
, const char *caller
)
3068 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3069 _mesa_error(ctx
, GL_INVALID_ENUM
,
3070 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3074 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3076 * "An INVALID_OPERATION error is generated :
3079 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3080 * FEEDBACK_BUFFER and transform feedback is currently active."
3082 * We assume that this is also meant to apply to BindBuffersRange
3083 * and BindBuffersBase.
3085 if (tfObj
->Active
) {
3086 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3087 "%s(Changing transform feedback buffers while "
3088 "transform feedback is active)", caller
);
3092 /* The ARB_multi_bind_spec says:
3094 * "An INVALID_OPERATION error is generated if <first> + <count> is
3095 * greater than the number of target-specific indexed binding points,
3096 * as described in section 6.7.1."
3098 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3100 "%s(first=%u + count=%d > the value of "
3101 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3102 caller
, first
, count
,
3103 ctx
->Const
.MaxTransformFeedbackBuffers
);
3111 * Unbind all transform feedback buffers in the range
3112 * <first> through <first>+<count>-1
3115 unbind_xfb_buffers(struct gl_context
*ctx
,
3116 struct gl_transform_feedback_object
*tfObj
,
3117 GLuint first
, GLsizei count
)
3119 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3122 for (i
= 0; i
< count
; i
++)
3123 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3128 bind_xfb_buffers_base(struct gl_context
*ctx
,
3129 GLuint first
, GLsizei count
,
3130 const GLuint
*buffers
)
3132 struct gl_transform_feedback_object
*tfObj
=
3133 ctx
->TransformFeedback
.CurrentObject
;
3136 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3137 "glBindBuffersBase"))
3140 /* Assume that at least one binding will be changed */
3141 FLUSH_VERTICES(ctx
, 0);
3142 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3145 /* The ARB_multi_bind spec says:
3147 * "If <buffers> is NULL, all bindings from <first> through
3148 * <first>+<count>-1 are reset to their unbound (zero) state."
3150 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3154 /* Note that the error semantics for multi-bind commands differ from
3155 * those of other GL commands.
3157 * The Issues section in the ARB_multi_bind spec says:
3159 * "(11) Typically, OpenGL specifies that if an error is generated by a
3160 * command, that command has no effect. This is somewhat
3161 * unfortunate for multi-bind commands, because it would require a
3162 * first pass to scan the entire list of bound objects for errors
3163 * and then a second pass to actually perform the bindings.
3164 * Should we have different error semantics?
3166 * RESOLVED: Yes. In this specification, when the parameters for
3167 * one of the <count> binding points are invalid, that binding point
3168 * is not updated and an error will be generated. However, other
3169 * binding points in the same command will be updated if their
3170 * parameters are valid and no other error occurs."
3173 _mesa_begin_bufferobj_lookups(ctx
);
3175 for (i
= 0; i
< count
; i
++) {
3176 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3177 struct gl_buffer_object
*bufObj
;
3179 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3180 bufObj
= boundBufObj
;
3182 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3183 "glBindBuffersBase");
3186 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3190 _mesa_end_bufferobj_lookups(ctx
);
3194 bind_xfb_buffers_range(struct gl_context
*ctx
,
3195 GLuint first
, GLsizei count
,
3196 const GLuint
*buffers
,
3197 const GLintptr
*offsets
,
3198 const GLsizeiptr
*sizes
)
3200 struct gl_transform_feedback_object
*tfObj
=
3201 ctx
->TransformFeedback
.CurrentObject
;
3204 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3205 "glBindBuffersRange"))
3208 /* Assume that at least one binding will be changed */
3209 FLUSH_VERTICES(ctx
, 0);
3210 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3213 /* The ARB_multi_bind spec says:
3215 * "If <buffers> is NULL, all bindings from <first> through
3216 * <first>+<count>-1 are reset to their unbound (zero) state.
3217 * In this case, the offsets and sizes associated with the
3218 * binding points are set to default values, ignoring
3219 * <offsets> and <sizes>."
3221 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3225 /* Note that the error semantics for multi-bind commands differ from
3226 * those of other GL commands.
3228 * The Issues section in the ARB_multi_bind spec says:
3230 * "(11) Typically, OpenGL specifies that if an error is generated by a
3231 * command, that command has no effect. This is somewhat
3232 * unfortunate for multi-bind commands, because it would require a
3233 * first pass to scan the entire list of bound objects for errors
3234 * and then a second pass to actually perform the bindings.
3235 * Should we have different error semantics?
3237 * RESOLVED: Yes. In this specification, when the parameters for
3238 * one of the <count> binding points are invalid, that binding point
3239 * is not updated and an error will be generated. However, other
3240 * binding points in the same command will be updated if their
3241 * parameters are valid and no other error occurs."
3244 _mesa_begin_bufferobj_lookups(ctx
);
3246 for (i
= 0; i
< count
; i
++) {
3247 const GLuint index
= first
+ i
;
3248 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3249 struct gl_buffer_object
*bufObj
;
3251 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3254 /* The ARB_multi_bind spec says:
3256 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3257 * pair of values in <offsets> and <sizes> does not respectively
3258 * satisfy the constraints described for those parameters for the
3259 * specified target, as described in section 6.7.1 (per binding)."
3261 * Section 6.7.1 refers to table 6.5, which says:
3263 * "┌───────────────────────────────────────────────────────────────┐
3264 * │ Transform feedback array bindings (see sec. 13.2.2) │
3265 * ├───────────────────────┬───────────────────────────────────────┤
3267 * │ offset restriction │ multiple of 4 │
3269 * │ size restriction │ multiple of 4 │
3270 * └───────────────────────┴───────────────────────────────────────┘"
3272 if (offsets
[i
] & 0x3) {
3273 _mesa_error(ctx
, GL_INVALID_VALUE
,
3274 "glBindBuffersRange(offsets[%u]=%" PRId64
3275 " is misaligned; it must be a multiple of 4 when "
3276 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3277 i
, (int64_t) offsets
[i
]);
3281 if (sizes
[i
] & 0x3) {
3282 _mesa_error(ctx
, GL_INVALID_VALUE
,
3283 "glBindBuffersRange(sizes[%u]=%" PRId64
3284 " is misaligned; it must be a multiple of 4 when "
3285 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3286 i
, (int64_t) sizes
[i
]);
3290 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3291 bufObj
= boundBufObj
;
3293 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3294 "glBindBuffersRange");
3297 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
3298 offsets
[i
], sizes
[i
]);
3301 _mesa_end_bufferobj_lookups(ctx
);
3305 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
3306 GLuint first
, GLsizei count
,
3309 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
3310 _mesa_error(ctx
, GL_INVALID_ENUM
,
3311 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
3315 /* The ARB_multi_bind_spec says:
3317 * "An INVALID_OPERATION error is generated if <first> + <count> is
3318 * greater than the number of target-specific indexed binding points,
3319 * as described in section 6.7.1."
3321 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
3322 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3323 "%s(first=%u + count=%d > the value of "
3324 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
3325 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
3333 * Unbind all atomic counter buffers in the range
3334 * <first> through <first>+<count>-1
3337 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3339 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3342 for (i
= 0; i
< count
; i
++)
3343 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
3348 bind_atomic_buffers_base(struct gl_context
*ctx
,
3351 const GLuint
*buffers
)
3355 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3356 "glBindBuffersBase"))
3359 /* Assume that at least one binding will be changed */
3360 FLUSH_VERTICES(ctx
, 0);
3361 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3364 /* The ARB_multi_bind spec says:
3366 * "If <buffers> is NULL, all bindings from <first> through
3367 * <first>+<count>-1 are reset to their unbound (zero) state."
3369 unbind_atomic_buffers(ctx
, first
, count
);
3373 /* Note that the error semantics for multi-bind commands differ from
3374 * those of other GL commands.
3376 * The Issues section in the ARB_multi_bind spec says:
3378 * "(11) Typically, OpenGL specifies that if an error is generated by a
3379 * command, that command has no effect. This is somewhat
3380 * unfortunate for multi-bind commands, because it would require a
3381 * first pass to scan the entire list of bound objects for errors
3382 * and then a second pass to actually perform the bindings.
3383 * Should we have different error semantics?
3385 * RESOLVED: Yes. In this specification, when the parameters for
3386 * one of the <count> binding points are invalid, that binding point
3387 * is not updated and an error will be generated. However, other
3388 * binding points in the same command will be updated if their
3389 * parameters are valid and no other error occurs."
3392 _mesa_begin_bufferobj_lookups(ctx
);
3394 for (i
= 0; i
< count
; i
++) {
3395 struct gl_atomic_buffer_binding
*binding
=
3396 &ctx
->AtomicBufferBindings
[first
+ i
];
3397 struct gl_buffer_object
*bufObj
;
3399 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3400 bufObj
= binding
->BufferObject
;
3402 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3403 "glBindBuffersBase");
3406 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
3409 _mesa_end_bufferobj_lookups(ctx
);
3413 bind_atomic_buffers_range(struct gl_context
*ctx
,
3416 const GLuint
*buffers
,
3417 const GLintptr
*offsets
,
3418 const GLsizeiptr
*sizes
)
3422 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3423 "glBindBuffersRange"))
3426 /* Assume that at least one binding will be changed */
3427 FLUSH_VERTICES(ctx
, 0);
3428 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3431 /* The ARB_multi_bind spec says:
3433 * "If <buffers> is NULL, all bindings from <first> through
3434 * <first>+<count>-1 are reset to their unbound (zero) state.
3435 * In this case, the offsets and sizes associated with the
3436 * binding points are set to default values, ignoring
3437 * <offsets> and <sizes>."
3439 unbind_atomic_buffers(ctx
, first
, count
);
3443 /* Note that the error semantics for multi-bind commands differ from
3444 * those of other GL commands.
3446 * The Issues section in the ARB_multi_bind spec says:
3448 * "(11) Typically, OpenGL specifies that if an error is generated by a
3449 * command, that command has no effect. This is somewhat
3450 * unfortunate for multi-bind commands, because it would require a
3451 * first pass to scan the entire list of bound objects for errors
3452 * and then a second pass to actually perform the bindings.
3453 * Should we have different error semantics?
3455 * RESOLVED: Yes. In this specification, when the parameters for
3456 * one of the <count> binding points are invalid, that binding point
3457 * is not updated and an error will be generated. However, other
3458 * binding points in the same command will be updated if their
3459 * parameters are valid and no other error occurs."
3462 _mesa_begin_bufferobj_lookups(ctx
);
3464 for (i
= 0; i
< count
; i
++) {
3465 struct gl_atomic_buffer_binding
*binding
=
3466 &ctx
->AtomicBufferBindings
[first
+ i
];
3467 struct gl_buffer_object
*bufObj
;
3469 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3472 /* The ARB_multi_bind spec says:
3474 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3475 * pair of values in <offsets> and <sizes> does not respectively
3476 * satisfy the constraints described for those parameters for the
3477 * specified target, as described in section 6.7.1 (per binding)."
3479 * Section 6.7.1 refers to table 6.5, which says:
3481 * "┌───────────────────────────────────────────────────────────────┐
3482 * │ Atomic counter array bindings (see sec. 7.7.2) │
3483 * ├───────────────────────┬───────────────────────────────────────┤
3485 * │ offset restriction │ multiple of 4 │
3487 * │ size restriction │ none │
3488 * └───────────────────────┴───────────────────────────────────────┘"
3490 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
3491 _mesa_error(ctx
, GL_INVALID_VALUE
,
3492 "glBindBuffersRange(offsets[%u]=%" PRId64
3493 " is misaligned; it must be a multiple of %d when "
3494 "target=GL_ATOMIC_COUNTER_BUFFER)",
3495 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
3499 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3500 bufObj
= binding
->BufferObject
;
3502 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3503 "glBindBuffersRange");
3506 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
3509 _mesa_end_bufferobj_lookups(ctx
);
3513 _mesa_BindBufferRange(GLenum target
, GLuint index
,
3514 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
3516 GET_CURRENT_CONTEXT(ctx
);
3517 struct gl_buffer_object
*bufObj
;
3520 bufObj
= ctx
->Shared
->NullBufferObj
;
3522 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3524 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3525 &bufObj
, "glBindBufferRange"))
3529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3530 "glBindBufferRange(invalid buffer=%u)", buffer
);
3536 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
3543 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3544 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
3547 case GL_UNIFORM_BUFFER
:
3548 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
3550 case GL_ATOMIC_COUNTER_BUFFER
:
3551 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
3552 "glBindBufferRange");
3555 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
3561 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
3563 GET_CURRENT_CONTEXT(ctx
);
3564 struct gl_buffer_object
*bufObj
;
3567 bufObj
= ctx
->Shared
->NullBufferObj
;
3569 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3571 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3572 &bufObj
, "glBindBufferBase"))
3576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3577 "glBindBufferBase(invalid buffer=%u)", buffer
);
3581 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
3582 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
3584 * "BindBufferBase is equivalent to calling BindBufferRange with offset
3585 * zero and size equal to the size of buffer."
3587 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
3589 * "If the parameter (starting offset or size) was not specified when the
3590 * buffer object was bound, zero is returned."
3592 * What happens if the size of the buffer changes? Does the size of the
3593 * buffer at the moment glBindBufferBase was called still play a role, like
3594 * the first quote would imply, or is the size meaningless in the
3595 * glBindBufferBase case like the second quote would suggest? The GL 4.1
3596 * core spec page 45 says:
3598 * "It is equivalent to calling BindBufferRange with offset zero, while
3599 * size is determined by the size of the bound buffer at the time the
3602 * My interpretation is that the GL 4.1 spec was a clarification of the
3603 * behavior, not a change. In particular, this choice will only make
3604 * rendering work in cases where it would have had undefined results.
3608 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3609 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
3611 case GL_UNIFORM_BUFFER
:
3612 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
3614 case GL_ATOMIC_COUNTER_BUFFER
:
3615 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
3616 "glBindBufferBase");
3619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
3625 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
3626 const GLuint
*buffers
,
3627 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3629 GET_CURRENT_CONTEXT(ctx
);
3632 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3633 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3635 case GL_UNIFORM_BUFFER
:
3636 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3638 case GL_ATOMIC_COUNTER_BUFFER
:
3639 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
3643 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
3644 _mesa_lookup_enum_by_nr(target
));
3650 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
3651 const GLuint
*buffers
)
3653 GET_CURRENT_CONTEXT(ctx
);
3656 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3657 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
3659 case GL_UNIFORM_BUFFER
:
3660 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
3662 case GL_ATOMIC_COUNTER_BUFFER
:
3663 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
3666 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
3667 _mesa_lookup_enum_by_nr(target
));
3673 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
3676 GET_CURRENT_CONTEXT(ctx
);
3677 struct gl_buffer_object
*bufObj
;
3678 const GLintptr end
= offset
+ length
;
3680 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3682 _mesa_error(ctx
, GL_INVALID_VALUE
,
3683 "glInvalidateBufferSubData(name = 0x%x) invalid object",
3688 /* The GL_ARB_invalidate_subdata spec says:
3690 * "An INVALID_VALUE error is generated if <offset> or <length> is
3691 * negative, or if <offset> + <length> is greater than the value of
3694 if (end
< 0 || end
> bufObj
->Size
) {
3695 _mesa_error(ctx
, GL_INVALID_VALUE
,
3696 "glInvalidateBufferSubData(invalid offset or length)");
3700 /* The OpenGL 4.4 (Core Profile) spec says:
3702 * "An INVALID_OPERATION error is generated if buffer is currently
3703 * mapped by MapBuffer or if the invalidate range intersects the range
3704 * currently mapped by MapBufferRange, unless it was mapped
3705 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3707 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
3708 bufferobj_range_mapped(bufObj
, offset
, length
)) {
3709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3710 "glInvalidateBufferSubData(intersection with mapped "
3715 /* We don't actually do anything for this yet. Just return after
3716 * validating the parameters and generating the required errors.
3722 _mesa_InvalidateBufferData(GLuint buffer
)
3724 GET_CURRENT_CONTEXT(ctx
);
3725 struct gl_buffer_object
*bufObj
;
3727 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3729 _mesa_error(ctx
, GL_INVALID_VALUE
,
3730 "glInvalidateBufferData(name = 0x%x) invalid object",
3735 /* The OpenGL 4.4 (Core Profile) spec says:
3737 * "An INVALID_OPERATION error is generated if buffer is currently
3738 * mapped by MapBuffer or if the invalidate range intersects the range
3739 * currently mapped by MapBufferRange, unless it was mapped
3740 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3742 if (_mesa_check_disallowed_mapping(bufObj
)) {
3743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3744 "glInvalidateBufferData(intersection with mapped "
3749 /* We don't actually do anything for this yet. Just return after
3750 * validating the parameters and generating the required errors.