Panda3D
textureContext.h
1 // Filename: textureContext.h
2 // Created by: drose (07Oct99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TEXTURECONTEXT_H
16 #define TEXTURECONTEXT_H
17 
18 #include "pandabase.h"
19 
20 #include "bufferContext.h"
21 #include "texture.h"
22 #include "preparedGraphicsObjects.h"
23 #include "adaptiveLru.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : TextureContext
27 // Description : This is a special class object that holds all the
28 // information returned by a particular GSG to indicate
29 // the texture's internal context identifier.
30 //
31 // Textures typically have an immediate-mode and a
32 // retained-mode operation. When using textures in
33 // retained-mode (in response to Texture::prepare()),
34 // the GSG will create some internal handle for the
35 // texture and store it here. The texture stores all of
36 // these handles internally.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_GOBJ TextureContext : public BufferContext, public AdaptiveLruPage {
39 public:
40  INLINE TextureContext(PreparedGraphicsObjects *pgo, Texture *tex, int view);
41 
42 PUBLISHED:
43  INLINE Texture *get_texture() const;
44  INLINE int get_view() const;
45 
46  INLINE bool was_modified() const;
47  INLINE bool was_properties_modified() const;
48  INLINE bool was_image_modified() const;
49  INLINE bool was_simple_image_modified() const;
50 
51  INLINE UpdateSeq get_properties_modified() const;
52  INLINE UpdateSeq get_image_modified() const;
53  INLINE UpdateSeq get_simple_image_modified() const;
54 
55 public:
56  INLINE void update_data_size_bytes(size_t new_data_size_bytes);
57  INLINE void mark_loaded();
58  INLINE void mark_simple_loaded();
59  INLINE void mark_unloaded();
60  INLINE void mark_needs_reload();
61 
62  virtual void output(ostream &out) const;
63  virtual void write(ostream &out, int indent_level) const;
64 
65 private:
66  // This cannot be a PT(Texture), because the texture and the GSG
67  // both own their TextureContexts! That would create a circular
68  // reference count.
69  Texture *_texture;
70  int _view;
71  UpdateSeq _properties_modified;
72  UpdateSeq _image_modified;
73  UpdateSeq _simple_image_modified;
74 
75 public:
76  static TypeHandle get_class_type() {
77  return _type_handle;
78  }
79  static void init_type() {
80  BufferContext::init_type();
81  register_type(_type_handle, "TextureContext",
82  BufferContext::get_class_type());
83  }
84  virtual TypeHandle get_type() const {
85  return get_class_type();
86  }
87  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
88 
89 private:
90  static TypeHandle _type_handle;
91 
92  friend class PreparedGraphicsObjects;
93 };
94 
95 inline ostream &operator << (ostream &out, const TextureContext &context) {
96  context.output(out);
97  return out;
98 }
99 
100 #include "textureContext.I"
101 
102 #endif
103 
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
Definition: bufferContext.h:41
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
This is a special class object that holds all the information returned by a particular GSG to indicat...
A table of objects that are saved within the graphics context for reference by handle later...
void update_data_size_bytes(size_t new_data_size_bytes)
Should be called (usually by a derived class) when the on-card size of this object has changed...
One atomic piece that may be managed by a AdaptiveLru chain.
Definition: adaptiveLru.h:145
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43