2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
34 #include <inttypes.h> /* for PRId64 macro */
41 #include "bufferobj.h"
46 #include "glformats.h"
48 #include "transformfeedback.h"
54 /*#define BOUNDS_CHECK*/
58 * Used as a placeholder for buffer objects between glGenBuffers() and
59 * glBindBuffer() so that glIsBuffer() can work correctly.
61 static struct gl_buffer_object DummyBufferObject
;
65 * Return pointer to address of a buffer object target.
66 * \param ctx the GL context
67 * \param target the buffer object target to be retrieved.
68 * \return pointer to pointer to the buffer object bound to \c target in the
69 * specified context or \c NULL if \c target is invalid.
71 static inline struct gl_buffer_object
**
72 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
74 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
76 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
77 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
81 case GL_ARRAY_BUFFER_ARB
:
82 return &ctx
->Array
.ArrayBufferObj
;
83 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
84 return &ctx
->Array
.VAO
->IndexBufferObj
;
85 case GL_PIXEL_PACK_BUFFER_EXT
:
86 return &ctx
->Pack
.BufferObj
;
87 case GL_PIXEL_UNPACK_BUFFER_EXT
:
88 return &ctx
->Unpack
.BufferObj
;
89 case GL_COPY_READ_BUFFER
:
90 return &ctx
->CopyReadBuffer
;
91 case GL_COPY_WRITE_BUFFER
:
92 return &ctx
->CopyWriteBuffer
;
93 case GL_DRAW_INDIRECT_BUFFER
:
94 if (ctx
->API
== API_OPENGL_CORE
&&
95 ctx
->Extensions
.ARB_draw_indirect
) {
96 return &ctx
->DrawIndirectBuffer
;
99 case GL_TRANSFORM_FEEDBACK_BUFFER
:
100 if (ctx
->Extensions
.EXT_transform_feedback
) {
101 return &ctx
->TransformFeedback
.CurrentBuffer
;
104 case GL_TEXTURE_BUFFER
:
105 if (ctx
->API
== API_OPENGL_CORE
&&
106 ctx
->Extensions
.ARB_texture_buffer_object
) {
107 return &ctx
->Texture
.BufferObject
;
110 case GL_UNIFORM_BUFFER
:
111 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
112 return &ctx
->UniformBuffer
;
115 case GL_ATOMIC_COUNTER_BUFFER
:
116 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
117 return &ctx
->AtomicBuffer
;
120 case GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
:
121 if (ctx
->Extensions
.AMD_pinned_memory
) {
122 return &ctx
->ExternalVirtualMemoryBuffer
;
133 * Get the buffer object bound to the specified target in a GL context.
134 * \param ctx the GL context
135 * \param target the buffer object target to be retrieved.
136 * \param error the GL error to record if target is illegal.
137 * \return pointer to the buffer object bound to \c target in the
138 * specified context or \c NULL if \c target is invalid.
140 static inline struct gl_buffer_object
*
141 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
144 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
147 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
151 if (!_mesa_is_bufferobj(*bufObj
)) {
152 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
161 * Convert a GLbitfield describing the mapped buffer access flags
162 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
165 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
167 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
168 if ((access
& rwFlags
) == rwFlags
)
169 return GL_READ_WRITE
;
170 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
172 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
173 return GL_WRITE_ONLY
;
175 /* Otherwise, AccessFlags is zero (the default state).
177 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
179 * Name Type Initial Value Legal Values
181 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
184 * However, table 6.8 in the GL_OES_mapbuffer extension says:
186 * Get Value Type Get Command Value Description
187 * --------- ---- ----------- ----- -----------
188 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
190 * The difference is because GL_OES_mapbuffer only supports mapping buffers
195 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
200 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
202 * The regions do not overlap if and only if the end of the given
203 * region is before the mapped region or the start of the given region
204 * is after the mapped region.
206 * \param obj Buffer object target on which to operate.
207 * \param offset Offset of the first byte of the subdata range.
208 * \param size Size, in bytes, of the subdata range.
209 * \return true if ranges overlap, false otherwise
213 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
214 GLintptr offset
, GLsizeiptr size
)
216 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
217 const GLintptr end
= offset
+ size
;
218 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
219 obj
->Mappings
[MAP_USER
].Length
;
221 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
230 * Tests the subdata range parameters and sets the GL error code for
231 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
232 * \c glClearBufferSubData.
234 * \param ctx GL context.
235 * \param target Buffer object target on which to operate.
236 * \param offset Offset of the first byte of the subdata range.
237 * \param size Size, in bytes, of the subdata range.
238 * \param mappedRange If true, checks if an overlapping range is mapped.
239 * If false, checks if buffer is mapped.
240 * \param errorNoBuffer Error code if no buffer is bound to target.
241 * \param caller Name of calling function for recording errors.
242 * \return A pointer to the buffer object bound to \c target in the
243 * specified context or \c NULL if any of the parameter or state
244 * conditions are invalid.
246 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
248 static struct gl_buffer_object
*
249 buffer_object_subdata_range_good(struct gl_context
* ctx
, GLenum target
,
250 GLintptrARB offset
, GLsizeiptrARB size
,
251 bool mappedRange
, GLenum errorNoBuffer
,
254 struct gl_buffer_object
*bufObj
;
257 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
262 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
266 bufObj
= get_buffer(ctx
, caller
, target
, errorNoBuffer
);
270 if (offset
+ size
> bufObj
->Size
) {
271 _mesa_error(ctx
, GL_INVALID_VALUE
,
272 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
273 (unsigned long) offset
,
274 (unsigned long) size
,
275 (unsigned long) bufObj
->Size
);
279 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
283 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
284 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
289 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
290 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
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 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB 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 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
611 GLsizeiptrARB 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_buffer_clear_subdata(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 _mesa_buffer_map_range( 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 _mesa_buffer_flush_mapped_range( 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::MapBuffer().
751 * The input parameters will have been already tested for errors.
753 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
756 _mesa_buffer_unmap(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 _mesa_copy_buffer_subdata(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
->AtomicBuffer
,
840 ctx
->Shared
->NullBufferObj
);
842 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
843 ctx
->Shared
->NullBufferObj
);
845 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
846 _mesa_reference_buffer_object(ctx
,
847 &ctx
->UniformBufferBindings
[i
].BufferObject
,
848 ctx
->Shared
->NullBufferObj
);
849 ctx
->UniformBufferBindings
[i
].Offset
= -1;
850 ctx
->UniformBufferBindings
[i
].Size
= -1;
853 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
854 _mesa_reference_buffer_object(ctx
,
855 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
856 ctx
->Shared
->NullBufferObj
);
857 ctx
->AtomicBufferBindings
[i
].Offset
= -1;
858 ctx
->AtomicBufferBindings
[i
].Size
= -1;
864 _mesa_free_buffer_objects( struct gl_context
*ctx
)
868 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
870 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
871 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
873 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
875 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
877 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
879 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
880 _mesa_reference_buffer_object(ctx
,
881 &ctx
->UniformBufferBindings
[i
].BufferObject
,
885 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
886 _mesa_reference_buffer_object(ctx
,
887 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
894 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
897 struct gl_buffer_object
**buf_handle
,
900 struct gl_buffer_object
*buf
= *buf_handle
;
902 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
903 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
907 if (!buf
|| buf
== &DummyBufferObject
) {
908 /* If this is a new buffer object id, or one which was generated but
909 * never used before, allocate a buffer object now.
911 assert(ctx
->Driver
.NewBufferObject
);
912 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
);
914 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
917 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
925 * Bind the specified target to buffer for the specified context.
926 * Called by glBindBuffer() and other functions.
929 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
931 struct gl_buffer_object
*oldBufObj
;
932 struct gl_buffer_object
*newBufObj
= NULL
;
933 struct gl_buffer_object
**bindTarget
= NULL
;
935 bindTarget
= get_buffer_target(ctx
, target
);
937 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
941 /* Get pointer to old buffer object (to be unbound) */
942 oldBufObj
= *bindTarget
;
943 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
944 return; /* rebinding the same buffer object- no change */
947 * Get pointer to new buffer object (newBufObj)
950 /* The spec says there's not a buffer object named 0, but we use
951 * one internally because it simplifies things.
953 newBufObj
= ctx
->Shared
->NullBufferObj
;
956 /* non-default buffer object */
957 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
958 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
959 &newBufObj
, "glBindBuffer"))
963 /* bind new buffer */
964 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
969 * Update the default buffer objects in the given context to reference those
970 * specified in the shared state and release those referencing the old
974 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
976 /* Bind the NullBufferObj to remove references to those
977 * in the shared context hash table.
979 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
980 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
981 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
982 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
988 * Return the gl_buffer_object for the given ID.
989 * Always return NULL for ID 0.
991 struct gl_buffer_object
*
992 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
997 return (struct gl_buffer_object
*)
998 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
1002 struct gl_buffer_object
*
1003 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1005 return (struct gl_buffer_object
*)
1006 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1010 * A convenience function for direct state access functions that throws
1011 * GL_INVALID_OPERATION if buffer is not the name of a buffer object in the
1014 struct gl_buffer_object
*
1015 _mesa_lookup_bufferobj_err(struct gl_context
*ctx
, GLuint buffer
,
1018 struct gl_buffer_object
*bufObj
;
1020 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1022 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1023 "%s(non-generated buffer name %u)", caller
, buffer
);
1030 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1032 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1037 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1039 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1044 * Look up a buffer object for a multi-bind function.
1046 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1047 * of generating an error if the buffer ID is not zero or the name
1048 * of an existing buffer object.
1050 * If the buffer ID refers to an existing buffer object, a pointer
1051 * to the buffer object is returned. If the ID is zero, a pointer
1052 * to the shared NullBufferObj is returned. If the ID is not zero
1053 * and does not refer to a valid buffer object, this function
1056 * This function assumes that the caller has already locked the
1057 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1059 struct gl_buffer_object
*
1060 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1061 const GLuint
*buffers
,
1062 GLuint index
, const char *caller
)
1064 struct gl_buffer_object
*bufObj
;
1066 if (buffers
[index
] != 0) {
1067 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1069 /* The multi-bind functions don't create the buffer objects
1070 when they don't exist. */
1071 if (bufObj
== &DummyBufferObject
)
1074 bufObj
= ctx
->Shared
->NullBufferObj
;
1077 /* The ARB_multi_bind spec says:
1079 * "An INVALID_OPERATION error is generated if any value
1080 * in <buffers> is not zero or the name of an existing
1081 * buffer object (per binding)."
1083 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1084 "%s(buffers[%u]=%u is not zero or the name "
1085 "of an existing buffer object)",
1086 caller
, index
, buffers
[index
]);
1094 * If *ptr points to obj, set ptr = the Null/default buffer object.
1095 * This is a helper for buffer object deletion.
1096 * The GL spec says that deleting a buffer object causes it to get
1097 * unbound from all arrays in the current context.
1100 unbind(struct gl_context
*ctx
,
1101 struct gl_buffer_object
**ptr
,
1102 struct gl_buffer_object
*obj
)
1105 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1111 * Plug default/fallback buffer object functions into the device
1115 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1117 /* GL_ARB_vertex/pixel_buffer_object */
1118 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1119 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1120 driver
->BufferData
= _mesa_buffer_data
;
1121 driver
->BufferSubData
= _mesa_buffer_subdata
;
1122 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1123 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
1125 /* GL_ARB_clear_buffer_object */
1126 driver
->ClearBufferSubData
= _mesa_buffer_clear_subdata
;
1128 /* GL_ARB_map_buffer_range */
1129 driver
->MapBufferRange
= _mesa_buffer_map_range
;
1130 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
1132 /* GL_ARB_copy_buffer */
1133 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
1138 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1139 struct gl_buffer_object
*bufObj
)
1143 for (i
= 0; i
< MAP_COUNT
; i
++) {
1144 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1145 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1146 assert(bufObj
->Mappings
[i
].Pointer
== NULL
);
1147 bufObj
->Mappings
[i
].AccessFlags
= 0;
1153 /**********************************************************************/
1155 /**********************************************************************/
1158 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1160 GET_CURRENT_CONTEXT(ctx
);
1162 if (MESA_VERBOSE
& VERBOSE_API
)
1163 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1164 _mesa_lookup_enum_by_nr(target
), buffer
);
1166 bind_buffer_object(ctx
, target
, buffer
);
1171 * Delete a set of buffer objects.
1173 * \param n Number of buffer objects to delete.
1174 * \param ids Array of \c n buffer object IDs.
1177 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1179 GET_CURRENT_CONTEXT(ctx
);
1181 FLUSH_VERTICES(ctx
, 0);
1184 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1188 mtx_lock(&ctx
->Shared
->Mutex
);
1190 for (i
= 0; i
< n
; i
++) {
1191 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1193 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1196 assert(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1198 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1200 /* unbind any vertex pointers bound to this buffer */
1201 for (j
= 0; j
< ARRAY_SIZE(vao
->VertexBinding
); j
++) {
1202 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1205 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1206 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1208 if (vao
->IndexBufferObj
== bufObj
) {
1209 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1212 /* unbind ARB_draw_indirect binding point */
1213 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1214 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1217 /* unbind ARB_copy_buffer binding points */
1218 if (ctx
->CopyReadBuffer
== bufObj
) {
1219 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1221 if (ctx
->CopyWriteBuffer
== bufObj
) {
1222 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1225 /* unbind transform feedback binding points */
1226 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1227 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1229 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1230 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1231 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1235 /* unbind UBO binding points */
1236 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1237 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1238 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1242 if (ctx
->UniformBuffer
== bufObj
) {
1243 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1246 /* unbind Atomci Buffer binding points */
1247 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1248 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1249 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1253 if (ctx
->AtomicBuffer
== bufObj
) {
1254 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1257 /* unbind any pixel pack/unpack pointers bound to this buffer */
1258 if (ctx
->Pack
.BufferObj
== bufObj
) {
1259 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1261 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1262 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1265 if (ctx
->Texture
.BufferObject
== bufObj
) {
1266 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1269 if (ctx
->ExternalVirtualMemoryBuffer
== bufObj
) {
1270 _mesa_BindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
, 0);
1273 /* The ID is immediately freed for re-use */
1274 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1275 /* Make sure we do not run into the classic ABA problem on bind.
1276 * We don't want to allow re-binding a buffer object that's been
1277 * "deleted" by glDeleteBuffers().
1279 * The explicit rebinding to the default object in the current context
1280 * prevents the above in the current context, but another context
1281 * sharing the same objects might suffer from this problem.
1282 * The alternative would be to do the hash lookup in any case on bind
1283 * which would introduce more runtime overhead than this.
1285 bufObj
->DeletePending
= GL_TRUE
;
1286 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1290 mtx_unlock(&ctx
->Shared
->Mutex
);
1295 * Generate a set of unique buffer object IDs and store them in \c buffer.
1297 * \param n Number of IDs to generate.
1298 * \param buffer Array of \c n locations to store the IDs.
1301 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
1303 GET_CURRENT_CONTEXT(ctx
);
1307 if (MESA_VERBOSE
& VERBOSE_API
)
1308 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
1311 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
1320 * This must be atomic (generation and allocation of buffer object IDs)
1322 mtx_lock(&ctx
->Shared
->Mutex
);
1324 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1326 /* Insert the ID and pointer to dummy buffer object into hash table */
1327 for (i
= 0; i
< n
; i
++) {
1328 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
1329 &DummyBufferObject
);
1330 buffer
[i
] = first
+ i
;
1333 mtx_unlock(&ctx
->Shared
->Mutex
);
1338 * Determine if ID is the name of a buffer object.
1340 * \param id ID of the potential buffer object.
1341 * \return \c GL_TRUE if \c id is the name of a buffer object,
1342 * \c GL_FALSE otherwise.
1344 GLboolean GLAPIENTRY
1345 _mesa_IsBuffer(GLuint id
)
1347 struct gl_buffer_object
*bufObj
;
1348 GET_CURRENT_CONTEXT(ctx
);
1349 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1351 mtx_lock(&ctx
->Shared
->Mutex
);
1352 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1353 mtx_unlock(&ctx
->Shared
->Mutex
);
1355 return bufObj
&& bufObj
!= &DummyBufferObject
;
1360 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1363 GET_CURRENT_CONTEXT(ctx
);
1364 struct gl_buffer_object
*bufObj
;
1367 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(size <= 0)");
1371 if (flags
& ~(GL_MAP_READ_BIT
|
1373 GL_MAP_PERSISTENT_BIT
|
1374 GL_MAP_COHERENT_BIT
|
1375 GL_DYNAMIC_STORAGE_BIT
|
1376 GL_CLIENT_STORAGE_BIT
)) {
1377 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags)");
1381 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1382 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1383 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=READ/WRITE)");
1387 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1388 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=PERSISTENT)");
1392 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1396 if (bufObj
->Immutable
) {
1397 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage(immutable)");
1401 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1402 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1404 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1406 bufObj
->Written
= GL_TRUE
;
1407 bufObj
->Immutable
= GL_TRUE
;
1409 assert(ctx
->Driver
.BufferData
);
1410 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1412 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1413 /* Even though the interaction between AMD_pinned_memory and
1414 * glBufferStorage is not described in the spec, Graham Sellers
1415 * said that it should behave the same as glBufferData.
1417 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage()");
1420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferStorage()");
1427 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1428 const GLvoid
* data
, GLenum usage
)
1430 GET_CURRENT_CONTEXT(ctx
);
1431 struct gl_buffer_object
*bufObj
;
1434 if (MESA_VERBOSE
& VERBOSE_API
)
1435 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1436 _mesa_lookup_enum_by_nr(target
),
1437 (long int) size
, data
,
1438 _mesa_lookup_enum_by_nr(usage
));
1441 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1446 case GL_STREAM_DRAW_ARB
:
1447 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1450 case GL_STATIC_DRAW_ARB
:
1451 case GL_DYNAMIC_DRAW_ARB
:
1455 case GL_STREAM_READ_ARB
:
1456 case GL_STREAM_COPY_ARB
:
1457 case GL_STATIC_READ_ARB
:
1458 case GL_STATIC_COPY_ARB
:
1459 case GL_DYNAMIC_READ_ARB
:
1460 case GL_DYNAMIC_COPY_ARB
:
1461 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1465 valid_usage
= false;
1470 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1474 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
, GL_INVALID_OPERATION
);
1478 if (bufObj
->Immutable
) {
1479 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData(immutable)");
1483 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1484 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1486 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1488 bufObj
->Written
= GL_TRUE
;
1491 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1492 bufObj
->Name
, size
, data
, usage
);
1499 assert(ctx
->Driver
.BufferData
);
1500 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1503 GL_DYNAMIC_STORAGE_BIT
,
1505 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1506 /* From GL_AMD_pinned_memory:
1508 * INVALID_OPERATION is generated by BufferData if <target> is
1509 * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
1510 * mapped to the GPU address space.
1512 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData()");
1515 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferData()");
1522 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1523 GLsizeiptrARB size
, const GLvoid
* data
)
1525 GET_CURRENT_CONTEXT(ctx
);
1526 struct gl_buffer_object
*bufObj
;
1528 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1529 false, GL_INVALID_OPERATION
,
1530 "glBufferSubDataARB" );
1532 /* error already recorded */
1536 if (bufObj
->Immutable
&&
1537 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1538 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubData");
1545 bufObj
->Written
= GL_TRUE
;
1547 assert(ctx
->Driver
.BufferSubData
);
1548 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1553 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1554 GLsizeiptrARB size
, void * data
)
1556 GET_CURRENT_CONTEXT(ctx
);
1557 struct gl_buffer_object
*bufObj
;
1559 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1560 false, GL_INVALID_OPERATION
,
1561 "glGetBufferSubDataARB");
1563 /* error already recorded */
1567 assert(ctx
->Driver
.GetBufferSubData
);
1568 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1573 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1574 GLenum type
, const GLvoid
* data
)
1576 GET_CURRENT_CONTEXT(ctx
);
1577 struct gl_buffer_object
* bufObj
;
1578 mesa_format mesaFormat
;
1579 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1580 GLsizeiptr clearValueSize
;
1582 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1587 if (_mesa_check_disallowed_mapping(bufObj
)) {
1588 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1589 "glClearBufferData(buffer currently mapped)");
1593 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1595 "glClearBufferData");
1596 if (mesaFormat
== MESA_FORMAT_NONE
) {
1600 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1601 if (bufObj
->Size
% clearValueSize
!= 0) {
1602 _mesa_error(ctx
, GL_INVALID_VALUE
,
1603 "glClearBufferData(size is not a multiple of "
1604 "internalformat size)");
1609 /* clear to zeros, per the spec */
1610 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1611 NULL
, clearValueSize
, bufObj
);
1615 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1616 format
, type
, data
, "glClearBufferData")) {
1620 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1621 clearValue
, clearValueSize
, bufObj
);
1626 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1627 GLintptr offset
, GLsizeiptr size
,
1628 GLenum format
, GLenum type
,
1631 GET_CURRENT_CONTEXT(ctx
);
1632 struct gl_buffer_object
* bufObj
;
1633 mesa_format mesaFormat
;
1634 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1635 GLsizeiptr clearValueSize
;
1637 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1638 true, GL_INVALID_VALUE
,
1639 "glClearBufferSubData");
1644 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1646 "glClearBufferSubData");
1647 if (mesaFormat
== MESA_FORMAT_NONE
) {
1651 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1652 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1653 _mesa_error(ctx
, GL_INVALID_VALUE
,
1654 "glClearBufferSubData(offset or size is not a multiple of "
1655 "internalformat size)");
1660 /* clear to zeros, per the spec */
1662 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1663 NULL
, clearValueSize
, bufObj
);
1668 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1670 "glClearBufferSubData")) {
1675 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1676 clearValue
, clearValueSize
, bufObj
);
1682 _mesa_MapBuffer(GLenum target
, GLenum access
)
1684 GET_CURRENT_CONTEXT(ctx
);
1685 struct gl_buffer_object
* bufObj
;
1686 GLbitfield accessFlags
;
1690 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1693 case GL_READ_ONLY_ARB
:
1694 accessFlags
= GL_MAP_READ_BIT
;
1695 valid_access
= _mesa_is_desktop_gl(ctx
);
1697 case GL_WRITE_ONLY_ARB
:
1698 accessFlags
= GL_MAP_WRITE_BIT
;
1699 valid_access
= true;
1701 case GL_READ_WRITE_ARB
:
1702 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1703 valid_access
= _mesa_is_desktop_gl(ctx
);
1706 valid_access
= false;
1710 if (!valid_access
) {
1711 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1715 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
, GL_INVALID_OPERATION
);
1719 if (accessFlags
& GL_MAP_READ_BIT
&&
1720 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
1721 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1722 "glMapBuffer(invalid read flag)");
1726 if (accessFlags
& GL_MAP_WRITE_BIT
&&
1727 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
1728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1729 "glMapBuffer(invalid write flag)");
1733 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1734 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1738 if (!bufObj
->Size
) {
1739 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1740 "glMapBuffer(buffer size = 0)");
1744 assert(ctx
->Driver
.MapBufferRange
);
1745 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
,
1748 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1752 /* The driver callback should have set these fields.
1753 * This is important because other modules (like VBO) might call
1754 * the driver function directly.
1756 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
1757 assert(bufObj
->Mappings
[MAP_USER
].Length
== bufObj
->Size
);
1758 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1759 bufObj
->Mappings
[MAP_USER
].AccessFlags
= accessFlags
;
1762 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1763 bufObj
->Written
= GL_TRUE
;
1766 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1767 bufObj
->Name
, bufObj
->Size
, access
);
1768 if (access
== GL_WRITE_ONLY_ARB
) {
1770 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1771 for (i
= 0; i
< bufObj
->Size
; i
++)
1778 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1780 /* buffer is 100 bytes larger than requested, fill with magic value */
1781 for (i
= 0; i
< 100; i
++) {
1782 buf
[bufObj
->Size
- i
- 1] = 123;
1787 return bufObj
->Mappings
[MAP_USER
].Pointer
;
1791 GLboolean GLAPIENTRY
1792 _mesa_UnmapBuffer(GLenum target
)
1794 GET_CURRENT_CONTEXT(ctx
);
1795 struct gl_buffer_object
*bufObj
;
1796 GLboolean status
= GL_TRUE
;
1797 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1799 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
, GL_INVALID_OPERATION
);
1803 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1804 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1809 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1810 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1812 /* check that last 100 bytes are still = magic value */
1813 for (i
= 0; i
< 100; i
++) {
1814 GLuint pos
= bufObj
->Size
- i
- 1;
1815 if (buf
[pos
] != 123) {
1816 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1817 " at position %d (value = %u)\n",
1825 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1826 GLuint i
, unchanged
= 0;
1827 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1829 /* check which bytes changed */
1830 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1831 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1838 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1839 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1844 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1845 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1846 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1847 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1848 assert(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1855 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1857 GET_CURRENT_CONTEXT(ctx
);
1858 struct gl_buffer_object
*bufObj
;
1860 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
,
1861 GL_INVALID_OPERATION
);
1866 case GL_BUFFER_SIZE_ARB
:
1867 *params
= (GLint
) bufObj
->Size
;
1869 case GL_BUFFER_USAGE_ARB
:
1870 *params
= bufObj
->Usage
;
1872 case GL_BUFFER_ACCESS_ARB
:
1873 *params
= simplified_access_mode(ctx
,
1874 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1876 case GL_BUFFER_MAPPED_ARB
:
1877 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1879 case GL_BUFFER_ACCESS_FLAGS
:
1880 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1882 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1884 case GL_BUFFER_MAP_OFFSET
:
1885 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1887 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Offset
;
1889 case GL_BUFFER_MAP_LENGTH
:
1890 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1892 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Length
;
1894 case GL_BUFFER_IMMUTABLE_STORAGE
:
1895 if (!ctx
->Extensions
.ARB_buffer_storage
)
1897 *params
= bufObj
->Immutable
;
1899 case GL_BUFFER_STORAGE_FLAGS
:
1900 if (!ctx
->Extensions
.ARB_buffer_storage
)
1902 *params
= bufObj
->StorageFlags
;
1905 ; /* fall-through */
1909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1910 _mesa_lookup_enum_by_nr(pname
));
1916 * This is pretty much a duplicate of GetBufferParameteriv() but the
1917 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1920 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1922 GET_CURRENT_CONTEXT(ctx
);
1923 struct gl_buffer_object
*bufObj
;
1925 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
1926 GL_INVALID_OPERATION
);
1931 case GL_BUFFER_SIZE_ARB
:
1932 *params
= bufObj
->Size
;
1934 case GL_BUFFER_USAGE_ARB
:
1935 *params
= bufObj
->Usage
;
1937 case GL_BUFFER_ACCESS_ARB
:
1938 *params
= simplified_access_mode(ctx
,
1939 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1941 case GL_BUFFER_ACCESS_FLAGS
:
1942 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1944 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1946 case GL_BUFFER_MAPPED_ARB
:
1947 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1949 case GL_BUFFER_MAP_OFFSET
:
1950 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1952 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
1954 case GL_BUFFER_MAP_LENGTH
:
1955 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1957 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
1959 case GL_BUFFER_IMMUTABLE_STORAGE
:
1960 if (!ctx
->Extensions
.ARB_buffer_storage
)
1962 *params
= bufObj
->Immutable
;
1964 case GL_BUFFER_STORAGE_FLAGS
:
1965 if (!ctx
->Extensions
.ARB_buffer_storage
)
1967 *params
= bufObj
->StorageFlags
;
1970 ; /* fall-through */
1974 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1975 _mesa_lookup_enum_by_nr(pname
));
1980 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1982 GET_CURRENT_CONTEXT(ctx
);
1983 struct gl_buffer_object
* bufObj
;
1985 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1990 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
,
1991 GL_INVALID_OPERATION
);
1995 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2000 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
2001 GLintptr readOffset
, GLintptr writeOffset
,
2004 GET_CURRENT_CONTEXT(ctx
);
2005 struct gl_buffer_object
*src
, *dst
;
2007 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
2008 GL_INVALID_OPERATION
);
2012 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
2013 GL_INVALID_OPERATION
);
2017 if (_mesa_check_disallowed_mapping(src
)) {
2018 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2019 "glCopyBufferSubData(readBuffer is mapped)");
2023 if (_mesa_check_disallowed_mapping(dst
)) {
2024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2025 "glCopyBufferSubData(writeBuffer is mapped)");
2029 if (readOffset
< 0) {
2030 _mesa_error(ctx
, GL_INVALID_VALUE
,
2031 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
2035 if (writeOffset
< 0) {
2036 _mesa_error(ctx
, GL_INVALID_VALUE
,
2037 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
2042 _mesa_error(ctx
, GL_INVALID_VALUE
,
2043 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
2047 if (readOffset
+ size
> src
->Size
) {
2048 _mesa_error(ctx
, GL_INVALID_VALUE
,
2049 "glCopyBufferSubData(readOffset + size = %d)",
2050 (int) (readOffset
+ size
));
2054 if (writeOffset
+ size
> dst
->Size
) {
2055 _mesa_error(ctx
, GL_INVALID_VALUE
,
2056 "glCopyBufferSubData(writeOffset + size = %d)",
2057 (int) (writeOffset
+ size
));
2062 if (readOffset
+ size
<= writeOffset
) {
2065 else if (writeOffset
+ size
<= readOffset
) {
2069 /* overlapping src/dst is illegal */
2070 _mesa_error(ctx
, GL_INVALID_VALUE
,
2071 "glCopyBufferSubData(overlapping src/dst)");
2076 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2081 * See GL_ARB_map_buffer_range spec
2084 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2087 GET_CURRENT_CONTEXT(ctx
);
2088 struct gl_buffer_object
*bufObj
;
2090 GLbitfield allowed_access
;
2092 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2094 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "glMapBufferRange(extension not supported)");
2101 _mesa_error(ctx
, GL_INVALID_VALUE
,
2102 "glMapBufferRange(offset = %ld)", (long)offset
);
2107 _mesa_error(ctx
, GL_INVALID_VALUE
,
2108 "glMapBufferRange(length = %ld)", (long)length
);
2112 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2114 * "An INVALID_OPERATION error is generated for any of the following
2117 * * <length> is zero."
2119 if (_mesa_is_gles(ctx
) && length
== 0) {
2120 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2121 "glMapBufferRange(length = 0)");
2125 allowed_access
= GL_MAP_READ_BIT
|
2127 GL_MAP_INVALIDATE_RANGE_BIT
|
2128 GL_MAP_INVALIDATE_BUFFER_BIT
|
2129 GL_MAP_FLUSH_EXPLICIT_BIT
|
2130 GL_MAP_UNSYNCHRONIZED_BIT
;
2132 if (ctx
->Extensions
.ARB_buffer_storage
) {
2133 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2134 GL_MAP_COHERENT_BIT
;
2137 if (access
& ~allowed_access
) {
2138 /* generate an error if any other than allowed bit is set */
2139 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
2143 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "glMapBufferRange(access indicates neither read or write)");
2149 if ((access
& GL_MAP_READ_BIT
) &&
2150 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2151 GL_MAP_INVALIDATE_BUFFER_BIT
|
2152 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2153 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2154 "glMapBufferRange(invalid access flags)");
2158 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2159 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2161 "glMapBufferRange(invalid access flags)");
2165 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2169 if (access
& GL_MAP_READ_BIT
&&
2170 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2172 "glMapBufferRange(invalid read flag)");
2176 if (access
& GL_MAP_WRITE_BIT
&&
2177 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glMapBufferRange(invalid write flag)");
2183 if (access
& GL_MAP_COHERENT_BIT
&&
2184 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2185 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2186 "glMapBufferRange(invalid coherent flag)");
2190 if (access
& GL_MAP_PERSISTENT_BIT
&&
2191 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2192 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2193 "glMapBufferRange(invalid persistent flag)");
2197 if (offset
+ length
> bufObj
->Size
) {
2198 _mesa_error(ctx
, GL_INVALID_VALUE
,
2199 "glMapBufferRange(offset + length > size)");
2203 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2205 "glMapBufferRange(buffer already mapped)");
2209 if (!bufObj
->Size
) {
2210 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2211 "glMapBufferRange(buffer size = 0)");
2215 /* Mapping zero bytes should return a non-null pointer. */
2217 static long dummy
= 0;
2218 bufObj
->Mappings
[MAP_USER
].Pointer
= &dummy
;
2219 bufObj
->Mappings
[MAP_USER
].Length
= length
;
2220 bufObj
->Mappings
[MAP_USER
].Offset
= offset
;
2221 bufObj
->Mappings
[MAP_USER
].AccessFlags
= access
;
2222 return bufObj
->Mappings
[MAP_USER
].Pointer
;
2225 assert(ctx
->Driver
.MapBufferRange
);
2226 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2229 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
2232 /* The driver callback should have set all these fields.
2233 * This is important because other modules (like VBO) might call
2234 * the driver function directly.
2236 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2237 assert(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2238 assert(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2239 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2247 * See GL_ARB_map_buffer_range spec
2250 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
2252 GET_CURRENT_CONTEXT(ctx
);
2253 struct gl_buffer_object
*bufObj
;
2255 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2257 "glFlushMappedBufferRange(extension not supported)");
2262 _mesa_error(ctx
, GL_INVALID_VALUE
,
2263 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
2268 _mesa_error(ctx
, GL_INVALID_VALUE
,
2269 "glFlushMappedBufferRange(length = %ld)", (long)length
);
2273 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2274 GL_INVALID_OPERATION
);
2278 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2279 /* buffer is not mapped */
2280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2281 "glFlushMappedBufferRange(buffer is not mapped)");
2285 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2286 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2287 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2288 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
2292 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2293 _mesa_error(ctx
, GL_INVALID_VALUE
,
2294 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
2295 (long)offset
, (long)length
,
2296 (long)bufObj
->Mappings
[MAP_USER
].Length
);
2300 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2302 if (ctx
->Driver
.FlushMappedBufferRange
)
2303 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2309 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2311 struct gl_buffer_object
*bufObj
;
2314 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2316 _mesa_error(ctx
, GL_INVALID_VALUE
,
2317 "glObjectPurgeable(name = 0x%x)", name
);
2320 if (!_mesa_is_bufferobj(bufObj
)) {
2321 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2325 if (bufObj
->Purgeable
) {
2326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2327 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2328 return GL_VOLATILE_APPLE
;
2331 bufObj
->Purgeable
= GL_TRUE
;
2333 retval
= GL_VOLATILE_APPLE
;
2334 if (ctx
->Driver
.BufferObjectPurgeable
)
2335 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2342 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2344 struct gl_renderbuffer
*bufObj
;
2347 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2349 _mesa_error(ctx
, GL_INVALID_VALUE
,
2350 "glObjectUnpurgeable(name = 0x%x)", name
);
2354 if (bufObj
->Purgeable
) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2356 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2357 return GL_VOLATILE_APPLE
;
2360 bufObj
->Purgeable
= GL_TRUE
;
2362 retval
= GL_VOLATILE_APPLE
;
2363 if (ctx
->Driver
.RenderObjectPurgeable
)
2364 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2371 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2373 struct gl_texture_object
*bufObj
;
2376 bufObj
= _mesa_lookup_texture(ctx
, name
);
2378 _mesa_error(ctx
, GL_INVALID_VALUE
,
2379 "glObjectPurgeable(name = 0x%x)", name
);
2383 if (bufObj
->Purgeable
) {
2384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2385 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2386 return GL_VOLATILE_APPLE
;
2389 bufObj
->Purgeable
= GL_TRUE
;
2391 retval
= GL_VOLATILE_APPLE
;
2392 if (ctx
->Driver
.TextureObjectPurgeable
)
2393 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2400 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2404 GET_CURRENT_CONTEXT(ctx
);
2405 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2408 _mesa_error(ctx
, GL_INVALID_VALUE
,
2409 "glObjectPurgeable(name = 0x%x)", name
);
2414 case GL_VOLATILE_APPLE
:
2415 case GL_RELEASED_APPLE
:
2419 _mesa_error(ctx
, GL_INVALID_ENUM
,
2420 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2425 switch (objectType
) {
2427 retval
= texture_object_purgeable(ctx
, name
, option
);
2429 case GL_RENDERBUFFER_EXT
:
2430 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2432 case GL_BUFFER_OBJECT_APPLE
:
2433 retval
= buffer_object_purgeable(ctx
, name
, option
);
2436 _mesa_error(ctx
, GL_INVALID_ENUM
,
2437 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2442 /* In strict conformance to the spec, we must only return VOLATILE when
2443 * when passed the VOLATILE option. Madness.
2445 * XXX First fix the spec, then fix me.
2447 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2452 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2454 struct gl_buffer_object
*bufObj
;
2457 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2459 _mesa_error(ctx
, GL_INVALID_VALUE
,
2460 "glObjectUnpurgeable(name = 0x%x)", name
);
2464 if (! bufObj
->Purgeable
) {
2465 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2466 "glObjectUnpurgeable(name = 0x%x) object is "
2467 " already \"unpurged\"", name
);
2471 bufObj
->Purgeable
= GL_FALSE
;
2474 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2475 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2482 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2484 struct gl_renderbuffer
*bufObj
;
2487 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2489 _mesa_error(ctx
, GL_INVALID_VALUE
,
2490 "glObjectUnpurgeable(name = 0x%x)", name
);
2494 if (! bufObj
->Purgeable
) {
2495 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2496 "glObjectUnpurgeable(name = 0x%x) object is "
2497 " already \"unpurged\"", name
);
2501 bufObj
->Purgeable
= GL_FALSE
;
2504 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2505 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2512 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2514 struct gl_texture_object
*bufObj
;
2517 bufObj
= _mesa_lookup_texture(ctx
, name
);
2519 _mesa_error(ctx
, GL_INVALID_VALUE
,
2520 "glObjectUnpurgeable(name = 0x%x)", name
);
2524 if (! bufObj
->Purgeable
) {
2525 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2526 "glObjectUnpurgeable(name = 0x%x) object is"
2527 " already \"unpurged\"", name
);
2531 bufObj
->Purgeable
= GL_FALSE
;
2534 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2535 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2542 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2544 GET_CURRENT_CONTEXT(ctx
);
2545 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2548 _mesa_error(ctx
, GL_INVALID_VALUE
,
2549 "glObjectUnpurgeable(name = 0x%x)", name
);
2554 case GL_RETAINED_APPLE
:
2555 case GL_UNDEFINED_APPLE
:
2559 _mesa_error(ctx
, GL_INVALID_ENUM
,
2560 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2565 switch (objectType
) {
2566 case GL_BUFFER_OBJECT_APPLE
:
2567 return buffer_object_unpurgeable(ctx
, name
, option
);
2569 return texture_object_unpurgeable(ctx
, name
, option
);
2570 case GL_RENDERBUFFER_EXT
:
2571 return renderbuffer_unpurgeable(ctx
, name
, option
);
2573 _mesa_error(ctx
, GL_INVALID_ENUM
,
2574 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2582 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2583 GLenum pname
, GLint
*params
)
2585 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2587 _mesa_error(ctx
, GL_INVALID_VALUE
,
2588 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2593 case GL_PURGEABLE_APPLE
:
2594 *params
= bufObj
->Purgeable
;
2597 _mesa_error(ctx
, GL_INVALID_ENUM
,
2598 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2606 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2607 GLenum pname
, GLint
*params
)
2609 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2611 _mesa_error(ctx
, GL_INVALID_VALUE
,
2612 "glObjectUnpurgeable(name = 0x%x)", name
);
2617 case GL_PURGEABLE_APPLE
:
2618 *params
= rb
->Purgeable
;
2621 _mesa_error(ctx
, GL_INVALID_ENUM
,
2622 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2630 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2631 GLenum pname
, GLint
*params
)
2633 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2635 _mesa_error(ctx
, GL_INVALID_VALUE
,
2636 "glObjectUnpurgeable(name = 0x%x)", name
);
2641 case GL_PURGEABLE_APPLE
:
2642 *params
= texObj
->Purgeable
;
2645 _mesa_error(ctx
, GL_INVALID_ENUM
,
2646 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2654 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2657 GET_CURRENT_CONTEXT(ctx
);
2660 _mesa_error(ctx
, GL_INVALID_VALUE
,
2661 "glGetObjectParameteriv(name = 0x%x)", name
);
2665 switch (objectType
) {
2667 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2669 case GL_BUFFER_OBJECT_APPLE
:
2670 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2672 case GL_RENDERBUFFER_EXT
:
2673 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2676 _mesa_error(ctx
, GL_INVALID_ENUM
,
2677 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2683 * Binds a buffer object to a uniform buffer binding point.
2685 * The caller is responsible for flushing vertices and updating
2689 set_ubo_binding(struct gl_context
*ctx
,
2690 struct gl_uniform_buffer_binding
*binding
,
2691 struct gl_buffer_object
*bufObj
,
2696 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2698 binding
->Offset
= offset
;
2699 binding
->Size
= size
;
2700 binding
->AutomaticSize
= autoSize
;
2702 /* If this is a real buffer object, mark it has having been used
2703 * at some point as a UBO.
2706 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
2710 * Binds a buffer object to a uniform buffer binding point.
2712 * Unlike set_ubo_binding(), this function also flushes vertices
2713 * and updates NewDriverState. It also checks if the binding
2714 * has actually changed before updating it.
2717 bind_uniform_buffer(struct gl_context
*ctx
,
2719 struct gl_buffer_object
*bufObj
,
2724 struct gl_uniform_buffer_binding
*binding
=
2725 &ctx
->UniformBufferBindings
[index
];
2727 if (binding
->BufferObject
== bufObj
&&
2728 binding
->Offset
== offset
&&
2729 binding
->Size
== size
&&
2730 binding
->AutomaticSize
== autoSize
) {
2734 FLUSH_VERTICES(ctx
, 0);
2735 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2737 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
2741 * Bind a region of a buffer object to a uniform block binding point.
2742 * \param index the uniform buffer binding point index
2743 * \param bufObj the buffer object
2744 * \param offset offset to the start of buffer object region
2745 * \param size size of the buffer object region
2748 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2750 struct gl_buffer_object
*bufObj
,
2754 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2755 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2759 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2760 _mesa_error(ctx
, GL_INVALID_VALUE
,
2761 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
2762 ctx
->Const
.UniformBufferOffsetAlignment
);
2766 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2771 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2772 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2777 * Bind a buffer object to a uniform block binding point.
2778 * As above, but offset = 0.
2781 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2783 struct gl_buffer_object
*bufObj
)
2785 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2786 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2790 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2792 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2793 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2795 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2799 * Binds a buffer object to an atomic buffer binding point.
2801 * The caller is responsible for validating the offset,
2802 * flushing the vertices and updating NewDriverState.
2805 set_atomic_buffer_binding(struct gl_context
*ctx
,
2806 struct gl_atomic_buffer_binding
*binding
,
2807 struct gl_buffer_object
*bufObj
,
2811 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2813 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2814 binding
->Offset
= -1;
2817 binding
->Offset
= offset
;
2818 binding
->Size
= size
;
2819 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
2824 * Binds a buffer object to an atomic buffer binding point.
2826 * Unlike set_atomic_buffer_binding(), this function also validates the
2827 * index and offset, flushes vertices, and updates NewDriverState.
2828 * It also checks if the binding has actually changing before
2832 bind_atomic_buffer(struct gl_context
*ctx
,
2834 struct gl_buffer_object
*bufObj
,
2839 struct gl_atomic_buffer_binding
*binding
;
2841 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2842 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2846 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2847 _mesa_error(ctx
, GL_INVALID_VALUE
,
2848 "%s(offset misaligned %d/%d)", name
, (int) offset
,
2849 ATOMIC_COUNTER_SIZE
);
2853 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2855 binding
= &ctx
->AtomicBufferBindings
[index
];
2856 if (binding
->BufferObject
== bufObj
&&
2857 binding
->Offset
== offset
&&
2858 binding
->Size
== size
) {
2862 FLUSH_VERTICES(ctx
, 0);
2863 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2865 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
2869 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
2871 const GLintptr
*offsets
,
2872 const GLsizeiptr
*sizes
)
2874 if (offsets
[index
] < 0) {
2875 /* The ARB_multi_bind spec says:
2877 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2878 * value in <offsets> is less than zero (per binding)."
2880 _mesa_error(ctx
, GL_INVALID_VALUE
,
2881 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
2882 index
, (int64_t) offsets
[index
]);
2886 if (sizes
[index
] <= 0) {
2887 /* The ARB_multi_bind spec says:
2889 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2890 * value in <sizes> is less than or equal to zero (per binding)."
2892 _mesa_error(ctx
, GL_INVALID_VALUE
,
2893 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
2894 index
, (int64_t) sizes
[index
]);
2902 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
2903 GLuint first
, GLsizei count
,
2906 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
2907 _mesa_error(ctx
, GL_INVALID_ENUM
,
2908 "%s(target=GL_UNIFORM_BUFFER)", caller
);
2912 /* The ARB_multi_bind_spec says:
2914 * "An INVALID_OPERATION error is generated if <first> + <count> is
2915 * greater than the number of target-specific indexed binding points,
2916 * as described in section 6.7.1."
2918 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
2919 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2920 "%s(first=%u + count=%d > the value of "
2921 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
2922 caller
, first
, count
,
2923 ctx
->Const
.MaxUniformBufferBindings
);
2931 * Unbind all uniform buffers in the range
2932 * <first> through <first>+<count>-1
2935 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
2937 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
2940 for (i
= 0; i
< count
; i
++)
2941 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
2942 bufObj
, -1, -1, GL_TRUE
);
2946 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2947 const GLuint
*buffers
)
2951 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
2954 /* Assume that at least one binding will be changed */
2955 FLUSH_VERTICES(ctx
, 0);
2956 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2959 /* The ARB_multi_bind spec says:
2961 * "If <buffers> is NULL, all bindings from <first> through
2962 * <first>+<count>-1 are reset to their unbound (zero) state."
2964 unbind_uniform_buffers(ctx
, first
, count
);
2968 /* Note that the error semantics for multi-bind commands differ from
2969 * those of other GL commands.
2971 * The Issues section in the ARB_multi_bind spec says:
2973 * "(11) Typically, OpenGL specifies that if an error is generated by a
2974 * command, that command has no effect. This is somewhat
2975 * unfortunate for multi-bind commands, because it would require a
2976 * first pass to scan the entire list of bound objects for errors
2977 * and then a second pass to actually perform the bindings.
2978 * Should we have different error semantics?
2980 * RESOLVED: Yes. In this specification, when the parameters for
2981 * one of the <count> binding points are invalid, that binding point
2982 * is not updated and an error will be generated. However, other
2983 * binding points in the same command will be updated if their
2984 * parameters are valid and no other error occurs."
2987 _mesa_begin_bufferobj_lookups(ctx
);
2989 for (i
= 0; i
< count
; i
++) {
2990 struct gl_uniform_buffer_binding
*binding
=
2991 &ctx
->UniformBufferBindings
[first
+ i
];
2992 struct gl_buffer_object
*bufObj
;
2994 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
2995 bufObj
= binding
->BufferObject
;
2997 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
2998 "glBindBuffersBase");
3001 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3002 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
3004 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
3008 _mesa_end_bufferobj_lookups(ctx
);
3012 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3013 const GLuint
*buffers
,
3014 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3018 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
3019 "glBindBuffersRange"))
3022 /* Assume that at least one binding will be changed */
3023 FLUSH_VERTICES(ctx
, 0);
3024 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3027 /* The ARB_multi_bind spec says:
3029 * "If <buffers> is NULL, all bindings from <first> through
3030 * <first>+<count>-1 are reset to their unbound (zero) state.
3031 * In this case, the offsets and sizes associated with the
3032 * binding points are set to default values, ignoring
3033 * <offsets> and <sizes>."
3035 unbind_uniform_buffers(ctx
, first
, count
);
3039 /* Note that the error semantics for multi-bind commands differ from
3040 * those of other GL commands.
3042 * The Issues section in the ARB_multi_bind spec says:
3044 * "(11) Typically, OpenGL specifies that if an error is generated by a
3045 * command, that command has no effect. This is somewhat
3046 * unfortunate for multi-bind commands, because it would require a
3047 * first pass to scan the entire list of bound objects for errors
3048 * and then a second pass to actually perform the bindings.
3049 * Should we have different error semantics?
3051 * RESOLVED: Yes. In this specification, when the parameters for
3052 * one of the <count> binding points are invalid, that binding point
3053 * is not updated and an error will be generated. However, other
3054 * binding points in the same command will be updated if their
3055 * parameters are valid and no other error occurs."
3058 _mesa_begin_bufferobj_lookups(ctx
);
3060 for (i
= 0; i
< count
; i
++) {
3061 struct gl_uniform_buffer_binding
*binding
=
3062 &ctx
->UniformBufferBindings
[first
+ i
];
3063 struct gl_buffer_object
*bufObj
;
3065 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3068 /* The ARB_multi_bind spec says:
3070 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3071 * pair of values in <offsets> and <sizes> does not respectively
3072 * satisfy the constraints described for those parameters for the
3073 * specified target, as described in section 6.7.1 (per binding)."
3075 * Section 6.7.1 refers to table 6.5, which says:
3077 * "┌───────────────────────────────────────────────────────────────┐
3078 * │ Uniform buffer array bindings (see sec. 7.6) │
3079 * ├─────────────────────┬─────────────────────────────────────────┤
3081 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3082 * │ │ OFFSET_ALIGNMENT │
3084 * │ size restriction │ none │
3085 * └─────────────────────┴─────────────────────────────────────────┘"
3087 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3088 _mesa_error(ctx
, GL_INVALID_VALUE
,
3089 "glBindBuffersRange(offsets[%u]=%" PRId64
3090 " is misaligned; it must be a multiple of the value of "
3091 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3092 "target=GL_UNIFORM_BUFFER)",
3093 i
, (int64_t) offsets
[i
],
3094 ctx
->Const
.UniformBufferOffsetAlignment
);
3098 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3099 bufObj
= binding
->BufferObject
;
3101 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3102 "glBindBuffersRange");
3105 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3106 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3108 set_ubo_binding(ctx
, binding
, bufObj
,
3109 offsets
[i
], sizes
[i
], GL_FALSE
);
3113 _mesa_end_bufferobj_lookups(ctx
);
3117 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3118 struct gl_transform_feedback_object
*tfObj
,
3119 GLuint first
, GLsizei count
, const char *caller
)
3121 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3122 _mesa_error(ctx
, GL_INVALID_ENUM
,
3123 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3127 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3129 * "An INVALID_OPERATION error is generated :
3132 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3133 * FEEDBACK_BUFFER and transform feedback is currently active."
3135 * We assume that this is also meant to apply to BindBuffersRange
3136 * and BindBuffersBase.
3138 if (tfObj
->Active
) {
3139 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3140 "%s(Changing transform feedback buffers while "
3141 "transform feedback is active)", caller
);
3145 /* The ARB_multi_bind_spec says:
3147 * "An INVALID_OPERATION error is generated if <first> + <count> is
3148 * greater than the number of target-specific indexed binding points,
3149 * as described in section 6.7.1."
3151 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3152 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3153 "%s(first=%u + count=%d > the value of "
3154 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3155 caller
, first
, count
,
3156 ctx
->Const
.MaxTransformFeedbackBuffers
);
3164 * Unbind all transform feedback buffers in the range
3165 * <first> through <first>+<count>-1
3168 unbind_xfb_buffers(struct gl_context
*ctx
,
3169 struct gl_transform_feedback_object
*tfObj
,
3170 GLuint first
, GLsizei count
)
3172 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3175 for (i
= 0; i
< count
; i
++)
3176 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3181 bind_xfb_buffers_base(struct gl_context
*ctx
,
3182 GLuint first
, GLsizei count
,
3183 const GLuint
*buffers
)
3185 struct gl_transform_feedback_object
*tfObj
=
3186 ctx
->TransformFeedback
.CurrentObject
;
3189 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3190 "glBindBuffersBase"))
3193 /* Assume that at least one binding will be changed */
3194 FLUSH_VERTICES(ctx
, 0);
3195 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3198 /* The ARB_multi_bind spec says:
3200 * "If <buffers> is NULL, all bindings from <first> through
3201 * <first>+<count>-1 are reset to their unbound (zero) state."
3203 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3207 /* Note that the error semantics for multi-bind commands differ from
3208 * those of other GL commands.
3210 * The Issues section in the ARB_multi_bind spec says:
3212 * "(11) Typically, OpenGL specifies that if an error is generated by a
3213 * command, that command has no effect. This is somewhat
3214 * unfortunate for multi-bind commands, because it would require a
3215 * first pass to scan the entire list of bound objects for errors
3216 * and then a second pass to actually perform the bindings.
3217 * Should we have different error semantics?
3219 * RESOLVED: Yes. In this specification, when the parameters for
3220 * one of the <count> binding points are invalid, that binding point
3221 * is not updated and an error will be generated. However, other
3222 * binding points in the same command will be updated if their
3223 * parameters are valid and no other error occurs."
3226 _mesa_begin_bufferobj_lookups(ctx
);
3228 for (i
= 0; i
< count
; i
++) {
3229 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3230 struct gl_buffer_object
*bufObj
;
3232 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3233 bufObj
= boundBufObj
;
3235 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3236 "glBindBuffersBase");
3239 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3243 _mesa_end_bufferobj_lookups(ctx
);
3247 bind_xfb_buffers_range(struct gl_context
*ctx
,
3248 GLuint first
, GLsizei count
,
3249 const GLuint
*buffers
,
3250 const GLintptr
*offsets
,
3251 const GLsizeiptr
*sizes
)
3253 struct gl_transform_feedback_object
*tfObj
=
3254 ctx
->TransformFeedback
.CurrentObject
;
3257 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3258 "glBindBuffersRange"))
3261 /* Assume that at least one binding will be changed */
3262 FLUSH_VERTICES(ctx
, 0);
3263 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3266 /* The ARB_multi_bind spec says:
3268 * "If <buffers> is NULL, all bindings from <first> through
3269 * <first>+<count>-1 are reset to their unbound (zero) state.
3270 * In this case, the offsets and sizes associated with the
3271 * binding points are set to default values, ignoring
3272 * <offsets> and <sizes>."
3274 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3278 /* Note that the error semantics for multi-bind commands differ from
3279 * those of other GL commands.
3281 * The Issues section in the ARB_multi_bind spec says:
3283 * "(11) Typically, OpenGL specifies that if an error is generated by a
3284 * command, that command has no effect. This is somewhat
3285 * unfortunate for multi-bind commands, because it would require a
3286 * first pass to scan the entire list of bound objects for errors
3287 * and then a second pass to actually perform the bindings.
3288 * Should we have different error semantics?
3290 * RESOLVED: Yes. In this specification, when the parameters for
3291 * one of the <count> binding points are invalid, that binding point
3292 * is not updated and an error will be generated. However, other
3293 * binding points in the same command will be updated if their
3294 * parameters are valid and no other error occurs."
3297 _mesa_begin_bufferobj_lookups(ctx
);
3299 for (i
= 0; i
< count
; i
++) {
3300 const GLuint index
= first
+ i
;
3301 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3302 struct gl_buffer_object
*bufObj
;
3304 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3307 /* The ARB_multi_bind spec says:
3309 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3310 * pair of values in <offsets> and <sizes> does not respectively
3311 * satisfy the constraints described for those parameters for the
3312 * specified target, as described in section 6.7.1 (per binding)."
3314 * Section 6.7.1 refers to table 6.5, which says:
3316 * "┌───────────────────────────────────────────────────────────────┐
3317 * │ Transform feedback array bindings (see sec. 13.2.2) │
3318 * ├───────────────────────┬───────────────────────────────────────┤
3320 * │ offset restriction │ multiple of 4 │
3322 * │ size restriction │ multiple of 4 │
3323 * └───────────────────────┴───────────────────────────────────────┘"
3325 if (offsets
[i
] & 0x3) {
3326 _mesa_error(ctx
, GL_INVALID_VALUE
,
3327 "glBindBuffersRange(offsets[%u]=%" PRId64
3328 " is misaligned; it must be a multiple of 4 when "
3329 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3330 i
, (int64_t) offsets
[i
]);
3334 if (sizes
[i
] & 0x3) {
3335 _mesa_error(ctx
, GL_INVALID_VALUE
,
3336 "glBindBuffersRange(sizes[%u]=%" PRId64
3337 " is misaligned; it must be a multiple of 4 when "
3338 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3339 i
, (int64_t) sizes
[i
]);
3343 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3344 bufObj
= boundBufObj
;
3346 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3347 "glBindBuffersRange");
3350 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
3351 offsets
[i
], sizes
[i
]);
3354 _mesa_end_bufferobj_lookups(ctx
);
3358 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
3359 GLuint first
, GLsizei count
,
3362 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
3363 _mesa_error(ctx
, GL_INVALID_ENUM
,
3364 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
3368 /* The ARB_multi_bind_spec says:
3370 * "An INVALID_OPERATION error is generated if <first> + <count> is
3371 * greater than the number of target-specific indexed binding points,
3372 * as described in section 6.7.1."
3374 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
3375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3376 "%s(first=%u + count=%d > the value of "
3377 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
3378 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
3386 * Unbind all atomic counter buffers in the range
3387 * <first> through <first>+<count>-1
3390 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3392 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3395 for (i
= 0; i
< count
; i
++)
3396 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
3401 bind_atomic_buffers_base(struct gl_context
*ctx
,
3404 const GLuint
*buffers
)
3408 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3409 "glBindBuffersBase"))
3412 /* Assume that at least one binding will be changed */
3413 FLUSH_VERTICES(ctx
, 0);
3414 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3417 /* The ARB_multi_bind spec says:
3419 * "If <buffers> is NULL, all bindings from <first> through
3420 * <first>+<count>-1 are reset to their unbound (zero) state."
3422 unbind_atomic_buffers(ctx
, first
, count
);
3426 /* Note that the error semantics for multi-bind commands differ from
3427 * those of other GL commands.
3429 * The Issues section in the ARB_multi_bind spec says:
3431 * "(11) Typically, OpenGL specifies that if an error is generated by a
3432 * command, that command has no effect. This is somewhat
3433 * unfortunate for multi-bind commands, because it would require a
3434 * first pass to scan the entire list of bound objects for errors
3435 * and then a second pass to actually perform the bindings.
3436 * Should we have different error semantics?
3438 * RESOLVED: Yes. In this specification, when the parameters for
3439 * one of the <count> binding points are invalid, that binding point
3440 * is not updated and an error will be generated. However, other
3441 * binding points in the same command will be updated if their
3442 * parameters are valid and no other error occurs."
3445 _mesa_begin_bufferobj_lookups(ctx
);
3447 for (i
= 0; i
< count
; i
++) {
3448 struct gl_atomic_buffer_binding
*binding
=
3449 &ctx
->AtomicBufferBindings
[first
+ i
];
3450 struct gl_buffer_object
*bufObj
;
3452 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3453 bufObj
= binding
->BufferObject
;
3455 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3456 "glBindBuffersBase");
3459 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
3462 _mesa_end_bufferobj_lookups(ctx
);
3466 bind_atomic_buffers_range(struct gl_context
*ctx
,
3469 const GLuint
*buffers
,
3470 const GLintptr
*offsets
,
3471 const GLsizeiptr
*sizes
)
3475 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3476 "glBindBuffersRange"))
3479 /* Assume that at least one binding will be changed */
3480 FLUSH_VERTICES(ctx
, 0);
3481 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3484 /* The ARB_multi_bind spec says:
3486 * "If <buffers> is NULL, all bindings from <first> through
3487 * <first>+<count>-1 are reset to their unbound (zero) state.
3488 * In this case, the offsets and sizes associated with the
3489 * binding points are set to default values, ignoring
3490 * <offsets> and <sizes>."
3492 unbind_atomic_buffers(ctx
, first
, count
);
3496 /* Note that the error semantics for multi-bind commands differ from
3497 * those of other GL commands.
3499 * The Issues section in the ARB_multi_bind spec says:
3501 * "(11) Typically, OpenGL specifies that if an error is generated by a
3502 * command, that command has no effect. This is somewhat
3503 * unfortunate for multi-bind commands, because it would require a
3504 * first pass to scan the entire list of bound objects for errors
3505 * and then a second pass to actually perform the bindings.
3506 * Should we have different error semantics?
3508 * RESOLVED: Yes. In this specification, when the parameters for
3509 * one of the <count> binding points are invalid, that binding point
3510 * is not updated and an error will be generated. However, other
3511 * binding points in the same command will be updated if their
3512 * parameters are valid and no other error occurs."
3515 _mesa_begin_bufferobj_lookups(ctx
);
3517 for (i
= 0; i
< count
; i
++) {
3518 struct gl_atomic_buffer_binding
*binding
=
3519 &ctx
->AtomicBufferBindings
[first
+ i
];
3520 struct gl_buffer_object
*bufObj
;
3522 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3525 /* The ARB_multi_bind spec says:
3527 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3528 * pair of values in <offsets> and <sizes> does not respectively
3529 * satisfy the constraints described for those parameters for the
3530 * specified target, as described in section 6.7.1 (per binding)."
3532 * Section 6.7.1 refers to table 6.5, which says:
3534 * "┌───────────────────────────────────────────────────────────────┐
3535 * │ Atomic counter array bindings (see sec. 7.7.2) │
3536 * ├───────────────────────┬───────────────────────────────────────┤
3538 * │ offset restriction │ multiple of 4 │
3540 * │ size restriction │ none │
3541 * └───────────────────────┴───────────────────────────────────────┘"
3543 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
3544 _mesa_error(ctx
, GL_INVALID_VALUE
,
3545 "glBindBuffersRange(offsets[%u]=%" PRId64
3546 " is misaligned; it must be a multiple of %d when "
3547 "target=GL_ATOMIC_COUNTER_BUFFER)",
3548 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
3552 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3553 bufObj
= binding
->BufferObject
;
3555 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3556 "glBindBuffersRange");
3559 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
3562 _mesa_end_bufferobj_lookups(ctx
);
3566 _mesa_BindBufferRange(GLenum target
, GLuint index
,
3567 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
3569 GET_CURRENT_CONTEXT(ctx
);
3570 struct gl_buffer_object
*bufObj
;
3573 bufObj
= ctx
->Shared
->NullBufferObj
;
3575 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3577 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3578 &bufObj
, "glBindBufferRange"))
3582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3583 "glBindBufferRange(invalid buffer=%u)", buffer
);
3589 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
3596 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3597 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
3600 case GL_UNIFORM_BUFFER
:
3601 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
3603 case GL_ATOMIC_COUNTER_BUFFER
:
3604 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
3605 "glBindBufferRange");
3608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
3614 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
3616 GET_CURRENT_CONTEXT(ctx
);
3617 struct gl_buffer_object
*bufObj
;
3620 bufObj
= ctx
->Shared
->NullBufferObj
;
3622 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3624 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3625 &bufObj
, "glBindBufferBase"))
3629 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3630 "glBindBufferBase(invalid buffer=%u)", buffer
);
3634 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
3635 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
3637 * "BindBufferBase is equivalent to calling BindBufferRange with offset
3638 * zero and size equal to the size of buffer."
3640 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
3642 * "If the parameter (starting offset or size) was not specified when the
3643 * buffer object was bound, zero is returned."
3645 * What happens if the size of the buffer changes? Does the size of the
3646 * buffer at the moment glBindBufferBase was called still play a role, like
3647 * the first quote would imply, or is the size meaningless in the
3648 * glBindBufferBase case like the second quote would suggest? The GL 4.1
3649 * core spec page 45 says:
3651 * "It is equivalent to calling BindBufferRange with offset zero, while
3652 * size is determined by the size of the bound buffer at the time the
3655 * My interpretation is that the GL 4.1 spec was a clarification of the
3656 * behavior, not a change. In particular, this choice will only make
3657 * rendering work in cases where it would have had undefined results.
3661 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3662 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
3664 case GL_UNIFORM_BUFFER
:
3665 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
3667 case GL_ATOMIC_COUNTER_BUFFER
:
3668 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
3669 "glBindBufferBase");
3672 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
3678 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
3679 const GLuint
*buffers
,
3680 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3682 GET_CURRENT_CONTEXT(ctx
);
3685 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3686 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3688 case GL_UNIFORM_BUFFER
:
3689 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3691 case GL_ATOMIC_COUNTER_BUFFER
:
3692 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
3696 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
3697 _mesa_lookup_enum_by_nr(target
));
3703 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
3704 const GLuint
*buffers
)
3706 GET_CURRENT_CONTEXT(ctx
);
3709 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3710 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
3712 case GL_UNIFORM_BUFFER
:
3713 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
3715 case GL_ATOMIC_COUNTER_BUFFER
:
3716 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
3719 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
3720 _mesa_lookup_enum_by_nr(target
));
3726 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
3729 GET_CURRENT_CONTEXT(ctx
);
3730 struct gl_buffer_object
*bufObj
;
3731 const GLintptr end
= offset
+ length
;
3733 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3735 _mesa_error(ctx
, GL_INVALID_VALUE
,
3736 "glInvalidateBufferSubData(name = 0x%x) invalid object",
3741 /* The GL_ARB_invalidate_subdata spec says:
3743 * "An INVALID_VALUE error is generated if <offset> or <length> is
3744 * negative, or if <offset> + <length> is greater than the value of
3747 if (end
< 0 || end
> bufObj
->Size
) {
3748 _mesa_error(ctx
, GL_INVALID_VALUE
,
3749 "glInvalidateBufferSubData(invalid offset or length)");
3753 /* The OpenGL 4.4 (Core Profile) spec says:
3755 * "An INVALID_OPERATION error is generated if buffer is currently
3756 * mapped by MapBuffer or if the invalidate range intersects the range
3757 * currently mapped by MapBufferRange, unless it was mapped
3758 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3760 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
3761 bufferobj_range_mapped(bufObj
, offset
, length
)) {
3762 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3763 "glInvalidateBufferSubData(intersection with mapped "
3768 /* We don't actually do anything for this yet. Just return after
3769 * validating the parameters and generating the required errors.
3775 _mesa_InvalidateBufferData(GLuint buffer
)
3777 GET_CURRENT_CONTEXT(ctx
);
3778 struct gl_buffer_object
*bufObj
;
3780 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3782 _mesa_error(ctx
, GL_INVALID_VALUE
,
3783 "glInvalidateBufferData(name = 0x%x) invalid object",
3788 /* The OpenGL 4.4 (Core Profile) spec says:
3790 * "An INVALID_OPERATION error is generated if buffer is currently
3791 * mapped by MapBuffer or if the invalidate range intersects the range
3792 * currently mapped by MapBufferRange, unless it was mapped
3793 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3795 if (_mesa_check_disallowed_mapping(bufObj
)) {
3796 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3797 "glInvalidateBufferData(intersection with mapped "
3802 /* We don't actually do anything for this yet. Just return after
3803 * validating the parameters and generating the required errors.