Skip to content

Commit

Permalink
improve messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nmwsharp committed Jan 28, 2025
1 parent e4d989a commit 9f2997b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
3 changes: 2 additions & 1 deletion include/polyscope/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace polyscope {
// == Register various kinds of messages

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

// Non-fatal warnings. Warnings with the same base message are batched together, so the UI doesn't get completely
// overwhelmed if you call this in a dense loop.
Expand Down
5 changes: 3 additions & 2 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ void buildWarningUI(std::string warningBaseString, std::string warningDetailStri
} // namespace


void info(std::string message) {
if (options::verbosity > 0) {
void info(std::string message) { info(0, message); }
void info(int verbosityLevel, std::string message) {
if (options::verbosity > verbosityLevel) {
std::cout << options::printPrefix << message << std::endl;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void init(std::string backend) {
return;
}

info(5, "Initializing Polyscope");

state::backend = backend;

if (options::usePrefsFile) {
Expand Down
29 changes: 9 additions & 20 deletions src/render/opengl/gl_engine_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,21 @@ void GLEngineEGL::resolveEGL() {
// We are furthermore loading `libEGL.so` dynamically in the middle of runtime, rather than at load time as via ldd
// etc. At the end of this function we also load EGL extensions in the usual way.


if (options::verbosity > 5) {
std::cout << polyscope::options::printPrefix << "Attempting to dlopen libEGL.so" << std::endl;
}
info(5, "Attempting to dlopen libEGL.so");
void* handle = dlopen("libEGL.so", RTLD_LAZY);
if (handle && options::verbosity > 5) {
std::cout << polyscope::options::printPrefix << " ...loaded libEGL.so" << std::endl;
}
if (handle) info(5, " ...loaded libEGL.so");
if (!handle) {
handle = dlopen("libEGL.so.1", RTLD_LAZY); // try it while we're at it, happens on OSMesa without dev headers
}
if (handle && options::verbosity > 5) {
std::cout << polyscope::options::printPrefix << " ...loaded libEGL.so.1" << std::endl;
}
if (handle) info(5, " ...loaded libEGL.so.1");
if (!handle) {
error("EGL: Could not open libEGL.so");
error(
"EGL: Could not open libEGL.so. Ensure graphics drivers are installed, or fall back on (much slower!) software "
"rendering by installing OSMesa from your package manager.");
}

// Get EGL functions
if (options::verbosity > 5) {
std::cout << polyscope::options::printPrefix << "Attempting to dlsym resolve EGL functions" << std::endl;
}
info(5, "Attempting to dlsym resolve EGL functions");

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

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

scoreDevices.emplace_back(score, iDevice);
Expand Down

0 comments on commit 9f2997b

Please sign in to comment.