Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "rve_render_server/render_texture.h"
00031
00032 #include <OGRE/OgreRenderWindow.h>
00033 #include <OGRE/OgreRenderSystem.h>
00034 #include <OGRE/OgreRoot.h>
00035 #include <OGRE/OgreTextureManager.h>
00036 #include <OGRE/OgreHardwarePixelBuffer.h>
00037
00038 #include <ros/assert.h>
00039
00040 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
00041 #include <GL/glx.h>
00042 #endif
00043
00044 namespace rve_render_server
00045 {
00046
00047 RenderTexture::RenderTexture(const rve_common::UUID& id, Renderer* rend, uint32_t width, uint32_t height)
00048 : RenderTarget(id, rend, width, height)
00049 , render_texture_(0)
00050 , recreate_texture_(false)
00051 {
00052 create();
00053 setTarget(render_texture_);
00054 }
00055
00056 RenderTexture::~RenderTexture()
00057 {
00058 Ogre::TextureManager::getSingleton().remove(tex_->getName());
00059 }
00060
00061 void RenderTexture::create()
00062 {
00063 if (!tex_.isNull())
00064 {
00065 Ogre::TextureManager::getSingleton().remove(tex_->getName());
00066 }
00067
00068 std::stringstream ss;
00069 ss << getID();
00070 tex_ = Ogre::TextureManager::getSingleton().createManual(ss.str(), ROS_PACKAGE_NAME, Ogre::TEX_TYPE_2D, getWidth(), getHeight(), 0, Ogre::PF_BYTE_RGBA, Ogre::TU_RENDERTARGET);
00071 render_texture_ = tex_->getBuffer()->getRenderTarget();
00072 }
00073
00074 void RenderTexture::resize(uint32_t width, uint32_t height)
00075 {
00076 RenderTarget::resize(width, height);
00077
00078 recreate_texture_ = true;
00079 }
00080
00081 void RenderTexture::beginRender()
00082 {
00083 if (recreate_texture_)
00084 {
00085 recreate_texture_ = false;
00086 create();
00087 }
00088
00089 RenderTarget::beginRender();
00090 }
00091
00092 }