2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keithw@vmware.com>
29 #include "main/mtypes.h"
30 #include "main/bufferobj.h"
31 #include "main/imports.h"
33 #include "vbo_private.h"
37 * Called at context creation time.
39 void vbo_save_init( struct gl_context
*ctx
)
41 struct vbo_context
*vbo
= vbo_context(ctx
);
42 struct vbo_save_context
*save
= &vbo
->save
;
46 vbo_save_api_init( save
);
49 struct gl_vertex_array
*arrays
= save
->arrays
;
52 memcpy(arrays
, &vbo
->currval
[VBO_ATTRIB_POS
],
53 VERT_ATTRIB_FF_MAX
* sizeof(arrays
[0]));
54 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; ++i
) {
55 struct gl_vertex_array
*array
;
56 array
= &arrays
[VERT_ATTRIB_FF(i
)];
57 array
->BufferObj
= NULL
;
58 _mesa_reference_buffer_object(ctx
, &arrays
->BufferObj
,
59 vbo
->currval
[VBO_ATTRIB_POS
+i
].BufferObj
);
62 memcpy(arrays
+ VERT_ATTRIB_GENERIC(0),
63 &vbo
->currval
[VBO_ATTRIB_GENERIC0
],
64 VERT_ATTRIB_GENERIC_MAX
* sizeof(arrays
[0]));
66 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; ++i
) {
67 struct gl_vertex_array
*array
;
68 array
= &arrays
[VERT_ATTRIB_GENERIC(i
)];
69 array
->BufferObj
= NULL
;
70 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
71 vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
].BufferObj
);
75 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
79 void vbo_save_destroy( struct gl_context
*ctx
)
81 struct vbo_context
*vbo
= vbo_context(ctx
);
82 struct vbo_save_context
*save
= &vbo
->save
;
85 if (save
->prim_store
) {
86 if ( --save
->prim_store
->refcount
== 0 ) {
87 free(save
->prim_store
);
88 save
->prim_store
= NULL
;
90 if ( --save
->vertex_store
->refcount
== 0 ) {
91 _mesa_reference_buffer_object(ctx
,
92 &save
->vertex_store
->bufferobj
, NULL
);
93 free(save
->vertex_store
);
94 save
->vertex_store
= NULL
;
98 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
99 _mesa_reference_buffer_object(ctx
, &save
->arrays
[i
].BufferObj
, NULL
);
106 /* Note that this can occur during the playback of a display list:
108 void vbo_save_fallback( struct gl_context
*ctx
, GLboolean fallback
)
110 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
113 save
->replay_flags
|= VBO_SAVE_FALLBACK
;
115 save
->replay_flags
&= ~VBO_SAVE_FALLBACK
;