Panda3D
tinyTextureContext.cxx
1 // Filename: tinyTextureContext.cxx
2 // Created by: drose (30Apr08)
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 #include "tinyTextureContext.h"
16 #include "zgl.h"
17 
18 TypeHandle TinyTextureContext::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: TinyTextureContext::Destructor
22 // Access: Public
23 // Description: Releases the memory associated with the texture.
24 ////////////////////////////////////////////////////////////////////
27  GLTexture *gltex = &_gltex;
28  if (gltex->allocated_buffer != NULL) {
29  nassertv(gltex->num_levels != 0);
30  TinyTextureContext::get_class_type().dec_memory_usage(TypeHandle::MC_array, gltex->total_bytecount);
31  PANDA_FREE_ARRAY(gltex->allocated_buffer);
32  gltex->allocated_buffer = NULL;
33  gltex->total_bytecount = 0;
34  gltex->num_levels = 0;
35  } else {
36  nassertv(gltex->num_levels == 0);
37  }
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: TinyTextureContext::evict_lru
42 // Access: Public, Virtual
43 // Description: Evicts the page from the LRU. Called internally when
44 // the LRU determines that it is full. May also be
45 // called externally when necessary to explicitly evict
46 // the page.
47 //
48 // It is legal for this method to either evict the page
49 // as requested, do nothing (in which case the eviction
50 // will be requested again at the next epoch), or
51 // requeue itself on the tail of the queue (in which
52 // case the eviction will be requested again much
53 // later).
54 ////////////////////////////////////////////////////////////////////
57  dequeue_lru();
58 
59  GLTexture *gltex = &_gltex;
60  if (gltex->allocated_buffer != NULL) {
61  nassertv(gltex->num_levels != 0);
62  TinyTextureContext::get_class_type().dec_memory_usage(TypeHandle::MC_array, gltex->total_bytecount);
63  PANDA_FREE_ARRAY(gltex->allocated_buffer);
64  gltex->allocated_buffer = NULL;
65  gltex->total_bytecount = 0;
66  gltex->num_levels = 0;
67  } else {
68  nassertv(gltex->num_levels == 0);
69  }
70 
72  mark_unloaded();
73 }
virtual void evict_lru()
Evicts the page from the LRU.
void dequeue_lru()
Removes the page from its AdaptiveLru.
Definition: adaptiveLru.I:171
Definition: zgl.h:123
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...
void mark_unloaded()
Should be called after the texture has been forced out of texture memory.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
~TinyTextureContext()
Releases the memory associated with the texture.