1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci * Authors:
25bf215546Sopenharmony_ci *    Keith Whitwell <keithw@vmware.com>
26bf215546Sopenharmony_ci */
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "main/arrayobj.h"
30bf215546Sopenharmony_ci#include "main/bufferobj.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "util/u_memory.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "vbo_private.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci/**
38bf215546Sopenharmony_ci * Called at context creation time.
39bf215546Sopenharmony_ci */
40bf215546Sopenharmony_civoid vbo_save_init( struct gl_context *ctx )
41bf215546Sopenharmony_ci{
42bf215546Sopenharmony_ci   struct vbo_context *vbo = vbo_context(ctx);
43bf215546Sopenharmony_ci   struct vbo_save_context *save = &vbo->save;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   vbo_save_api_init( save );
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   for (gl_vertex_processing_mode vpm = VP_MODE_FF; vpm < VP_MODE_MAX; ++vpm)
48bf215546Sopenharmony_ci      save->VAO[vpm] = NULL;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   save->no_current_update = false;
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci   ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
53bf215546Sopenharmony_ci}
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_civoid vbo_save_destroy( struct gl_context *ctx )
57bf215546Sopenharmony_ci{
58bf215546Sopenharmony_ci   struct vbo_context *vbo = vbo_context(ctx);
59bf215546Sopenharmony_ci   struct vbo_save_context *save = &vbo->save;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   for (gl_vertex_processing_mode vpm = VP_MODE_FF; vpm < VP_MODE_MAX; ++vpm)
62bf215546Sopenharmony_ci      _mesa_reference_vao(ctx, &save->VAO[vpm], NULL);
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   if (save->prim_store) {
65bf215546Sopenharmony_ci      free(save->prim_store->prims);
66bf215546Sopenharmony_ci      FREE(save->prim_store);
67bf215546Sopenharmony_ci      save->prim_store = NULL;
68bf215546Sopenharmony_ci   }
69bf215546Sopenharmony_ci   if (save->vertex_store) {
70bf215546Sopenharmony_ci      free(save->vertex_store->buffer_in_ram);
71bf215546Sopenharmony_ci      FREE(save->vertex_store);
72bf215546Sopenharmony_ci      save->vertex_store = NULL;
73bf215546Sopenharmony_ci   }
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   if (save->copied.buffer)
76bf215546Sopenharmony_ci      free(save->copied.buffer);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   _mesa_reference_buffer_object(ctx, &save->current_bo, NULL);
79bf215546Sopenharmony_ci}
80