[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #include "OgreStableHeaders.h"
|
---|
| 26 |
|
---|
| 27 | #include "OgreRenderTexture.h"
|
---|
| 28 | #include "OgreException.h"
|
---|
| 29 | #include "OgreHardwarePixelBuffer.h"
|
---|
| 30 | #include "OgreImage.h"
|
---|
| 31 | #include "OgreImageCodec.h"
|
---|
| 32 |
|
---|
| 33 | namespace Ogre
|
---|
| 34 | {
|
---|
| 35 |
|
---|
| 36 | //-----------------------------------------------------------------------------
|
---|
| 37 | RenderTexture::RenderTexture(HardwarePixelBuffer *buffer, size_t zoffset):
|
---|
| 38 | mBuffer(buffer), mZOffset(zoffset)
|
---|
| 39 | {
|
---|
| 40 | mPriority = OGRE_REND_TO_TEX_RT_GROUP;
|
---|
| 41 | mWidth = mBuffer->getWidth();
|
---|
| 42 | mHeight = mBuffer->getHeight();
|
---|
| 43 | mColourDepth = Ogre::PixelUtil::getNumElemBits(mBuffer->getFormat());
|
---|
| 44 | }
|
---|
| 45 | RenderTexture::~RenderTexture()
|
---|
| 46 | {
|
---|
| 47 | mBuffer->_clearSliceRTT(0);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void RenderTexture::writeContentsToFile( const String & filename )
|
---|
| 51 | {
|
---|
| 52 | // copyToMemory
|
---|
| 53 | ImageCodec::ImageData *imgData = new ImageCodec::ImageData();
|
---|
| 54 |
|
---|
| 55 | imgData->width = mWidth;
|
---|
| 56 | imgData->height = mHeight;
|
---|
| 57 | imgData->depth = 1;
|
---|
| 58 | imgData->format = PF_BYTE_RGBA;
|
---|
| 59 | size_t size = imgData->width * imgData->height * 4;
|
---|
| 60 |
|
---|
| 61 | // Allocate buffer
|
---|
| 62 | uchar* pBuffer = new uchar[size];
|
---|
| 63 |
|
---|
| 64 | // Read pixels
|
---|
| 65 | mBuffer->blitToMemory(
|
---|
| 66 | Box(0,0,mZOffset,mWidth,mHeight,mZOffset+1),
|
---|
| 67 | PixelBox(mWidth, mHeight, 1, imgData->format, pBuffer)
|
---|
| 68 | );
|
---|
| 69 |
|
---|
| 70 | // Wrap buffer in a chunk
|
---|
| 71 | MemoryDataStreamPtr stream(new MemoryDataStream(
|
---|
| 72 | pBuffer, size, false));
|
---|
| 73 |
|
---|
| 74 | // Get codec
|
---|
| 75 | size_t pos = filename.find_last_of(".");
|
---|
| 76 | String extension;
|
---|
| 77 | if( pos == String::npos )
|
---|
| 78 | OGRE_EXCEPT(
|
---|
| 79 | Exception::ERR_INVALIDPARAMS,
|
---|
| 80 | "Unable to determine image type for '" + filename + "' - invalid extension.",
|
---|
| 81 | "GLRenderTexture::writeContentsToFile" );
|
---|
| 82 |
|
---|
| 83 | while( pos != filename.length() - 1 )
|
---|
| 84 | extension += filename[++pos];
|
---|
| 85 |
|
---|
| 86 | // Get the codec
|
---|
| 87 | Codec * pCodec = Codec::getCodec(extension);
|
---|
| 88 |
|
---|
| 89 | // Write out
|
---|
| 90 | Codec::CodecDataPtr codecDataPtr(imgData);
|
---|
| 91 | pCodec->codeToFile(stream, filename, codecDataPtr);
|
---|
| 92 |
|
---|
| 93 | delete [] pBuffer;
|
---|
| 94 | }
|
---|
| 95 | //-----------------------------------------------------------------------------
|
---|
| 96 | MultiRenderTarget::MultiRenderTarget(const String &name)
|
---|
| 97 | {
|
---|
| 98 | mPriority = OGRE_REND_TO_TEX_RT_GROUP;
|
---|
| 99 | mName = name;
|
---|
| 100 | /// Width and height is unknown with no targets attached
|
---|
| 101 | mWidth = mHeight = 0;
|
---|
| 102 | }
|
---|
| 103 | //-----------------------------------------------------------------------------
|
---|
| 104 | void MultiRenderTarget::writeContentsToFile( const String & filename )
|
---|
| 105 | {
|
---|
| 106 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
|
---|
| 107 | "Cannot write MultiRenderTargets to disk",
|
---|
| 108 | "MultiRenderTarget::writeContentsToFile");
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | }
|
---|