Skip to content

Commit

Permalink
Client|Cleanup: GuiRootWidget provides a texture with a solid white p…
Browse files Browse the repository at this point in the history
…ixel

A shared texture with a single white pixel is quite useful in many
widgets (at least until skin textures are added).
  • Loading branch information
skyjake committed May 29, 2013
1 parent 0047e5a commit 936b566
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/guirootwidget.h
Expand Up @@ -50,6 +50,7 @@ class GuiRootWidget : public de::RootWidget

de::AtlasTexture &atlas();
de::GLUniform &uAtlas();
de::Id solidWhitePixel() const;

static de::GLShaderBank &shaders();

Expand Down
30 changes: 23 additions & 7 deletions doomsday/client/src/ui/widgets/guirootwidget.cpp
Expand Up @@ -31,6 +31,7 @@ DENG2_PIMPL(GuiRootWidget)
ClientWindow *window;
QScopedPointer<AtlasTexture> atlas; ///< Shared atlas for most UI graphics/text.
GLUniform uTexAtlas;
Id solidWhiteTex;

Instance(Public *i, ClientWindow *win)
: Base(i),
Expand All @@ -46,6 +47,21 @@ DENG2_PIMPL(GuiRootWidget)
// shared GL resources, so we'll ask the widgets to do this now.
self.notifyTree(&Widget::deinitialize);
}

void initAtlas()
{
if(atlas.isNull())
{
atlas.reset(AtlasTexture::newWithRowAllocator(
Atlas::BackingStore | Atlas::AllowDefragment,
GLTexture::maximumSize().min(GLTexture::Size(4096, 4096))));
uTexAtlas = *atlas;

Image const solidWhitePixel = Image::solidColor(Image::Color(255, 255, 255, 255),
Image::Size(1, 1));
solidWhiteTex = atlas->alloc(solidWhitePixel);
}
}
};

GuiRootWidget::GuiRootWidget(ClientWindow *window)
Expand All @@ -65,13 +81,7 @@ ClientWindow &GuiRootWidget::window()

AtlasTexture &GuiRootWidget::atlas()
{
if(d->atlas.isNull())
{
d->atlas.reset(AtlasTexture::newWithRowAllocator(
Atlas::BackingStore | Atlas::AllowDefragment,
GLTexture::maximumSize().min(GLTexture::Size(4096, 4096))));
d->uTexAtlas = *d->atlas;
}
d->initAtlas();
return *d->atlas;
}

Expand All @@ -80,6 +90,12 @@ GLUniform &GuiRootWidget::uAtlas()
return d->uTexAtlas;
}

Id GuiRootWidget::solidWhitePixel() const
{
d->initAtlas();
return d->solidWhiteTex;
}

GLShaderBank &GuiRootWidget::shaders()
{
return ClientApp::glShaderBank();
Expand Down
15 changes: 5 additions & 10 deletions doomsday/client/src/ui/widgets/lineeditwidget.cpp
Expand Up @@ -48,7 +48,6 @@ DENG2_OBSERVES(Atlas, Reposition)
// GL objects.
bool needGeometry;
GLTextComposer composer;
Id bgTex;
Drawable drawable;
GLUniform uMvpMatrix;
GLUniform uColor;
Expand Down Expand Up @@ -114,9 +113,6 @@ DENG2_OBSERVES(Atlas, Reposition)
composer.setAtlas(atlas());
composer.setText(self.text());

// Temporary background texture for development...
bgTex = atlas().alloc(Image::solidColor(Image::Color(255, 255, 255, 255), Image::Size(1, 1)));

drawable.addBuffer(ID_BUF_TEXT, new VertexBuf);
drawable.addBufferWithNewProgram(ID_BUF_CURSOR, new VertexBuf, "cursor");

Expand All @@ -133,7 +129,6 @@ DENG2_OBSERVES(Atlas, Reposition)

void glDeinit()
{
atlas().release(bgTex);
composer.release();
}

Expand All @@ -155,12 +150,14 @@ DENG2_OBSERVES(Atlas, Reposition)

// The background.
VertexBuf::Builder verts;
verts.makeQuad(pos, bgColor, atlas().imageRectf(bgTex).middle());
verts.makeQuad(pos, bgColor, atlas().imageRectf(self.root().solidWhitePixel()).middle());

// Text lines.
Rectanglei const contentRect = pos.shrunk(margin);
composer.makeVertices(verts, contentRect, AlignLeft, AlignLeft);

Rectanglef const solidWhiteUv = atlas().imageRectf(self.root().solidWhitePixel());

// Underline the possible suggested completion.
if(self.isSuggestingCompletion())
{
Expand All @@ -178,8 +175,7 @@ DENG2_OBSERVES(Atlas, Reposition)
Vector2i end = wraps.charTopLeftInPixels(i, i == endPos.y? endPos.x : span.end) + offset;

verts.makeQuad(Rectanglef(start, end + Vector2i(0, 1)),
Vector4f(1, 1, 1, 1),
atlas().imageRectf(bgTex).middle());
Vector4f(1, 1, 1, 1), solidWhiteUv.middle());
}
}

Expand All @@ -194,8 +190,7 @@ DENG2_OBSERVES(Atlas, Reposition)
verts.clear();
verts.makeQuad(Rectanglef(cp + Vector2f(-1, 0),
cp + Vector2f(1, font->height().value())),
Vector4f(1, 1, 1, 1),
atlas().imageRectf(bgTex).middle());
Vector4f(1, 1, 1, 1), solidWhiteUv.middle());

drawable.buffer<VertexBuf>(ID_BUF_CURSOR)
.setVertices(gl::TriangleStrip, verts, gl::Static);
Expand Down
7 changes: 1 addition & 6 deletions doomsday/client/src/ui/widgets/logwidget.cpp
Expand Up @@ -331,7 +331,6 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle
GLUniform uBgMvpMatrix;
Matrix4f projMatrix;
Matrix4f viewMatrix;
Id bgTex;
Id scrollTex;

Instance(Public *i)
Expand Down Expand Up @@ -490,8 +489,6 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle

Image solidWhitePixel = Image::solidColor(Image::Color(255, 255, 255, 255),
Image::Size(1, 1));
bgTex = self.root().atlas().alloc(solidWhitePixel);

scrollTex = entryAtlas->alloc(solidWhitePixel);

uTex = entryAtlas;
Expand All @@ -512,8 +509,6 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle

void glDeinit()
{
self.root().atlas().release(bgTex);

clearCache();

delete entryAtlas;
Expand Down Expand Up @@ -750,7 +745,7 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle
bgBuf->setVertices(gl::TriangleStrip,
VertexBuf::Builder().makeQuad(pos,
self.style().colors().colorf("background"),
self.root().atlas().imageRectf(bgTex).middle()),
self.root().atlas().imageRectf(self.root().solidWhitePixel()).middle()),
gl::Static);
}

Expand Down

0 comments on commit 936b566

Please sign in to comment.