Changeset 8413
- Timestamp:
- May 7, 2011, 8:43:37 PM (14 years ago)
- Location:
- code/trunk/src/modules/designtools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/designtools/ScreenshotManager.cc
r8406 r8413 66 66 Constructor. 67 67 */ 68 ScreenshotManager::ScreenshotManager() 68 ScreenshotManager::ScreenshotManager() : finalPicturePB_(NULL), data_(NULL) 69 69 { 70 70 RegisterRootObject(ScreenshotManager); … … 78 78 ScreenshotManager::~ScreenshotManager() 79 79 { 80 80 this->cleanup(); 81 } 82 83 /** 84 @brief 85 Frees used memory. 86 */ 87 void ScreenshotManager::cleanup(void) 88 { 89 if(this->finalPicturePB_ != NULL) 90 { 91 delete this->finalPicturePB_; 92 this->finalPicturePB_ = NULL; 93 } 94 if(this->data_ != NULL) 95 { 96 delete this->data_; 97 this->data_ = NULL; 98 } 99 if(!this->tempTexture_.isNull()) 100 this->tempTexture_.freeMethod(); 81 101 } 82 102 … … 101 121 Ogre::RenderWindow* pRenderWindow = GraphicsManager::getInstance().getRenderWindow(); 102 122 103 // If the window size has changed 104 if(this->windowWidth_ != pRenderWindow->getWidth() || this->windowHeight_ != pRenderWindow->getHeight()) 105 { 106 // Update current window size 107 this->windowWidth_ = pRenderWindow->getWidth(); 108 this->windowHeight_ = pRenderWindow->getHeight(); 109 110 // Create temporary texture 111 this->tempTexture_ = Ogre::TextureManager::getSingleton().createManual("ScreenShotTex", 112 Resource::getDefaultResourceGroup(), Ogre::TEX_TYPE_2D, this->windowWidth_, 113 this->windowHeight_, 0, Ogre::PF_B8G8R8, Ogre::TU_RENDERTARGET); 114 115 // Get the current render target of the temporary texture 116 this->renderTarget_ = this->tempTexture_->getBuffer()->getRenderTarget(); 117 118 // HardwarePixelBufferSharedPtr to the buffer of the temporary texture 119 this->buffer_ = this->tempTexture_->getBuffer(); 120 121 // Create PixelBox 122 this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3]; 123 this->finalPicturePB_ = Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_); 124 } 125 } 126 123 // Update current window size 124 this->windowWidth_ = pRenderWindow->getWidth(); 125 this->windowHeight_ = pRenderWindow->getHeight(); 126 127 // Create temporary texture 128 this->tempTexture_ = Ogre::TextureManager::getSingleton().createManual("ScreenShotTex", Resource::getDefaultResourceGroup(), Ogre::TEX_TYPE_2D, this->windowWidth_, this->windowHeight_, 0, Ogre::PF_B8G8R8, Ogre::TU_RENDERTARGET); 129 130 // Get the current render target of the temporary texture 131 this->renderTarget_ = this->tempTexture_->getBuffer()->getRenderTarget(); 132 133 // HardwarePixelBufferSharedPtr to the buffer of the temporary texture 134 this->buffer_ = this->tempTexture_->getBuffer(); 135 136 // Create PixelBox 137 this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3]; 138 this->finalPicturePB_ = new Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_); 139 } 127 140 128 141 /** … … 143 156 } 144 157 else 145 {146 158 COUT(1) << "There needs to be an active camera to make screenshots." << endl; 147 return; 148 }159 160 this->cleanup(); 149 161 } 150 162 … … 152 164 @brief 153 165 Creates a screenshot and returns it. 166 After calling this method the ScreenshotManager should be cleaned using cleanup(). 154 167 @return 155 Returns a pointer to an Ogre::Image with the screenshot. 168 Returns a pointer to an Ogre::Image with the screenshot. The memory must be freed, when the image is no longer needed. 156 169 */ 157 170 Ogre::Image* ScreenshotManager::getScreenshot() … … 165 178 @brief 166 179 Creates a screenshot with the given camera and returns it. 180 After calling this method the ScreenshotManager should be cleaned using cleanup(). 167 181 @param camera 168 182 A pointer to the camera the screenshot should be taken with. 169 183 @return 170 Returns a pointer to an Ogre::Image with the screenshot. 184 Returns a pointer to an Ogre::Image with the screenshot. The memory must be freed, when the image is no longer needed. 171 185 */ 172 186 Ogre::Image* ScreenshotManager::getScreenshot(Ogre::Camera* camera) … … 198 212 if(this->gridSize_ <= 1) 199 213 { 214 //TODO: Not working. 200 215 // Simple case where the contents of the screen are taken directly 201 216 // Also used when an invalid value is passed within gridSize (zero or negative grid size) 202 217 this->renderTarget_->update(); // Render 203 218 204 finalImage = &finalImage->loadDynamicImage(static_cast<unsigned char*>(finalPicturePB_.data), finalPicturePB_.getWidth(), finalPicturePB_.getHeight(),Ogre::PF_B8G8R8);219 finalImage->loadDynamicImage(static_cast<unsigned char*>(finalPicturePB_->data), finalPicturePB_->getWidth(), finalPicturePB_->getHeight(),Ogre::PF_B8G8R8); 205 220 } 206 221 else … … 240 255 // Copy the content from the temp buffer into the final picture PixelBox 241 256 // Place the tempBuffer content at the right position 242 this->buffer_->blitToMemory(this->finalPicturePB_ .getSubVolume(subBox));257 this->buffer_->blitToMemory(this->finalPicturePB_->getSubVolume(subBox)); 243 258 244 259 COUT(4) << "Created screenshot number " << nbScreenshots << " for multi grid HD screenshot." << endl; … … 250 265 251 266 // Insert the PixelBox data into the Image Object 252 finalImage->loadDynamicImage(static_cast<unsigned char*>(this->finalPicturePB_ .data), this->finalPicturePB_.getWidth(), this->finalPicturePB_.getHeight(), 1, Ogre::PF_B8G8R8, false);267 finalImage->loadDynamicImage(static_cast<unsigned char*>(this->finalPicturePB_->data), this->finalPicturePB_->getWidth(), this->finalPicturePB_->getHeight(), 1, Ogre::PF_B8G8R8, false); 253 268 } 254 269 … … 275 290 276 291 this->gridSize_ = size; 277 // New PixelBox for the changed size.278 this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3];279 this->finalPicturePB_ = Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_);280 292 } 281 293 -
code/trunk/src/modules/designtools/ScreenshotManager.h
r8232 r8413 53 53 Class encapsulates screenshot functionality and provides a method for making multi grid (i.e. HD) screenshots. 54 54 55 56 55 @author 57 56 This code comes from http://www.ogre3d.org/tikiwiki/High+resolution+screenshots which is Public Domain. … … 88 87 inline unsigned int getGridSize(void) 89 88 { return this->gridSize_; } 89 90 void cleanup(void); // Frees used memory. 90 91 91 92 protected: … … 103 104 Ogre::HardwarePixelBufferSharedPtr buffer_; //!< Buffer for the temporary texture. 104 105 105 Ogre::PixelBox finalPicturePB_; //!< PixelBox for large screenshots, contains the screenshot for gridSize_ > 1.106 Ogre::PixelBox* finalPicturePB_; //!< PixelBox for large screenshots, contains the screenshot for gridSize_ > 1. 106 107 uint8_t* data_; //!< Data pointer for the PixelBox. 107 108 -
code/trunk/src/modules/designtools/SkyboxGenerator.cc
r8351 r8413 315 315 image->save(PathConfig::getInstance().getLogPathString()+name); 316 316 delete image; 317 ScreenshotManager::getInstance().cleanup(); // Free memory in ScreenshotManager. 317 318 } 318 319 }
Note: See TracChangeset
for help on using the changeset viewer.