Skip to content

Commit

Permalink
Client|LogWidget: Observe when entry atlas is full
Browse files Browse the repository at this point in the history
If the entry atlas becomes full, empty it completely and start over
so that only the visible entries are allocated.
  • Loading branch information
skyjake committed Jul 4, 2013
1 parent 199409d commit d58b108
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions doomsday/client/src/ui/widgets/logwidget.cpp
Expand Up @@ -42,6 +42,7 @@ using namespace ui;

DENG2_PIMPL(LogWidget),
DENG2_OBSERVES(Atlas, Reposition),
DENG2_OBSERVES(Atlas, OutOfSpace),
public Font::RichFormat::IStyle
{
typedef GLBufferT<Vertex2TexRgba> VertexBuf;
Expand Down Expand Up @@ -491,7 +492,9 @@ public Font::RichFormat::IStyle
entryAtlas = AtlasTexture::newWithRowAllocator(
Atlas::BackingStore | Atlas::AllowDefragment,
GLTexture::maximumSize().min(Atlas::Size(2048, 1024)));

entryAtlas->audienceForReposition += this;
entryAtlas->audienceForOutOfSpace += this;

// Simple texture for the scroll indicator.
Image solidWhitePixel = Image::solidColor(Image::Color(255, 255, 255, 255),
Expand Down Expand Up @@ -535,6 +538,15 @@ public Font::RichFormat::IStyle
}
}

void atlasOutOfSpace(Atlas &atlas)
{
if(entryAtlas == &atlas)
{
entryAtlasLayoutChanged = true;
releaseAllComposedEntries();
}
}

duint contentWidth() const
{
return self.viewportSize().x;
Expand Down Expand Up @@ -620,6 +632,17 @@ public Font::RichFormat::IStyle
}
}

/**
* Releases all entries currently stored in the entry atlas.
*/
void releaseAllComposedEntries()
{
for(int i = 0; i < cache.size(); ++i)
{
cache[i]->clear();
}
}

/**
* Removes entries from the sink and the cache.
*/
Expand Down Expand Up @@ -711,17 +734,20 @@ public Font::RichFormat::IStyle
}
visibleRange.start = idx;
}
}

if(entryAtlasLayoutChanged)
{
// Oops, the atlas was optimized during the loop and some items'
// positions are obsolete.
verts.clear();
continue;
if(entryAtlasLayoutChanged)
{
goto nextAttempt;
}
}

// Successfully completed.
break;

nextAttempt:
// Oops, the atlas was optimized during the loop and some items'
// positions are obsolete.
verts.clear();
}

// Draw the scroll indicator, too.
Expand Down

0 comments on commit d58b108

Please sign in to comment.