Add layering to text renderer

This commit is contained in:
Zach Pomerantz 2016-02-01 19:48:55 -08:00
parent 127f9694f6
commit 9af7dc9c3e
4 changed files with 11 additions and 6 deletions

View file

@ -72,12 +72,12 @@ float TextRenderer3D::getFontSize() const {
}
void TextRenderer3D::draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color,
const glm::vec2& bounds) {
const glm::vec2& bounds, bool layered) {
// The font does all the OpenGL work
if (_font) {
// Cache color so that the pointer stays valid.
_color = color;
_font->drawString(batch, x, y, str, &_color, _effectType, bounds);
_font->drawString(batch, x, y, str, &_color, _effectType, bounds, layered);
}
}

View file

@ -40,7 +40,7 @@ public:
float getFontSize() const; // Pixel size
void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(1.0f),
const glm::vec2& bounds = glm::vec2(-1.0f));
const glm::vec2& bounds = glm::vec2(-1.0f), bool layered = false);
private:
TextRenderer3D(const char* family, float pointSize, int weight = -1, bool italic = false,

View file

@ -234,6 +234,10 @@ void Font::setupGPU() {
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_pipeline = gpu::Pipeline::create(program, state);
auto layeredState = std::make_shared<gpu::State>(state->getValues());
layeredState->setDepthTest(false);
_layeredPipeline = gpu::Pipeline::create(program, layeredState);
}
// Sanity checks
@ -336,7 +340,7 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2
}
void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color,
EffectType effectType, const glm::vec2& bounds) {
EffectType effectType, const glm::vec2& bounds, bool layered) {
if (str == "") {
return;
}
@ -347,7 +351,7 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c
setupGPU();
batch.setPipeline(_pipeline);
batch.setPipeline(layered ? _layeredPipeline : _pipeline);
batch.setResourceTexture(_fontLoc, _texture);
batch._glUniform1i(_outlineLoc, (effectType == OUTLINE_EFFECT));
batch._glUniform4fv(_colorLoc, 1, (const float*)color);

View file

@ -27,7 +27,7 @@ public:
// Render string to batch
void drawString(gpu::Batch& batch, float x, float y, const QString& str,
const glm::vec4* color, EffectType effectType,
const glm::vec2& bound);
const glm::vec2& bound, bool layered = false);
static Font* load(QIODevice& fontFile);
static Font* load(const QString& family);
@ -61,6 +61,7 @@ private:
// gpu structures
gpu::PipelinePointer _pipeline;
gpu::PipelinePointer _layeredPipeline;
gpu::TexturePointer _texture;
gpu::Stream::FormatPointer _format;
gpu::BufferPointer _verticesBuffer;