2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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.
25 * Keith Whitwell <keith@tungstengraphics.com>
29 #include "main/mtypes.h"
30 #include "main/bufferobj.h"
31 #include "main/imports.h"
32 #include "main/mfeatures.h"
34 #include "vbo_context.h"
40 static void vbo_save_callback_init( struct gl_context
*ctx
)
42 ctx
->Driver
.NewList
= vbo_save_NewList
;
43 ctx
->Driver
.EndList
= vbo_save_EndList
;
44 ctx
->Driver
.SaveFlushVertices
= vbo_save_SaveFlushVertices
;
45 ctx
->Driver
.BeginCallList
= vbo_save_BeginCallList
;
46 ctx
->Driver
.EndCallList
= vbo_save_EndCallList
;
47 ctx
->Driver
.NotifySaveBegin
= vbo_save_NotifyBegin
;
53 * Called at context creation time.
55 void vbo_save_init( struct gl_context
*ctx
)
57 struct vbo_context
*vbo
= vbo_context(ctx
);
58 struct vbo_save_context
*save
= &vbo
->save
;
62 vbo_save_api_init( save
);
63 vbo_save_callback_init(ctx
);
66 struct gl_client_array
*arrays
= save
->arrays
;
69 memcpy(arrays
, &vbo
->currval
[VBO_ATTRIB_POS
],
70 VERT_ATTRIB_FF_MAX
* sizeof(arrays
[0]));
71 for (i
= 0; i
< VERT_ATTRIB_FF_MAX
; ++i
) {
72 struct gl_client_array
*array
;
73 array
= &arrays
[VERT_ATTRIB_FF(i
)];
74 array
->BufferObj
= NULL
;
75 _mesa_reference_buffer_object(ctx
, &arrays
->BufferObj
,
76 vbo
->currval
[VBO_ATTRIB_POS
+i
].BufferObj
);
79 memcpy(arrays
+ VERT_ATTRIB_GENERIC(0),
80 &vbo
->currval
[VBO_ATTRIB_GENERIC0
],
81 VERT_ATTRIB_GENERIC_MAX
* sizeof(arrays
[0]));
83 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; ++i
) {
84 struct gl_client_array
*array
;
85 array
= &arrays
[VERT_ATTRIB_GENERIC(i
)];
86 array
->BufferObj
= NULL
;
87 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
88 vbo
->currval
[VBO_ATTRIB_GENERIC0
+i
].BufferObj
);
92 ctx
->Driver
.CurrentSavePrimitive
= PRIM_UNKNOWN
;
96 void vbo_save_destroy( struct gl_context
*ctx
)
98 struct vbo_context
*vbo
= vbo_context(ctx
);
99 struct vbo_save_context
*save
= &vbo
->save
;
102 if (save
->prim_store
) {
103 if ( --save
->prim_store
->refcount
== 0 ) {
104 FREE( save
->prim_store
);
105 save
->prim_store
= NULL
;
107 if ( --save
->vertex_store
->refcount
== 0 ) {
108 _mesa_reference_buffer_object(ctx
,
109 &save
->vertex_store
->bufferobj
, NULL
);
110 FREE( save
->vertex_store
);
111 save
->vertex_store
= NULL
;
115 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
116 _mesa_reference_buffer_object(ctx
, &save
->arrays
[i
].BufferObj
, NULL
);
123 /* Note that this can occur during the playback of a display list:
125 void vbo_save_fallback( struct gl_context
*ctx
, GLboolean fallback
)
127 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
130 save
->replay_flags
|= VBO_SAVE_FALLBACK
;
132 save
->replay_flags
&= ~VBO_SAVE_FALLBACK
;
136 #endif /* FEATURE_dlist */