textureContext.h
00001 // Filename: textureContext.h
00002 // Created by:  drose (07Oct99)
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 TEXTURECONTEXT_H
00016 #define TEXTURECONTEXT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "bufferContext.h"
00021 #include "texture.h"
00022 #include "preparedGraphicsObjects.h"
00023 #include "adaptiveLru.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : TextureContext
00027 // Description : This is a special class object that holds all the
00028 //               information returned by a particular GSG to indicate
00029 //               the texture's internal context identifier.
00030 //
00031 //               Textures typically have an immediate-mode and a
00032 //               retained-mode operation.  When using textures in
00033 //               retained-mode (in response to Texture::prepare()),
00034 //               the GSG will create some internal handle for the
00035 //               texture and store it here.  The texture stores all of
00036 //               these handles internally.
00037 ////////////////////////////////////////////////////////////////////
00038 class EXPCL_PANDA_GOBJ TextureContext : public BufferContext, public AdaptiveLruPage {
00039 public:
00040   INLINE TextureContext(PreparedGraphicsObjects *pgo, Texture *tex, int view);
00041 
00042 PUBLISHED:
00043   INLINE Texture *get_texture() const;
00044   INLINE int get_view() const;
00045 
00046   INLINE bool was_modified() const;
00047   INLINE bool was_properties_modified() const;
00048   INLINE bool was_image_modified() const;
00049   INLINE bool was_simple_image_modified() const;
00050 
00051   INLINE UpdateSeq get_properties_modified() const;
00052   INLINE UpdateSeq get_image_modified() const;
00053   INLINE UpdateSeq get_simple_image_modified() const;
00054 
00055 public:
00056   INLINE void update_data_size_bytes(size_t new_data_size_bytes);
00057   INLINE void mark_loaded();
00058   INLINE void mark_simple_loaded();
00059   INLINE void mark_unloaded();
00060   INLINE void mark_needs_reload();
00061 
00062   virtual void output(ostream &out) const;
00063   virtual void write(ostream &out, int indent_level) const;
00064 
00065 private:
00066   // This cannot be a PT(Texture), because the texture and the GSG
00067   // both own their TextureContexts!  That would create a circular
00068   // reference count.
00069   Texture *_texture;
00070   int _view;
00071   UpdateSeq _properties_modified;
00072   UpdateSeq _image_modified;
00073   UpdateSeq _simple_image_modified;
00074   
00075 public:
00076   static TypeHandle get_class_type() {
00077     return _type_handle;
00078   }
00079   static void init_type() {
00080     BufferContext::init_type();
00081     register_type(_type_handle, "TextureContext",
00082                   BufferContext::get_class_type());
00083   }
00084   virtual TypeHandle get_type() const {
00085     return get_class_type();
00086   }
00087   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00088 
00089 private:
00090   static TypeHandle _type_handle;
00091 
00092   friend class PreparedGraphicsObjects;
00093 };
00094 
00095 inline ostream &operator << (ostream &out, const TextureContext &context) {
00096   context.output(out);
00097   return out;
00098 }
00099 
00100 #include "textureContext.I"
00101 
00102 #endif
00103