// Filename: vertexBufferContext.h
// Created by:  drose (17Mar05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University.  All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license.  You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////

#ifndef VERTEXBUFFERCONTEXT_H
#define VERTEXBUFFERCONTEXT_H

#include "pandabase.h"

#include "bufferContext.h"
#include "geomVertexArrayData.h"
#include "preparedGraphicsObjects.h"
#include "adaptiveLru.h"

////////////////////////////////////////////////////////////////////
//       Class : VertexBufferContext
// Description : This is a special class object that holds all the
//               information returned by a particular GSG to indicate
//               the vertex data array's internal context identifier.
//
//               This allows the GSG to cache the vertex data array in
//               whatever way makes sense.  For instance, DirectX can
//               allocate a vertex buffer for the array.  OpenGL can
//               create a buffer object.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GOBJ VertexBufferContext : public BufferContext, public AdaptiveLruPage {
public:
  INLINE VertexBufferContext(PreparedGraphicsObjects *pgo,
                             GeomVertexArrayData *data);

PUBLISHED:
  INLINE GeomVertexArrayData *get_data() const;

  INLINE bool changed_size(const GeomVertexArrayDataHandle *reader) const;
  INLINE bool changed_usage_hint(const GeomVertexArrayDataHandle *reader) const;
  INLINE bool was_modified(const GeomVertexArrayDataHandle *reader) const;

public:
  INLINE void update_data_size_bytes(size_t new_data_size_bytes);
  INLINE void mark_loaded(const GeomVertexArrayDataHandle *reader);
  INLINE void mark_unloaded();

  virtual void output(ostream &out) const;
  virtual void write(ostream &out, int indent_level) const;

private:
  // This cannot be a PT(GeomVertexArrayData), because the data and
  // the GSG both own their VertexBufferContexts!  That would create a
  // circular reference count.
  GeomVertexArrayData *_data;
  GeomEnums::UsageHint _usage_hint;

public:
  static TypeHandle get_class_type() {
    return _type_handle;
  }
  static void init_type() {
    BufferContext::init_type();
    register_type(_type_handle, "VertexBufferContext",
                  BufferContext::get_class_type());
  }
  virtual TypeHandle get_type() const {
    return get_class_type();
  }
  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}

private:
  static TypeHandle _type_handle;

  friend class PreparedGraphicsObjects;
};

inline ostream &operator << (ostream &out, const VertexBufferContext &context) {
  context.output(out);
  return out;
}

#include "vertexBufferContext.I"

#endif

