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
);
1011 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1013 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1018 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1020 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1025 * Look up a buffer object for a multi-bind function.
1027 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1028 * of generating an error if the buffer ID is not zero or the name
1029 * of an existing buffer object.
1031 * If the buffer ID refers to an existing buffer object, a pointer
1032 * to the buffer object is returned. If the ID is zero, a pointer
1033 * to the shared NullBufferObj is returned. If the ID is not zero
1034 * and does not refer to a valid buffer object, this function
1037 * This function assumes that the caller has already locked the
1038 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1040 struct gl_buffer_object
*
1041 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1042 const GLuint
*buffers
,
1043 GLuint index
, const char *caller
)
1045 struct gl_buffer_object
*bufObj
;
1047 if (buffers
[index
] != 0) {
1048 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1050 /* The multi-bind functions don't create the buffer objects
1051 when they don't exist. */
1052 if (bufObj
== &DummyBufferObject
)
1055 bufObj
= ctx
->Shared
->NullBufferObj
;
1058 /* The ARB_multi_bind spec says:
1060 * "An INVALID_OPERATION error is generated if any value
1061 * in <buffers> is not zero or the name of an existing
1062 * buffer object (per binding)."
1064 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1065 "%s(buffers[%u]=%u is not zero or the name "
1066 "of an existing buffer object)",
1067 caller
, index
, buffers
[index
]);
1075 * If *ptr points to obj, set ptr = the Null/default buffer object.
1076 * This is a helper for buffer object deletion.
1077 * The GL spec says that deleting a buffer object causes it to get
1078 * unbound from all arrays in the current context.
1081 unbind(struct gl_context
*ctx
,
1082 struct gl_buffer_object
**ptr
,
1083 struct gl_buffer_object
*obj
)
1086 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1092 * Plug default/fallback buffer object functions into the device
1096 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1098 /* GL_ARB_vertex/pixel_buffer_object */
1099 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1100 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1101 driver
->BufferData
= _mesa_buffer_data
;
1102 driver
->BufferSubData
= _mesa_buffer_subdata
;
1103 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1104 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
1106 /* GL_ARB_clear_buffer_object */
1107 driver
->ClearBufferSubData
= _mesa_buffer_clear_subdata
;
1109 /* GL_ARB_map_buffer_range */
1110 driver
->MapBufferRange
= _mesa_buffer_map_range
;
1111 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
1113 /* GL_ARB_copy_buffer */
1114 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
1119 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1120 struct gl_buffer_object
*bufObj
)
1124 for (i
= 0; i
< MAP_COUNT
; i
++) {
1125 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1126 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1127 assert(bufObj
->Mappings
[i
].Pointer
== NULL
);
1128 bufObj
->Mappings
[i
].AccessFlags
= 0;
1134 /**********************************************************************/
1136 /**********************************************************************/
1139 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1141 GET_CURRENT_CONTEXT(ctx
);
1143 if (MESA_VERBOSE
& VERBOSE_API
)
1144 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1145 _mesa_lookup_enum_by_nr(target
), buffer
);
1147 bind_buffer_object(ctx
, target
, buffer
);
1152 * Delete a set of buffer objects.
1154 * \param n Number of buffer objects to delete.
1155 * \param ids Array of \c n buffer object IDs.
1158 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1160 GET_CURRENT_CONTEXT(ctx
);
1162 FLUSH_VERTICES(ctx
, 0);
1165 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1169 mtx_lock(&ctx
->Shared
->Mutex
);
1171 for (i
= 0; i
< n
; i
++) {
1172 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1174 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1177 assert(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1179 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1181 /* unbind any vertex pointers bound to this buffer */
1182 for (j
= 0; j
< ARRAY_SIZE(vao
->VertexBinding
); j
++) {
1183 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1186 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1187 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1189 if (vao
->IndexBufferObj
== bufObj
) {
1190 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1193 /* unbind ARB_draw_indirect binding point */
1194 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1195 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1198 /* unbind ARB_copy_buffer binding points */
1199 if (ctx
->CopyReadBuffer
== bufObj
) {
1200 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1202 if (ctx
->CopyWriteBuffer
== bufObj
) {
1203 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1206 /* unbind transform feedback binding points */
1207 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1208 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1210 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1211 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1212 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1216 /* unbind UBO binding points */
1217 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1218 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1219 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1223 if (ctx
->UniformBuffer
== bufObj
) {
1224 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1227 /* unbind Atomci Buffer binding points */
1228 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1229 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1230 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1234 if (ctx
->AtomicBuffer
== bufObj
) {
1235 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1238 /* unbind any pixel pack/unpack pointers bound to this buffer */
1239 if (ctx
->Pack
.BufferObj
== bufObj
) {
1240 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1242 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1243 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1246 if (ctx
->Texture
.BufferObject
== bufObj
) {
1247 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1250 if (ctx
->ExternalVirtualMemoryBuffer
== bufObj
) {
1251 _mesa_BindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
, 0);
1254 /* The ID is immediately freed for re-use */
1255 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1256 /* Make sure we do not run into the classic ABA problem on bind.
1257 * We don't want to allow re-binding a buffer object that's been
1258 * "deleted" by glDeleteBuffers().
1260 * The explicit rebinding to the default object in the current context
1261 * prevents the above in the current context, but another context
1262 * sharing the same objects might suffer from this problem.
1263 * The alternative would be to do the hash lookup in any case on bind
1264 * which would introduce more runtime overhead than this.
1266 bufObj
->DeletePending
= GL_TRUE
;
1267 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1271 mtx_unlock(&ctx
->Shared
->Mutex
);
1276 * Generate a set of unique buffer object IDs and store them in \c buffer.
1278 * \param n Number of IDs to generate.
1279 * \param buffer Array of \c n locations to store the IDs.
1282 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
1284 GET_CURRENT_CONTEXT(ctx
);
1288 if (MESA_VERBOSE
& VERBOSE_API
)
1289 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
1292 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
1301 * This must be atomic (generation and allocation of buffer object IDs)
1303 mtx_lock(&ctx
->Shared
->Mutex
);
1305 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1307 /* Insert the ID and pointer to dummy buffer object into hash table */
1308 for (i
= 0; i
< n
; i
++) {
1309 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
1310 &DummyBufferObject
);
1311 buffer
[i
] = first
+ i
;
1314 mtx_unlock(&ctx
->Shared
->Mutex
);
1319 * Determine if ID is the name of a buffer object.
1321 * \param id ID of the potential buffer object.
1322 * \return \c GL_TRUE if \c id is the name of a buffer object,
1323 * \c GL_FALSE otherwise.
1325 GLboolean GLAPIENTRY
1326 _mesa_IsBuffer(GLuint id
)
1328 struct gl_buffer_object
*bufObj
;
1329 GET_CURRENT_CONTEXT(ctx
);
1330 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1332 mtx_lock(&ctx
->Shared
->Mutex
);
1333 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1334 mtx_unlock(&ctx
->Shared
->Mutex
);
1336 return bufObj
&& bufObj
!= &DummyBufferObject
;
1341 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1344 GET_CURRENT_CONTEXT(ctx
);
1345 struct gl_buffer_object
*bufObj
;
1348 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(size <= 0)");
1352 if (flags
& ~(GL_MAP_READ_BIT
|
1354 GL_MAP_PERSISTENT_BIT
|
1355 GL_MAP_COHERENT_BIT
|
1356 GL_DYNAMIC_STORAGE_BIT
|
1357 GL_CLIENT_STORAGE_BIT
)) {
1358 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags)");
1362 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1363 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1364 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=READ/WRITE)");
1368 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1369 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=PERSISTENT)");
1373 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1377 if (bufObj
->Immutable
) {
1378 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage(immutable)");
1382 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1383 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1385 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1387 bufObj
->Written
= GL_TRUE
;
1388 bufObj
->Immutable
= GL_TRUE
;
1390 assert(ctx
->Driver
.BufferData
);
1391 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1393 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1394 /* Even though the interaction between AMD_pinned_memory and
1395 * glBufferStorage is not described in the spec, Graham Sellers
1396 * said that it should behave the same as glBufferData.
1398 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage()");
1401 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferStorage()");
1408 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1409 const GLvoid
* data
, GLenum usage
)
1411 GET_CURRENT_CONTEXT(ctx
);
1412 struct gl_buffer_object
*bufObj
;
1415 if (MESA_VERBOSE
& VERBOSE_API
)
1416 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1417 _mesa_lookup_enum_by_nr(target
),
1418 (long int) size
, data
,
1419 _mesa_lookup_enum_by_nr(usage
));
1422 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1427 case GL_STREAM_DRAW_ARB
:
1428 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1431 case GL_STATIC_DRAW_ARB
:
1432 case GL_DYNAMIC_DRAW_ARB
:
1436 case GL_STREAM_READ_ARB
:
1437 case GL_STREAM_COPY_ARB
:
1438 case GL_STATIC_READ_ARB
:
1439 case GL_STATIC_COPY_ARB
:
1440 case GL_DYNAMIC_READ_ARB
:
1441 case GL_DYNAMIC_COPY_ARB
:
1442 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1446 valid_usage
= false;
1451 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1455 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
, GL_INVALID_OPERATION
);
1459 if (bufObj
->Immutable
) {
1460 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData(immutable)");
1464 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1465 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1467 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1469 bufObj
->Written
= GL_TRUE
;
1472 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1473 bufObj
->Name
, size
, data
, usage
);
1480 assert(ctx
->Driver
.BufferData
);
1481 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1484 GL_DYNAMIC_STORAGE_BIT
,
1486 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1487 /* From GL_AMD_pinned_memory:
1489 * INVALID_OPERATION is generated by BufferData if <target> is
1490 * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
1491 * mapped to the GPU address space.
1493 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData()");
1496 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferData()");
1503 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1504 GLsizeiptrARB size
, const GLvoid
* data
)
1506 GET_CURRENT_CONTEXT(ctx
);
1507 struct gl_buffer_object
*bufObj
;
1509 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1510 false, GL_INVALID_OPERATION
,
1511 "glBufferSubDataARB" );
1513 /* error already recorded */
1517 if (bufObj
->Immutable
&&
1518 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1519 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubData");
1526 bufObj
->Written
= GL_TRUE
;
1528 assert(ctx
->Driver
.BufferSubData
);
1529 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1534 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1535 GLsizeiptrARB size
, void * data
)
1537 GET_CURRENT_CONTEXT(ctx
);
1538 struct gl_buffer_object
*bufObj
;
1540 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1541 false, GL_INVALID_OPERATION
,
1542 "glGetBufferSubDataARB");
1544 /* error already recorded */
1548 assert(ctx
->Driver
.GetBufferSubData
);
1549 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1554 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1555 GLenum type
, const GLvoid
* data
)
1557 GET_CURRENT_CONTEXT(ctx
);
1558 struct gl_buffer_object
* bufObj
;
1559 mesa_format mesaFormat
;
1560 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1561 GLsizeiptr clearValueSize
;
1563 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1568 if (_mesa_check_disallowed_mapping(bufObj
)) {
1569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1570 "glClearBufferData(buffer currently mapped)");
1574 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1576 "glClearBufferData");
1577 if (mesaFormat
== MESA_FORMAT_NONE
) {
1581 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1582 if (bufObj
->Size
% clearValueSize
!= 0) {
1583 _mesa_error(ctx
, GL_INVALID_VALUE
,
1584 "glClearBufferData(size is not a multiple of "
1585 "internalformat size)");
1590 /* clear to zeros, per the spec */
1591 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1592 NULL
, clearValueSize
, bufObj
);
1596 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1597 format
, type
, data
, "glClearBufferData")) {
1601 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1602 clearValue
, clearValueSize
, bufObj
);
1607 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1608 GLintptr offset
, GLsizeiptr size
,
1609 GLenum format
, GLenum type
,
1612 GET_CURRENT_CONTEXT(ctx
);
1613 struct gl_buffer_object
* bufObj
;
1614 mesa_format mesaFormat
;
1615 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1616 GLsizeiptr clearValueSize
;
1618 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1619 true, GL_INVALID_VALUE
,
1620 "glClearBufferSubData");
1625 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1627 "glClearBufferSubData");
1628 if (mesaFormat
== MESA_FORMAT_NONE
) {
1632 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1633 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1634 _mesa_error(ctx
, GL_INVALID_VALUE
,
1635 "glClearBufferSubData(offset or size is not a multiple of "
1636 "internalformat size)");
1641 /* clear to zeros, per the spec */
1643 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1644 NULL
, clearValueSize
, bufObj
);
1649 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1651 "glClearBufferSubData")) {
1656 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1657 clearValue
, clearValueSize
, bufObj
);
1663 _mesa_MapBuffer(GLenum target
, GLenum access
)
1665 GET_CURRENT_CONTEXT(ctx
);
1666 struct gl_buffer_object
* bufObj
;
1667 GLbitfield accessFlags
;
1671 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1674 case GL_READ_ONLY_ARB
:
1675 accessFlags
= GL_MAP_READ_BIT
;
1676 valid_access
= _mesa_is_desktop_gl(ctx
);
1678 case GL_WRITE_ONLY_ARB
:
1679 accessFlags
= GL_MAP_WRITE_BIT
;
1680 valid_access
= true;
1682 case GL_READ_WRITE_ARB
:
1683 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1684 valid_access
= _mesa_is_desktop_gl(ctx
);
1687 valid_access
= false;
1691 if (!valid_access
) {
1692 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1696 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
, GL_INVALID_OPERATION
);
1700 if (accessFlags
& GL_MAP_READ_BIT
&&
1701 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
1702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1703 "glMapBuffer(invalid read flag)");
1707 if (accessFlags
& GL_MAP_WRITE_BIT
&&
1708 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "glMapBuffer(invalid write flag)");
1714 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1715 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1719 if (!bufObj
->Size
) {
1720 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1721 "glMapBuffer(buffer size = 0)");
1725 assert(ctx
->Driver
.MapBufferRange
);
1726 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
,
1729 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1733 /* The driver callback should have set these fields.
1734 * This is important because other modules (like VBO) might call
1735 * the driver function directly.
1737 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
1738 assert(bufObj
->Mappings
[MAP_USER
].Length
== bufObj
->Size
);
1739 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1740 bufObj
->Mappings
[MAP_USER
].AccessFlags
= accessFlags
;
1743 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1744 bufObj
->Written
= GL_TRUE
;
1747 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1748 bufObj
->Name
, bufObj
->Size
, access
);
1749 if (access
== GL_WRITE_ONLY_ARB
) {
1751 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1752 for (i
= 0; i
< bufObj
->Size
; i
++)
1759 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1761 /* buffer is 100 bytes larger than requested, fill with magic value */
1762 for (i
= 0; i
< 100; i
++) {
1763 buf
[bufObj
->Size
- i
- 1] = 123;
1768 return bufObj
->Mappings
[MAP_USER
].Pointer
;
1772 GLboolean GLAPIENTRY
1773 _mesa_UnmapBuffer(GLenum target
)
1775 GET_CURRENT_CONTEXT(ctx
);
1776 struct gl_buffer_object
*bufObj
;
1777 GLboolean status
= GL_TRUE
;
1778 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1780 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
, GL_INVALID_OPERATION
);
1784 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1785 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1790 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1791 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1793 /* check that last 100 bytes are still = magic value */
1794 for (i
= 0; i
< 100; i
++) {
1795 GLuint pos
= bufObj
->Size
- i
- 1;
1796 if (buf
[pos
] != 123) {
1797 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1798 " at position %d (value = %u)\n",
1806 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1807 GLuint i
, unchanged
= 0;
1808 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1810 /* check which bytes changed */
1811 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1812 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1819 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1820 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1825 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1826 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1827 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1828 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1829 assert(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1836 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1838 GET_CURRENT_CONTEXT(ctx
);
1839 struct gl_buffer_object
*bufObj
;
1841 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
,
1842 GL_INVALID_OPERATION
);
1847 case GL_BUFFER_SIZE_ARB
:
1848 *params
= (GLint
) bufObj
->Size
;
1850 case GL_BUFFER_USAGE_ARB
:
1851 *params
= bufObj
->Usage
;
1853 case GL_BUFFER_ACCESS_ARB
:
1854 *params
= simplified_access_mode(ctx
,
1855 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1857 case GL_BUFFER_MAPPED_ARB
:
1858 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1860 case GL_BUFFER_ACCESS_FLAGS
:
1861 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1863 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1865 case GL_BUFFER_MAP_OFFSET
:
1866 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1868 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Offset
;
1870 case GL_BUFFER_MAP_LENGTH
:
1871 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1873 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Length
;
1875 case GL_BUFFER_IMMUTABLE_STORAGE
:
1876 if (!ctx
->Extensions
.ARB_buffer_storage
)
1878 *params
= bufObj
->Immutable
;
1880 case GL_BUFFER_STORAGE_FLAGS
:
1881 if (!ctx
->Extensions
.ARB_buffer_storage
)
1883 *params
= bufObj
->StorageFlags
;
1886 ; /* fall-through */
1890 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1891 _mesa_lookup_enum_by_nr(pname
));
1897 * This is pretty much a duplicate of GetBufferParameteriv() but the
1898 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1901 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1903 GET_CURRENT_CONTEXT(ctx
);
1904 struct gl_buffer_object
*bufObj
;
1906 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
1907 GL_INVALID_OPERATION
);
1912 case GL_BUFFER_SIZE_ARB
:
1913 *params
= bufObj
->Size
;
1915 case GL_BUFFER_USAGE_ARB
:
1916 *params
= bufObj
->Usage
;
1918 case GL_BUFFER_ACCESS_ARB
:
1919 *params
= simplified_access_mode(ctx
,
1920 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1922 case GL_BUFFER_ACCESS_FLAGS
:
1923 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1925 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1927 case GL_BUFFER_MAPPED_ARB
:
1928 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1930 case GL_BUFFER_MAP_OFFSET
:
1931 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1933 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
1935 case GL_BUFFER_MAP_LENGTH
:
1936 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1938 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
1940 case GL_BUFFER_IMMUTABLE_STORAGE
:
1941 if (!ctx
->Extensions
.ARB_buffer_storage
)
1943 *params
= bufObj
->Immutable
;
1945 case GL_BUFFER_STORAGE_FLAGS
:
1946 if (!ctx
->Extensions
.ARB_buffer_storage
)
1948 *params
= bufObj
->StorageFlags
;
1951 ; /* fall-through */
1955 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1956 _mesa_lookup_enum_by_nr(pname
));
1961 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1963 GET_CURRENT_CONTEXT(ctx
);
1964 struct gl_buffer_object
* bufObj
;
1966 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1967 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1971 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
,
1972 GL_INVALID_OPERATION
);
1976 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
1981 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1982 GLintptr readOffset
, GLintptr writeOffset
,
1985 GET_CURRENT_CONTEXT(ctx
);
1986 struct gl_buffer_object
*src
, *dst
;
1988 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
1989 GL_INVALID_OPERATION
);
1993 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
1994 GL_INVALID_OPERATION
);
1998 if (_mesa_check_disallowed_mapping(src
)) {
1999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2000 "glCopyBufferSubData(readBuffer is mapped)");
2004 if (_mesa_check_disallowed_mapping(dst
)) {
2005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2006 "glCopyBufferSubData(writeBuffer is mapped)");
2010 if (readOffset
< 0) {
2011 _mesa_error(ctx
, GL_INVALID_VALUE
,
2012 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
2016 if (writeOffset
< 0) {
2017 _mesa_error(ctx
, GL_INVALID_VALUE
,
2018 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
2023 _mesa_error(ctx
, GL_INVALID_VALUE
,
2024 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
2028 if (readOffset
+ size
> src
->Size
) {
2029 _mesa_error(ctx
, GL_INVALID_VALUE
,
2030 "glCopyBufferSubData(readOffset + size = %d)",
2031 (int) (readOffset
+ size
));
2035 if (writeOffset
+ size
> dst
->Size
) {
2036 _mesa_error(ctx
, GL_INVALID_VALUE
,
2037 "glCopyBufferSubData(writeOffset + size = %d)",
2038 (int) (writeOffset
+ size
));
2043 if (readOffset
+ size
<= writeOffset
) {
2046 else if (writeOffset
+ size
<= readOffset
) {
2050 /* overlapping src/dst is illegal */
2051 _mesa_error(ctx
, GL_INVALID_VALUE
,
2052 "glCopyBufferSubData(overlapping src/dst)");
2057 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2062 * See GL_ARB_map_buffer_range spec
2065 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2068 GET_CURRENT_CONTEXT(ctx
);
2069 struct gl_buffer_object
*bufObj
;
2071 GLbitfield allowed_access
;
2073 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2075 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2076 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2077 "glMapBufferRange(extension not supported)");
2082 _mesa_error(ctx
, GL_INVALID_VALUE
,
2083 "glMapBufferRange(offset = %ld)", (long)offset
);
2088 _mesa_error(ctx
, GL_INVALID_VALUE
,
2089 "glMapBufferRange(length = %ld)", (long)length
);
2093 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2095 * "An INVALID_OPERATION error is generated for any of the following
2098 * * <length> is zero."
2100 if (_mesa_is_gles(ctx
) && length
== 0) {
2101 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2102 "glMapBufferRange(length = 0)");
2106 allowed_access
= GL_MAP_READ_BIT
|
2108 GL_MAP_INVALIDATE_RANGE_BIT
|
2109 GL_MAP_INVALIDATE_BUFFER_BIT
|
2110 GL_MAP_FLUSH_EXPLICIT_BIT
|
2111 GL_MAP_UNSYNCHRONIZED_BIT
;
2113 if (ctx
->Extensions
.ARB_buffer_storage
) {
2114 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2115 GL_MAP_COHERENT_BIT
;
2118 if (access
& ~allowed_access
) {
2119 /* generate an error if any other than allowed bit is set */
2120 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
2124 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2125 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2126 "glMapBufferRange(access indicates neither read or write)");
2130 if ((access
& GL_MAP_READ_BIT
) &&
2131 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2132 GL_MAP_INVALIDATE_BUFFER_BIT
|
2133 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2134 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2135 "glMapBufferRange(invalid access flags)");
2139 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2140 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2141 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2142 "glMapBufferRange(invalid access flags)");
2146 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2150 if (access
& GL_MAP_READ_BIT
&&
2151 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2152 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2153 "glMapBufferRange(invalid read flag)");
2157 if (access
& GL_MAP_WRITE_BIT
&&
2158 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2160 "glMapBufferRange(invalid write flag)");
2164 if (access
& GL_MAP_COHERENT_BIT
&&
2165 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2166 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2167 "glMapBufferRange(invalid coherent flag)");
2171 if (access
& GL_MAP_PERSISTENT_BIT
&&
2172 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2174 "glMapBufferRange(invalid persistent flag)");
2178 if (offset
+ length
> bufObj
->Size
) {
2179 _mesa_error(ctx
, GL_INVALID_VALUE
,
2180 "glMapBufferRange(offset + length > size)");
2184 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2185 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2186 "glMapBufferRange(buffer already mapped)");
2190 if (!bufObj
->Size
) {
2191 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2192 "glMapBufferRange(buffer size = 0)");
2196 /* Mapping zero bytes should return a non-null pointer. */
2198 static long dummy
= 0;
2199 bufObj
->Mappings
[MAP_USER
].Pointer
= &dummy
;
2200 bufObj
->Mappings
[MAP_USER
].Length
= length
;
2201 bufObj
->Mappings
[MAP_USER
].Offset
= offset
;
2202 bufObj
->Mappings
[MAP_USER
].AccessFlags
= access
;
2203 return bufObj
->Mappings
[MAP_USER
].Pointer
;
2206 assert(ctx
->Driver
.MapBufferRange
);
2207 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2210 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
2213 /* The driver callback should have set all these fields.
2214 * This is important because other modules (like VBO) might call
2215 * the driver function directly.
2217 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2218 assert(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2219 assert(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2220 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2228 * See GL_ARB_map_buffer_range spec
2231 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
2233 GET_CURRENT_CONTEXT(ctx
);
2234 struct gl_buffer_object
*bufObj
;
2236 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2238 "glFlushMappedBufferRange(extension not supported)");
2243 _mesa_error(ctx
, GL_INVALID_VALUE
,
2244 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
2249 _mesa_error(ctx
, GL_INVALID_VALUE
,
2250 "glFlushMappedBufferRange(length = %ld)", (long)length
);
2254 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2255 GL_INVALID_OPERATION
);
2259 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2260 /* buffer is not mapped */
2261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2262 "glFlushMappedBufferRange(buffer is not mapped)");
2266 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2267 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2268 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2269 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
2273 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2274 _mesa_error(ctx
, GL_INVALID_VALUE
,
2275 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
2276 (long)offset
, (long)length
,
2277 (long)bufObj
->Mappings
[MAP_USER
].Length
);
2281 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2283 if (ctx
->Driver
.FlushMappedBufferRange
)
2284 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2290 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2292 struct gl_buffer_object
*bufObj
;
2295 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2297 _mesa_error(ctx
, GL_INVALID_VALUE
,
2298 "glObjectPurgeable(name = 0x%x)", name
);
2301 if (!_mesa_is_bufferobj(bufObj
)) {
2302 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2306 if (bufObj
->Purgeable
) {
2307 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2308 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2309 return GL_VOLATILE_APPLE
;
2312 bufObj
->Purgeable
= GL_TRUE
;
2314 retval
= GL_VOLATILE_APPLE
;
2315 if (ctx
->Driver
.BufferObjectPurgeable
)
2316 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2323 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2325 struct gl_renderbuffer
*bufObj
;
2328 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2330 _mesa_error(ctx
, GL_INVALID_VALUE
,
2331 "glObjectUnpurgeable(name = 0x%x)", name
);
2335 if (bufObj
->Purgeable
) {
2336 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2337 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2338 return GL_VOLATILE_APPLE
;
2341 bufObj
->Purgeable
= GL_TRUE
;
2343 retval
= GL_VOLATILE_APPLE
;
2344 if (ctx
->Driver
.RenderObjectPurgeable
)
2345 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2352 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2354 struct gl_texture_object
*bufObj
;
2357 bufObj
= _mesa_lookup_texture(ctx
, name
);
2359 _mesa_error(ctx
, GL_INVALID_VALUE
,
2360 "glObjectPurgeable(name = 0x%x)", name
);
2364 if (bufObj
->Purgeable
) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2366 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2367 return GL_VOLATILE_APPLE
;
2370 bufObj
->Purgeable
= GL_TRUE
;
2372 retval
= GL_VOLATILE_APPLE
;
2373 if (ctx
->Driver
.TextureObjectPurgeable
)
2374 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2381 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2385 GET_CURRENT_CONTEXT(ctx
);
2386 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2389 _mesa_error(ctx
, GL_INVALID_VALUE
,
2390 "glObjectPurgeable(name = 0x%x)", name
);
2395 case GL_VOLATILE_APPLE
:
2396 case GL_RELEASED_APPLE
:
2400 _mesa_error(ctx
, GL_INVALID_ENUM
,
2401 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2406 switch (objectType
) {
2408 retval
= texture_object_purgeable(ctx
, name
, option
);
2410 case GL_RENDERBUFFER_EXT
:
2411 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2413 case GL_BUFFER_OBJECT_APPLE
:
2414 retval
= buffer_object_purgeable(ctx
, name
, option
);
2417 _mesa_error(ctx
, GL_INVALID_ENUM
,
2418 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2423 /* In strict conformance to the spec, we must only return VOLATILE when
2424 * when passed the VOLATILE option. Madness.
2426 * XXX First fix the spec, then fix me.
2428 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2433 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2435 struct gl_buffer_object
*bufObj
;
2438 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2440 _mesa_error(ctx
, GL_INVALID_VALUE
,
2441 "glObjectUnpurgeable(name = 0x%x)", name
);
2445 if (! bufObj
->Purgeable
) {
2446 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2447 "glObjectUnpurgeable(name = 0x%x) object is "
2448 " already \"unpurged\"", name
);
2452 bufObj
->Purgeable
= GL_FALSE
;
2455 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2456 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2463 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2465 struct gl_renderbuffer
*bufObj
;
2468 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2470 _mesa_error(ctx
, GL_INVALID_VALUE
,
2471 "glObjectUnpurgeable(name = 0x%x)", name
);
2475 if (! bufObj
->Purgeable
) {
2476 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2477 "glObjectUnpurgeable(name = 0x%x) object is "
2478 " already \"unpurged\"", name
);
2482 bufObj
->Purgeable
= GL_FALSE
;
2485 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2486 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2493 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2495 struct gl_texture_object
*bufObj
;
2498 bufObj
= _mesa_lookup_texture(ctx
, name
);
2500 _mesa_error(ctx
, GL_INVALID_VALUE
,
2501 "glObjectUnpurgeable(name = 0x%x)", name
);
2505 if (! bufObj
->Purgeable
) {
2506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2507 "glObjectUnpurgeable(name = 0x%x) object is"
2508 " already \"unpurged\"", name
);
2512 bufObj
->Purgeable
= GL_FALSE
;
2515 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2516 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2523 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2525 GET_CURRENT_CONTEXT(ctx
);
2526 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2529 _mesa_error(ctx
, GL_INVALID_VALUE
,
2530 "glObjectUnpurgeable(name = 0x%x)", name
);
2535 case GL_RETAINED_APPLE
:
2536 case GL_UNDEFINED_APPLE
:
2540 _mesa_error(ctx
, GL_INVALID_ENUM
,
2541 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2546 switch (objectType
) {
2547 case GL_BUFFER_OBJECT_APPLE
:
2548 return buffer_object_unpurgeable(ctx
, name
, option
);
2550 return texture_object_unpurgeable(ctx
, name
, option
);
2551 case GL_RENDERBUFFER_EXT
:
2552 return renderbuffer_unpurgeable(ctx
, name
, option
);
2554 _mesa_error(ctx
, GL_INVALID_ENUM
,
2555 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2563 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2564 GLenum pname
, GLint
*params
)
2566 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2568 _mesa_error(ctx
, GL_INVALID_VALUE
,
2569 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2574 case GL_PURGEABLE_APPLE
:
2575 *params
= bufObj
->Purgeable
;
2578 _mesa_error(ctx
, GL_INVALID_ENUM
,
2579 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2587 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2588 GLenum pname
, GLint
*params
)
2590 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2592 _mesa_error(ctx
, GL_INVALID_VALUE
,
2593 "glObjectUnpurgeable(name = 0x%x)", name
);
2598 case GL_PURGEABLE_APPLE
:
2599 *params
= rb
->Purgeable
;
2602 _mesa_error(ctx
, GL_INVALID_ENUM
,
2603 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2611 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2612 GLenum pname
, GLint
*params
)
2614 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2616 _mesa_error(ctx
, GL_INVALID_VALUE
,
2617 "glObjectUnpurgeable(name = 0x%x)", name
);
2622 case GL_PURGEABLE_APPLE
:
2623 *params
= texObj
->Purgeable
;
2626 _mesa_error(ctx
, GL_INVALID_ENUM
,
2627 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2635 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2638 GET_CURRENT_CONTEXT(ctx
);
2641 _mesa_error(ctx
, GL_INVALID_VALUE
,
2642 "glGetObjectParameteriv(name = 0x%x)", name
);
2646 switch (objectType
) {
2648 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2650 case GL_BUFFER_OBJECT_APPLE
:
2651 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2653 case GL_RENDERBUFFER_EXT
:
2654 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2657 _mesa_error(ctx
, GL_INVALID_ENUM
,
2658 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2664 * Binds a buffer object to a uniform buffer binding point.
2666 * The caller is responsible for flushing vertices and updating
2670 set_ubo_binding(struct gl_context
*ctx
,
2671 struct gl_uniform_buffer_binding
*binding
,
2672 struct gl_buffer_object
*bufObj
,
2677 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2679 binding
->Offset
= offset
;
2680 binding
->Size
= size
;
2681 binding
->AutomaticSize
= autoSize
;
2683 /* If this is a real buffer object, mark it has having been used
2684 * at some point as a UBO.
2687 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
2691 * Binds a buffer object to a uniform buffer binding point.
2693 * Unlike set_ubo_binding(), this function also flushes vertices
2694 * and updates NewDriverState. It also checks if the binding
2695 * has actually changed before updating it.
2698 bind_uniform_buffer(struct gl_context
*ctx
,
2700 struct gl_buffer_object
*bufObj
,
2705 struct gl_uniform_buffer_binding
*binding
=
2706 &ctx
->UniformBufferBindings
[index
];
2708 if (binding
->BufferObject
== bufObj
&&
2709 binding
->Offset
== offset
&&
2710 binding
->Size
== size
&&
2711 binding
->AutomaticSize
== autoSize
) {
2715 FLUSH_VERTICES(ctx
, 0);
2716 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2718 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
2722 * Bind a region of a buffer object to a uniform block binding point.
2723 * \param index the uniform buffer binding point index
2724 * \param bufObj the buffer object
2725 * \param offset offset to the start of buffer object region
2726 * \param size size of the buffer object region
2729 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2731 struct gl_buffer_object
*bufObj
,
2735 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2736 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2740 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2741 _mesa_error(ctx
, GL_INVALID_VALUE
,
2742 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
2743 ctx
->Const
.UniformBufferOffsetAlignment
);
2747 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2752 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2753 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2758 * Bind a buffer object to a uniform block binding point.
2759 * As above, but offset = 0.
2762 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2764 struct gl_buffer_object
*bufObj
)
2766 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2767 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2771 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2773 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2774 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2776 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2780 * Binds a buffer object to an atomic buffer binding point.
2782 * The caller is responsible for validating the offset,
2783 * flushing the vertices and updating NewDriverState.
2786 set_atomic_buffer_binding(struct gl_context
*ctx
,
2787 struct gl_atomic_buffer_binding
*binding
,
2788 struct gl_buffer_object
*bufObj
,
2792 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2794 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2795 binding
->Offset
= -1;
2798 binding
->Offset
= offset
;
2799 binding
->Size
= size
;
2800 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
2805 * Binds a buffer object to an atomic buffer binding point.
2807 * Unlike set_atomic_buffer_binding(), this function also validates the
2808 * index and offset, flushes vertices, and updates NewDriverState.
2809 * It also checks if the binding has actually changing before
2813 bind_atomic_buffer(struct gl_context
*ctx
,
2815 struct gl_buffer_object
*bufObj
,
2820 struct gl_atomic_buffer_binding
*binding
;
2822 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2823 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2827 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2828 _mesa_error(ctx
, GL_INVALID_VALUE
,
2829 "%s(offset misaligned %d/%d)", name
, (int) offset
,
2830 ATOMIC_COUNTER_SIZE
);
2834 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2836 binding
= &ctx
->AtomicBufferBindings
[index
];
2837 if (binding
->BufferObject
== bufObj
&&
2838 binding
->Offset
== offset
&&
2839 binding
->Size
== size
) {
2843 FLUSH_VERTICES(ctx
, 0);
2844 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2846 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
2850 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
2852 const GLintptr
*offsets
,
2853 const GLsizeiptr
*sizes
)
2855 if (offsets
[index
] < 0) {
2856 /* The ARB_multi_bind spec says:
2858 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2859 * value in <offsets> is less than zero (per binding)."
2861 _mesa_error(ctx
, GL_INVALID_VALUE
,
2862 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
2863 index
, (int64_t) offsets
[index
]);
2867 if (sizes
[index
] <= 0) {
2868 /* The ARB_multi_bind spec says:
2870 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2871 * value in <sizes> is less than or equal to zero (per binding)."
2873 _mesa_error(ctx
, GL_INVALID_VALUE
,
2874 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
2875 index
, (int64_t) sizes
[index
]);
2883 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
2884 GLuint first
, GLsizei count
,
2887 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
2888 _mesa_error(ctx
, GL_INVALID_ENUM
,
2889 "%s(target=GL_UNIFORM_BUFFER)", caller
);
2893 /* The ARB_multi_bind_spec says:
2895 * "An INVALID_OPERATION error is generated if <first> + <count> is
2896 * greater than the number of target-specific indexed binding points,
2897 * as described in section 6.7.1."
2899 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
2900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2901 "%s(first=%u + count=%d > the value of "
2902 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
2903 caller
, first
, count
,
2904 ctx
->Const
.MaxUniformBufferBindings
);
2912 * Unbind all uniform buffers in the range
2913 * <first> through <first>+<count>-1
2916 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
2918 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
2921 for (i
= 0; i
< count
; i
++)
2922 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
2923 bufObj
, -1, -1, GL_TRUE
);
2927 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2928 const GLuint
*buffers
)
2932 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
2935 /* Assume that at least one binding will be changed */
2936 FLUSH_VERTICES(ctx
, 0);
2937 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2940 /* The ARB_multi_bind spec says:
2942 * "If <buffers> is NULL, all bindings from <first> through
2943 * <first>+<count>-1 are reset to their unbound (zero) state."
2945 unbind_uniform_buffers(ctx
, first
, count
);
2949 /* Note that the error semantics for multi-bind commands differ from
2950 * those of other GL commands.
2952 * The Issues section in the ARB_multi_bind spec says:
2954 * "(11) Typically, OpenGL specifies that if an error is generated by a
2955 * command, that command has no effect. This is somewhat
2956 * unfortunate for multi-bind commands, because it would require a
2957 * first pass to scan the entire list of bound objects for errors
2958 * and then a second pass to actually perform the bindings.
2959 * Should we have different error semantics?
2961 * RESOLVED: Yes. In this specification, when the parameters for
2962 * one of the <count> binding points are invalid, that binding point
2963 * is not updated and an error will be generated. However, other
2964 * binding points in the same command will be updated if their
2965 * parameters are valid and no other error occurs."
2968 _mesa_begin_bufferobj_lookups(ctx
);
2970 for (i
= 0; i
< count
; i
++) {
2971 struct gl_uniform_buffer_binding
*binding
=
2972 &ctx
->UniformBufferBindings
[first
+ i
];
2973 struct gl_buffer_object
*bufObj
;
2975 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
2976 bufObj
= binding
->BufferObject
;
2978 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
2979 "glBindBuffersBase");
2982 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2983 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
2985 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
2989 _mesa_end_bufferobj_lookups(ctx
);
2993 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2994 const GLuint
*buffers
,
2995 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
2999 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
3000 "glBindBuffersRange"))
3003 /* Assume that at least one binding will be changed */
3004 FLUSH_VERTICES(ctx
, 0);
3005 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3008 /* The ARB_multi_bind spec says:
3010 * "If <buffers> is NULL, all bindings from <first> through
3011 * <first>+<count>-1 are reset to their unbound (zero) state.
3012 * In this case, the offsets and sizes associated with the
3013 * binding points are set to default values, ignoring
3014 * <offsets> and <sizes>."
3016 unbind_uniform_buffers(ctx
, first
, count
);
3020 /* Note that the error semantics for multi-bind commands differ from
3021 * those of other GL commands.
3023 * The Issues section in the ARB_multi_bind spec says:
3025 * "(11) Typically, OpenGL specifies that if an error is generated by a
3026 * command, that command has no effect. This is somewhat
3027 * unfortunate for multi-bind commands, because it would require a
3028 * first pass to scan the entire list of bound objects for errors
3029 * and then a second pass to actually perform the bindings.
3030 * Should we have different error semantics?
3032 * RESOLVED: Yes. In this specification, when the parameters for
3033 * one of the <count> binding points are invalid, that binding point
3034 * is not updated and an error will be generated. However, other
3035 * binding points in the same command will be updated if their
3036 * parameters are valid and no other error occurs."
3039 _mesa_begin_bufferobj_lookups(ctx
);
3041 for (i
= 0; i
< count
; i
++) {
3042 struct gl_uniform_buffer_binding
*binding
=
3043 &ctx
->UniformBufferBindings
[first
+ i
];
3044 struct gl_buffer_object
*bufObj
;
3046 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3049 /* The ARB_multi_bind spec says:
3051 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3052 * pair of values in <offsets> and <sizes> does not respectively
3053 * satisfy the constraints described for those parameters for the
3054 * specified target, as described in section 6.7.1 (per binding)."
3056 * Section 6.7.1 refers to table 6.5, which says:
3058 * "┌───────────────────────────────────────────────────────────────┐
3059 * │ Uniform buffer array bindings (see sec. 7.6) │
3060 * ├─────────────────────┬─────────────────────────────────────────┤
3062 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3063 * │ │ OFFSET_ALIGNMENT │
3065 * │ size restriction │ none │
3066 * └─────────────────────┴─────────────────────────────────────────┘"
3068 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3069 _mesa_error(ctx
, GL_INVALID_VALUE
,
3070 "glBindBuffersRange(offsets[%u]=%" PRId64
3071 " is misaligned; it must be a multiple of the value of "
3072 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3073 "target=GL_UNIFORM_BUFFER)",
3074 i
, (int64_t) offsets
[i
],
3075 ctx
->Const
.UniformBufferOffsetAlignment
);
3079 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3080 bufObj
= binding
->BufferObject
;
3082 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3083 "glBindBuffersRange");
3086 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3087 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3089 set_ubo_binding(ctx
, binding
, bufObj
,
3090 offsets
[i
], sizes
[i
], GL_FALSE
);
3094 _mesa_end_bufferobj_lookups(ctx
);
3098 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3099 struct gl_transform_feedback_object
*tfObj
,
3100 GLuint first
, GLsizei count
, const char *caller
)
3102 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3103 _mesa_error(ctx
, GL_INVALID_ENUM
,
3104 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3108 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3110 * "An INVALID_OPERATION error is generated :
3113 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3114 * FEEDBACK_BUFFER and transform feedback is currently active."
3116 * We assume that this is also meant to apply to BindBuffersRange
3117 * and BindBuffersBase.
3119 if (tfObj
->Active
) {
3120 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3121 "%s(Changing transform feedback buffers while "
3122 "transform feedback is active)", caller
);
3126 /* The ARB_multi_bind_spec says:
3128 * "An INVALID_OPERATION error is generated if <first> + <count> is
3129 * greater than the number of target-specific indexed binding points,
3130 * as described in section 6.7.1."
3132 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3133 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3134 "%s(first=%u + count=%d > the value of "
3135 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3136 caller
, first
, count
,
3137 ctx
->Const
.MaxTransformFeedbackBuffers
);
3145 * Unbind all transform feedback buffers in the range
3146 * <first> through <first>+<count>-1
3149 unbind_xfb_buffers(struct gl_context
*ctx
,
3150 struct gl_transform_feedback_object
*tfObj
,
3151 GLuint first
, GLsizei count
)
3153 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3156 for (i
= 0; i
< count
; i
++)
3157 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3162 bind_xfb_buffers_base(struct gl_context
*ctx
,
3163 GLuint first
, GLsizei count
,
3164 const GLuint
*buffers
)
3166 struct gl_transform_feedback_object
*tfObj
=
3167 ctx
->TransformFeedback
.CurrentObject
;
3170 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3171 "glBindBuffersBase"))
3174 /* Assume that at least one binding will be changed */
3175 FLUSH_VERTICES(ctx
, 0);
3176 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3179 /* The ARB_multi_bind spec says:
3181 * "If <buffers> is NULL, all bindings from <first> through
3182 * <first>+<count>-1 are reset to their unbound (zero) state."
3184 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3188 /* Note that the error semantics for multi-bind commands differ from
3189 * those of other GL commands.
3191 * The Issues section in the ARB_multi_bind spec says:
3193 * "(11) Typically, OpenGL specifies that if an error is generated by a
3194 * command, that command has no effect. This is somewhat
3195 * unfortunate for multi-bind commands, because it would require a
3196 * first pass to scan the entire list of bound objects for errors
3197 * and then a second pass to actually perform the bindings.
3198 * Should we have different error semantics?
3200 * RESOLVED: Yes. In this specification, when the parameters for
3201 * one of the <count> binding points are invalid, that binding point
3202 * is not updated and an error will be generated. However, other
3203 * binding points in the same command will be updated if their
3204 * parameters are valid and no other error occurs."
3207 _mesa_begin_bufferobj_lookups(ctx
);
3209 for (i
= 0; i
< count
; i
++) {
3210 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3211 struct gl_buffer_object
*bufObj
;
3213 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3214 bufObj
= boundBufObj
;
3216 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3217 "glBindBuffersBase");
3220 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3224 _mesa_end_bufferobj_lookups(ctx
);
3228 bind_xfb_buffers_range(struct gl_context
*ctx
,
3229 GLuint first
, GLsizei count
,
3230 const GLuint
*buffers
,
3231 const GLintptr
*offsets
,
3232 const GLsizeiptr
*sizes
)
3234 struct gl_transform_feedback_object
*tfObj
=
3235 ctx
->TransformFeedback
.CurrentObject
;
3238 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3239 "glBindBuffersRange"))
3242 /* Assume that at least one binding will be changed */
3243 FLUSH_VERTICES(ctx
, 0);
3244 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3247 /* The ARB_multi_bind spec says:
3249 * "If <buffers> is NULL, all bindings from <first> through
3250 * <first>+<count>-1 are reset to their unbound (zero) state.
3251 * In this case, the offsets and sizes associated with the
3252 * binding points are set to default values, ignoring
3253 * <offsets> and <sizes>."
3255 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3259 /* Note that the error semantics for multi-bind commands differ from
3260 * those of other GL commands.
3262 * The Issues section in the ARB_multi_bind spec says:
3264 * "(11) Typically, OpenGL specifies that if an error is generated by a
3265 * command, that command has no effect. This is somewhat
3266 * unfortunate for multi-bind commands, because it would require a
3267 * first pass to scan the entire list of bound objects for errors
3268 * and then a second pass to actually perform the bindings.
3269 * Should we have different error semantics?
3271 * RESOLVED: Yes. In this specification, when the parameters for
3272 * one of the <count> binding points are invalid, that binding point
3273 * is not updated and an error will be generated. However, other
3274 * binding points in the same command will be updated if their
3275 * parameters are valid and no other error occurs."
3278 _mesa_begin_bufferobj_lookups(ctx
);
3280 for (i
= 0; i
< count
; i
++) {
3281 const GLuint index
= first
+ i
;
3282 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3283 struct gl_buffer_object
*bufObj
;
3285 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3288 /* The ARB_multi_bind spec says:
3290 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3291 * pair of values in <offsets> and <sizes> does not respectively
3292 * satisfy the constraints described for those parameters for the
3293 * specified target, as described in section 6.7.1 (per binding)."
3295 * Section 6.7.1 refers to table 6.5, which says:
3297 * "┌───────────────────────────────────────────────────────────────┐
3298 * │ Transform feedback array bindings (see sec. 13.2.2) │
3299 * ├───────────────────────┬───────────────────────────────────────┤
3301 * │ offset restriction │ multiple of 4 │
3303 * │ size restriction │ multiple of 4 │
3304 * └───────────────────────┴───────────────────────────────────────┘"
3306 if (offsets
[i
] & 0x3) {
3307 _mesa_error(ctx
, GL_INVALID_VALUE
,
3308 "glBindBuffersRange(offsets[%u]=%" PRId64
3309 " is misaligned; it must be a multiple of 4 when "
3310 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3311 i
, (int64_t) offsets
[i
]);
3315 if (sizes
[i
] & 0x3) {
3316 _mesa_error(ctx
, GL_INVALID_VALUE
,
3317 "glBindBuffersRange(sizes[%u]=%" PRId64
3318 " is misaligned; it must be a multiple of 4 when "
3319 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3320 i
, (int64_t) sizes
[i
]);
3324 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3325 bufObj
= boundBufObj
;
3327 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3328 "glBindBuffersRange");
3331 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
3332 offsets
[i
], sizes
[i
]);
3335 _mesa_end_bufferobj_lookups(ctx
);
3339 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
3340 GLuint first
, GLsizei count
,
3343 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
3344 _mesa_error(ctx
, GL_INVALID_ENUM
,
3345 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
3349 /* The ARB_multi_bind_spec says:
3351 * "An INVALID_OPERATION error is generated if <first> + <count> is
3352 * greater than the number of target-specific indexed binding points,
3353 * as described in section 6.7.1."
3355 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
3356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3357 "%s(first=%u + count=%d > the value of "
3358 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
3359 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
3367 * Unbind all atomic counter buffers in the range
3368 * <first> through <first>+<count>-1
3371 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3373 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3376 for (i
= 0; i
< count
; i
++)
3377 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
3382 bind_atomic_buffers_base(struct gl_context
*ctx
,
3385 const GLuint
*buffers
)
3389 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3390 "glBindBuffersBase"))
3393 /* Assume that at least one binding will be changed */
3394 FLUSH_VERTICES(ctx
, 0);
3395 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3398 /* The ARB_multi_bind spec says:
3400 * "If <buffers> is NULL, all bindings from <first> through
3401 * <first>+<count>-1 are reset to their unbound (zero) state."
3403 unbind_atomic_buffers(ctx
, first
, count
);
3407 /* Note that the error semantics for multi-bind commands differ from
3408 * those of other GL commands.
3410 * The Issues section in the ARB_multi_bind spec says:
3412 * "(11) Typically, OpenGL specifies that if an error is generated by a
3413 * command, that command has no effect. This is somewhat
3414 * unfortunate for multi-bind commands, because it would require a
3415 * first pass to scan the entire list of bound objects for errors
3416 * and then a second pass to actually perform the bindings.
3417 * Should we have different error semantics?
3419 * RESOLVED: Yes. In this specification, when the parameters for
3420 * one of the <count> binding points are invalid, that binding point
3421 * is not updated and an error will be generated. However, other
3422 * binding points in the same command will be updated if their
3423 * parameters are valid and no other error occurs."
3426 _mesa_begin_bufferobj_lookups(ctx
);
3428 for (i
= 0; i
< count
; i
++) {
3429 struct gl_atomic_buffer_binding
*binding
=
3430 &ctx
->AtomicBufferBindings
[first
+ i
];
3431 struct gl_buffer_object
*bufObj
;
3433 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3434 bufObj
= binding
->BufferObject
;
3436 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3437 "glBindBuffersBase");
3440 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
3443 _mesa_end_bufferobj_lookups(ctx
);
3447 bind_atomic_buffers_range(struct gl_context
*ctx
,
3450 const GLuint
*buffers
,
3451 const GLintptr
*offsets
,
3452 const GLsizeiptr
*sizes
)
3456 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3457 "glBindBuffersRange"))
3460 /* Assume that at least one binding will be changed */
3461 FLUSH_VERTICES(ctx
, 0);
3462 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3465 /* The ARB_multi_bind spec says:
3467 * "If <buffers> is NULL, all bindings from <first> through
3468 * <first>+<count>-1 are reset to their unbound (zero) state.
3469 * In this case, the offsets and sizes associated with the
3470 * binding points are set to default values, ignoring
3471 * <offsets> and <sizes>."
3473 unbind_atomic_buffers(ctx
, first
, count
);
3477 /* Note that the error semantics for multi-bind commands differ from
3478 * those of other GL commands.
3480 * The Issues section in the ARB_multi_bind spec says:
3482 * "(11) Typically, OpenGL specifies that if an error is generated by a
3483 * command, that command has no effect. This is somewhat
3484 * unfortunate for multi-bind commands, because it would require a
3485 * first pass to scan the entire list of bound objects for errors
3486 * and then a second pass to actually perform the bindings.
3487 * Should we have different error semantics?
3489 * RESOLVED: Yes. In this specification, when the parameters for
3490 * one of the <count> binding points are invalid, that binding point
3491 * is not updated and an error will be generated. However, other
3492 * binding points in the same command will be updated if their
3493 * parameters are valid and no other error occurs."
3496 _mesa_begin_bufferobj_lookups(ctx
);
3498 for (i
= 0; i
< count
; i
++) {
3499 struct gl_atomic_buffer_binding
*binding
=
3500 &ctx
->AtomicBufferBindings
[first
+ i
];
3501 struct gl_buffer_object
*bufObj
;
3503 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3506 /* The ARB_multi_bind spec says:
3508 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3509 * pair of values in <offsets> and <sizes> does not respectively
3510 * satisfy the constraints described for those parameters for the
3511 * specified target, as described in section 6.7.1 (per binding)."
3513 * Section 6.7.1 refers to table 6.5, which says:
3515 * "┌───────────────────────────────────────────────────────────────┐
3516 * │ Atomic counter array bindings (see sec. 7.7.2) │
3517 * ├───────────────────────┬───────────────────────────────────────┤
3519 * │ offset restriction │ multiple of 4 │
3521 * │ size restriction │ none │
3522 * └───────────────────────┴───────────────────────────────────────┘"
3524 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
3525 _mesa_error(ctx
, GL_INVALID_VALUE
,
3526 "glBindBuffersRange(offsets[%u]=%" PRId64
3527 " is misaligned; it must be a multiple of %d when "
3528 "target=GL_ATOMIC_COUNTER_BUFFER)",
3529 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
3533 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3534 bufObj
= binding
->BufferObject
;
3536 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3537 "glBindBuffersRange");
3540 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
3543 _mesa_end_bufferobj_lookups(ctx
);
3547 _mesa_BindBufferRange(GLenum target
, GLuint index
,
3548 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
3550 GET_CURRENT_CONTEXT(ctx
);
3551 struct gl_buffer_object
*bufObj
;
3554 bufObj
= ctx
->Shared
->NullBufferObj
;
3556 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3558 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3559 &bufObj
, "glBindBufferRange"))
3563 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3564 "glBindBufferRange(invalid buffer=%u)", buffer
);
3570 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
3577 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3578 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
3581 case GL_UNIFORM_BUFFER
:
3582 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
3584 case GL_ATOMIC_COUNTER_BUFFER
:
3585 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
3586 "glBindBufferRange");
3589 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
3595 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
3597 GET_CURRENT_CONTEXT(ctx
);
3598 struct gl_buffer_object
*bufObj
;
3601 bufObj
= ctx
->Shared
->NullBufferObj
;
3603 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3605 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3606 &bufObj
, "glBindBufferBase"))
3610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3611 "glBindBufferBase(invalid buffer=%u)", buffer
);
3615 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
3616 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
3618 * "BindBufferBase is equivalent to calling BindBufferRange with offset
3619 * zero and size equal to the size of buffer."
3621 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
3623 * "If the parameter (starting offset or size) was not specified when the
3624 * buffer object was bound, zero is returned."
3626 * What happens if the size of the buffer changes? Does the size of the
3627 * buffer at the moment glBindBufferBase was called still play a role, like
3628 * the first quote would imply, or is the size meaningless in the
3629 * glBindBufferBase case like the second quote would suggest? The GL 4.1
3630 * core spec page 45 says:
3632 * "It is equivalent to calling BindBufferRange with offset zero, while
3633 * size is determined by the size of the bound buffer at the time the
3636 * My interpretation is that the GL 4.1 spec was a clarification of the
3637 * behavior, not a change. In particular, this choice will only make
3638 * rendering work in cases where it would have had undefined results.
3642 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3643 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
3645 case GL_UNIFORM_BUFFER
:
3646 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
3648 case GL_ATOMIC_COUNTER_BUFFER
:
3649 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
3650 "glBindBufferBase");
3653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
3659 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
3660 const GLuint
*buffers
,
3661 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3663 GET_CURRENT_CONTEXT(ctx
);
3666 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3667 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3669 case GL_UNIFORM_BUFFER
:
3670 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3672 case GL_ATOMIC_COUNTER_BUFFER
:
3673 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
3677 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
3678 _mesa_lookup_enum_by_nr(target
));
3684 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
3685 const GLuint
*buffers
)
3687 GET_CURRENT_CONTEXT(ctx
);
3690 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3691 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
3693 case GL_UNIFORM_BUFFER
:
3694 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
3696 case GL_ATOMIC_COUNTER_BUFFER
:
3697 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
3700 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
3701 _mesa_lookup_enum_by_nr(target
));
3707 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
3710 GET_CURRENT_CONTEXT(ctx
);
3711 struct gl_buffer_object
*bufObj
;
3712 const GLintptr end
= offset
+ length
;
3714 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3716 _mesa_error(ctx
, GL_INVALID_VALUE
,
3717 "glInvalidateBufferSubData(name = 0x%x) invalid object",
3722 /* The GL_ARB_invalidate_subdata spec says:
3724 * "An INVALID_VALUE error is generated if <offset> or <length> is
3725 * negative, or if <offset> + <length> is greater than the value of
3728 if (end
< 0 || end
> bufObj
->Size
) {
3729 _mesa_error(ctx
, GL_INVALID_VALUE
,
3730 "glInvalidateBufferSubData(invalid offset or length)");
3734 /* The OpenGL 4.4 (Core Profile) spec says:
3736 * "An INVALID_OPERATION error is generated if buffer is currently
3737 * mapped by MapBuffer or if the invalidate range intersects the range
3738 * currently mapped by MapBufferRange, unless it was mapped
3739 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3741 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
3742 bufferobj_range_mapped(bufObj
, offset
, length
)) {
3743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3744 "glInvalidateBufferSubData(intersection with mapped "
3749 /* We don't actually do anything for this yet. Just return after
3750 * validating the parameters and generating the required errors.
3756 _mesa_InvalidateBufferData(GLuint buffer
)
3758 GET_CURRENT_CONTEXT(ctx
);
3759 struct gl_buffer_object
*bufObj
;
3761 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3763 _mesa_error(ctx
, GL_INVALID_VALUE
,
3764 "glInvalidateBufferData(name = 0x%x) invalid object",
3769 /* The OpenGL 4.4 (Core Profile) spec says:
3771 * "An INVALID_OPERATION error is generated if buffer is currently
3772 * mapped by MapBuffer or if the invalidate range intersects the range
3773 * currently mapped by MapBufferRange, unless it was mapped
3774 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3776 if (_mesa_check_disallowed_mapping(bufObj
)) {
3777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3778 "glInvalidateBufferData(intersection with mapped "
3783 /* We don't actually do anything for this yet. Just return after
3784 * validating the parameters and generating the required errors.