Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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 <keith@tungstengraphics.com>
  26.  */
  27.  
  28.  
  29. #include "main/mtypes.h"
  30. #include "main/bufferobj.h"
  31. #include "main/imports.h"
  32.  
  33. #include "vbo_context.h"
  34.  
  35.  
  36. static void vbo_save_callback_init( struct gl_context *ctx )
  37. {
  38.    ctx->Driver.NewList = vbo_save_NewList;
  39.    ctx->Driver.EndList = vbo_save_EndList;
  40.    ctx->Driver.SaveFlushVertices = vbo_save_SaveFlushVertices;
  41.    ctx->Driver.BeginCallList = vbo_save_BeginCallList;
  42.    ctx->Driver.EndCallList = vbo_save_EndCallList;
  43.    ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin;
  44. }
  45.  
  46.  
  47.  
  48. /**
  49.  * Called at context creation time.
  50.  */
  51. void vbo_save_init( struct gl_context *ctx )
  52. {
  53.    struct vbo_context *vbo = vbo_context(ctx);
  54.    struct vbo_save_context *save = &vbo->save;
  55.  
  56.    save->ctx = ctx;
  57.  
  58.    vbo_save_api_init( save );
  59.    vbo_save_callback_init(ctx);
  60.  
  61.    {
  62.       struct gl_client_array *arrays = save->arrays;
  63.       unsigned i;
  64.  
  65.       memcpy(arrays, &vbo->currval[VBO_ATTRIB_POS],
  66.              VERT_ATTRIB_FF_MAX * sizeof(arrays[0]));
  67.       for (i = 0; i < VERT_ATTRIB_FF_MAX; ++i) {
  68.          struct gl_client_array *array;
  69.          array = &arrays[VERT_ATTRIB_FF(i)];
  70.          array->BufferObj = NULL;
  71.          _mesa_reference_buffer_object(ctx, &arrays->BufferObj,
  72.                                        vbo->currval[VBO_ATTRIB_POS+i].BufferObj);
  73.       }
  74.  
  75.       memcpy(arrays + VERT_ATTRIB_GENERIC(0),
  76.              &vbo->currval[VBO_ATTRIB_GENERIC0],
  77.              VERT_ATTRIB_GENERIC_MAX * sizeof(arrays[0]));
  78.  
  79.       for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; ++i) {
  80.          struct gl_client_array *array;
  81.          array = &arrays[VERT_ATTRIB_GENERIC(i)];
  82.          array->BufferObj = NULL;
  83.          _mesa_reference_buffer_object(ctx, &array->BufferObj,
  84.                            vbo->currval[VBO_ATTRIB_GENERIC0+i].BufferObj);
  85.       }
  86.    }
  87.  
  88.    ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END;
  89. }
  90.  
  91.  
  92. void vbo_save_destroy( struct gl_context *ctx )
  93. {
  94.    struct vbo_context *vbo = vbo_context(ctx);
  95.    struct vbo_save_context *save = &vbo->save;
  96.    GLuint i;
  97.  
  98.    if (save->prim_store) {
  99.       if ( --save->prim_store->refcount == 0 ) {
  100.          free(save->prim_store);
  101.          save->prim_store = NULL;
  102.       }
  103.       if ( --save->vertex_store->refcount == 0 ) {
  104.          _mesa_reference_buffer_object(ctx,
  105.                                        &save->vertex_store->bufferobj, NULL);
  106.          free(save->vertex_store);
  107.          save->vertex_store = NULL;
  108.       }
  109.    }
  110.  
  111.    for (i = 0; i < VBO_ATTRIB_MAX; i++) {
  112.       _mesa_reference_buffer_object(ctx, &save->arrays[i].BufferObj, NULL);
  113.    }
  114. }
  115.  
  116.  
  117.  
  118.  
  119. /* Note that this can occur during the playback of a display list:
  120.  */
  121. void vbo_save_fallback( struct gl_context *ctx, GLboolean fallback )
  122. {
  123.    struct vbo_save_context *save = &vbo_context(ctx)->save;
  124.  
  125.    if (fallback)
  126.       save->replay_flags |= VBO_SAVE_FALLBACK;
  127.    else
  128.       save->replay_flags &= ~VBO_SAVE_FALLBACK;
  129. }
  130.