33 #include <QtCore/qglobal.h> 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 <OgreOverlaySystem.h> 64 #include <QMessageBox> 86 ROS_INFO_STREAM(
"Forcing OpenGl version " << (
float)version / 100.0 <<
"." );
110 ogre_root_ =
new Ogre::Root( rviz_path+
"/ogre_media/plugins.cfg" );
111 #if ((OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR >= 9) || OGRE_VERSION_MAJOR >= 2 ) 120 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
125 #if ((OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR >= 9) || OGRE_VERSION_MAJOR >= 2 ) 136 Display *display = XOpenDisplay(0);
138 if (display ==
NULL) {
140 ROS_WARN(
"$DISPLAY is invalid, falling back on default :0");
141 display = XOpenDisplay(
":0");
143 if (display ==
NULL) {
144 ROS_FATAL(
"Can't open default or :0 display. Try setting DISPLAY environment variable.");
145 throw std::runtime_error(
"Can't open default or :0 display!\n");
150 int screen = DefaultScreen( display );
152 int attribList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16,
153 GLX_STENCIL_SIZE, 8,
None };
155 XVisualInfo *visual = glXChooseVisual( display, screen, (
int*)attribList );
158 RootWindow( display, screen ),
159 0, 0, 1, 1, 0, 0, 0 );
161 GLXContext context = glXCreateContext( display, visual,
NULL, 1 );
171 plugin_prefix +=
"lib";
173 ogre_root_->loadPlugin( plugin_prefix +
"RenderSystem_GL" );
174 ogre_root_->loadPlugin( plugin_prefix +
"Plugin_OctreeSceneManager" );
175 ogre_root_->loadPlugin( plugin_prefix +
"Plugin_ParticleFX" );
186 Ogre::RenderSystem *renderSys =
ogre_root_->getRenderSystem();
187 renderSys->createRenderSystemCapabilities();
188 const Ogre::RenderSystemCapabilities* caps = renderSys->getCapabilities();
189 int major = caps->getDriverVersion().major;
190 int minor = caps->getDriverVersion().minor;
227 Ogre::RenderSystem *renderSys;
228 const Ogre::RenderSystemList *rsList;
231 #if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR == 6 234 rsList = &(
ogre_root_->getAvailableRenderers());
239 for(
unsigned int i = 0; i < rsList->size(); i++ )
241 renderSys = rsList->at( i );
242 if( renderSys->getName().compare(
"OpenGL Rendering Subsystem")== 0 )
248 if( renderSys ==
NULL )
250 throw std::runtime_error(
"Could not find the opengl rendering subsystem!\n" );
254 renderSys->setConfigOption(
"Full Screen",
"No");
265 renderSys->setConfigOption(
"FSAA",
"4");
274 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media",
"FileSystem",
ROS_PACKAGE_NAME );
275 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/textures",
"FileSystem",
ROS_PACKAGE_NAME );
276 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/fonts",
"FileSystem",
ROS_PACKAGE_NAME );
277 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/models",
"FileSystem",
ROS_PACKAGE_NAME );
278 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials",
"FileSystem",
ROS_PACKAGE_NAME );
279 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/scripts",
"FileSystem",
ROS_PACKAGE_NAME );
280 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/glsl120",
"FileSystem",
ROS_PACKAGE_NAME );
281 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/glsl120/nogp",
"FileSystem",
ROS_PACKAGE_NAME );
287 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/glsl150",
"FileSystem",
ROS_PACKAGE_NAME );
288 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/scripts150",
"FileSystem",
ROS_PACKAGE_NAME );
292 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( rviz_path +
"/ogre_media/materials/scripts120",
"FileSystem",
ROS_PACKAGE_NAME );
296 std::string
s =
"Your graphics driver does not support OpenGL 2.1. Please enable software rendering before running RViz (e.g. type 'export LIBGL_ALWAYS_SOFTWARE=1').";
298 msgBox.setText(s.c_str());
300 throw std::runtime_error( s );
304 std::vector<std::string> media_paths;
306 std::string delim(
":");
307 for( std::vector<std::string>::iterator iter = media_paths.begin(); iter != media_paths.end(); ++iter )
313 int pos2 = iter->find(delim);
314 while( pos2 != (
int)std::string::npos )
316 path = iter->substr( pos1, pos2 - pos1 );
317 ROS_DEBUG(
"adding resource location: '%s'\n", path.c_str());
318 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( path,
"FileSystem",
ROS_PACKAGE_NAME );
320 pos2 = iter->find( delim, pos2 + 1 );
322 path = iter->substr( pos1, iter->size() - pos1 );
323 ROS_DEBUG(
"adding resource location: '%s'\n", path.c_str());
324 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( path,
"FileSystem",
ROS_PACKAGE_NAME );
339 static int (*old_error_handler)(
Display*, XErrorEvent* );
340 int checkBadDrawable(
Display* display, XErrorEvent* error )
342 if( error->error_code == BadDrawable &&
343 error->request_code == 136 &&
344 error->minor_code == 3 )
346 x_baddrawable_error =
true;
353 return old_error_handler( display, error );
364 static int windowCounter = 0;
366 Ogre::NameValuePairList params;
367 Ogre::RenderWindow *window =
NULL;
369 params[
"externalWindowHandle"] = Ogre::StringConverter::toString(window_id);
370 params[
"parentWindowHandle"] = Ogre::StringConverter::toString(window_id);
372 params[
"externalGLControl"] =
true;
376 params[
"FSAA"] =
"4";
380 #if defined(Q_OS_MAC) 381 params[
"macAPI"] =
"cocoa";
382 params[
"macAPICocoaUseNSView"] =
"true";
384 params[
"contentScalingFactor"] = std::to_string(pixel_ratio);
386 std::ostringstream stream;
387 stream <<
"OgreWindow(" << windowCounter++ <<
")";
391 #if !OGRE_STEREO_ENABLE 396 bool is_stereo =
false;
399 params[
"stereoMode"] =
"Frame Sequential";
401 params.erase(
"stereoMode");
405 #if OGRE_STEREO_ENABLE 406 is_stereo = window->isStereoEnabled();
421 if ( window ==
NULL )
428 ROS_ERROR(
"Unable to create the rendering window after 100 tries." );
434 window->setActive(
true);
436 window->setAutoUpdated(
false);
447 const std::string& name,
450 const Ogre::NameValuePairList* params,
453 Ogre::RenderWindow *window =
NULL;
457 old_error_handler = XSetErrorHandler( &checkBadDrawable );
460 while (window ==
NULL && (attempts++) < max_attempts)
464 window =
ogre_root_->createRenderWindow( name, width, height,
false, params );
468 if( x_baddrawable_error )
472 x_baddrawable_error =
false;
475 catch(
const std::exception & ex )
477 std::cerr <<
"rviz::RenderSystem: error creating render window: " 478 << ex.what() << std::endl;
484 XSetErrorHandler( old_error_handler );
487 if( window && attempts > 1 )
489 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_