Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2019-12-17 20:39:01 +0300
committertamasmeszaros <meszaros.q@gmail.com>2019-12-17 20:39:01 +0300
commitacfaff3741380f81bd67f1cffb2e307f5f1c5802 (patch)
treeb9c2b5934fd8f9a771e902553adc74762a70a0c0 /sandboxes
parente25cd1ce1a2051d5ec61568120beb5fc340eafb7 (diff)
Dont use glut for fps measure.
Diffstat (limited to 'sandboxes')
-rw-r--r--sandboxes/opencsg/CMakeLists.txt3
-rw-r--r--sandboxes/opencsg/GLScene.cpp58
2 files changed, 38 insertions, 23 deletions
diff --git a/sandboxes/opencsg/CMakeLists.txt b/sandboxes/opencsg/CMakeLists.txt
index cf66867a5..145912431 100644
--- a/sandboxes/opencsg/CMakeLists.txt
+++ b/sandboxes/opencsg/CMakeLists.txt
@@ -11,7 +11,7 @@ find_package(wxWidgets 3.1 REQUIRED COMPONENTS core base gl html)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(OpenCSG REQUIRED)
-# find_package(GLUT REQUIRED)
+ find_package(GLUT REQUIRED)
include(${wxWidgets_USE_FILE})
@@ -22,6 +22,7 @@ target_compile_definitions(opencsg_example PRIVATE ${wxWidgets_DEFINITIONS})
target_link_libraries(opencsg_example ${wxWidgets_LIBRARIES}
OpenCSG::opencsg
GLEW::GLEW
+ GLUT::GLUT
OpenGL::GL
#-lXrandr -lXext -lX11
)
diff --git a/sandboxes/opencsg/GLScene.cpp b/sandboxes/opencsg/GLScene.cpp
index 2c3d1ffcd..9df3b601e 100644
--- a/sandboxes/opencsg/GLScene.cpp
+++ b/sandboxes/opencsg/GLScene.cpp
@@ -1,3 +1,5 @@
+#include <chrono>
+
#include "GLScene.hpp"
#include <libslic3r/Utils.hpp>
#include <libslic3r/SLAPrint.hpp>
@@ -5,11 +7,11 @@
#include <GL/glew.h>
-//#ifdef __APPLE__
-//#include <GLUT/glut.h>
-//#else
-//#include <GL/glut.h>
-//#endif
+#ifdef __APPLE__
+#include <GLUT/glut.h>
+#else
+#include <GL/glut.h>
+#endif
#include <boost/log/trivial.hpp>
@@ -56,23 +58,36 @@ Scene::Scene() = default;
Scene::~Scene() = default;
void renderfps () {
+ using Clock = std::chrono::high_resolution_clock;
+ using Duration = Clock::duration;
+ using TimePoint = Clock::time_point;
+
static std::ostringstream fpsStream;
- static int fps = 0;
- static int ancient = 0;
- static int last = 0;
- static int msec = 0;
-
- last = msec;
-// msec = glutGet(GLUT_ELAPSED_TIME);
- if (last / 1000 != msec / 1000) {
+ static int frames = 0;
+ static TimePoint last = Clock::now();
+
+ static const double resolution = 0.01;
+ static double fps = 0.;
+
+ auto to_sec = [](Duration d) -> double {
+ return d.count() * double(Duration::period::num) / Duration::period::den;
+ };
+
+ ++frames;
+
+ TimePoint msec = Clock::now();
+ double seconds = to_sec(msec - last);
+ if (seconds >= resolution) {
+ last = msec;
+
+ fps = 0.5 * (fps + frames / seconds);
- float correctedFps = fps * 1000.0f / float(msec - ancient);
fpsStream.str("");
- fpsStream << "fps: " << correctedFps << std::ends;
+ fpsStream << "fps: " << std::setprecision(4) << fps << std::ends;
- ancient = msec;
- fps = 0;
+ frames = 0;
}
+
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
@@ -82,15 +97,14 @@ void renderfps () {
glRasterPos2f(-1.0f, -1.0f);
glDisable(GL_LIGHTING);
std::string s = fpsStream.str();
-// for (unsigned int i=0; i<s.size(); ++i) {
-// glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]);
-// }
+ for (unsigned int i=0; i<s.size(); ++i) {
+ glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]);
+ }
glEnable(GL_LIGHTING);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
- ++fps;
glFlush();
}
@@ -358,7 +372,7 @@ void Display::set_active(long width, long height)
if (!m_initialized) {
glewInit();
-// glutInit(&argc, nullptr);
+ glutInit(&argc, nullptr);
m_initialized = true;
}