Added small program to measure font atlas performance, ryzom/ryzomcore#626

develop
Nimetu 4 years ago
parent 87b5a77d4f
commit 661a2bdaf7

@ -1,4 +1,5 @@
ADD_SUBDIRECTORY(font)
ADD_SUBDIRECTORY(font_perf)
ADD_SUBDIRECTORY(cluster_viewer)
ADD_SUBDIRECTORY(shape_viewer)

@ -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 <ESC> 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));

@ -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)

@ -0,0 +1,99 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// 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 <http://www.gnu.org/licenses/>.
#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 <windows.h>
#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;
}
Loading…
Cancel
Save