set uniforms of msdf-combo
This commit is contained in:
parent
161b59ee17
commit
c1d6d052be
6 changed files with 63 additions and 35 deletions
|
@ -241,5 +241,18 @@ void LayerComposition::setVFlip(bool vFlip){
|
||||||
void LayerComposition::setLayerOrder(const vector <LayerID> & layerOrder){
|
void LayerComposition::setLayerOrder(const vector <LayerID> & layerOrder){
|
||||||
this->layerOrder = layerOrder;
|
this->layerOrder = layerOrder;
|
||||||
}
|
}
|
||||||
|
void LayerComposition::setMsdfUniform1fv(const vector <string> & names,
|
||||||
|
const vector <float> & values){
|
||||||
|
for(const auto & [identifier, layerCombo] : atlasLayerCombos){
|
||||||
|
if(identifier.type == LayerType::MSDFGEN){
|
||||||
|
auto combo = static_pointer_cast <MsdfAtlasLayerCombo>(layerCombo);
|
||||||
|
combo->getShader()->begin();
|
||||||
|
for(int i = 0; i < names.size(); i++){
|
||||||
|
combo->getShader()->setUniform1f(names[i], values[i]);
|
||||||
|
}
|
||||||
|
combo->getShader()->end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,9 @@ class LayerComposition {
|
||||||
shared_ptr <Layer> getLayer(const LayerID & layerID);
|
shared_ptr <Layer> getLayer(const LayerID & layerID);
|
||||||
const unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > & getAtlasLayerCombos() const;
|
const unordered_map <ComboIdentifier, shared_ptr <AtlasLayerCombo> > & getAtlasLayerCombos() const;
|
||||||
void setVFlip(bool vFlip);
|
void setVFlip(bool vFlip);
|
||||||
|
|
||||||
void setLayerOrder(const vector <LayerID> & layerOrder);
|
void setLayerOrder(const vector <LayerID> & layerOrder);
|
||||||
|
void setMsdfUniform1fv(const vector <string> & names,
|
||||||
|
const vector <float> & values);
|
||||||
private:
|
private:
|
||||||
VFlipState vFlipState = V_FLIP_UNKNOWN;
|
VFlipState vFlipState = V_FLIP_UNKNOWN;
|
||||||
unordered_map <LayerID, shared_ptr <Layer> > layers;
|
unordered_map <LayerID, shared_ptr <Layer> > layers;
|
||||||
|
|
|
@ -6,9 +6,12 @@
|
||||||
#include "of3dGraphics.h"
|
#include "of3dGraphics.h"
|
||||||
#include "ofFileUtils.h"
|
#include "ofFileUtils.h"
|
||||||
#include "ofGraphics.h"
|
#include "ofGraphics.h"
|
||||||
|
#include "ofUtils.h"
|
||||||
#include "ofxProfiler.h"
|
#include "ofxProfiler.h"
|
||||||
#include <GL/glext.h>
|
#ifdef TARGET_EMSCRIPTEN
|
||||||
#include <GLES3/gl3.h>
|
#include <GL/glext.h>
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
|
||||||
|
@ -154,8 +157,8 @@ void MsdfAtlasLayerCombo::draw(bool fade){
|
||||||
for(const auto & layer : layers){
|
for(const auto & layer : layers){
|
||||||
elements += layer->nElements;
|
elements += layer->nElements;
|
||||||
}
|
}
|
||||||
//vertices.resize(elements * 4);
|
vertices.reserve(elements * 4);
|
||||||
//indices.resize(elements * 6);
|
indices.reserve(elements * 6);
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
indices.clear();
|
indices.clear();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
@ -230,4 +233,7 @@ const ofImage & MsdfAtlasLayerCombo::getAtlasImage(){
|
||||||
string MsdfAtlasLayerCombo::getAtlasImagePath(){
|
string MsdfAtlasLayerCombo::getAtlasImagePath(){
|
||||||
return atlas->getAtlasPath();
|
return atlas->getAtlasPath();
|
||||||
}
|
}
|
||||||
|
shared_ptr <ofShader> MsdfAtlasLayerCombo::getShader(){
|
||||||
|
return msdfShader;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "AtlasLayerCombo.h"
|
#include "AtlasLayerCombo.h"
|
||||||
#include "MsdfLayer.h"
|
#include "MsdfLayer.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
using BufferVertex = MsdfLayer::BufferVertex;
|
using BufferVertex = MsdfLayer::BufferVertex;
|
||||||
|
@ -25,8 +26,8 @@ class MsdfAtlasLayerCombo : public AtlasLayerCombo {
|
||||||
void exit();
|
void exit();
|
||||||
const ofImage & getAtlasImage();
|
const ofImage & getAtlasImage();
|
||||||
string getAtlasImagePath();
|
string getAtlasImagePath();
|
||||||
shared_ptr <Layer> getLayer(); // TODO: is this used
|
|
||||||
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
shared_ptr <ofxMsdfgen::Atlas> atlas;
|
||||||
|
shared_ptr <ofShader> getShader();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MsdfAtlasLayerComboSettings settings;
|
MsdfAtlasLayerComboSettings settings;
|
||||||
|
|
|
@ -376,8 +376,8 @@ bool MsdfLayer::collectCharacter(const char character,
|
||||||
glm::vec4 p2 = glm::vec4(w, h, 0, 1);
|
glm::vec4 p2 = glm::vec4(w, h, 0, 1);
|
||||||
glm::vec4 p3 = glm::vec4(w, 0, 0, 1);
|
glm::vec4 p3 = glm::vec4(w, 0, 0, 1);
|
||||||
|
|
||||||
vertices.reserve(nodes.size() * 4);
|
//vertices.reserve(nodes.size() * 4);
|
||||||
indices.reserve(nodes.size() * 6);
|
//indices.reserve(nodes.size() * 6);
|
||||||
for(int i = 0; i < nodes.size(); i++){
|
for(int i = 0; i < nodes.size(); i++){
|
||||||
const glm::vec4 & color = colors[i];
|
const glm::vec4 & color = colors[i];
|
||||||
ofNode & node = nodes[i];
|
ofNode & node = nodes[i];
|
||||||
|
@ -387,37 +387,42 @@ bool MsdfLayer::collectCharacter(const char character,
|
||||||
//glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1);
|
//glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1);
|
||||||
glm::mat4 globalTransform = node.getGlobalTransformMatrix();
|
glm::mat4 globalTransform = node.getGlobalTransformMatrix();
|
||||||
|
|
||||||
|
//std::lock_guard <std::mutex> vm(vertices_mutex);
|
||||||
|
vertices_mutex.lock();
|
||||||
int32_t base = static_cast <int32_t>(vertices.size());
|
int32_t base = static_cast <int32_t>(vertices.size());
|
||||||
vertices.push_back(BufferVertex{
|
vertices.insert(vertices.end(), {
|
||||||
|
BufferVertex{
|
||||||
{p0.x, p0.y, p0.z, p0.w},
|
{p0.x, p0.y, p0.z, p0.w},
|
||||||
{uv0_a.x, uv0_a.y},
|
{uv0_a.x, uv0_a.y},
|
||||||
{uv0_b.x, uv0_b.y},
|
{uv0_b.x, uv0_b.y},
|
||||||
{color.r, color.g, color.b, color.a},
|
{color.r, color.g, color.b, color.a},
|
||||||
mix, globalTransform
|
mix, globalTransform
|
||||||
});
|
},
|
||||||
vertices.push_back(BufferVertex{
|
BufferVertex{
|
||||||
{p1.x, p1.y, p1.z, p1.w},
|
{p1.x, p1.y, p1.z, p1.w},
|
||||||
{uv1_a.x, uv1_a.y},
|
{uv1_a.x, uv1_a.y},
|
||||||
{uv1_b.x, uv1_b.y},
|
{uv1_b.x, uv1_b.y},
|
||||||
{color.r, color.g, color.b, color.a},
|
{color.r, color.g, color.b, color.a},
|
||||||
mix, globalTransform
|
mix, globalTransform
|
||||||
});
|
},
|
||||||
vertices.push_back(BufferVertex{
|
BufferVertex{
|
||||||
{p2.x, p2.y, p2.z, p2.w},
|
{p2.x, p2.y, p2.z, p2.w},
|
||||||
{uv2_a.x, uv2_a.y},
|
{uv2_a.x, uv2_a.y},
|
||||||
{uv2_b.x, uv2_b.y},
|
{uv2_b.x, uv2_b.y},
|
||||||
{color.r, color.g, color.b, color.a},
|
{color.r, color.g, color.b, color.a},
|
||||||
mix, globalTransform
|
mix, globalTransform
|
||||||
});
|
},
|
||||||
vertices.push_back(BufferVertex{
|
BufferVertex{
|
||||||
{p3.x, p3.y, p3.z, p3.w},
|
{p3.x, p3.y, p3.z, p3.w},
|
||||||
{uv3_a.x, uv3_a.y},
|
{uv3_a.x, uv3_a.y},
|
||||||
{uv3_b.x, uv3_b.y},
|
{uv3_b.x, uv3_b.y},
|
||||||
{color.r, color.g, color.b, color.a},
|
{color.r, color.g, color.b, color.a},
|
||||||
mix, globalTransform
|
mix, globalTransform
|
||||||
|
}
|
||||||
});
|
});
|
||||||
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
|
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
|
||||||
nElements++;
|
nElements++;
|
||||||
|
vertices_mutex.unlock();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,5 +101,7 @@ class MsdfLayer : public Layer {
|
||||||
ofNode outerNode;
|
ofNode outerNode;
|
||||||
ofNode innerNode;
|
ofNode innerNode;
|
||||||
Layer::BoundingBox boundingBox;
|
Layer::BoundingBox boundingBox;
|
||||||
|
std::mutex vertices_mutex;
|
||||||
|
std::mutex indices_mutex;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue