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 _mesa_is_gles31(ctx
)) {
97 return &ctx
->DrawIndirectBuffer
;
100 case GL_TRANSFORM_FEEDBACK_BUFFER
:
101 if (ctx
->Extensions
.EXT_transform_feedback
) {
102 return &ctx
->TransformFeedback
.CurrentBuffer
;
105 case GL_TEXTURE_BUFFER
:
106 if (ctx
->API
== API_OPENGL_CORE
&&
107 ctx
->Extensions
.ARB_texture_buffer_object
) {
108 return &ctx
->Texture
.BufferObject
;
111 case GL_UNIFORM_BUFFER
:
112 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
113 return &ctx
->UniformBuffer
;
116 case GL_SHADER_STORAGE_BUFFER
:
117 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
118 return &ctx
->ShaderStorageBuffer
;
121 case GL_ATOMIC_COUNTER_BUFFER
:
122 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
123 return &ctx
->AtomicBuffer
;
126 case GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
:
127 if (ctx
->Extensions
.AMD_pinned_memory
) {
128 return &ctx
->ExternalVirtualMemoryBuffer
;
139 * Get the buffer object bound to the specified target in a GL context.
140 * \param ctx the GL context
141 * \param target the buffer object target to be retrieved.
142 * \param error the GL error to record if target is illegal.
143 * \return pointer to the buffer object bound to \c target in the
144 * specified context or \c NULL if \c target is invalid.
146 static inline struct gl_buffer_object
*
147 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
150 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
153 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
157 if (!_mesa_is_bufferobj(*bufObj
)) {
158 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
167 * Convert a GLbitfield describing the mapped buffer access flags
168 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
171 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
173 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
174 if ((access
& rwFlags
) == rwFlags
)
175 return GL_READ_WRITE
;
176 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
178 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
179 return GL_WRITE_ONLY
;
181 /* Otherwise, AccessFlags is zero (the default state).
183 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
185 * Name Type Initial Value Legal Values
187 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
190 * However, table 6.8 in the GL_OES_mapbuffer extension says:
192 * Get Value Type Get Command Value Description
193 * --------- ---- ----------- ----- -----------
194 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
196 * The difference is because GL_OES_mapbuffer only supports mapping buffers
201 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
206 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
208 * The regions do not overlap if and only if the end of the given
209 * region is before the mapped region or the start of the given region
210 * is after the mapped region.
212 * \param obj Buffer object target on which to operate.
213 * \param offset Offset of the first byte of the subdata range.
214 * \param size Size, in bytes, of the subdata range.
215 * \return true if ranges overlap, false otherwise
219 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
220 GLintptr offset
, GLsizeiptr size
)
222 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
223 const GLintptr end
= offset
+ size
;
224 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
225 obj
->Mappings
[MAP_USER
].Length
;
227 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
236 * Tests the subdata range parameters and sets the GL error code for
237 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
238 * \c glClearBufferSubData.
240 * \param ctx GL context.
241 * \param bufObj The buffer object.
242 * \param offset Offset of the first byte of the subdata range.
243 * \param size Size, in bytes, of the subdata range.
244 * \param mappedRange If true, checks if an overlapping range is mapped.
245 * If false, checks if buffer is mapped.
246 * \param caller Name of calling function for recording errors.
247 * \return false if error, true otherwise
249 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
252 buffer_object_subdata_range_good(struct gl_context
*ctx
,
253 struct gl_buffer_object
*bufObj
,
254 GLintptr offset
, GLsizeiptr size
,
255 bool mappedRange
, const char *caller
)
258 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
263 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
267 if (offset
+ size
> bufObj
->Size
) {
268 _mesa_error(ctx
, GL_INVALID_VALUE
,
269 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
270 (unsigned long) offset
,
271 (unsigned long) size
,
272 (unsigned long) bufObj
->Size
);
276 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
280 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
282 "%s(range is mapped without persistent bit)",
288 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
289 _mesa_error(ctx
, GL_INVALID_OPERATION
,
290 "%s(buffer is mapped without persistent bit)",
301 * Test the format and type parameters and set the GL error code for
302 * \c glClearBufferData and \c glClearBufferSubData.
304 * \param ctx GL context.
305 * \param internalformat Format to which the data is to be converted.
306 * \param format Format of the supplied data.
307 * \param type Type of the supplied data.
308 * \param caller Name of calling function for recording errors.
309 * \return If internalformat, format and type are legal the mesa_format
310 * corresponding to internalformat, otherwise MESA_FORMAT_NONE.
312 * \sa glClearBufferData and glClearBufferSubData
315 validate_clear_buffer_format(struct gl_context
*ctx
,
316 GLenum internalformat
,
317 GLenum format
, GLenum type
,
320 mesa_format mesaFormat
;
321 GLenum errorFormatType
;
323 mesaFormat
= _mesa_validate_texbuffer_format(ctx
, internalformat
);
324 if (mesaFormat
== MESA_FORMAT_NONE
) {
325 _mesa_error(ctx
, GL_INVALID_ENUM
,
326 "%s(invalid internalformat)", caller
);
327 return MESA_FORMAT_NONE
;
330 /* NOTE: not mentioned in ARB_clear_buffer_object but according to
331 * EXT_texture_integer there is no conversion between integer and
332 * non-integer formats
334 if (_mesa_is_enum_format_signed_int(format
) !=
335 _mesa_is_format_integer_color(mesaFormat
)) {
336 _mesa_error(ctx
, GL_INVALID_OPERATION
,
337 "%s(integer vs non-integer)", caller
);
338 return MESA_FORMAT_NONE
;
341 if (!_mesa_is_color_format(format
)) {
342 _mesa_error(ctx
, GL_INVALID_ENUM
,
343 "%s(format is not a color format)", caller
);
344 return MESA_FORMAT_NONE
;
347 errorFormatType
= _mesa_error_check_format_and_type(ctx
, format
, type
);
348 if (errorFormatType
!= GL_NO_ERROR
) {
349 _mesa_error(ctx
, GL_INVALID_ENUM
,
350 "%s(invalid format or type)", caller
);
351 return MESA_FORMAT_NONE
;
359 * Convert user-specified clear value to the specified internal format.
361 * \param ctx GL context.
362 * \param internalformat Format to which the data is converted.
363 * \param clearValue Points to the converted clear value.
364 * \param format Format of the supplied data.
365 * \param type Type of the supplied data.
366 * \param data Data which is to be converted to internalformat.
367 * \param caller Name of calling function for recording errors.
368 * \return true if data could be converted, false otherwise.
370 * \sa glClearBufferData, glClearBufferSubData
373 convert_clear_buffer_data(struct gl_context
*ctx
,
374 mesa_format internalformat
,
375 GLubyte
*clearValue
, GLenum format
, GLenum type
,
376 const GLvoid
*data
, const char *caller
)
378 GLenum internalformatBase
= _mesa_get_format_base_format(internalformat
);
380 if (_mesa_texstore(ctx
, 1, internalformatBase
, internalformat
,
381 0, &clearValue
, 1, 1, 1,
382 format
, type
, data
, &ctx
->Unpack
)) {
386 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
393 * Allocate and initialize a new buffer object.
395 * Default callback for the \c dd_function_table::NewBufferObject() hook.
397 static struct gl_buffer_object
*
398 _mesa_new_buffer_object(struct gl_context
*ctx
, GLuint name
)
400 struct gl_buffer_object
*obj
;
404 obj
= MALLOC_STRUCT(gl_buffer_object
);
405 _mesa_initialize_buffer_object(ctx
, obj
, name
);
411 * Delete a buffer object.
413 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
416 _mesa_delete_buffer_object(struct gl_context
*ctx
,
417 struct gl_buffer_object
*bufObj
)
421 _mesa_align_free(bufObj
->Data
);
423 /* assign strange values here to help w/ debugging */
424 bufObj
->RefCount
= -1000;
427 mtx_destroy(&bufObj
->Mutex
);
435 * Set ptr to bufObj w/ reference counting.
436 * This is normally only called from the _mesa_reference_buffer_object() macro
437 * when there's a real pointer change.
440 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
441 struct gl_buffer_object
**ptr
,
442 struct gl_buffer_object
*bufObj
)
445 /* Unreference the old buffer */
446 GLboolean deleteFlag
= GL_FALSE
;
447 struct gl_buffer_object
*oldObj
= *ptr
;
449 mtx_lock(&oldObj
->Mutex
);
450 assert(oldObj
->RefCount
> 0);
453 printf("BufferObj %p %d DECR to %d\n",
454 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
456 deleteFlag
= (oldObj
->RefCount
== 0);
457 mtx_unlock(&oldObj
->Mutex
);
461 /* some sanity checking: don't delete a buffer still in use */
463 /* unfortunately, these tests are invalid during context tear-down */
464 assert(ctx
->Array
.ArrayBufferObj
!= bufObj
);
465 assert(ctx
->Array
.VAO
->IndexBufferObj
!= bufObj
);
466 assert(ctx
->Array
.VAO
->Vertex
.BufferObj
!= bufObj
);
469 assert(ctx
->Driver
.DeleteBuffer
);
470 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
478 /* reference new buffer */
479 mtx_lock(&bufObj
->Mutex
);
480 if (bufObj
->RefCount
== 0) {
481 /* this buffer's being deleted (look just above) */
482 /* Not sure this can every really happen. Warn if it does. */
483 _mesa_problem(NULL
, "referencing deleted buffer object");
489 printf("BufferObj %p %d INCR to %d\n",
490 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
494 mtx_unlock(&bufObj
->Mutex
);
500 * Initialize a buffer object to default values.
503 _mesa_initialize_buffer_object(struct gl_context
*ctx
,
504 struct gl_buffer_object
*obj
,
507 memset(obj
, 0, sizeof(struct gl_buffer_object
));
508 mtx_init(&obj
->Mutex
, mtx_plain
);
511 obj
->Usage
= GL_STATIC_DRAW_ARB
;
517 * Callback called from _mesa_HashWalk()
520 count_buffer_size(GLuint key
, void *data
, void *userData
)
522 const struct gl_buffer_object
*bufObj
=
523 (const struct gl_buffer_object
*) data
;
524 GLuint
*total
= (GLuint
*) userData
;
526 *total
= *total
+ bufObj
->Size
;
531 * Compute total size (in bytes) of all buffer objects for the given context.
532 * For debugging purposes.
535 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
539 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
546 * Allocate space for and store data in a buffer object. Any data that was
547 * previously stored in the buffer object is lost. If \c data is \c NULL,
548 * memory will be allocated, but no copy will occur.
550 * This is the default callback for \c dd_function_table::BufferData()
551 * Note that all GL error checking will have been done already.
553 * \param ctx GL context.
554 * \param target Buffer object target on which to operate.
555 * \param size Size, in bytes, of the new data store.
556 * \param data Pointer to the data to store in the buffer object. This
557 * pointer may be \c NULL.
558 * \param usage Hints about how the data will be used.
559 * \param bufObj Object to be used.
561 * \return GL_TRUE for success, GL_FALSE for failure
562 * \sa glBufferDataARB, dd_function_table::BufferData.
565 buffer_data_fallback(struct gl_context
*ctx
, GLenum target
, GLsizeiptr size
,
566 const GLvoid
*data
, GLenum usage
, GLenum storageFlags
,
567 struct gl_buffer_object
*bufObj
)
573 _mesa_align_free( bufObj
->Data
);
575 new_data
= _mesa_align_malloc( size
, ctx
->Const
.MinMapBufferAlignment
);
577 bufObj
->Data
= (GLubyte
*) new_data
;
579 bufObj
->Usage
= usage
;
580 bufObj
->StorageFlags
= storageFlags
;
583 memcpy( bufObj
->Data
, data
, size
);
595 * Replace data in a subrange of buffer object. If the data range
596 * specified by \c size + \c offset extends beyond the end of the buffer or
597 * if \c data is \c NULL, no copy is performed.
599 * This is the default callback for \c dd_function_table::BufferSubData()
600 * Note that all GL error checking will have been done already.
602 * \param ctx GL context.
603 * \param offset Offset of the first byte to be modified.
604 * \param size Size, in bytes, of the data range.
605 * \param data Pointer to the data to store in the buffer object.
606 * \param bufObj Object to be used.
608 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
611 buffer_sub_data_fallback(struct gl_context
*ctx
, GLintptr offset
,
612 GLsizeiptr size
, const GLvoid
*data
,
613 struct gl_buffer_object
*bufObj
)
617 /* this should have been caught in _mesa_BufferSubData() */
618 assert(size
+ offset
<= bufObj
->Size
);
621 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
627 * Retrieve data from a subrange of buffer object. If the data range
628 * specified by \c size + \c offset extends beyond the end of the buffer or
629 * if \c data is \c NULL, no copy is performed.
631 * This is the default callback for \c dd_function_table::GetBufferSubData()
632 * Note that all GL error checking will have been done already.
634 * \param ctx GL context.
635 * \param target Buffer object target on which to operate.
636 * \param offset Offset of the first byte to be fetched.
637 * \param size Size, in bytes, of the data range.
638 * \param data Destination for data
639 * \param bufObj Object to be used.
641 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
644 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
645 GLsizeiptrARB size
, GLvoid
* data
,
646 struct gl_buffer_object
* bufObj
)
650 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
651 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
657 * Clear a subrange of the buffer object with copies of the supplied data.
658 * If data is NULL the buffer is filled with zeros.
660 * This is the default callback for \c dd_function_table::ClearBufferSubData()
661 * Note that all GL error checking will have been done already.
663 * \param ctx GL context.
664 * \param offset Offset of the first byte to be cleared.
665 * \param size Size, in bytes, of the to be cleared range.
666 * \param clearValue Source of the data.
667 * \param clearValueSize Size, in bytes, of the supplied data.
668 * \param bufObj Object to be cleared.
670 * \sa glClearBufferSubData, glClearBufferData and
671 * dd_function_table::ClearBufferSubData.
674 _mesa_ClearBufferSubData_sw(struct gl_context
*ctx
,
675 GLintptr offset
, GLsizeiptr size
,
676 const GLvoid
*clearValue
,
677 GLsizeiptr clearValueSize
,
678 struct gl_buffer_object
*bufObj
)
683 assert(ctx
->Driver
.MapBufferRange
);
684 dest
= ctx
->Driver
.MapBufferRange(ctx
, offset
, size
,
686 GL_MAP_INVALIDATE_RANGE_BIT
,
687 bufObj
, MAP_INTERNAL
);
690 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearBuffer[Sub]Data");
694 if (clearValue
== NULL
) {
695 /* Clear with zeros, per the spec */
696 memset(dest
, 0, size
);
697 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
701 for (i
= 0; i
< size
/clearValueSize
; ++i
) {
702 memcpy(dest
, clearValue
, clearValueSize
);
703 dest
+= clearValueSize
;
706 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
711 * Default fallback for \c dd_function_table::MapBufferRange().
712 * Called via glMapBufferRange().
715 map_buffer_range_fallback(struct gl_context
*ctx
, GLintptr offset
,
716 GLsizeiptr length
, GLbitfield access
,
717 struct gl_buffer_object
*bufObj
,
718 gl_map_buffer_index index
)
721 assert(!_mesa_bufferobj_mapped(bufObj
, index
));
722 /* Just return a direct pointer to the data */
723 bufObj
->Mappings
[index
].Pointer
= bufObj
->Data
+ offset
;
724 bufObj
->Mappings
[index
].Length
= length
;
725 bufObj
->Mappings
[index
].Offset
= offset
;
726 bufObj
->Mappings
[index
].AccessFlags
= access
;
727 return bufObj
->Mappings
[index
].Pointer
;
732 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
733 * Called via glFlushMappedBufferRange().
736 flush_mapped_buffer_range_fallback(struct gl_context
*ctx
,
737 GLintptr offset
, GLsizeiptr length
,
738 struct gl_buffer_object
*obj
,
739 gl_map_buffer_index index
)
750 * Default callback for \c dd_function_table::UnmapBuffer().
752 * The input parameters will have been already tested for errors.
754 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
757 unmap_buffer_fallback(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
758 gl_map_buffer_index index
)
761 /* XXX we might assert here that bufObj->Pointer is non-null */
762 bufObj
->Mappings
[index
].Pointer
= NULL
;
763 bufObj
->Mappings
[index
].Length
= 0;
764 bufObj
->Mappings
[index
].Offset
= 0;
765 bufObj
->Mappings
[index
].AccessFlags
= 0x0;
771 * Default fallback for \c dd_function_table::CopyBufferSubData().
772 * Called via glCopyBufferSubData().
775 copy_buffer_sub_data_fallback(struct gl_context
*ctx
,
776 struct gl_buffer_object
*src
,
777 struct gl_buffer_object
*dst
,
778 GLintptr readOffset
, GLintptr writeOffset
,
781 GLubyte
*srcPtr
, *dstPtr
;
784 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
786 GL_MAP_WRITE_BIT
, src
,
792 srcPtr
+= readOffset
;
793 dstPtr
+= writeOffset
;
795 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
796 GL_MAP_READ_BIT
, src
,
798 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
800 GL_MAP_INVALIDATE_RANGE_BIT
), dst
,
804 /* Note: the src and dst regions will never overlap. Trying to do so
805 * would generate GL_INVALID_VALUE earlier.
807 if (srcPtr
&& dstPtr
)
808 memcpy(dstPtr
, srcPtr
, size
);
810 ctx
->Driver
.UnmapBuffer(ctx
, src
, MAP_INTERNAL
);
812 ctx
->Driver
.UnmapBuffer(ctx
, dst
, MAP_INTERNAL
);
818 * Initialize the state associated with buffer objects
821 _mesa_init_buffer_objects( struct gl_context
*ctx
)
825 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
826 mtx_init(&DummyBufferObject
.Mutex
, mtx_plain
);
827 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
829 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
830 ctx
->Shared
->NullBufferObj
);
832 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
833 ctx
->Shared
->NullBufferObj
);
834 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
835 ctx
->Shared
->NullBufferObj
);
837 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
838 ctx
->Shared
->NullBufferObj
);
840 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
,
841 ctx
->Shared
->NullBufferObj
);
843 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
,
844 ctx
->Shared
->NullBufferObj
);
846 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
847 ctx
->Shared
->NullBufferObj
);
849 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
850 _mesa_reference_buffer_object(ctx
,
851 &ctx
->UniformBufferBindings
[i
].BufferObject
,
852 ctx
->Shared
->NullBufferObj
);
853 ctx
->UniformBufferBindings
[i
].Offset
= -1;
854 ctx
->UniformBufferBindings
[i
].Size
= -1;
857 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
858 _mesa_reference_buffer_object(ctx
,
859 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
860 ctx
->Shared
->NullBufferObj
);
861 ctx
->ShaderStorageBufferBindings
[i
].Offset
= -1;
862 ctx
->ShaderStorageBufferBindings
[i
].Size
= -1;
865 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
866 _mesa_reference_buffer_object(ctx
,
867 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
868 ctx
->Shared
->NullBufferObj
);
869 ctx
->AtomicBufferBindings
[i
].Offset
= -1;
870 ctx
->AtomicBufferBindings
[i
].Size
= -1;
876 _mesa_free_buffer_objects( struct gl_context
*ctx
)
880 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
882 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
883 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
885 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
887 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, NULL
);
889 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
891 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
893 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
894 _mesa_reference_buffer_object(ctx
,
895 &ctx
->UniformBufferBindings
[i
].BufferObject
,
899 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
900 _mesa_reference_buffer_object(ctx
,
901 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
905 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
906 _mesa_reference_buffer_object(ctx
,
907 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
914 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
917 struct gl_buffer_object
**buf_handle
,
920 struct gl_buffer_object
*buf
= *buf_handle
;
922 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
923 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
927 if (!buf
|| buf
== &DummyBufferObject
) {
928 /* If this is a new buffer object id, or one which was generated but
929 * never used before, allocate a buffer object now.
931 assert(ctx
->Driver
.NewBufferObject
);
932 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
);
934 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
937 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
945 * Bind the specified target to buffer for the specified context.
946 * Called by glBindBuffer() and other functions.
949 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
951 struct gl_buffer_object
*oldBufObj
;
952 struct gl_buffer_object
*newBufObj
= NULL
;
953 struct gl_buffer_object
**bindTarget
= NULL
;
955 bindTarget
= get_buffer_target(ctx
, target
);
957 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
961 /* Get pointer to old buffer object (to be unbound) */
962 oldBufObj
= *bindTarget
;
963 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
964 return; /* rebinding the same buffer object- no change */
967 * Get pointer to new buffer object (newBufObj)
970 /* The spec says there's not a buffer object named 0, but we use
971 * one internally because it simplifies things.
973 newBufObj
= ctx
->Shared
->NullBufferObj
;
976 /* non-default buffer object */
977 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
978 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
979 &newBufObj
, "glBindBuffer"))
983 /* bind new buffer */
984 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
989 * Update the default buffer objects in the given context to reference those
990 * specified in the shared state and release those referencing the old
994 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
996 /* Bind the NullBufferObj to remove references to those
997 * in the shared context hash table.
999 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
1000 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
1001 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
1002 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
1008 * Return the gl_buffer_object for the given ID.
1009 * Always return NULL for ID 0.
1011 struct gl_buffer_object
*
1012 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
1017 return (struct gl_buffer_object
*)
1018 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
1022 struct gl_buffer_object
*
1023 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1025 return (struct gl_buffer_object
*)
1026 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1030 * A convenience function for direct state access functions that throws
1031 * GL_INVALID_OPERATION if buffer is not the name of an existing
1034 struct gl_buffer_object
*
1035 _mesa_lookup_bufferobj_err(struct gl_context
*ctx
, GLuint buffer
,
1038 struct gl_buffer_object
*bufObj
;
1040 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1041 if (!bufObj
|| bufObj
== &DummyBufferObject
) {
1042 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1043 "%s(non-existent buffer object %u)", caller
, buffer
);
1052 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1054 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1059 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1061 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1066 * Look up a buffer object for a multi-bind function.
1068 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1069 * of generating an error if the buffer ID is not zero or the name
1070 * of an existing buffer object.
1072 * If the buffer ID refers to an existing buffer object, a pointer
1073 * to the buffer object is returned. If the ID is zero, a pointer
1074 * to the shared NullBufferObj is returned. If the ID is not zero
1075 * and does not refer to a valid buffer object, this function
1078 * This function assumes that the caller has already locked the
1079 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1081 struct gl_buffer_object
*
1082 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1083 const GLuint
*buffers
,
1084 GLuint index
, const char *caller
)
1086 struct gl_buffer_object
*bufObj
;
1088 if (buffers
[index
] != 0) {
1089 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1091 /* The multi-bind functions don't create the buffer objects
1092 when they don't exist. */
1093 if (bufObj
== &DummyBufferObject
)
1096 bufObj
= ctx
->Shared
->NullBufferObj
;
1099 /* The ARB_multi_bind spec says:
1101 * "An INVALID_OPERATION error is generated if any value
1102 * in <buffers> is not zero or the name of an existing
1103 * buffer object (per binding)."
1105 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1106 "%s(buffers[%u]=%u is not zero or the name "
1107 "of an existing buffer object)",
1108 caller
, index
, buffers
[index
]);
1116 * If *ptr points to obj, set ptr = the Null/default buffer object.
1117 * This is a helper for buffer object deletion.
1118 * The GL spec says that deleting a buffer object causes it to get
1119 * unbound from all arrays in the current context.
1122 unbind(struct gl_context
*ctx
,
1123 struct gl_buffer_object
**ptr
,
1124 struct gl_buffer_object
*obj
)
1127 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1133 * Plug default/fallback buffer object functions into the device
1137 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1139 /* GL_ARB_vertex/pixel_buffer_object */
1140 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1141 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1142 driver
->BufferData
= buffer_data_fallback
;
1143 driver
->BufferSubData
= buffer_sub_data_fallback
;
1144 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1145 driver
->UnmapBuffer
= unmap_buffer_fallback
;
1147 /* GL_ARB_clear_buffer_object */
1148 driver
->ClearBufferSubData
= _mesa_ClearBufferSubData_sw
;
1150 /* GL_ARB_map_buffer_range */
1151 driver
->MapBufferRange
= map_buffer_range_fallback
;
1152 driver
->FlushMappedBufferRange
= flush_mapped_buffer_range_fallback
;
1154 /* GL_ARB_copy_buffer */
1155 driver
->CopyBufferSubData
= copy_buffer_sub_data_fallback
;
1160 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1161 struct gl_buffer_object
*bufObj
)
1165 for (i
= 0; i
< MAP_COUNT
; i
++) {
1166 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1167 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1168 assert(bufObj
->Mappings
[i
].Pointer
== NULL
);
1169 bufObj
->Mappings
[i
].AccessFlags
= 0;
1175 /**********************************************************************/
1177 /**********************************************************************/
1180 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1182 GET_CURRENT_CONTEXT(ctx
);
1184 if (MESA_VERBOSE
& VERBOSE_API
)
1185 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1186 _mesa_enum_to_string(target
), buffer
);
1188 bind_buffer_object(ctx
, target
, buffer
);
1193 * Delete a set of buffer objects.
1195 * \param n Number of buffer objects to delete.
1196 * \param ids Array of \c n buffer object IDs.
1199 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1201 GET_CURRENT_CONTEXT(ctx
);
1203 FLUSH_VERTICES(ctx
, 0);
1206 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1210 mtx_lock(&ctx
->Shared
->Mutex
);
1212 for (i
= 0; i
< n
; i
++) {
1213 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1215 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1218 assert(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1220 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1222 /* unbind any vertex pointers bound to this buffer */
1223 for (j
= 0; j
< ARRAY_SIZE(vao
->VertexBinding
); j
++) {
1224 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1227 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1228 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1230 if (vao
->IndexBufferObj
== bufObj
) {
1231 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1234 /* unbind ARB_draw_indirect binding point */
1235 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1236 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1239 /* unbind ARB_copy_buffer binding points */
1240 if (ctx
->CopyReadBuffer
== bufObj
) {
1241 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1243 if (ctx
->CopyWriteBuffer
== bufObj
) {
1244 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1247 /* unbind transform feedback binding points */
1248 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1249 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1251 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1252 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1253 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1257 /* unbind UBO binding points */
1258 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1259 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1260 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1264 if (ctx
->UniformBuffer
== bufObj
) {
1265 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1268 /* unbind SSBO binding points */
1269 for (j
= 0; j
< ctx
->Const
.MaxShaderStorageBufferBindings
; j
++) {
1270 if (ctx
->ShaderStorageBufferBindings
[j
].BufferObject
== bufObj
) {
1271 _mesa_BindBufferBase(GL_SHADER_STORAGE_BUFFER
, j
, 0);
1275 if (ctx
->ShaderStorageBuffer
== bufObj
) {
1276 _mesa_BindBuffer(GL_SHADER_STORAGE_BUFFER
, 0);
1279 /* unbind Atomci Buffer binding points */
1280 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1281 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1282 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1286 if (ctx
->AtomicBuffer
== bufObj
) {
1287 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1290 /* unbind any pixel pack/unpack pointers bound to this buffer */
1291 if (ctx
->Pack
.BufferObj
== bufObj
) {
1292 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1294 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1295 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1298 if (ctx
->Texture
.BufferObject
== bufObj
) {
1299 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1302 if (ctx
->ExternalVirtualMemoryBuffer
== bufObj
) {
1303 _mesa_BindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
, 0);
1306 /* The ID is immediately freed for re-use */
1307 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1308 /* Make sure we do not run into the classic ABA problem on bind.
1309 * We don't want to allow re-binding a buffer object that's been
1310 * "deleted" by glDeleteBuffers().
1312 * The explicit rebinding to the default object in the current context
1313 * prevents the above in the current context, but another context
1314 * sharing the same objects might suffer from this problem.
1315 * The alternative would be to do the hash lookup in any case on bind
1316 * which would introduce more runtime overhead than this.
1318 bufObj
->DeletePending
= GL_TRUE
;
1319 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1323 mtx_unlock(&ctx
->Shared
->Mutex
);
1328 * This is the implementation for glGenBuffers and glCreateBuffers. It is not
1329 * exposed to the rest of Mesa to encourage the use of nameless buffers in
1333 create_buffers(GLsizei n
, GLuint
*buffers
, bool dsa
)
1335 GET_CURRENT_CONTEXT(ctx
);
1338 struct gl_buffer_object
*buf
;
1340 const char *func
= dsa
? "glCreateBuffers" : "glGenBuffers";
1342 if (MESA_VERBOSE
& VERBOSE_API
)
1343 _mesa_debug(ctx
, "%s(%d)\n", func
, n
);
1346 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n %d < 0)", func
, n
);
1355 * This must be atomic (generation and allocation of buffer object IDs)
1357 mtx_lock(&ctx
->Shared
->Mutex
);
1359 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1361 /* Insert the ID and pointer into the hash table. If non-DSA, insert a
1362 * DummyBufferObject. Otherwise, create a new buffer object and insert
1365 for (i
= 0; i
< n
; i
++) {
1366 buffers
[i
] = first
+ i
;
1368 assert(ctx
->Driver
.NewBufferObject
);
1369 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffers
[i
]);
1371 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1372 mtx_unlock(&ctx
->Shared
->Mutex
);
1377 buf
= &DummyBufferObject
;
1379 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffers
[i
], buf
);
1382 mtx_unlock(&ctx
->Shared
->Mutex
);
1386 * Generate a set of unique buffer object IDs and store them in \c buffers.
1388 * \param n Number of IDs to generate.
1389 * \param buffers Array of \c n locations to store the IDs.
1392 _mesa_GenBuffers(GLsizei n
, GLuint
*buffers
)
1394 create_buffers(n
, buffers
, false);
1398 * Create a set of buffer objects and store their unique IDs in \c buffers.
1400 * \param n Number of IDs to generate.
1401 * \param buffers Array of \c n locations to store the IDs.
1404 _mesa_CreateBuffers(GLsizei n
, GLuint
*buffers
)
1406 create_buffers(n
, buffers
, true);
1411 * Determine if ID is the name of a buffer object.
1413 * \param id ID of the potential buffer object.
1414 * \return \c GL_TRUE if \c id is the name of a buffer object,
1415 * \c GL_FALSE otherwise.
1417 GLboolean GLAPIENTRY
1418 _mesa_IsBuffer(GLuint id
)
1420 struct gl_buffer_object
*bufObj
;
1421 GET_CURRENT_CONTEXT(ctx
);
1422 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1424 mtx_lock(&ctx
->Shared
->Mutex
);
1425 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1426 mtx_unlock(&ctx
->Shared
->Mutex
);
1428 return bufObj
&& bufObj
!= &DummyBufferObject
;
1433 _mesa_buffer_storage(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1434 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1435 GLbitfield flags
, const char *func
)
1438 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size <= 0)", func
);
1442 if (flags
& ~(GL_MAP_READ_BIT
|
1444 GL_MAP_PERSISTENT_BIT
|
1445 GL_MAP_COHERENT_BIT
|
1446 GL_DYNAMIC_STORAGE_BIT
|
1447 GL_CLIENT_STORAGE_BIT
)) {
1448 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid flag bits set)", func
);
1452 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1453 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1454 _mesa_error(ctx
, GL_INVALID_VALUE
,
1455 "%s(PERSISTENT and flags!=READ/WRITE)", func
);
1459 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1460 _mesa_error(ctx
, GL_INVALID_VALUE
,
1461 "%s(COHERENT and flags!=PERSISTENT)", func
);
1465 if (bufObj
->Immutable
) {
1466 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1470 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1471 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1473 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1475 bufObj
->Written
= GL_TRUE
;
1476 bufObj
->Immutable
= GL_TRUE
;
1478 assert(ctx
->Driver
.BufferData
);
1479 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1481 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1482 /* Even though the interaction between AMD_pinned_memory and
1483 * glBufferStorage is not described in the spec, Graham Sellers
1484 * said that it should behave the same as glBufferData.
1486 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1489 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1495 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1498 GET_CURRENT_CONTEXT(ctx
);
1499 struct gl_buffer_object
*bufObj
;
1501 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1505 _mesa_buffer_storage(ctx
, bufObj
, target
, size
, data
, flags
,
1510 _mesa_NamedBufferStorage(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1513 GET_CURRENT_CONTEXT(ctx
);
1514 struct gl_buffer_object
*bufObj
;
1516 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferStorage");
1521 * In direct state access, buffer objects have an unspecified target since
1522 * they are not required to be bound.
1524 _mesa_buffer_storage(ctx
, bufObj
, GL_NONE
, size
, data
, flags
,
1525 "glNamedBufferStorage");
1530 _mesa_buffer_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1531 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1532 GLenum usage
, const char *func
)
1536 if (MESA_VERBOSE
& VERBOSE_API
)
1537 _mesa_debug(ctx
, "%s(%s, %ld, %p, %s)\n",
1539 _mesa_enum_to_string(target
),
1540 (long int) size
, data
,
1541 _mesa_enum_to_string(usage
));
1544 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", func
);
1549 case GL_STREAM_DRAW_ARB
:
1550 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1553 case GL_STATIC_DRAW_ARB
:
1554 case GL_DYNAMIC_DRAW_ARB
:
1558 case GL_STREAM_READ_ARB
:
1559 case GL_STREAM_COPY_ARB
:
1560 case GL_STATIC_READ_ARB
:
1561 case GL_STATIC_COPY_ARB
:
1562 case GL_DYNAMIC_READ_ARB
:
1563 case GL_DYNAMIC_COPY_ARB
:
1564 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1568 valid_usage
= false;
1573 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid usage: %s)", func
,
1574 _mesa_enum_to_string(usage
));
1578 if (bufObj
->Immutable
) {
1579 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1583 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1584 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1586 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1588 bufObj
->Written
= GL_TRUE
;
1591 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1592 bufObj
->Name
, size
, data
, usage
);
1599 assert(ctx
->Driver
.BufferData
);
1600 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1603 GL_DYNAMIC_STORAGE_BIT
,
1605 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1606 /* From GL_AMD_pinned_memory:
1608 * INVALID_OPERATION is generated by BufferData if <target> is
1609 * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
1610 * mapped to the GPU address space.
1612 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1615 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1621 _mesa_BufferData(GLenum target
, GLsizeiptr size
,
1622 const GLvoid
*data
, GLenum usage
)
1624 GET_CURRENT_CONTEXT(ctx
);
1625 struct gl_buffer_object
*bufObj
;
1627 bufObj
= get_buffer(ctx
, "glBufferData", target
, GL_INVALID_OPERATION
);
1631 _mesa_buffer_data(ctx
, bufObj
, target
, size
, data
, usage
,
1636 _mesa_NamedBufferData(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1639 GET_CURRENT_CONTEXT(ctx
);
1640 struct gl_buffer_object
*bufObj
;
1642 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferData");
1646 /* In direct state access, buffer objects have an unspecified target since
1647 * they are not required to be bound.
1649 _mesa_buffer_data(ctx
, bufObj
, GL_NONE
, size
, data
, usage
,
1650 "glNamedBufferData");
1655 * Implementation for glBufferSubData and glNamedBufferSubData.
1657 * \param ctx GL context.
1658 * \param bufObj The buffer object.
1659 * \param offset Offset of the first byte of the subdata range.
1660 * \param size Size, in bytes, of the subdata range.
1661 * \param data The data store.
1662 * \param func Name of calling function for recording errors.
1666 _mesa_buffer_sub_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1667 GLintptr offset
, GLsizeiptr size
, const GLvoid
*data
,
1670 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1672 /* error already recorded */
1676 if (bufObj
->Immutable
&&
1677 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1678 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1685 bufObj
->Written
= GL_TRUE
;
1687 assert(ctx
->Driver
.BufferSubData
);
1688 ctx
->Driver
.BufferSubData(ctx
, offset
, size
, data
, bufObj
);
1692 _mesa_BufferSubData(GLenum target
, GLintptr offset
,
1693 GLsizeiptr size
, const GLvoid
*data
)
1695 GET_CURRENT_CONTEXT(ctx
);
1696 struct gl_buffer_object
*bufObj
;
1698 bufObj
= get_buffer(ctx
, "glBufferSubData", target
, GL_INVALID_OPERATION
);
1702 _mesa_buffer_sub_data(ctx
, bufObj
, offset
, size
, data
, "glBufferSubData");
1706 _mesa_NamedBufferSubData(GLuint buffer
, GLintptr offset
,
1707 GLsizeiptr size
, const GLvoid
*data
)
1709 GET_CURRENT_CONTEXT(ctx
);
1710 struct gl_buffer_object
*bufObj
;
1712 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferSubData");
1716 _mesa_buffer_sub_data(ctx
, bufObj
, offset
, size
, data
,
1717 "glNamedBufferSubData");
1722 _mesa_GetBufferSubData(GLenum target
, GLintptr offset
,
1723 GLsizeiptr size
, GLvoid
*data
)
1725 GET_CURRENT_CONTEXT(ctx
);
1726 struct gl_buffer_object
*bufObj
;
1728 bufObj
= get_buffer(ctx
, "glGetBufferSubData", target
,
1729 GL_INVALID_OPERATION
);
1733 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1734 "glGetBufferSubData")) {
1738 assert(ctx
->Driver
.GetBufferSubData
);
1739 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1743 _mesa_GetNamedBufferSubData(GLuint buffer
, GLintptr offset
,
1744 GLsizeiptr size
, GLvoid
*data
)
1746 GET_CURRENT_CONTEXT(ctx
);
1747 struct gl_buffer_object
*bufObj
;
1749 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1750 "glGetNamedBufferSubData");
1754 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1755 "glGetNamedBufferSubData")) {
1759 assert(ctx
->Driver
.GetBufferSubData
);
1760 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1765 * \param subdata true if caller is *SubData, false if *Data
1768 _mesa_clear_buffer_sub_data(struct gl_context
*ctx
,
1769 struct gl_buffer_object
*bufObj
,
1770 GLenum internalformat
,
1771 GLintptr offset
, GLsizeiptr size
,
1772 GLenum format
, GLenum type
,
1774 const char *func
, bool subdata
)
1776 mesa_format mesaFormat
;
1777 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1778 GLsizeiptr clearValueSize
;
1780 /* This checks for disallowed mappings. */
1781 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1786 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1787 format
, type
, func
);
1789 if (mesaFormat
== MESA_FORMAT_NONE
) {
1793 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1794 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
,
1796 "%s(offset or size is not a multiple of "
1797 "internalformat size)", func
);
1802 /* clear to zeros, per the spec */
1804 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1805 NULL
, clearValueSize
, bufObj
);
1810 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1811 format
, type
, data
, func
)) {
1816 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1817 clearValue
, clearValueSize
, bufObj
);
1822 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1823 GLenum type
, const GLvoid
*data
)
1825 GET_CURRENT_CONTEXT(ctx
);
1826 struct gl_buffer_object
*bufObj
;
1828 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1832 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
1834 "glClearBufferData", false);
1838 _mesa_ClearNamedBufferData(GLuint buffer
, GLenum internalformat
,
1839 GLenum format
, GLenum type
, const GLvoid
*data
)
1841 GET_CURRENT_CONTEXT(ctx
);
1842 struct gl_buffer_object
*bufObj
;
1844 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glClearNamedBufferData");
1848 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
1850 "glClearNamedBufferData", false);
1855 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1856 GLintptr offset
, GLsizeiptr size
,
1857 GLenum format
, GLenum type
,
1860 GET_CURRENT_CONTEXT(ctx
);
1861 struct gl_buffer_object
*bufObj
;
1863 bufObj
= get_buffer(ctx
, "glClearBufferSubData", target
, GL_INVALID_VALUE
);
1867 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
,
1869 "glClearBufferSubData", true);
1873 _mesa_ClearNamedBufferSubData(GLuint buffer
, GLenum internalformat
,
1874 GLintptr offset
, GLsizeiptr size
,
1875 GLenum format
, GLenum type
,
1878 GET_CURRENT_CONTEXT(ctx
);
1879 struct gl_buffer_object
*bufObj
;
1881 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1882 "glClearNamedBufferSubData");
1886 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
,
1888 "glClearNamedBufferSubData", true);
1893 _mesa_unmap_buffer(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1896 GLboolean status
= GL_TRUE
;
1897 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1899 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1901 "%s(buffer is not mapped)", func
);
1906 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1907 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1909 /* check that last 100 bytes are still = magic value */
1910 for (i
= 0; i
< 100; i
++) {
1911 GLuint pos
= bufObj
->Size
- i
- 1;
1912 if (buf
[pos
] != 123) {
1913 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1914 " at position %d (value = %u)\n",
1922 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1923 GLuint i
, unchanged
= 0;
1924 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1926 /* check which bytes changed */
1927 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1928 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1935 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1936 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1941 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1942 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1943 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1944 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1945 assert(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1950 GLboolean GLAPIENTRY
1951 _mesa_UnmapBuffer(GLenum target
)
1953 GET_CURRENT_CONTEXT(ctx
);
1954 struct gl_buffer_object
*bufObj
;
1956 bufObj
= get_buffer(ctx
, "glUnmapBuffer", target
, GL_INVALID_OPERATION
);
1960 return _mesa_unmap_buffer(ctx
, bufObj
, "glUnmapBuffer");
1963 GLboolean GLAPIENTRY
1964 _mesa_UnmapNamedBuffer(GLuint buffer
)
1966 GET_CURRENT_CONTEXT(ctx
);
1967 struct gl_buffer_object
*bufObj
;
1969 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glUnmapNamedBuffer");
1973 return _mesa_unmap_buffer(ctx
, bufObj
, "glUnmapNamedBuffer");
1978 get_buffer_parameter(struct gl_context
*ctx
,
1979 struct gl_buffer_object
*bufObj
, GLenum pname
,
1980 GLint64
*params
, const char *func
)
1983 case GL_BUFFER_SIZE_ARB
:
1984 *params
= bufObj
->Size
;
1986 case GL_BUFFER_USAGE_ARB
:
1987 *params
= bufObj
->Usage
;
1989 case GL_BUFFER_ACCESS_ARB
:
1990 *params
= simplified_access_mode(ctx
,
1991 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1993 case GL_BUFFER_MAPPED_ARB
:
1994 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1996 case GL_BUFFER_ACCESS_FLAGS
:
1997 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1999 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
2001 case GL_BUFFER_MAP_OFFSET
:
2002 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2004 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
2006 case GL_BUFFER_MAP_LENGTH
:
2007 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2009 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
2011 case GL_BUFFER_IMMUTABLE_STORAGE
:
2012 if (!ctx
->Extensions
.ARB_buffer_storage
)
2014 *params
= bufObj
->Immutable
;
2016 case GL_BUFFER_STORAGE_FLAGS
:
2017 if (!ctx
->Extensions
.ARB_buffer_storage
)
2019 *params
= bufObj
->StorageFlags
;
2028 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname: %s)", func
,
2029 _mesa_enum_to_string(pname
));
2034 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2036 GET_CURRENT_CONTEXT(ctx
);
2037 struct gl_buffer_object
*bufObj
;
2040 bufObj
= get_buffer(ctx
, "glGetBufferParameteriv", target
,
2041 GL_INVALID_OPERATION
);
2045 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2046 "glGetBufferParameteriv"))
2047 return; /* Error already recorded. */
2049 *params
= (GLint
) parameter
;
2053 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
2055 GET_CURRENT_CONTEXT(ctx
);
2056 struct gl_buffer_object
*bufObj
;
2059 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
2060 GL_INVALID_OPERATION
);
2064 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2065 "glGetBufferParameteri64v"))
2066 return; /* Error already recorded. */
2068 *params
= parameter
;
2072 _mesa_GetNamedBufferParameteriv(GLuint buffer
, GLenum pname
, GLint
*params
)
2074 GET_CURRENT_CONTEXT(ctx
);
2075 struct gl_buffer_object
*bufObj
;
2078 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2079 "glGetNamedBufferParameteriv");
2083 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2084 "glGetNamedBufferParameteriv"))
2085 return; /* Error already recorded. */
2087 *params
= (GLint
) parameter
;
2091 _mesa_GetNamedBufferParameteri64v(GLuint buffer
, GLenum pname
,
2094 GET_CURRENT_CONTEXT(ctx
);
2095 struct gl_buffer_object
*bufObj
;
2098 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2099 "glGetNamedBufferParameteri64v");
2103 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2104 "glGetNamedBufferParameteri64v"))
2105 return; /* Error already recorded. */
2107 *params
= parameter
;
2112 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
2114 GET_CURRENT_CONTEXT(ctx
);
2115 struct gl_buffer_object
*bufObj
;
2117 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2118 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointerv(pname != "
2119 "GL_BUFFER_MAP_POINTER)");
2123 bufObj
= get_buffer(ctx
, "glGetBufferPointerv", target
,
2124 GL_INVALID_OPERATION
);
2128 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2132 _mesa_GetNamedBufferPointerv(GLuint buffer
, GLenum pname
, GLvoid
**params
)
2134 GET_CURRENT_CONTEXT(ctx
);
2135 struct gl_buffer_object
*bufObj
;
2137 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2138 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetNamedBufferPointerv(pname != "
2139 "GL_BUFFER_MAP_POINTER)");
2143 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2144 "glGetNamedBufferPointerv");
2148 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2153 _mesa_copy_buffer_sub_data(struct gl_context
*ctx
,
2154 struct gl_buffer_object
*src
,
2155 struct gl_buffer_object
*dst
,
2156 GLintptr readOffset
, GLintptr writeOffset
,
2157 GLsizeiptr size
, const char *func
)
2159 if (_mesa_check_disallowed_mapping(src
)) {
2160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2161 "%s(readBuffer is mapped)", func
);
2165 if (_mesa_check_disallowed_mapping(dst
)) {
2166 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2167 "%s(writeBuffer is mapped)", func
);
2171 if (readOffset
< 0) {
2172 _mesa_error(ctx
, GL_INVALID_VALUE
,
2173 "%s(readOffset %d < 0)", func
, (int) readOffset
);
2177 if (writeOffset
< 0) {
2178 _mesa_error(ctx
, GL_INVALID_VALUE
,
2179 "%s(writeOffset %d < 0)", func
, (int) writeOffset
);
2184 _mesa_error(ctx
, GL_INVALID_VALUE
,
2185 "%s(size %d < 0)", func
, (int) size
);
2189 if (readOffset
+ size
> src
->Size
) {
2190 _mesa_error(ctx
, GL_INVALID_VALUE
,
2191 "%s(readOffset %d + size %d > src_buffer_size %d)", func
,
2192 (int) readOffset
, (int) size
, (int) src
->Size
);
2196 if (writeOffset
+ size
> dst
->Size
) {
2197 _mesa_error(ctx
, GL_INVALID_VALUE
,
2198 "%s(writeOffset %d + size %d > dst_buffer_size %d)", func
,
2199 (int) writeOffset
, (int) size
, (int) dst
->Size
);
2204 if (readOffset
+ size
<= writeOffset
) {
2207 else if (writeOffset
+ size
<= readOffset
) {
2211 /* overlapping src/dst is illegal */
2212 _mesa_error(ctx
, GL_INVALID_VALUE
,
2213 "%s(overlapping src/dst)", func
);
2218 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2222 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
2223 GLintptr readOffset
, GLintptr writeOffset
,
2226 GET_CURRENT_CONTEXT(ctx
);
2227 struct gl_buffer_object
*src
, *dst
;
2229 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
2230 GL_INVALID_OPERATION
);
2234 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
2235 GL_INVALID_OPERATION
);
2239 _mesa_copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2240 "glCopyBufferSubData");
2244 _mesa_CopyNamedBufferSubData(GLuint readBuffer
, GLuint writeBuffer
,
2245 GLintptr readOffset
, GLintptr writeOffset
,
2248 GET_CURRENT_CONTEXT(ctx
);
2249 struct gl_buffer_object
*src
, *dst
;
2251 src
= _mesa_lookup_bufferobj_err(ctx
, readBuffer
,
2252 "glCopyNamedBufferSubData");
2256 dst
= _mesa_lookup_bufferobj_err(ctx
, writeBuffer
,
2257 "glCopyNamedBufferSubData");
2261 _mesa_copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2262 "glCopyNamedBufferSubData");
2267 _mesa_map_buffer_range(struct gl_context
*ctx
,
2268 struct gl_buffer_object
*bufObj
,
2269 GLintptr offset
, GLsizeiptr length
,
2270 GLbitfield access
, const char *func
)
2273 GLbitfield allowed_access
;
2275 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2278 _mesa_error(ctx
, GL_INVALID_VALUE
,
2279 "%s(offset %ld < 0)", func
, (long) offset
);
2284 _mesa_error(ctx
, GL_INVALID_VALUE
,
2285 "%s(length %ld < 0)", func
, (long) length
);
2289 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2291 * "An INVALID_OPERATION error is generated for any of the following
2294 * * <length> is zero."
2296 * Additionally, page 94 of the PDF of the OpenGL 4.5 core spec
2297 * (30.10.2014) also says this, so it's no longer allowed for desktop GL,
2301 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(length = 0)", func
);
2305 allowed_access
= GL_MAP_READ_BIT
|
2307 GL_MAP_INVALIDATE_RANGE_BIT
|
2308 GL_MAP_INVALIDATE_BUFFER_BIT
|
2309 GL_MAP_FLUSH_EXPLICIT_BIT
|
2310 GL_MAP_UNSYNCHRONIZED_BIT
;
2312 if (ctx
->Extensions
.ARB_buffer_storage
) {
2313 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2314 GL_MAP_COHERENT_BIT
;
2317 if (access
& ~allowed_access
) {
2318 /* generate an error if any bits other than those allowed are set */
2319 _mesa_error(ctx
, GL_INVALID_VALUE
,
2320 "%s(access has undefined bits set)", func
);
2324 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2325 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2326 "%s(access indicates neither read or write)", func
);
2330 if ((access
& GL_MAP_READ_BIT
) &&
2331 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2332 GL_MAP_INVALIDATE_BUFFER_BIT
|
2333 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2335 "%s(read access with disallowed bits)", func
);
2339 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2340 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2342 "%s(access has flush explicit without write)", func
);
2346 if (access
& GL_MAP_READ_BIT
&&
2347 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2349 "%s(buffer does not allow read access)", func
);
2353 if (access
& GL_MAP_WRITE_BIT
&&
2354 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2356 "%s(buffer does not allow write access)", func
);
2360 if (access
& GL_MAP_COHERENT_BIT
&&
2361 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2363 "%s(buffer does not allow coherent access)", func
);
2367 if (access
& GL_MAP_PERSISTENT_BIT
&&
2368 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2369 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2370 "%s(buffer does not allow persistent access)", func
);
2374 if (offset
+ length
> bufObj
->Size
) {
2375 _mesa_error(ctx
, GL_INVALID_VALUE
,
2376 "%s(offset %td + length %td > buffer_size %td)", func
,
2377 offset
, length
, bufObj
->Size
);
2381 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2382 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2383 "%s(buffer already mapped)", func
);
2387 if (!bufObj
->Size
) {
2388 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(buffer size = 0)", func
);
2393 assert(ctx
->Driver
.MapBufferRange
);
2394 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2397 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(map failed)", func
);
2400 /* The driver callback should have set all these fields.
2401 * This is important because other modules (like VBO) might call
2402 * the driver function directly.
2404 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2405 assert(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2406 assert(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2407 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2410 if (access
& GL_MAP_WRITE_BIT
)
2411 bufObj
->Written
= GL_TRUE
;
2414 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2415 printf("glMapBuffer(%u, sz %ld, access 0x%x)\n",
2416 bufObj
->Name
, bufObj
->Size
, access
);
2417 /* Access must be write only */
2418 if ((access
& GL_MAP_WRITE_BIT
) && (!(access
& ~GL_MAP_WRITE_BIT
))) {
2420 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
2421 for (i
= 0; i
< bufObj
->Size
; i
++)
2428 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2429 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
2431 /* buffer is 100 bytes larger than requested, fill with magic value */
2432 for (i
= 0; i
< 100; i
++) {
2433 buf
[bufObj
->Size
- i
- 1] = 123;
2442 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2445 GET_CURRENT_CONTEXT(ctx
);
2446 struct gl_buffer_object
*bufObj
;
2448 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2449 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2450 "glMapBufferRange(ARB_map_buffer_range not supported)");
2454 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2458 return _mesa_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2459 "glMapBufferRange");
2463 _mesa_MapNamedBufferRange(GLuint buffer
, GLintptr offset
, GLsizeiptr length
,
2466 GET_CURRENT_CONTEXT(ctx
);
2467 struct gl_buffer_object
*bufObj
;
2469 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2471 "glMapNamedBufferRange("
2472 "ARB_map_buffer_range not supported)");
2476 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBufferRange");
2480 return _mesa_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2481 "glMapNamedBufferRange");
2485 * Converts GLenum access from MapBuffer and MapNamedBuffer into
2486 * flags for input to _mesa_map_buffer_range.
2488 * \return true if the type of requested access is permissible.
2491 get_map_buffer_access_flags(struct gl_context
*ctx
, GLenum access
,
2495 case GL_READ_ONLY_ARB
:
2496 *flags
= GL_MAP_READ_BIT
;
2497 return _mesa_is_desktop_gl(ctx
);
2498 case GL_WRITE_ONLY_ARB
:
2499 *flags
= GL_MAP_WRITE_BIT
;
2501 case GL_READ_WRITE_ARB
:
2502 *flags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
2503 return _mesa_is_desktop_gl(ctx
);
2510 _mesa_MapBuffer(GLenum target
, GLenum access
)
2512 GET_CURRENT_CONTEXT(ctx
);
2513 struct gl_buffer_object
*bufObj
;
2514 GLbitfield accessFlags
;
2516 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2517 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBuffer(invalid access)");
2521 bufObj
= get_buffer(ctx
, "glMapBuffer", target
, GL_INVALID_OPERATION
);
2525 return _mesa_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2530 _mesa_MapNamedBuffer(GLuint buffer
, GLenum access
)
2532 GET_CURRENT_CONTEXT(ctx
);
2533 struct gl_buffer_object
*bufObj
;
2534 GLbitfield accessFlags
;
2536 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2537 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapNamedBuffer(invalid access)");
2541 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBuffer");
2545 return _mesa_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2546 "glMapNamedBuffer");
2551 _mesa_flush_mapped_buffer_range(struct gl_context
*ctx
,
2552 struct gl_buffer_object
*bufObj
,
2553 GLintptr offset
, GLsizeiptr length
,
2556 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2558 "%s(ARB_map_buffer_range not supported)", func
);
2563 _mesa_error(ctx
, GL_INVALID_VALUE
,
2564 "%s(offset %ld < 0)", func
, (long) offset
);
2569 _mesa_error(ctx
, GL_INVALID_VALUE
,
2570 "%s(length %ld < 0)", func
, (long) length
);
2574 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2575 /* buffer is not mapped */
2576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2577 "%s(buffer is not mapped)", func
);
2581 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2582 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2584 "%s(GL_MAP_FLUSH_EXPLICIT_BIT not set)", func
);
2588 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2589 _mesa_error(ctx
, GL_INVALID_VALUE
,
2590 "%s(offset %ld + length %ld > mapped length %ld)", func
,
2591 (long) offset
, (long) length
,
2592 (long) bufObj
->Mappings
[MAP_USER
].Length
);
2596 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2598 if (ctx
->Driver
.FlushMappedBufferRange
)
2599 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2604 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
,
2607 GET_CURRENT_CONTEXT(ctx
);
2608 struct gl_buffer_object
*bufObj
;
2610 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2611 GL_INVALID_OPERATION
);
2615 _mesa_flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2616 "glFlushMappedBufferRange");
2620 _mesa_FlushMappedNamedBufferRange(GLuint buffer
, GLintptr offset
,
2623 GET_CURRENT_CONTEXT(ctx
);
2624 struct gl_buffer_object
*bufObj
;
2626 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2627 "glFlushMappedNamedBufferRange");
2631 _mesa_flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2632 "glFlushMappedNamedBufferRange");
2637 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2639 struct gl_buffer_object
*bufObj
;
2642 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2644 _mesa_error(ctx
, GL_INVALID_VALUE
,
2645 "glObjectPurgeable(name = 0x%x)", name
);
2648 if (!_mesa_is_bufferobj(bufObj
)) {
2649 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2653 if (bufObj
->Purgeable
) {
2654 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2655 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2656 return GL_VOLATILE_APPLE
;
2659 bufObj
->Purgeable
= GL_TRUE
;
2661 retval
= GL_VOLATILE_APPLE
;
2662 if (ctx
->Driver
.BufferObjectPurgeable
)
2663 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2670 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2672 struct gl_renderbuffer
*bufObj
;
2675 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2677 _mesa_error(ctx
, GL_INVALID_VALUE
,
2678 "glObjectUnpurgeable(name = 0x%x)", name
);
2682 if (bufObj
->Purgeable
) {
2683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2684 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2685 return GL_VOLATILE_APPLE
;
2688 bufObj
->Purgeable
= GL_TRUE
;
2690 retval
= GL_VOLATILE_APPLE
;
2691 if (ctx
->Driver
.RenderObjectPurgeable
)
2692 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2699 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2701 struct gl_texture_object
*bufObj
;
2704 bufObj
= _mesa_lookup_texture(ctx
, name
);
2706 _mesa_error(ctx
, GL_INVALID_VALUE
,
2707 "glObjectPurgeable(name = 0x%x)", name
);
2711 if (bufObj
->Purgeable
) {
2712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2713 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2714 return GL_VOLATILE_APPLE
;
2717 bufObj
->Purgeable
= GL_TRUE
;
2719 retval
= GL_VOLATILE_APPLE
;
2720 if (ctx
->Driver
.TextureObjectPurgeable
)
2721 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2728 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2732 GET_CURRENT_CONTEXT(ctx
);
2733 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2736 _mesa_error(ctx
, GL_INVALID_VALUE
,
2737 "glObjectPurgeable(name = 0x%x)", name
);
2742 case GL_VOLATILE_APPLE
:
2743 case GL_RELEASED_APPLE
:
2747 _mesa_error(ctx
, GL_INVALID_ENUM
,
2748 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2753 switch (objectType
) {
2755 retval
= texture_object_purgeable(ctx
, name
, option
);
2757 case GL_RENDERBUFFER_EXT
:
2758 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2760 case GL_BUFFER_OBJECT_APPLE
:
2761 retval
= buffer_object_purgeable(ctx
, name
, option
);
2764 _mesa_error(ctx
, GL_INVALID_ENUM
,
2765 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2770 /* In strict conformance to the spec, we must only return VOLATILE when
2771 * when passed the VOLATILE option. Madness.
2773 * XXX First fix the spec, then fix me.
2775 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2780 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2782 struct gl_buffer_object
*bufObj
;
2785 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2787 _mesa_error(ctx
, GL_INVALID_VALUE
,
2788 "glObjectUnpurgeable(name = 0x%x)", name
);
2792 if (! bufObj
->Purgeable
) {
2793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2794 "glObjectUnpurgeable(name = 0x%x) object is "
2795 " already \"unpurged\"", name
);
2799 bufObj
->Purgeable
= GL_FALSE
;
2802 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2803 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2810 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2812 struct gl_renderbuffer
*bufObj
;
2815 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2817 _mesa_error(ctx
, GL_INVALID_VALUE
,
2818 "glObjectUnpurgeable(name = 0x%x)", name
);
2822 if (! bufObj
->Purgeable
) {
2823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2824 "glObjectUnpurgeable(name = 0x%x) object is "
2825 " already \"unpurged\"", name
);
2829 bufObj
->Purgeable
= GL_FALSE
;
2832 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2833 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2840 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2842 struct gl_texture_object
*bufObj
;
2845 bufObj
= _mesa_lookup_texture(ctx
, name
);
2847 _mesa_error(ctx
, GL_INVALID_VALUE
,
2848 "glObjectUnpurgeable(name = 0x%x)", name
);
2852 if (! bufObj
->Purgeable
) {
2853 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2854 "glObjectUnpurgeable(name = 0x%x) object is"
2855 " already \"unpurged\"", name
);
2859 bufObj
->Purgeable
= GL_FALSE
;
2862 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2863 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2870 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2872 GET_CURRENT_CONTEXT(ctx
);
2873 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2876 _mesa_error(ctx
, GL_INVALID_VALUE
,
2877 "glObjectUnpurgeable(name = 0x%x)", name
);
2882 case GL_RETAINED_APPLE
:
2883 case GL_UNDEFINED_APPLE
:
2887 _mesa_error(ctx
, GL_INVALID_ENUM
,
2888 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2893 switch (objectType
) {
2894 case GL_BUFFER_OBJECT_APPLE
:
2895 return buffer_object_unpurgeable(ctx
, name
, option
);
2897 return texture_object_unpurgeable(ctx
, name
, option
);
2898 case GL_RENDERBUFFER_EXT
:
2899 return renderbuffer_unpurgeable(ctx
, name
, option
);
2901 _mesa_error(ctx
, GL_INVALID_ENUM
,
2902 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2910 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2911 GLenum pname
, GLint
*params
)
2913 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2915 _mesa_error(ctx
, GL_INVALID_VALUE
,
2916 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2921 case GL_PURGEABLE_APPLE
:
2922 *params
= bufObj
->Purgeable
;
2925 _mesa_error(ctx
, GL_INVALID_ENUM
,
2926 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2934 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2935 GLenum pname
, GLint
*params
)
2937 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2939 _mesa_error(ctx
, GL_INVALID_VALUE
,
2940 "glObjectUnpurgeable(name = 0x%x)", name
);
2945 case GL_PURGEABLE_APPLE
:
2946 *params
= rb
->Purgeable
;
2949 _mesa_error(ctx
, GL_INVALID_ENUM
,
2950 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2958 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2959 GLenum pname
, GLint
*params
)
2961 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2963 _mesa_error(ctx
, GL_INVALID_VALUE
,
2964 "glObjectUnpurgeable(name = 0x%x)", name
);
2969 case GL_PURGEABLE_APPLE
:
2970 *params
= texObj
->Purgeable
;
2973 _mesa_error(ctx
, GL_INVALID_ENUM
,
2974 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2982 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2985 GET_CURRENT_CONTEXT(ctx
);
2988 _mesa_error(ctx
, GL_INVALID_VALUE
,
2989 "glGetObjectParameteriv(name = 0x%x)", name
);
2993 switch (objectType
) {
2995 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2997 case GL_BUFFER_OBJECT_APPLE
:
2998 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
3000 case GL_RENDERBUFFER_EXT
:
3001 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
3004 _mesa_error(ctx
, GL_INVALID_ENUM
,
3005 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
3011 * Binds a buffer object to a uniform buffer binding point.
3013 * The caller is responsible for flushing vertices and updating
3017 set_ubo_binding(struct gl_context
*ctx
,
3018 struct gl_uniform_buffer_binding
*binding
,
3019 struct gl_buffer_object
*bufObj
,
3024 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3026 binding
->Offset
= offset
;
3027 binding
->Size
= size
;
3028 binding
->AutomaticSize
= autoSize
;
3030 /* If this is a real buffer object, mark it has having been used
3031 * at some point as a UBO.
3034 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
3038 * Binds a buffer object to a shader storage buffer binding point.
3040 * The caller is responsible for flushing vertices and updating
3044 set_ssbo_binding(struct gl_context
*ctx
,
3045 struct gl_shader_storage_buffer_binding
*binding
,
3046 struct gl_buffer_object
*bufObj
,
3051 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3053 binding
->Offset
= offset
;
3054 binding
->Size
= size
;
3055 binding
->AutomaticSize
= autoSize
;
3057 /* If this is a real buffer object, mark it has having been used
3058 * at some point as a SSBO.
3061 bufObj
->UsageHistory
|= USAGE_SHADER_STORAGE_BUFFER
;
3065 * Binds a buffer object to a uniform buffer binding point.
3067 * Unlike set_ubo_binding(), this function also flushes vertices
3068 * and updates NewDriverState. It also checks if the binding
3069 * has actually changed before updating it.
3072 bind_uniform_buffer(struct gl_context
*ctx
,
3074 struct gl_buffer_object
*bufObj
,
3079 struct gl_uniform_buffer_binding
*binding
=
3080 &ctx
->UniformBufferBindings
[index
];
3082 if (binding
->BufferObject
== bufObj
&&
3083 binding
->Offset
== offset
&&
3084 binding
->Size
== size
&&
3085 binding
->AutomaticSize
== autoSize
) {
3089 FLUSH_VERTICES(ctx
, 0);
3090 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3092 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3096 * Binds a buffer object to a shader storage buffer binding point.
3098 * Unlike set_ssbo_binding(), this function also flushes vertices
3099 * and updates NewDriverState. It also checks if the binding
3100 * has actually changed before updating it.
3103 bind_shader_storage_buffer(struct gl_context
*ctx
,
3105 struct gl_buffer_object
*bufObj
,
3110 struct gl_shader_storage_buffer_binding
*binding
=
3111 &ctx
->ShaderStorageBufferBindings
[index
];
3113 if (binding
->BufferObject
== bufObj
&&
3114 binding
->Offset
== offset
&&
3115 binding
->Size
== size
&&
3116 binding
->AutomaticSize
== autoSize
) {
3120 FLUSH_VERTICES(ctx
, 0);
3121 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3123 set_ssbo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3127 * Bind a region of a buffer object to a uniform block binding point.
3128 * \param index the uniform buffer binding point index
3129 * \param bufObj the buffer object
3130 * \param offset offset to the start of buffer object region
3131 * \param size size of the buffer object region
3134 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
3136 struct gl_buffer_object
*bufObj
,
3140 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3141 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3145 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3146 _mesa_error(ctx
, GL_INVALID_VALUE
,
3147 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3148 ctx
->Const
.UniformBufferOffsetAlignment
);
3152 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3157 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3158 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3162 * Bind a region of a buffer object to a shader storage block binding point.
3163 * \param index the shader storage buffer binding point index
3164 * \param bufObj the buffer object
3165 * \param offset offset to the start of buffer object region
3166 * \param size size of the buffer object region
3169 bind_buffer_range_shader_storage_buffer(struct gl_context
*ctx
,
3171 struct gl_buffer_object
*bufObj
,
3175 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3176 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3180 if (offset
& (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3181 _mesa_error(ctx
, GL_INVALID_VALUE
,
3182 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3183 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3187 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3192 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3193 bind_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3197 * Bind a buffer object to a uniform block binding point.
3198 * As above, but offset = 0.
3201 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
3203 struct gl_buffer_object
*bufObj
)
3205 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3206 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3210 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3212 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3213 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3215 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3219 * Bind a buffer object to a shader storage block binding point.
3220 * As above, but offset = 0.
3223 bind_buffer_base_shader_storage_buffer(struct gl_context
*ctx
,
3225 struct gl_buffer_object
*bufObj
)
3227 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3228 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3232 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3234 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3235 bind_shader_storage_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3237 bind_shader_storage_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3241 * Binds a buffer object to an atomic buffer binding point.
3243 * The caller is responsible for validating the offset,
3244 * flushing the vertices and updating NewDriverState.
3247 set_atomic_buffer_binding(struct gl_context
*ctx
,
3248 struct gl_atomic_buffer_binding
*binding
,
3249 struct gl_buffer_object
*bufObj
,
3253 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3255 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3256 binding
->Offset
= -1;
3259 binding
->Offset
= offset
;
3260 binding
->Size
= size
;
3261 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
3266 * Binds a buffer object to an atomic buffer binding point.
3268 * Unlike set_atomic_buffer_binding(), this function also validates the
3269 * index and offset, flushes vertices, and updates NewDriverState.
3270 * It also checks if the binding has actually changing before
3274 bind_atomic_buffer(struct gl_context
*ctx
,
3276 struct gl_buffer_object
*bufObj
,
3281 struct gl_atomic_buffer_binding
*binding
;
3283 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
3284 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
3288 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
3289 _mesa_error(ctx
, GL_INVALID_VALUE
,
3290 "%s(offset misaligned %d/%d)", name
, (int) offset
,
3291 ATOMIC_COUNTER_SIZE
);
3295 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
3297 binding
= &ctx
->AtomicBufferBindings
[index
];
3298 if (binding
->BufferObject
== bufObj
&&
3299 binding
->Offset
== offset
&&
3300 binding
->Size
== size
) {
3304 FLUSH_VERTICES(ctx
, 0);
3305 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3307 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
3311 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
3313 const GLintptr
*offsets
,
3314 const GLsizeiptr
*sizes
)
3316 if (offsets
[index
] < 0) {
3317 /* The ARB_multi_bind spec says:
3319 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3320 * value in <offsets> is less than zero (per binding)."
3322 _mesa_error(ctx
, GL_INVALID_VALUE
,
3323 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
3324 index
, (int64_t) offsets
[index
]);
3328 if (sizes
[index
] <= 0) {
3329 /* The ARB_multi_bind spec says:
3331 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3332 * value in <sizes> is less than or equal to zero (per binding)."
3334 _mesa_error(ctx
, GL_INVALID_VALUE
,
3335 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
3336 index
, (int64_t) sizes
[index
]);
3344 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
3345 GLuint first
, GLsizei count
,
3348 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
3349 _mesa_error(ctx
, GL_INVALID_ENUM
,
3350 "%s(target=GL_UNIFORM_BUFFER)", caller
);
3354 /* The ARB_multi_bind_spec says:
3356 * "An INVALID_OPERATION error is generated if <first> + <count> is
3357 * greater than the number of target-specific indexed binding points,
3358 * as described in section 6.7.1."
3360 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
3361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3362 "%s(first=%u + count=%d > the value of "
3363 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
3364 caller
, first
, count
,
3365 ctx
->Const
.MaxUniformBufferBindings
);
3373 error_check_bind_shader_storage_buffers(struct gl_context
*ctx
,
3374 GLuint first
, GLsizei count
,
3377 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
3378 _mesa_error(ctx
, GL_INVALID_ENUM
,
3379 "%s(target=GL_SHADER_STORAGE_BUFFER)", caller
);
3383 /* The ARB_multi_bind_spec says:
3385 * "An INVALID_OPERATION error is generated if <first> + <count> is
3386 * greater than the number of target-specific indexed binding points,
3387 * as described in section 6.7.1."
3389 if (first
+ count
> ctx
->Const
.MaxShaderStorageBufferBindings
) {
3390 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3391 "%s(first=%u + count=%d > the value of "
3392 "GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS=%u)",
3393 caller
, first
, count
,
3394 ctx
->Const
.MaxShaderStorageBufferBindings
);
3402 * Unbind all uniform buffers in the range
3403 * <first> through <first>+<count>-1
3406 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3408 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3411 for (i
= 0; i
< count
; i
++)
3412 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
3413 bufObj
, -1, -1, GL_TRUE
);
3417 * Unbind all shader storage buffers in the range
3418 * <first> through <first>+<count>-1
3421 unbind_shader_storage_buffers(struct gl_context
*ctx
, GLuint first
,
3424 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3427 for (i
= 0; i
< count
; i
++)
3428 set_ssbo_binding(ctx
, &ctx
->ShaderStorageBufferBindings
[first
+ i
],
3429 bufObj
, -1, -1, GL_TRUE
);
3433 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3434 const GLuint
*buffers
)
3438 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
3441 /* Assume that at least one binding will be changed */
3442 FLUSH_VERTICES(ctx
, 0);
3443 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3446 /* The ARB_multi_bind spec says:
3448 * "If <buffers> is NULL, all bindings from <first> through
3449 * <first>+<count>-1 are reset to their unbound (zero) state."
3451 unbind_uniform_buffers(ctx
, first
, count
);
3455 /* Note that the error semantics for multi-bind commands differ from
3456 * those of other GL commands.
3458 * The Issues section in the ARB_multi_bind spec says:
3460 * "(11) Typically, OpenGL specifies that if an error is generated by a
3461 * command, that command has no effect. This is somewhat
3462 * unfortunate for multi-bind commands, because it would require a
3463 * first pass to scan the entire list of bound objects for errors
3464 * and then a second pass to actually perform the bindings.
3465 * Should we have different error semantics?
3467 * RESOLVED: Yes. In this specification, when the parameters for
3468 * one of the <count> binding points are invalid, that binding point
3469 * is not updated and an error will be generated. However, other
3470 * binding points in the same command will be updated if their
3471 * parameters are valid and no other error occurs."
3474 _mesa_begin_bufferobj_lookups(ctx
);
3476 for (i
= 0; i
< count
; i
++) {
3477 struct gl_uniform_buffer_binding
*binding
=
3478 &ctx
->UniformBufferBindings
[first
+ i
];
3479 struct gl_buffer_object
*bufObj
;
3481 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3482 bufObj
= binding
->BufferObject
;
3484 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3485 "glBindBuffersBase");
3488 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3489 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
3491 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
3495 _mesa_end_bufferobj_lookups(ctx
);
3499 bind_shader_storage_buffers_base(struct gl_context
*ctx
, GLuint first
,
3500 GLsizei count
, const GLuint
*buffers
)
3504 if (!error_check_bind_shader_storage_buffers(ctx
, first
, count
,
3505 "glBindBuffersBase"))
3508 /* Assume that at least one binding will be changed */
3509 FLUSH_VERTICES(ctx
, 0);
3510 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3513 /* The ARB_multi_bind spec says:
3515 * "If <buffers> is NULL, all bindings from <first> through
3516 * <first>+<count>-1 are reset to their unbound (zero) state."
3518 unbind_shader_storage_buffers(ctx
, first
, count
);
3522 /* Note that the error semantics for multi-bind commands differ from
3523 * those of other GL commands.
3525 * The Issues section in the ARB_multi_bind spec says:
3527 * "(11) Typically, OpenGL specifies that if an error is generated by a
3528 * command, that command has no effect. This is somewhat
3529 * unfortunate for multi-bind commands, because it would require a
3530 * first pass to scan the entire list of bound objects for errors
3531 * and then a second pass to actually perform the bindings.
3532 * Should we have different error semantics?
3534 * RESOLVED: Yes. In this specification, when the parameters for
3535 * one of the <count> binding points are invalid, that binding point
3536 * is not updated and an error will be generated. However, other
3537 * binding points in the same command will be updated if their
3538 * parameters are valid and no other error occurs."
3541 _mesa_begin_bufferobj_lookups(ctx
);
3543 for (i
= 0; i
< count
; i
++) {
3544 struct gl_shader_storage_buffer_binding
*binding
=
3545 &ctx
->ShaderStorageBufferBindings
[first
+ i
];
3546 struct gl_buffer_object
*bufObj
;
3548 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3549 bufObj
= binding
->BufferObject
;
3551 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3552 "glBindBuffersBase");
3555 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3556 set_ssbo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
3558 set_ssbo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
3562 _mesa_end_bufferobj_lookups(ctx
);
3566 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3567 const GLuint
*buffers
,
3568 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3572 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
3573 "glBindBuffersRange"))
3576 /* Assume that at least one binding will be changed */
3577 FLUSH_VERTICES(ctx
, 0);
3578 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3581 /* The ARB_multi_bind spec says:
3583 * "If <buffers> is NULL, all bindings from <first> through
3584 * <first>+<count>-1 are reset to their unbound (zero) state.
3585 * In this case, the offsets and sizes associated with the
3586 * binding points are set to default values, ignoring
3587 * <offsets> and <sizes>."
3589 unbind_uniform_buffers(ctx
, first
, count
);
3593 /* Note that the error semantics for multi-bind commands differ from
3594 * those of other GL commands.
3596 * The Issues section in the ARB_multi_bind spec says:
3598 * "(11) Typically, OpenGL specifies that if an error is generated by a
3599 * command, that command has no effect. This is somewhat
3600 * unfortunate for multi-bind commands, because it would require a
3601 * first pass to scan the entire list of bound objects for errors
3602 * and then a second pass to actually perform the bindings.
3603 * Should we have different error semantics?
3605 * RESOLVED: Yes. In this specification, when the parameters for
3606 * one of the <count> binding points are invalid, that binding point
3607 * is not updated and an error will be generated. However, other
3608 * binding points in the same command will be updated if their
3609 * parameters are valid and no other error occurs."
3612 _mesa_begin_bufferobj_lookups(ctx
);
3614 for (i
= 0; i
< count
; i
++) {
3615 struct gl_uniform_buffer_binding
*binding
=
3616 &ctx
->UniformBufferBindings
[first
+ i
];
3617 struct gl_buffer_object
*bufObj
;
3619 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3622 /* The ARB_multi_bind spec says:
3624 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3625 * pair of values in <offsets> and <sizes> does not respectively
3626 * satisfy the constraints described for those parameters for the
3627 * specified target, as described in section 6.7.1 (per binding)."
3629 * Section 6.7.1 refers to table 6.5, which says:
3631 * "┌───────────────────────────────────────────────────────────────┐
3632 * │ Uniform buffer array bindings (see sec. 7.6) │
3633 * ├─────────────────────┬─────────────────────────────────────────┤
3635 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3636 * │ │ OFFSET_ALIGNMENT │
3638 * │ size restriction │ none │
3639 * └─────────────────────┴─────────────────────────────────────────┘"
3641 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3642 _mesa_error(ctx
, GL_INVALID_VALUE
,
3643 "glBindBuffersRange(offsets[%u]=%" PRId64
3644 " is misaligned; it must be a multiple of the value of "
3645 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3646 "target=GL_UNIFORM_BUFFER)",
3647 i
, (int64_t) offsets
[i
],
3648 ctx
->Const
.UniformBufferOffsetAlignment
);
3652 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3653 bufObj
= binding
->BufferObject
;
3655 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3656 "glBindBuffersRange");
3659 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3660 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3662 set_ubo_binding(ctx
, binding
, bufObj
,
3663 offsets
[i
], sizes
[i
], GL_FALSE
);
3667 _mesa_end_bufferobj_lookups(ctx
);
3671 bind_shader_storage_buffers_range(struct gl_context
*ctx
, GLuint first
,
3672 GLsizei count
, const GLuint
*buffers
,
3673 const GLintptr
*offsets
,
3674 const GLsizeiptr
*sizes
)
3678 if (!error_check_bind_shader_storage_buffers(ctx
, first
, count
,
3679 "glBindBuffersRange"))
3682 /* Assume that at least one binding will be changed */
3683 FLUSH_VERTICES(ctx
, 0);
3684 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3687 /* The ARB_multi_bind spec says:
3689 * "If <buffers> is NULL, all bindings from <first> through
3690 * <first>+<count>-1 are reset to their unbound (zero) state.
3691 * In this case, the offsets and sizes associated with the
3692 * binding points are set to default values, ignoring
3693 * <offsets> and <sizes>."
3695 unbind_shader_storage_buffers(ctx
, first
, count
);
3699 /* Note that the error semantics for multi-bind commands differ from
3700 * those of other GL commands.
3702 * The Issues section in the ARB_multi_bind spec says:
3704 * "(11) Typically, OpenGL specifies that if an error is generated by a
3705 * command, that command has no effect. This is somewhat
3706 * unfortunate for multi-bind commands, because it would require a
3707 * first pass to scan the entire list of bound objects for errors
3708 * and then a second pass to actually perform the bindings.
3709 * Should we have different error semantics?
3711 * RESOLVED: Yes. In this specification, when the parameters for
3712 * one of the <count> binding points are invalid, that binding point
3713 * is not updated and an error will be generated. However, other
3714 * binding points in the same command will be updated if their
3715 * parameters are valid and no other error occurs."
3718 _mesa_begin_bufferobj_lookups(ctx
);
3720 for (i
= 0; i
< count
; i
++) {
3721 struct gl_shader_storage_buffer_binding
*binding
=
3722 &ctx
->ShaderStorageBufferBindings
[first
+ i
];
3723 struct gl_buffer_object
*bufObj
;
3725 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3728 /* The ARB_multi_bind spec says:
3730 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3731 * pair of values in <offsets> and <sizes> does not respectively
3732 * satisfy the constraints described for those parameters for the
3733 * specified target, as described in section 6.7.1 (per binding)."
3735 * Section 6.7.1 refers to table 6.5, which says:
3737 * "┌───────────────────────────────────────────────────────────────┐
3738 * │ Shader storage buffer array bindings (see sec. 7.8) │
3739 * ├─────────────────────┬─────────────────────────────────────────┤
3741 * │ offset restriction │ multiple of value of SHADER_STORAGE_- │
3742 * │ │ BUFFER_OFFSET_ALIGNMENT │
3744 * │ size restriction │ none │
3745 * └─────────────────────┴─────────────────────────────────────────┘"
3747 if (offsets
[i
] & (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3748 _mesa_error(ctx
, GL_INVALID_VALUE
,
3749 "glBindBuffersRange(offsets[%u]=%" PRId64
3750 " is misaligned; it must be a multiple of the value of "
3751 "GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT=%u when "
3752 "target=GL_SHADER_STORAGE_BUFFER)",
3753 i
, (int64_t) offsets
[i
],
3754 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3758 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3759 bufObj
= binding
->BufferObject
;
3761 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3762 "glBindBuffersRange");
3765 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3766 set_ssbo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3768 set_ssbo_binding(ctx
, binding
, bufObj
,
3769 offsets
[i
], sizes
[i
], GL_FALSE
);
3773 _mesa_end_bufferobj_lookups(ctx
);
3777 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3778 struct gl_transform_feedback_object
*tfObj
,
3779 GLuint first
, GLsizei count
, const char *caller
)
3781 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3782 _mesa_error(ctx
, GL_INVALID_ENUM
,
3783 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3787 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3789 * "An INVALID_OPERATION error is generated :
3792 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3793 * FEEDBACK_BUFFER and transform feedback is currently active."
3795 * We assume that this is also meant to apply to BindBuffersRange
3796 * and BindBuffersBase.
3798 if (tfObj
->Active
) {
3799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3800 "%s(Changing transform feedback buffers while "
3801 "transform feedback is active)", caller
);
3805 /* The ARB_multi_bind_spec says:
3807 * "An INVALID_OPERATION error is generated if <first> + <count> is
3808 * greater than the number of target-specific indexed binding points,
3809 * as described in section 6.7.1."
3811 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3813 "%s(first=%u + count=%d > the value of "
3814 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3815 caller
, first
, count
,
3816 ctx
->Const
.MaxTransformFeedbackBuffers
);
3824 * Unbind all transform feedback buffers in the range
3825 * <first> through <first>+<count>-1
3828 unbind_xfb_buffers(struct gl_context
*ctx
,
3829 struct gl_transform_feedback_object
*tfObj
,
3830 GLuint first
, GLsizei count
)
3832 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3835 for (i
= 0; i
< count
; i
++)
3836 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3841 bind_xfb_buffers_base(struct gl_context
*ctx
,
3842 GLuint first
, GLsizei count
,
3843 const GLuint
*buffers
)
3845 struct gl_transform_feedback_object
*tfObj
=
3846 ctx
->TransformFeedback
.CurrentObject
;
3849 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3850 "glBindBuffersBase"))
3853 /* Assume that at least one binding will be changed */
3854 FLUSH_VERTICES(ctx
, 0);
3855 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3858 /* The ARB_multi_bind spec says:
3860 * "If <buffers> is NULL, all bindings from <first> through
3861 * <first>+<count>-1 are reset to their unbound (zero) state."
3863 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3867 /* Note that the error semantics for multi-bind commands differ from
3868 * those of other GL commands.
3870 * The Issues section in the ARB_multi_bind spec says:
3872 * "(11) Typically, OpenGL specifies that if an error is generated by a
3873 * command, that command has no effect. This is somewhat
3874 * unfortunate for multi-bind commands, because it would require a
3875 * first pass to scan the entire list of bound objects for errors
3876 * and then a second pass to actually perform the bindings.
3877 * Should we have different error semantics?
3879 * RESOLVED: Yes. In this specification, when the parameters for
3880 * one of the <count> binding points are invalid, that binding point
3881 * is not updated and an error will be generated. However, other
3882 * binding points in the same command will be updated if their
3883 * parameters are valid and no other error occurs."
3886 _mesa_begin_bufferobj_lookups(ctx
);
3888 for (i
= 0; i
< count
; i
++) {
3889 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3890 struct gl_buffer_object
*bufObj
;
3892 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3893 bufObj
= boundBufObj
;
3895 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3896 "glBindBuffersBase");
3899 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3903 _mesa_end_bufferobj_lookups(ctx
);
3907 bind_xfb_buffers_range(struct gl_context
*ctx
,
3908 GLuint first
, GLsizei count
,
3909 const GLuint
*buffers
,
3910 const GLintptr
*offsets
,
3911 const GLsizeiptr
*sizes
)
3913 struct gl_transform_feedback_object
*tfObj
=
3914 ctx
->TransformFeedback
.CurrentObject
;
3917 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3918 "glBindBuffersRange"))
3921 /* Assume that at least one binding will be changed */
3922 FLUSH_VERTICES(ctx
, 0);
3923 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3926 /* The ARB_multi_bind spec says:
3928 * "If <buffers> is NULL, all bindings from <first> through
3929 * <first>+<count>-1 are reset to their unbound (zero) state.
3930 * In this case, the offsets and sizes associated with the
3931 * binding points are set to default values, ignoring
3932 * <offsets> and <sizes>."
3934 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3938 /* Note that the error semantics for multi-bind commands differ from
3939 * those of other GL commands.
3941 * The Issues section in the ARB_multi_bind spec says:
3943 * "(11) Typically, OpenGL specifies that if an error is generated by a
3944 * command, that command has no effect. This is somewhat
3945 * unfortunate for multi-bind commands, because it would require a
3946 * first pass to scan the entire list of bound objects for errors
3947 * and then a second pass to actually perform the bindings.
3948 * Should we have different error semantics?
3950 * RESOLVED: Yes. In this specification, when the parameters for
3951 * one of the <count> binding points are invalid, that binding point
3952 * is not updated and an error will be generated. However, other
3953 * binding points in the same command will be updated if their
3954 * parameters are valid and no other error occurs."
3957 _mesa_begin_bufferobj_lookups(ctx
);
3959 for (i
= 0; i
< count
; i
++) {
3960 const GLuint index
= first
+ i
;
3961 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3962 struct gl_buffer_object
*bufObj
;
3964 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3967 /* The ARB_multi_bind spec says:
3969 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3970 * pair of values in <offsets> and <sizes> does not respectively
3971 * satisfy the constraints described for those parameters for the
3972 * specified target, as described in section 6.7.1 (per binding)."
3974 * Section 6.7.1 refers to table 6.5, which says:
3976 * "┌───────────────────────────────────────────────────────────────┐
3977 * │ Transform feedback array bindings (see sec. 13.2.2) │
3978 * ├───────────────────────┬───────────────────────────────────────┤
3980 * │ offset restriction │ multiple of 4 │
3982 * │ size restriction │ multiple of 4 │
3983 * └───────────────────────┴───────────────────────────────────────┘"
3985 if (offsets
[i
] & 0x3) {
3986 _mesa_error(ctx
, GL_INVALID_VALUE
,
3987 "glBindBuffersRange(offsets[%u]=%" PRId64
3988 " is misaligned; it must be a multiple of 4 when "
3989 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3990 i
, (int64_t) offsets
[i
]);
3994 if (sizes
[i
] & 0x3) {
3995 _mesa_error(ctx
, GL_INVALID_VALUE
,
3996 "glBindBuffersRange(sizes[%u]=%" PRId64
3997 " is misaligned; it must be a multiple of 4 when "
3998 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3999 i
, (int64_t) sizes
[i
]);
4003 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
4004 bufObj
= boundBufObj
;
4006 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4007 "glBindBuffersRange");
4010 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
4011 offsets
[i
], sizes
[i
]);
4014 _mesa_end_bufferobj_lookups(ctx
);
4018 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
4019 GLuint first
, GLsizei count
,
4022 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
4023 _mesa_error(ctx
, GL_INVALID_ENUM
,
4024 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
4028 /* The ARB_multi_bind_spec says:
4030 * "An INVALID_OPERATION error is generated if <first> + <count> is
4031 * greater than the number of target-specific indexed binding points,
4032 * as described in section 6.7.1."
4034 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
4035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4036 "%s(first=%u + count=%d > the value of "
4037 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
4038 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
4046 * Unbind all atomic counter buffers in the range
4047 * <first> through <first>+<count>-1
4050 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
4052 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
4055 for (i
= 0; i
< count
; i
++)
4056 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
4061 bind_atomic_buffers_base(struct gl_context
*ctx
,
4064 const GLuint
*buffers
)
4068 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
4069 "glBindBuffersBase"))
4072 /* Assume that at least one binding will be changed */
4073 FLUSH_VERTICES(ctx
, 0);
4074 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
4077 /* The ARB_multi_bind spec says:
4079 * "If <buffers> is NULL, all bindings from <first> through
4080 * <first>+<count>-1 are reset to their unbound (zero) state."
4082 unbind_atomic_buffers(ctx
, first
, count
);
4086 /* Note that the error semantics for multi-bind commands differ from
4087 * those of other GL commands.
4089 * The Issues section in the ARB_multi_bind spec says:
4091 * "(11) Typically, OpenGL specifies that if an error is generated by a
4092 * command, that command has no effect. This is somewhat
4093 * unfortunate for multi-bind commands, because it would require a
4094 * first pass to scan the entire list of bound objects for errors
4095 * and then a second pass to actually perform the bindings.
4096 * Should we have different error semantics?
4098 * RESOLVED: Yes. In this specification, when the parameters for
4099 * one of the <count> binding points are invalid, that binding point
4100 * is not updated and an error will be generated. However, other
4101 * binding points in the same command will be updated if their
4102 * parameters are valid and no other error occurs."
4105 _mesa_begin_bufferobj_lookups(ctx
);
4107 for (i
= 0; i
< count
; i
++) {
4108 struct gl_atomic_buffer_binding
*binding
=
4109 &ctx
->AtomicBufferBindings
[first
+ i
];
4110 struct gl_buffer_object
*bufObj
;
4112 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
4113 bufObj
= binding
->BufferObject
;
4115 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4116 "glBindBuffersBase");
4119 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
4122 _mesa_end_bufferobj_lookups(ctx
);
4126 bind_atomic_buffers_range(struct gl_context
*ctx
,
4129 const GLuint
*buffers
,
4130 const GLintptr
*offsets
,
4131 const GLsizeiptr
*sizes
)
4135 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
4136 "glBindBuffersRange"))
4139 /* Assume that at least one binding will be changed */
4140 FLUSH_VERTICES(ctx
, 0);
4141 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
4144 /* The ARB_multi_bind spec says:
4146 * "If <buffers> is NULL, all bindings from <first> through
4147 * <first>+<count>-1 are reset to their unbound (zero) state.
4148 * In this case, the offsets and sizes associated with the
4149 * binding points are set to default values, ignoring
4150 * <offsets> and <sizes>."
4152 unbind_atomic_buffers(ctx
, first
, count
);
4156 /* Note that the error semantics for multi-bind commands differ from
4157 * those of other GL commands.
4159 * The Issues section in the ARB_multi_bind spec says:
4161 * "(11) Typically, OpenGL specifies that if an error is generated by a
4162 * command, that command has no effect. This is somewhat
4163 * unfortunate for multi-bind commands, because it would require a
4164 * first pass to scan the entire list of bound objects for errors
4165 * and then a second pass to actually perform the bindings.
4166 * Should we have different error semantics?
4168 * RESOLVED: Yes. In this specification, when the parameters for
4169 * one of the <count> binding points are invalid, that binding point
4170 * is not updated and an error will be generated. However, other
4171 * binding points in the same command will be updated if their
4172 * parameters are valid and no other error occurs."
4175 _mesa_begin_bufferobj_lookups(ctx
);
4177 for (i
= 0; i
< count
; i
++) {
4178 struct gl_atomic_buffer_binding
*binding
=
4179 &ctx
->AtomicBufferBindings
[first
+ i
];
4180 struct gl_buffer_object
*bufObj
;
4182 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
4185 /* The ARB_multi_bind spec says:
4187 * "An INVALID_VALUE error is generated by BindBuffersRange if any
4188 * pair of values in <offsets> and <sizes> does not respectively
4189 * satisfy the constraints described for those parameters for the
4190 * specified target, as described in section 6.7.1 (per binding)."
4192 * Section 6.7.1 refers to table 6.5, which says:
4194 * "┌───────────────────────────────────────────────────────────────┐
4195 * │ Atomic counter array bindings (see sec. 7.7.2) │
4196 * ├───────────────────────┬───────────────────────────────────────┤
4198 * │ offset restriction │ multiple of 4 │
4200 * │ size restriction │ none │
4201 * └───────────────────────┴───────────────────────────────────────┘"
4203 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
4204 _mesa_error(ctx
, GL_INVALID_VALUE
,
4205 "glBindBuffersRange(offsets[%u]=%" PRId64
4206 " is misaligned; it must be a multiple of %d when "
4207 "target=GL_ATOMIC_COUNTER_BUFFER)",
4208 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
4212 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
4213 bufObj
= binding
->BufferObject
;
4215 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4216 "glBindBuffersRange");
4219 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
4222 _mesa_end_bufferobj_lookups(ctx
);
4226 _mesa_BindBufferRange(GLenum target
, GLuint index
,
4227 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
4229 GET_CURRENT_CONTEXT(ctx
);
4230 struct gl_buffer_object
*bufObj
;
4233 bufObj
= ctx
->Shared
->NullBufferObj
;
4235 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4237 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
4238 &bufObj
, "glBindBufferRange"))
4242 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4243 "glBindBufferRange(invalid buffer=%u)", buffer
);
4249 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
4256 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4257 _mesa_bind_buffer_range_transform_feedback(ctx
,
4258 ctx
->TransformFeedback
.CurrentObject
,
4259 index
, bufObj
, offset
, size
,
4262 case GL_UNIFORM_BUFFER
:
4263 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
4265 case GL_SHADER_STORAGE_BUFFER
:
4266 bind_buffer_range_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
);
4268 case GL_ATOMIC_COUNTER_BUFFER
:
4269 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
4270 "glBindBufferRange");
4273 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
4279 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
4281 GET_CURRENT_CONTEXT(ctx
);
4282 struct gl_buffer_object
*bufObj
;
4285 bufObj
= ctx
->Shared
->NullBufferObj
;
4287 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4289 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
4290 &bufObj
, "glBindBufferBase"))
4294 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4295 "glBindBufferBase(invalid buffer=%u)", buffer
);
4299 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
4300 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
4302 * "BindBufferBase is equivalent to calling BindBufferRange with offset
4303 * zero and size equal to the size of buffer."
4305 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
4307 * "If the parameter (starting offset or size) was not specified when the
4308 * buffer object was bound, zero is returned."
4310 * What happens if the size of the buffer changes? Does the size of the
4311 * buffer at the moment glBindBufferBase was called still play a role, like
4312 * the first quote would imply, or is the size meaningless in the
4313 * glBindBufferBase case like the second quote would suggest? The GL 4.1
4314 * core spec page 45 says:
4316 * "It is equivalent to calling BindBufferRange with offset zero, while
4317 * size is determined by the size of the bound buffer at the time the
4320 * My interpretation is that the GL 4.1 spec was a clarification of the
4321 * behavior, not a change. In particular, this choice will only make
4322 * rendering work in cases where it would have had undefined results.
4326 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4327 _mesa_bind_buffer_base_transform_feedback(ctx
,
4328 ctx
->TransformFeedback
.CurrentObject
,
4329 index
, bufObj
, false);
4331 case GL_UNIFORM_BUFFER
:
4332 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
4334 case GL_SHADER_STORAGE_BUFFER
:
4335 bind_buffer_base_shader_storage_buffer(ctx
, index
, bufObj
);
4337 case GL_ATOMIC_COUNTER_BUFFER
:
4338 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
4339 "glBindBufferBase");
4342 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
4348 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
4349 const GLuint
*buffers
,
4350 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
4352 GET_CURRENT_CONTEXT(ctx
);
4355 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4356 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
4358 case GL_UNIFORM_BUFFER
:
4359 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
4361 case GL_SHADER_STORAGE_BUFFER
:
4362 bind_shader_storage_buffers_range(ctx
, first
, count
, buffers
, offsets
,
4365 case GL_ATOMIC_COUNTER_BUFFER
:
4366 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
4370 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
4371 _mesa_enum_to_string(target
));
4377 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
4378 const GLuint
*buffers
)
4380 GET_CURRENT_CONTEXT(ctx
);
4383 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4384 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
4386 case GL_UNIFORM_BUFFER
:
4387 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
4389 case GL_SHADER_STORAGE_BUFFER
:
4390 bind_shader_storage_buffers_base(ctx
, first
, count
, buffers
);
4392 case GL_ATOMIC_COUNTER_BUFFER
:
4393 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
4396 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
4397 _mesa_enum_to_string(target
));
4403 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
4406 GET_CURRENT_CONTEXT(ctx
);
4407 struct gl_buffer_object
*bufObj
;
4408 const GLintptr end
= offset
+ length
;
4410 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4412 _mesa_error(ctx
, GL_INVALID_VALUE
,
4413 "glInvalidateBufferSubData(name = 0x%x) invalid object",
4418 /* The GL_ARB_invalidate_subdata spec says:
4420 * "An INVALID_VALUE error is generated if <offset> or <length> is
4421 * negative, or if <offset> + <length> is greater than the value of
4424 if (end
< 0 || end
> bufObj
->Size
) {
4425 _mesa_error(ctx
, GL_INVALID_VALUE
,
4426 "glInvalidateBufferSubData(invalid offset or length)");
4430 /* The OpenGL 4.4 (Core Profile) spec says:
4432 * "An INVALID_OPERATION error is generated if buffer is currently
4433 * mapped by MapBuffer or if the invalidate range intersects the range
4434 * currently mapped by MapBufferRange, unless it was mapped
4435 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4437 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
4438 bufferobj_range_mapped(bufObj
, offset
, length
)) {
4439 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4440 "glInvalidateBufferSubData(intersection with mapped "
4445 /* We don't actually do anything for this yet. Just return after
4446 * validating the parameters and generating the required errors.
4452 _mesa_InvalidateBufferData(GLuint buffer
)
4454 GET_CURRENT_CONTEXT(ctx
);
4455 struct gl_buffer_object
*bufObj
;
4457 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4459 _mesa_error(ctx
, GL_INVALID_VALUE
,
4460 "glInvalidateBufferData(name = 0x%x) invalid object",
4465 /* The OpenGL 4.4 (Core Profile) spec says:
4467 * "An INVALID_OPERATION error is generated if buffer is currently
4468 * mapped by MapBuffer or if the invalidate range intersects the range
4469 * currently mapped by MapBufferRange, unless it was mapped
4470 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4472 if (_mesa_check_disallowed_mapping(bufObj
)) {
4473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4474 "glInvalidateBufferData(intersection with mapped "
4479 /* We don't actually do anything for this yet. Just return after
4480 * validating the parameters and generating the required errors.