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
37 #include "bufferobj.h"
41 * Get the buffer object bound to the specified target in a GL context.
43 * \param ctx GL context
44 * \param target Buffer object target to be retrieved. Currently this must
45 * be either \c GL_ARRAY_BUFFER or \c GL_ELEMENT_ARRAY_BUFFER.
46 * \param str Name of caller for logging errors.
47 * \return A pointer to the buffer object bound to \c target in the
48 * specified context or \c NULL if \c target is invalid or no
49 * buffer object is bound.
51 static INLINE
struct gl_buffer_object
*
52 buffer_object_get_target( GLcontext
*ctx
, GLenum target
, const char * str
)
54 struct gl_buffer_object
* bufObj
= NULL
;
57 case GL_ARRAY_BUFFER_ARB
:
58 bufObj
= ctx
->Array
.ArrayBufferObj
;
60 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
61 bufObj
= ctx
->Array
.ElementArrayBufferObj
;
64 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(target)", str
);
68 if (bufObj
->Name
== 0)
76 * Tests the subdata range parameters and sets the GL error code for
77 * \c glBufferSubDataARB and \c glGetBufferSubDataARB.
79 * \param ctx GL context.
80 * \param target Buffer object target on which to operate.
81 * \param offset Offset of the first byte of the subdata range.
82 * \param size Size, in bytes, of the subdata range.
83 * \param str Name of caller for logging errors.
84 * \return A pointer to the buffer object bound to \c target in the
85 * specified context or \c NULL if any of the parameter or state
86 * conditions for \c glBufferSubDataARB or \c glGetBufferSubDataARB
89 * \sa glBufferSubDataARB, glGetBufferSubDataARB
91 static struct gl_buffer_object
*
92 buffer_object_subdata_range_good( GLcontext
* ctx
, GLenum target
,
93 GLintptrARB offset
, GLsizeiptrARB size
,
96 struct gl_buffer_object
*bufObj
;
99 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", str
);
104 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", str
);
108 bufObj
= buffer_object_get_target( ctx
, target
, str
);
109 if ( bufObj
== NULL
) {
113 if ( (GLuint
)(offset
+ size
) > bufObj
->Size
) {
114 _mesa_error(ctx
, GL_INVALID_VALUE
,
115 "%s(size + offset > buffer size)", str
);
119 if ( bufObj
->Pointer
!= NULL
) {
120 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", str
);
129 * Allocate and initialize a new buffer object.
131 * This function is intended to be called via
132 * \c dd_function_table::NewBufferObject.
134 struct gl_buffer_object
*
135 _mesa_new_buffer_object( GLcontext
*ctx
, GLuint name
, GLenum target
)
137 struct gl_buffer_object
*obj
;
138 obj
= MALLOC_STRUCT(gl_buffer_object
);
139 _mesa_initialize_buffer_object(obj
, name
, target
);
145 * Delete a buffer object.
147 * This function is intended to be called via
148 * \c dd_function_table::DeleteBufferObject.
151 _mesa_delete_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*bufObj
)
154 _mesa_free(bufObj
->Data
);
160 * Initialize a buffer object to default values.
163 _mesa_initialize_buffer_object( struct gl_buffer_object
*obj
,
164 GLuint name
, GLenum target
)
166 _mesa_bzero(obj
, sizeof(struct gl_buffer_object
));
169 obj
->Usage
= GL_STATIC_DRAW_ARB
;
170 obj
->Access
= GL_READ_WRITE_ARB
;
175 * Add the given buffer object to the buffer object pool.
178 _mesa_save_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*obj
)
181 /* insert into hash table */
182 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, obj
->Name
, obj
);
188 * Remove the given buffer object from the buffer object pool.
189 * Do not deallocate the buffer object though.
192 _mesa_remove_buffer_object( GLcontext
*ctx
, struct gl_buffer_object
*bufObj
)
194 if (bufObj
->Name
> 0) {
195 /* remove from hash table */
196 _mesa_HashRemove(ctx
->Shared
->BufferObjects
, bufObj
->Name
);
202 * Allocate space for and store data in a buffer object. Any data that was
203 * previously stored in the buffer object is lost. If \c data is \c NULL,
204 * memory will be allocated, but no copy will occur.
206 * This function is intended to be called via
207 * \c dd_function_table::BufferData. This function need not set GL error
208 * codes. The input parameters will have been tested before calling.
210 * \param ctx GL context.
211 * \param target Buffer object target on which to operate.
212 * \param size Size, in bytes, of the new data store.
213 * \param data Pointer to the data to store in the buffer object. This
214 * pointer may be \c NULL.
215 * \param usage Hints about how the data will be used.
216 * \param bufObj Object to be used.
218 * \sa glBufferDataARB, dd_function_table::BufferData.
221 _mesa_buffer_data( GLcontext
*ctx
, GLenum target
, GLsizeiptrARB size
,
222 const GLvoid
* data
, GLenum usage
,
223 struct gl_buffer_object
* bufObj
)
229 new_data
= _mesa_realloc( bufObj
->Data
, bufObj
->Size
, size
);
230 if ( new_data
!= NULL
) {
231 bufObj
->Data
= (GLubyte
*) new_data
;
233 bufObj
->Usage
= usage
;
235 if ( data
!= NULL
) {
236 _mesa_memcpy( bufObj
->Data
, data
, size
);
243 * Replace data in a subrange of buffer object. If the data range
244 * specified by \c size + \c offset extends beyond the end of the buffer or
245 * if \c data is \c NULL, no copy is performed.
247 * This function is intended to be called by
248 * \c dd_function_table::BufferSubData. This function need not set GL error
249 * codes. The input parameters will have been tested before calling.
251 * \param ctx GL context.
252 * \param target Buffer object target on which to operate.
253 * \param offset Offset of the first byte to be modified.
254 * \param size Size, in bytes, of the data range.
255 * \param data Pointer to the data to store in the buffer object.
256 * \param bufObj Object to be used.
258 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
261 _mesa_buffer_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
262 GLsizeiptrARB size
, const GLvoid
* data
,
263 struct gl_buffer_object
* bufObj
)
265 if ( (bufObj
->Data
!= NULL
)
266 && ((GLuint
)(size
+ offset
) <= bufObj
->Size
) ) {
267 _mesa_memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
273 * Retrieve data from a subrange of buffer object. If the data range
274 * specified by \c size + \c offset extends beyond the end of the buffer or
275 * if \c data is \c NULL, no copy is performed.
277 * This function is intended to be called by
278 * \c dd_function_table::BufferGetSubData. This function need not set GL error
279 * codes. The input parameters will have been tested before calling.
281 * \param ctx GL context.
282 * \param target Buffer object target on which to operate.
283 * \param offset Offset of the first byte to be modified.
284 * \param size Size, in bytes, of the data range.
285 * \param data Pointer to the data to store in the buffer object.
286 * \param bufObj Object to be used.
288 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
291 _mesa_buffer_get_subdata( GLcontext
*ctx
, GLenum target
, GLintptrARB offset
,
292 GLsizeiptrARB size
, GLvoid
* data
,
293 struct gl_buffer_object
* bufObj
)
295 if ( (bufObj
->Data
!= NULL
)
296 && ((GLuint
)(size
+ offset
) <= bufObj
->Size
) ) {
297 _mesa_memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
303 * Maps the private data buffer into the processor's address space.
305 * This function is intended to be called by \c dd_function_table::MapBuffer.
306 * This function need not set GL error codes. The input parameters will have
307 * been tested before calling.
309 * \param ctx GL context.
310 * \param target Buffer object target on which to operate.
311 * \param access Information about how the buffer will be accessed.
312 * \param bufObj Object to be used.
313 * \return A pointer to the object's internal data store that can be accessed
316 * \sa glMapBufferARB, dd_function_table::MapBuffer
319 _mesa_buffer_map( GLcontext
*ctx
, GLenum target
, GLenum access
,
320 struct gl_buffer_object
* bufObj
)
327 * Initialize the state associated with buffer objects
330 _mesa_init_buffer_objects( GLcontext
*ctx
)
334 /* Allocate the default buffer object and set refcount so high that
335 * it never gets deleted.
337 ctx
->Array
.NullBufferObj
= _mesa_new_buffer_object(ctx
, 0, 0);
338 if (ctx
->Array
.NullBufferObj
)
339 ctx
->Array
.NullBufferObj
->RefCount
= 1000;
341 ctx
->Array
.ArrayBufferObj
= ctx
->Array
.NullBufferObj
;
342 ctx
->Array
.ElementArrayBufferObj
= ctx
->Array
.NullBufferObj
;
344 /* Vertex array buffers */
345 ctx
->Array
.Vertex
.BufferObj
= ctx
->Array
.NullBufferObj
;
346 ctx
->Array
.Normal
.BufferObj
= ctx
->Array
.NullBufferObj
;
347 ctx
->Array
.Color
.BufferObj
= ctx
->Array
.NullBufferObj
;
348 ctx
->Array
.SecondaryColor
.BufferObj
= ctx
->Array
.NullBufferObj
;
349 ctx
->Array
.FogCoord
.BufferObj
= ctx
->Array
.NullBufferObj
;
350 ctx
->Array
.Index
.BufferObj
= ctx
->Array
.NullBufferObj
;
351 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
352 ctx
->Array
.TexCoord
[i
].BufferObj
= ctx
->Array
.NullBufferObj
;
354 ctx
->Array
.EdgeFlag
.BufferObj
= ctx
->Array
.NullBufferObj
;
355 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
356 ctx
->Array
.VertexAttrib
[i
].BufferObj
= ctx
->Array
.NullBufferObj
;
362 /**********************************************************************/
364 /**********************************************************************/
367 _mesa_BindBufferARB(GLenum target
, GLuint buffer
)
369 GET_CURRENT_CONTEXT(ctx
);
370 struct gl_buffer_object
*oldBufObj
;
371 struct gl_buffer_object
*newBufObj
= 0;
372 ASSERT_OUTSIDE_BEGIN_END(ctx
);
374 oldBufObj
= buffer_object_get_target( ctx
, target
, "BindBufferARB" );
375 if ( (oldBufObj
!= NULL
) && (oldBufObj
->Name
== buffer
) )
376 return; /* rebinding the same buffer object- no change */
379 * Get pointer to new buffer object (newBufObj)
382 /* The spec says there's not a buffer object named 0, but we use
383 * one internally because it simplifies things.
385 newBufObj
= ctx
->Array
.NullBufferObj
;
388 /* non-default buffer object */
389 const struct _mesa_HashTable
*hash
= ctx
->Shared
->BufferObjects
;
390 newBufObj
= (struct gl_buffer_object
*) _mesa_HashLookup(hash
, buffer
);
392 /* if this is a new buffer object id, allocate a buffer object now */
393 newBufObj
= (*ctx
->Driver
.NewBufferObject
)(ctx
, buffer
, target
);
395 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindBufferARB");
398 _mesa_save_buffer_object(ctx
, newBufObj
);
400 newBufObj
->RefCount
++;
404 case GL_ARRAY_BUFFER_ARB
:
405 ctx
->Array
.ArrayBufferObj
= newBufObj
;
407 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
408 ctx
->Array
.ElementArrayBufferObj
= newBufObj
;
412 /* Pass BindBuffer call to device driver */
413 if ( (ctx
->Driver
.BindBuffer
!= NULL
) && (newBufObj
!= NULL
) )
414 (*ctx
->Driver
.BindBuffer
)( ctx
, target
, newBufObj
);
416 if ( oldBufObj
!= NULL
) {
417 oldBufObj
->RefCount
--;
418 assert(oldBufObj
->RefCount
>= 0);
419 if (oldBufObj
->RefCount
== 0) {
420 assert(oldBufObj
->Name
!= 0);
421 _mesa_remove_buffer_object(ctx
, oldBufObj
);
422 ASSERT(ctx
->Driver
.DeleteBuffer
);
423 (*ctx
->Driver
.DeleteBuffer
)( ctx
, oldBufObj
);
430 * Delete a set of buffer objects.
432 * \param n Number of buffer objects to delete.
433 * \param buffer Array of \c n buffer object IDs.
436 _mesa_DeleteBuffersARB(GLsizei n
, const GLuint
*ids
)
438 GET_CURRENT_CONTEXT(ctx
);
440 ASSERT_OUTSIDE_BEGIN_END(ctx
);
443 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
447 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
449 for (i
= 0; i
< n
; i
++) {
451 struct gl_buffer_object
*bufObj
= (struct gl_buffer_object
*)
452 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, ids
[i
]);
454 /* unbind any vertex pointers bound to this buffer */
457 ASSERT(bufObj
->Name
!= 0);
459 if (ctx
->Array
.Vertex
.BufferObj
== bufObj
)
460 ctx
->Array
.Vertex
.BufferObj
= ctx
->Array
.NullBufferObj
;
461 if (ctx
->Array
.Normal
.BufferObj
== bufObj
)
462 ctx
->Array
.Normal
.BufferObj
= ctx
->Array
.NullBufferObj
;
463 if (ctx
->Array
.Color
.BufferObj
== bufObj
)
464 ctx
->Array
.Color
.BufferObj
= ctx
->Array
.NullBufferObj
;
465 if (ctx
->Array
.SecondaryColor
.BufferObj
== bufObj
)
466 ctx
->Array
.SecondaryColor
.BufferObj
= ctx
->Array
.NullBufferObj
;
467 if (ctx
->Array
.FogCoord
.BufferObj
== bufObj
)
468 ctx
->Array
.FogCoord
.BufferObj
= ctx
->Array
.NullBufferObj
;
469 if (ctx
->Array
.Index
.BufferObj
== bufObj
)
470 ctx
->Array
.Index
.BufferObj
= ctx
->Array
.NullBufferObj
;
471 if (ctx
->Array
.EdgeFlag
.BufferObj
== bufObj
)
472 ctx
->Array
.EdgeFlag
.BufferObj
= ctx
->Array
.NullBufferObj
;
473 for (j
= 0; j
< MAX_TEXTURE_UNITS
; j
++) {
474 if (ctx
->Array
.TexCoord
[j
].BufferObj
== bufObj
)
475 ctx
->Array
.TexCoord
[j
].BufferObj
= ctx
->Array
.NullBufferObj
;
477 for (j
= 0; j
< VERT_ATTRIB_MAX
; j
++) {
478 if (ctx
->Array
.VertexAttrib
[j
].BufferObj
== bufObj
)
479 ctx
->Array
.VertexAttrib
[j
].BufferObj
= ctx
->Array
.NullBufferObj
;
482 /* if deleting bound buffers, rebind to zero */
483 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
484 _mesa_BindBufferARB( GL_ARRAY_BUFFER_ARB
, 0 );
486 if (ctx
->Array
.ElementArrayBufferObj
== bufObj
) {
487 _mesa_BindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB
, 0 );
491 if (bufObj
->RefCount
<= 0) {
492 _mesa_remove_buffer_object(ctx
, bufObj
);
493 ASSERT(ctx
->Driver
.DeleteBuffer
);
494 (*ctx
->Driver
.DeleteBuffer
)(ctx
, bufObj
);
500 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
505 * Generate a set of unique buffer object IDs and store them in \c buffer.
507 * \param n Number of IDs to generate.
508 * \param buffer Array of \c n locations to store the IDs.
511 _mesa_GenBuffersARB(GLsizei n
, GLuint
*buffer
)
513 GET_CURRENT_CONTEXT(ctx
);
516 ASSERT_OUTSIDE_BEGIN_END(ctx
);
519 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenBuffersARB");
523 if ( buffer
== NULL
) {
528 * This must be atomic (generation and allocation of buffer object IDs)
530 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
532 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
534 /* Allocate new, empty buffer objects and return identifiers */
535 for (i
= 0; i
< n
; i
++) {
536 struct gl_buffer_object
*bufObj
;
537 GLuint name
= first
+ i
;
539 bufObj
= (*ctx
->Driver
.NewBufferObject
)( ctx
, name
, target
);
541 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenBuffersARB");
544 _mesa_save_buffer_object(ctx
, bufObj
);
545 buffer
[i
] = first
+ i
;
548 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
553 * Determine if ID is the name of a buffer object.
555 * \param id ID of the potential buffer object.
556 * \return \c GL_TRUE if \c id is the name of a buffer object,
557 * \c GL_FALSE otherwise.
560 _mesa_IsBufferARB(GLuint id
)
562 struct gl_buffer_object
* bufObj
;
563 GET_CURRENT_CONTEXT(ctx
);
564 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
569 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
570 bufObj
= (struct gl_buffer_object
*) _mesa_HashLookup(ctx
->Shared
->BufferObjects
, id
);
571 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
573 return (bufObj
!= NULL
);
578 _mesa_BufferDataARB(GLenum target
, GLsizeiptrARB size
,
579 const GLvoid
* data
, GLenum usage
)
581 GET_CURRENT_CONTEXT(ctx
);
582 struct gl_buffer_object
*bufObj
;
583 ASSERT_OUTSIDE_BEGIN_END(ctx
);
586 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBufferDataARB(size < 0)");
591 case GL_STREAM_DRAW_ARB
:
592 case GL_STREAM_READ_ARB
:
593 case GL_STREAM_COPY_ARB
:
594 case GL_STATIC_DRAW_ARB
:
595 case GL_STATIC_READ_ARB
:
596 case GL_STATIC_COPY_ARB
:
597 case GL_DYNAMIC_DRAW_ARB
:
598 case GL_DYNAMIC_READ_ARB
:
599 case GL_DYNAMIC_COPY_ARB
:
603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBufferDataARB(usage)");
607 bufObj
= buffer_object_get_target( ctx
, target
, "BufferDataARB" );
608 if ( bufObj
== NULL
) {
609 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferDataARB" );
613 if (bufObj
->Pointer
) {
614 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferDataARB(buffer is mapped)" );
618 ASSERT(ctx
->Driver
.BufferData
);
620 /* Give the buffer object to the driver! <data> may be null! */
621 (*ctx
->Driver
.BufferData
)( ctx
, target
, size
, data
, usage
, bufObj
);
626 _mesa_BufferSubDataARB(GLenum target
, GLintptrARB offset
,
627 GLsizeiptrARB size
, const GLvoid
* data
)
629 GET_CURRENT_CONTEXT(ctx
);
630 struct gl_buffer_object
*bufObj
;
631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
633 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
634 "BufferSubDataARB" );
636 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubDataARB" );
640 if (bufObj
->Pointer
) {
641 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBufferSubDataARB(buffer is mapped)" );
645 ASSERT(ctx
->Driver
.BufferSubData
);
646 (*ctx
->Driver
.BufferSubData
)( ctx
, target
, offset
, size
, data
, bufObj
);
651 _mesa_GetBufferSubDataARB(GLenum target
, GLintptrARB offset
,
652 GLsizeiptrARB size
, void * data
)
654 GET_CURRENT_CONTEXT(ctx
);
655 struct gl_buffer_object
*bufObj
;
656 ASSERT_OUTSIDE_BEGIN_END(ctx
);
658 bufObj
= buffer_object_subdata_range_good( ctx
, target
, offset
, size
,
659 "GetBufferSubDataARB" );
661 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferSubDataARB" );
665 if (bufObj
->Pointer
) {
666 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferSubDataARB(buffer is mapped)" );
670 ASSERT(ctx
->Driver
.GetBufferSubData
);
671 (*ctx
->Driver
.GetBufferSubData
)( ctx
, target
, offset
, size
, data
, bufObj
);
676 _mesa_MapBufferARB(GLenum target
, GLenum access
)
678 GET_CURRENT_CONTEXT(ctx
);
679 struct gl_buffer_object
* bufObj
;
680 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, NULL
);
683 case GL_READ_ONLY_ARB
:
684 case GL_WRITE_ONLY_ARB
:
685 case GL_READ_WRITE_ARB
:
689 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBufferARB(access)");
693 bufObj
= buffer_object_get_target( ctx
, target
, "MapBufferARB" );
694 if ( bufObj
== NULL
) {
695 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB" );
699 if ( bufObj
->Pointer
!= NULL
) {
700 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMapBufferARB(already mapped)");
704 ASSERT(ctx
->Driver
.MapBuffer
);
705 bufObj
->Pointer
= (*ctx
->Driver
.MapBuffer
)( ctx
, target
, access
, bufObj
);
706 if ( bufObj
->Pointer
== NULL
) {
707 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glMapBufferARB(access)");
710 bufObj
->Access
= access
;
712 return bufObj
->Pointer
;
717 _mesa_UnmapBufferARB(GLenum target
)
719 GET_CURRENT_CONTEXT(ctx
);
720 struct gl_buffer_object
*bufObj
;
721 GLboolean status
= GL_TRUE
;
722 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
724 bufObj
= buffer_object_get_target( ctx
, target
, "UnmapBufferARB" );
725 if ( bufObj
== NULL
) {
726 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB" );
730 if ( bufObj
->Pointer
== NULL
) {
731 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUnmapBufferARB");
735 if ( ctx
->Driver
.UnmapBuffer
!= NULL
) {
736 status
= (*ctx
->Driver
.UnmapBuffer
)( ctx
, target
, bufObj
);
739 bufObj
->Access
= GL_READ_WRITE_ARB
; /* initial value, OK? */
740 bufObj
->Pointer
= NULL
;
747 _mesa_GetBufferParameterivARB(GLenum target
, GLenum pname
, GLint
*params
)
749 GET_CURRENT_CONTEXT(ctx
);
750 struct gl_buffer_object
*bufObj
;
751 ASSERT_OUTSIDE_BEGIN_END(ctx
);
753 bufObj
= buffer_object_get_target( ctx
, target
, "GetBufferParameterivARB" );
755 _mesa_error(ctx
, GL_INVALID_OPERATION
, "GetBufferParameterivARB" );
760 case GL_BUFFER_SIZE_ARB
:
761 *params
= bufObj
->Size
;
763 case GL_BUFFER_USAGE_ARB
:
764 *params
= bufObj
->Usage
;
766 case GL_BUFFER_ACCESS_ARB
:
767 *params
= bufObj
->Access
;
769 case GL_BUFFER_MAPPED_ARB
:
770 *params
= (bufObj
->Pointer
!= NULL
);
773 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferParameterivARB(pname)");
780 _mesa_GetBufferPointervARB(GLenum target
, GLenum pname
, GLvoid
**params
)
782 GET_CURRENT_CONTEXT(ctx
);
783 struct gl_buffer_object
* bufObj
;
784 ASSERT_OUTSIDE_BEGIN_END(ctx
);
786 if (pname
!= GL_BUFFER_MAP_POINTER_ARB
) {
787 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointervARB(pname)");
791 bufObj
= buffer_object_get_target( ctx
, target
, "GetBufferPointervARB" );
792 if ( bufObj
== NULL
) {
793 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetBufferPointervARB" );
797 *params
= bufObj
->Pointer
;