profiler & misc cleanup

This commit is contained in:
jrkb 2023-06-18 17:34:34 +02:00
parent 6a61dc60f1
commit 619c07853f
3 changed files with 55 additions and 49 deletions

View file

@ -5,6 +5,7 @@
#include "of3dGraphics.h"
#include "ofFileUtils.h"
#include "ofGraphics.h"
#include "ofxProfiler.h"
#include <GL/glext.h>
#include <GLES3/gl3.h>
@ -139,6 +140,7 @@ bool MsdfAtlasLayerCombo::hasChildren(){
// unique
void MsdfAtlasLayerCombo::draw(){
OFX_PROFILER_FUNCTION()
int elements = 0;
for(const auto & layer : layers){
elements += layer->nElements;

View file

@ -5,6 +5,7 @@
#include "ofGraphics.h"
#include "ofGraphicsConstants.h"
#include "ofUtils.h"
#include "ofxProfiler.h"
namespace ofxVariableLab {
@ -318,6 +319,7 @@ void MsdfLayer::collectCharacter(const char character,
glm::vec4 color,
ofxVariableLab::FontVariation fontVariation){
OFX_PROFILER_FUNCTION()
const ofImage & atlasImage = atlas->getAtlasImage();
ofNode n = node;
n.setScale(n.getScale() * scaleFactor);
@ -349,15 +351,15 @@ void MsdfLayer::collectCharacter(const char character,
// FIXME: make sure this does not happen
ofLogError("MsdfLayer::draw") << "y smaller 0, this is not good" << endl;
}
double pl_a, pb_a, pr_a, pt_a;
double pl_b, pb_b, pr_b, pt_b;
gg_a.getQuadPlaneBounds(pl_a, pb_a, pr_a, pt_a);
gg_b.getQuadPlaneBounds(pl_b, pb_b, pr_b, pt_b);
//double pl_a, pb_a, pr_a, pt_a;
//double pl_b, pb_b, pr_b, pt_b;
//gg_a.getQuadPlaneBounds(pl_a, pb_a, pr_a, pt_a);
//gg_b.getQuadPlaneBounds(pl_b, pb_b, pr_b, pt_b);
float w = glm::mix(float(w_a), float(w_b), mix);
float h = glm::mix(float(h_a), float(h_b), mix);
float pl = glm::mix(float(pl_a), float(pl_b), mix);
float pt = glm::mix(float(pt_a), float(pt_b), mix);
//float pl = glm::mix(float(pl_a), float(pl_b), mix);
//float pt = glm::mix(float(pt_a), float(pt_b), mix);
//float magic = atlas->settings.scale;
//getVFlip(settings.vFlipBehaviour,
@ -369,15 +371,6 @@ void MsdfLayer::collectCharacter(const char character,
//n.move(pl * magic, -1 * pt * magic, 0);
//}
glm::vec2 translation_a = glm::vec2(float(x_a) / float(atlas_w),
float(y_a) / float(atlas_h));
glm::vec2 scale_a = glm::vec2(float(w_a) / float(atlas_w),
float(h_a) / float(atlas_h));
glm::vec2 translation_b = glm::vec2(float(x_b) / float(atlas_w),
float(y_b) / float(atlas_h));
glm::vec2 scale_b = glm::vec2(float(w_b) / float(atlas_w),
float(h_b) / float(atlas_h));
glm::vec4 p0 = n.getGlobalTransformMatrix() * glm::vec4(0, 0, 0, 1);
glm::vec4 p1 = n.getGlobalTransformMatrix() * glm::vec4(0, h, 0, 1);
glm::vec4 p2 = n.getGlobalTransformMatrix() * glm::vec4(w, h, 0, 1);
@ -387,6 +380,16 @@ void MsdfLayer::collectCharacter(const char character,
|| isInside(camera, p1)
|| isInside(camera, p2)
|| isInside(camera, p3)){
OFX_PROFILER_SCOPE("prepare vertices / indices");
glm::vec2 translation_a = glm::vec2(float(x_a) / float(atlas_w),
float(y_a) / float(atlas_h));
glm::vec2 scale_a = glm::vec2(float(w_a) / float(atlas_w),
float(h_a) / float(atlas_h));
glm::vec2 translation_b = glm::vec2(float(x_b) / float(atlas_w),
float(y_b) / float(atlas_h));
glm::vec2 scale_b = glm::vec2(float(w_b) / float(atlas_w),
float(h_b) / float(atlas_h));
glm::vec2 uv0_a = translation_a;
glm::vec2 uv0_b = translation_b;
@ -396,36 +399,39 @@ void MsdfLayer::collectCharacter(const char character,
glm::vec2 uv2_b = scale_b + translation_b;
glm::vec2 uv3_a = glm::vec2(scale_a.x, 0) + translation_a;
glm::vec2 uv3_b = glm::vec2(scale_b.x, 0) + translation_b;
int32_t base = static_cast <int32_t>(vertices.size());
vertices.push_back(BufferVertex{
{p0.x, p0.y, p0.z, p0.w},
{uv0_a.x, uv0_a.y},
{uv0_b.x, uv0_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p1.x, p1.y, p1.z, p1.w},
{uv1_a.x, uv1_a.y},
{uv1_b.x, uv1_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p2.x, p2.y, p2.z, p2.w},
{uv2_a.x, uv2_a.y},
{uv2_b.x, uv2_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p3.x, p3.y, p3.z, p3.w},
{uv3_a.x, uv3_a.y},
{uv3_b.x, uv3_b.y},
{color.r, color.g, color.b, color.a},
mix
});
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
for(int i = 0; i < 1; i++){
float distance = 200;
int32_t base = static_cast <int32_t>(vertices.size());
vertices.push_back(BufferVertex{
{p0.x, p0.y + i * distance, p0.z, p0.w},
{uv0_a.x, uv0_a.y},
{uv0_b.x, uv0_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p1.x, p1.y + i * distance, p1.z, p1.w},
{uv1_a.x, uv1_a.y},
{uv1_b.x, uv1_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p2.x, p2.y + i * distance, p2.z, p2.w},
{uv2_a.x, uv2_a.y},
{uv2_b.x, uv2_b.y},
{color.r, color.g, color.b, color.a},
mix
});
vertices.push_back(BufferVertex{
{p3.x, p3.y + i * distance, p3.z, p3.w},
{uv3_a.x, uv3_a.y},
{uv3_b.x, uv3_b.y},
{color.r, color.g, color.b, color.a},
mix
});
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
}
nElements++;
}
}

View file

@ -8,6 +8,7 @@
#include "json.hpp"
#include "ofAppRunner.h"
#include "of3dGraphics.h"
#include "ofxProfiler.h"
#include "ofCamera.h"
#include "ofUtils.h"
#include <ft2build.h>
@ -168,12 +169,9 @@ static bool isInside(float px, float py, float x, float y, float w, float h){
}
static bool isInside(const ofCamera & camera, const glm::vec4 & position){
OFX_PROFILER_FUNCTION()
const auto & viewport = ofGetCurrentRenderer()->getCurrentViewport();
glm::vec3 screenPosition = camera.worldToScreen(position);
glm::vec3 cameraPosition = camera.worldToCamera(position);
//glm::mat4 clipSpaceToWorld = camera.getGlobalTransformMatrix() * glm::inverse(camera.getProjectionMatrix(viewport));
//glm::mat4 worldToClipSpace = camera.getProjectionMatrix(viewport);
//glm::vec4 worldSpacePosition = position * worldToClipSpace;
if(screenPosition.x >= 0.0f && screenPosition.x <= ofGetWidth()
&& screenPosition.y >= 0.0f && screenPosition.y <= ofGetHeight()
&& screenPosition.z <= 1.0f){