Skip to content

Commit 9f2997b

Browse files
committed
improve messages
1 parent e4d989a commit 9f2997b

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

include/polyscope/messages.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace polyscope {
99
// == Register various kinds of messages
1010

1111
// General details, things you would print to stdout. For now, that's exactly what it does
12-
void info(std::string message);
12+
void info(std::string message); // default verbosityLevel = 0
13+
void info(int verbosityLevel, std::string message); // only printed if verbosity > vebosityLevel
1314

1415
// Non-fatal warnings. Warnings with the same base message are batched together, so the UI doesn't get completely
1516
// overwhelmed if you call this in a dense loop.

src/messages.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ void buildWarningUI(std::string warningBaseString, std::string warningDetailStri
203203
} // namespace
204204

205205

206-
void info(std::string message) {
207-
if (options::verbosity > 0) {
206+
void info(std::string message) { info(0, message); }
207+
void info(int verbosityLevel, std::string message) {
208+
if (options::verbosity > verbosityLevel) {
208209
std::cout << options::printPrefix << message << std::endl;
209210
}
210211
}

src/polyscope.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ void init(std::string backend) {
143143
return;
144144
}
145145

146+
info(5, "Initializing Polyscope");
147+
146148
state::backend = backend;
147149

148150
if (options::usePrefsFile) {

src/render/opengl/gl_engine_egl.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,28 +285,21 @@ void GLEngineEGL::resolveEGL() {
285285
// We are furthermore loading `libEGL.so` dynamically in the middle of runtime, rather than at load time as via ldd
286286
// etc. At the end of this function we also load EGL extensions in the usual way.
287287

288-
289-
if (options::verbosity > 5) {
290-
std::cout << polyscope::options::printPrefix << "Attempting to dlopen libEGL.so" << std::endl;
291-
}
288+
info(5, "Attempting to dlopen libEGL.so");
292289
void* handle = dlopen("libEGL.so", RTLD_LAZY);
293-
if (handle && options::verbosity > 5) {
294-
std::cout << polyscope::options::printPrefix << " ...loaded libEGL.so" << std::endl;
295-
}
290+
if (handle) info(5, " ...loaded libEGL.so");
296291
if (!handle) {
297292
handle = dlopen("libEGL.so.1", RTLD_LAZY); // try it while we're at it, happens on OSMesa without dev headers
298293
}
299-
if (handle && options::verbosity > 5) {
300-
std::cout << polyscope::options::printPrefix << " ...loaded libEGL.so.1" << std::endl;
301-
}
294+
if (handle) info(5, " ...loaded libEGL.so.1");
302295
if (!handle) {
303-
error("EGL: Could not open libEGL.so");
296+
error(
297+
"EGL: Could not open libEGL.so. Ensure graphics drivers are installed, or fall back on (much slower!) software "
298+
"rendering by installing OSMesa from your package manager.");
304299
}
305300

306301
// Get EGL functions
307-
if (options::verbosity > 5) {
308-
std::cout << polyscope::options::printPrefix << "Attempting to dlsym resolve EGL functions" << std::endl;
309-
}
302+
info(5, "Attempting to dlsym resolve EGL functions");
310303

311304
eglGetError = (eglGetErrorT)dlsym(handle, "eglGetError");
312305
eglGetPlatformDisplay = (eglGetPlatformDisplayT)dlsym(handle, "eglGetPlatformDisplay");
@@ -383,10 +376,7 @@ void GLEngineEGL::sortAvailableDevicesByPreference(
383376
// NOTE: on many machines (cloud VMs?) the query string above is nullptr, and this whole function does nothing
384377
// useful
385378
if (vendorStrRaw == nullptr) {
386-
if (polyscope::options::verbosity > 5) {
387-
std::cout << polyscope::options::printPrefix << " EGLDevice " << iDevice << " -- vendor: " << "NULL"
388-
<< " priority score: " << score << std::endl;
389-
}
379+
info(5, "EGLDevice " + std::to_string(iDevice) + " -- vendor: NULL priority score: " std::to_string(score);
390380
scoreDevices.emplace_back(score, iDevice);
391381
continue;
392382
}
@@ -415,8 +405,7 @@ void GLEngineEGL::sortAvailableDevicesByPreference(
415405

416406
// at high verbosity levels, log the priority
417407
if (polyscope::options::verbosity > 5) {
418-
std::cout << polyscope::options::printPrefix << " EGLDevice " << iDevice << " -- vendor: " << vendorStr
419-
<< " priority score: " << score << std::endl;
408+
info(5, "EGLDevice " + std::to_string(iDevice) + " -- vendor: " + vendorStr + " priority score: " std::to_string(score);
420409
}
421410

422411
scoreDevices.emplace_back(score, iDevice);

0 commit comments

Comments
 (0)