28 const int TextureManager::kEnd = -1;
63 : items_(max_texture_units), back_(max_texture_units - 1), front_(0) {
64 DCHECK_EQ(items_.size(),
static_cast<size_t>(max_texture_units));
65 DCHECK_GE(max_texture_units, 1) <<
"TextureManager was initialized with < 1 "
66 "texture units. This could mean that "
67 "there is no valid GL context bound.";
75 DCHECK_LT(unit, static_cast<int>(items_.size()));
76 return items_[unit].texture;
80 DCHECK_LT(current_unit, static_cast<int>(items_.size()));
81 if (current_unit != kEnd && items_[current_unit].texture == texture) {
89 items_[back_].texture =
texture;
95 void TextureManager::Touch(
int unit) {
96 DCHECK_LT(unit, static_cast<int>(items_.size()));
100 Item& this_item = items_[unit];
102 if (this_item.prev != kEnd) {
104 Item& prev_item = items_[this_item.prev];
105 prev_item.next = this_item.next;
107 front_ = this_item.next;
109 if (this_item.next != kEnd) {
111 Item& next_item = items_[this_item.next];
112 next_item.prev = this_item.prev;
118 Item& back_item = items_[back_];
119 back_item.next = unit;
120 this_item.prev = back_;
121 this_item.next = kEnd;
126 if (units.GetMinPoint() < 0) {
127 LOG(
ERROR) <<
"The minimum unit for TextureManager to use must be >= 0.";
131 front_ = std::min(static_cast<int>(units.GetMinPoint()),
132 static_cast<int>(items_.size() - 1U));
133 back_ = std::min(static_cast<int>(units.GetMaxPoint()),
134 static_cast<int>(items_.size() - 1U));
137 memset(&items_[0], 0,
sizeof(Item) * items_.size());
140 items_[front_].prev = kEnd;
141 items_[front_].texture = NULL;
142 items_[front_].next = (front_ < back_) ? front_ + 1 : kEnd;
143 items_[back_].prev = (front_ < back_) ? back_ - 1 : kEnd;
144 items_[back_].texture = NULL;
145 items_[back_].next = kEnd;
146 for (
int i = front_ + 1; i < back_; ++i) {
147 items_[i].prev = i - 1;
148 items_[i].texture = NULL;
149 items_[i].next = i + 1;
int GetUnit(TextureType texture, int current_unit)
Returns the unit associated with the data pointer.
TextureType GetTexture(int unit) const
Returns the data at index unit.
Range< 1, int32 > Range1i
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
TextureManager(int max_texture_units)
A TextureManager must be initialized with a size of at least 1.
void SetUnitRange(const math::Range1i &units)
Sets the inclusive range of units that the TextureManager uses.
~TextureManager() override
#define DCHECK_GE(val1, val2)
Copyright 2016 Google Inc.
#define DCHECK_EQ(val1, val2)
TexturePtr texture
The Texture to add sub-image data to.
#define DCHECK_LT(val1, val2)