mesa: Restore 78-column wrapping of license text in C-style comments.
[mesa.git] / src / mesa / vbo / vbo_save.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29
30 #include "main/mtypes.h"
31 #include "main/bufferobj.h"
32 #include "main/imports.h"
33
34 #include "vbo_context.h"
35
36
37 static void vbo_save_callback_init( struct gl_context *ctx )
38 {
39 ctx->Driver.NewList = vbo_save_NewList;
40 ctx->Driver.EndList = vbo_save_EndList;
41 ctx->Driver.SaveFlushVertices = vbo_save_SaveFlushVertices;
42 ctx->Driver.BeginCallList = vbo_save_BeginCallList;
43 ctx->Driver.EndCallList = vbo_save_EndCallList;
44 ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin;
45 }
46
47
48
49 /**
50 * Called at context creation time.
51 */
52 void vbo_save_init( struct gl_context *ctx )
53 {
54 struct vbo_context *vbo = vbo_context(ctx);
55 struct vbo_save_context *save = &vbo->save;
56
57 save->ctx = ctx;
58
59 vbo_save_api_init( save );
60 vbo_save_callback_init(ctx);
61
62 {
63 struct gl_client_array *arrays = save->arrays;
64 unsigned i;
65
66 memcpy(arrays, &vbo->currval[VBO_ATTRIB_POS],
67 VERT_ATTRIB_FF_MAX * sizeof(arrays[0]));
68 for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) {
69 struct gl_client_array *array;
70 array = &arrays[VERT_ATTRIB_FF(i)];
71 array->BufferObj = NULL;
72 _mesa_reference_buffer_object(ctx, &arrays->BufferObj,
73 vbo->currval[VBO_ATTRIB_POS+i].BufferObj);
74 }
75
76 memcpy(arrays + VERT_ATTRIB_GENERIC(0),
77 &vbo->currval[VBO_ATTRIB_GENERIC0],
78 VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0]));
79
80 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) {
81 struct gl_client_array *array;
82 array = &arrays[VERT_ATTRIB_GENERIC(i)];
83 array->BufferObj = NULL;
84 _mesa_reference_buffer_object(ctx, &array->BufferObj,
85 vbo->currval[VBO_ATTRIB_GENERIC0+i].BufferObj);
86 }
87 }
88
89 ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
90 }
91
92
93 void vbo_save_destroy( struct gl_context *ctx )
94 {
95 struct vbo_context *vbo = vbo_context(ctx);
96 struct vbo_save_context *save = &vbo->save;
97 GLuint i;
98
99 if (save->prim_store) {
100 if ( --save->prim_store->refcount == 0 ) {
101 free(save->prim_store);
102 save->prim_store = NULL;
103 }
104 if ( --save->vertex_store->refcount == 0 ) {
105 _mesa_reference_buffer_object(ctx,
106 &save->vertex_store->bufferobj, NULL);
107 free(save->vertex_store);
108 save->vertex_store = NULL;
109 }
110 }
111
112 for (i = 0; i < VBO_ATTRIB_MAX; i++) {
113 _mesa_reference_buffer_object(ctx, &save->arrays[i].BufferObj, NULL);
114 }
115 }
116
117
118
119
120 /* Note that this can occur during the playback of a display list:
121 */
122 void vbo_save_fallback( struct gl_context *ctx, GLboolean fallback )
123 {
124 struct vbo_save_context *save = &vbo_context(ctx)->save;
125
126 if (fallback)
127 save->replay_flags |= VBO_SAVE_FALLBACK;
128 else
129 save->replay_flags &= ~VBO_SAVE_FALLBACK;
130 }