From 661a2bdaf7827cac9c863ab1eb4c69edafd244da Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 4 Jan 2021 20:34:56 +0200 Subject: [PATCH] Added small program to measure font atlas performance, ryzom/ryzomcore#626 --- nel/samples/3d/CMakeLists.txt | 1 + nel/samples/3d/font/main.cpp | 32 +++++++- nel/samples/3d/font_perf/CMakeLists.txt | 14 ++++ nel/samples/3d/font_perf/beteckna.ttf | Bin 0 -> 16488 bytes nel/samples/3d/font_perf/main.cpp | 99 ++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 nel/samples/3d/font_perf/CMakeLists.txt create mode 100644 nel/samples/3d/font_perf/beteckna.ttf create mode 100644 nel/samples/3d/font_perf/main.cpp diff --git a/nel/samples/3d/CMakeLists.txt b/nel/samples/3d/CMakeLists.txt index 772ab0056..1062579cd 100644 --- a/nel/samples/3d/CMakeLists.txt +++ b/nel/samples/3d/CMakeLists.txt @@ -1,4 +1,5 @@ ADD_SUBDIRECTORY(font) +ADD_SUBDIRECTORY(font_perf) ADD_SUBDIRECTORY(cluster_viewer) ADD_SUBDIRECTORY(shape_viewer) diff --git a/nel/samples/3d/font/main.cpp b/nel/samples/3d/font/main.cpp index 5a656be49..1d5eaa114 100644 --- a/nel/samples/3d/font/main.cpp +++ b/nel/samples/3d/font/main.cpp @@ -22,6 +22,7 @@ #include "nel/misc/event_emitter.h" #include "nel/misc/event_listener.h" #include "nel/misc/path.h" +#include "nel/misc/random.h" // look at 3dinit example #include "nel/3d/nelu.h" @@ -97,10 +98,12 @@ int main(int argc, char **argv) CNELU::EventServer.addEmitter(CNELU::Driver->getEventEmitter()); CNELU::AsyncListener.addToServer(CNELU::EventServer); + NLMISC::CValueSmoother smoothFPS; + NLMISC::CRandom rnd; do { // look at 3dinit example - CNELU::clearBuffers(CRGBA(0,0,0)); + CNELU::clearBuffers(CRGBA(120,120,0)); // now, every frame, we have to render the computer string. @@ -168,12 +171,39 @@ int main(int argc, char **argv) tc.setHotSpot (CComputedString::BottomRight); tc.printAt (0.99f, 0.01f, string("Press to quit")); + /*for(uint i = 0; i < 1000; ++i) + { + uint fontSize = rnd.rand(40) + 10; + tc.setColor(CRGBA(rnd.rand(255), rnd.rand(255), rnd.rand(255))); + tc.setFontSize(fontSize); + tc.setHotSpot(CComputedString::MiddleMiddle); + tc.printAt(rnd.frand(1.f), rnd.frand(1.f), toString("%d", fontSize)); + }*/ + + { + static TTicks oldTick = CTime::getPerformanceTime(); + TTicks newTick = CTime::getPerformanceTime(); + double deltaTime = CTime::ticksToSecond (newTick-oldTick); + oldTick = newTick; + smoothFPS.addValue((float)deltaTime); + deltaTime = smoothFPS.getSmoothValue (); + if (deltaTime > 0.0) + { + //printf("FPS: %.5f\n", 1.f/deltaTime); + tc.setFontSize(16); + tc.setColor(CRGBA::Yellow); + tc.setHotSpot(CComputedString::TopLeft); + tc.printAt(0.01f, 0.99f, toString("FPS:%.f", 1.0f/deltaTime)); + } + } + // look 3dinit example CNELU::swapBuffers(); CNELU::screenshot(); // look at event example CNELU::EventServer.pump(true); + } while(!CNELU::AsyncListener.isKeyPushed(KeyESCAPE)); diff --git a/nel/samples/3d/font_perf/CMakeLists.txt b/nel/samples/3d/font_perf/CMakeLists.txt new file mode 100644 index 000000000..2f794c983 --- /dev/null +++ b/nel/samples/3d/font_perf/CMakeLists.txt @@ -0,0 +1,14 @@ +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(nl_sample_font_perf ${SRC}) + +ADD_DEFINITIONS(-DFONT_DIR="\\"${NL_SHARE_ABSOLUTE_PREFIX}/nl_sample_font_perf/\\"") + +TARGET_LINK_LIBRARIES(nl_sample_font_perf nelmisc nel3d) +NL_DEFAULT_PROPS(nl_sample_font_perf "NeL, Samples, 3D: Font Performance Test") +NL_ADD_RUNTIME_FLAGS(nl_sample_font_perf) + +INSTALL(TARGETS nl_sample_font_perf RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT samples3d) +INSTALL(FILES beteckna.ttf DESTINATION ${NL_SHARE_PREFIX}/nl_sample_font_perf COMPONENT samples3d) + + diff --git a/nel/samples/3d/font_perf/beteckna.ttf b/nel/samples/3d/font_perf/beteckna.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e9a117f4d4906362913e2eebe10d06c0119ce957 GIT binary patch literal 16488 zcmeHu2Yg%A{qH&FUfrubEy+{Xuq9iPWm(gE$4Trs)3FneB#yHQ&Ljz;BmojgNLYQ8 z(Xu-K6bc1G!f5`i0EM=UKp1VI1qv;t6#k{ObVYjKb7hAl4|xB+Pd}gc-se*#SGxDy zbAEfBVL}NZCbEkNWPMjxU+>hPmgf=DIs>i6Q#+@0kxFtNAvJ69?3y}z*1TWctSQ0s z_XsiGGq&@ZLRZUUlr%`+xNbA#@v_myDe~y59f#;S3=H`qKwjj&53? z%>omtS%&xOm21yk(X(RJ+k{AcgaqDSwS08hdwEZI@$MhEQmfFQ-YM?J*aV)-R-L_h zoBKz>d3b&m*YUOM#zw^j#=V57R^k2oXOC`MPaY#2{{lR_$4Adz-t}C3oRCN>+A{0c zZQA_I-;n2RQ4zu}Wk0~nU*>-C zwuYiNBNF7qKf4I&P`(Lq^XJ(srYyscJDU~U*;-Bs*@tJ&3t_jh`}jM;06WH8XfLjN z@n#1#(mql^e@KGtb#eoXk{`wvj2g8y`+`>jO=8OlI^GAw*!AU z*}%R{;_MG(j6F-P0=^v_-{gh&)$-~DSJcq%IqcCJ=u%0TTd)| zW8jVXKRt`&Y#e~T_(P=$<3u-Z*(bedav10rM3p3~HCmnCU^JO6R$HFk;mj{6EGjN> zmAXA%Us<_7P*E8Sg{vaf(VAF1kxZp)>*^aCo0?l%+uA!2sisbw-rX~!cjm0wbLP(L zo8LdMVBz4<@Q8wC=@?l~R*+RI$!fBOtUYTIH6dqzdYijjyy(o9)1Q~*9ye@UxBm1O zcp4?#Ge7T>M{@t7WSHzFuTn1^r@QHQ=u?cad{)nhg6GoFqI+KV zo-U(r)GyQDs(;nsG9(O34BHIX7>*c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-fyUVX3waE=BcFcP>VIk(NR&@u&_S3@GRVWAbEp4YAwN=-2iJ6{P7&IJeC!NEFkkbt~*L*D1W zldgcg_am-81sW2N@ovcY9AIsRPu>Kdyb*EqDahnIfE)tUu#)+>r%waa3jvkKdG6^+ zKs^qqPXOvGfQp!cY*&ZBQLWEL5Up1MLlPK{0|Vj-WHW&G3-Nw1TMFo5MCmQSP=)H> z1WwF|Cl>Hng0&DAxd9SSK*}*hfkz?f3h;|~0!!gDmxk>9u#9=MmzqJ6m(U9t`5-D zjJZaG!ae7_Sg~UZG*yCX$Ax@R#%&E*H;Bj@Lsm$D`!wpIT0GZf4@0(xfZ<+XfE}S< zH`;pvaW3*&A9T>4{T}4}BWUpmWPKPsY|7aP;Ecd>d8M`ue2jpP^MQ2-u$~LrPz{2M z!R*aE&Y}LX;I0fZDhC&SNRa=%a0Pl)!qS7#X%%LG5!h-qG!mb%{xl?Ci`F{DQs={p z=Rua!VXf7m^*Pvl0zHDzSS{#24x5j{=Bpv=TcEvqNT~sK5XGokK&XSAPlKKF>^dJ( zyB$`(M6s0vu*M&Q{;NU%S3v(|kXrAA)b4^*>jAS8(t8xrI|7(V_)-)S>s2H+9ei}7 zp6CVqnV@DCbT${%%|m-1w-xjp0nKIL|I6S%1jrA8|0rNW)3Btf>`qV>!&4HRR|Ctd zxa0HnPEgMOiee6EnDBYPm;xAGfH4()rb7nZfYAeMoq_h=>2X`eA6Ih8O|84D(1M{t;!yP9c*f%*us^BHHt}_|V% +// Copyright (C) 2020 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/misc/types_nl.h" + +#include "nel/misc/event_emitter.h" +#include "nel/misc/event_listener.h" +#include "nel/misc/path.h" +#include "nel/misc/random.h" + +// look at 3dinit example +#include "nel/3d/nelu.h" + +// used for font management +#include "nel/3d/font_manager.h" +#include "nel/3d/computed_string.h" +#include "nel/3d/text_context.h" +#include "nel/3d/driver_user.h" + +#ifdef NL_OS_WINDOWS + #ifndef NL_COMP_MINGW + #define NOMINMAX + #endif + #include +#endif // NL_OS_WINDOWS + +#ifndef FONT_DIR +# define FONT_DIR "." +#endif + +using namespace std; +using namespace NL3D; +using namespace NLMISC; + +int main(int argc, char **argv) +{ + // look at 3dinit example + CNELU::init (800, 600, CViewport(), 32, true, 0, false, false); + + NLMISC::CPath::addSearchPath(FONT_DIR); + + // create a font manager + CFontManager fontManager; + + // set the font cache to 2 megabytes (default is 1mb) + fontManager.setMaxMemory(2000000); + + CTextContext tc; + + tc.init (CNELU::Driver, &fontManager); + + // The first param is the font name (could be ttf, pfb, fon, etc...). The + // second one is optional, it's the font kerning file + tc.setFontGenerator (NLMISC::CPath::lookup("beteckna.ttf")); + + NLMISC::CRandom rnd; + + uint nbCount = 100000; + TTicks startTick = CTime::getPerformanceTime(); + std::string txt; + for(uint i = 0; i < nbCount; ++i) + { + uint fontSize = rnd.rand(200); + bool embolden = rnd.rand(1) == 1; + bool oblique = rnd.rand(1) == 1; + txt = toString("Lorem ipsum %03d", fontSize); + + CComputedString cs; + fontManager.computeString(txt, tc.getFontGenerator(), CRGBA::White, fontSize, embolden, oblique, CNELU::Driver, cs); + } + + TTicks endTick = CTime::getPerformanceTime(); + + double deltaTime = CTime::ticksToSecond(endTick-startTick); + std::string msg = toString("Generated %d strings in %.2fs\n", nbCount, deltaTime); + + nlinfo("%s", msg.c_str()); + printf("%s", msg.c_str()); + + fontManager.dumpCache ("font_pref_cache_dump.tga"); + + // look at 3dinit example + CNELU::release(); + + return EXIT_SUCCESS; +}