2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
34 #include <inttypes.h> /* for PRId64 macro */
41 #include "bufferobj.h"
46 #include "glformats.h"
48 #include "transformfeedback.h"
54 /*#define BOUNDS_CHECK*/
58 * Used as a placeholder for buffer objects between glGenBuffers() and
59 * glBindBuffer() so that glIsBuffer() can work correctly.
61 static struct gl_buffer_object DummyBufferObject
;
65 * Return pointer to address of a buffer object target.
66 * \param ctx the GL context
67 * \param target the buffer object target to be retrieved.
68 * \return pointer to pointer to the buffer object bound to \c target in the
69 * specified context or \c NULL if \c target is invalid.
71 static inline struct gl_buffer_object
**
72 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
74 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
76 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
77 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
81 case GL_ARRAY_BUFFER_ARB
:
82 return &ctx
->Array
.ArrayBufferObj
;
83 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
84 return &ctx
->Array
.VAO
->IndexBufferObj
;
85 case GL_PIXEL_PACK_BUFFER_EXT
:
86 return &ctx
->Pack
.BufferObj
;
87 case GL_PIXEL_UNPACK_BUFFER_EXT
:
88 return &ctx
->Unpack
.BufferObj
;
89 case GL_COPY_READ_BUFFER
:
90 return &ctx
->CopyReadBuffer
;
91 case GL_COPY_WRITE_BUFFER
:
92 return &ctx
->CopyWriteBuffer
;
93 case GL_DRAW_INDIRECT_BUFFER
:
94 if (ctx
->API
== API_OPENGL_CORE
&&
95 ctx
->Extensions
.ARB_draw_indirect
) {
96 return &ctx
->DrawIndirectBuffer
;
99 case GL_TRANSFORM_FEEDBACK_BUFFER
:
100 if (ctx
->Extensions
.EXT_transform_feedback
) {
101 return &ctx
->TransformFeedback
.CurrentBuffer
;
104 case GL_TEXTURE_BUFFER
:
105 if (ctx
->API
== API_OPENGL_CORE
&&
106 ctx
->Extensions
.ARB_texture_buffer_object
) {
107 return &ctx
->Texture
.BufferObject
;
110 case GL_UNIFORM_BUFFER
:
111 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
112 return &ctx
->UniformBuffer
;
115 case GL_ATOMIC_COUNTER_BUFFER
:
116 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
117 return &ctx
->AtomicBuffer
;
128 * Get the buffer object bound to the specified target in a GL context.
129 * \param ctx the GL context
130 * \param target the buffer object target to be retrieved.
131 * \param error the GL error to record if target is illegal.
132 * \return pointer to the buffer object bound to \c target in the
133 * specified context or \c NULL if \c target is invalid.
135 static inline struct gl_buffer_object
*
136 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
139 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
142 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
146 if (!_mesa_is_bufferobj(*bufObj
)) {
147 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
156 * Convert a GLbitfield describing the mapped buffer access flags
157 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
160 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
162 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
163 if ((access
& rwFlags
) == rwFlags
)
164 return GL_READ_WRITE
;
165 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
167 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
168 return GL_WRITE_ONLY
;
170 /* Otherwise, AccessFlags is zero (the default state).
172 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
174 * Name Type Initial Value Legal Values
176 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
179 * However, table 6.8 in the GL_OES_mapbuffer extension says:
181 * Get Value Type Get Command Value Description
182 * --------- ---- ----------- ----- -----------
183 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
185 * The difference is because GL_OES_mapbuffer only supports mapping buffers
190 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
195 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
197 * The regions do not overlap if and only if the end of the given
198 * region is before the mapped region or the start of the given region
199 * is after the mapped region.
201 * \param obj Buffer object target on which to operate.
202 * \param offset Offset of the first byte of the subdata range.
203 * \param size Size, in bytes, of the subdata range.
204 * \return true if ranges overlap, false otherwise
208 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
209 GLintptr offset
, GLsizeiptr size
)
211 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
212 const GLintptr end
= offset
+ size
;
213 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
214 obj
->Mappings
[MAP_USER
].Length
;
216 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
225 * Tests the subdata range parameters and sets the GL error code for
226 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
227 * \c glClearBufferSubData.
229 * \param ctx GL context.
230 * \param target Buffer object target on which to operate.
231 * \param offset Offset of the first byte of the subdata range.
232 * \param size Size, in bytes, of the subdata range.
233 * \param mappedRange If true, checks if an overlapping range is mapped.
234 * If false, checks if buffer is mapped.
235 * \param errorNoBuffer Error code if no buffer is bound to target.
236 * \param caller Name of calling function for recording errors.
237 * \return A pointer to the buffer object bound to \c target in the
238 * specified context or \c NULL if any of the parameter or state
239 * conditions are invalid.
241 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
243 static struct gl_buffer_object
*
244 buffer_object_subdata_range_good(struct gl_context
* ctx
, GLenum target
,
245 GLintptrARB offset
, GLsizeiptrARB size
,
246 bool mappedRange
, GLenum errorNoBuffer
,
249 struct gl_buffer_object
*bufObj
;
252 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
257 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
261 bufObj
= get_buffer(ctx
, caller
, target
, errorNoBuffer
);
265 if (offset
+ size
> bufObj
->Size
) {
266 _mesa_error(ctx
, GL_INVALID_VALUE
,
267 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
268 (unsigned long) offset
,
269 (unsigned long) size
,
270 (unsigned long) bufObj
->Size
);
274 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
278 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
279 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
284 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
285 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", caller
);
295 * Test the format and type parameters and set the GL error code for
296 * \c glClearBufferData and \c glClearBufferSubData.
298 * \param ctx GL context.
299 * \param internalformat Format to which the data is to be converted.
300 * \param format Format of the supplied data.
301 * \param type Type of the supplied data.
302 * \param caller Name of calling function for recording errors.
303 * \return If internalformat, format and type are legal the mesa_format
304 * corresponding to internalformat, otherwise MESA_FORMAT_NONE.
306 * \sa glClearBufferData and glClearBufferSubData
309 validate_clear_buffer_format(struct gl_context
*ctx
,
310 GLenum internalformat
,
311 GLenum format
, GLenum type
,
314 mesa_format mesaFormat
;
315 GLenum errorFormatType
;
317 mesaFormat
= _mesa_validate_texbuffer_format(ctx
, internalformat
);
318 if (mesaFormat
== MESA_FORMAT_NONE
) {
319 _mesa_error(ctx
, GL_INVALID_ENUM
,
320 "%s(invalid internalformat)", caller
);
321 return MESA_FORMAT_NONE
;
324 /* NOTE: not mentioned in ARB_clear_buffer_object but according to
325 * EXT_texture_integer there is no conversion between integer and
326 * non-integer formats
328 if (_mesa_is_enum_format_signed_int(format
) !=
329 _mesa_is_format_integer_color(mesaFormat
)) {
330 _mesa_error(ctx
, GL_INVALID_OPERATION
,
331 "%s(integer vs non-integer)", caller
);
332 return MESA_FORMAT_NONE
;
335 if (!_mesa_is_color_format(format
)) {
336 _mesa_error(ctx
, GL_INVALID_ENUM
,
337 "%s(format is not a color format)", caller
);
338 return MESA_FORMAT_NONE
;
341 errorFormatType
= _mesa_error_check_format_and_type(ctx
, format
, type
);
342 if (errorFormatType
!= GL_NO_ERROR
) {
343 _mesa_error(ctx
, GL_INVALID_ENUM
,
344 "%s(invalid format or type)", caller
);
345 return MESA_FORMAT_NONE
;
353 * Convert user-specified clear value to the specified internal format.
355 * \param ctx GL context.
356 * \param internalformat Format to which the data is converted.
357 * \param clearValue Points to the converted clear value.
358 * \param format Format of the supplied data.
359 * \param type Type of the supplied data.
360 * \param data Data which is to be converted to internalformat.
361 * \param caller Name of calling function for recording errors.
362 * \return true if data could be converted, false otherwise.
364 * \sa glClearBufferData, glClearBufferSubData
367 convert_clear_buffer_data(struct gl_context
*ctx
,
368 mesa_format internalformat
,
369 GLubyte
*clearValue
, GLenum format
, GLenum type
,
370 const GLvoid
*data
, const char *caller
)
372 GLenum internalformatBase
= _mesa_get_format_base_format(internalformat
);
374 if (_mesa_texstore(ctx
, 1, internalformatBase
, internalformat
,
375 0, &clearValue
, 1, 1, 1,
376 format
, type
, data
, &ctx
->Unpack
)) {
380 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
387 * Allocate and initialize a new buffer object.
389 * Default callback for the \c dd_function_table::NewBufferObject() hook.
391 static struct gl_buffer_object
*
392 _mesa_new_buffer_object(struct gl_context
*ctx
, GLuint name
)
394 struct gl_buffer_object
*obj
;
398 obj
= MALLOC_STRUCT(gl_buffer_object
);
399 _mesa_initialize_buffer_object(ctx
, obj
, name
);
405 * Delete a buffer object.
407 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
410 _mesa_delete_buffer_object(struct gl_context
*ctx
,
411 struct gl_buffer_object
*bufObj
)
415 _mesa_align_free(bufObj
->Data
);
417 /* assign strange values here to help w/ debugging */
418 bufObj
->RefCount
= -1000;
421 mtx_destroy(&bufObj
->Mutex
);
429 * Set ptr to bufObj w/ reference counting.
430 * This is normally only called from the _mesa_reference_buffer_object() macro
431 * when there's a real pointer change.
434 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
435 struct gl_buffer_object
**ptr
,
436 struct gl_buffer_object
*bufObj
)
439 /* Unreference the old buffer */
440 GLboolean deleteFlag
= GL_FALSE
;
441 struct gl_buffer_object
*oldObj
= *ptr
;
443 mtx_lock(&oldObj
->Mutex
);
444 ASSERT(oldObj
->RefCount
> 0);
447 printf("BufferObj %p %d DECR to %d\n",
448 (void *) oldObj
, oldObj
->Name
, oldObj
->RefCount
);
450 deleteFlag
= (oldObj
->RefCount
== 0);
451 mtx_unlock(&oldObj
->Mutex
);
455 /* some sanity checking: don't delete a buffer still in use */
457 /* unfortunately, these tests are invalid during context tear-down */
458 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
459 ASSERT(ctx
->Array
.VAO
->IndexBufferObj
!= bufObj
);
460 ASSERT(ctx
->Array
.VAO
->Vertex
.BufferObj
!= bufObj
);
463 ASSERT(ctx
->Driver
.DeleteBuffer
);
464 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
472 /* reference new buffer */
473 mtx_lock(&bufObj
->Mutex
);
474 if (bufObj
->RefCount
== 0) {
475 /* this buffer's being deleted (look just above) */
476 /* Not sure this can every really happen. Warn if it does. */
477 _mesa_problem(NULL
, "referencing deleted buffer object");
483 printf("BufferObj %p %d INCR to %d\n",
484 (void *) bufObj
, bufObj
->Name
, bufObj
->RefCount
);
488 mtx_unlock(&bufObj
->Mutex
);
494 * Initialize a buffer object to default values.
497 _mesa_initialize_buffer_object(struct gl_context
*ctx
,
498 struct gl_buffer_object
*obj
,
501 memset(obj
, 0, sizeof(struct gl_buffer_object
));
502 mtx_init(&obj
->Mutex
, mtx_plain
);
505 obj
->Usage
= GL_STATIC_DRAW_ARB
;
511 * Callback called from _mesa_HashWalk()
514 count_buffer_size(GLuint key
, void *data
, void *userData
)
516 const struct gl_buffer_object
*bufObj
=
517 (const struct gl_buffer_object
*) data
;
518 GLuint
*total
= (GLuint
*) userData
;
520 *total
= *total
+ bufObj
->Size
;
525 * Compute total size (in bytes) of all buffer objects for the given context.
526 * For debugging purposes.
529 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
533 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
540 * Allocate space for and store data in a buffer object. Any data that was
541 * previously stored in the buffer object is lost. If \c data is \c NULL,
542 * memory will be allocated, but no copy will occur.
544 * This is the default callback for \c dd_function_table::BufferData()
545 * Note that all GL error checking will have been done already.
547 * \param ctx GL context.
548 * \param target Buffer object target on which to operate.
549 * \param size Size, in bytes, of the new data store.
550 * \param data Pointer to the data to store in the buffer object. This
551 * pointer may be \c NULL.
552 * \param usage Hints about how the data will be used.
553 * \param bufObj Object to be used.
555 * \return GL_TRUE for success, GL_FALSE for failure
556 * \sa glBufferDataARB, dd_function_table::BufferData.
559 _mesa_buffer_data( struct gl_context
*ctx
, GLenum target
, GLsizeiptrARB size
,
560 const GLvoid
* data
, GLenum usage
, GLenum storageFlags
,
561 struct gl_buffer_object
* bufObj
)
567 _mesa_align_free( bufObj
->Data
);
569 new_data
= _mesa_align_malloc( size
, ctx
->Const
.MinMapBufferAlignment
);
571 bufObj
->Data
= (GLubyte
*) new_data
;
573 bufObj
->Usage
= usage
;
574 bufObj
->StorageFlags
= storageFlags
;
577 memcpy( bufObj
->Data
, data
, size
);
589 * Replace data in a subrange of buffer object. If the data range
590 * specified by \c size + \c offset extends beyond the end of the buffer or
591 * if \c data is \c NULL, no copy is performed.
593 * This is the default callback for \c dd_function_table::BufferSubData()
594 * Note that all GL error checking will have been done already.
596 * \param ctx GL context.
597 * \param offset Offset of the first byte to be modified.
598 * \param size Size, in bytes, of the data range.
599 * \param data Pointer to the data to store in the buffer object.
600 * \param bufObj Object to be used.
602 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
605 _mesa_buffer_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
606 GLsizeiptrARB size
, const GLvoid
* data
,
607 struct gl_buffer_object
* bufObj
)
611 /* this should have been caught in _mesa_BufferSubData() */
612 ASSERT(size
+ offset
<= bufObj
->Size
);
615 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
621 * Retrieve data from a subrange of buffer object. If the data range
622 * specified by \c size + \c offset extends beyond the end of the buffer or
623 * if \c data is \c NULL, no copy is performed.
625 * This is the default callback for \c dd_function_table::GetBufferSubData()
626 * Note that all GL error checking will have been done already.
628 * \param ctx GL context.
629 * \param target Buffer object target on which to operate.
630 * \param offset Offset of the first byte to be fetched.
631 * \param size Size, in bytes, of the data range.
632 * \param data Destination for data
633 * \param bufObj Object to be used.
635 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
638 _mesa_buffer_get_subdata( struct gl_context
*ctx
, GLintptrARB offset
,
639 GLsizeiptrARB size
, GLvoid
* data
,
640 struct gl_buffer_object
* bufObj
)
644 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
645 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
651 * Clear a subrange of the buffer object with copies of the supplied data.
652 * If data is NULL the buffer is filled with zeros.
654 * This is the default callback for \c dd_function_table::ClearBufferSubData()
655 * Note that all GL error checking will have been done already.
657 * \param ctx GL context.
658 * \param offset Offset of the first byte to be cleared.
659 * \param size Size, in bytes, of the to be cleared range.
660 * \param clearValue Source of the data.
661 * \param clearValueSize Size, in bytes, of the supplied data.
662 * \param bufObj Object to be cleared.
664 * \sa glClearBufferSubData, glClearBufferData and
665 * dd_function_table::ClearBufferSubData.
668 _mesa_buffer_clear_subdata(struct gl_context
*ctx
,
669 GLintptr offset
, GLsizeiptr size
,
670 const GLvoid
*clearValue
,
671 GLsizeiptr clearValueSize
,
672 struct gl_buffer_object
*bufObj
)
677 ASSERT(ctx
->Driver
.MapBufferRange
);
678 dest
= ctx
->Driver
.MapBufferRange(ctx
, offset
, size
,
680 GL_MAP_INVALIDATE_RANGE_BIT
,
681 bufObj
, MAP_INTERNAL
);
684 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearBuffer[Sub]Data");
688 if (clearValue
== NULL
) {
689 /* Clear with zeros, per the spec */
690 memset(dest
, 0, size
);
691 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
695 for (i
= 0; i
< size
/clearValueSize
; ++i
) {
696 memcpy(dest
, clearValue
, clearValueSize
);
697 dest
+= clearValueSize
;
700 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
705 * Default fallback for \c dd_function_table::MapBufferRange().
706 * Called via glMapBufferRange().
709 _mesa_buffer_map_range( struct gl_context
*ctx
, GLintptr offset
,
710 GLsizeiptr length
, GLbitfield access
,
711 struct gl_buffer_object
*bufObj
,
712 gl_map_buffer_index index
)
715 assert(!_mesa_bufferobj_mapped(bufObj
, index
));
716 /* Just return a direct pointer to the data */
717 bufObj
->Mappings
[index
].Pointer
= bufObj
->Data
+ offset
;
718 bufObj
->Mappings
[index
].Length
= length
;
719 bufObj
->Mappings
[index
].Offset
= offset
;
720 bufObj
->Mappings
[index
].AccessFlags
= access
;
721 return bufObj
->Mappings
[index
].Pointer
;
726 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
727 * Called via glFlushMappedBufferRange().
730 _mesa_buffer_flush_mapped_range( struct gl_context
*ctx
,
731 GLintptr offset
, GLsizeiptr length
,
732 struct gl_buffer_object
*obj
,
733 gl_map_buffer_index index
)
744 * Default callback for \c dd_function_table::MapBuffer().
746 * The input parameters will have been already tested for errors.
748 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
751 _mesa_buffer_unmap(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
752 gl_map_buffer_index index
)
755 /* XXX we might assert here that bufObj->Pointer is non-null */
756 bufObj
->Mappings
[index
].Pointer
= NULL
;
757 bufObj
->Mappings
[index
].Length
= 0;
758 bufObj
->Mappings
[index
].Offset
= 0;
759 bufObj
->Mappings
[index
].AccessFlags
= 0x0;
765 * Default fallback for \c dd_function_table::CopyBufferSubData().
766 * Called via glCopyBufferSubData().
769 _mesa_copy_buffer_subdata(struct gl_context
*ctx
,
770 struct gl_buffer_object
*src
,
771 struct gl_buffer_object
*dst
,
772 GLintptr readOffset
, GLintptr writeOffset
,
775 GLubyte
*srcPtr
, *dstPtr
;
778 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
780 GL_MAP_WRITE_BIT
, src
,
786 srcPtr
+= readOffset
;
787 dstPtr
+= writeOffset
;
789 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
790 GL_MAP_READ_BIT
, src
,
792 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
794 GL_MAP_INVALIDATE_RANGE_BIT
), dst
,
798 /* Note: the src and dst regions will never overlap. Trying to do so
799 * would generate GL_INVALID_VALUE earlier.
801 if (srcPtr
&& dstPtr
)
802 memcpy(dstPtr
, srcPtr
, size
);
804 ctx
->Driver
.UnmapBuffer(ctx
, src
, MAP_INTERNAL
);
806 ctx
->Driver
.UnmapBuffer(ctx
, dst
, MAP_INTERNAL
);
812 * Initialize the state associated with buffer objects
815 _mesa_init_buffer_objects( struct gl_context
*ctx
)
819 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
820 mtx_init(&DummyBufferObject
.Mutex
, mtx_plain
);
821 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
823 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
824 ctx
->Shared
->NullBufferObj
);
826 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
827 ctx
->Shared
->NullBufferObj
);
828 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
829 ctx
->Shared
->NullBufferObj
);
831 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
832 ctx
->Shared
->NullBufferObj
);
834 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
,
835 ctx
->Shared
->NullBufferObj
);
837 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
838 ctx
->Shared
->NullBufferObj
);
840 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
841 _mesa_reference_buffer_object(ctx
,
842 &ctx
->UniformBufferBindings
[i
].BufferObject
,
843 ctx
->Shared
->NullBufferObj
);
844 ctx
->UniformBufferBindings
[i
].Offset
= -1;
845 ctx
->UniformBufferBindings
[i
].Size
= -1;
848 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
849 _mesa_reference_buffer_object(ctx
,
850 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
851 ctx
->Shared
->NullBufferObj
);
852 ctx
->AtomicBufferBindings
[i
].Offset
= -1;
853 ctx
->AtomicBufferBindings
[i
].Size
= -1;
859 _mesa_free_buffer_objects( struct gl_context
*ctx
)
863 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
865 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
866 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
868 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
870 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
872 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
874 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
875 _mesa_reference_buffer_object(ctx
,
876 &ctx
->UniformBufferBindings
[i
].BufferObject
,
880 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
881 _mesa_reference_buffer_object(ctx
,
882 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
889 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
892 struct gl_buffer_object
**buf_handle
,
895 struct gl_buffer_object
*buf
= *buf_handle
;
897 if (!buf
&& ctx
->API
== API_OPENGL_CORE
) {
898 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
902 if (!buf
|| buf
== &DummyBufferObject
) {
903 /* If this is a new buffer object id, or one which was generated but
904 * never used before, allocate a buffer object now.
906 ASSERT(ctx
->Driver
.NewBufferObject
);
907 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
);
909 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
912 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
920 * Bind the specified target to buffer for the specified context.
921 * Called by glBindBuffer() and other functions.
924 bind_buffer_object(struct gl_context
*ctx
, GLenum target
, GLuint buffer
)
926 struct gl_buffer_object
*oldBufObj
;
927 struct gl_buffer_object
*newBufObj
= NULL
;
928 struct gl_buffer_object
**bindTarget
= NULL
;
930 bindTarget
= get_buffer_target(ctx
, target
);
932 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target 0x%x)", target
);
936 /* Get pointer to old buffer object (to be unbound) */
937 oldBufObj
= *bindTarget
;
938 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
939 return; /* rebinding the same buffer object- no change */
942 * Get pointer to new buffer object (newBufObj)
945 /* The spec says there's not a buffer object named 0, but we use
946 * one internally because it simplifies things.
948 newBufObj
= ctx
->Shared
->NullBufferObj
;
951 /* non-default buffer object */
952 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
953 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
954 &newBufObj
, "glBindBuffer"))
958 /* bind new buffer */
959 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
964 * Update the default buffer objects in the given context to reference those
965 * specified in the shared state and release those referencing the old
969 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
971 /* Bind the NullBufferObj to remove references to those
972 * in the shared context hash table.
974 bind_buffer_object( ctx
, GL_ARRAY_BUFFER_ARB
, 0);
975 bind_buffer_object( ctx
, GL_ELEMENT_ARRAY_BUFFER_ARB
, 0);
976 bind_buffer_object( ctx
, GL_PIXEL_PACK_BUFFER_ARB
, 0);
977 bind_buffer_object( ctx
, GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
983 * Return the gl_buffer_object for the given ID.
984 * Always return NULL for ID 0.
986 struct gl_buffer_object
*
987 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
992 return (struct gl_buffer_object
*)
993 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
997 struct gl_buffer_object
*
998 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1000 return (struct gl_buffer_object
*)
1001 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1006 _mesa_begin_bufferobj_lookups(struct gl_context
*ctx
)
1008 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1013 _mesa_end_bufferobj_lookups(struct gl_context
*ctx
)
1015 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1020 * Look up a buffer object for a multi-bind function.
1022 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1023 * of generating an error if the buffer ID is not zero or the name
1024 * of an existing buffer object.
1026 * If the buffer ID refers to an existing buffer object, a pointer
1027 * to the buffer object is returned. If the ID is zero, a pointer
1028 * to the shared NullBufferObj is returned. If the ID is not zero
1029 * and does not refer to a valid buffer object, this function
1032 * This function assumes that the caller has already locked the
1033 * hash table mutex by calling _mesa_begin_bufferobj_lookups().
1035 struct gl_buffer_object
*
1036 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1037 const GLuint
*buffers
,
1038 GLuint index
, const char *caller
)
1040 struct gl_buffer_object
*bufObj
;
1042 if (buffers
[index
] != 0) {
1043 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1045 /* The multi-bind functions don't create the buffer objects
1046 when they don't exist. */
1047 if (bufObj
== &DummyBufferObject
)
1050 bufObj
= ctx
->Shared
->NullBufferObj
;
1053 /* The ARB_multi_bind spec says:
1055 * "An INVALID_OPERATION error is generated if any value
1056 * in <buffers> is not zero or the name of an existing
1057 * buffer object (per binding)."
1059 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1060 "%s(buffers[%u]=%u is not zero or the name "
1061 "of an existing buffer object)",
1062 caller
, index
, buffers
[index
]);
1070 * If *ptr points to obj, set ptr = the Null/default buffer object.
1071 * This is a helper for buffer object deletion.
1072 * The GL spec says that deleting a buffer object causes it to get
1073 * unbound from all arrays in the current context.
1076 unbind(struct gl_context
*ctx
,
1077 struct gl_buffer_object
**ptr
,
1078 struct gl_buffer_object
*obj
)
1081 _mesa_reference_buffer_object(ctx
, ptr
, ctx
->Shared
->NullBufferObj
);
1087 * Plug default/fallback buffer object functions into the device
1091 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1093 /* GL_ARB_vertex/pixel_buffer_object */
1094 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1095 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1096 driver
->BufferData
= _mesa_buffer_data
;
1097 driver
->BufferSubData
= _mesa_buffer_subdata
;
1098 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
1099 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
1101 /* GL_ARB_clear_buffer_object */
1102 driver
->ClearBufferSubData
= _mesa_buffer_clear_subdata
;
1104 /* GL_ARB_map_buffer_range */
1105 driver
->MapBufferRange
= _mesa_buffer_map_range
;
1106 driver
->FlushMappedBufferRange
= _mesa_buffer_flush_mapped_range
;
1108 /* GL_ARB_copy_buffer */
1109 driver
->CopyBufferSubData
= _mesa_copy_buffer_subdata
;
1114 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1115 struct gl_buffer_object
*bufObj
)
1119 for (i
= 0; i
< MAP_COUNT
; i
++) {
1120 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1121 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1122 ASSERT(bufObj
->Mappings
[i
].Pointer
== NULL
);
1123 bufObj
->Mappings
[i
].AccessFlags
= 0;
1129 /**********************************************************************/
1131 /**********************************************************************/
1134 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1136 GET_CURRENT_CONTEXT(ctx
);
1138 if (MESA_VERBOSE
& VERBOSE_API
)
1139 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1140 _mesa_lookup_enum_by_nr(target
), buffer
);
1142 bind_buffer_object(ctx
, target
, buffer
);
1147 * Delete a set of buffer objects.
1149 * \param n Number of buffer objects to delete.
1150 * \param ids Array of \c n buffer object IDs.
1153 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1155 GET_CURRENT_CONTEXT(ctx
);
1157 FLUSH_VERTICES(ctx
, 0);
1160 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1164 mtx_lock(&ctx
->Shared
->Mutex
);
1166 for (i
= 0; i
< n
; i
++) {
1167 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, ids
[i
]);
1169 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1172 ASSERT(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1174 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1176 /* unbind any vertex pointers bound to this buffer */
1177 for (j
= 0; j
< Elements(vao
->VertexBinding
); j
++) {
1178 unbind(ctx
, &vao
->VertexBinding
[j
].BufferObj
, bufObj
);
1181 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1182 _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB
, 0 );
1184 if (vao
->IndexBufferObj
== bufObj
) {
1185 _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
1188 /* unbind ARB_draw_indirect binding point */
1189 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1190 _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER
, 0 );
1193 /* unbind ARB_copy_buffer binding points */
1194 if (ctx
->CopyReadBuffer
== bufObj
) {
1195 _mesa_BindBuffer( GL_COPY_READ_BUFFER
, 0 );
1197 if (ctx
->CopyWriteBuffer
== bufObj
) {
1198 _mesa_BindBuffer( GL_COPY_WRITE_BUFFER
, 0 );
1201 /* unbind transform feedback binding points */
1202 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1203 _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER
, 0 );
1205 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1206 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1207 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1211 /* unbind UBO binding points */
1212 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1213 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1214 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1218 if (ctx
->UniformBuffer
== bufObj
) {
1219 _mesa_BindBuffer( GL_UNIFORM_BUFFER
, 0 );
1222 /* unbind Atomci Buffer binding points */
1223 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1224 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1225 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1229 if (ctx
->AtomicBuffer
== bufObj
) {
1230 _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER
, 0 );
1233 /* unbind any pixel pack/unpack pointers bound to this buffer */
1234 if (ctx
->Pack
.BufferObj
== bufObj
) {
1235 _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
1237 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1238 _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
1241 if (ctx
->Texture
.BufferObject
== bufObj
) {
1242 _mesa_BindBuffer( GL_TEXTURE_BUFFER
, 0 );
1245 /* The ID is immediately freed for re-use */
1246 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, ids
[i
]);
1247 /* Make sure we do not run into the classic ABA problem on bind.
1248 * We don't want to allow re-binding a buffer object that's been
1249 * "deleted" by glDeleteBuffers().
1251 * The explicit rebinding to the default object in the current context
1252 * prevents the above in the current context, but another context
1253 * sharing the same objects might suffer from this problem.
1254 * The alternative would be to do the hash lookup in any case on bind
1255 * which would introduce more runtime overhead than this.
1257 bufObj
->DeletePending
= GL_TRUE
;
1258 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1262 mtx_unlock(&ctx
->Shared
->Mutex
);
1267 * Generate a set of unique buffer object IDs and store them in \c buffer.
1269 * \param n Number of IDs to generate.
1270 * \param buffer Array of \c n locations to store the IDs.
1273 _mesa_GenBuffers(GLsizei n
, GLuint
*buffer
)
1275 GET_CURRENT_CONTEXT(ctx
);
1279 if (MESA_VERBOSE
& VERBOSE_API
)
1280 _mesa_debug(ctx
, "glGenBuffers(%d)\n", n
);
1283 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
1292 * This must be atomic (generation and allocation of buffer object IDs)
1294 mtx_lock(&ctx
->Shared
->Mutex
);
1296 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1298 /* Insert the ID and pointer to dummy buffer object into hash table */
1299 for (i
= 0; i
< n
; i
++) {
1300 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, first
+ i
,
1301 &DummyBufferObject
);
1302 buffer
[i
] = first
+ i
;
1305 mtx_unlock(&ctx
->Shared
->Mutex
);
1310 * Determine if ID is the name of a buffer object.
1312 * \param id ID of the potential buffer object.
1313 * \return \c GL_TRUE if \c id is the name of a buffer object,
1314 * \c GL_FALSE otherwise.
1316 GLboolean GLAPIENTRY
1317 _mesa_IsBuffer(GLuint id
)
1319 struct gl_buffer_object
*bufObj
;
1320 GET_CURRENT_CONTEXT(ctx
);
1321 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1323 mtx_lock(&ctx
->Shared
->Mutex
);
1324 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1325 mtx_unlock(&ctx
->Shared
->Mutex
);
1327 return bufObj
&& bufObj
!= &DummyBufferObject
;
1332 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1335 GET_CURRENT_CONTEXT(ctx
);
1336 struct gl_buffer_object
*bufObj
;
1339 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(size <= 0)");
1343 if (flags
& ~(GL_MAP_READ_BIT
|
1345 GL_MAP_PERSISTENT_BIT
|
1346 GL_MAP_COHERENT_BIT
|
1347 GL_DYNAMIC_STORAGE_BIT
|
1348 GL_CLIENT_STORAGE_BIT
)) {
1349 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags)");
1353 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1354 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1355 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=READ/WRITE)");
1359 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1360 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferStorage(flags!=PERSISTENT)");
1364 bufObj
= get_buffer(ctx
, "glBufferStorage", target
, GL_INVALID_OPERATION
);
1368 if (bufObj
->Immutable
) {
1369 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferStorage(immutable)");
1373 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1374 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1376 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1378 bufObj
->Written
= GL_TRUE
;
1379 bufObj
->Immutable
= GL_TRUE
;
1381 ASSERT(ctx
->Driver
.BufferData
);
1382 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1384 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferStorage()");
1390 _mesa_BufferData(GLenum target
, GLsizeiptrARB size
,
1391 const GLvoid
* data
, GLenum usage
)
1393 GET_CURRENT_CONTEXT(ctx
);
1394 struct gl_buffer_object
*bufObj
;
1397 if (MESA_VERBOSE
& VERBOSE_API
)
1398 _mesa_debug(ctx
, "glBufferData(%s, %ld, %p, %s)\n",
1399 _mesa_lookup_enum_by_nr(target
),
1400 (long int) size
, data
,
1401 _mesa_lookup_enum_by_nr(usage
));
1404 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
1409 case GL_STREAM_DRAW_ARB
:
1410 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1413 case GL_STATIC_DRAW_ARB
:
1414 case GL_DYNAMIC_DRAW_ARB
:
1418 case GL_STREAM_READ_ARB
:
1419 case GL_STREAM_COPY_ARB
:
1420 case GL_STATIC_READ_ARB
:
1421 case GL_STATIC_COPY_ARB
:
1422 case GL_DYNAMIC_READ_ARB
:
1423 case GL_DYNAMIC_COPY_ARB
:
1424 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1428 valid_usage
= false;
1433 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferData(usage)");
1437 bufObj
= get_buffer(ctx
, "glBufferDataARB", target
, GL_INVALID_OPERATION
);
1441 if (bufObj
->Immutable
) {
1442 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferData(immutable)");
1446 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1447 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1449 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1451 bufObj
->Written
= GL_TRUE
;
1454 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1455 bufObj
->Name
, size
, data
, usage
);
1462 ASSERT(ctx
->Driver
.BufferData
);
1463 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1466 GL_DYNAMIC_STORAGE_BIT
,
1468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBufferDataARB()");
1474 _mesa_BufferSubData(GLenum target
, GLintptrARB offset
,
1475 GLsizeiptrARB size
, const GLvoid
* data
)
1477 GET_CURRENT_CONTEXT(ctx
);
1478 struct gl_buffer_object
*bufObj
;
1480 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
1481 false, GL_INVALID_OPERATION
,
1482 "glBufferSubDataARB" );
1484 /* error already recorded */
1488 if (bufObj
->Immutable
&&
1489 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1490 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubData");
1497 bufObj
->Written
= GL_TRUE
;
1499 ASSERT(ctx
->Driver
.BufferSubData
);
1500 ctx
->Driver
.BufferSubData( ctx
, offset
, size
, data
, bufObj
);
1505 _mesa_GetBufferSubData(GLenum target
, GLintptrARB offset
,
1506 GLsizeiptrARB size
, void * data
)
1508 GET_CURRENT_CONTEXT(ctx
);
1509 struct gl_buffer_object
*bufObj
;
1511 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1512 false, GL_INVALID_OPERATION
,
1513 "glGetBufferSubDataARB");
1515 /* error already recorded */
1519 ASSERT(ctx
->Driver
.GetBufferSubData
);
1520 ctx
->Driver
.GetBufferSubData( ctx
, offset
, size
, data
, bufObj
);
1525 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
1526 GLenum type
, const GLvoid
* data
)
1528 GET_CURRENT_CONTEXT(ctx
);
1529 struct gl_buffer_object
* bufObj
;
1530 mesa_format mesaFormat
;
1531 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1532 GLsizeiptr clearValueSize
;
1534 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
1539 if (_mesa_check_disallowed_mapping(bufObj
)) {
1540 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1541 "glClearBufferData(buffer currently mapped)");
1545 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1547 "glClearBufferData");
1548 if (mesaFormat
== MESA_FORMAT_NONE
) {
1552 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1553 if (bufObj
->Size
% clearValueSize
!= 0) {
1554 _mesa_error(ctx
, GL_INVALID_VALUE
,
1555 "glClearBufferData(size is not a multiple of "
1556 "internalformat size)");
1561 /* clear to zeros, per the spec */
1562 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1563 NULL
, clearValueSize
, bufObj
);
1567 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1568 format
, type
, data
, "glClearBufferData")) {
1572 ctx
->Driver
.ClearBufferSubData(ctx
, 0, bufObj
->Size
,
1573 clearValue
, clearValueSize
, bufObj
);
1578 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
1579 GLintptr offset
, GLsizeiptr size
,
1580 GLenum format
, GLenum type
,
1583 GET_CURRENT_CONTEXT(ctx
);
1584 struct gl_buffer_object
* bufObj
;
1585 mesa_format mesaFormat
;
1586 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1587 GLsizeiptr clearValueSize
;
1589 bufObj
= buffer_object_subdata_range_good(ctx
, target
, offset
, size
,
1590 true, GL_INVALID_VALUE
,
1591 "glClearBufferSubData");
1596 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1598 "glClearBufferSubData");
1599 if (mesaFormat
== MESA_FORMAT_NONE
) {
1603 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1604 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1605 _mesa_error(ctx
, GL_INVALID_VALUE
,
1606 "glClearBufferSubData(offset or size is not a multiple of "
1607 "internalformat size)");
1612 /* clear to zeros, per the spec */
1614 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1615 NULL
, clearValueSize
, bufObj
);
1620 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
1622 "glClearBufferSubData")) {
1627 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1628 clearValue
, clearValueSize
, bufObj
);
1634 _mesa_MapBuffer(GLenum target
, GLenum access
)
1636 GET_CURRENT_CONTEXT(ctx
);
1637 struct gl_buffer_object
* bufObj
;
1638 GLbitfield accessFlags
;
1642 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
1645 case GL_READ_ONLY_ARB
:
1646 accessFlags
= GL_MAP_READ_BIT
;
1647 valid_access
= _mesa_is_desktop_gl(ctx
);
1649 case GL_WRITE_ONLY_ARB
:
1650 accessFlags
= GL_MAP_WRITE_BIT
;
1651 valid_access
= true;
1653 case GL_READ_WRITE_ARB
:
1654 accessFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
1655 valid_access
= _mesa_is_desktop_gl(ctx
);
1658 valid_access
= false;
1662 if (!valid_access
) {
1663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
1667 bufObj
= get_buffer(ctx
, "glMapBufferARB", target
, GL_INVALID_OPERATION
);
1671 if (accessFlags
& GL_MAP_READ_BIT
&&
1672 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
1673 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1674 "glMapBuffer(invalid read flag)");
1678 if (accessFlags
& GL_MAP_WRITE_BIT
&&
1679 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
1680 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1681 "glMapBuffer(invalid write flag)");
1685 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1686 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
1690 if (!bufObj
->Size
) {
1691 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1692 "glMapBuffer(buffer size = 0)");
1696 ASSERT(ctx
->Driver
.MapBufferRange
);
1697 map
= ctx
->Driver
.MapBufferRange(ctx
, 0, bufObj
->Size
, accessFlags
, bufObj
,
1700 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
1704 /* The driver callback should have set these fields.
1705 * This is important because other modules (like VBO) might call
1706 * the driver function directly.
1708 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
1709 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== bufObj
->Size
);
1710 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1711 bufObj
->Mappings
[MAP_USER
].AccessFlags
= accessFlags
;
1714 if (access
== GL_WRITE_ONLY_ARB
|| access
== GL_READ_WRITE_ARB
)
1715 bufObj
->Written
= GL_TRUE
;
1718 printf("glMapBufferARB(%u, sz %ld, access 0x%x)\n",
1719 bufObj
->Name
, bufObj
->Size
, access
);
1720 if (access
== GL_WRITE_ONLY_ARB
) {
1722 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1723 for (i
= 0; i
< bufObj
->Size
; i
++)
1730 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1732 /* buffer is 100 bytes larger than requested, fill with magic value */
1733 for (i
= 0; i
< 100; i
++) {
1734 buf
[bufObj
->Size
- i
- 1] = 123;
1739 return bufObj
->Mappings
[MAP_USER
].Pointer
;
1743 GLboolean GLAPIENTRY
1744 _mesa_UnmapBuffer(GLenum target
)
1746 GET_CURRENT_CONTEXT(ctx
);
1747 struct gl_buffer_object
*bufObj
;
1748 GLboolean status
= GL_TRUE
;
1749 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1751 bufObj
= get_buffer(ctx
, "glUnmapBufferARB", target
, GL_INVALID_OPERATION
);
1755 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
1756 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
1761 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
1762 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
1764 /* check that last 100 bytes are still = magic value */
1765 for (i
= 0; i
< 100; i
++) {
1766 GLuint pos
= bufObj
->Size
- i
- 1;
1767 if (buf
[pos
] != 123) {
1768 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
1769 " at position %d (value = %u)\n",
1777 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
1778 GLuint i
, unchanged
= 0;
1779 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
1781 /* check which bytes changed */
1782 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
1783 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
1790 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
1791 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
1796 status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
1797 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
1798 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
1799 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
1800 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== 0);
1807 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
1809 GET_CURRENT_CONTEXT(ctx
);
1810 struct gl_buffer_object
*bufObj
;
1812 bufObj
= get_buffer(ctx
, "glGetBufferParameterivARB", target
,
1813 GL_INVALID_OPERATION
);
1818 case GL_BUFFER_SIZE_ARB
:
1819 *params
= (GLint
) bufObj
->Size
;
1821 case GL_BUFFER_USAGE_ARB
:
1822 *params
= bufObj
->Usage
;
1824 case GL_BUFFER_ACCESS_ARB
:
1825 *params
= simplified_access_mode(ctx
,
1826 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1828 case GL_BUFFER_MAPPED_ARB
:
1829 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1831 case GL_BUFFER_ACCESS_FLAGS
:
1832 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1834 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1836 case GL_BUFFER_MAP_OFFSET
:
1837 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1839 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Offset
;
1841 case GL_BUFFER_MAP_LENGTH
:
1842 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1844 *params
= (GLint
) bufObj
->Mappings
[MAP_USER
].Length
;
1846 case GL_BUFFER_IMMUTABLE_STORAGE
:
1847 if (!ctx
->Extensions
.ARB_buffer_storage
)
1849 *params
= bufObj
->Immutable
;
1851 case GL_BUFFER_STORAGE_FLAGS
:
1852 if (!ctx
->Extensions
.ARB_buffer_storage
)
1854 *params
= bufObj
->StorageFlags
;
1857 ; /* fall-through */
1861 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname=%s)",
1862 _mesa_lookup_enum_by_nr(pname
));
1868 * This is pretty much a duplicate of GetBufferParameteriv() but the
1869 * GL_BUFFER_SIZE_ARB attribute will be 64-bits on a 64-bit system.
1872 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
1874 GET_CURRENT_CONTEXT(ctx
);
1875 struct gl_buffer_object
*bufObj
;
1877 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
1878 GL_INVALID_OPERATION
);
1883 case GL_BUFFER_SIZE_ARB
:
1884 *params
= bufObj
->Size
;
1886 case GL_BUFFER_USAGE_ARB
:
1887 *params
= bufObj
->Usage
;
1889 case GL_BUFFER_ACCESS_ARB
:
1890 *params
= simplified_access_mode(ctx
,
1891 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
1893 case GL_BUFFER_ACCESS_FLAGS
:
1894 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1896 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
1898 case GL_BUFFER_MAPPED_ARB
:
1899 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
1901 case GL_BUFFER_MAP_OFFSET
:
1902 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1904 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
1906 case GL_BUFFER_MAP_LENGTH
:
1907 if (!ctx
->Extensions
.ARB_map_buffer_range
)
1909 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
1911 case GL_BUFFER_IMMUTABLE_STORAGE
:
1912 if (!ctx
->Extensions
.ARB_buffer_storage
)
1914 *params
= bufObj
->Immutable
;
1916 case GL_BUFFER_STORAGE_FLAGS
:
1917 if (!ctx
->Extensions
.ARB_buffer_storage
)
1919 *params
= bufObj
->StorageFlags
;
1922 ; /* fall-through */
1926 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameteri64v(pname=%s)",
1927 _mesa_lookup_enum_by_nr(pname
));
1932 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
1934 GET_CURRENT_CONTEXT(ctx
);
1935 struct gl_buffer_object
* bufObj
;
1937 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
1938 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
1942 bufObj
= get_buffer(ctx
, "glGetBufferPointervARB", target
,
1943 GL_INVALID_OPERATION
);
1947 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
1952 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
1953 GLintptr readOffset
, GLintptr writeOffset
,
1956 GET_CURRENT_CONTEXT(ctx
);
1957 struct gl_buffer_object
*src
, *dst
;
1959 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
1960 GL_INVALID_OPERATION
);
1964 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
1965 GL_INVALID_OPERATION
);
1969 if (_mesa_check_disallowed_mapping(src
)) {
1970 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1971 "glCopyBufferSubData(readBuffer is mapped)");
1975 if (_mesa_check_disallowed_mapping(dst
)) {
1976 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1977 "glCopyBufferSubData(writeBuffer is mapped)");
1981 if (readOffset
< 0) {
1982 _mesa_error(ctx
, GL_INVALID_VALUE
,
1983 "glCopyBufferSubData(readOffset = %d)", (int) readOffset
);
1987 if (writeOffset
< 0) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
,
1989 "glCopyBufferSubData(writeOffset = %d)", (int) writeOffset
);
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glCopyBufferSubData(writeOffset = %d)", (int) size
);
1999 if (readOffset
+ size
> src
->Size
) {
2000 _mesa_error(ctx
, GL_INVALID_VALUE
,
2001 "glCopyBufferSubData(readOffset + size = %d)",
2002 (int) (readOffset
+ size
));
2006 if (writeOffset
+ size
> dst
->Size
) {
2007 _mesa_error(ctx
, GL_INVALID_VALUE
,
2008 "glCopyBufferSubData(writeOffset + size = %d)",
2009 (int) (writeOffset
+ size
));
2014 if (readOffset
+ size
<= writeOffset
) {
2017 else if (writeOffset
+ size
<= readOffset
) {
2021 /* overlapping src/dst is illegal */
2022 _mesa_error(ctx
, GL_INVALID_VALUE
,
2023 "glCopyBufferSubData(overlapping src/dst)");
2028 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2033 * See GL_ARB_map_buffer_range spec
2036 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2039 GET_CURRENT_CONTEXT(ctx
);
2040 struct gl_buffer_object
*bufObj
;
2042 GLbitfield allowed_access
;
2044 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
2046 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2047 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2048 "glMapBufferRange(extension not supported)");
2053 _mesa_error(ctx
, GL_INVALID_VALUE
,
2054 "glMapBufferRange(offset = %ld)", (long)offset
);
2059 _mesa_error(ctx
, GL_INVALID_VALUE
,
2060 "glMapBufferRange(length = %ld)", (long)length
);
2064 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2066 * "An INVALID_OPERATION error is generated for any of the following
2069 * * <length> is zero."
2071 if (_mesa_is_gles(ctx
) && length
== 0) {
2072 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2073 "glMapBufferRange(length = 0)");
2077 allowed_access
= GL_MAP_READ_BIT
|
2079 GL_MAP_INVALIDATE_RANGE_BIT
|
2080 GL_MAP_INVALIDATE_BUFFER_BIT
|
2081 GL_MAP_FLUSH_EXPLICIT_BIT
|
2082 GL_MAP_UNSYNCHRONIZED_BIT
;
2084 if (ctx
->Extensions
.ARB_buffer_storage
) {
2085 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2086 GL_MAP_COHERENT_BIT
;
2089 if (access
& ~allowed_access
) {
2090 /* generate an error if any other than allowed bit is set */
2091 _mesa_error(ctx
, GL_INVALID_VALUE
, "glMapBufferRange(access)");
2095 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2096 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2097 "glMapBufferRange(access indicates neither read or write)");
2101 if ((access
& GL_MAP_READ_BIT
) &&
2102 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2103 GL_MAP_INVALIDATE_BUFFER_BIT
|
2104 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2105 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2106 "glMapBufferRange(invalid access flags)");
2110 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2111 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2113 "glMapBufferRange(invalid access flags)");
2117 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2121 if (access
& GL_MAP_READ_BIT
&&
2122 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2123 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2124 "glMapBufferRange(invalid read flag)");
2128 if (access
& GL_MAP_WRITE_BIT
&&
2129 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2130 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2131 "glMapBufferRange(invalid write flag)");
2135 if (access
& GL_MAP_COHERENT_BIT
&&
2136 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2138 "glMapBufferRange(invalid coherent flag)");
2142 if (access
& GL_MAP_PERSISTENT_BIT
&&
2143 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "glMapBufferRange(invalid persistent flag)");
2149 if (offset
+ length
> bufObj
->Size
) {
2150 _mesa_error(ctx
, GL_INVALID_VALUE
,
2151 "glMapBufferRange(offset + length > size)");
2155 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2156 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2157 "glMapBufferRange(buffer already mapped)");
2161 if (!bufObj
->Size
) {
2162 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2163 "glMapBufferRange(buffer size = 0)");
2167 /* Mapping zero bytes should return a non-null pointer. */
2169 static long dummy
= 0;
2170 bufObj
->Mappings
[MAP_USER
].Pointer
= &dummy
;
2171 bufObj
->Mappings
[MAP_USER
].Length
= length
;
2172 bufObj
->Mappings
[MAP_USER
].Offset
= offset
;
2173 bufObj
->Mappings
[MAP_USER
].AccessFlags
= access
;
2174 return bufObj
->Mappings
[MAP_USER
].Pointer
;
2177 ASSERT(ctx
->Driver
.MapBufferRange
);
2178 map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2181 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(map failed)");
2184 /* The driver callback should have set all these fields.
2185 * This is important because other modules (like VBO) might call
2186 * the driver function directly.
2188 ASSERT(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2189 ASSERT(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2190 ASSERT(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2191 ASSERT(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2199 * See GL_ARB_map_buffer_range spec
2202 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
)
2204 GET_CURRENT_CONTEXT(ctx
);
2205 struct gl_buffer_object
*bufObj
;
2207 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2208 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2209 "glFlushMappedBufferRange(extension not supported)");
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glFlushMappedBufferRange(offset = %ld)", (long)offset
);
2220 _mesa_error(ctx
, GL_INVALID_VALUE
,
2221 "glFlushMappedBufferRange(length = %ld)", (long)length
);
2225 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2226 GL_INVALID_OPERATION
);
2230 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2231 /* buffer is not mapped */
2232 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2233 "glFlushMappedBufferRange(buffer is not mapped)");
2237 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2238 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2240 "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
2244 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2245 _mesa_error(ctx
, GL_INVALID_VALUE
,
2246 "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
2247 (long)offset
, (long)length
,
2248 (long)bufObj
->Mappings
[MAP_USER
].Length
);
2252 ASSERT(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2254 if (ctx
->Driver
.FlushMappedBufferRange
)
2255 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2261 buffer_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2263 struct gl_buffer_object
*bufObj
;
2266 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2268 _mesa_error(ctx
, GL_INVALID_VALUE
,
2269 "glObjectPurgeable(name = 0x%x)", name
);
2272 if (!_mesa_is_bufferobj(bufObj
)) {
2273 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glObjectPurgeable(buffer 0)" );
2277 if (bufObj
->Purgeable
) {
2278 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2279 "glObjectPurgeable(name = 0x%x) is already purgeable", name
);
2280 return GL_VOLATILE_APPLE
;
2283 bufObj
->Purgeable
= GL_TRUE
;
2285 retval
= GL_VOLATILE_APPLE
;
2286 if (ctx
->Driver
.BufferObjectPurgeable
)
2287 retval
= ctx
->Driver
.BufferObjectPurgeable(ctx
, bufObj
, option
);
2294 renderbuffer_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2296 struct gl_renderbuffer
*bufObj
;
2299 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2301 _mesa_error(ctx
, GL_INVALID_VALUE
,
2302 "glObjectUnpurgeable(name = 0x%x)", name
);
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
.RenderObjectPurgeable
)
2316 retval
= ctx
->Driver
.RenderObjectPurgeable(ctx
, bufObj
, option
);
2323 texture_object_purgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2325 struct gl_texture_object
*bufObj
;
2328 bufObj
= _mesa_lookup_texture(ctx
, name
);
2330 _mesa_error(ctx
, GL_INVALID_VALUE
,
2331 "glObjectPurgeable(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
.TextureObjectPurgeable
)
2345 retval
= ctx
->Driver
.TextureObjectPurgeable(ctx
, bufObj
, option
);
2352 _mesa_ObjectPurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2356 GET_CURRENT_CONTEXT(ctx
);
2357 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2360 _mesa_error(ctx
, GL_INVALID_VALUE
,
2361 "glObjectPurgeable(name = 0x%x)", name
);
2366 case GL_VOLATILE_APPLE
:
2367 case GL_RELEASED_APPLE
:
2371 _mesa_error(ctx
, GL_INVALID_ENUM
,
2372 "glObjectPurgeable(name = 0x%x) invalid option: %d",
2377 switch (objectType
) {
2379 retval
= texture_object_purgeable(ctx
, name
, option
);
2381 case GL_RENDERBUFFER_EXT
:
2382 retval
= renderbuffer_purgeable(ctx
, name
, option
);
2384 case GL_BUFFER_OBJECT_APPLE
:
2385 retval
= buffer_object_purgeable(ctx
, name
, option
);
2388 _mesa_error(ctx
, GL_INVALID_ENUM
,
2389 "glObjectPurgeable(name = 0x%x) invalid type: %d",
2394 /* In strict conformance to the spec, we must only return VOLATILE when
2395 * when passed the VOLATILE option. Madness.
2397 * XXX First fix the spec, then fix me.
2399 return option
== GL_VOLATILE_APPLE
? GL_VOLATILE_APPLE
: retval
;
2404 buffer_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2406 struct gl_buffer_object
*bufObj
;
2409 bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2411 _mesa_error(ctx
, GL_INVALID_VALUE
,
2412 "glObjectUnpurgeable(name = 0x%x)", name
);
2416 if (! bufObj
->Purgeable
) {
2417 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2418 "glObjectUnpurgeable(name = 0x%x) object is "
2419 " already \"unpurged\"", name
);
2423 bufObj
->Purgeable
= GL_FALSE
;
2426 if (ctx
->Driver
.BufferObjectUnpurgeable
)
2427 retval
= ctx
->Driver
.BufferObjectUnpurgeable(ctx
, bufObj
, option
);
2434 renderbuffer_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2436 struct gl_renderbuffer
*bufObj
;
2439 bufObj
= _mesa_lookup_renderbuffer(ctx
, name
);
2441 _mesa_error(ctx
, GL_INVALID_VALUE
,
2442 "glObjectUnpurgeable(name = 0x%x)", name
);
2446 if (! bufObj
->Purgeable
) {
2447 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2448 "glObjectUnpurgeable(name = 0x%x) object is "
2449 " already \"unpurged\"", name
);
2453 bufObj
->Purgeable
= GL_FALSE
;
2456 if (ctx
->Driver
.RenderObjectUnpurgeable
)
2457 retval
= ctx
->Driver
.RenderObjectUnpurgeable(ctx
, bufObj
, option
);
2464 texture_object_unpurgeable(struct gl_context
*ctx
, GLuint name
, GLenum option
)
2466 struct gl_texture_object
*bufObj
;
2469 bufObj
= _mesa_lookup_texture(ctx
, name
);
2471 _mesa_error(ctx
, GL_INVALID_VALUE
,
2472 "glObjectUnpurgeable(name = 0x%x)", name
);
2476 if (! bufObj
->Purgeable
) {
2477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2478 "glObjectUnpurgeable(name = 0x%x) object is"
2479 " already \"unpurged\"", name
);
2483 bufObj
->Purgeable
= GL_FALSE
;
2486 if (ctx
->Driver
.TextureObjectUnpurgeable
)
2487 retval
= ctx
->Driver
.TextureObjectUnpurgeable(ctx
, bufObj
, option
);
2494 _mesa_ObjectUnpurgeableAPPLE(GLenum objectType
, GLuint name
, GLenum option
)
2496 GET_CURRENT_CONTEXT(ctx
);
2497 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
2500 _mesa_error(ctx
, GL_INVALID_VALUE
,
2501 "glObjectUnpurgeable(name = 0x%x)", name
);
2506 case GL_RETAINED_APPLE
:
2507 case GL_UNDEFINED_APPLE
:
2511 _mesa_error(ctx
, GL_INVALID_ENUM
,
2512 "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
2517 switch (objectType
) {
2518 case GL_BUFFER_OBJECT_APPLE
:
2519 return buffer_object_unpurgeable(ctx
, name
, option
);
2521 return texture_object_unpurgeable(ctx
, name
, option
);
2522 case GL_RENDERBUFFER_EXT
:
2523 return renderbuffer_unpurgeable(ctx
, name
, option
);
2525 _mesa_error(ctx
, GL_INVALID_ENUM
,
2526 "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
2534 get_buffer_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2535 GLenum pname
, GLint
*params
)
2537 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
2539 _mesa_error(ctx
, GL_INVALID_VALUE
,
2540 "glGetObjectParameteriv(name = 0x%x) invalid object", name
);
2545 case GL_PURGEABLE_APPLE
:
2546 *params
= bufObj
->Purgeable
;
2549 _mesa_error(ctx
, GL_INVALID_ENUM
,
2550 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2558 get_renderbuffer_parameteriv(struct gl_context
*ctx
, GLuint name
,
2559 GLenum pname
, GLint
*params
)
2561 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
2563 _mesa_error(ctx
, GL_INVALID_VALUE
,
2564 "glObjectUnpurgeable(name = 0x%x)", name
);
2569 case GL_PURGEABLE_APPLE
:
2570 *params
= rb
->Purgeable
;
2573 _mesa_error(ctx
, GL_INVALID_ENUM
,
2574 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2582 get_texture_object_parameteriv(struct gl_context
*ctx
, GLuint name
,
2583 GLenum pname
, GLint
*params
)
2585 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
2587 _mesa_error(ctx
, GL_INVALID_VALUE
,
2588 "glObjectUnpurgeable(name = 0x%x)", name
);
2593 case GL_PURGEABLE_APPLE
:
2594 *params
= texObj
->Purgeable
;
2597 _mesa_error(ctx
, GL_INVALID_ENUM
,
2598 "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
2606 _mesa_GetObjectParameterivAPPLE(GLenum objectType
, GLuint name
, GLenum pname
,
2609 GET_CURRENT_CONTEXT(ctx
);
2612 _mesa_error(ctx
, GL_INVALID_VALUE
,
2613 "glGetObjectParameteriv(name = 0x%x)", name
);
2617 switch (objectType
) {
2619 get_texture_object_parameteriv(ctx
, name
, pname
, params
);
2621 case GL_BUFFER_OBJECT_APPLE
:
2622 get_buffer_object_parameteriv(ctx
, name
, pname
, params
);
2624 case GL_RENDERBUFFER_EXT
:
2625 get_renderbuffer_parameteriv(ctx
, name
, pname
, params
);
2628 _mesa_error(ctx
, GL_INVALID_ENUM
,
2629 "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
2635 * Binds a buffer object to a uniform buffer binding point.
2637 * The caller is responsible for flushing vertices and updating
2641 set_ubo_binding(struct gl_context
*ctx
,
2642 struct gl_uniform_buffer_binding
*binding
,
2643 struct gl_buffer_object
*bufObj
,
2648 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2650 binding
->Offset
= offset
;
2651 binding
->Size
= size
;
2652 binding
->AutomaticSize
= autoSize
;
2654 /* If this is a real buffer object, mark it has having been used
2655 * at some point as a UBO.
2658 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
2662 * Binds a buffer object to a uniform buffer binding point.
2664 * Unlike set_ubo_binding(), this function also flushes vertices
2665 * and updates NewDriverState. It also checks if the binding
2666 * has actually changed before updating it.
2669 bind_uniform_buffer(struct gl_context
*ctx
,
2671 struct gl_buffer_object
*bufObj
,
2676 struct gl_uniform_buffer_binding
*binding
=
2677 &ctx
->UniformBufferBindings
[index
];
2679 if (binding
->BufferObject
== bufObj
&&
2680 binding
->Offset
== offset
&&
2681 binding
->Size
== size
&&
2682 binding
->AutomaticSize
== autoSize
) {
2686 FLUSH_VERTICES(ctx
, 0);
2687 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2689 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
2693 * Bind a region of a buffer object to a uniform block binding point.
2694 * \param index the uniform buffer binding point index
2695 * \param bufObj the buffer object
2696 * \param offset offset to the start of buffer object region
2697 * \param size size of the buffer object region
2700 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
2702 struct gl_buffer_object
*bufObj
,
2706 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2707 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
2711 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
2712 _mesa_error(ctx
, GL_INVALID_VALUE
,
2713 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
2714 ctx
->Const
.UniformBufferOffsetAlignment
);
2718 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2723 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2724 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
2729 * Bind a buffer object to a uniform block binding point.
2730 * As above, but offset = 0.
2733 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
2735 struct gl_buffer_object
*bufObj
)
2737 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
2738 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
2742 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
2744 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2745 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
2747 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
2751 * Binds a buffer object to an atomic buffer binding point.
2753 * The caller is responsible for validating the offset,
2754 * flushing the vertices and updating NewDriverState.
2757 set_atomic_buffer_binding(struct gl_context
*ctx
,
2758 struct gl_atomic_buffer_binding
*binding
,
2759 struct gl_buffer_object
*bufObj
,
2763 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
2765 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
2766 binding
->Offset
= -1;
2769 binding
->Offset
= offset
;
2770 binding
->Size
= size
;
2771 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
2776 * Binds a buffer object to an atomic buffer binding point.
2778 * Unlike set_atomic_buffer_binding(), this function also validates the
2779 * index and offset, flushes vertices, and updates NewDriverState.
2780 * It also checks if the binding has actually changing before
2784 bind_atomic_buffer(struct gl_context
*ctx
,
2786 struct gl_buffer_object
*bufObj
,
2791 struct gl_atomic_buffer_binding
*binding
;
2793 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
2794 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
2798 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
2799 _mesa_error(ctx
, GL_INVALID_VALUE
,
2800 "%s(offset misaligned %d/%d)", name
, (int) offset
,
2801 ATOMIC_COUNTER_SIZE
);
2805 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
2807 binding
= &ctx
->AtomicBufferBindings
[index
];
2808 if (binding
->BufferObject
== bufObj
&&
2809 binding
->Offset
== offset
&&
2810 binding
->Size
== size
) {
2814 FLUSH_VERTICES(ctx
, 0);
2815 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
2817 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
2821 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
2823 const GLintptr
*offsets
,
2824 const GLsizeiptr
*sizes
)
2826 if (offsets
[index
] < 0) {
2827 /* The ARB_multi_bind spec says:
2829 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2830 * value in <offsets> is less than zero (per binding)."
2832 _mesa_error(ctx
, GL_INVALID_VALUE
,
2833 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
2834 index
, (int64_t) offsets
[index
]);
2838 if (sizes
[index
] <= 0) {
2839 /* The ARB_multi_bind spec says:
2841 * "An INVALID_VALUE error is generated by BindBuffersRange if any
2842 * value in <sizes> is less than or equal to zero (per binding)."
2844 _mesa_error(ctx
, GL_INVALID_VALUE
,
2845 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
2846 index
, (int64_t) sizes
[index
]);
2854 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
2855 GLuint first
, GLsizei count
,
2858 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
2859 _mesa_error(ctx
, GL_INVALID_ENUM
,
2860 "%s(target=GL_UNIFORM_BUFFER)", caller
);
2864 /* The ARB_multi_bind_spec says:
2866 * "An INVALID_OPERATION error is generated if <first> + <count> is
2867 * greater than the number of target-specific indexed binding points,
2868 * as described in section 6.7.1."
2870 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
2871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2872 "%s(first=%u + count=%d > the value of "
2873 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
2874 caller
, first
, count
,
2875 ctx
->Const
.MaxUniformBufferBindings
);
2883 * Unbind all uniform buffers in the range
2884 * <first> through <first>+<count>-1
2887 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
2889 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
2892 for (i
= 0; i
< count
; i
++)
2893 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
2894 bufObj
, -1, -1, GL_TRUE
);
2898 bind_uniform_buffers_base(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2899 const GLuint
*buffers
)
2903 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, "glBindBuffersBase"))
2906 /* Assume that at least one binding will be changed */
2907 FLUSH_VERTICES(ctx
, 0);
2908 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2911 /* The ARB_multi_bind spec says:
2913 * "If <buffers> is NULL, all bindings from <first> through
2914 * <first>+<count>-1 are reset to their unbound (zero) state."
2916 unbind_uniform_buffers(ctx
, first
, count
);
2920 /* Note that the error semantics for multi-bind commands differ from
2921 * those of other GL commands.
2923 * The Issues section in the ARB_multi_bind spec says:
2925 * "(11) Typically, OpenGL specifies that if an error is generated by a
2926 * command, that command has no effect. This is somewhat
2927 * unfortunate for multi-bind commands, because it would require a
2928 * first pass to scan the entire list of bound objects for errors
2929 * and then a second pass to actually perform the bindings.
2930 * Should we have different error semantics?
2932 * RESOLVED: Yes. In this specification, when the parameters for
2933 * one of the <count> binding points are invalid, that binding point
2934 * is not updated and an error will be generated. However, other
2935 * binding points in the same command will be updated if their
2936 * parameters are valid and no other error occurs."
2939 _mesa_begin_bufferobj_lookups(ctx
);
2941 for (i
= 0; i
< count
; i
++) {
2942 struct gl_uniform_buffer_binding
*binding
=
2943 &ctx
->UniformBufferBindings
[first
+ i
];
2944 struct gl_buffer_object
*bufObj
;
2946 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
2947 bufObj
= binding
->BufferObject
;
2949 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
2950 "glBindBuffersBase");
2953 if (bufObj
== ctx
->Shared
->NullBufferObj
)
2954 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_TRUE
);
2956 set_ubo_binding(ctx
, binding
, bufObj
, 0, 0, GL_TRUE
);
2960 _mesa_end_bufferobj_lookups(ctx
);
2964 bind_uniform_buffers_range(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
2965 const GLuint
*buffers
,
2966 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
2970 if (!error_check_bind_uniform_buffers(ctx
, first
, count
,
2971 "glBindBuffersRange"))
2974 /* Assume that at least one binding will be changed */
2975 FLUSH_VERTICES(ctx
, 0);
2976 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
2979 /* The ARB_multi_bind spec says:
2981 * "If <buffers> is NULL, all bindings from <first> through
2982 * <first>+<count>-1 are reset to their unbound (zero) state.
2983 * In this case, the offsets and sizes associated with the
2984 * binding points are set to default values, ignoring
2985 * <offsets> and <sizes>."
2987 unbind_uniform_buffers(ctx
, first
, count
);
2991 /* Note that the error semantics for multi-bind commands differ from
2992 * those of other GL commands.
2994 * The Issues section in the ARB_multi_bind spec says:
2996 * "(11) Typically, OpenGL specifies that if an error is generated by a
2997 * command, that command has no effect. This is somewhat
2998 * unfortunate for multi-bind commands, because it would require a
2999 * first pass to scan the entire list of bound objects for errors
3000 * and then a second pass to actually perform the bindings.
3001 * Should we have different error semantics?
3003 * RESOLVED: Yes. In this specification, when the parameters for
3004 * one of the <count> binding points are invalid, that binding point
3005 * is not updated and an error will be generated. However, other
3006 * binding points in the same command will be updated if their
3007 * parameters are valid and no other error occurs."
3010 _mesa_begin_bufferobj_lookups(ctx
);
3012 for (i
= 0; i
< count
; i
++) {
3013 struct gl_uniform_buffer_binding
*binding
=
3014 &ctx
->UniformBufferBindings
[first
+ i
];
3015 struct gl_buffer_object
*bufObj
;
3017 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3020 /* The ARB_multi_bind spec says:
3022 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3023 * pair of values in <offsets> and <sizes> does not respectively
3024 * satisfy the constraints described for those parameters for the
3025 * specified target, as described in section 6.7.1 (per binding)."
3027 * Section 6.7.1 refers to table 6.5, which says:
3029 * "┌───────────────────────────────────────────────────────────────┐
3030 * │ Uniform buffer array bindings (see sec. 7.6) │
3031 * ├─────────────────────┬─────────────────────────────────────────┤
3033 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3034 * │ │ OFFSET_ALIGNMENT │
3036 * │ size restriction │ none │
3037 * └─────────────────────┴─────────────────────────────────────────┘"
3039 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3040 _mesa_error(ctx
, GL_INVALID_VALUE
,
3041 "glBindBuffersRange(offsets[%u]=%" PRId64
3042 " is misaligned; it must be a multiple of the value of "
3043 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3044 "target=GL_UNIFORM_BUFFER)",
3045 i
, (int64_t) offsets
[i
],
3046 ctx
->Const
.UniformBufferOffsetAlignment
);
3050 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3051 bufObj
= binding
->BufferObject
;
3053 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3054 "glBindBuffersRange");
3057 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3058 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, GL_FALSE
);
3060 set_ubo_binding(ctx
, binding
, bufObj
,
3061 offsets
[i
], sizes
[i
], GL_FALSE
);
3065 _mesa_end_bufferobj_lookups(ctx
);
3069 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3070 struct gl_transform_feedback_object
*tfObj
,
3071 GLuint first
, GLsizei count
, const char *caller
)
3073 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3074 _mesa_error(ctx
, GL_INVALID_ENUM
,
3075 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3079 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3081 * "An INVALID_OPERATION error is generated :
3084 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3085 * FEEDBACK_BUFFER and transform feedback is currently active."
3087 * We assume that this is also meant to apply to BindBuffersRange
3088 * and BindBuffersBase.
3090 if (tfObj
->Active
) {
3091 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3092 "%s(Changing transform feedback buffers while "
3093 "transform feedback is active)", caller
);
3097 /* The ARB_multi_bind_spec says:
3099 * "An INVALID_OPERATION error is generated if <first> + <count> is
3100 * greater than the number of target-specific indexed binding points,
3101 * as described in section 6.7.1."
3103 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3104 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3105 "%s(first=%u + count=%d > the value of "
3106 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3107 caller
, first
, count
,
3108 ctx
->Const
.MaxTransformFeedbackBuffers
);
3116 * Unbind all transform feedback buffers in the range
3117 * <first> through <first>+<count>-1
3120 unbind_xfb_buffers(struct gl_context
*ctx
,
3121 struct gl_transform_feedback_object
*tfObj
,
3122 GLuint first
, GLsizei count
)
3124 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3127 for (i
= 0; i
< count
; i
++)
3128 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3133 bind_xfb_buffers_base(struct gl_context
*ctx
,
3134 GLuint first
, GLsizei count
,
3135 const GLuint
*buffers
)
3137 struct gl_transform_feedback_object
*tfObj
=
3138 ctx
->TransformFeedback
.CurrentObject
;
3141 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3142 "glBindBuffersBase"))
3145 /* Assume that at least one binding will be changed */
3146 FLUSH_VERTICES(ctx
, 0);
3147 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3150 /* The ARB_multi_bind spec says:
3152 * "If <buffers> is NULL, all bindings from <first> through
3153 * <first>+<count>-1 are reset to their unbound (zero) state."
3155 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3159 /* Note that the error semantics for multi-bind commands differ from
3160 * those of other GL commands.
3162 * The Issues section in the ARB_multi_bind spec says:
3164 * "(11) Typically, OpenGL specifies that if an error is generated by a
3165 * command, that command has no effect. This is somewhat
3166 * unfortunate for multi-bind commands, because it would require a
3167 * first pass to scan the entire list of bound objects for errors
3168 * and then a second pass to actually perform the bindings.
3169 * Should we have different error semantics?
3171 * RESOLVED: Yes. In this specification, when the parameters for
3172 * one of the <count> binding points are invalid, that binding point
3173 * is not updated and an error will be generated. However, other
3174 * binding points in the same command will be updated if their
3175 * parameters are valid and no other error occurs."
3178 _mesa_begin_bufferobj_lookups(ctx
);
3180 for (i
= 0; i
< count
; i
++) {
3181 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[first
+ i
];
3182 struct gl_buffer_object
*bufObj
;
3184 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3185 bufObj
= boundBufObj
;
3187 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3188 "glBindBuffersBase");
3191 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3195 _mesa_end_bufferobj_lookups(ctx
);
3199 bind_xfb_buffers_range(struct gl_context
*ctx
,
3200 GLuint first
, GLsizei count
,
3201 const GLuint
*buffers
,
3202 const GLintptr
*offsets
,
3203 const GLsizeiptr
*sizes
)
3205 struct gl_transform_feedback_object
*tfObj
=
3206 ctx
->TransformFeedback
.CurrentObject
;
3209 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
,
3210 "glBindBuffersRange"))
3213 /* Assume that at least one binding will be changed */
3214 FLUSH_VERTICES(ctx
, 0);
3215 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3218 /* The ARB_multi_bind spec says:
3220 * "If <buffers> is NULL, all bindings from <first> through
3221 * <first>+<count>-1 are reset to their unbound (zero) state.
3222 * In this case, the offsets and sizes associated with the
3223 * binding points are set to default values, ignoring
3224 * <offsets> and <sizes>."
3226 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3230 /* Note that the error semantics for multi-bind commands differ from
3231 * those of other GL commands.
3233 * The Issues section in the ARB_multi_bind spec says:
3235 * "(11) Typically, OpenGL specifies that if an error is generated by a
3236 * command, that command has no effect. This is somewhat
3237 * unfortunate for multi-bind commands, because it would require a
3238 * first pass to scan the entire list of bound objects for errors
3239 * and then a second pass to actually perform the bindings.
3240 * Should we have different error semantics?
3242 * RESOLVED: Yes. In this specification, when the parameters for
3243 * one of the <count> binding points are invalid, that binding point
3244 * is not updated and an error will be generated. However, other
3245 * binding points in the same command will be updated if their
3246 * parameters are valid and no other error occurs."
3249 _mesa_begin_bufferobj_lookups(ctx
);
3251 for (i
= 0; i
< count
; i
++) {
3252 const GLuint index
= first
+ i
;
3253 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3254 struct gl_buffer_object
*bufObj
;
3256 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3259 /* The ARB_multi_bind spec says:
3261 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3262 * pair of values in <offsets> and <sizes> does not respectively
3263 * satisfy the constraints described for those parameters for the
3264 * specified target, as described in section 6.7.1 (per binding)."
3266 * Section 6.7.1 refers to table 6.5, which says:
3268 * "┌───────────────────────────────────────────────────────────────┐
3269 * │ Transform feedback array bindings (see sec. 13.2.2) │
3270 * ├───────────────────────┬───────────────────────────────────────┤
3272 * │ offset restriction │ multiple of 4 │
3274 * │ size restriction │ multiple of 4 │
3275 * └───────────────────────┴───────────────────────────────────────┘"
3277 if (offsets
[i
] & 0x3) {
3278 _mesa_error(ctx
, GL_INVALID_VALUE
,
3279 "glBindBuffersRange(offsets[%u]=%" PRId64
3280 " is misaligned; it must be a multiple of 4 when "
3281 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3282 i
, (int64_t) offsets
[i
]);
3286 if (sizes
[i
] & 0x3) {
3287 _mesa_error(ctx
, GL_INVALID_VALUE
,
3288 "glBindBuffersRange(sizes[%u]=%" PRId64
3289 " is misaligned; it must be a multiple of 4 when "
3290 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3291 i
, (int64_t) sizes
[i
]);
3295 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3296 bufObj
= boundBufObj
;
3298 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3299 "glBindBuffersRange");
3302 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
3303 offsets
[i
], sizes
[i
]);
3306 _mesa_end_bufferobj_lookups(ctx
);
3310 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
3311 GLuint first
, GLsizei count
,
3314 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
3315 _mesa_error(ctx
, GL_INVALID_ENUM
,
3316 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
3320 /* The ARB_multi_bind_spec says:
3322 * "An INVALID_OPERATION error is generated if <first> + <count> is
3323 * greater than the number of target-specific indexed binding points,
3324 * as described in section 6.7.1."
3326 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
3327 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3328 "%s(first=%u + count=%d > the value of "
3329 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
3330 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
3338 * Unbind all atomic counter buffers in the range
3339 * <first> through <first>+<count>-1
3342 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3344 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3347 for (i
= 0; i
< count
; i
++)
3348 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
3353 bind_atomic_buffers_base(struct gl_context
*ctx
,
3356 const GLuint
*buffers
)
3360 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3361 "glBindBuffersBase"))
3364 /* Assume that at least one binding will be changed */
3365 FLUSH_VERTICES(ctx
, 0);
3366 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3369 /* The ARB_multi_bind spec says:
3371 * "If <buffers> is NULL, all bindings from <first> through
3372 * <first>+<count>-1 are reset to their unbound (zero) state."
3374 unbind_atomic_buffers(ctx
, first
, count
);
3378 /* Note that the error semantics for multi-bind commands differ from
3379 * those of other GL commands.
3381 * The Issues section in the ARB_multi_bind spec says:
3383 * "(11) Typically, OpenGL specifies that if an error is generated by a
3384 * command, that command has no effect. This is somewhat
3385 * unfortunate for multi-bind commands, because it would require a
3386 * first pass to scan the entire list of bound objects for errors
3387 * and then a second pass to actually perform the bindings.
3388 * Should we have different error semantics?
3390 * RESOLVED: Yes. In this specification, when the parameters for
3391 * one of the <count> binding points are invalid, that binding point
3392 * is not updated and an error will be generated. However, other
3393 * binding points in the same command will be updated if their
3394 * parameters are valid and no other error occurs."
3397 _mesa_begin_bufferobj_lookups(ctx
);
3399 for (i
= 0; i
< count
; i
++) {
3400 struct gl_atomic_buffer_binding
*binding
=
3401 &ctx
->AtomicBufferBindings
[first
+ i
];
3402 struct gl_buffer_object
*bufObj
;
3404 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3405 bufObj
= binding
->BufferObject
;
3407 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3408 "glBindBuffersBase");
3411 set_atomic_buffer_binding(ctx
, binding
, bufObj
, 0, 0);
3414 _mesa_end_bufferobj_lookups(ctx
);
3418 bind_atomic_buffers_range(struct gl_context
*ctx
,
3421 const GLuint
*buffers
,
3422 const GLintptr
*offsets
,
3423 const GLsizeiptr
*sizes
)
3427 if (!error_check_bind_atomic_buffers(ctx
, first
, count
,
3428 "glBindBuffersRange"))
3431 /* Assume that at least one binding will be changed */
3432 FLUSH_VERTICES(ctx
, 0);
3433 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3436 /* The ARB_multi_bind spec says:
3438 * "If <buffers> is NULL, all bindings from <first> through
3439 * <first>+<count>-1 are reset to their unbound (zero) state.
3440 * In this case, the offsets and sizes associated with the
3441 * binding points are set to default values, ignoring
3442 * <offsets> and <sizes>."
3444 unbind_atomic_buffers(ctx
, first
, count
);
3448 /* Note that the error semantics for multi-bind commands differ from
3449 * those of other GL commands.
3451 * The Issues section in the ARB_multi_bind spec says:
3453 * "(11) Typically, OpenGL specifies that if an error is generated by a
3454 * command, that command has no effect. This is somewhat
3455 * unfortunate for multi-bind commands, because it would require a
3456 * first pass to scan the entire list of bound objects for errors
3457 * and then a second pass to actually perform the bindings.
3458 * Should we have different error semantics?
3460 * RESOLVED: Yes. In this specification, when the parameters for
3461 * one of the <count> binding points are invalid, that binding point
3462 * is not updated and an error will be generated. However, other
3463 * binding points in the same command will be updated if their
3464 * parameters are valid and no other error occurs."
3467 _mesa_begin_bufferobj_lookups(ctx
);
3469 for (i
= 0; i
< count
; i
++) {
3470 struct gl_atomic_buffer_binding
*binding
=
3471 &ctx
->AtomicBufferBindings
[first
+ i
];
3472 struct gl_buffer_object
*bufObj
;
3474 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3477 /* The ARB_multi_bind spec says:
3479 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3480 * pair of values in <offsets> and <sizes> does not respectively
3481 * satisfy the constraints described for those parameters for the
3482 * specified target, as described in section 6.7.1 (per binding)."
3484 * Section 6.7.1 refers to table 6.5, which says:
3486 * "┌───────────────────────────────────────────────────────────────┐
3487 * │ Atomic counter array bindings (see sec. 7.7.2) │
3488 * ├───────────────────────┬───────────────────────────────────────┤
3490 * │ offset restriction │ multiple of 4 │
3492 * │ size restriction │ none │
3493 * └───────────────────────┴───────────────────────────────────────┘"
3495 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
3496 _mesa_error(ctx
, GL_INVALID_VALUE
,
3497 "glBindBuffersRange(offsets[%u]=%" PRId64
3498 " is misaligned; it must be a multiple of %d when "
3499 "target=GL_ATOMIC_COUNTER_BUFFER)",
3500 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
3504 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3505 bufObj
= binding
->BufferObject
;
3507 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
3508 "glBindBuffersRange");
3511 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offsets
[i
], sizes
[i
]);
3514 _mesa_end_bufferobj_lookups(ctx
);
3518 _mesa_BindBufferRange(GLenum target
, GLuint index
,
3519 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
3521 GET_CURRENT_CONTEXT(ctx
);
3522 struct gl_buffer_object
*bufObj
;
3525 bufObj
= ctx
->Shared
->NullBufferObj
;
3527 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3529 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3530 &bufObj
, "glBindBufferRange"))
3534 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3535 "glBindBufferRange(invalid buffer=%u)", buffer
);
3541 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
3548 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3549 _mesa_bind_buffer_range_transform_feedback(ctx
, index
, bufObj
,
3552 case GL_UNIFORM_BUFFER
:
3553 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
3555 case GL_ATOMIC_COUNTER_BUFFER
:
3556 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
3557 "glBindBufferRange");
3560 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
3566 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
3568 GET_CURRENT_CONTEXT(ctx
);
3569 struct gl_buffer_object
*bufObj
;
3572 bufObj
= ctx
->Shared
->NullBufferObj
;
3574 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3576 if (!_mesa_handle_bind_buffer_gen(ctx
, target
, buffer
,
3577 &bufObj
, "glBindBufferBase"))
3581 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3582 "glBindBufferBase(invalid buffer=%u)", buffer
);
3586 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
3587 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
3589 * "BindBufferBase is equivalent to calling BindBufferRange with offset
3590 * zero and size equal to the size of buffer."
3592 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
3594 * "If the parameter (starting offset or size) was not specified when the
3595 * buffer object was bound, zero is returned."
3597 * What happens if the size of the buffer changes? Does the size of the
3598 * buffer at the moment glBindBufferBase was called still play a role, like
3599 * the first quote would imply, or is the size meaningless in the
3600 * glBindBufferBase case like the second quote would suggest? The GL 4.1
3601 * core spec page 45 says:
3603 * "It is equivalent to calling BindBufferRange with offset zero, while
3604 * size is determined by the size of the bound buffer at the time the
3607 * My interpretation is that the GL 4.1 spec was a clarification of the
3608 * behavior, not a change. In particular, this choice will only make
3609 * rendering work in cases where it would have had undefined results.
3613 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3614 _mesa_bind_buffer_base_transform_feedback(ctx
, index
, bufObj
);
3616 case GL_UNIFORM_BUFFER
:
3617 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
3619 case GL_ATOMIC_COUNTER_BUFFER
:
3620 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
3621 "glBindBufferBase");
3624 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
3630 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
3631 const GLuint
*buffers
,
3632 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
3634 GET_CURRENT_CONTEXT(ctx
);
3637 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3638 bind_xfb_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3640 case GL_UNIFORM_BUFFER
:
3641 bind_uniform_buffers_range(ctx
, first
, count
, buffers
, offsets
, sizes
);
3643 case GL_ATOMIC_COUNTER_BUFFER
:
3644 bind_atomic_buffers_range(ctx
, first
, count
, buffers
,
3648 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
3649 _mesa_lookup_enum_by_nr(target
));
3655 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
3656 const GLuint
*buffers
)
3658 GET_CURRENT_CONTEXT(ctx
);
3661 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3662 bind_xfb_buffers_base(ctx
, first
, count
, buffers
);
3664 case GL_UNIFORM_BUFFER
:
3665 bind_uniform_buffers_base(ctx
, first
, count
, buffers
);
3667 case GL_ATOMIC_COUNTER_BUFFER
:
3668 bind_atomic_buffers_base(ctx
, first
, count
, buffers
);
3671 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
3672 _mesa_lookup_enum_by_nr(target
));
3678 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
3681 GET_CURRENT_CONTEXT(ctx
);
3682 struct gl_buffer_object
*bufObj
;
3683 const GLintptr end
= offset
+ length
;
3685 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3687 _mesa_error(ctx
, GL_INVALID_VALUE
,
3688 "glInvalidateBufferSubData(name = 0x%x) invalid object",
3693 /* The GL_ARB_invalidate_subdata spec says:
3695 * "An INVALID_VALUE error is generated if <offset> or <length> is
3696 * negative, or if <offset> + <length> is greater than the value of
3699 if (end
< 0 || end
> bufObj
->Size
) {
3700 _mesa_error(ctx
, GL_INVALID_VALUE
,
3701 "glInvalidateBufferSubData(invalid offset or length)");
3705 /* The OpenGL 4.4 (Core Profile) spec says:
3707 * "An INVALID_OPERATION error is generated if buffer is currently
3708 * mapped by MapBuffer or if the invalidate range intersects the range
3709 * currently mapped by MapBufferRange, unless it was mapped
3710 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3712 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
3713 bufferobj_range_mapped(bufObj
, offset
, length
)) {
3714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3715 "glInvalidateBufferSubData(intersection with mapped "
3720 /* We don't actually do anything for this yet. Just return after
3721 * validating the parameters and generating the required errors.
3727 _mesa_InvalidateBufferData(GLuint buffer
)
3729 GET_CURRENT_CONTEXT(ctx
);
3730 struct gl_buffer_object
*bufObj
;
3732 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3734 _mesa_error(ctx
, GL_INVALID_VALUE
,
3735 "glInvalidateBufferData(name = 0x%x) invalid object",
3740 /* The OpenGL 4.4 (Core Profile) spec says:
3742 * "An INVALID_OPERATION error is generated if buffer is currently
3743 * mapped by MapBuffer or if the invalidate range intersects the range
3744 * currently mapped by MapBufferRange, unless it was mapped
3745 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
3747 if (_mesa_check_disallowed_mapping(bufObj
)) {
3748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3749 "glInvalidateBufferData(intersection with mapped "
3754 /* We don't actually do anything for this yet. Just return after
3755 * validating the parameters and generating the required errors.