introduce naive layerID
This commit is contained in:
parent
ad95ad0fe9
commit
f118627dbc
6 changed files with 82 additions and 36 deletions
|
@ -1,3 +1,6 @@
|
|||
#include "Layer.h"
|
||||
|
||||
// Layer is virtual
|
||||
namespace ofxVariableLab {
|
||||
int Layer::n_layers = 0;
|
||||
}
|
||||
|
|
25
src/Layer.h
25
src/Layer.h
|
@ -11,6 +11,14 @@
|
|||
#include <memory>
|
||||
|
||||
namespace ofxVariableLab {
|
||||
|
||||
using LayerID = string;
|
||||
|
||||
struct LayerSettings {
|
||||
uint32_t maxBufferSize = 100;
|
||||
VFlipBehaviour vFlipBehaviour = V_FLIP_ONCE_AUTO;
|
||||
};
|
||||
|
||||
class Layer {
|
||||
public:
|
||||
enum Type {
|
||||
|
@ -29,26 +37,25 @@ class Layer {
|
|||
float mirror_y_distance = 0;
|
||||
float letterDelay = 0;
|
||||
string text = "abcdefghijklmnoprstuvqxyzABUIWERJSD";
|
||||
};
|
||||
struct Settings {
|
||||
uint32_t maxBufferSize = 100;
|
||||
VFlipBehaviour vFlipBehaviour = V_FLIP_ONCE_AUTO;
|
||||
string fontPath;
|
||||
};
|
||||
|
||||
virtual void setup(const Settings & settings) = 0;
|
||||
virtual void setup(const LayerSettings & settings = LayerSettings()) = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void draw(glm::vec3 position = glm::vec3(0, 0, 0)) = 0;
|
||||
virtual void drawCharacter(const char character,
|
||||
glm::vec3 position = glm::vec3(0, 0, 0),
|
||||
ofxMsdfgen::FontVariation fontVariation = ofxMsdfgen::FontVariation()) = 0;
|
||||
glm::vec4 color = glm::vec4(1, 1, 1, 1),
|
||||
float rotation = 0,
|
||||
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) = 0;
|
||||
virtual void setProps(const Props & props) = 0;
|
||||
virtual const Props & getProps() const = 0;
|
||||
virtual void clearPropsBuffer() = 0;
|
||||
virtual void setId(const string & id) = 0;
|
||||
virtual const string & getId() = 0;
|
||||
virtual void setId(const LayerID & id) = 0;
|
||||
virtual const LayerID & getId() = 0;
|
||||
virtual void setShader(shared_ptr <ofShader> _shader) = 0;
|
||||
virtual shared_ptr <ofShader> getShader() const = 0;
|
||||
virtual const Type & getType() const = 0;
|
||||
static int n_layers;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ void MsdfAtlasLayerCombo::careForChild(shared_ptr <Layer> layer){
|
|||
isDirty = true;
|
||||
}
|
||||
}
|
||||
layers.push_back(msdfLayer);
|
||||
}
|
||||
|
||||
const ComboIdentifier & MsdfAtlasLayerCombo::getIdentifier() const {
|
||||
|
@ -73,9 +74,10 @@ void LayerComposition::update(){
|
|||
}
|
||||
}
|
||||
|
||||
void LayerComposition::addLayer(const ComboIdentifier & identifier,
|
||||
LayerID LayerComposition::addLayer(const ComboIdentifier & identifier,
|
||||
const string & text,
|
||||
const std::vector <FontVariation> & variations){
|
||||
string layerID = "";
|
||||
if(atlasLayerCombos.count(identifier) <= 0){
|
||||
switch(identifier.type){
|
||||
case Layer::GPUFONT: {
|
||||
|
@ -92,8 +94,11 @@ void LayerComposition::addLayer(const ComboIdentifier & identifier,
|
|||
auto layer = make_shared <MsdfLayer>();
|
||||
auto props = Layer::Props();
|
||||
props.text = text;
|
||||
props.fontPath = identifier.fontPath;
|
||||
layer->setProps(props);
|
||||
layer->setup();
|
||||
std::vector <ofxMsdfgen::FontVariation> msdfVariations;
|
||||
cout << "yeah yeah" << layerID << endl;
|
||||
for(const auto & v : variations){
|
||||
msdfVariations.push_back({v.name, v.value});
|
||||
}
|
||||
|
@ -101,17 +106,26 @@ void LayerComposition::addLayer(const ComboIdentifier & identifier,
|
|||
// so we know it's dirty
|
||||
combo->atlas->addVariations(msdfVariations);
|
||||
combo->careForChild(layer);
|
||||
layers.push_back(layer);
|
||||
layers[layer->getId()] = layer;
|
||||
atlasLayerCombos[identifier] = std::move(combo);
|
||||
break;
|
||||
layerID = layer->getId();
|
||||
cout << "yeah yeah and the id is then:" << layerID << endl;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
cout << "whaaat we didnt find anyone like this" << layerID << endl;
|
||||
}
|
||||
cout << "LayerComposition::addLayer returns " << layerID << endl;
|
||||
return layerID;
|
||||
}
|
||||
|
||||
shared_ptr <Layer> LayerComposition::getLayer(const LayerID & layerID){
|
||||
return layers[layerID];
|
||||
}
|
||||
|
||||
void LayerComposition::draw() const {
|
||||
for(const auto & layer_it : layers){
|
||||
layer_it->draw(glm::vec3(0, 0, 0));
|
||||
layer_it.second->draw(glm::vec3(0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,9 +70,11 @@ class MsdfAtlasLayerCombo : public AtlasLayerCombo {
|
|||
void update() override;
|
||||
void careForChild(shared_ptr <Layer> layer) override;
|
||||
const ComboIdentifier & getIdentifier() const override;
|
||||
shared_ptr <Layer> getLayer();
|
||||
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
||||
|
||||
private:
|
||||
vector <shared_ptr <MsdfLayer> > layers;
|
||||
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
||||
shared_ptr <ofShader> msdfShader;
|
||||
ComboIdentifier identifier;
|
||||
|
@ -84,13 +86,14 @@ class LayerComposition {
|
|||
void setup();
|
||||
void update();
|
||||
void draw() const;
|
||||
void addLayer(const ComboIdentifier & identifier,
|
||||
LayerID addLayer(const ComboIdentifier & identifier,
|
||||
const string & text,
|
||||
const std::vector <FontVariation> & variations);
|
||||
shared_ptr <ofxVariableLab::Layer> getLayer(const LayerID & layerID);
|
||||
|
||||
private:
|
||||
|
||||
vector <shared_ptr <ofxVariableLab::Layer> > layers;
|
||||
unordered_map <LayerID, shared_ptr <ofxVariableLab::Layer> > layers;
|
||||
unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > atlasLayerCombos;
|
||||
//unordered_map <LayerIdentifier, shared_ptr <ofxVariableLab::Layer> > layers;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "MsdfLayer.h"
|
||||
#include "Atlas.h"
|
||||
#include "Utils.h"
|
||||
#include "fwd.hpp"
|
||||
#include "ofGraphics.h"
|
||||
|
@ -6,8 +7,12 @@
|
|||
|
||||
namespace ofxVariableLab {
|
||||
|
||||
void MsdfLayer::setup(const Settings & settings){
|
||||
void MsdfLayer::setup(const LayerSettings & settings){
|
||||
this->settings = settings;
|
||||
if(id == ""){
|
||||
id = ofToString(Layer::n_layers);
|
||||
n_layers++;
|
||||
}
|
||||
}
|
||||
|
||||
void MsdfLayer::update(){
|
||||
|
@ -157,7 +162,9 @@ void MsdfLayer::draw(glm::vec3 position){
|
|||
}
|
||||
void MsdfLayer::drawCharacter(const char character,
|
||||
glm::vec3 position,
|
||||
ofxMsdfgen::FontVariation fontVariation){
|
||||
glm::vec4 color,
|
||||
float rotation,
|
||||
ofxVariableLab::FontVariation fontVariation){
|
||||
const ofImage & atlasImage = atlas->getAtlasImage();
|
||||
ofDisableAlphaBlending();
|
||||
ofEnableDepthTest();
|
||||
|
@ -168,21 +175,24 @@ void MsdfLayer::drawCharacter(const char character,
|
|||
|
||||
shader->begin();
|
||||
shader->setUniformTexture("msdf", atlasImage.getTexture(), 0);
|
||||
shader->setUniform4f("fontColor", ofFloatColor::white);
|
||||
shader->setUniform2f("unitRange", unitRange);
|
||||
shader->end();
|
||||
|
||||
ofPushMatrix();
|
||||
ofTranslate(position);
|
||||
ofPushStyle();
|
||||
ofSetColor(ofColor::pink);
|
||||
|
||||
float mix = -1;
|
||||
ofxMsdfgen::GlyphGeometry gg_a;
|
||||
ofxMsdfgen::GlyphGeometry gg_b;
|
||||
|
||||
ofxMsdfgen::FontVariation fv{
|
||||
fontVariation.name,
|
||||
fontVariation.value
|
||||
};
|
||||
|
||||
bool success = atlas->getGlyphGeometryPair(character,
|
||||
fontVariation,
|
||||
fv,
|
||||
gg_a,
|
||||
gg_b,
|
||||
mix);
|
||||
|
@ -215,8 +225,14 @@ void MsdfLayer::drawCharacter(const char character,
|
|||
ofPushMatrix();
|
||||
float magic = atlas->settings.scale;
|
||||
ofSetColor(ofFloatColor(1, 1, 1, 1));
|
||||
ofTranslate(pl * magic, 0, 0);
|
||||
ofTranslate(0, -1 * pt * magic, 0);
|
||||
getVFlip(settings.vFlipBehaviour,
|
||||
ofGetCurrentOrientationMatrix(),
|
||||
vFlip);
|
||||
if(vFlip == V_FLIP_OFF){
|
||||
ofTranslate(pl * magic, (pt * magic) + (-1 * h), 0);
|
||||
}else{
|
||||
ofTranslate(pl * magic, -1 * pt * magic, 0);
|
||||
}
|
||||
|
||||
glm::vec2 translation_a = glm::vec2(float(x_a) / float(atlas_w),
|
||||
float(y_a) / float(atlas_h));
|
||||
|
@ -227,12 +243,13 @@ void MsdfLayer::drawCharacter(const char character,
|
|||
glm::vec2 scale_b = glm::vec2(float(w_b) / float(atlas_w),
|
||||
float(h_b) / float(atlas_h));
|
||||
shader->begin();
|
||||
shader->setUniform4f("fontColor", ofFloatColor::yellow);
|
||||
shader->setUniform4f("fontColor", color);
|
||||
shader->setUniform2f("translation_a", translation_a);
|
||||
shader->setUniform2f("scale_a", scale_a);
|
||||
shader->setUniform2f("translation_b", translation_b);
|
||||
shader->setUniform2f("scale_b", scale_b);
|
||||
shader->setUniform1f("msdf_mix", mix);
|
||||
//ofRotateDeg(rotation, 0, 0, 1);
|
||||
atlasImage.draw(0, 0, w, h);
|
||||
shader->end();
|
||||
ofPopMatrix();
|
||||
|
@ -274,10 +291,10 @@ const Layer::Props & MsdfLayer::getProps() const {
|
|||
void MsdfLayer::clearPropsBuffer(){
|
||||
propsBuffer.clear();
|
||||
}
|
||||
void MsdfLayer::setId(const string & id){
|
||||
void MsdfLayer::setId(const LayerID & id){
|
||||
this->id = id;
|
||||
}
|
||||
const string & MsdfLayer::getId(){
|
||||
const LayerID & MsdfLayer::getId(){
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,19 @@ namespace ofxVariableLab {
|
|||
|
||||
class MsdfLayer : public Layer {
|
||||
public:
|
||||
void setup(const Settings & settings);
|
||||
void setup(const LayerSettings & settings = LayerSettings()) override;
|
||||
void update() override;
|
||||
void draw(glm::vec3 position = glm::vec3(0, 0, 0)) override;
|
||||
void drawCharacter(const char character,
|
||||
glm::vec3 position = glm::vec3(0, 0, 0),
|
||||
ofxMsdfgen::FontVariation fontVariation = ofxMsdfgen::FontVariation()) override;
|
||||
glm::vec4 color = glm::vec4(1, 1, 1, 1),
|
||||
float rotation = 0,
|
||||
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override;
|
||||
void setProps(const Props & props) override;
|
||||
const Props & getProps() const override;
|
||||
void clearPropsBuffer() override;
|
||||
void setId(const string & id) override;
|
||||
const string & getId() override;
|
||||
void setId(const LayerID & id) override;
|
||||
const LayerID & getId() override;
|
||||
void setShader(shared_ptr <ofShader> _shader) override;
|
||||
shared_ptr <ofShader> getShader() const override;
|
||||
const Type & getType() const override;
|
||||
|
@ -30,13 +32,13 @@ class MsdfLayer : public Layer {
|
|||
|
||||
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
||||
|
||||
Settings settings;
|
||||
LayerSettings settings;
|
||||
std::deque <Props> propsBuffer;
|
||||
shared_ptr <ofShader> shader;
|
||||
/// \brief are props updated but not drawn yet
|
||||
bool isDirty = true;
|
||||
/// \brief hashed id
|
||||
string id;
|
||||
/// \brief hashed id, or just counting up
|
||||
string id = "";
|
||||
VFlipState vFlip = V_FLIP_UNKNOWN;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue