Draw "OSM" as a view. ES 3.0: Tell tilers to discard depth/stencil of the backbuffer.

Also, don't even bind the UI texture unless there's UI to draw (probably negligible optimization).
This commit is contained in:
Henrik Rydgard
2014-12-31 20:43:28 +01:00
parent 4002cf6dac
commit 0cbff84489
4 changed files with 106 additions and 74 deletions
+33 -25
View File
@@ -5,12 +5,43 @@
#include "base/timeutil.h"
#include "gfx_es2/draw_buffer.h"
#include "ui/ui_context.h"
OnScreenMessages osm;
void OnScreenMessages::Draw(DrawBuffer &draw, const Bounds &bounds) {
void OnScreenMessagesView::Draw(UIContext &dc) {
// First, clean out old messages.
std::lock_guard<std::recursive_mutex> guard(mutex_);
osm.Lock();
osm.Clean();
// Get height
float w, h;
dc.Draw()->MeasureText(UBUNTU24, "Wg", &w, &h);
float y = 10.0f;
// Then draw them all.
const std::list<OnScreenMessages::Message> &messages = osm.Messages();
for (auto iter = messages.begin(); iter != messages.end(); ++iter) {
float alpha = (iter->endTime - time_now_d()) * 4.0f;
if (alpha > 1.0) alpha = 1.0f;
if (alpha < 0.0) alpha = 0.0f;
// Messages that are wider than the screen are left-aligned instead of centered.
float tw, th;
dc.Draw()->MeasureText(UBUNTU24, iter->text.c_str(), &tw, &th);
float x = bounds_.centerX();
int align = ALIGN_TOP | ALIGN_HCENTER;
if (tw > bounds_.w) {
align = ALIGN_TOP | ALIGN_LEFT;
x = 2;
}
dc.Draw()->DrawTextShadow(UBUNTU24, iter->text.c_str(), x, y, colorAlpha(iter->color, alpha), align);
y += h;
}
osm.Unlock();
}
void OnScreenMessages::Clean() {
restart:
double now = time_now_d();
for (auto iter = messages_.begin(); iter != messages_.end(); iter++) {
@@ -19,29 +50,6 @@ restart:
goto restart;
}
}
// Get height
float w, h;
draw.MeasureText(UBUNTU24, "Wg", &w, &h);
float y = 10.0f;
// Then draw them all.
for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) {
float alpha = (iter->endTime - time_now_d()) * 4.0f;
if (alpha > 1.0) alpha = 1.0f;
if (alpha < 0.0) alpha = 0.0f;
// Messages that are wider than the screen are left-aligned instead of centered.
float tw, th;
draw.MeasureText(UBUNTU24, iter->text.c_str(), &tw, &th);
float x = bounds.centerX();
int align = ALIGN_TOP | ALIGN_HCENTER;
if (tw > bounds.w) {
align = ALIGN_TOP | ALIGN_LEFT;
x = 2;
}
draw.DrawTextShadow(UBUNTU24, iter->text.c_str(), x, y, colorAlpha(iter->color, alpha), align);
y += h;
}
}
void OnScreenMessages::Show(const std::string &message, float duration_s, uint32_t color, int icon, bool checkUnique) {