2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
34 #include <inttypes.h> /* for PRId64 macro */
41 #include "bufferobj.h"
46 #include "glformats.h"
48 #include "transformfeedback.h"
54 /*#define BOUNDS_CHECK*/
58 * Used as a placeholder for buffer objects between glGenBuffers() and
59 * glBindBuffer() so that glIsBuffer() can work correctly.
61 static struct gl_buffer_object DummyBufferObject
;
65 * Return pointer to address of a buffer object target.
66 * \param ctx the GL context
67 * \param target the buffer object target to be retrieved.
68 * \return pointer to pointer to the buffer object bound to \c target in the
69 * specified context or \c NULL if \c target is invalid.
71 static inline struct gl_buffer_object
**
72 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
74 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
76 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
77 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
81 case GL_ARRAY_BUFFER_ARB
:
82 return &ctx
->Array
.ArrayBufferObj
;
83 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
84 return &ctx
->Array
.VAO
->IndexBufferObj
;
85 case GL_PIXEL_PACK_BUFFER_EXT
:
86 return &ctx
->Pack
.BufferObj
;
87 case GL_PIXEL_UNPACK_BUFFER_EXT
:
88 return &ctx
->Unpack
.BufferObj
;
89 case GL_COPY_READ_BUFFER
:
90 return &ctx
->CopyReadBuffer
;
91 case GL_COPY_WRITE_BUFFER
:
92 return &ctx
->CopyWriteBuffer
;
93 case GL_DRAW_INDIRECT_BUFFER
:
94 if (ctx
->API
== API_OPENGL_CORE
&&
95 ctx
->Extensions
.ARB_draw_indirect
) {
96 return &ctx
->DrawIndirectBuffer
;
99 case GL_TRANSFORM_FEEDBACK_BUFFER
:
100 if (ctx
->Extensions
.EXT_transform_feedback
) {
101 return &ctx
->TransformFeedback
.CurrentBuffer
;
104 case GL_TEXTURE_BUFFER
:
105 if (ctx
->API
== API_OPENGL_CORE
&&
106 ctx
->Extensions
.ARB_texture_buffer_object
) {
107 return &ctx
->Texture
.BufferObject
;
110 case GL_UNIFORM_BUFFER
:
111 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
112 return &ctx
->UniformBuffer
;
115 case GL_SHADER_STORAGE_BUFFER
:
116 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
117 return &ctx
->ShaderStorageBuffer
;
120 case GL_ATOMIC_COUNTER_BUFFER
:
121 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
122 return &ctx
->AtomicBuffer
;
125 case GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
:
126 if (ctx
->Extensions
.AMD_pinned_memory
) {
127 return &ctx
->ExternalVirtualMemoryBuffer
;
138 * Get the buffer object bound to the specified target in a GL context.
139 * \param ctx the GL context
140 * \param target the buffer object target to be retrieved.
141 * \param error the GL error to record if target is illegal.
142 * \return pointer to the buffer object bound to \c target in the
143 * specified context or \c NULL if \c target is invalid.
145 static inline struct gl_buffer_object
*
146 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
149 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
152 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
156 if (!_mesa_is_bufferobj(*bufObj
)) {
157 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
166 * Convert a GLbitfield describing the mapped buffer access flags
167 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
170 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
172 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
173 if ((access
& rwFlags
) == rwFlags
)
174 return GL_READ_WRITE
;
175 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
177 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
178 return GL_WRITE_ONLY
;
180 /* Otherwise, AccessFlags is zero (the default state).
182 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
184 * Name Type Initial Value Legal Values
186 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
189 * However, table 6.8 in the GL_OES_mapbuffer extension says:
191 * Get Value Type Get Command Value Description
192 * --------- ---- ----------- ----- -----------
193 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
195 * The difference is because GL_OES_mapbuffer only supports mapping buffers
200 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
205 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
207 * The regions do not overlap if and only if the end of the given
208 * region is before the mapped region or the start of the given region
209 * is after the mapped region.
211 * \param obj Buffer object target on which to operate.
212 * \param offset Offset of the first byte of the subdata range.
213 * \param size Size, in bytes, of the subdata range.
214 * \return true if ranges overlap, false otherwise
218 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
219 GLintptr offset
, GLsizeiptr size
)
221 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
222 const GLintptr end
= offset
+ size
;
223 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
224 obj
->Mappings
[MAP_USER
].Length
;
226 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
235 * Tests the subdata range parameters and sets the GL error code for
236 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
237 * \c glClearBufferSubData.
239 * \param ctx GL context.
240 * \param bufObj The buffer object.
241 * \param offset Offset of the first byte of the subdata range.
242 * \param size Size, in bytes, of the subdata range.
243 * \param mappedRange If true, checks if an overlapping range is mapped.
244 * If false, checks if buffer is mapped.
245 * \param caller Name of calling function for recording errors.
246 * \return false if error, true otherwise
248 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
251 buffer_object_subdata_range_good(struct gl_context
*ctx
,
252 struct gl_buffer_object
*bufObj
,
253 GLintptr offset
, GLsizeiptr size
,
254 bool mappedRange
, const char *caller
)
257 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
262 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
266 if (offset
+ size
> bufObj
->Size
) {
267 _mesa_error(ctx
, GL_INVALID_VALUE
,
268 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
269 (unsigned long) offset
,
270 (unsigned long) size
,
271 (unsigned long) bufObj
->Size
);
275 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
279 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
281 "%s(range is mapped without persistent bit)",
287 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
289 "%s(buffer is mapped without persistent bit)",
300 * Test the format and type parameters and set the GL error code for
301 * \c glClearBufferData and \c glClearBufferSubData.
303 * \param ctx GL context.
304 * \param internalformat Format to which the data is to be converted.
305 * \param format Format of the supplied data.
306 * \param type Type of the supplied data.
307 * \param caller Name of calling function for recording errors.
308 * \return If internalformat, format and type are legal the mesa_format
309 * corresponding to internalformat, otherwise MESA_FORMAT_NONE.
311 * \sa glClearBufferData and glClearBufferSubData
314 validate_clear_buffer_format(struct gl_context
*ctx
,
315 GLenum internalformat
,
316 GLenum format
, GLenum type
,
319 mesa_format mesaFormat
;
320 GLenum errorFormatType
;
322 mesaFormat
= _mesa_validate_texbuffer_format(ctx
, internalformat
);
323 if (mesaFormat
== MESA_FORMAT_NONE
) {
324 _mesa_error(ctx
, GL_INVALID_ENUM
,
325 "%s(invalid internalformat)", caller
);
326 return MESA_FORMAT_NONE
;
329 /* NOTE: not mentioned in ARB_clear_buffer_object but according to
330 * EXT_texture_integer there is no conversion between integer and
331 * non-integer formats
333 if (_mesa_is_enum_format_signed_int(format
) !=
334 _mesa_is_format_integer_color(mesaFormat
)) {
335 _mesa_error(ctx
, GL_INVALID_OPERATION
,
336 "%s(integer vs non-integer)", caller
);
337 return MESA_FORMAT_NONE
;
340 if (!_mesa_is_color_format(format
)) {
341 _mesa_error(ctx
, GL_INVALID_ENUM
,
342 "%s(format is not a color format)", caller
);
343 return MESA_FORMAT_NONE
;
346 errorFormatType
= _mesa_error_check_format_and_type(ctx
, format
, type
);
347 if (errorFormatType
!= GL_NO_ERROR
) {
348 _mesa_error(ctx
, GL_INVALID_ENUM
,
349 "%s(invalid format or type)", caller
);
350 return MESA_FORMAT_NONE
;
358 * Convert user-specified clear value to the specified internal format.
360 * \param ctx GL context.
361 * \param internalformat Format to which the data is converted.
362 * \param clearValue Points to the converted clear value.
363 * \param format Format of the supplied data.
364 * \param type Type of the supplied data.
365 * \param data Data which is to be converted to internalformat.
366 * \param caller Name of calling function for recording errors.
367 * \return true if data could be converted, false otherwise.
369 * \sa glClearBufferData, glClearBufferSubData
372 convert_clear_buffer_data(struct gl_context
*ctx
,
373 mesa_format internalformat
,
374 GLubyte
*clearValue
, GLenum format
, GLenum type
,
375 const GLvoid
*data
, const char *caller
)
377 GLenum internalformatBase
= _mesa_get_format_base_format(internalformat
);
379 if (_mesa_texstore(ctx
, 1, internalformatBase
, internalformat
,
380 0, &clearValue
, 1, 1, 1,
381 format
, type
, data
, &ctx
->Unpack
)) {
385 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
392 * Allocate and initialize a new buffer object.
394 * Default callback for the \c dd_function_table::NewBufferObject() hook.
396 static struct gl_buffer_object
*
397 _mesa_new_buffer_object(struct gl_context
*ctx
, GLuint name
)
399 struct gl_buffer_object
*obj
;
403 obj
= MALLOC_STRUCT(gl_buffer_object
);
404 _mesa_initialize_buffer_object(ctx
, obj
, name
);
410 * Delete a buffer object.
412 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
415 _mesa_delete_buffer_object(struct gl_context
*ctx
,
416 struct gl_buffer_object
*bufObj
)
420 _mesa_align_free(bufObj
->Data
);
422 /* assign strange values here to help w/ debugging */
423 bufObj
->RefCount
= -1000;
426 mtx_destroy(&bufObj
->Mutex
);
434 * Set ptr to bufObj w/ reference counting.
435 * This is normally only called from the _mesa_reference_buffer_object() macro
436 * when there's a real pointer change.
439 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
440 struct gl_buffer_object
**ptr
,
441 struct gl_buffer_object
*bufObj
)
444 /* Unreference the old buffer */
445 GLboolean deleteFlag
= GL_FALSE
;
446 struct gl_buffer_object
*oldObj
= *ptr
;
448 mtx_lock(&oldObj
->Mutex
);
449 assert(oldObj
->RefCount
> 0);
452 printf("BufferObj %p %d DECR to %d\n",
453 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
455 deleteFlag
= (oldObj
->RefCount
== 0);
456 mtx_unlock(&oldObj
->Mutex
);
460 /* some sanity checking: don't delete a buffer still in use */
462 /* unfortunately, these tests are invalid during context tear-down */
463 assert(ctx
->Array
.ArrayBufferObj
!= bufObj
);
464 assert(ctx
->Array
.VAO
->IndexBufferObj
!= bufObj
);
465 assert(ctx
->Array
.VAO
->Vertex
.BufferObj
!= bufObj
);
468 assert(ctx
->Driver
.DeleteBuffer
);
469 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
477 /* reference new buffer */
478 mtx_lock(&bufObj
->Mutex
);
479 if (bufObj
->RefCount
== 0) {
480 /* this buffer's being deleted (look just above) */
481 /* Not sure this can every really happen. Warn if it does. */
482 _mesa_problem(NULL
, "referencing deleted buffer object");
488 printf("BufferObj %p %d INCR to %d\n",
489 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
493 mtx_unlock(&bufObj
->Mutex
);
499 * Initialize a buffer object to default values.
502 _mesa_initialize_buffer_object(struct gl_context
*ctx
,
503 struct gl_buffer_object
*obj
,
506 memset(obj
, 0, sizeof(struct gl_buffer_object
));
507 mtx_init(&obj
->Mutex
, mtx_plain
);
510 obj
->Usage
= GL_STATIC_DRAW_ARB
;
516 * Callback called from _mesa_HashWalk()
519 count_buffer_size(GLuint key
, void *data
, void *userData
)
521 const struct gl_buffer_object
*bufObj
=
522 (const struct gl_buffer_object
*) data
;
523 GLuint
*total
= (GLuint
*) userData
;
525 *total
= *total
+ bufObj
->Size
;
530 * Compute total size (in bytes) of all buffer objects for the given context.
531 * For debugging purposes.
534 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
538 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
545 * Allocate space for and store data in a buffer object. Any data that was
546 * previously stored in the buffer object is lost. If \c data is \c NULL,
547 * memory will be allocated, but no copy will occur.
549 * This is the default callback for \c dd_function_table::BufferData()
550 * Note that all GL error checking will have been done already.
552 * \param ctx GL context.
553 * \param target Buffer object target on which to operate.
554 * \param size Size, in bytes, of the new data store.
555 * \param data Pointer to the data to store in the buffer object. This
556 * pointer may be \c NULL.
557 * \param usage Hints about how the data will be used.
558 * \param bufObj Object to be used.
560 * \return GL_TRUE for success, GL_FALSE for failure
561 * \sa glBufferDataARB, dd_function_table::BufferData.
564 buffer_data_fallback(struct gl_context
*ctx
, GLenum target
, GLsizeiptr size
,
565 const GLvoid
*data
, GLenum usage
, GLenum storageFlags
,
566 struct gl_buffer_object
*bufObj
)
572 _mesa_align_free( bufObj
->Data
);
574 new_data
= _mesa_align_malloc( size
, ctx
->Const
.MinMapBufferAlignment
);
576 bufObj
->Data
= (GLubyte
*) new_data
;
578 bufObj
->Usage
= usage
;
579 bufObj
->StorageFlags
= storageFlags
;
582 memcpy( bufObj
->Data
, data
, size
);
594 * Replace data in a subrange of buffer object. If the data range
595 * specified by \c size + \c offset extends beyond the end of the buffer or
596 * if \c data is \c NULL, no copy is performed.
598 * This is the default callback for \c dd_function_table::BufferSubData()
599 * Note that all GL error checking will have been done already.
601 * \param ctx GL context.
602 * \param offset Offset of the first byte to be modified.
603 * \param size Size, in bytes, of the data range.
604 * \param data Pointer to the data to store in the buffer object.
605 * \param bufObj Object to be used.
607 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
610 buffer_sub_data_fallback(struct gl_context
*ctx
, GLintptr offset
,
611 GLsizeiptr size
, const GLvoid
*data
,
612 struct gl_buffer_object
*bufObj
)
616 /* this should have been caught in _mesa_BufferSubData() */
617 assert(size
+ offset
<= bufObj
->Size
);
620 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
626 * Retrieve data from a subrange of buffer object. If the data range
627 * specified by \c size + \c offset extends beyond the end of the buffer or
628 * if \c data is \c NULL, no copy is performed.
630 * This is the default callback for \c dd_function_table::GetBufferSubData()
631 * Note that all GL error checking will have been done already.
633 * \param ctx GL context.
634 * \param target Buffer object target on which to operate.
635 * \param offset Offset of the first byte to be fetched.
636 * \param size Size, in bytes, of the data range.
637 * \param data Destination for data
638 * \param bufObj Object to be used.
640 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
643 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
644 GLsizeiptrARB size
, GLvoid
* data
,
645 struct gl_buffer_object
* bufObj
)
649 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
650 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
656 * Clear a subrange of the buffer object with copies of the supplied data.
657 * If data is NULL the buffer is filled with zeros.
659 * This is the default callback for \c dd_function_table::ClearBufferSubData()
660 * Note that all GL error checking will have been done already.
662 * \param ctx GL context.
663 * \param offset Offset of the first byte to be cleared.
664 * \param size Size, in bytes, of the to be cleared range.
665 * \param clearValue Source of the data.
666 * \param clearValueSize Size, in bytes, of the supplied data.
667 * \param bufObj Object to be cleared.
669 * \sa glClearBufferSubData, glClearBufferData and
670 * dd_function_table::ClearBufferSubData.
673 _mesa_ClearBufferSubData_sw(struct gl_context
*ctx
,
674 GLintptr offset
, GLsizeiptr size
,
675 const GLvoid
*clearValue
,
676 GLsizeiptr clearValueSize
,
677 struct gl_buffer_object
*bufObj
)
682 assert(ctx
->Driver
.MapBufferRange
);
683 dest
= ctx
->Driver
.MapBufferRange(ctx
, offset
, size
,
685 GL_MAP_INVALIDATE_RANGE_BIT
,
686 bufObj
, MAP_INTERNAL
);
689 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearBuffer[Sub]Data");
693 if (clearValue
== NULL
) {
694 /* Clear with zeros, per the spec */
695 memset(dest
, 0, size
);
696 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
700 for (i
= 0; i
< size
/clearValueSize
; ++i
) {
701 memcpy(dest
, clearValue
, clearValueSize
);
702 dest
+= clearValueSize
;
705 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
710 * Default fallback for \c dd_function_table::MapBufferRange().
711 * Called via glMapBufferRange().
714 map_buffer_range_fallback(struct gl_context
*ctx
, GLintptr offset
,
715 GLsizeiptr length
, GLbitfield access
,
716 struct gl_buffer_object
*bufObj
,
717 gl_map_buffer_index index
)
720 assert(!_mesa_bufferobj_mapped(bufObj
, index
));
721 /* Just return a direct pointer to the data */
722 bufObj
->Mappings
[index
].Pointer
= bufObj
->Data
+ offset
;
723 bufObj
->Mappings
[index
].Length
= length
;
724 bufObj
->Mappings
[index
].Offset
= offset
;
725 bufObj
->Mappings
[index
].AccessFlags
= access
;
726 return bufObj
->Mappings
[index
].Pointer
;
731 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
732 * Called via glFlushMappedBufferRange().
735 flush_mapped_buffer_range_fallback(struct gl_context
*ctx
,
736 GLintptr offset
, GLsizeiptr length
,
737 struct gl_buffer_object
*obj
,
738 gl_map_buffer_index index
)
749 * Default callback for \c dd_function_table::UnmapBuffer().
751 * The input parameters will have been already tested for errors.
753 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
756 unmap_buffer_fallback(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
757 gl_map_buffer_index index
)
760 /* XXX we might assert here that bufObj->Pointer is non-null */
761 bufObj
->Mappings
[index
].Pointer
= NULL
;
762 bufObj
->Mappings
[index
].Length
= 0;
763 bufObj
->Mappings
[index
].Offset
= 0;
764 bufObj
->Mappings
[index
].AccessFlags
= 0x0;
770 * Default fallback for \c dd_function_table::CopyBufferSubData().
771 * Called via glCopyBufferSubData().
774 copy_buffer_sub_data_fallback(struct gl_context
*ctx
,
775 struct gl_buffer_object
*src
,
776 struct gl_buffer_object
*dst
,
777 GLintptr readOffset
, GLintptr writeOffset
,
780 GLubyte
*srcPtr
, *dstPtr
;
783 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
785 GL_MAP_WRITE_BIT
, src
,
791 srcPtr
+= readOffset
;
792 dstPtr
+= writeOffset
;
794 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
795 GL_MAP_READ_BIT
, src
,
797 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
799 GL_MAP_INVALIDATE_RANGE_BIT
), dst
,
803 /* Note: the src and dst regions will never overlap. Trying to do so
804 * would generate GL_INVALID_VALUE earlier.
806 if (srcPtr
&& dstPtr
)
807 memcpy(dstPtr
, srcPtr
, size
);
809 ctx
->Driver
.UnmapBuffer(ctx
, src
, MAP_INTERNAL
);
811 ctx
->Driver
.UnmapBuffer(ctx
, dst
, MAP_INTERNAL
);
817 * Initialize the state associated with buffer objects
820 _mesa_init_buffer_objects( struct gl_context
*ctx
)
824 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
825 mtx_init(&DummyBufferObject
.Mutex
, mtx_plain
);
826 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
828 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
829 ctx
->Shared
->NullBufferObj
);
831 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
832 ctx
->Shared
->NullBufferObj
);
833 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
834 ctx
->Shared
->NullBufferObj
);
836 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
837 ctx
->Shared
->NullBufferObj
);
839 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
,
840 ctx
->Shared
->NullBufferObj
);
842 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
,
843 ctx
->Shared
->NullBufferObj
);
845 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
846 ctx
->Shared
->NullBufferObj
);
848 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
849 _mesa_reference_buffer_object(ctx
,
850 &ctx
->UniformBufferBindings
[i
].BufferObject
,
851 ctx
->Shared
->NullBufferObj
);
852 ctx
->UniformBufferBindings
[i
].Offset
= -1;
853 ctx
->UniformBufferBindings
[i
].Size
= -1;
856 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
857 _mesa_reference_buffer_object(ctx
,
858 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
859 ctx
->Shared
->NullBufferObj
);
860 ctx
->ShaderStorageBufferBindings
[i
].Offset
= -1;
861 ctx
->ShaderStorageBufferBindings
[i
].Size
= -1;
864 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
865 _mesa_reference_buffer_object(ctx
,
866 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
867 ctx
->Shared
->NullBufferObj
);
868 ctx
->AtomicBufferBindings
[i
].Offset
= -1;
869 ctx
->AtomicBufferBindings
[i
].Size
= -1;
875 _mesa_free_buffer_objects( struct gl_context
*ctx
)
879 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
881 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
882 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
884 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
886 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, NULL
);
888 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
890 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
892 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
893 _mesa_reference_buffer_object(ctx
,
894 &ctx
->UniformBufferBindings
[i
].BufferObject
,
898 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
899 _mesa_reference_buffer_object(ctx
,
900 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
904 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
905 _mesa_reference_buffer_object(ctx
,
906 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
913 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
916 struct gl_buffer_object
**buf_handle
,
919 struct gl_buffer_object
*buf
= *buf_handle
;
921 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
922 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
926 if (!buf
|| buf
== &DummyBufferObject
) {
927 /* If this is a new buffer object id, or one which was generated but
928 * never used before, allocate a buffer object now.
930 assert(ctx
->Driver
.NewBufferObject
);
931 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
);
933 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
936 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
944 * Bind the specified target to buffer for the specified context.
945 * Called by glBindBuffer() and other functions.
948 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
950 struct gl_buffer_object
*oldBufObj
;
951 struct gl_buffer_object
*newBufObj
= NULL
;
952 struct gl_buffer_object
**bindTarget
= NULL
;
954 bindTarget
= get_buffer_target(ctx
, target
);
956 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
960 /* Get pointer to old buffer object (to be unbound) */
961 oldBufObj
= *bindTarget
;
962 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
963 return; /* rebinding the same buffer object- no change */
966 * Get pointer to new buffer object (newBufObj)
969 /* The spec says there's not a buffer object named 0, but we use
970 * one internally because it simplifies things.
972 newBufObj
= ctx
->Shared
->NullBufferObj
;
975 /* non-default buffer object */
976 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
977 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
978 &newBufObj
, "glBindBuffer"))
982 /* bind new buffer */
983 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
988 * Update the default buffer objects in the given context to reference those
989 * specified in the shared state and release those referencing the old
993 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
995 /* Bind the NullBufferObj to remove references to those
996 * in the shared context hash table.
998 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
999 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
1000 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
1001 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
1007 * Return the gl_buffer_object for the given ID.
1008 * Always return NULL for ID 0.
1010 struct gl_buffer_object
*
1011 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
1016 return (struct gl_buffer_object
*)
1017 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
1021 struct gl_buffer_object
*
1022 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1024 return (struct gl_buffer_object
*)
1025 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1029 * A convenience function for direct state access functions that throws
1030 * GL_INVALID_OPERATION if buffer is not the name of an existing
1033 struct gl_buffer_object
*
1034 _mesa_lookup_bufferobj_err(struct gl_context
*ctx
, GLuint buffer
,
1037 struct gl_buffer_object
*bufObj
;
1039 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1040 if (!bufObj
|| bufObj
== &DummyBufferObject
) {
1041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1042 "%s(non-existent buffer object %u)", caller
, buffer
);
1051 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1053 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1058 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1060 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1065 * Look up a buffer object for a multi-bind function.
1067 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1068 * of generating an error if the buffer ID is not zero or the name
1069 * of an existing buffer object.
1071 * If the buffer ID refers to an existing buffer object, a pointer
1072 * to the buffer object is returned. If the ID is zero, a pointer
1073 * to the shared NullBufferObj is returned. If the ID is not zero
1074 * and does not refer to a valid buffer object, this function
1077 * This function assumes that the caller has already locked the
1078 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1080 struct gl_buffer_object
*
1081 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1082 const GLuint
*buffers
,
1083 GLuint index
, const char *caller
)
1085 struct gl_buffer_object
*bufObj
;
1087 if (buffers
[index
] != 0) {
1088 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1090 /* The multi-bind functions don't create the buffer objects
1091 when they don't exist. */
1092 if (bufObj
== &DummyBufferObject
)
1095 bufObj
= ctx
->Shared
->NullBufferObj
;
1098 /* The ARB_multi_bind spec says:
1100 * "An INVALID_OPERATION error is generated if any value
1101 * in <buffers> is not zero or the name of an existing
1102 * buffer object (per binding)."
1104 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1105 "%s(buffers[%u]=%u is not zero or the name "
1106 "of an existing buffer object)",
1107 caller
, index
, buffers
[index
]);
1115 * If *ptr points to obj, set ptr = the Null/default buffer object.
1116 * This is a helper for buffer object deletion.
1117 * The GL spec says that deleting a buffer object causes it to get
1118 * unbound from all arrays in the current context.
1121 unbind(struct gl_context
*ctx
,
1122 struct gl_buffer_object
**ptr
,
1123 struct gl_buffer_object
*obj
)
1126 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1132 * Plug default/fallback buffer object functions into the device
1136 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1138 /* GL_ARB_vertex/pixel_buffer_object */
1139 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1140 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1141 driver
->BufferData
= buffer_data_fallback
;
1142 driver
->BufferSubData
= buffer_sub_data_fallback
;
1143 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1144 driver
->UnmapBuffer
= unmap_buffer_fallback
;
1146 /* GL_ARB_clear_buffer_object */
1147 driver
->ClearBufferSubData
= _mesa_ClearBufferSubData_sw
;
1149 /* GL_ARB_map_buffer_range */
1150 driver
->MapBufferRange
= map_buffer_range_fallback
;
1151 driver
->FlushMappedBufferRange
= flush_mapped_buffer_range_fallback
;
1153 /* GL_ARB_copy_buffer */
1154 driver
->CopyBufferSubData
= copy_buffer_sub_data_fallback
;
1159 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1160 struct gl_buffer_object
*bufObj
)
1164 for (i
= 0; i
< MAP_COUNT
; i
++) {
1165 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1166 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1167 assert(bufObj
->Mappings
[i
].Pointer
== NULL
);
1168 bufObj
->Mappings
[i
].AccessFlags
= 0;
1174 /**********************************************************************/
1176 /**********************************************************************/
1179 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1181 GET_CURRENT_CONTEXT(ctx
);
1183 if (MESA_VERBOSE
& VERBOSE_API
)
1184 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1185 _mesa_enum_to_string(target
), buffer
);
1187 bind_buffer_object(ctx
, target
, buffer
);
1192 * Delete a set of buffer objects.
1194 * \param n Number of buffer objects to delete.
1195 * \param ids Array of \c n buffer object IDs.
1198 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1200 GET_CURRENT_CONTEXT(ctx
);
1202 FLUSH_VERTICES(ctx
, 0);
1205 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1209 mtx_lock(&ctx
->Shared
->Mutex
);
1211 for (i
= 0; i
< n
; i
++) {
1212 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1214 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1217 assert(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1219 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1221 /* unbind any vertex pointers bound to this buffer */
1222 for (j
= 0; j
< ARRAY_SIZE(vao
->VertexBinding
); j
++) {
1223 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1226 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1227 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1229 if (vao
->IndexBufferObj
== bufObj
) {
1230 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1233 /* unbind ARB_draw_indirect binding point */
1234 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1235 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1238 /* unbind ARB_copy_buffer binding points */
1239 if (ctx
->CopyReadBuffer
== bufObj
) {
1240 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1242 if (ctx
->CopyWriteBuffer
== bufObj
) {
1243 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1246 /* unbind transform feedback binding points */
1247 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1248 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1250 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1251 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1252 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1256 /* unbind UBO binding points */
1257 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1258 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1259 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1263 if (ctx
->UniformBuffer
== bufObj
) {
1264 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1267 /* unbind SSBO binding points */
1268 for (j
= 0; j
< ctx
->Const
.MaxShaderStorageBufferBindings
; j
++) {
1269 if (ctx
->ShaderStorageBufferBindings
[j
].BufferObject
== bufObj
) {
1270 _mesa_BindBufferBase(GL_SHADER_STORAGE_BUFFER
, j
, 0);
1274 if (ctx
->ShaderStorageBuffer
== bufObj
) {
1275 _mesa_BindBuffer(GL_SHADER_STORAGE_BUFFER
, 0);
1278 /* unbind Atomci Buffer binding points */
1279 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1280 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1281 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1285 if (ctx
->AtomicBuffer
== bufObj
) {
1286 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1289 /* unbind any pixel pack/unpack pointers bound to this buffer */
1290 if (ctx
->Pack
.BufferObj
== bufObj
) {
1291 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1293 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1294 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1297 if (ctx
->Texture
.BufferObject
== bufObj
) {
1298 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1301 if (ctx
->ExternalVirtualMemoryBuffer
== bufObj
) {
1302 _mesa_BindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
, 0);
1305 /* The ID is immediately freed for re-use */
1306 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1307 /* Make sure we do not run into the classic ABA problem on bind.
1308 * We don't want to allow re-binding a buffer object that's been
1309 * "deleted" by glDeleteBuffers().
1311 * The explicit rebinding to the default object in the current context
1312 * prevents the above in the current context, but another context
1313 * sharing the same objects might suffer from this problem.
1314 * The alternative would be to do the hash lookup in any case on bind
1315 * which would introduce more runtime overhead than this.
1317 bufObj
->DeletePending
= GL_TRUE
;
1318 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1322 mtx_unlock(&ctx
->Shared
->Mutex
);
1327 * This is the implementation for glGenBuffers and glCreateBuffers. It is not
1328 * exposed to the rest of Mesa to encourage the use of nameless buffers in
1332 create_buffers(GLsizei n
, GLuint
*buffers
, bool dsa
)
1334 GET_CURRENT_CONTEXT(ctx
);
1337 struct gl_buffer_object
*buf
;
1339 const char *func
= dsa
? "glCreateBuffers" : "glGenBuffers";
1341 if (MESA_VERBOSE
& VERBOSE_API
)
1342 _mesa_debug(ctx
, "%s(%d)\n", func
, n
);
1345 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n %d < 0)", func
, n
);
1354 * This must be atomic (generation and allocation of buffer object IDs)
1356 mtx_lock(&ctx
->Shared
->Mutex
);
1358 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1360 /* Insert the ID and pointer into the hash table. If non-DSA, insert a
1361 * DummyBufferObject. Otherwise, create a new buffer object and insert
1364 for (i
= 0; i
< n
; i
++) {
1365 buffers
[i
] = first
+ i
;
1367 assert(ctx
->Driver
.NewBufferObject
);
1368 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffers
[i
]);
1370 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1371 mtx_unlock(&ctx
->Shared
->Mutex
);
1376 buf
= &DummyBufferObject
;
1378 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffers
[i
], buf
);
1381 mtx_unlock(&ctx
->Shared
->Mutex
);
1385 * Generate a set of unique buffer object IDs and store them in \c buffers.
1387 * \param n Number of IDs to generate.
1388 * \param buffers Array of \c n locations to store the IDs.
1391 _mesa_GenBuffers(GLsizei n
, GLuint
*buffers
)
1393 create_buffers(n
, buffers
, false);
1397 * Create a set of buffer objects and store their unique IDs in \c buffers.
1399 * \param n Number of IDs to generate.
1400 * \param buffers Array of \c n locations to store the IDs.
1403 _mesa_CreateBuffers(GLsizei n
, GLuint
*buffers
)
1405 create_buffers(n
, buffers
, true);
1410 * Determine if ID is the name of a buffer object.
1412 * \param id ID of the potential buffer object.
1413 * \return \c GL_TRUE if \c id is the name of a buffer object,
1414 * \c GL_FALSE otherwise.
1416 GLboolean GLAPIENTRY
1417 _mesa_IsBuffer(GLuint id
)
1419 struct gl_buffer_object
*bufObj
;
1420 GET_CURRENT_CONTEXT(ctx
);
1421 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1423 mtx_lock(&ctx
->Shared
->Mutex
);
1424 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1425 mtx_unlock(&ctx
->Shared
->Mutex
);
1427 return bufObj
&& bufObj
!= &DummyBufferObject
;
1432 _mesa_buffer_storage(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1433 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1434 GLbitfield flags
, const char *func
)
1437 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size <= 0)", func
);
1441 if (flags
& ~(GL_MAP_READ_BIT
|
1443 GL_MAP_PERSISTENT_BIT
|
1444 GL_MAP_COHERENT_BIT
|
1445 GL_DYNAMIC_STORAGE_BIT
|
1446 GL_CLIENT_STORAGE_BIT
)) {
1447 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid flag bits set)", func
);
1451 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1452 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1453 _mesa_error(ctx
, GL_INVALID_VALUE
,
1454 "%s(PERSISTENT and flags!=READ/WRITE)", func
);
1458 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1459 _mesa_error(ctx
, GL_INVALID_VALUE
,
1460 "%s(COHERENT and flags!=PERSISTENT)", func
);
1464 if (bufObj
->Immutable
) {
1465 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1469 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1470 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1472 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1474 bufObj
->Written
= GL_TRUE
;
1475 bufObj
->Immutable
= GL_TRUE
;
1477 assert(ctx
->Driver
.BufferData
);
1478 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1480 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1481 /* Even though the interaction between AMD_pinned_memory and
1482 * glBufferStorage is not described in the spec, Graham Sellers
1483 * said that it should behave the same as glBufferData.
1485 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1488 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1494 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1497 GET_CURRENT_CONTEXT(ctx
);
1498 struct gl_buffer_object
*bufObj
;
1500 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1504 _mesa_buffer_storage(ctx
, bufObj
, target
, size
, data
, flags
,
1509 _mesa_NamedBufferStorage(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1512 GET_CURRENT_CONTEXT(ctx
);
1513 struct gl_buffer_object
*bufObj
;
1515 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferStorage");
1520 * In direct state access, buffer objects have an unspecified target since
1521 * they are not required to be bound.
1523 _mesa_buffer_storage(ctx
, bufObj
, GL_NONE
, size
, data
, flags
,
1524 "glNamedBufferStorage");
1529 _mesa_buffer_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1530 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1531 GLenum usage
, const char *func
)
1535 if (MESA_VERBOSE
& VERBOSE_API
)
1536 _mesa_debug(ctx
, "%s(%s, %ld, %p, %s)\n",
1538 _mesa_enum_to_string(target
),
1539 (long int) size
, data
,
1540 _mesa_enum_to_string(usage
));
1543 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", func
);
1548 case GL_STREAM_DRAW_ARB
:
1549 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1552 case GL_STATIC_DRAW_ARB
:
1553 case GL_DYNAMIC_DRAW_ARB
:
1557 case GL_STREAM_READ_ARB
:
1558 case GL_STREAM_COPY_ARB
:
1559 case GL_STATIC_READ_ARB
:
1560 case GL_STATIC_COPY_ARB
:
1561 case GL_DYNAMIC_READ_ARB
:
1562 case GL_DYNAMIC_COPY_ARB
:
1563 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1567 valid_usage
= false;
1572 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid usage: %s)", func
,
1573 _mesa_enum_to_string(usage
));
1577 if (bufObj
->Immutable
) {
1578 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1582 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1583 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1585 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1587 bufObj
->Written
= GL_TRUE
;
1590 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1591 bufObj
->Name
, size
, data
, usage
);
1598 assert(ctx
->Driver
.BufferData
);
1599 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1602 GL_DYNAMIC_STORAGE_BIT
,
1604 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1605 /* From GL_AMD_pinned_memory:
1607 * INVALID_OPERATION is generated by BufferData if <target> is
1608 * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
1609 * mapped to the GPU address space.
1611 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1614 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1620 _mesa_BufferData(GLenum target
, GLsizeiptr size
,
1621 const GLvoid
*data
, GLenum usage
)
1623 GET_CURRENT_CONTEXT(ctx
);
1624 struct gl_buffer_object
*bufObj
;
1626 bufObj
= get_buffer(ctx
, "glBufferData", target
, GL_INVALID_OPERATION
);
1630 _mesa_buffer_data(ctx
, bufObj
, target
, size
, data
, usage
,
1635 _mesa_NamedBufferData(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1638 GET_CURRENT_CONTEXT(ctx
);
1639 struct gl_buffer_object
*bufObj
;
1641 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferData");
1645 /* In direct state access, buffer objects have an unspecified target since
1646 * they are not required to be bound.
1648 _mesa_buffer_data(ctx
, bufObj
, GL_NONE
, size
, data
, usage
,
1649 "glNamedBufferData");
1654 * Implementation for glBufferSubData and glNamedBufferSubData.
1656 * \param ctx GL context.
1657 * \param bufObj The buffer object.
1658 * \param offset Offset of the first byte of the subdata range.
1659 * \param size Size, in bytes, of the subdata range.
1660 * \param data The data store.
1661 * \param func Name of calling function for recording errors.
1665 _mesa_buffer_sub_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1666 GLintptr offset
, GLsizeiptr size
, const GLvoid
*data
,
1669 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1671 /* error already recorded */
1675 if (bufObj
->Immutable
&&
1676 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1677 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1684 bufObj
->Written
= GL_TRUE
;
1686 assert(ctx
->Driver
.BufferSubData
);
1687 ctx
->Driver
.BufferSubData(ctx
, offset
, size
, data
, bufObj
);
1691 _mesa_BufferSubData(GLenum target
, GLintptr offset
,
1692 GLsizeiptr size
, const GLvoid
*data
)
1694 GET_CURRENT_CONTEXT(ctx
);
1695 struct gl_buffer_object
*bufObj
;
1697 bufObj
= get_buffer(ctx
, "glBufferSubData", target
, GL_INVALID_OPERATION
);
1701 _mesa_buffer_sub_data(ctx
, bufObj
, offset
, size
, data
, "glBufferSubData");
1705 _mesa_NamedBufferSubData(GLuint buffer
, GLintptr offset
,
1706 GLsizeiptr size
, const GLvoid
*data
)
1708 GET_CURRENT_CONTEXT(ctx
);
1709 struct gl_buffer_object
*bufObj
;
1711 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferSubData");
1715 _mesa_buffer_sub_data(ctx
, bufObj
, offset
, size
, data
,
1716 "glNamedBufferSubData");
1721 _mesa_GetBufferSubData(GLenum target
, GLintptr offset
,
1722 GLsizeiptr size
, GLvoid
*data
)
1724 GET_CURRENT_CONTEXT(ctx
);
1725 struct gl_buffer_object
*bufObj
;
1727 bufObj
= get_buffer(ctx
, "glGetBufferSubData", target
,
1728 GL_INVALID_OPERATION
);
1732 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1733 "glGetBufferSubData")) {
1737 assert(ctx
->Driver
.GetBufferSubData
);
1738 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1742 _mesa_GetNamedBufferSubData(GLuint buffer
, GLintptr offset
,
1743 GLsizeiptr size
, GLvoid
*data
)
1745 GET_CURRENT_CONTEXT(ctx
);
1746 struct gl_buffer_object
*bufObj
;
1748 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1749 "glGetNamedBufferSubData");
1753 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1754 "glGetNamedBufferSubData")) {
1758 assert(ctx
->Driver
.GetBufferSubData
);
1759 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1764 * \param subdata true if caller is *SubData, false if *Data
1767 _mesa_clear_buffer_sub_data(struct gl_context
*ctx
,
1768 struct gl_buffer_object
*bufObj
,
1769 GLenum internalformat
,
1770 GLintptr offset
, GLsizeiptr size
,
1771 GLenum format
, GLenum type
,
1773 const char *func
, bool subdata
)
1775 mesa_format mesaFormat
;
1776 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1777 GLsizeiptr clearValueSize
;
1779 /* This checks for disallowed mappings. */
1780 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1785 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1786 format
, type
, func
);
1788 if (mesaFormat
== MESA_FORMAT_NONE
) {
1792 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1793 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
,
1795 "%s(offset or size is not a multiple of "
1796 "internalformat size)", func
);
1801 /* clear to zeros, per the spec */
1803 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1804 NULL
, clearValueSize
, bufObj
);
1809 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1810 format
, type
, data
, func
)) {
1815 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1816 clearValue
, clearValueSize
, bufObj
);
1821 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1822 GLenum type
, const GLvoid
*data
)
1824 GET_CURRENT_CONTEXT(ctx
);
1825 struct gl_buffer_object
*bufObj
;
1827 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1831 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
1833 "glClearBufferData", false);
1837 _mesa_ClearNamedBufferData(GLuint buffer
, GLenum internalformat
,
1838 GLenum format
, GLenum type
, const GLvoid
*data
)
1840 GET_CURRENT_CONTEXT(ctx
);
1841 struct gl_buffer_object
*bufObj
;
1843 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glClearNamedBufferData");
1847 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
1849 "glClearNamedBufferData", false);
1854 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1855 GLintptr offset
, GLsizeiptr size
,
1856 GLenum format
, GLenum type
,
1859 GET_CURRENT_CONTEXT(ctx
);
1860 struct gl_buffer_object
*bufObj
;
1862 bufObj
= get_buffer(ctx
, "glClearBufferSubData", target
, GL_INVALID_VALUE
);
1866 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
,
1868 "glClearBufferSubData", true);
1872 _mesa_ClearNamedBufferSubData(GLuint buffer
, GLenum internalformat
,
1873 GLintptr offset
, GLsizeiptr size
,
1874 GLenum format
, GLenum type
,
1877 GET_CURRENT_CONTEXT(ctx
);
1878 struct gl_buffer_object
*bufObj
;
1880 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1881 "glClearNamedBufferSubData");
1885 _mesa_clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
,
1887 "glClearNamedBufferSubData", true);
1892 _mesa_unmap_buffer(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1895 GLboolean status
= GL_TRUE
;
1896 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1898 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1900 "%s(buffer is not mapped)", func
);
1905 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1906 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1908 /* check that last 100 bytes are still = magic value */
1909 for (i
= 0; i
< 100; i
++) {
1910 GLuint pos
= bufObj
->Size
- i
- 1;
1911 if (buf
[pos
] != 123) {
1912 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1913 " at position %d (value = %u)\n",
1921 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1922 GLuint i
, unchanged
= 0;
1923 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1925 /* check which bytes changed */
1926 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1927 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1934 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1935 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1940 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1941 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1942 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1943 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1944 assert(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1949 GLboolean GLAPIENTRY
1950 _mesa_UnmapBuffer(GLenum target
)
1952 GET_CURRENT_CONTEXT(ctx
);
1953 struct gl_buffer_object
*bufObj
;
1955 bufObj
= get_buffer(ctx
, "glUnmapBuffer", target
, GL_INVALID_OPERATION
);
1959 return _mesa_unmap_buffer(ctx
, bufObj
, "glUnmapBuffer");
1962 GLboolean GLAPIENTRY
1963 _mesa_UnmapNamedBuffer(GLuint buffer
)
1965 GET_CURRENT_CONTEXT(ctx
);
1966 struct gl_buffer_object
*bufObj
;
1968 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glUnmapNamedBuffer");
1972 return _mesa_unmap_buffer(ctx
, bufObj
, "glUnmapNamedBuffer");
1977 get_buffer_parameter(struct gl_context
*ctx
,
1978 struct gl_buffer_object
*bufObj
, GLenum pname
,
1979 GLint64
*params
, const char *func
)
1982 case GL_BUFFER_SIZE_ARB
:
1983 *params
= bufObj
->Size
;
1985 case GL_BUFFER_USAGE_ARB
:
1986 *params
= bufObj
->Usage
;
1988 case GL_BUFFER_ACCESS_ARB
:
1989 *params
= simplified_access_mode(ctx
,
1990 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1992 case GL_BUFFER_MAPPED_ARB
:
1993 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1995 case GL_BUFFER_ACCESS_FLAGS
:
1996 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1998 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
2000 case GL_BUFFER_MAP_OFFSET
:
2001 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2003 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
2005 case GL_BUFFER_MAP_LENGTH
:
2006 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2008 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
2010 case GL_BUFFER_IMMUTABLE_STORAGE
:
2011 if (!ctx
->Extensions
.ARB_buffer_storage
)
2013 *params
= bufObj
->Immutable
;
2015 case GL_BUFFER_STORAGE_FLAGS
:
2016 if (!ctx
->Extensions
.ARB_buffer_storage
)
2018 *params
= bufObj
->StorageFlags
;
2027 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname: %s)", func
,
2028 _mesa_enum_to_string(pname
));
2033 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2035 GET_CURRENT_CONTEXT(ctx
);
2036 struct gl_buffer_object
*bufObj
;
2039 bufObj
= get_buffer(ctx
, "glGetBufferParameteriv", target
,
2040 GL_INVALID_OPERATION
);
2044 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2045 "glGetBufferParameteriv"))
2046 return; /* Error already recorded. */
2048 *params
= (GLint
) parameter
;
2052 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
2054 GET_CURRENT_CONTEXT(ctx
);
2055 struct gl_buffer_object
*bufObj
;
2058 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
2059 GL_INVALID_OPERATION
);
2063 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2064 "glGetBufferParameteri64v"))
2065 return; /* Error already recorded. */
2067 *params
= parameter
;
2071 _mesa_GetNamedBufferParameteriv(GLuint buffer
, GLenum pname
, GLint
*params
)
2073 GET_CURRENT_CONTEXT(ctx
);
2074 struct gl_buffer_object
*bufObj
;
2077 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2078 "glGetNamedBufferParameteriv");
2082 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2083 "glGetNamedBufferParameteriv"))
2084 return; /* Error already recorded. */
2086 *params
= (GLint
) parameter
;
2090 _mesa_GetNamedBufferParameteri64v(GLuint buffer
, GLenum pname
,
2093 GET_CURRENT_CONTEXT(ctx
);
2094 struct gl_buffer_object
*bufObj
;
2097 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2098 "glGetNamedBufferParameteri64v");
2102 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2103 "glGetNamedBufferParameteri64v"))
2104 return; /* Error already recorded. */
2106 *params
= parameter
;
2111 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
2113 GET_CURRENT_CONTEXT(ctx
);
2114 struct gl_buffer_object
*bufObj
;
2116 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2117 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointerv(pname != "
2118 "GL_BUFFER_MAP_POINTER)");
2122 bufObj
= get_buffer(ctx
, "glGetBufferPointerv", target
,
2123 GL_INVALID_OPERATION
);
2127 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2131 _mesa_GetNamedBufferPointerv(GLuint buffer
, GLenum pname
, GLvoid
**params
)
2133 GET_CURRENT_CONTEXT(ctx
);
2134 struct gl_buffer_object
*bufObj
;
2136 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2137 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetNamedBufferPointerv(pname != "
2138 "GL_BUFFER_MAP_POINTER)");
2142 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2143 "glGetNamedBufferPointerv");
2147 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2152 _mesa_copy_buffer_sub_data(struct gl_context
*ctx
,
2153 struct gl_buffer_object
*src
,
2154 struct gl_buffer_object
*dst
,
2155 GLintptr readOffset
, GLintptr writeOffset
,
2156 GLsizeiptr size
, const char *func
)
2158 if (_mesa_check_disallowed_mapping(src
)) {
2159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2160 "%s(readBuffer is mapped)", func
);
2164 if (_mesa_check_disallowed_mapping(dst
)) {
2165 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2166 "%s(writeBuffer is mapped)", func
);
2170 if (readOffset
< 0) {
2171 _mesa_error(ctx
, GL_INVALID_VALUE
,
2172 "%s(readOffset %d < 0)", func
, (int) readOffset
);
2176 if (writeOffset
< 0) {
2177 _mesa_error(ctx
, GL_INVALID_VALUE
,
2178 "%s(writeOffset %d < 0)", func
, (int) writeOffset
);
2183 _mesa_error(ctx
, GL_INVALID_VALUE
,
2184 "%s(size %d < 0)", func
, (int) size
);
2188 if (readOffset
+ size
> src
->Size
) {
2189 _mesa_error(ctx
, GL_INVALID_VALUE
,
2190 "%s(readOffset %d + size %d > src_buffer_size %d)", func
,
2191 (int) readOffset
, (int) size
, (int) src
->Size
);
2195 if (writeOffset
+ size
> dst
->Size
) {
2196 _mesa_error(ctx
, GL_INVALID_VALUE
,
2197 "%s(writeOffset %d + size %d > dst_buffer_size %d)", func
,
2198 (int) writeOffset
, (int) size
, (int) dst
->Size
);
2203 if (readOffset
+ size
<= writeOffset
) {
2206 else if (writeOffset
+ size
<= readOffset
) {
2210 /* overlapping src/dst is illegal */
2211 _mesa_error(ctx
, GL_INVALID_VALUE
,
2212 "%s(overlapping src/dst)", func
);
2217 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2221 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
2222 GLintptr readOffset
, GLintptr writeOffset
,
2225 GET_CURRENT_CONTEXT(ctx
);
2226 struct gl_buffer_object
*src
, *dst
;
2228 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
2229 GL_INVALID_OPERATION
);
2233 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
2234 GL_INVALID_OPERATION
);
2238 _mesa_copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2239 "glCopyBufferSubData");
2243 _mesa_CopyNamedBufferSubData(GLuint readBuffer
, GLuint writeBuffer
,
2244 GLintptr readOffset
, GLintptr writeOffset
,
2247 GET_CURRENT_CONTEXT(ctx
);
2248 struct gl_buffer_object
*src
, *dst
;
2250 src
= _mesa_lookup_bufferobj_err(ctx
, readBuffer
,
2251 "glCopyNamedBufferSubData");
2255 dst
= _mesa_lookup_bufferobj_err(ctx
, writeBuffer
,
2256 "glCopyNamedBufferSubData");
2260 _mesa_copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2261 "glCopyNamedBufferSubData");
2266 _mesa_map_buffer_range(struct gl_context
*ctx
,
2267 struct gl_buffer_object
*bufObj
,
2268 GLintptr offset
, GLsizeiptr length
,
2269 GLbitfield access
, const char *func
)
2272 GLbitfield allowed_access
;
2274 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2277 _mesa_error(ctx
, GL_INVALID_VALUE
,
2278 "%s(offset %ld < 0)", func
, (long) offset
);
2283 _mesa_error(ctx
, GL_INVALID_VALUE
,
2284 "%s(length %ld < 0)", func
, (long) length
);
2288 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2290 * "An INVALID_OPERATION error is generated for any of the following
2293 * * <length> is zero."
2295 * Additionally, page 94 of the PDF of the OpenGL 4.5 core spec
2296 * (30.10.2014) also says this, so it's no longer allowed for desktop GL,
2300 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(length = 0)", func
);
2304 allowed_access
= GL_MAP_READ_BIT
|
2306 GL_MAP_INVALIDATE_RANGE_BIT
|
2307 GL_MAP_INVALIDATE_BUFFER_BIT
|
2308 GL_MAP_FLUSH_EXPLICIT_BIT
|
2309 GL_MAP_UNSYNCHRONIZED_BIT
;
2311 if (ctx
->Extensions
.ARB_buffer_storage
) {
2312 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2313 GL_MAP_COHERENT_BIT
;
2316 if (access
& ~allowed_access
) {
2317 /* generate an error if any bits other than those allowed are set */
2318 _mesa_error(ctx
, GL_INVALID_VALUE
,
2319 "%s(access has undefined bits set)", func
);
2323 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2324 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2325 "%s(access indicates neither read or write)", func
);
2329 if ((access
& GL_MAP_READ_BIT
) &&
2330 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2331 GL_MAP_INVALIDATE_BUFFER_BIT
|
2332 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2333 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2334 "%s(read access with disallowed bits)", func
);
2338 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2339 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2341 "%s(access has flush explicit without write)", func
);
2345 if (access
& GL_MAP_READ_BIT
&&
2346 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2348 "%s(buffer does not allow read access)", func
);
2352 if (access
& GL_MAP_WRITE_BIT
&&
2353 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2354 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2355 "%s(buffer does not allow write access)", func
);
2359 if (access
& GL_MAP_COHERENT_BIT
&&
2360 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2362 "%s(buffer does not allow coherent access)", func
);
2366 if (access
& GL_MAP_PERSISTENT_BIT
&&
2367 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2368 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2369 "%s(buffer does not allow persistent access)", func
);
2373 if (offset
+ length
> bufObj
->Size
) {
2374 _mesa_error(ctx
, GL_INVALID_VALUE
,
2375 "%s(offset %ld + length %ld > buffer_size %ld)", func
,
2376 offset
, length
, bufObj
->Size
);
2380 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2381 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2382 "%s(buffer already mapped)", func
);
2386 if (!bufObj
->Size
) {
2387 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(buffer size = 0)", func
);
2392 assert(ctx
->Driver
.MapBufferRange
);
2393 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(map failed)", func
);
2399 /* The driver callback should have set all these fields.
2400 * This is important because other modules (like VBO) might call
2401 * the driver function directly.
2403 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2404 assert(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2405 assert(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2406 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2409 if (access
& GL_MAP_WRITE_BIT
)
2410 bufObj
->Written
= GL_TRUE
;
2413 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2414 printf("glMapBuffer(%u, sz %ld, access 0x%x)\n",
2415 bufObj
->Name
, bufObj
->Size
, access
);
2416 /* Access must be write only */
2417 if ((access
& GL_MAP_WRITE_BIT
) && (!(access
& ~GL_MAP_WRITE_BIT
))) {
2419 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
2420 for (i
= 0; i
< bufObj
->Size
; i
++)
2427 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2428 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
2430 /* buffer is 100 bytes larger than requested, fill with magic value */
2431 for (i
= 0; i
< 100; i
++) {
2432 buf
[bufObj
->Size
- i
- 1] = 123;
2441 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2444 GET_CURRENT_CONTEXT(ctx
);
2445 struct gl_buffer_object
*bufObj
;
2447 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2449 "glMapBufferRange(ARB_map_buffer_range not supported)");
2453 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2457 return _mesa_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2458 "glMapBufferRange");
2462 _mesa_MapNamedBufferRange(GLuint buffer
, GLintptr offset
, GLsizeiptr length
,
2465 GET_CURRENT_CONTEXT(ctx
);
2466 struct gl_buffer_object
*bufObj
;
2468 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2469 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2470 "glMapNamedBufferRange("
2471 "ARB_map_buffer_range not supported)");
2475 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBufferRange");
2479 return _mesa_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2480 "glMapNamedBufferRange");
2484 * Converts GLenum access from MapBuffer and MapNamedBuffer into
2485 * flags for input to _mesa_map_buffer_range.
2487 * \return true if the type of requested access is permissible.
2490 get_map_buffer_access_flags(struct gl_context
*ctx
, GLenum access
,
2494 case GL_READ_ONLY_ARB
:
2495 *flags
= GL_MAP_READ_BIT
;
2496 return _mesa_is_desktop_gl(ctx
);
2497 case GL_WRITE_ONLY_ARB
:
2498 *flags
= GL_MAP_WRITE_BIT
;
2500 case GL_READ_WRITE_ARB
:
2501 *flags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
2502 return _mesa_is_desktop_gl(ctx
);
2509 _mesa_MapBuffer(GLenum target
, GLenum access
)
2511 GET_CURRENT_CONTEXT(ctx
);
2512 struct gl_buffer_object
*bufObj
;
2513 GLbitfield accessFlags
;
2515 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBuffer(invalid access)");
2520 bufObj
= get_buffer(ctx
, "glMapBuffer", target
, GL_INVALID_OPERATION
);
2524 return _mesa_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2529 _mesa_MapNamedBuffer(GLuint buffer
, GLenum access
)
2531 GET_CURRENT_CONTEXT(ctx
);
2532 struct gl_buffer_object
*bufObj
;
2533 GLbitfield accessFlags
;
2535 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2536 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapNamedBuffer(invalid access)");
2540 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBuffer");
2544 return _mesa_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2545 "glMapNamedBuffer");
2550 _mesa_flush_mapped_buffer_range(struct gl_context
*ctx
,
2551 struct gl_buffer_object
*bufObj
,
2552 GLintptr offset
, GLsizeiptr length
,
2555 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2556 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2557 "%s(ARB_map_buffer_range not supported)", func
);
2562 _mesa_error(ctx
, GL_INVALID_VALUE
,
2563 "%s(offset %ld < 0)", func
, (long) offset
);
2568 _mesa_error(ctx
, GL_INVALID_VALUE
,
2569 "%s(length %ld < 0)", func
, (long) length
);
2573 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2574 /* buffer is not mapped */
2575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2576 "%s(buffer is not mapped)", func
);
2580 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2581 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2583 "%s(GL_MAP_FLUSH_EXPLICIT_BIT not set)", func
);
2587 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2588 _mesa_error(ctx
, GL_INVALID_VALUE
,
2589 "%s(offset %ld + length %ld > mapped length %ld)", func
,
2590 (long) offset
, (long) length
,
2591 (long) bufObj
->Mappings
[MAP_USER
].Length
);
2595 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2597 if (ctx
->Driver
.FlushMappedBufferRange
)
2598 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2603 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
,
2606 GET_CURRENT_CONTEXT(ctx
);
2607 struct gl_buffer_object
*bufObj
;
2609 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2610 GL_INVALID_OPERATION
);
2614 _mesa_flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2615 "glFlushMappedBufferRange");
2619 _mesa_FlushMappedNamedBufferRange(GLuint buffer
, GLintptr offset
,
2622 GET_CURRENT_CONTEXT(ctx
);
2623 struct gl_buffer_object
*bufObj
;
2625 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2626 "glFlushMappedNamedBufferRange");
2630 _mesa_flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2631 "glFlushMappedNamedBufferRange");
2636 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2638 struct gl_buffer_object
*bufObj
;
2641 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2643 _mesa_error(ctx
, GL_INVALID_VALUE
,
2644 "glObjectPurgeable(name = 0x%x)", name
);
2647 if (!_mesa_is_bufferobj(bufObj
)) {
2648 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2652 if (bufObj
->Purgeable
) {
2653 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2654 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2655 return GL_VOLATILE_APPLE
;
2658 bufObj
->Purgeable
= GL_TRUE
;
2660 retval
= GL_VOLATILE_APPLE
;
2661 if (ctx
->Driver
.BufferObjectPurgeable
)
2662 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2669 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2671 struct gl_renderbuffer
*bufObj
;
2674 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2676 _mesa_error(ctx
, GL_INVALID_VALUE
,
2677 "glObjectUnpurgeable(name = 0x%x)", name
);
2681 if (bufObj
->Purgeable
) {
2682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2683 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2684 return GL_VOLATILE_APPLE
;
2687 bufObj
->Purgeable
= GL_TRUE
;
2689 retval
= GL_VOLATILE_APPLE
;
2690 if (ctx
->Driver
.RenderObjectPurgeable
)
2691 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2698 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2700 struct gl_texture_object
*bufObj
;
2703 bufObj
= _mesa_lookup_texture(ctx
, name
);
2705 _mesa_error(ctx
, GL_INVALID_VALUE
,
2706 "glObjectPurgeable(name = 0x%x)", name
);
2710 if (bufObj
->Purgeable
) {
2711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2712 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2713 return GL_VOLATILE_APPLE
;
2716 bufObj
->Purgeable
= GL_TRUE
;
2718 retval
= GL_VOLATILE_APPLE
;
2719 if (ctx
->Driver
.TextureObjectPurgeable
)
2720 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2727 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2731 GET_CURRENT_CONTEXT(ctx
);
2732 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2735 _mesa_error(ctx
, GL_INVALID_VALUE
,
2736 "glObjectPurgeable(name = 0x%x)", name
);
2741 case GL_VOLATILE_APPLE
:
2742 case GL_RELEASED_APPLE
:
2746 _mesa_error(ctx
, GL_INVALID_ENUM
,
2747 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2752 switch (objectType
) {
2754 retval
= texture_object_purgeable(ctx
, name
, option
);
2756 case GL_RENDERBUFFER_EXT
:
2757 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2759 case GL_BUFFER_OBJECT_APPLE
:
2760 retval
= buffer_object_purgeable(ctx
, name
, option
);
2763 _mesa_error(ctx
, GL_INVALID_ENUM
,
2764 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2769 /* In strict conformance to the spec, we must only return VOLATILE when
2770 * when passed the VOLATILE option. Madness.
2772 * XXX First fix the spec, then fix me.
2774 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2779 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2781 struct gl_buffer_object
*bufObj
;
2784 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2786 _mesa_error(ctx
, GL_INVALID_VALUE
,
2787 "glObjectUnpurgeable(name = 0x%x)", name
);
2791 if (! bufObj
->Purgeable
) {
2792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2793 "glObjectUnpurgeable(name = 0x%x) object is "
2794 " already \"unpurged\"", name
);
2798 bufObj
->Purgeable
= GL_FALSE
;
2801 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2802 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2809 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2811 struct gl_renderbuffer
*bufObj
;
2814 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2816 _mesa_error(ctx
, GL_INVALID_VALUE
,
2817 "glObjectUnpurgeable(name = 0x%x)", name
);
2821 if (! bufObj
->Purgeable
) {
2822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2823 "glObjectUnpurgeable(name = 0x%x) object is "
2824 " already \"unpurged\"", name
);
2828 bufObj
->Purgeable
= GL_FALSE
;
2831 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2832 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2839 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2841 struct gl_texture_object
*bufObj
;
2844 bufObj
= _mesa_lookup_texture(ctx
, name
);
2846 _mesa_error(ctx
, GL_INVALID_VALUE
,
2847 "glObjectUnpurgeable(name = 0x%x)", name
);
2851 if (! bufObj
->Purgeable
) {
2852 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2853 "glObjectUnpurgeable(name = 0x%x) object is"
2854 " already \"unpurged\"", name
);
2858 bufObj
->Purgeable
= GL_FALSE
;
2861 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2862 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2869 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2871 GET_CURRENT_CONTEXT(ctx
);
2872 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2875 _mesa_error(ctx
, GL_INVALID_VALUE
,
2876 "glObjectUnpurgeable(name = 0x%x)", name
);
2881 case GL_RETAINED_APPLE
:
2882 case GL_UNDEFINED_APPLE
:
2886 _mesa_error(ctx
, GL_INVALID_ENUM
,
2887 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2892 switch (objectType
) {
2893 case GL_BUFFER_OBJECT_APPLE
:
2894 return buffer_object_unpurgeable(ctx
, name
, option
);
2896 return texture_object_unpurgeable(ctx
, name
, option
);
2897 case GL_RENDERBUFFER_EXT
:
2898 return renderbuffer_unpurgeable(ctx
, name
, option
);
2900 _mesa_error(ctx
, GL_INVALID_ENUM
,
2901 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2909 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2910 GLenum pname
, GLint
*params
)
2912 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2914 _mesa_error(ctx
, GL_INVALID_VALUE
,
2915 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2920 case GL_PURGEABLE_APPLE
:
2921 *params
= bufObj
->Purgeable
;
2924 _mesa_error(ctx
, GL_INVALID_ENUM
,
2925 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2933 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2934 GLenum pname
, GLint
*params
)
2936 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2938 _mesa_error(ctx
, GL_INVALID_VALUE
,
2939 "glObjectUnpurgeable(name = 0x%x)", name
);
2944 case GL_PURGEABLE_APPLE
:
2945 *params
= rb
->Purgeable
;
2948 _mesa_error(ctx
, GL_INVALID_ENUM
,
2949 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2957 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2958 GLenum pname
, GLint
*params
)
2960 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2962 _mesa_error(ctx
, GL_INVALID_VALUE
,
2963 "glObjectUnpurgeable(name = 0x%x)", name
);
2968 case GL_PURGEABLE_APPLE
:
2969 *params
= texObj
->Purgeable
;
2972 _mesa_error(ctx
, GL_INVALID_ENUM
,
2973 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2981 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2984 GET_CURRENT_CONTEXT(ctx
);
2987 _mesa_error(ctx
, GL_INVALID_VALUE
,
2988 "glGetObjectParameteriv(name = 0x%x)", name
);
2992 switch (objectType
) {
2994 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2996 case GL_BUFFER_OBJECT_APPLE
:
2997 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2999 case GL_RENDERBUFFER_EXT
:
3000 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
3003 _mesa_error(ctx
, GL_INVALID_ENUM
,
3004 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
3010 * Binds a buffer object to a uniform buffer binding point.
3012 * The caller is responsible for flushing vertices and updating
3016 set_ubo_binding(struct gl_context
*ctx
,
3017 struct gl_uniform_buffer_binding
*binding
,
3018 struct gl_buffer_object
*bufObj
,
3023 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3025 binding
->Offset
= offset
;
3026 binding
->Size
= size
;
3027 binding
->AutomaticSize
= autoSize
;
3029 /* If this is a real buffer object, mark it has having been used
3030 * at some point as a UBO.
3033 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
3037 * Binds a buffer object to a shader storage buffer binding point.
3039 * The caller is responsible for flushing vertices and updating
3043 set_ssbo_binding(struct gl_context
*ctx
,
3044 struct gl_shader_storage_buffer_binding
*binding
,
3045 struct gl_buffer_object
*bufObj
,
3050 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3052 binding
->Offset
= offset
;
3053 binding
->Size
= size
;
3054 binding
->AutomaticSize
= autoSize
;
3056 /* If this is a real buffer object, mark it has having been used
3057 * at some point as a SSBO.
3060 bufObj
->UsageHistory
|= USAGE_SHADER_STORAGE_BUFFER
;
3064 * Binds a buffer object to a uniform buffer binding point.
3066 * Unlike set_ubo_binding(), this function also flushes vertices
3067 * and updates NewDriverState. It also checks if the binding
3068 * has actually changed before updating it.
3071 bind_uniform_buffer(struct gl_context
*ctx
,
3073 struct gl_buffer_object
*bufObj
,
3078 struct gl_uniform_buffer_binding
*binding
=
3079 &ctx
->UniformBufferBindings
[index
];
3081 if (binding
->BufferObject
== bufObj
&&
3082 binding
->Offset
== offset
&&
3083 binding
->Size
== size
&&
3084 binding
->AutomaticSize
== autoSize
) {
3088 FLUSH_VERTICES(ctx
, 0);
3089 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3091 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3095 * Binds a buffer object to a shader storage buffer binding point.
3097 * Unlike set_ssbo_binding(), this function also flushes vertices
3098 * and updates NewDriverState. It also checks if the binding
3099 * has actually changed before updating it.
3102 bind_shader_storage_buffer(struct gl_context
*ctx
,
3104 struct gl_buffer_object
*bufObj
,
3109 struct gl_shader_storage_buffer_binding
*binding
=
3110 &ctx
->ShaderStorageBufferBindings
[index
];
3112 if (binding
->BufferObject
== bufObj
&&
3113 binding
->Offset
== offset
&&
3114 binding
->Size
== size
&&
3115 binding
->AutomaticSize
== autoSize
) {
3119 FLUSH_VERTICES(ctx
, 0);
3120 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3122 set_ssbo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3126 * Bind a region of a buffer object to a uniform block binding point.
3127 * \param index the uniform buffer binding point index
3128 * \param bufObj the buffer object
3129 * \param offset offset to the start of buffer object region
3130 * \param size size of the buffer object region
3133 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
3135 struct gl_buffer_object
*bufObj
,
3139 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3140 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3144 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3145 _mesa_error(ctx
, GL_INVALID_VALUE
,
3146 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3147 ctx
->Const
.UniformBufferOffsetAlignment
);
3151 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3156 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3157 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3161 * Bind a region of a buffer object to a shader storage block binding point.
3162 * \param index the shader storage buffer binding point index
3163 * \param bufObj the buffer object
3164 * \param offset offset to the start of buffer object region
3165 * \param size size of the buffer object region
3168 bind_buffer_range_shader_storage_buffer(struct gl_context
*ctx
,
3170 struct gl_buffer_object
*bufObj
,
3174 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3175 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3179 if (offset
& (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3180 _mesa_error(ctx
, GL_INVALID_VALUE
,
3181 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3182 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3186 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3191 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3192 bind_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3196 * Bind a buffer object to a uniform block binding point.
3197 * As above, but offset = 0.
3200 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
3202 struct gl_buffer_object
*bufObj
)
3204 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3205 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3209 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3211 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3212 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3214 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3218 * Bind a buffer object to a shader storage block binding point.
3219 * As above, but offset = 0.
3222 bind_buffer_base_shader_storage_buffer(struct gl_context
*ctx
,
3224 struct gl_buffer_object
*bufObj
)
3226 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3227 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3231 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3233 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3234 bind_shader_storage_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3236 bind_shader_storage_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3240 * Binds a buffer object to an atomic buffer binding point.
3242 * The caller is responsible for validating the offset,
3243 * flushing the vertices and updating NewDriverState.
3246 set_atomic_buffer_binding(struct gl_context
*ctx
,
3247 struct gl_atomic_buffer_binding
*binding
,
3248 struct gl_buffer_object
*bufObj
,
3252 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3254 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3255 binding
->Offset
= -1;
3258 binding
->Offset
= offset
;
3259 binding
->Size
= size
;
3260 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
3265 * Binds a buffer object to an atomic buffer binding point.
3267 * Unlike set_atomic_buffer_binding(), this function also validates the
3268 * index and offset, flushes vertices, and updates NewDriverState.
3269 * It also checks if the binding has actually changing before
3273 bind_atomic_buffer(struct gl_context
*ctx
,
3275 struct gl_buffer_object
*bufObj
,
3280 struct gl_atomic_buffer_binding
*binding
;
3282 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
3283 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
3287 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
3288 _mesa_error(ctx
, GL_INVALID_VALUE
,
3289 "%s(offset misaligned %d/%d)", name
, (int) offset
,
3290 ATOMIC_COUNTER_SIZE
);
3294 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
3296 binding
= &ctx
->AtomicBufferBindings
[index
];
3297 if (binding
->BufferObject
== bufObj
&&
3298 binding
->Offset
== offset
&&
3299 binding
->Size
== size
) {
3303 FLUSH_VERTICES(ctx
, 0);
3304 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3306 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
3310 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
3312 const GLintptr
*offsets
,
3313 const GLsizeiptr
*sizes
)
3315 if (offsets
[index
] < 0) {
3316 /* The ARB_multi_bind spec says:
3318 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3319 * value in <offsets> is less than zero (per binding)."
3321 _mesa_error(ctx
, GL_INVALID_VALUE
,
3322 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
3323 index
, (int64_t) offsets
[index
]);
3327 if (sizes
[index
] <= 0) {
3328 /* The ARB_multi_bind spec says:
3330 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3331 * value in <sizes> is less than or equal to zero (per binding)."
3333 _mesa_error(ctx
, GL_INVALID_VALUE
,
3334 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
3335 index
, (int64_t) sizes
[index
]);
3343 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
3344 GLuint first
, GLsizei count
,
3347 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
3348 _mesa_error(ctx
, GL_INVALID_ENUM
,
3349 "%s(target=GL_UNIFORM_BUFFER)", caller
);
3353 /* The ARB_multi_bind_spec says:
3355 * "An INVALID_OPERATION error is generated if <first> + <count> is
3356 * greater than the number of target-specific indexed binding points,
3357 * as described in section 6.7.1."
3359 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
3360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3361 "%s(first=%u + count=%d > the value of "
3362 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
3363 caller
, first
, count
,
3364 ctx
->Const
.MaxUniformBufferBindings
);
3372 error_check_bind_shader_storage_buffers(struct gl_context
*ctx
,
3373 GLuint first
, GLsizei count
,
3376 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
3377 _mesa_error(ctx
, GL_INVALID_ENUM
,
3378 "%s(target=GL_SHADER_STORAGE_BUFFER)", caller
);
3382 /* The ARB_multi_bind_spec says:
3384 * "An INVALID_OPERATION error is generated if <first> + <count> is
3385 * greater than the number of target-specific indexed binding points,
3386 * as described in section 6.7.1."
3388 if (first
+ count
> ctx
->Const
.MaxShaderStorageBufferBindings
) {
3389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3390 "%s(first=%u + count=%d > the value of "
3391 "GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS=%u)",
3392 caller
, first
, count
,
3393 ctx
->Const
.MaxShaderStorageBufferBindings
);
3401 * Unbind all uniform buffers in the range
3402 * <first> through <first>+<count>-1
3405 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3407 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3410 for (i
= 0; i
< count
; i
++)
3411 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
3412 bufObj
, -1, -1, GL_TRUE
);
3416 * Unbind all shader storage buffers in the range
3417 * <first> through <first>+<count>-1
3420 unbind_shader_storage_buffers(struct gl_context
*ctx
, GLuint first
,
3423 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3426 for (i
= 0; i
< count
; i
++)
3427 set_ssbo_binding(ctx
, &ctx
->ShaderStorageBufferBindings
[first
+ i
],
3428 bufObj
, -1, -1, GL_TRUE
);
3432 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3433 const GLuint
*buffers
)
3437 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
3440 /* Assume that at least one binding will be changed */
3441 FLUSH_VERTICES(ctx
, 0);
3442 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3445 /* The ARB_multi_bind spec says:
3447 * "If <buffers> is NULL, all bindings from <first> through
3448 * <first>+<count>-1 are reset to their unbound (zero) state."
3450 unbind_uniform_buffers(ctx
, first
, count
);
3454 /* Note that the error semantics for multi-bind commands differ from
3455 * those of other GL commands.
3457 * The Issues section in the ARB_multi_bind spec says:
3459 * "(11) Typically, OpenGL specifies that if an error is generated by a
3460 * command, that command has no effect. This is somewhat
3461 * unfortunate for multi-bind commands, because it would require a
3462 * first pass to scan the entire list of bound objects for errors
3463 * and then a second pass to actually perform the bindings.
3464 * Should we have different error semantics?
3466 * RESOLVED: Yes. In this specification, when the parameters for
3467 * one of the <count> binding points are invalid, that binding point
3468 * is not updated and an error will be generated. However, other
3469 * binding points in the same command will be updated if their
3470 * parameters are valid and no other error occurs."
3473 _mesa_begin_bufferobj_lookups(ctx
);
3475 for (i
= 0; i
< count
; i
++) {
3476 struct gl_uniform_buffer_binding
*binding
=
3477 &ctx
->UniformBufferBindings
[first
+ i
];
3478 struct gl_buffer_object
*bufObj
;
3480 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3481 bufObj
= binding
->BufferObject
;
3483 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3484 "glBindBuffersBase");
3487 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3488 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
3490 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
3494 _mesa_end_bufferobj_lookups(ctx
);
3498 bind_shader_storage_buffers_base(struct gl_context
*ctx
, GLuint first
,
3499 GLsizei count
, const GLuint
*buffers
)
3503 if (!error_check_bind_shader_storage_buffers(ctx
, first
, count
,
3504 "glBindBuffersBase"))
3507 /* Assume that at least one binding will be changed */
3508 FLUSH_VERTICES(ctx
, 0);
3509 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3512 /* The ARB_multi_bind spec says:
3514 * "If <buffers> is NULL, all bindings from <first> through
3515 * <first>+<count>-1 are reset to their unbound (zero) state."
3517 unbind_shader_storage_buffers(ctx
, first
, count
);
3521 /* Note that the error semantics for multi-bind commands differ from
3522 * those of other GL commands.
3524 * The Issues section in the ARB_multi_bind spec says:
3526 * "(11) Typically, OpenGL specifies that if an error is generated by a
3527 * command, that command has no effect. This is somewhat
3528 * unfortunate for multi-bind commands, because it would require a
3529 * first pass to scan the entire list of bound objects for errors
3530 * and then a second pass to actually perform the bindings.
3531 * Should we have different error semantics?
3533 * RESOLVED: Yes. In this specification, when the parameters for
3534 * one of the <count> binding points are invalid, that binding point
3535 * is not updated and an error will be generated. However, other
3536 * binding points in the same command will be updated if their
3537 * parameters are valid and no other error occurs."
3540 _mesa_begin_bufferobj_lookups(ctx
);
3542 for (i
= 0; i
< count
; i
++) {
3543 struct gl_shader_storage_buffer_binding
*binding
=
3544 &ctx
->ShaderStorageBufferBindings
[first
+ i
];
3545 struct gl_buffer_object
*bufObj
;
3547 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3548 bufObj
= binding
->BufferObject
;
3550 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3551 "glBindBuffersBase");
3554 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3555 set_ssbo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
3557 set_ssbo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
3561 _mesa_end_bufferobj_lookups(ctx
);
3565 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3566 const GLuint
*buffers
,
3567 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3571 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
3572 "glBindBuffersRange"))
3575 /* Assume that at least one binding will be changed */
3576 FLUSH_VERTICES(ctx
, 0);
3577 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3580 /* The ARB_multi_bind spec says:
3582 * "If <buffers> is NULL, all bindings from <first> through
3583 * <first>+<count>-1 are reset to their unbound (zero) state.
3584 * In this case, the offsets and sizes associated with the
3585 * binding points are set to default values, ignoring
3586 * <offsets> and <sizes>."
3588 unbind_uniform_buffers(ctx
, first
, count
);
3592 /* Note that the error semantics for multi-bind commands differ from
3593 * those of other GL commands.
3595 * The Issues section in the ARB_multi_bind spec says:
3597 * "(11) Typically, OpenGL specifies that if an error is generated by a
3598 * command, that command has no effect. This is somewhat
3599 * unfortunate for multi-bind commands, because it would require a
3600 * first pass to scan the entire list of bound objects for errors
3601 * and then a second pass to actually perform the bindings.
3602 * Should we have different error semantics?
3604 * RESOLVED: Yes. In this specification, when the parameters for
3605 * one of the <count> binding points are invalid, that binding point
3606 * is not updated and an error will be generated. However, other
3607 * binding points in the same command will be updated if their
3608 * parameters are valid and no other error occurs."
3611 _mesa_begin_bufferobj_lookups(ctx
);
3613 for (i
= 0; i
< count
; i
++) {
3614 struct gl_uniform_buffer_binding
*binding
=
3615 &ctx
->UniformBufferBindings
[first
+ i
];
3616 struct gl_buffer_object
*bufObj
;
3618 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3621 /* The ARB_multi_bind spec says:
3623 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3624 * pair of values in <offsets> and <sizes> does not respectively
3625 * satisfy the constraints described for those parameters for the
3626 * specified target, as described in section 6.7.1 (per binding)."
3628 * Section 6.7.1 refers to table 6.5, which says:
3630 * "┌───────────────────────────────────────────────────────────────┐
3631 * │ Uniform buffer array bindings (see sec. 7.6) │
3632 * ├─────────────────────┬─────────────────────────────────────────┤
3634 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3635 * │ │ OFFSET_ALIGNMENT │
3637 * │ size restriction │ none │
3638 * └─────────────────────┴─────────────────────────────────────────┘"
3640 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3641 _mesa_error(ctx
, GL_INVALID_VALUE
,
3642 "glBindBuffersRange(offsets[%u]=%" PRId64
3643 " is misaligned; it must be a multiple of the value of "
3644 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3645 "target=GL_UNIFORM_BUFFER)",
3646 i
, (int64_t) offsets
[i
],
3647 ctx
->Const
.UniformBufferOffsetAlignment
);
3651 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3652 bufObj
= binding
->BufferObject
;
3654 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3655 "glBindBuffersRange");
3658 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3659 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3661 set_ubo_binding(ctx
, binding
, bufObj
,
3662 offsets
[i
], sizes
[i
], GL_FALSE
);
3666 _mesa_end_bufferobj_lookups(ctx
);
3670 bind_shader_storage_buffers_range(struct gl_context
*ctx
, GLuint first
,
3671 GLsizei count
, const GLuint
*buffers
,
3672 const GLintptr
*offsets
,
3673 const GLsizeiptr
*sizes
)
3677 if (!error_check_bind_shader_storage_buffers(ctx
, first
, count
,
3678 "glBindBuffersRange"))
3681 /* Assume that at least one binding will be changed */
3682 FLUSH_VERTICES(ctx
, 0);
3683 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3686 /* The ARB_multi_bind spec says:
3688 * "If <buffers> is NULL, all bindings from <first> through
3689 * <first>+<count>-1 are reset to their unbound (zero) state.
3690 * In this case, the offsets and sizes associated with the
3691 * binding points are set to default values, ignoring
3692 * <offsets> and <sizes>."
3694 unbind_shader_storage_buffers(ctx
, first
, count
);
3698 /* Note that the error semantics for multi-bind commands differ from
3699 * those of other GL commands.
3701 * The Issues section in the ARB_multi_bind spec says:
3703 * "(11) Typically, OpenGL specifies that if an error is generated by a
3704 * command, that command has no effect. This is somewhat
3705 * unfortunate for multi-bind commands, because it would require a
3706 * first pass to scan the entire list of bound objects for errors
3707 * and then a second pass to actually perform the bindings.
3708 * Should we have different error semantics?
3710 * RESOLVED: Yes. In this specification, when the parameters for
3711 * one of the <count> binding points are invalid, that binding point
3712 * is not updated and an error will be generated. However, other
3713 * binding points in the same command will be updated if their
3714 * parameters are valid and no other error occurs."
3717 _mesa_begin_bufferobj_lookups(ctx
);
3719 for (i
= 0; i
< count
; i
++) {
3720 struct gl_shader_storage_buffer_binding
*binding
=
3721 &ctx
->ShaderStorageBufferBindings
[first
+ i
];
3722 struct gl_buffer_object
*bufObj
;
3724 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3727 /* The ARB_multi_bind spec says:
3729 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3730 * pair of values in <offsets> and <sizes> does not respectively
3731 * satisfy the constraints described for those parameters for the
3732 * specified target, as described in section 6.7.1 (per binding)."
3734 * Section 6.7.1 refers to table 6.5, which says:
3736 * "┌───────────────────────────────────────────────────────────────┐
3737 * │ Shader storage buffer array bindings (see sec. 7.8) │
3738 * ├─────────────────────┬─────────────────────────────────────────┤
3740 * │ offset restriction │ multiple of value of SHADER_STORAGE_- │
3741 * │ │ BUFFER_OFFSET_ALIGNMENT │
3743 * │ size restriction │ none │
3744 * └─────────────────────┴─────────────────────────────────────────┘"
3746 if (offsets
[i
] & (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3747 _mesa_error(ctx
, GL_INVALID_VALUE
,
3748 "glBindBuffersRange(offsets[%u]=%" PRId64
3749 " is misaligned; it must be a multiple of the value of "
3750 "GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT=%u when "
3751 "target=GL_SHADER_STORAGE_BUFFER)",
3752 i
, (int64_t) offsets
[i
],
3753 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3757 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3758 bufObj
= binding
->BufferObject
;
3760 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3761 "glBindBuffersRange");
3764 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3765 set_ssbo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3767 set_ssbo_binding(ctx
, binding
, bufObj
,
3768 offsets
[i
], sizes
[i
], GL_FALSE
);
3772 _mesa_end_bufferobj_lookups(ctx
);
3776 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3777 struct gl_transform_feedback_object
*tfObj
,
3778 GLuint first
, GLsizei count
, const char *caller
)
3780 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3781 _mesa_error(ctx
, GL_INVALID_ENUM
,
3782 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3786 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3788 * "An INVALID_OPERATION error is generated :
3791 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3792 * FEEDBACK_BUFFER and transform feedback is currently active."
3794 * We assume that this is also meant to apply to BindBuffersRange
3795 * and BindBuffersBase.
3797 if (tfObj
->Active
) {
3798 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3799 "%s(Changing transform feedback buffers while "
3800 "transform feedback is active)", caller
);
3804 /* The ARB_multi_bind_spec says:
3806 * "An INVALID_OPERATION error is generated if <first> + <count> is
3807 * greater than the number of target-specific indexed binding points,
3808 * as described in section 6.7.1."
3810 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3811 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3812 "%s(first=%u + count=%d > the value of "
3813 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3814 caller
, first
, count
,
3815 ctx
->Const
.MaxTransformFeedbackBuffers
);
3823 * Unbind all transform feedback buffers in the range
3824 * <first> through <first>+<count>-1
3827 unbind_xfb_buffers(struct gl_context
*ctx
,
3828 struct gl_transform_feedback_object
*tfObj
,
3829 GLuint first
, GLsizei count
)
3831 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3834 for (i
= 0; i
< count
; i
++)
3835 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3840 bind_xfb_buffers_base(struct gl_context
*ctx
,
3841 GLuint first
, GLsizei count
,
3842 const GLuint
*buffers
)
3844 struct gl_transform_feedback_object
*tfObj
=
3845 ctx
->TransformFeedback
.CurrentObject
;
3848 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3849 "glBindBuffersBase"))
3852 /* Assume that at least one binding will be changed */
3853 FLUSH_VERTICES(ctx
, 0);
3854 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3857 /* The ARB_multi_bind spec says:
3859 * "If <buffers> is NULL, all bindings from <first> through
3860 * <first>+<count>-1 are reset to their unbound (zero) state."
3862 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3866 /* Note that the error semantics for multi-bind commands differ from
3867 * those of other GL commands.
3869 * The Issues section in the ARB_multi_bind spec says:
3871 * "(11) Typically, OpenGL specifies that if an error is generated by a
3872 * command, that command has no effect. This is somewhat
3873 * unfortunate for multi-bind commands, because it would require a
3874 * first pass to scan the entire list of bound objects for errors
3875 * and then a second pass to actually perform the bindings.
3876 * Should we have different error semantics?
3878 * RESOLVED: Yes. In this specification, when the parameters for
3879 * one of the <count> binding points are invalid, that binding point
3880 * is not updated and an error will be generated. However, other
3881 * binding points in the same command will be updated if their
3882 * parameters are valid and no other error occurs."
3885 _mesa_begin_bufferobj_lookups(ctx
);
3887 for (i
= 0; i
< count
; i
++) {
3888 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3889 struct gl_buffer_object
*bufObj
;
3891 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3892 bufObj
= boundBufObj
;
3894 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3895 "glBindBuffersBase");
3898 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3902 _mesa_end_bufferobj_lookups(ctx
);
3906 bind_xfb_buffers_range(struct gl_context
*ctx
,
3907 GLuint first
, GLsizei count
,
3908 const GLuint
*buffers
,
3909 const GLintptr
*offsets
,
3910 const GLsizeiptr
*sizes
)
3912 struct gl_transform_feedback_object
*tfObj
=
3913 ctx
->TransformFeedback
.CurrentObject
;
3916 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3917 "glBindBuffersRange"))
3920 /* Assume that at least one binding will be changed */
3921 FLUSH_VERTICES(ctx
, 0);
3922 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3925 /* The ARB_multi_bind spec says:
3927 * "If <buffers> is NULL, all bindings from <first> through
3928 * <first>+<count>-1 are reset to their unbound (zero) state.
3929 * In this case, the offsets and sizes associated with the
3930 * binding points are set to default values, ignoring
3931 * <offsets> and <sizes>."
3933 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3937 /* Note that the error semantics for multi-bind commands differ from
3938 * those of other GL commands.
3940 * The Issues section in the ARB_multi_bind spec says:
3942 * "(11) Typically, OpenGL specifies that if an error is generated by a
3943 * command, that command has no effect. This is somewhat
3944 * unfortunate for multi-bind commands, because it would require a
3945 * first pass to scan the entire list of bound objects for errors
3946 * and then a second pass to actually perform the bindings.
3947 * Should we have different error semantics?
3949 * RESOLVED: Yes. In this specification, when the parameters for
3950 * one of the <count> binding points are invalid, that binding point
3951 * is not updated and an error will be generated. However, other
3952 * binding points in the same command will be updated if their
3953 * parameters are valid and no other error occurs."
3956 _mesa_begin_bufferobj_lookups(ctx
);
3958 for (i
= 0; i
< count
; i
++) {
3959 const GLuint index
= first
+ i
;
3960 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3961 struct gl_buffer_object
*bufObj
;
3963 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3966 /* The ARB_multi_bind spec says:
3968 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3969 * pair of values in <offsets> and <sizes> does not respectively
3970 * satisfy the constraints described for those parameters for the
3971 * specified target, as described in section 6.7.1 (per binding)."
3973 * Section 6.7.1 refers to table 6.5, which says:
3975 * "┌───────────────────────────────────────────────────────────────┐
3976 * │ Transform feedback array bindings (see sec. 13.2.2) │
3977 * ├───────────────────────┬───────────────────────────────────────┤
3979 * │ offset restriction │ multiple of 4 │
3981 * │ size restriction │ multiple of 4 │
3982 * └───────────────────────┴───────────────────────────────────────┘"
3984 if (offsets
[i
] & 0x3) {
3985 _mesa_error(ctx
, GL_INVALID_VALUE
,
3986 "glBindBuffersRange(offsets[%u]=%" PRId64
3987 " is misaligned; it must be a multiple of 4 when "
3988 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3989 i
, (int64_t) offsets
[i
]);
3993 if (sizes
[i
] & 0x3) {
3994 _mesa_error(ctx
, GL_INVALID_VALUE
,
3995 "glBindBuffersRange(sizes[%u]=%" PRId64
3996 " is misaligned; it must be a multiple of 4 when "
3997 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3998 i
, (int64_t) sizes
[i
]);
4002 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
4003 bufObj
= boundBufObj
;
4005 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4006 "glBindBuffersRange");
4009 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
4010 offsets
[i
], sizes
[i
]);
4013 _mesa_end_bufferobj_lookups(ctx
);
4017 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
4018 GLuint first
, GLsizei count
,
4021 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
4022 _mesa_error(ctx
, GL_INVALID_ENUM
,
4023 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
4027 /* The ARB_multi_bind_spec says:
4029 * "An INVALID_OPERATION error is generated if <first> + <count> is
4030 * greater than the number of target-specific indexed binding points,
4031 * as described in section 6.7.1."
4033 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
4034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4035 "%s(first=%u + count=%d > the value of "
4036 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
4037 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
4045 * Unbind all atomic counter buffers in the range
4046 * <first> through <first>+<count>-1
4049 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
4051 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
4054 for (i
= 0; i
< count
; i
++)
4055 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
4060 bind_atomic_buffers_base(struct gl_context
*ctx
,
4063 const GLuint
*buffers
)
4067 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
4068 "glBindBuffersBase"))
4071 /* Assume that at least one binding will be changed */
4072 FLUSH_VERTICES(ctx
, 0);
4073 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
4076 /* The ARB_multi_bind spec says:
4078 * "If <buffers> is NULL, all bindings from <first> through
4079 * <first>+<count>-1 are reset to their unbound (zero) state."
4081 unbind_atomic_buffers(ctx
, first
, count
);
4085 /* Note that the error semantics for multi-bind commands differ from
4086 * those of other GL commands.
4088 * The Issues section in the ARB_multi_bind spec says:
4090 * "(11) Typically, OpenGL specifies that if an error is generated by a
4091 * command, that command has no effect. This is somewhat
4092 * unfortunate for multi-bind commands, because it would require a
4093 * first pass to scan the entire list of bound objects for errors
4094 * and then a second pass to actually perform the bindings.
4095 * Should we have different error semantics?
4097 * RESOLVED: Yes. In this specification, when the parameters for
4098 * one of the <count> binding points are invalid, that binding point
4099 * is not updated and an error will be generated. However, other
4100 * binding points in the same command will be updated if their
4101 * parameters are valid and no other error occurs."
4104 _mesa_begin_bufferobj_lookups(ctx
);
4106 for (i
= 0; i
< count
; i
++) {
4107 struct gl_atomic_buffer_binding
*binding
=
4108 &ctx
->AtomicBufferBindings
[first
+ i
];
4109 struct gl_buffer_object
*bufObj
;
4111 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
4112 bufObj
= binding
->BufferObject
;
4114 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4115 "glBindBuffersBase");
4118 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
4121 _mesa_end_bufferobj_lookups(ctx
);
4125 bind_atomic_buffers_range(struct gl_context
*ctx
,
4128 const GLuint
*buffers
,
4129 const GLintptr
*offsets
,
4130 const GLsizeiptr
*sizes
)
4134 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
4135 "glBindBuffersRange"))
4138 /* Assume that at least one binding will be changed */
4139 FLUSH_VERTICES(ctx
, 0);
4140 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
4143 /* The ARB_multi_bind spec says:
4145 * "If <buffers> is NULL, all bindings from <first> through
4146 * <first>+<count>-1 are reset to their unbound (zero) state.
4147 * In this case, the offsets and sizes associated with the
4148 * binding points are set to default values, ignoring
4149 * <offsets> and <sizes>."
4151 unbind_atomic_buffers(ctx
, first
, count
);
4155 /* Note that the error semantics for multi-bind commands differ from
4156 * those of other GL commands.
4158 * The Issues section in the ARB_multi_bind spec says:
4160 * "(11) Typically, OpenGL specifies that if an error is generated by a
4161 * command, that command has no effect. This is somewhat
4162 * unfortunate for multi-bind commands, because it would require a
4163 * first pass to scan the entire list of bound objects for errors
4164 * and then a second pass to actually perform the bindings.
4165 * Should we have different error semantics?
4167 * RESOLVED: Yes. In this specification, when the parameters for
4168 * one of the <count> binding points are invalid, that binding point
4169 * is not updated and an error will be generated. However, other
4170 * binding points in the same command will be updated if their
4171 * parameters are valid and no other error occurs."
4174 _mesa_begin_bufferobj_lookups(ctx
);
4176 for (i
= 0; i
< count
; i
++) {
4177 struct gl_atomic_buffer_binding
*binding
=
4178 &ctx
->AtomicBufferBindings
[first
+ i
];
4179 struct gl_buffer_object
*bufObj
;
4181 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
4184 /* The ARB_multi_bind spec says:
4186 * "An INVALID_VALUE error is generated by BindBuffersRange if any
4187 * pair of values in <offsets> and <sizes> does not respectively
4188 * satisfy the constraints described for those parameters for the
4189 * specified target, as described in section 6.7.1 (per binding)."
4191 * Section 6.7.1 refers to table 6.5, which says:
4193 * "┌───────────────────────────────────────────────────────────────┐
4194 * │ Atomic counter array bindings (see sec. 7.7.2) │
4195 * ├───────────────────────┬───────────────────────────────────────┤
4197 * │ offset restriction │ multiple of 4 │
4199 * │ size restriction │ none │
4200 * └───────────────────────┴───────────────────────────────────────┘"
4202 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
4203 _mesa_error(ctx
, GL_INVALID_VALUE
,
4204 "glBindBuffersRange(offsets[%u]=%" PRId64
4205 " is misaligned; it must be a multiple of %d when "
4206 "target=GL_ATOMIC_COUNTER_BUFFER)",
4207 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
4211 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
4212 bufObj
= binding
->BufferObject
;
4214 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
4215 "glBindBuffersRange");
4218 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
4221 _mesa_end_bufferobj_lookups(ctx
);
4225 _mesa_BindBufferRange(GLenum target
, GLuint index
,
4226 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
4228 GET_CURRENT_CONTEXT(ctx
);
4229 struct gl_buffer_object
*bufObj
;
4232 bufObj
= ctx
->Shared
->NullBufferObj
;
4234 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4236 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
4237 &bufObj
, "glBindBufferRange"))
4241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4242 "glBindBufferRange(invalid buffer=%u)", buffer
);
4248 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
4255 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4256 _mesa_bind_buffer_range_transform_feedback(ctx
,
4257 ctx
->TransformFeedback
.CurrentObject
,
4258 index
, bufObj
, offset
, size
,
4261 case GL_UNIFORM_BUFFER
:
4262 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
4264 case GL_SHADER_STORAGE_BUFFER
:
4265 bind_buffer_range_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
);
4267 case GL_ATOMIC_COUNTER_BUFFER
:
4268 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
4269 "glBindBufferRange");
4272 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
4278 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
4280 GET_CURRENT_CONTEXT(ctx
);
4281 struct gl_buffer_object
*bufObj
;
4284 bufObj
= ctx
->Shared
->NullBufferObj
;
4286 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4288 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
4289 &bufObj
, "glBindBufferBase"))
4293 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4294 "glBindBufferBase(invalid buffer=%u)", buffer
);
4298 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
4299 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
4301 * "BindBufferBase is equivalent to calling BindBufferRange with offset
4302 * zero and size equal to the size of buffer."
4304 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
4306 * "If the parameter (starting offset or size) was not specified when the
4307 * buffer object was bound, zero is returned."
4309 * What happens if the size of the buffer changes? Does the size of the
4310 * buffer at the moment glBindBufferBase was called still play a role, like
4311 * the first quote would imply, or is the size meaningless in the
4312 * glBindBufferBase case like the second quote would suggest? The GL 4.1
4313 * core spec page 45 says:
4315 * "It is equivalent to calling BindBufferRange with offset zero, while
4316 * size is determined by the size of the bound buffer at the time the
4319 * My interpretation is that the GL 4.1 spec was a clarification of the
4320 * behavior, not a change. In particular, this choice will only make
4321 * rendering work in cases where it would have had undefined results.
4325 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4326 _mesa_bind_buffer_base_transform_feedback(ctx
,
4327 ctx
->TransformFeedback
.CurrentObject
,
4328 index
, bufObj
, false);
4330 case GL_UNIFORM_BUFFER
:
4331 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
4333 case GL_SHADER_STORAGE_BUFFER
:
4334 bind_buffer_base_shader_storage_buffer(ctx
, index
, bufObj
);
4336 case GL_ATOMIC_COUNTER_BUFFER
:
4337 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
4338 "glBindBufferBase");
4341 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
4347 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
4348 const GLuint
*buffers
,
4349 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
4351 GET_CURRENT_CONTEXT(ctx
);
4354 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4355 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
4357 case GL_UNIFORM_BUFFER
:
4358 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
4360 case GL_SHADER_STORAGE_BUFFER
:
4361 bind_shader_storage_buffers_range(ctx
, first
, count
, buffers
, offsets
,
4364 case GL_ATOMIC_COUNTER_BUFFER
:
4365 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
4369 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
4370 _mesa_enum_to_string(target
));
4376 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
4377 const GLuint
*buffers
)
4379 GET_CURRENT_CONTEXT(ctx
);
4382 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4383 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
4385 case GL_UNIFORM_BUFFER
:
4386 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
4388 case GL_SHADER_STORAGE_BUFFER
:
4389 bind_shader_storage_buffers_base(ctx
, first
, count
, buffers
);
4391 case GL_ATOMIC_COUNTER_BUFFER
:
4392 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
4395 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
4396 _mesa_enum_to_string(target
));
4402 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
4405 GET_CURRENT_CONTEXT(ctx
);
4406 struct gl_buffer_object
*bufObj
;
4407 const GLintptr end
= offset
+ length
;
4409 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4411 _mesa_error(ctx
, GL_INVALID_VALUE
,
4412 "glInvalidateBufferSubData(name = 0x%x) invalid object",
4417 /* The GL_ARB_invalidate_subdata spec says:
4419 * "An INVALID_VALUE error is generated if <offset> or <length> is
4420 * negative, or if <offset> + <length> is greater than the value of
4423 if (end
< 0 || end
> bufObj
->Size
) {
4424 _mesa_error(ctx
, GL_INVALID_VALUE
,
4425 "glInvalidateBufferSubData(invalid offset or length)");
4429 /* The OpenGL 4.4 (Core Profile) spec says:
4431 * "An INVALID_OPERATION error is generated if buffer is currently
4432 * mapped by MapBuffer or if the invalidate range intersects the range
4433 * currently mapped by MapBufferRange, unless it was mapped
4434 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4436 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
4437 bufferobj_range_mapped(bufObj
, offset
, length
)) {
4438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4439 "glInvalidateBufferSubData(intersection with mapped "
4444 /* We don't actually do anything for this yet. Just return after
4445 * validating the parameters and generating the required errors.
4451 _mesa_InvalidateBufferData(GLuint buffer
)
4453 GET_CURRENT_CONTEXT(ctx
);
4454 struct gl_buffer_object
*bufObj
;
4456 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4458 _mesa_error(ctx
, GL_INVALID_VALUE
,
4459 "glInvalidateBufferData(name = 0x%x) invalid object",
4464 /* The OpenGL 4.4 (Core Profile) spec says:
4466 * "An INVALID_OPERATION error is generated if buffer is currently
4467 * mapped by MapBuffer or if the invalidate range intersects the range
4468 * currently mapped by MapBufferRange, unless it was mapped
4469 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4471 if (_mesa_check_disallowed_mapping(bufObj
)) {
4472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4473 "glInvalidateBufferData(intersection with mapped "
4478 /* We don't actually do anything for this yet. Just return after
4479 * validating the parameters and generating the required errors.