add GPUFontLayer

This commit is contained in:
jrkb 2023-04-12 09:52:52 +02:00
parent 09e2bb63c7
commit b16046e5b8
2 changed files with 120 additions and 0 deletions

66
src/GPUFontLayer.cpp Normal file
View file

@ -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 <ofxGPUFont::Atlas> _atlas){
//atlas = _atlas;
//// TODO: this does not seem proper
//propsBuffer[0].fontSize_px = atlas->settings.scale;
//}
//shared_ptr <ofxGPUFont::Atlas> 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;
}
}

54
src/GPUFontLayer.h Normal file
View file

@ -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 <ofShader> _shader) override {
ofLogError("GPUFontLayer") << "using OpenGL shaders directly, no ofShader implemented";
}
shared_ptr <ofShader> 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 <ofxGPUFont::Atlas> _atlas);
//shared_ptr <ofxGPUFont::Atlas> getAtlas() const;
//shared_ptr <ofxGPUFont::Atlas> atlas;
LayerSettings settings;
std::deque <Props> 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;
};
}