Skip to content

Commit

Permalink
Fix render system (#1101)
Browse files Browse the repository at this point in the history
* typedef to handle different types for window id handles

* update to follow latest recommendations

for integrating Qt5 and Ogre3D, see:

http://www.ogre3d.org/tikiwiki/tiki-
index.php?page=Integrating+Ogre+into+QT5

* restore conditional for Qt5

fixes #1100
  • Loading branch information
wjwwood committed Jun 5, 2017
1 parent 81e8771 commit afb808a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
24 changes: 10 additions & 14 deletions src/rviz/ogre_helpers/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,19 @@ int checkBadDrawable( Display* display, XErrorEvent* error )
}
#endif // Q_WS_X11

Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height, double pixel_ratio )
Ogre::RenderWindow* RenderSystem::makeRenderWindow(
WindowIDType window_id,
unsigned int width,
unsigned int height,
double pixel_ratio)
{
static int windowCounter = 0; // Every RenderWindow needs a unique name, oy.

Ogre::NameValuePairList params;
Ogre::RenderWindow *window = NULL;

std::stringstream window_handle_stream;
window_handle_stream << window_id;

#ifdef Q_OS_MAC
params["externalWindowHandle"] = window_handle_stream.str();
#else
params["parentWindowHandle"] = window_handle_stream.str();
#endif
params["externalWindowHandle"] = Ogre::StringConverter::toString(window_id);
params["parentWindowHandle"] = Ogre::StringConverter::toString(window_id);

params["externalGLControl"] = true;

Expand All @@ -366,11 +364,9 @@ Ogre::RenderWindow* RenderSystem::makeRenderWindow( intptr_t window_id, unsigned
}

// Set the macAPI for Ogre based on the Qt implementation
#ifdef QT_MAC_USE_COCOA
params["macAPI"] = "cocoa";
params["macAPICocoaUseNSView"] = "true";
#else
params["macAPI"] = "carbon";
#if defined(Q_OS_MAC)
parameters["macAPI"] = "cocoa";
parameters["macAPICocoaUseNSView"] = "true";
#endif
params["contentScalingFactor"] = std::to_string(pixel_ratio);

Expand Down
15 changes: 13 additions & 2 deletions src/rviz/ogre_helpers/render_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ namespace rviz
class RenderSystem
{
public:

#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
typedef size_t WindowIDType;
#else
typedef unsigned long WindowIDType;
#endif

static RenderSystem* get();

Ogre::RenderWindow* makeRenderWindow( intptr_t window_id, unsigned int width, unsigned int height, double pixel_ratio = 1.0 );
Ogre::RenderWindow* makeRenderWindow(
WindowIDType window_id,
unsigned int width,
unsigned int height,
double pixel_ratio = 1.0);

Ogre::Root* root() { return ogre_root_; }

Expand Down Expand Up @@ -92,7 +103,7 @@ class RenderSystem
static RenderSystem* instance_;

// ID for a dummy window of size 1x1, used to keep Ogre happy.
unsigned long dummy_window_id_;
WindowIDType dummy_window_id_;

Ogre::Root* ogre_root_;
Ogre::OverlaySystem* ogre_overlay_system_;
Expand Down
11 changes: 3 additions & 8 deletions src/rviz/ogre_helpers/render_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,11 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )
this->setLayout(mainLayout);
#endif

#ifdef Q_OS_MAC
uintptr_t win_id = winId();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
rviz::RenderSystem::WindowIDType win_id = this->renderFrame->winId();
#else
# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
unsigned int win_id = renderFrame->winId();
# else
unsigned int win_id = winId();
# endif
rviz::RenderSystem::WindowIDType win_id = this->winId();
#endif

QApplication::flush();

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Expand Down

0 comments on commit afb808a

Please sign in to comment.