diff --git a/src/GPUFontLayer.cpp b/src/GPUFontLayer.cpp new file mode 100644 index 0000000..5afc846 --- /dev/null +++ b/src/GPUFontLayer.cpp @@ -0,0 +1,66 @@ +#include "GPUFontLayer.h" +#include "Atlas.h" +#include "Utils.h" +#include "fwd.hpp" +#include "ofGraphics.h" +#include "ofUtils.h" + +namespace ofxVariableLab { + +void GPUFontLayer::setup(const LayerSettings & settings){ + this->settings = settings; + if(id == ""){ + id = ofToString(Layer::n_layers); + n_layers++; + } +} + +void GPUFontLayer::update(){ + if(isDirty){ + isDirty = false; + } +} + +void GPUFontLayer::draw(glm::vec3 position){ +} +void GPUFontLayer::drawCharacter(const char character, + glm::vec3 position, + glm::vec4 color, + float rotation, + float scale, + ofxVariableLab::FontVariation fontVariation){ +} +const Layer::Type & GPUFontLayer::getType() const { + return type; +} +void GPUFontLayer::setVFlip(const VFlipState vFlip){ + this->vFlip = vFlip; +} + +//void GPUFontLayer::setAtlas(shared_ptr _atlas){ +//atlas = _atlas; +//// TODO: this does not seem proper +//propsBuffer[0].fontSize_px = atlas->settings.scale; +//} +//shared_ptr GPUFontLayer::getAtlas() const { +//return atlas; +//} +void GPUFontLayer::setProps(const Props & props){ + while(propsBuffer.size() > max(0, int(settings.maxBufferSize - 1))){ + propsBuffer.pop_back(); + } + propsBuffer.push_front(props); +} +const Layer::Props & GPUFontLayer::getProps() const { + return propsBuffer[0]; +} +void GPUFontLayer::clearPropsBuffer(){ + propsBuffer.clear(); +} +void GPUFontLayer::setId(const LayerID & id){ + this->id = id; +} +const LayerID & GPUFontLayer::getId(){ + return id; +} +} diff --git a/src/GPUFontLayer.h b/src/GPUFontLayer.h new file mode 100644 index 0000000..a4cb792 --- /dev/null +++ b/src/GPUFontLayer.h @@ -0,0 +1,54 @@ +#pragma once + +#include "ofMain.h" +#include "ofxGPUFont.h" +#include "Atlas.h" +#include "Layer.h" +#include "Utils.h" + +namespace ofxVariableLab { + +class GPUFontLayer : public Layer { + public: + 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), + glm::vec4 color = glm::vec4(1, 1, 1, 1), + float rotation = 0, + float scale = 1, + ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation()) override; + void setProps(const Props & props) override; + const Props & getProps() const override; + void clearPropsBuffer() override; + void setId(const LayerID & id) override; + const LayerID & getId() override; + void setShader(shared_ptr _shader) override { + ofLogError("GPUFontLayer") << "using OpenGL shaders directly, no ofShader implemented"; + } + shared_ptr getShader() const override { + ofLogError("GPUFontLayer") << "using OpenGL shaders directly, no ofShader implemented"; + return NULL; // evil? + } + + const Type & getType() const override; + void setVFlip(const VFlipState vFlip) override; + + //void setAtlas(shared_ptr _atlas); + //shared_ptr getAtlas() const; + + //shared_ptr atlas; + + 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; + + private: + Layer::Type type = GPUFONT; +}; +}