xref: /third_party/mesa3d/src/mesa/vbo/vbo_save.c (revision bf215546)
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/arrayobj.h"
30#include "main/bufferobj.h"
31
32#include "util/u_memory.h"
33
34#include "vbo_private.h"
35
36
37/**
38 * Called at context creation time.
39 */
40void vbo_save_init( struct gl_context *ctx )
41{
42   struct vbo_context *vbo = vbo_context(ctx);
43   struct vbo_save_context *save = &vbo->save;
44
45   vbo_save_api_init( save );
46
47   for (gl_vertex_processing_mode vpm = VP_MODE_FF; vpm < VP_MODE_MAX; ++vpm)
48      save->VAO[vpm] = NULL;
49
50   save->no_current_update = false;
51
52   ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
53}
54
55
56void vbo_save_destroy( struct gl_context *ctx )
57{
58   struct vbo_context *vbo = vbo_context(ctx);
59   struct vbo_save_context *save = &vbo->save;
60
61   for (gl_vertex_processing_mode vpm = VP_MODE_FF; vpm < VP_MODE_MAX; ++vpm)
62      _mesa_reference_vao(ctx, &save->VAO[vpm], NULL);
63
64   if (save->prim_store) {
65      free(save->prim_store->prims);
66      FREE(save->prim_store);
67      save->prim_store = NULL;
68   }
69   if (save->vertex_store) {
70      free(save->vertex_store->buffer_in_ram);
71      FREE(save->vertex_store);
72      save->vertex_store = NULL;
73   }
74
75   if (save->copied.buffer)
76      free(save->copied.buffer);
77
78   _mesa_reference_buffer_object(ctx, &save->current_bo, NULL);
79}
80