2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul 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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \brief Functions for the GL_ARB_vertex_buffer_object extension.
29 * \author Brian Paul, Ian Romanick
38 #include "bufferobj.h"
42 * Get the buffer object bound to the specified target in a GL context.
44 * \param ctx GL context
45 * \param target Buffer object target to be retrieved. Currently this must
46 * be either \c GL_ARRAY_BUFFER or \c GL_ELEMENT_ARRAY_BUFFER.
47 * \param str Name of caller for logging errors.
48 * \return A pointer to the buffer object bound to \c target in the
49 * specified context or \c NULL if \c target is invalid or no
50 * buffer object is bound.
52 static INLINE
struct gl_buffer_object
*
53 buffer_object_get_target( GLcontext
*ctx
, GLenum target
, const char * str
)
55 struct gl_buffer_object
* bufObj
= NULL
;
58 case GL_ARRAY_BUFFER_ARB
:
59 bufObj
= ctx
->Array
.ArrayBufferObj
;
61 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
62 bufObj
= ctx
->Array
.ElementArrayBufferObj
;
64 case GL_PIXEL_PACK_BUFFER_EXT
:
65 bufObj
= ctx
->Pack
.BufferObj
;
67 case GL_PIXEL_UNPACK_BUFFER_EXT
:
68 bufObj
= ctx
->Unpack
.BufferObj
;
71 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(target)", str
);
75 if (bufObj
->Name
== 0)
83 * Tests the subdata range parameters and sets the GL error code for
84 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
86 * \param ctx GL context.
87 * \param target Buffer object target on which to operate.
88 * \param offset Offset of the first byte of the subdata range.
89 * \param size Size, in bytes, of the subdata range.
90 * \param str Name of caller for logging errors.
91 * \return A pointer to the buffer object bound to \c target in the
92 * specified context or \c NULL if any of the parameter or state
93 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
96 * \sa glBufferSubDataARB, glGetBufferSubDataARB
98 static struct gl_buffer_object
*
99 buffer_object_subdata_range_good( GLcontext
* ctx
, GLenum target
,
100 GLintptrARB offset
, GLsizeiptrARB size
,
103 struct gl_buffer_object
*bufObj
;
106 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", str
);
111 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", str
);
115 bufObj
= buffer_object_get_target( ctx
, target
, str
);
116 if ( bufObj
== NULL
) {
120 if ( (GLuint
)(offset
+ size
) > bufObj
->Size
) {
121 _mesa_error(ctx
, GL_INVALID_VALUE
,
122 "%s(size + offset > buffer size)", str
);
126 if ( bufObj
->Pointer
!= NULL
) {
127 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", str
);
136 * Allocate and initialize a new buffer object.
138 * This function is intended to be called via
139 * \c dd_function_table::NewBufferObject.
141 struct gl_buffer_object
*
142 _mesa_new_buffer_object( GLcontext
*ctx
, GLuint name
, GLenum target
)
144 struct gl_buffer_object
*obj
;
148 obj
= MALLOC_STRUCT(gl_buffer_object
);
149 _mesa_initialize_buffer_object(obj
, name
, target
);
155 * Delete a buffer object.
157 * This function is intended to be called via
158 * \c dd_function_table::DeleteBuffer.
161 _mesa_delete_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*bufObj
)
166 _mesa_free(bufObj
->Data
);
172 * Initialize a buffer object to default values.
175 _mesa_initialize_buffer_object( struct gl_buffer_object
*obj
,
176 GLuint name
, GLenum target
)
180 _mesa_bzero(obj
, sizeof(struct gl_buffer_object
));
183 obj
->Usage
= GL_STATIC_DRAW_ARB
;
184 obj
->Access
= GL_READ_WRITE_ARB
;
189 * Add the given buffer object to the buffer object pool.
192 _mesa_save_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*obj
)
195 /* insert into hash table */
196 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, obj
->Name
, obj
);
202 * Remove the given buffer object from the buffer object pool.
203 * Do not deallocate the buffer object though.
206 _mesa_remove_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*bufObj
)
208 if (bufObj
->Name
> 0) {
209 /* remove from hash table */
210 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, bufObj
->Name
);
216 * Allocate space for and store data in a buffer object. Any data that was
217 * previously stored in the buffer object is lost. If \c data is \c NULL,
218 * memory will be allocated, but no copy will occur.
220 * This function is intended to be called via
221 * \c dd_function_table::BufferData. This function need not set GL error
222 * codes. The input parameters will have been tested before calling.
224 * \param ctx GL context.
225 * \param target Buffer object target on which to operate.
226 * \param size Size, in bytes, of the new data store.
227 * \param data Pointer to the data to store in the buffer object. This
228 * pointer may be \c NULL.
229 * \param usage Hints about how the data will be used.
230 * \param bufObj Object to be used.
232 * \sa glBufferDataARB, dd_function_table::BufferData.
235 _mesa_buffer_data( GLcontext
*ctx
, GLenum target
, GLsizeiptrARB size
,
236 const GLvoid
* data
, GLenum usage
,
237 struct gl_buffer_object
* bufObj
)
241 (void) ctx
; (void) target
;
243 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
244 if ( new_data
!= NULL
) {
245 bufObj
->Data
= (GLubyte
*) new_data
;
247 bufObj
->Usage
= usage
;
249 if ( data
!= NULL
) {
250 _mesa_memcpy( bufObj
->Data
, data
, size
);
257 * Replace data in a subrange of buffer object. If the data range
258 * specified by \c size + \c offset extends beyond the end of the buffer or
259 * if \c data is \c NULL, no copy is performed.
261 * This function is intended to be called by
262 * \c dd_function_table::BufferSubData. This function need not set GL error
263 * codes. The input parameters will have been tested before calling.
265 * \param ctx GL context.
266 * \param target Buffer object target on which to operate.
267 * \param offset Offset of the first byte to be modified.
268 * \param size Size, in bytes, of the data range.
269 * \param data Pointer to the data to store in the buffer object.
270 * \param bufObj Object to be used.
272 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
275 _mesa_buffer_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
276 GLsizeiptrARB size
, const GLvoid
* data
,
277 struct gl_buffer_object
* bufObj
)
279 (void) ctx
; (void) target
;
281 if ( (bufObj
->Data
!= NULL
)
282 && ((GLuint
)(size
+ offset
) <= bufObj
->Size
) ) {
283 _mesa_memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
289 * Retrieve data from a subrange of buffer object. If the data range
290 * specified by \c size + \c offset extends beyond the end of the buffer or
291 * if \c data is \c NULL, no copy is performed.
293 * This function is intended to be called by
294 * \c dd_function_table::BufferGetSubData. This function need not set GL error
295 * codes. The input parameters will have been tested before calling.
297 * \param ctx GL context.
298 * \param target Buffer object target on which to operate.
299 * \param offset Offset of the first byte to be modified.
300 * \param size Size, in bytes, of the data range.
301 * \param data Pointer to the data to store in the buffer object.
302 * \param bufObj Object to be used.
304 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
307 _mesa_buffer_get_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
308 GLsizeiptrARB size
, GLvoid
* data
,
309 struct gl_buffer_object
* bufObj
)
311 (void) ctx
; (void) target
;
313 if ( (bufObj
->Data
!= NULL
)
314 && ((GLuint
)(size
+ offset
) <= bufObj
->Size
) ) {
315 _mesa_memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
321 * Maps the private data buffer into the processor's address space.
323 * This function is intended to be called by \c dd_function_table::MapBuffer.
324 * This function need not set GL error codes. The input parameters will have
325 * been tested before calling.
327 * \param ctx GL context.
328 * \param target Buffer object target on which to operate.
329 * \param access Information about how the buffer will be accessed.
330 * \param bufObj Object to be used.
331 * \return A pointer to the object's internal data store that can be accessed
334 * \sa glMapBufferARB, dd_function_table::MapBuffer
337 _mesa_buffer_map( GLcontext
*ctx
, GLenum target
, GLenum access
,
338 struct gl_buffer_object
* bufObj
)
340 (void) ctx
; (void) target
; (void) access
;
346 * Initialize the state associated with buffer objects
349 _mesa_init_buffer_objects( GLcontext
*ctx
)
353 /* Allocate the default buffer object and set refcount so high that
354 * it never gets deleted.
356 ctx
->Array
.NullBufferObj
= _mesa_new_buffer_object(ctx
, 0, 0);
357 if (ctx
->Array
.NullBufferObj
)
358 ctx
->Array
.NullBufferObj
->RefCount
= 1000;
360 ctx
->Array
.ArrayBufferObj
= ctx
->Array
.NullBufferObj
;
361 ctx
->Array
.ElementArrayBufferObj
= ctx
->Array
.NullBufferObj
;
363 /* Vertex array buffers */
364 ctx
->Array
.Vertex
.BufferObj
= ctx
->Array
.NullBufferObj
;
365 ctx
->Array
.Normal
.BufferObj
= ctx
->Array
.NullBufferObj
;
366 ctx
->Array
.Color
.BufferObj
= ctx
->Array
.NullBufferObj
;
367 ctx
->Array
.SecondaryColor
.BufferObj
= ctx
->Array
.NullBufferObj
;
368 ctx
->Array
.FogCoord
.BufferObj
= ctx
->Array
.NullBufferObj
;
369 ctx
->Array
.Index
.BufferObj
= ctx
->Array
.NullBufferObj
;
370 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
371 ctx
->Array
.TexCoord
[i
].BufferObj
= ctx
->Array
.NullBufferObj
;
373 ctx
->Array
.EdgeFlag
.BufferObj
= ctx
->Array
.NullBufferObj
;
374 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
375 ctx
->Array
.VertexAttrib
[i
].BufferObj
= ctx
->Array
.NullBufferObj
;
381 * When we're about to read pixel data out of a PBO (via glDrawPixels,
382 * glTexImage, etc) or write data into a PBO (via glReadPixels,
383 * glGetTexImage, etc) we call this function to check that we're not
384 * going to read out of bounds.
386 * \param width width of image to read/write
387 * \param height height of image to read/write
388 * \param depth depth of image to read/write
389 * \param format format of image to read/write
390 * \param type datatype of image to read/write
391 * \param ptr the user-provided pointer/offset
392 * \return GL_TRUE if the PBO access is OK, GL_FALSE if the access would
396 _mesa_validate_pbo_access(const struct gl_pixelstore_attrib
*pack
,
397 GLsizei width
, GLsizei height
, GLsizei depth
,
398 GLenum format
, GLenum type
, const GLvoid
*ptr
)
402 ASSERT(pack
->BufferObj
->Name
!= 0);
404 if (pack
->BufferObj
->Size
== 0)
408 /* get address of first pixel we'll read */
409 start
= _mesa_image_address(pack
, ptr
, width
, height
,
410 format
, type
, 0, 0, 0);
412 /* get address just past the last pixel we'll read */
413 end
= _mesa_image_address(pack
, ptr
, width
, height
,
414 format
, type
, depth
-1, height
-1, width
);
417 if ((const GLubyte
*) start
> (const GLubyte
*) pack
->BufferObj
->Size
) {
418 /* This will catch negative values / wrap-around */
421 if ((const GLubyte
*) end
> (const GLubyte
*) pack
->BufferObj
->Size
) {
422 /* Image read goes beyond end of buffer */
433 /**********************************************************************/
435 /**********************************************************************/
438 _mesa_BindBufferARB(GLenum target
, GLuint buffer
)
440 GET_CURRENT_CONTEXT(ctx
);
441 struct gl_buffer_object
*oldBufObj
;
442 struct gl_buffer_object
*newBufObj
= 0;
443 ASSERT_OUTSIDE_BEGIN_END(ctx
);
445 oldBufObj
= buffer_object_get_target( ctx
, target
, "BindBufferARB" );
446 if ( (oldBufObj
!= NULL
) && (oldBufObj
->Name
== buffer
) )
447 return; /* rebinding the same buffer object- no change */
450 * Get pointer to new buffer object (newBufObj)
453 /* The spec says there's not a buffer object named 0, but we use
454 * one internally because it simplifies things.
456 newBufObj
= ctx
->Array
.NullBufferObj
;
459 /* non-default buffer object */
460 const struct _mesa_HashTable
*hash
= ctx
->Shared
->BufferObjects
;
461 newBufObj
= (struct gl_buffer_object
*) _mesa_HashLookup(hash
, buffer
);
463 /* if this is a new buffer object id, allocate a buffer object now */
464 newBufObj
= (*ctx
->Driver
.NewBufferObject
)(ctx
, buffer
, target
);
466 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindBufferARB");
469 _mesa_save_buffer_object(ctx
, newBufObj
);
471 newBufObj
->RefCount
++;
475 case GL_ARRAY_BUFFER_ARB
:
476 ctx
->Array
.ArrayBufferObj
= newBufObj
;
478 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
479 ctx
->Array
.ElementArrayBufferObj
= newBufObj
;
481 case GL_PIXEL_PACK_BUFFER_EXT
:
482 ctx
->Pack
.BufferObj
= newBufObj
;
484 case GL_PIXEL_UNPACK_BUFFER_EXT
:
485 ctx
->Unpack
.BufferObj
= newBufObj
;
488 _mesa_problem(ctx
, "Bad target in _mesa_BindBufferARB");
492 /* Pass BindBuffer call to device driver */
493 if ( (ctx
->Driver
.BindBuffer
!= NULL
) && (newBufObj
!= NULL
) )
494 (*ctx
->Driver
.BindBuffer
)( ctx
, target
, newBufObj
);
496 if ( oldBufObj
!= NULL
) {
497 oldBufObj
->RefCount
--;
498 assert(oldBufObj
->RefCount
>= 0);
499 if (oldBufObj
->RefCount
== 0) {
500 assert(oldBufObj
->Name
!= 0);
501 _mesa_remove_buffer_object(ctx
, oldBufObj
);
502 ASSERT(ctx
->Driver
.DeleteBuffer
);
503 (*ctx
->Driver
.DeleteBuffer
)( ctx
, oldBufObj
);
510 * Delete a set of buffer objects.
512 * \param n Number of buffer objects to delete.
513 * \param ids Array of \c n buffer object IDs.
516 _mesa_DeleteBuffersARB(GLsizei n
, const GLuint
*ids
)
518 GET_CURRENT_CONTEXT(ctx
);
520 ASSERT_OUTSIDE_BEGIN_END(ctx
);
523 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
527 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
529 for (i
= 0; i
< n
; i
++) {
531 struct gl_buffer_object
*bufObj
= (struct gl_buffer_object
*)
532 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, ids
[i
]);
534 /* unbind any vertex pointers bound to this buffer */
537 ASSERT(bufObj
->Name
== ids
[i
]);
539 if (ctx
->Array
.Vertex
.BufferObj
== bufObj
) {
541 ctx
->Array
.Vertex
.BufferObj
= ctx
->Array
.NullBufferObj
;
542 ctx
->Array
.NullBufferObj
->RefCount
++;
544 if (ctx
->Array
.Normal
.BufferObj
== bufObj
) {
546 ctx
->Array
.Normal
.BufferObj
= ctx
->Array
.NullBufferObj
;
547 ctx
->Array
.NullBufferObj
->RefCount
++;
549 if (ctx
->Array
.Color
.BufferObj
== bufObj
) {
551 ctx
->Array
.Color
.BufferObj
= ctx
->Array
.NullBufferObj
;
552 ctx
->Array
.NullBufferObj
->RefCount
++;
554 if (ctx
->Array
.SecondaryColor
.BufferObj
== bufObj
) {
556 ctx
->Array
.SecondaryColor
.BufferObj
= ctx
->Array
.NullBufferObj
;
557 ctx
->Array
.NullBufferObj
->RefCount
++;
559 if (ctx
->Array
.FogCoord
.BufferObj
== bufObj
) {
561 ctx
->Array
.FogCoord
.BufferObj
= ctx
->Array
.NullBufferObj
;
562 ctx
->Array
.NullBufferObj
->RefCount
++;
564 if (ctx
->Array
.Index
.BufferObj
== bufObj
) {
566 ctx
->Array
.Index
.BufferObj
= ctx
->Array
.NullBufferObj
;
567 ctx
->Array
.NullBufferObj
->RefCount
++;
569 if (ctx
->Array
.EdgeFlag
.BufferObj
== bufObj
) {
571 ctx
->Array
.EdgeFlag
.BufferObj
= ctx
->Array
.NullBufferObj
;
572 ctx
->Array
.NullBufferObj
->RefCount
++;
574 for (j
= 0; j
< MAX_TEXTURE_UNITS
; j
++) {
575 if (ctx
->Array
.TexCoord
[j
].BufferObj
== bufObj
) {
577 ctx
->Array
.TexCoord
[j
].BufferObj
= ctx
->Array
.NullBufferObj
;
578 ctx
->Array
.NullBufferObj
->RefCount
++;
581 for (j
= 0; j
< VERT_ATTRIB_MAX
; j
++) {
582 if (ctx
->Array
.VertexAttrib
[j
].BufferObj
== bufObj
) {
584 ctx
->Array
.VertexAttrib
[j
].BufferObj
= ctx
->Array
.NullBufferObj
;
585 ctx
->Array
.NullBufferObj
->RefCount
++;
589 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
590 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB
, 0 );
592 if (ctx
->Array
.ElementArrayBufferObj
== bufObj
) {
593 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
596 if (ctx
->Pack
.BufferObj
== bufObj
) {
597 _mesa_BindBufferARB( GL_PIXEL_PACK_BUFFER_EXT
, 0 );
599 if (ctx
->Unpack
.BufferObj
== bufObj
) {
600 _mesa_BindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT
, 0 );
603 /* decrement refcount and delete if <= 0 */
604 if (!bufObj
->DeletePending
) {
605 bufObj
->DeletePending
= GL_TRUE
;
609 if (bufObj
->RefCount
<= 0) {
610 /* buffer should not be bound anymore! */
611 ASSERT(ctx
->Array
.ArrayBufferObj
!= bufObj
);
612 ASSERT(ctx
->Array
.ElementArrayBufferObj
!= bufObj
);
613 ASSERT(ctx
->Array
.Vertex
.BufferObj
!= bufObj
);
614 _mesa_remove_buffer_object(ctx
, bufObj
);
615 ASSERT(ctx
->Driver
.DeleteBuffer
);
616 (*ctx
->Driver
.DeleteBuffer
)(ctx
, bufObj
);
622 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
627 * Generate a set of unique buffer object IDs and store them in \c buffer.
629 * \param n Number of IDs to generate.
630 * \param buffer Array of \c n locations to store the IDs.
633 _mesa_GenBuffersARB(GLsizei n
, GLuint
*buffer
)
635 GET_CURRENT_CONTEXT(ctx
);
638 ASSERT_OUTSIDE_BEGIN_END(ctx
);
641 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
645 if ( buffer
== NULL
) {
650 * This must be atomic (generation and allocation of buffer object IDs)
652 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
654 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
656 /* Allocate new, empty buffer objects and return identifiers */
657 for (i
= 0; i
< n
; i
++) {
658 struct gl_buffer_object
*bufObj
;
659 GLuint name
= first
+ i
;
661 bufObj
= (*ctx
->Driver
.NewBufferObject
)( ctx
, name
, target
);
663 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenBuffersARB");
666 _mesa_save_buffer_object(ctx
, bufObj
);
667 buffer
[i
] = first
+ i
;
670 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
675 * Determine if ID is the name of a buffer object.
677 * \param id ID of the potential buffer object.
678 * \return \c GL_TRUE if \c id is the name of a buffer object,
679 * \c GL_FALSE otherwise.
682 _mesa_IsBufferARB(GLuint id
)
684 struct gl_buffer_object
* bufObj
;
685 GET_CURRENT_CONTEXT(ctx
);
686 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
691 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
692 bufObj
= (struct gl_buffer_object
*) _mesa_HashLookup(ctx
->Shared
->BufferObjects
, id
);
693 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
695 return bufObj
&& !bufObj
->DeletePending
;
700 _mesa_BufferDataARB(GLenum target
, GLsizeiptrARB size
,
701 const GLvoid
* data
, GLenum usage
)
703 GET_CURRENT_CONTEXT(ctx
);
704 struct gl_buffer_object
*bufObj
;
705 ASSERT_OUTSIDE_BEGIN_END(ctx
);
708 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
713 case GL_STREAM_DRAW_ARB
:
714 case GL_STREAM_READ_ARB
:
715 case GL_STREAM_COPY_ARB
:
716 case GL_STATIC_DRAW_ARB
:
717 case GL_STATIC_READ_ARB
:
718 case GL_STATIC_COPY_ARB
:
719 case GL_DYNAMIC_DRAW_ARB
:
720 case GL_DYNAMIC_READ_ARB
:
721 case GL_DYNAMIC_COPY_ARB
:
725 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferDataARB(usage)");
729 bufObj
= buffer_object_get_target( ctx
, target
, "BufferDataARB" );
730 if ( bufObj
== NULL
) {
731 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferDataARB" );
735 if (bufObj
->Pointer
) {
736 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferDataARB(buffer is mapped)" );
740 ASSERT(ctx
->Driver
.BufferData
);
742 /* Give the buffer object to the driver! <data> may be null! */
743 (*ctx
->Driver
.BufferData
)( ctx
, target
, size
, data
, usage
, bufObj
);
748 _mesa_BufferSubDataARB(GLenum target
, GLintptrARB offset
,
749 GLsizeiptrARB size
, const GLvoid
* data
)
751 GET_CURRENT_CONTEXT(ctx
);
752 struct gl_buffer_object
*bufObj
;
753 ASSERT_OUTSIDE_BEGIN_END(ctx
);
755 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
756 "BufferSubDataARB" );
758 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubDataARB" );
762 if (bufObj
->Pointer
) {
763 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubDataARB(buffer is mapped)" );
767 ASSERT(ctx
->Driver
.BufferSubData
);
768 (*ctx
->Driver
.BufferSubData
)( ctx
, target
, offset
, size
, data
, bufObj
);
773 _mesa_GetBufferSubDataARB(GLenum target
, GLintptrARB offset
,
774 GLsizeiptrARB size
, void * data
)
776 GET_CURRENT_CONTEXT(ctx
);
777 struct gl_buffer_object
*bufObj
;
778 ASSERT_OUTSIDE_BEGIN_END(ctx
);
780 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
781 "GetBufferSubDataARB" );
783 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferSubDataARB" );
787 if (bufObj
->Pointer
) {
788 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferSubDataARB(buffer is mapped)" );
792 ASSERT(ctx
->Driver
.GetBufferSubData
);
793 (*ctx
->Driver
.GetBufferSubData
)( ctx
, target
, offset
, size
, data
, bufObj
);
798 _mesa_MapBufferARB(GLenum target
, GLenum access
)
800 GET_CURRENT_CONTEXT(ctx
);
801 struct gl_buffer_object
* bufObj
;
802 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
805 case GL_READ_ONLY_ARB
:
806 case GL_WRITE_ONLY_ARB
:
807 case GL_READ_WRITE_ARB
:
811 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
815 bufObj
= buffer_object_get_target( ctx
, target
, "MapBufferARB" );
816 if ( bufObj
== NULL
) {
817 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB" );
821 if ( bufObj
->Pointer
!= NULL
) {
822 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
826 ASSERT(ctx
->Driver
.MapBuffer
);
827 bufObj
->Pointer
= (*ctx
->Driver
.MapBuffer
)( ctx
, target
, access
, bufObj
);
828 if ( bufObj
->Pointer
== NULL
) {
829 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(access)");
832 bufObj
->Access
= access
;
834 return bufObj
->Pointer
;
839 _mesa_UnmapBufferARB(GLenum target
)
841 GET_CURRENT_CONTEXT(ctx
);
842 struct gl_buffer_object
*bufObj
;
843 GLboolean status
= GL_TRUE
;
844 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
846 bufObj
= buffer_object_get_target( ctx
, target
, "UnmapBufferARB" );
847 if ( bufObj
== NULL
) {
848 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB" );
852 if ( bufObj
->Pointer
== NULL
) {
853 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
857 if ( ctx
->Driver
.UnmapBuffer
!= NULL
) {
858 status
= (*ctx
->Driver
.UnmapBuffer
)( ctx
, target
, bufObj
);
861 bufObj
->Access
= GL_READ_WRITE_ARB
; /* initial value, OK? */
862 bufObj
->Pointer
= NULL
;
869 _mesa_GetBufferParameterivARB(GLenum target
, GLenum pname
, GLint
*params
)
871 GET_CURRENT_CONTEXT(ctx
);
872 struct gl_buffer_object
*bufObj
;
873 ASSERT_OUTSIDE_BEGIN_END(ctx
);
875 bufObj
= buffer_object_get_target( ctx
, target
, "GetBufferParameterivARB" );
877 _mesa_error(ctx
, GL_INVALID_OPERATION
, "GetBufferParameterivARB" );
882 case GL_BUFFER_SIZE_ARB
:
883 *params
= bufObj
->Size
;
885 case GL_BUFFER_USAGE_ARB
:
886 *params
= bufObj
->Usage
;
888 case GL_BUFFER_ACCESS_ARB
:
889 *params
= bufObj
->Access
;
891 case GL_BUFFER_MAPPED_ARB
:
892 *params
= (bufObj
->Pointer
!= NULL
);
895 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname)");
902 _mesa_GetBufferPointervARB(GLenum target
, GLenum pname
, GLvoid
**params
)
904 GET_CURRENT_CONTEXT(ctx
);
905 struct gl_buffer_object
* bufObj
;
906 ASSERT_OUTSIDE_BEGIN_END(ctx
);
908 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
913 bufObj
= buffer_object_get_target( ctx
, target
, "GetBufferPointervARB" );
914 if ( bufObj
== NULL
) {
915 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferPointervARB" );
919 *params
= bufObj
->Pointer
;