vbo: add new VBO_ATTRIBS_ masks to vbo_attrib.h
[mesa.git] / src / mesa / vbo / vbo_save.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keithw@vmware.com>
26 */
27
28
29 #include "main/mtypes.h"
30 #include "main/bufferobj.h"
31
32 #include "vbo_private.h"
33
34
35 /**
36 * Called at context creation time.
37 */
38 void vbo_save_init( struct gl_context *ctx )
39 {
40 struct vbo_context *vbo = vbo_context(ctx);
41 struct vbo_save_context *save = &vbo->save;
42
43 save->ctx = ctx;
44
45 vbo_save_api_init( save );
46
47 {
48 struct gl_vertex_array *arrays = save->arrays;
49 unsigned i;
50
51 memcpy(arrays, &vbo->currval[VBO_ATTRIB_POS],
52 VERT_ATTRIB_FF_MAX * sizeof(arrays[0]));
53 for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) {
54 struct gl_vertex_array *array;
55 array = &arrays[VERT_ATTRIB_FF(i)];
56 array->BufferObj = NULL;
57 _mesa_reference_buffer_object(ctx, &arrays->BufferObj,
58 vbo->currval[VBO_ATTRIB_POS+i].BufferObj);
59 }
60
61 memcpy(arrays + VERT_ATTRIB_GENERIC(0),
62 &vbo->currval[VBO_ATTRIB_GENERIC0],
63 VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0]));
64
65 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) {
66 struct gl_vertex_array *array;
67 array = &arrays[VERT_ATTRIB_GENERIC(i)];
68 array->BufferObj = NULL;
69 _mesa_reference_buffer_object(ctx, &array->BufferObj,
70 vbo->currval[VBO_ATTRIB_GENERIC0+i].BufferObj);
71 }
72 }
73
74 ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
75 }
76
77
78 void vbo_save_destroy( struct gl_context *ctx )
79 {
80 struct vbo_context *vbo = vbo_context(ctx);
81 struct vbo_save_context *save = &vbo->save;
82 GLuint i;
83
84 if (save->prim_store) {
85 if ( --save->prim_store->refcount == 0 ) {
86 free(save->prim_store);
87 save->prim_store = NULL;
88 }
89 if ( --save->vertex_store->refcount == 0 ) {
90 _mesa_reference_buffer_object(ctx,
91 &save->vertex_store->bufferobj, NULL);
92 free(save->vertex_store);
93 save->vertex_store = NULL;
94 }
95 }
96
97 for (i = 0; i < VBO_ATTRIB_MAX; i++) {
98 _mesa_reference_buffer_object(ctx, &save->arrays[i].BufferObj, NULL);
99 }
100 }
101
102
103
104
105 /* Note that this can occur during the playback of a display list:
106 */
107 void vbo_save_fallback( struct gl_context *ctx, GLboolean fallback )
108 {
109 struct vbo_save_context *save = &vbo_context(ctx)->save;
110
111 if (fallback)
112 save->replay_flags |= VBO_SAVE_FALLBACK;
113 else
114 save->replay_flags &= ~VBO_SAVE_FALLBACK;
115 }