diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index 1285df1..2a880e5 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -203,6 +203,7 @@ void GPUFontAtlasLayerCombo::draw(){ std::vector bbs; float advanceY = 0; font->collectBoundingBoxes(layer->getVariationText(), + layer->getVariationTextAppearance(), bb, bbs, advanceY, true, layer->getProps().fontSize_px); glm::vec4 transformOrigin; @@ -240,11 +241,10 @@ void GPUFontAtlasLayerCombo::draw(){ mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1, 0, 0); mirrorOuterNode.setScale(-1, 1, 1); font->collectVerticesAndIndices(mirrorInnerNode, + layer->getVariationTextAppearance(), bbs_mirror_x, vertices, - indices, - layer->getColor(), - layer->getProps().fontSize_px); + indices); } if(layer->getProps().mirror_y){ auto bbs_mirror_y = bbs; @@ -257,11 +257,10 @@ void GPUFontAtlasLayerCombo::draw(){ mirrorOuterNode.move(0, layer->getProps().mirror_y_distance * -1, 0); mirrorOuterNode.setScale(1, -1, 1); font->collectVerticesAndIndices(mirrorInnerNode, + layer->getVariationTextAppearance(), bbs_mirror_y, vertices, - indices, - layer->getColor(), - layer->getProps().fontSize_px); + indices); } if(layer->getProps().mirror_xy){ auto bbs_mirror_xy = bbs; @@ -275,22 +274,22 @@ void GPUFontAtlasLayerCombo::draw(){ layer->getProps().mirror_y_distance * -1, 0); mirrorOuterNode.setScale(-1, -1, 1); font->collectVerticesAndIndices(mirrorInnerNode, + layer->getVariationTextAppearance(), bbs_mirror_xy, vertices, - indices, - layer->getColor(), - layer->getProps().fontSize_px); + indices); } font->collectVerticesAndIndices(layer->getInnerNode(), + layer->getVariationTextAppearance(), bbs, vertices, - indices, - layer->getColor(), - layer->getProps().fontSize_px); - + indices); } - font->draw(vertices, indices); + { + OFX_PROFILER_SCOPE("font->draw()"); + font->draw(vertices, indices); + } glUseProgram(currentProgram); ofPushStyle(); diff --git a/src/GPUFontLayer.cpp b/src/GPUFontLayer.cpp index 79fd3bb..0c8e07e 100644 --- a/src/GPUFontLayer.cpp +++ b/src/GPUFontLayer.cpp @@ -66,18 +66,30 @@ void GPUFontLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){ void GPUFontLayer::setProps(const Props & props){ OFX_PROFILER_FUNCTION(); - if(propsBuffer.size() == 0 || props.text != propsBuffer[0].text + bool propsBufferEmpty = propsBuffer.size() == 0; + bool setAppearanceAlready = false; + if(propsBufferEmpty || props.text != propsBuffer[0].text || propsBuffer[0].fontVariations != props.fontVariations){ + setAppearanceAlready = true; OFX_PROFILER_SCOPE("variations"); setDirtyDirty(true); variationText.clear(); variationText.resize(props.text.size()); + variationTextAppearance.clear(); + variationTextAppearance.resize(props.text.size()); int i = 0; for(const char c : props.text){ OFX_PROFILER_SCOPE("char"); + const Props & vProps = propsBufferEmpty ? props : getProps(i * props.letterDelay); ofxGPUFont::GlyphIdentity glyphIdentity; + ofxGPUFont::GlyphAppearance glyphAppearance; glyphIdentity.charcode = ofxGPUFont::decodeCharcode(&c); - const Props & vProps = getProps(i * props.letterDelay); + glyphAppearance.charcode = glyphIdentity.charcode; + glyphAppearance.color.r = vProps.color[0]; + glyphAppearance.color.g = vProps.color[1]; + glyphAppearance.color.b = vProps.color[2]; + glyphAppearance.color.a = vProps.color[3]; + glyphAppearance.fontSize_px = vProps.fontSize_px; for(const auto & fv : vProps.fontVariations){ glyphIdentity.coords.push_back( std::move(ofxGPUFont::float2f16dot16(round(fv.value * 0.1) * 10)) // convert to FT @@ -86,11 +98,25 @@ void GPUFontLayer::setProps(const Props & props){ ); } variationText[i] = std::move(glyphIdentity); + variationTextAppearance[i] = std::move(glyphAppearance); i++; } - } - if(props.fontPath != propsBuffer[0].fontPath){ + if(!setAppearanceAlready + && !propsBufferEmpty + && (propsBuffer[0].fontSize_px != props.fontSize_px + || propsBuffer[0].color != props.color)){ + for(int i = 0; i < props.text.size(); i++){ + const Props & vProps = getProps(i * props.letterDelay); + ofxGPUFont::GlyphAppearance & glyphAppearance = variationTextAppearance[i]; + glyphAppearance.fontSize_px = vProps.fontSize_px; + variationTextAppearance[i].color.r = vProps.color[0]; + variationTextAppearance[i].color.g = vProps.color[1]; + variationTextAppearance[i].color.b = vProps.color[2]; + variationTextAppearance[i].color.a = vProps.color[3]; + } + } + if(!propsBufferEmpty && props.fontPath != propsBuffer[0].fontPath){ notHappyWithMom = true; } @@ -124,4 +150,7 @@ const LayerID & GPUFontLayer::getId(){ const vector & GPUFontLayer::getVariationText(){ return variationText; } +const vector & GPUFontLayer::getVariationTextAppearance(){ + return variationTextAppearance; +} } diff --git a/src/GPUFontLayer.h b/src/GPUFontLayer.h index 57dbf63..68bb122 100644 --- a/src/GPUFontLayer.h +++ b/src/GPUFontLayer.h @@ -48,22 +48,19 @@ class GPUFontLayer : public Layer { ofNode & getInnerNode() override; const vector & getVariationText(); - - //void setAtlas(shared_ptr _atlas); - //shared_ptr getAtlas() const; - - //shared_ptr atlas; + const vector & getVariationTextAppearance(); LayerSettings settings; - std::deque propsBuffer; /// \brief are props updated but not drawn yet bool isDirty = true; /// \brief hashed id, or just counting up string id = ""; VFlipState vFlip = V_FLIP_UNKNOWN; vector variationText; + vector variationTextAppearance; private: + std::deque propsBuffer; ComboIdentifier momsComboIdentifier; bool notHappyWithMom = false; LayerType type = GPUFONT; diff --git a/src/Layer.h b/src/Layer.h index 3927502..9a0b5d1 100644 --- a/src/Layer.h +++ b/src/Layer.h @@ -30,7 +30,7 @@ class Layer { float y = 200; float rotation = 0; float fontSize_px = 42; - float color[4]; + std::array color; bool mirror_x = false; float mirror_x_distance = 0; bool mirror_y = false;