Skip to content

Commit 731d1f8

Browse files
committed
small changes to and extract HatchGlyph builder to declutter
1 parent c61f661 commit 731d1f8

File tree

1 file changed

+3
-143
lines changed

1 file changed

+3
-143
lines changed

62_CAD/main.cpp

Lines changed: 3 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ using namespace video;
2727
#include "nbl/video/surface/CSurfaceVulkan.h"
2828
#include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h"
2929

30+
#include "HatchGlyphBuilder.h"
31+
3032
#include <chrono>
3133
#define BENCHMARK_TILL_FIRST_FRAME
3234

3335
// Shader cache tests. Only define one of these, or none for no use of the Cache
3436
//#define SHADER_CACHE_TEST_COMPILATION_CACHE_STORE
3537
//#define SHADER_CACHE_TEST_CACHE_RETRIEVE
3638

37-
static constexpr bool DebugModeWireframe = false;
39+
static constexpr bool DebugModeWireframe = true;
3840
static constexpr bool DebugRotatingViewProj = false;
3941
static constexpr bool FragmentShaderPixelInterlock = false;
4042

@@ -1337,148 +1339,6 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
13371339
}
13381340
}
13391341

1340-
class FreetypeHatchBuilder
1341-
{
1342-
public:
1343-
// Start a new line from here
1344-
void moveTo(const float64_t2 to)
1345-
{
1346-
lastPosition = to;
1347-
}
1348-
1349-
// Continue the last line started with moveTo (could also use the last
1350-
// position from a lineTo)
1351-
void lineTo(const float64_t2 to)
1352-
{
1353-
if (to != lastPosition) {
1354-
std::vector<float64_t2> linePoints;
1355-
linePoints.push_back(lastPosition);
1356-
linePoints.push_back(to);
1357-
currentPolyline.addLinePoints(linePoints);
1358-
1359-
lastPosition = to;
1360-
}
1361-
}
1362-
1363-
// Continue the last moveTo or lineTo with a quadratic bezier:
1364-
// [last position, control, end]
1365-
void quadratic(const float64_t2 control, const float64_t2 to)
1366-
{
1367-
shapes::QuadraticBezier<double> bezier = shapes::QuadraticBezier<double>::construct(
1368-
lastPosition,
1369-
control,
1370-
to
1371-
);
1372-
currentPolyline.addQuadBeziers({ &bezier, 1 });
1373-
lastPosition = to;
1374-
}
1375-
1376-
// Continue the last moveTo or lineTo with a cubic bezier:
1377-
// [last position, control1, control2, end]
1378-
void cubic(const float64_t2 control1, const float64_t2 control2, const float64_t2 to)
1379-
{
1380-
std::vector<shapes::QuadraticBezier<double>> quadBeziers;
1381-
curves::CubicCurve myCurve(
1382-
float64_t4(lastPosition.x, lastPosition.y, control1.x, control1.y),
1383-
float64_t4(control2.x, control2.y, to.x, to.y)
1384-
);
1385-
1386-
curves::Subdivision::AddBezierFunc addToBezier = [&](shapes::QuadraticBezier<double>&& info) -> void
1387-
{
1388-
quadBeziers.push_back(info);
1389-
};
1390-
1391-
curves::Subdivision::adaptive(myCurve, 0.0, 1.0, 1e-5, addToBezier, 10u);
1392-
currentPolyline.addQuadBeziers(quadBeziers);
1393-
1394-
lastPosition = to;
1395-
}
1396-
1397-
void finish()
1398-
{
1399-
if (currentPolyline.getSectionsCount() > 0)
1400-
polylines.push_back(currentPolyline);
1401-
}
1402-
1403-
std::vector<CPolyline> polylines;
1404-
CPolyline currentPolyline = {};
1405-
// Set with move to and line to
1406-
float64_t2 lastPosition = float64_t2(0.0);
1407-
};
1408-
1409-
// TODO: Figure out what this is supposed to do
1410-
static double f26dot6ToDouble(float x)
1411-
{
1412-
return (1 / 64. * double(x));
1413-
}
1414-
1415-
static float64_t2 ftPoint2(const FT_Vector& vector) {
1416-
return float64_t2(f26dot6ToDouble(vector.x), f26dot6ToDouble(vector.y));
1417-
}
1418-
1419-
static int ftMoveTo(const FT_Vector* to, void* user) {
1420-
FreetypeHatchBuilder* context = reinterpret_cast<FreetypeHatchBuilder*>(user);
1421-
context->moveTo(ftPoint2(*to));
1422-
return 0;
1423-
}
1424-
static int ftLineTo(const FT_Vector* to, void* user) {
1425-
FreetypeHatchBuilder* context = reinterpret_cast<FreetypeHatchBuilder*>(user);
1426-
context->lineTo(ftPoint2(*to));
1427-
return 0;
1428-
}
1429-
1430-
static int ftConicTo(const FT_Vector* control, const FT_Vector* to, void* user) {
1431-
FreetypeHatchBuilder* context = reinterpret_cast<FreetypeHatchBuilder*>(user);
1432-
context->quadratic(ftPoint2(*control), ftPoint2(*to));
1433-
return 0;
1434-
}
1435-
1436-
static int ftCubicTo(const FT_Vector* control1, const FT_Vector* control2, const FT_Vector* to, void* user) {
1437-
FreetypeHatchBuilder* context = reinterpret_cast<FreetypeHatchBuilder*>(user);
1438-
context->cubic(ftPoint2(*control1), ftPoint2(*control2), ftPoint2(*to));
1439-
return 0;
1440-
}
1441-
1442-
static int ftMoveToMSDF(const FT_Vector* to, void* user) {
1443-
nbl::ext::TextRendering::GlyphShapeBuilder* context = reinterpret_cast<nbl::ext::TextRendering::GlyphShapeBuilder*>(user);
1444-
context->moveTo(ftPoint2(*to));
1445-
return 0;
1446-
}
1447-
static int ftLineToMSDF(const FT_Vector* to, void* user) {
1448-
nbl::ext::TextRendering::GlyphShapeBuilder* context = reinterpret_cast<nbl::ext::TextRendering::GlyphShapeBuilder*>(user);
1449-
context->lineTo(ftPoint2(*to));
1450-
return 0;
1451-
}
1452-
1453-
static int ftConicToMSDF(const FT_Vector* control, const FT_Vector* to, void* user) {
1454-
nbl::ext::TextRendering::GlyphShapeBuilder* context = reinterpret_cast<nbl::ext::TextRendering::GlyphShapeBuilder*>(user);
1455-
context->quadratic(ftPoint2(*control), ftPoint2(*to));
1456-
return 0;
1457-
}
1458-
1459-
static int ftCubicToMSDF(const FT_Vector* control1, const FT_Vector* control2, const FT_Vector* to, void* user) {
1460-
nbl::ext::TextRendering::GlyphShapeBuilder* context = reinterpret_cast<nbl::ext::TextRendering::GlyphShapeBuilder*>(user);
1461-
context->cubic(ftPoint2(*control1), ftPoint2(*control2), ftPoint2(*to));
1462-
return 0;
1463-
}
1464-
1465-
bool drawFreetypeGlyph(msdfgen::Shape& shape, FT_Library library, FT_Face face)
1466-
{
1467-
nbl::ext::TextRendering::GlyphShapeBuilder builder(shape);
1468-
FT_Outline_Funcs ftFunctions;
1469-
ftFunctions.move_to = &ftMoveToMSDF;
1470-
ftFunctions.line_to = &ftLineToMSDF;
1471-
ftFunctions.conic_to = &ftConicToMSDF;
1472-
ftFunctions.cubic_to = &ftCubicToMSDF;
1473-
ftFunctions.shift = 0;
1474-
ftFunctions.delta = 0;
1475-
FT_Error error = FT_Outline_Decompose(&face->glyph->outline, &ftFunctions, &builder);
1476-
if (error)
1477-
return false;
1478-
builder.finish();
1479-
return true;
1480-
}
1481-
14821342
void endFrameRender(SIntendedSubmitInfo& intendedSubmitInfo)
14831343
{
14841344
submitDraws(intendedSubmitInfo, false);

0 commit comments

Comments
 (0)