diff options
author | erwincoumans <erwincoumans@google.com> | 2021-11-13 22:20:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-13 22:20:13 -0800 |
commit | 691ad46baae412942d370d81f329e96081dc0147 (patch) | |
tree | cb7873128df8067dfa0b36ef50ccef5fd2769960 | |
parent | a9a103fc8c0fe758ef38416f082307dae64a72d7 (diff) | |
parent | 3c4cb801571492d8bcac40fcadee747d25254ac4 (diff) | |
download | bullet3-691ad46baae412942d370d81f329e96081dc0147.tar.gz |
Merge pull request #4024 from BlGene/egl_device_selection
EGL device selection by environment variable
-rw-r--r-- | examples/OpenGLWindow/EGLOpenGLWindow.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/examples/OpenGLWindow/EGLOpenGLWindow.cpp b/examples/OpenGLWindow/EGLOpenGLWindow.cpp index f8918f318..52fc66c7f 100644 --- a/examples/OpenGLWindow/EGLOpenGLWindow.cpp +++ b/examples/OpenGLWindow/EGLOpenGLWindow.cpp @@ -33,6 +33,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <cstdlib> #include "OpenGLInclude.h" @@ -124,6 +125,28 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) { printf("eglQueryDevicesEXT Failed.\n"); m_data->egl_display = EGL_NO_DISPLAY; + } else + { + // default case, should always happen (for future compatibility) + if (m_data->m_renderDevice == -1) + { + // check env variable + const char* env_p = std::getenv("EGL_VISIBLE_DEVICES"); + + // variable is set + if(env_p != NULL) + { + m_data->m_renderDevice = std::atoi(env_p); + fprintf(stderr, "EGL device choice: %d of %d (from EGL_VISIBLE_DEVICES)\n", m_data->m_renderDevice, num_devices); + + } else { + fprintf(stderr, "EGL device choice: %d of %d.\n", m_data->m_renderDevice, num_devices); + } // else leave with -1 + + } else + { + fprintf(stderr, "EGL device choice: %d of %d.\n", m_data->m_renderDevice, num_devices); + } } // Query EGL Screens if (m_data->m_renderDevice == -1) @@ -179,7 +202,7 @@ void EGLOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) if (!eglInitialize(m_data->egl_display, NULL, NULL)) { - fprintf(stderr, "Unable to initialize EGL\n"); + fprintf(stderr, "eglInitialize() failed with error: %x\n", eglGetError()); exit(EXIT_FAILURE); } |