render_window.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "rve_render_server/render_window.h"
00031 
00032 #include <OGRE/OgreRenderWindow.h>
00033 #include <OGRE/OgreRenderSystem.h>
00034 #include <OGRE/OgreRoot.h>
00035 
00036 #include <ros/assert.h>
00037 
00038 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
00039 #include <GL/glx.h>
00040 #endif
00041 
00042 namespace rve_render_server
00043 {
00044 
00045 RenderWindow::RenderWindow(const rve_common::UUID& id, Renderer* rend, const std::string& parent_window_handle, uint32_t width, uint32_t height)
00046 : RenderTarget(id, rend, width, height)
00047 , render_window_(0)
00048 {
00049   Ogre::Root* root = Ogre::Root::getSingletonPtr();
00050   Ogre::NameValuePairList params;
00051   params["parentWindowHandle"] = parent_window_handle;
00052   //params["FSAA"] = "8";
00053 
00054   std::stringstream id_str;
00055   id_str << id;
00056   Ogre::RenderWindow* win = root->createRenderWindow(id_str.str(), width, height, false, &params);
00057 
00058   win->setActive(true);
00059   win->setVisible(true);
00060   win->setAutoUpdated(false);
00061   render_window_ = win;
00062 
00063   setTarget(render_window_);
00064 }
00065 
00066 RenderWindow::~RenderWindow()
00067 {
00068   Ogre::Root* root = Ogre::Root::getSingletonPtr();
00069 
00070 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
00071   Display* disp = 0;
00072   render_window_->getCustomAttribute("XDISPLAY", &disp);
00073 #endif
00074 
00075   root->getRenderSystem()->destroyRenderWindow(render_window_->getName());
00076 
00077 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
00078   // Not syncing here can cause BadWindow errors
00079   XSync(disp, False);
00080 #endif
00081 }
00082 
00083 void RenderWindow::resize(uint32_t width, uint32_t height)
00084 {
00085   RenderTarget::resize(width, height);
00086 
00087   // Resize tries to actually resize the window on OSX, which can cause unfortunate results
00088 #if !defined(__APPLE__)
00089   render_window_->resize(width, height);
00090 #endif
00091 
00092   render_window_->windowMovedOrResized();
00093 }
00094 
00095 } // namespace rve_render_server


rve_render_server
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:15