From 3016879e22e71531d958389504f1d85dfa484e77 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sat, 3 Jun 2023 14:51:55 +0200 Subject: [PATCH] pass GPUFont/MsdfAtlasLayerComboSettings as reference --- src/AtlasLayerCombo.h | 2 +- src/GPUFontAtlasLayerCombo.cpp | 4 ++-- src/GPUFontAtlasLayerCombo.h | 2 +- src/LayerComposition.cpp | 13 +++++++++++-- src/LayerComposition.h | 2 ++ src/MsdfAtlasLayerCombo.cpp | 4 ++-- src/MsdfAtlasLayerCombo.h | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/AtlasLayerCombo.h b/src/AtlasLayerCombo.h index bde1897..20bfc7b 100644 --- a/src/AtlasLayerCombo.h +++ b/src/AtlasLayerCombo.h @@ -25,7 +25,7 @@ struct AtlasLayerComboSettings { class AtlasLayerCombo { public: virtual void setup(const ComboIdentifier & identifier, - AtlasLayerComboSettings settings) = 0; + const AtlasLayerComboSettings & settings) = 0; virtual void update() = 0; virtual bool hasChildren() = 0; virtual void careForChild(shared_ptr layer) = 0; diff --git a/src/GPUFontAtlasLayerCombo.cpp b/src/GPUFontAtlasLayerCombo.cpp index b31fb8f..d63ee30 100644 --- a/src/GPUFontAtlasLayerCombo.cpp +++ b/src/GPUFontAtlasLayerCombo.cpp @@ -13,9 +13,9 @@ namespace ofxVariableLab { void GPUFontAtlasLayerCombo::setup(const ComboIdentifier & identifier, - AtlasLayerComboSettings settings){ + const AtlasLayerComboSettings & settings){ this->identifier = identifier; - this->settings = static_cast (settings); + this->settings = static_cast (settings); #ifdef TARGET_EMSCRIPTEN string shaderDir = "data/ofxGPUFont/shaders/ES3"; #else diff --git a/src/GPUFontAtlasLayerCombo.h b/src/GPUFontAtlasLayerCombo.h index a1b4449..cf0c1ca 100644 --- a/src/GPUFontAtlasLayerCombo.h +++ b/src/GPUFontAtlasLayerCombo.h @@ -69,7 +69,7 @@ class GPUFontAtlasLayerCombo : public AtlasLayerCombo { const Layer::Props & props); public: void setup(const ComboIdentifier & identifier, - AtlasLayerComboSettings settings = GPUFontAtlasLayerComboSettings()) override; + const AtlasLayerComboSettings & settings = GPUFontAtlasLayerComboSettings()) override; void update() override; void careForChild(shared_ptr layer) override; void abandonChild(shared_ptr layer) override; diff --git a/src/LayerComposition.cpp b/src/LayerComposition.cpp index 2b02e34..6cb6340 100644 --- a/src/LayerComposition.cpp +++ b/src/LayerComposition.cpp @@ -1,7 +1,9 @@ #include "LayerComposition.h" #include "Atlas.h" +#include "AtlasLayerCombo.h" #include "GPUFontAtlasLayerCombo.h" #include "GPUFontLayer.h" +#include "MsdfAtlasLayerCombo.h" #include "MsdfLayer.h" #include "Utils.h" #include "ofUtils.h" @@ -70,9 +72,11 @@ LayerID LayerComposition::addLayer(const Layer::Props & props, ComboIdentifier identifier; identifier.fontPath = props.fontPath; identifier.type = LayerType::GPUFONT; + GPUFontAtlasLayerComboSettings s; return addLayer(identifier, props, props.fontVariations, + s, layerID); } @@ -80,6 +84,7 @@ LayerID LayerComposition::addLayer(const Layer::Props & props, LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, const string & text, const std::vector & variations, + AtlasLayerComboSettings & s, LayerID layerID){ auto props = Layer::Props(); props.text = text; @@ -87,12 +92,14 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, return addLayer(identifier, props, variations, + s, layerID); } LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, const Layer::Props & props, const std::vector & variations, + AtlasLayerComboSettings & s, LayerID layerID){ switch(identifier.type){ case LayerType::GPUFONT: { @@ -102,7 +109,7 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, // we don't have one yet // so let's create it combo = make_shared (); - GPUFontAtlasLayerComboSettings settings; + GPUFontAtlasLayerComboSettings & settings = static_cast (s); combo->setup(identifier, settings); atlasLayerCombos[identifier] = combo; }else{ @@ -129,7 +136,9 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, case LayerType::MSDFGEN: { // TODO: put most stuff in combo setup auto combo = make_shared (); - combo->setup(identifier); // TODO: add here text and variations + MsdfAtlasLayerComboSettings settings = static_cast (s); + cout << "LayerComposition::addLayer scale " << settings.scale << endl; + combo->setup(identifier, settings); // TODO: add here text and variations auto layer = make_shared (); layer->vFlip = vFlipState; layer->setProps(props); diff --git a/src/LayerComposition.h b/src/LayerComposition.h index 247745f..6b74cfb 100644 --- a/src/LayerComposition.h +++ b/src/LayerComposition.h @@ -20,10 +20,12 @@ class LayerComposition { LayerID addLayer(const ComboIdentifier & identifier, const string & text, const std::vector & variations, + AtlasLayerComboSettings & s, LayerID layerID = ""); LayerID addLayer(const ComboIdentifier & identifier, const Layer::Props & props, const std::vector & variations, + AtlasLayerComboSettings & s, LayerID layerID = ""); void findOrCreateNewMomForLayer(shared_ptr layer, ComboIdentifier idealMom); diff --git a/src/MsdfAtlasLayerCombo.cpp b/src/MsdfAtlasLayerCombo.cpp index d78751c..3cfebd2 100644 --- a/src/MsdfAtlasLayerCombo.cpp +++ b/src/MsdfAtlasLayerCombo.cpp @@ -5,9 +5,9 @@ namespace ofxVariableLab { void MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier, - AtlasLayerComboSettings settings){ + const AtlasLayerComboSettings & settings){ this->identifier = layerIdentifier; - this->settings = static_cast (settings); + this->settings = static_cast (settings); ofxMsdfgen::AtlasSettings atlasSettings; //settings.characters = "ABCDEFGHIJKL"; atlasSettings.scale = this->settings.scale; diff --git a/src/MsdfAtlasLayerCombo.h b/src/MsdfAtlasLayerCombo.h index 5ee60a6..cf19eb0 100644 --- a/src/MsdfAtlasLayerCombo.h +++ b/src/MsdfAtlasLayerCombo.h @@ -13,7 +13,7 @@ struct MsdfAtlasLayerComboSettings : public AtlasLayerComboSettings { class MsdfAtlasLayerCombo : public AtlasLayerCombo { public: void setup(const ComboIdentifier & identifier, - AtlasLayerComboSettings settings = MsdfAtlasLayerComboSettings()) override; + const AtlasLayerComboSettings & settings = MsdfAtlasLayerComboSettings()) override; void update() override; void careForChild(shared_ptr layer) override; void abandonChild(shared_ptr layer) override;