33 #include <QtCore/qglobal.h> 37 #if !defined(Q_OS_MAC) && !defined(Q_OS_WIN) 39 #include <X11/Xutil.h> 53 #include <OgreRenderWindow.h> 54 #include <OgreSceneManager.h> 55 #if ((OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR >= 9) || OGRE_VERSION_MAJOR >= 2) 56 #include <Overlay/OgreOverlaySystem.h> 64 #include <QMessageBox> 85 ROS_INFO_STREAM(
"Forcing OpenGl version " << (
float)version / 100.0 <<
".");
107 ogre_root_ =
new Ogre::Root(rviz_path +
"/ogre_media/plugins.cfg");
108 #if ((OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR >= 9) || OGRE_VERSION_MAJOR >= 2) 117 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
122 #if ((OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR >= 9) || OGRE_VERSION_MAJOR >= 2) 130 #if defined(Q_OS_MAC) || defined(Q_OS_WIN) 133 Display* display = XOpenDisplay(
nullptr);
135 if (display ==
nullptr)
137 ROS_WARN(
"$DISPLAY is invalid, falling back on default :0");
138 display = XOpenDisplay(
":0");
140 if (display ==
nullptr)
142 ROS_FATAL(
"Can't open default or :0 display. Try setting DISPLAY environment variable.");
143 throw std::runtime_error(
"Can't open default or :0 display!\n");
147 int screen = DefaultScreen(display);
149 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8,
None};
151 XVisualInfo* visual = glXChooseVisual(display, screen, (
int*)attribList);
153 dummy_window_id_ = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, 1, 1, 0, 0, 0);
155 GLXContext context = glXCreateContext(display, visual,
nullptr, 1);
165 plugin_prefix +=
"lib";
167 ogre_root_->loadPlugin(plugin_prefix +
"RenderSystem_GL");
168 ogre_root_->loadPlugin(plugin_prefix +
"Plugin_OctreeSceneManager");
169 ogre_root_->loadPlugin(plugin_prefix +
"Plugin_ParticleFX");
174 bool mesa_workaround =
false;
181 Ogre::RenderSystem* renderSys =
ogre_root_->getRenderSystem();
182 const Ogre::RenderSystemCapabilities* caps = renderSys->createRenderSystemCapabilities();
183 ROS_INFO(
"OpenGL device: %s", caps->getDeviceName().c_str());
184 int major = caps->getDriverVersion().major;
185 int minor = caps->getDriverVersion().minor;
188 std::string gl_version_string = (
const char*)glGetString(GL_VERSION);
190 mesa_workaround = gl_version_string.find(
"Mesa 2") != std::string::npos &&
gl_version_ >= 320;
223 ROS_INFO(
"OpenGl version: %.1f (GLSL %.1f) limited to GLSL 1.4 on Mesa system.",
235 Ogre::RenderSystem* renderSys;
236 const Ogre::RenderSystemList* rsList;
239 #if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR == 6 242 rsList = &(
ogre_root_->getAvailableRenderers());
247 for (
unsigned int i = 0; i < rsList->size(); i++)
249 renderSys = rsList->at(i);
250 if (renderSys->getName().compare(
"OpenGL Rendering Subsystem") == 0)
256 if (renderSys ==
nullptr)
258 throw std::runtime_error(
"Could not find the opengl rendering subsystem!\n");
262 renderSys->setConfigOption(
"Full Screen",
"No");
274 renderSys->setConfigOption(
"FSAA",
"4");
283 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path +
"/ogre_media",
"FileSystem",
285 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path +
"/ogre_media/textures",
287 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path +
"/ogre_media/fonts",
289 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path +
"/ogre_media/models",
291 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rviz_path +
"/ogre_media/materials",
293 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
294 rviz_path +
"/ogre_media/materials/scripts",
"FileSystem",
ROS_PACKAGE_NAME);
295 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
296 rviz_path +
"/ogre_media/materials/glsl120",
"FileSystem",
ROS_PACKAGE_NAME);
297 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
298 rviz_path +
"/ogre_media/materials/glsl120/nogp",
"FileSystem",
ROS_PACKAGE_NAME);
304 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
305 rviz_path +
"/ogre_media/materials/glsl150",
"FileSystem",
ROS_PACKAGE_NAME);
306 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
307 rviz_path +
"/ogre_media/materials/scripts150",
"FileSystem",
ROS_PACKAGE_NAME);
311 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
312 rviz_path +
"/ogre_media/materials/scripts120",
"FileSystem",
ROS_PACKAGE_NAME);
316 std::string
s =
"Your graphics driver does not support OpenGL 2.1. Please enable software rendering " 317 "before running RViz (e.g. type 'export LIBGL_ALWAYS_SOFTWARE=1').";
319 msgBox.setText(s.c_str());
321 throw std::runtime_error(s);
325 std::vector<std::string> media_paths;
327 std::string delim(
":");
328 for (std::vector<std::string>::iterator iter = media_paths.begin(); iter != media_paths.end(); ++iter)
334 int pos2 = iter->find(delim);
335 while (pos2 != (
int)std::string::npos)
337 path = iter->substr(pos1, pos2 - pos1);
338 ROS_DEBUG(
"adding resource location: '%s'\n", path.c_str());
339 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(path,
"FileSystem",
342 pos2 = iter->find(delim, pos2 + 1);
344 path = iter->substr(pos1, iter->size() - pos1);
345 ROS_DEBUG(
"adding resource location: '%s'\n", path.c_str());
346 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(path,
"FileSystem",
362 static int (*old_error_handler)(
Display*, XErrorEvent*);
363 int checkBadDrawable(
Display* display, XErrorEvent* error)
365 if (error->error_code == BadDrawable && error->request_code == 136 && error->minor_code == 3)
367 x_baddrawable_error =
true;
374 return old_error_handler(display, error);
384 static int windowCounter = 0;
386 Ogre::NameValuePairList params;
387 Ogre::RenderWindow* window =
nullptr;
389 params[
"externalWindowHandle"] = Ogre::StringConverter::toString(window_id);
390 params[
"parentWindowHandle"] = Ogre::StringConverter::toString(window_id);
392 params[
"externalGLControl"] =
true;
397 params[
"FSAA"] =
"4";
401 #if defined(Q_OS_MAC) 402 params[
"macAPI"] =
"cocoa";
403 params[
"macAPICocoaUseNSView"] =
"true";
405 params[
"contentScalingFactor"] = std::to_string(pixel_ratio);
407 std::ostringstream stream;
408 stream <<
"OgreWindow(" << windowCounter++ <<
")";
412 #if !OGRE_STEREO_ENABLE 417 bool is_stereo =
false;
420 params[
"stereoMode"] =
"Frame Sequential";
422 params.erase(
"stereoMode");
426 #if OGRE_STEREO_ENABLE 427 is_stereo = window->isStereoEnabled();
442 if (window ==
nullptr)
447 if (window ==
nullptr)
449 ROS_ERROR(
"Unable to create the rendering window after 100 tries.");
455 window->setActive(
true);
457 window->setAutoUpdated(
false);
470 const Ogre::NameValuePairList* params,
473 Ogre::RenderWindow* window =
nullptr;
477 old_error_handler = XSetErrorHandler(&checkBadDrawable);
480 while (window ==
nullptr && (attempts++) < max_attempts)
484 window =
ogre_root_->createRenderWindow(name, width, height,
false, params);
488 if (x_baddrawable_error)
492 x_baddrawable_error =
false;
495 catch (
const std::exception& ex)
497 std::cerr <<
"rviz::RenderSystem: error creating render window: " << ex.what() << std::endl;
503 XSetErrorHandler(old_error_handler);
506 if (window && attempts > 1)
508 ROS_INFO(
"Created render window after %d attempts.", attempts);
static void configureLogging()
Configure the Ogre::LogManager to give the currently selected behavior. This must be called before Og...
#define ROS_INFO_ONCE(...)
static RenderSystem * instance_
std::string get_ogre_plugin_path()
static RenderSystem * get()
static int force_gl_version_
Ogre::RenderWindow * makeRenderWindow(WindowIDType window_id, unsigned int width, unsigned int height, double pixel_ratio=1.0)
static void forceGlVersion(int version)
Ogre::RenderWindow * tryMakeRenderWindow(const std::string &name, unsigned int width, unsigned int height, const Ogre::NameValuePairList *params, int max_attempts)
WindowIDType dummy_window_id_
unsigned long WindowIDType
static void disableAntiAliasing()
void setupDummyWindowId()
void prepareOverlays(Ogre::SceneManager *scene_manager)
ROSLIB_DECL std::string getPath(const std::string &package_name)
ROSLIB_DECL void getPlugins(const std::string &package, const std::string &attribute, V_string &plugins, bool force_recrawl=false)
static bool force_no_stereo_
#define ROS_INFO_STREAM(args)
static bool x_baddrawable_error
Ogre::OverlaySystem * ogre_overlay_system_
static void forceNoStereo()
static bool use_anti_aliasing_