1fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/*
2fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Mesa 3-D graphics library
337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul * Version:  7.2
4fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
7fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
8fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * copy of this software and associated documentation files (the "Software"),
9fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * to deal in the Software without restriction, including without limitation
10fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
12fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Software is furnished to do so, subject to the following conditions:
13fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
14fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * The above copyright notice and this permission notice shall be included
15fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * in all copies or substantial portions of the Software.
16fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
17fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
24fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Authors:
25fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *    Keith Whitwell <keith@tungstengraphics.com>
26fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
27fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
28fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
29c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/mtypes.h"
3037c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul#include "main/bufferobj.h"
31c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/imports.h"
3214b36cd568b7f3ae963430248fcd7ef0b7a165f6Vinson Lee#include "main/mfeatures.h"
33fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
34fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_context.h"
35fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
36fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
378d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#if FEATURE_dlist
388d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu
39fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
40f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void vbo_save_callback_init( struct gl_context *ctx )
41e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell{
42e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.NewList = vbo_save_NewList;
43e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.EndList = vbo_save_EndList;
44e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.SaveFlushVertices = vbo_save_SaveFlushVertices;
45e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.BeginCallList = vbo_save_BeginCallList;
46e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.EndCallList = vbo_save_EndCallList;
47e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin;
48e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell}
49e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell
50e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell
51e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell
52c55ebc3e3e556a5bf5cd78cee2807f4cbb6f626aBrian Paul/**
53c55ebc3e3e556a5bf5cd78cee2807f4cbb6f626aBrian Paul * Called at context creation time.
54c55ebc3e3e556a5bf5cd78cee2807f4cbb6f626aBrian Paul */
55f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_init( struct gl_context *ctx )
56fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
57fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell   struct vbo_context *vbo = vbo_context(ctx);
58fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell   struct vbo_save_context *save = &vbo->save;
59fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
60fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   save->ctx = ctx;
61fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
62fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   vbo_save_api_init( save );
63e8abd098b36c30d76b4c396970fd793ae58e0702Keith Whitwell   vbo_save_callback_init(ctx);
64fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
65fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell   {
66fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell      struct gl_client_array *arrays = save->arrays;
6705ac187f305bb653d569b5c07446ec0f4cd7ff08José Fonseca      unsigned i;
6805ac187f305bb653d569b5c07446ec0f4cd7ff08José Fonseca
69fa48137f292bbf8cbcd65e9caf33633cddc96600Marek Olšák      memcpy(arrays, &vbo->currval[VBO_ATTRIB_POS],
70ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich             VERT_ATTRIB_FF_MAX * sizeof(arrays[0]));
71ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich      for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) {
72ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         struct gl_client_array *array;
73ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         array = &arrays[VERT_ATTRIB_FF(i)];
74ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         array->BufferObj = NULL;
75ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         _mesa_reference_buffer_object(ctx, &arrays->BufferObj,
76fa48137f292bbf8cbcd65e9caf33633cddc96600Marek Olšák                                       vbo->currval[VBO_ATTRIB_POS+i].BufferObj);
77ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich      }
78ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich
798c990de0d682bbedfd7e1988d4f8948ea99b0cc3Marek Olšák      memcpy(arrays + VERT_ATTRIB_GENERIC(0),
808c990de0d682bbedfd7e1988d4f8948ea99b0cc3Marek Olšák             &vbo->currval[VBO_ATTRIB_GENERIC0],
81ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich             VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0]));
828c990de0d682bbedfd7e1988d4f8948ea99b0cc3Marek Olšák
83ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich      for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) {
84ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         struct gl_client_array *array;
85ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         array = &arrays[VERT_ATTRIB_GENERIC(i)];
86ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         array->BufferObj = NULL;
87ed42c2580717527b2005580940fc766d95bb6b0bMathias Fröhlich         _mesa_reference_buffer_object(ctx, &array->BufferObj,
888c990de0d682bbedfd7e1988d4f8948ea99b0cc3Marek Olšák                           vbo->currval[VBO_ATTRIB_GENERIC0+i].BufferObj);
8905ac187f305bb653d569b5c07446ec0f4cd7ff08José Fonseca      }
90fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell   }
91fd2756006a0baf63f60548d8f509de5b9a143608Keith Whitwell
92fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
93fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
94fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
95fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
96f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_destroy( struct gl_context *ctx )
97fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
98f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian   struct vbo_context *vbo = vbo_context(ctx);
99f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian   struct vbo_save_context *save = &vbo->save;
10037c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul   GLuint i;
10137c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul
102f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian   if (save->prim_store) {
103f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian      if ( --save->prim_store->refcount == 0 ) {
104f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian         FREE( save->prim_store );
105f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian         save->prim_store = NULL;
106f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian      }
107f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian      if ( --save->vertex_store->refcount == 0 ) {
10837c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         _mesa_reference_buffer_object(ctx,
10937c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul                                       &save->vertex_store->bufferobj, NULL);
110f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian         FREE( save->vertex_store );
111f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian         save->vertex_store = NULL;
112f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian      }
113f0676cc4223fe05d84cee9d16f1094a7bfa181d4Brian   }
11437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul
11537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul   for (i = 0; i < VBO_ATTRIB_MAX; i++) {
11637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      _mesa_reference_buffer_object(ctx, &save->arrays[i].BufferObj, NULL);
11737c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul   }
118fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
119fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
120fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
121fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
122fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
123fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Note that this can occur during the playback of a display list:
124fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
125f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_fallback( struct gl_context *ctx, GLboolean fallback )
126fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
127fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   struct vbo_save_context *save = &vbo_context(ctx)->save;
128fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
129fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   if (fallback)
130fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      save->replay_flags |= VBO_SAVE_FALLBACK;
131fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   else
132fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      save->replay_flags &= ~VBO_SAVE_FALLBACK;
133fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
134fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
135fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
1368d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#endif /* FEATURE_dlist */
137