From ae10d5814211f2f62cdefbd35bee8a76e11fec47 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 16 Jul 2015 16:42:29 -0700 Subject: [PATCH] Fixing font class --- libraries/render-utils/src/text/Font.cpp | 52 ++---------------------- libraries/render-utils/src/text/Font.h | 8 ---- 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index 8e83c55fec..6aae7ae81a 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -7,8 +7,6 @@ #include "sdf_text3D_vert.h" #include "sdf_text3D_frag.h" -#include "sdf_text_vert.h" -#include "sdf_text_frag.h" #include "../RenderUtilsLogging.h" #include "FontFamilies.h" @@ -53,10 +51,10 @@ Font* Font::load(QIODevice& fontFile) { Font* Font::load(const QString& family) { if (!LOADED_FONTS.contains(family)) { - const QString SDFF_COURIER_PRIME_FILENAME = ":/CourierPrime.sdff"; - const QString SDFF_INCONSOLATA_MEDIUM_FILENAME = ":/InconsolataMedium.sdff"; - const QString SDFF_ROBOTO_FILENAME = ":/Roboto.sdff"; - const QString SDFF_TIMELESS_FILENAME = ":/Timeless.sdff"; + static const QString SDFF_COURIER_PRIME_FILENAME{ ":/CourierPrime.sdff" }; + static const QString SDFF_INCONSOLATA_MEDIUM_FILENAME{ ":/InconsolataMedium.sdff" }; + static const QString SDFF_ROBOTO_FILENAME{ ":/Roboto.sdff" }; + static const QString SDFF_TIMELESS_FILENAME{ ":/Timeless.sdff" }; QString loadFilename; @@ -234,27 +232,6 @@ void Font::setupGPU() { _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); } - { - auto vertexShader = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(sdf_text_vert))); - auto pixelShader = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(sdf_text_frag))); - gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader)); - - gpu::Shader::BindingSet slotBindings; - gpu::Shader::makeProgram(*program, slotBindings); - - _fontLoc2D = program->getTextures().findLocation("Font"); - _outlineLoc2D = program->getUniforms().findLocation("Outline"); - _colorLoc2D = program->getUniforms().findLocation("Color"); - - gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setCullMode(gpu::State::CULL_BACK); - state->setDepthTest(false); - state->setBlendFunction(false, - 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); - _pipeline2D = gpu::PipelinePointer(gpu::Pipeline::create(program, state)); - } - // Sanity checks static const int OFFSET = offsetof(TextureVertex, tex); assert(OFFSET == sizeof(glm::vec2)); @@ -343,24 +320,3 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); batch.draw(gpu::QUADS, _numVertices, 0); } - -void Font::drawString2D(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color, - EffectType effectType, const glm::vec2& bounds) { - if (str == "") { - return; - } - - if (str != _lastStringRendered || bounds != _lastBounds) { - rebuildVertices(x, y, str, bounds); - } - - setupGPU(); - - batch.setPipeline(_pipeline2D); - batch.setResourceTexture(_fontLoc2D, _texture); - batch._glUniform1i(_outlineLoc2D, (effectType == OUTLINE_EFFECT)); - batch._glUniform4fv(_colorLoc2D, 1, (const GLfloat*)color); - batch.setInputFormat(_format); - batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); - batch.draw(gpu::QUADS, _numVertices, 0); -} diff --git a/libraries/render-utils/src/text/Font.h b/libraries/render-utils/src/text/Font.h index 98d0a31cf4..55801419f9 100644 --- a/libraries/render-utils/src/text/Font.h +++ b/libraries/render-utils/src/text/Font.h @@ -29,10 +29,6 @@ public: const glm::vec4* color, EffectType effectType, const glm::vec2& bound); - void drawString2D(gpu::Batch& batch, float x, float y, const QString& str, - const glm::vec4* color, EffectType effectType, - const glm::vec2& bound); - static Font* load(QIODevice& fontFile); static Font* load(const QString& family); @@ -65,7 +61,6 @@ private: // gpu structures gpu::PipelinePointer _pipeline; - gpu::PipelinePointer _pipeline2D; gpu::TexturePointer _texture; gpu::Stream::FormatPointer _format; gpu::BufferPointer _verticesBuffer; @@ -75,9 +70,6 @@ private: int _fontLoc = -1; int _outlineLoc = -1; int _colorLoc = -1; - int _fontLoc2D = -1; - int _outlineLoc2D = -1; - int _colorLoc2D = -1; // last string render characteristics QString _lastStringRendered;