bufferContext.h
00001 // Filename: bufferContext.h
00002 // Created by:  drose (16Mar06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef BUFFERCONTEXT_H
00016 #define BUFFERCONTEXT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "savedContext.h"
00021 #include "updateSeq.h"
00022 #include "linkedListNode.h"
00023 #include "bufferContextChain.h"
00024 #include "bufferResidencyTracker.h"
00025 
00026 class PreparedGraphicsObjects;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : BufferContext
00030 // Description : This is a base class for those kinds of SavedContexts
00031 //               that occupy an easily-measured (and substantial)
00032 //               number of bytes in the video card's frame buffer
00033 //               memory or AGP memory.  At the present, this includes
00034 //               most of the SavedContext types: VertexBufferContext
00035 //               and IndexBufferContext, as well as TextureContext.
00036 //
00037 //               This class provides methods for tracking the video
00038 //               memory utilization, as well as residency of each
00039 //               object, via PStats.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA_GOBJ BufferContext : public SavedContext, private LinkedListNode {
00042 public:
00043   BufferContext(BufferResidencyTracker *residency);
00044   virtual ~BufferContext();
00045 
00046 PUBLISHED:
00047   INLINE size_t get_data_size_bytes() const;
00048   INLINE UpdateSeq get_modified() const;
00049   INLINE bool get_active() const;
00050   INLINE bool get_resident() const;
00051 
00052 public:
00053   INLINE void set_active(bool flag);
00054   INLINE void set_resident(bool flag);
00055 
00056   INLINE BufferContext *get_next() const;
00057 
00058   INLINE void update_data_size_bytes(size_t new_data_size_bytes);
00059   INLINE void update_modified(UpdateSeq new_modified);
00060 
00061 private:
00062   void set_owning_chain(BufferContextChain *chain);
00063 
00064 private:
00065   BufferResidencyTracker *_residency;
00066   int _residency_state;
00067 
00068   size_t _data_size_bytes;
00069   UpdateSeq _modified;
00070   BufferContextChain *_owning_chain;
00071 
00072 public:
00073   static TypeHandle get_class_type() {
00074     return _type_handle;
00075   }
00076   static void init_type() {
00077     SavedContext::init_type();
00078     register_type(_type_handle, "BufferContext",
00079                   SavedContext::get_class_type());
00080   }
00081   virtual TypeHandle get_type() const {
00082     return get_class_type();
00083   }
00084   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00085 
00086 private:
00087   static TypeHandle _type_handle;
00088 
00089   friend class PreparedGraphicsObjects;
00090   friend class BufferResidencyTracker;
00091   friend class BufferContextChain;
00092 };
00093 
00094 #include "bufferContext.I"
00095 
00096 #endif
00097