Example #1
0
	void FileSystemLayer::getConfigPaths()
	{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		// try to determine the application's path
		DWORD bufsize = 256;
		char* resolved = 0;
		do
		{
			char* buf = OGRE_ALLOC_T(char, bufsize, Ogre::MEMCATEGORY_GENERAL);
			DWORD retval = GetModuleFileName(NULL, buf, bufsize);
			if (retval == 0)
			{
				// failed
				OGRE_FREE(buf, Ogre::MEMCATEGORY_GENERAL);
				break;
			}

			if (retval < bufsize)
			{
				// operation was successful.
				resolved = buf;
			}
			else
			{
				// buffer was too small, grow buffer and try again
				OGRE_FREE(buf, Ogre::MEMCATEGORY_GENERAL);
				bufsize <<= 1;
			}
		} while (!resolved);

		Ogre::String appPath = resolved;
		if (resolved)
			OGRE_FREE(resolved, Ogre::MEMCATEGORY_GENERAL);
		if (!appPath.empty())
		{
			// need to strip the application filename from the path
			Ogre::String::size_type pos = appPath.rfind('\\');
			if (pos != Ogre::String::npos)
				appPath.erase(pos);
		}
		else
		{
			// fall back to current working dir
			appPath = ".";
		}

#elif OGRE_PLATFORM == OGRE_PLATFORM_WINRT
		Ogre::String appPath;
		if(!widePathToOgreString(appPath, Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data()))
		{
			// fallback to current working dir
			appPath = ".";
		}
#endif

		// use application path as config search path
		mConfigPaths.push_back(appPath + '\\');
	}
Example #2
0
	/*/////////////////////////////////////////////////////////////////*/
	bool OgreOggStreamSound::_stream(ALuint buffer)
	{
		std::vector<char> audioData;
		char* data;
		int  section = 0;
		int  result = 0;

		// Create buffer
		data = OGRE_ALLOC_T(char, mBufferSize, Ogre::MEMCATEGORY_GENERAL);
		memset(data, 0, mBufferSize);
		
		// Read only what was asked for
		while( !mStreamEOF && (static_cast<int>(audioData.size()) < mBufferSize) )
		{
			int  bytes = 0;
			// Read up to a buffer's worth of data
			bytes = ov_read(&mOggStream, data, static_cast<int>(mBufferSize), 0, 2, 1, &section);
			// EOF check
			if (bytes == 0)
			{
				// If set to loop wrap to start of stream
				if ( mLoop && mSeekable )
				{
					if ( ov_time_seek(&mOggStream, 0 + mLoopOffset)!= 0 )
					{
						Ogre::LogManager::getSingleton().logMessage("***--- OgreOggStream::_stream() - ERROR looping stream, ogg file NOT seekable!");
						break;
					}
				}
				else
				{
					mStreamEOF=true;
					// Don't loop - finish.
					break;
				}
			}
			// Append to end of buffer
			audioData.insert(audioData.end(), data, data + bytes);
			// Keep track of read data
			result+=bytes;
		}

		// EOF
		if(result == 0)
		{
			OGRE_FREE(data, Ogre::MEMCATEGORY_GENERAL);
			return false;
		}

		alGetError();
		// Copy buffer data
		alBufferData(buffer, mFormat, &audioData[0], static_cast<ALsizei>(audioData.size()), mVorbisInfo->rate);

		// Cleanup
		OGRE_FREE(data, Ogre::MEMCATEGORY_GENERAL);

		return true;
	}
Example #3
0
	//-----------------------------------------------------------------------------
	void ManualObject::resetTempAreas(void)
	{
		OGRE_FREE(mTempVertexBuffer, MEMCATEGORY_GEOMETRY);
		OGRE_FREE(mTempIndexBuffer, MEMCATEGORY_GEOMETRY);
		mTempVertexBuffer = 0;
		mTempIndexBuffer = 0;
		mTempVertexSize = TEMP_INITIAL_VERTEX_SIZE;
		mTempIndexSize = TEMP_INITIAL_INDEX_SIZE;
	}
Example #4
0
    //---------------------------------------------------------------------
    void DeflateStream::destroy()
    {
        if (getAccessMode() == READ)
            inflateEnd(mZStream);

        OGRE_FREE(mZStream, MEMCATEGORY_GENERAL);
        mZStream = 0;
        OGRE_FREE(mTmp, MEMCATEGORY_GENERAL);
        mTmp = 0;
    }
Example #5
0
	//-----------------------------------------------------------------------
	bool ConvexBody::operator == ( const ConvexBody& rhs ) const
	{
		if ( getPolygonCount() != rhs.getPolygonCount() )
			return false;

		// Compare the polygons. They may not be in correct order.
		// A correct convex body does not have identical polygons in its body.
		bool *bChecked = OGRE_ALLOC_T(bool, getPolygonCount(), MEMCATEGORY_SCENE_CONTROL);
		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bChecked[ i ] = false;
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bool bFound = false;

			for ( size_t j=0; j<getPolygonCount(); ++j )
			{
				const Polygon& pA = getPolygon( i );
				const Polygon& pB = rhs.getPolygon( j );

				if ( pA == pB )
				{
					bFound = true;
					bChecked[ i ] = true;
					break;
				}
			}

			if ( bFound == false )
			{
				OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
				bChecked = 0;
				return false;
			}
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			if ( bChecked[ i ] != true )
			{
				OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
				bChecked = 0;
				return false;
			}
		}

		OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
		bChecked = 0;
		return true;
	}
Example #6
0
	//-----------------------------------------------------------------------------
	Image & Image::operator = ( const Image &img )
	{
		if( m_pBuffer && m_bAutoDelete )
		{
			OGRE_FREE(m_pBuffer, MEMCATEGORY_GENERAL);
			m_pBuffer = NULL;
		}
		m_uWidth = img.m_uWidth;
		m_uHeight = img.m_uHeight;
		m_uDepth = img.m_uDepth;
		m_eFormat = img.m_eFormat;
		m_uSize = img.m_uSize;
		m_uFlags = img.m_uFlags;
		m_ucPixelSize = img.m_ucPixelSize;
		m_uNumMipmaps = img.m_uNumMipmaps;
		m_bAutoDelete = img.m_bAutoDelete;
		//Only create/copy when previous data was not dynamic data
		if( m_bAutoDelete )
		{
			m_pBuffer = OGRE_ALLOC_T(uchar, m_uSize, MEMCATEGORY_GENERAL);
			memcpy( m_pBuffer, img.m_pBuffer, m_uSize );
		}
		else
		{
			m_pBuffer = img.m_pBuffer;
		}

		return *this;
	}
Example #7
0
	//-----------------------------------------------------------------------------
	void ManualObject::resizeTempIndexBufferIfNeeded(size_t numInds)
	{
		size_t newSize = numInds * sizeof(uint32);
		if (newSize > mTempIndexSize || !mTempIndexBuffer)
		{
			if (!mTempIndexBuffer)
			{
				// init
				newSize = mTempIndexSize;
			}
			else
			{
				// increase to at least double current
				newSize = std::max(newSize, mTempIndexSize*2);
			}
			numInds = newSize / sizeof(uint32);
			uint32* tmp = mTempIndexBuffer;
			mTempIndexBuffer = OGRE_ALLOC_T(uint32, numInds, MEMCATEGORY_GEOMETRY);
			if (tmp)
			{
				memcpy(mTempIndexBuffer, tmp, mTempIndexSize);
				OGRE_FREE(tmp, MEMCATEGORY_GEOMETRY);
			}
			mTempIndexSize = newSize;
		}

	}
	//---------------------------------------------------------------------
	void TerrainLayerBlendMap::blit(const PixelBox &src, const Box &dstBox)
	{
		const PixelBox* srcBox = &src;

		if (srcBox->getWidth() != dstBox.getWidth() || srcBox->getHeight() != dstBox.getHeight())
		{
			// we need to rescale src to dst size first (also confvert format)
			void* tmpData = OGRE_MALLOC(dstBox.getWidth() * dstBox.getHeight(), MEMCATEGORY_GENERAL);
			srcBox = OGRE_NEW PixelBox(dstBox.getWidth(), dstBox.getHeight(), 1, PF_L8, tmpData);

			Image::scale(src, *srcBox);
		}

		// pixel conversion
		PixelBox dstMemBox(dstBox, PF_L8, mData);
		PixelUtil::bulkPixelConversion(*srcBox, dstMemBox);

		if (srcBox != &src)
		{
			// free temp
			OGRE_FREE(srcBox->data, MEMCATEGORY_GENERAL);
			OGRE_DELETE srcBox;
			srcBox = 0;
		}

		Rect dRect(dstBox.left, dstBox.top, dstBox.right, dstBox.bottom);
		dirtyRect(dRect);

	}
Example #9
0
	//-----------------------------------------------------------------------
	void CgProgram::freeCgArgs(void)
	{
		if (mCgArguments)
		{
			size_t index = 0;
			char* current = mCgArguments[index];
			while (current)
			{
				OGRE_FREE(current, MEMCATEGORY_RESOURCE);
				mCgArguments[index] = 0;
				current = mCgArguments[++index];
			}
			OGRE_FREE(mCgArguments, MEMCATEGORY_RESOURCE);
			mCgArguments = 0;
		}
	}
Example #10
0
    //-----------------------------------------------------------------------------
    Image & Image::flipAroundX()
    {
        if( !mBuffer )
        {
            OGRE_EXCEPT( 
                Exception::ERR_INTERNAL_ERROR,
                "Can not flip an uninitialised texture",
                "Image::flipAroundX" );
        }
        
        mNumMipmaps = 0; // Image operations lose precomputed mipmaps

        size_t rowSpan = mWidth * mPixelSize;

        uchar *pTempBuffer = OGRE_ALLOC_T(uchar, rowSpan * mHeight, MEMCATEGORY_GENERAL);
        uchar *ptr1 = mBuffer, *ptr2 = pTempBuffer + ( ( mHeight - 1 ) * rowSpan );

        for( ushort i = 0; i < mHeight; i++ )
        {
            memcpy( ptr2, ptr1, rowSpan );
            ptr1 += rowSpan; ptr2 -= rowSpan;
        }

        memcpy( mBuffer, pTempBuffer, rowSpan * mHeight);

        OGRE_FREE(pTempBuffer, MEMCATEGORY_GENERAL);

        return *this;
    }
	void AndroidArchive::unload()
	{
		if(mBuffer)
		{
			OGRE_FREE(mBuffer, MEMCATEGORY_GENERAL);
			mBuffer = 0;
		}
	}
Example #12
0
	//-----------------------------------------------------------------------------
	Image::~Image()
	{
		//Only delete if this was not a dynamic image (meaning app holds & destroys buffer)
		if( m_pBuffer && m_bAutoDelete )
		{
			OGRE_FREE(m_pBuffer, MEMCATEGORY_GENERAL);
			m_pBuffer = NULL;
		}
	}
Example #13
0
    //---------------------------------------------------------------------
    void Image::freeMemory()
    {
        //Only delete if this was not a dynamic image (meaning app holds & destroys buffer)
        if( mBuffer && mAutoDelete )
        {
            OGRE_FREE(mBuffer, MEMCATEGORY_GENERAL);
            mBuffer = NULL;
        }

    }
    //-----------------------------------------------------------------------
    void BspRaySceneQuery::clearTemporaries(void)
    {
        mObjsThisQuery.clear();
		vector<WorldFragment*>::type::iterator i;
        for (i = mSingleIntersections.begin(); i != mSingleIntersections.end(); ++i)
        {
            OGRE_FREE(*i, MEMCATEGORY_SCENE_CONTROL);
        }
        mSingleIntersections.clear();
    }
Example #15
0
	//-----------------------------------------------------------------------------
	Image & Image::load(DataStreamPtr& stream, const String& type )
	{
		if( m_pBuffer && m_bAutoDelete )
		{
			OGRE_FREE(m_pBuffer, MEMCATEGORY_GENERAL);
			m_pBuffer = NULL;
		}

		Codec * pCodec = 0;
		if (!type.empty())
		{
			// use named codec
			pCodec = Codec::getCodec(type);
		}
		else
		{
			// derive from magic number
			// read the first 32 bytes or file size, if less
			size_t magicLen = std::min(stream->size(), (size_t)32);
			char magicBuf[32];
			stream->read(magicBuf, magicLen);
			// return to start
			stream->seek(0);
			pCodec = Codec::getCodec(magicBuf, magicLen);
		}

		if( !pCodec )
			OGRE_EXCEPT(
			Exception::ERR_INVALIDPARAMS, 
			"Unable to load image - unable to identify codec. Check file extension "
			"and file format.",
			"Image::load" );

		Codec::DecodeResult res = pCodec->decode(stream);

		ImageCodec::ImageData* pData = 
			static_cast<ImageCodec::ImageData*>(res.second.getPointer());

		m_uWidth = pData->width;
		m_uHeight = pData->height;
		m_uDepth = pData->depth;
		m_uSize = pData->size;
		m_uNumMipmaps = pData->num_mipmaps;
		m_uFlags = pData->flags;

		// Get the format and compute the pixel size
		m_eFormat = pData->format;
		m_ucPixelSize = static_cast<uchar>(PixelUtil::getNumElemBytes( m_eFormat ));
		// Just use internal buffer of returned memory stream
		m_pBuffer = res.first->getPtr();
		// Make sure stream does not delete
		res.first->setFreeOnClose(false);

		return *this;
	}
//-----------------------------------------------------------------------------
void D3D9HardwarePixelBuffer::bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *volume, IDirect3DBaseTexture9 *mipTex)
{
    D3D9_DEVICE_ACCESS_CRITICAL_SECTION

    BufferResources* bufferResources = getBufferResources(dev);
    bool isNewBuffer = false;

    if (bufferResources == NULL)
    {
        bufferResources = createBufferResources();
        mMapDeviceToBufferResources[dev] = bufferResources;
        isNewBuffer = true;
    }

    bufferResources->mipTex = mipTex;
    bufferResources->volume = volume;
    bufferResources->volume->AddRef();
    
    D3DVOLUME_DESC desc;
    if(volume->GetDesc(&desc) != D3D_OK)
        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Could not get volume information",
         "D3D9HardwarePixelBuffer::D3D9HardwarePixelBuffer");
    mWidth = desc.Width;
    mHeight = desc.Height;
    mDepth = desc.Depth;
    mFormat = D3D9Mappings::_getPF(desc.Format);
    // Default
    mRowPitch = mWidth;
    mSlicePitch = mHeight*mWidth;
    mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);

    if (isNewBuffer && mOwnerTexture->isManuallyLoaded())
    {
        DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
        
        while (it != mMapDeviceToBufferResources.end())
        {
            if (it->second != bufferResources &&
                it->second->volume != NULL &&
                it->first->TestCooperativeLevel() == D3D_OK &&
                dev->TestCooperativeLevel() == D3D_OK)
            {
                Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth);
                PixelBox dstBox(fullBufferBox, mFormat);

                dstBox.data = OGRE_MALLOC(getSizeInBytes(), MEMCATEGORY_RESOURCE);
                blitToMemory(fullBufferBox, dstBox, it->second, it->first);
                blitFromMemory(dstBox, fullBufferBox, bufferResources);
                OGRE_FREE(dstBox.data, MEMCATEGORY_RESOURCE);
                break;
            }
            ++it;           
        }               
    }
}
Example #17
0
    //-----------------------------------------------------------------------
    void RenderTarget::writeContentsToFile(const String& filename)
    {
        PixelFormat pf = suggestPixelFormat();

        uchar *data = OGRE_ALLOC_T(uchar, mWidth * mHeight * PixelUtil::getNumElemBytes(pf), MEMCATEGORY_RENDERSYS);
        PixelBox pb(mWidth, mHeight, 1, pf, data);

        copyContentsToMemory(pb);

        Image().loadDynamicImage(data, mWidth, mHeight, 1, pf, false, 1, 0).save(filename);

        OGRE_FREE(data, MEMCATEGORY_RENDERSYS);
    }
Example #18
0
    //---------------------------------------------------------------------
    void Serializer::readFloats(DataStreamPtr& stream, double* pDest, size_t count)
    {
		// Read from float, convert to double
		float* tmp = OGRE_ALLOC_T(float, count, MEMCATEGORY_GENERAL);
		float* ptmp = tmp;
        stream->read(tmp, sizeof(float) * count);
        flipFromLittleEndian(tmp, sizeof(float), count);
		// Convert to doubles (no cast required)
		while(count--)
		{
			*pDest++ = *ptmp++;
		}
		OGRE_FREE(tmp, MEMCATEGORY_GENERAL);
    }
  // bool publishFrame(Ogre::RenderWindow * render_object, const std::string frame_id)
  bool publishFrame(Ogre::RenderTexture * render_object, const std::string frame_id)
  {
    if (pub_.getTopic() == "")
    {
      return false;
    }
    if (frame_id == "")
    {
      return false;
    }
    // RenderTarget::writeContentsToFile() used as example
    int height = render_object->getHeight();
    int width = render_object->getWidth();
    // the results of pixel format have to be used to determine
    // image.encoding
    Ogre::PixelFormat pf = render_object->suggestPixelFormat();
    uint pixelsize = Ogre::PixelUtil::getNumElemBytes(pf);
    uint datasize = width * height * pixelsize;

    // 1.05 multiplier is to avoid crash when the window is resized.
    // There should be a better solution.
    uchar *data = OGRE_ALLOC_T(uchar, datasize * 1.05, Ogre::MEMCATEGORY_RENDERSYS);
    Ogre::PixelBox pb(width, height, 1, pf, data);
    render_object->copyContentsToMemory(pb, Ogre::RenderTarget::FB_AUTO);

    sensor_msgs::Image image;
    image.header.stamp = ros::Time::now();
    image.header.seq = image_id_++;
    image.header.frame_id = frame_id;
    image.height = height;
    image.width = width;
    image.step = pixelsize * width;
    if (pixelsize == 3)
      image.encoding = sensor_msgs::image_encodings::RGB8;  // would break if pf changes
    else if (pixelsize == 4)
      image.encoding = sensor_msgs::image_encodings::RGBA8;  // would break if pf changes
    else
    {
      ROS_ERROR_STREAM("unknown pixe format " << pixelsize << " " << pf);
    }
    image.is_bigendian = (OGRE_ENDIAN == OGRE_ENDIAN_BIG);
    image.data.resize(datasize);
    memcpy(&image.data[0], data, datasize);
    pub_.publish(image);

    OGRE_FREE(data, Ogre::MEMCATEGORY_RENDERSYS);
  }
Example #20
0
	//-----------------------------------------------------------------------------
	Image& Image::loadDynamicImage( uchar* pData, size_t uWidth, size_t uHeight, 
		size_t depth,
		PixelFormat eFormat, bool autoDelete, 
		size_t numFaces, size_t numMipMaps)
	{

		if( m_pBuffer && m_bAutoDelete )
		{
			OGRE_FREE(m_pBuffer, MEMCATEGORY_GENERAL);
			m_pBuffer = NULL;
		}
		// Set image metadata
		m_uWidth = uWidth;
		m_uHeight = uHeight;
		m_uDepth = depth;
		m_eFormat = eFormat;
		m_ucPixelSize = static_cast<uchar>(PixelUtil::getNumElemBytes( m_eFormat ));
		m_uNumMipmaps = numMipMaps;
		m_uFlags = 0;
		// Set flags
		if (PixelUtil::isCompressed(eFormat))
			m_uFlags |= IF_COMPRESSED;
		if (m_uDepth != 1)
			m_uFlags |= IF_3D_TEXTURE;
		if(numFaces == 6)
			m_uFlags |= IF_CUBEMAP;
		if(numFaces != 6 && numFaces != 1)
			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
			"Number of faces currently must be 6 or 1.", 
			"Image::loadDynamicImage");

		m_uSize = calculateSize(numMipMaps, numFaces, uWidth, uHeight, depth, eFormat);

		if (pData)
		{
			m_pBuffer = pData;
			m_bAutoDelete = autoDelete;
		}
		else
		{
			m_bAutoDelete = true;
			m_pBuffer = OGRE_ALLOC_T(Ogre::uchar, m_uSize, Ogre::MEMCATEGORY_RESOURCE);
		}

		return *this;

	}
//-----------------------------------------------------------------------------  
void D3D9HardwarePixelBuffer::destroyBufferResources(IDirect3DDevice9* d3d9Device)
{
    D3D9_DEVICE_ACCESS_CRITICAL_SECTION

    DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.find(d3d9Device);

    if (it != mMapDeviceToBufferResources.end())
    {
        SAFE_RELEASE(it->second->surface);
        SAFE_RELEASE(it->second->volume);           
        if (it->second != NULL)
        {
            OGRE_FREE (it->second, MEMCATEGORY_RENDERSYS);
            it->second = NULL;
        }
        mMapDeviceToBufferResources.erase(it);
    }
}
Example #22
0
    //---------------------------------------------------------------------
    void Serializer::writeFloats(const double* const pDouble, size_t count)
    {
		// Convert to float, then write
		float* tmp = OGRE_ALLOC_T(float, count, MEMCATEGORY_GENERAL);
		for (unsigned int i = 0; i < count; ++i)
		{
			tmp[i] = static_cast<float>(pDouble[i]);
		}
		if(mFlipEndian)
		{
            flipToLittleEndian(tmp, sizeof(float), count);
            writeData(tmp, sizeof(float), count);
		}
		else
		{
            writeData(tmp, sizeof(float), count);
		}
		OGRE_FREE(tmp, MEMCATEGORY_GENERAL);
    }
Example #23
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeData(const void* buf, size_t size, size_t count)
	{
		checkStream(false, false, true);

		size_t totSize = size * count;
		if (mFlipEndian)
		{
			void* pToWrite = OGRE_MALLOC(totSize, MEMCATEGORY_GENERAL);
			memcpy(pToWrite, buf, totSize);

			Bitwise::bswapChunks(pToWrite, size, count);
			mStream->write(pToWrite, totSize);

			OGRE_FREE(pToWrite, MEMCATEGORY_GENERAL);
		}
		else
		{
			mStream->write(buf, totSize);
		}

	}
D3D9HardwarePixelBuffer::~D3D9HardwarePixelBuffer()
{
    D3D9_DEVICE_ACCESS_CRITICAL_SECTION

    destroyRenderTexture();

    DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();

    while (it != mMapDeviceToBufferResources.end())
    {
        SAFE_RELEASE(it->second->surface);
        SAFE_RELEASE(it->second->volume);
        if (it->second != NULL)
        {
            OGRE_FREE (it->second, MEMCATEGORY_RENDERSYS);
            it->second = NULL;
        }
        DeviceToBufferResourcesIterator deadi = it++;
        mMapDeviceToBufferResources.erase(deadi);
    }
}
Example #25
0
	Terrain* SnowTerrain::getTerrain()
	{
		if(!mTerrainGroup) return NULL;

		Terrain *t =  mTerrainGroup->getTerrain(0,0);
		return t;

		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while (ti.hasMoreElements())
		{
			Ogre::uint32 tkey = ti.peekNextKey();
			TerrainGroup::TerrainSlot* ts = ti.getNext();
			if (ts->instance && ts->instance->isLoaded())
			{

				float* heights = ts->instance->getHeightData();

				//PixelBox* pBox = ts->instance->calculateNormals());
				TexturePtr texturePtr = ts->instance->getTerrainNormalMap();
				HardwarePixelBufferSharedPtr buf = texturePtr->getBuffer();

				size_t bytes = buf->getSizeInBytes();
				size_t h = buf->getHeight();
				size_t w = buf->getWidth();
				size_t d = buf->getDepth();
				PixelFormat f = PF_BYTE_RGB;//buf->getFormat();


				uint8* tmpData = (uint8*)OGRE_MALLOC(w * h * 3, MEMCATEGORY_GENERAL);
				memset(tmpData,0,w*h*3);
				PixelBox pBox(w, h, d, f, tmpData);
				buf->blitToMemory(pBox);
				OGRE_FREE(tmpData, MEMCATEGORY_GENERAL);
				
			}
		}
		return NULL;
	}
Example #26
0
	//-----------------------------------------------------------------------------
	void ManualObject::resizeTempVertexBufferIfNeeded(size_t numVerts)
	{
		// Calculate byte size
		// Use decl if we know it by now, otherwise default size to pos/norm/texcoord*2
		size_t newSize;
		if (!mFirstVertex)
		{
			newSize = mDeclSize * numVerts;
		}
		else
		{
			// estimate - size checks will deal for subsequent verts
			newSize = TEMP_VERTEXSIZE_GUESS * numVerts;
		}
		if (newSize > mTempVertexSize || !mTempVertexBuffer)
		{
			if (!mTempVertexBuffer)
			{
				// init
				newSize = mTempVertexSize;
			}
			else
			{
				// increase to at least double current
				newSize = std::max(newSize, mTempVertexSize*2);
			}
			// copy old data
			char* tmp = mTempVertexBuffer;
			mTempVertexBuffer = OGRE_ALLOC_T(char, newSize, MEMCATEGORY_GEOMETRY);
			if (tmp)
			{
				memcpy(mTempVertexBuffer, tmp, mTempVertexSize);
				// delete old buffer
				OGRE_FREE(tmp, MEMCATEGORY_GEOMETRY);
			}
			mTempVertexSize = newSize;
		}
	}
	//-----------------------------------------------------------------------
    DefaultHardwareIndexBuffer::~DefaultHardwareIndexBuffer()
	{
		OGRE_FREE(mData, MEMCATEGORY_GEOMETRY);
	}
Example #28
0
 STDMETHOD(Close)(LPCVOID pData)
 {           
     OGRE_FREE(pData, MEMCATEGORY_RESOURCE);
     return S_OK;
 }
Example #29
0
    //-----------------------------------------------------------------------------
    Image & Image::flipAroundY()
    {
        if( !mBuffer )
        {
            OGRE_EXCEPT( 
                Exception::ERR_INTERNAL_ERROR,
                "Can not flip an uninitialised texture",
                "Image::flipAroundY" );
        }
        
        mNumMipmaps = 0; // Image operations lose precomputed mipmaps

        uchar   *pTempBuffer1 = NULL;
        ushort  *pTempBuffer2 = NULL;
        uchar   *pTempBuffer3 = NULL;
        uint    *pTempBuffer4 = NULL;

        uchar   *src1 = mBuffer;
        ushort  *src2 = (ushort *)mBuffer;
        uchar   *src3 = mBuffer;
        uint    *src4 = (uint *)mBuffer;

        ushort y;
        switch (mPixelSize)
        {
        case 1:
            pTempBuffer1 = OGRE_ALLOC_T(uchar, mWidth * mHeight, MEMCATEGORY_GENERAL);
            for (y = 0; y < mHeight; y++)
            {
                uchar *dst1 = (pTempBuffer1 + ((y * mWidth) + mWidth - 1));
                for (ushort x = 0; x < mWidth; x++)
                    memcpy(dst1--, src1++, sizeof(uchar));
            }

            memcpy(mBuffer, pTempBuffer1, mWidth * mHeight * sizeof(uchar));
            OGRE_FREE(pTempBuffer1, MEMCATEGORY_GENERAL);
            break;

        case 2:
            pTempBuffer2 = OGRE_ALLOC_T(ushort, mWidth * mHeight, MEMCATEGORY_GENERAL);
            for (y = 0; y < mHeight; y++)
            {
                ushort *dst2 = (pTempBuffer2 + ((y * mWidth) + mWidth - 1));
                for (ushort x = 0; x < mWidth; x++)
                    memcpy(dst2--, src2++, sizeof(ushort));
            }

            memcpy(mBuffer, pTempBuffer2, mWidth * mHeight * sizeof(ushort));
            OGRE_FREE(pTempBuffer2, MEMCATEGORY_GENERAL);
            break;

        case 3:
            pTempBuffer3 = OGRE_ALLOC_T(uchar, mWidth * mHeight * 3, MEMCATEGORY_GENERAL);
            for (y = 0; y < mHeight; y++)
            {
                size_t offset = ((y * mWidth) + (mWidth - 1)) * 3;
                uchar *dst3 = pTempBuffer3;
                dst3 += offset;
                for (size_t x = 0; x < mWidth; x++)
                {
                    memcpy(dst3, src3, sizeof(uchar) * 3);
                    dst3 -= 3; src3 += 3;
                }
            }

            memcpy(mBuffer, pTempBuffer3, mWidth * mHeight * sizeof(uchar) * 3);
            OGRE_FREE(pTempBuffer3, MEMCATEGORY_GENERAL);
            break;

        case 4:
            pTempBuffer4 = OGRE_ALLOC_T(uint, mWidth * mHeight, MEMCATEGORY_GENERAL);
            for (y = 0; y < mHeight; y++)
            {
                uint *dst4 = (pTempBuffer4 + ((y * mWidth) + mWidth - 1));
                for (ushort x = 0; x < mWidth; x++)
                    memcpy(dst4--, src4++, sizeof(uint));
            }

            memcpy(mBuffer, pTempBuffer4, mWidth * mHeight * sizeof(uint));
            OGRE_FREE(pTempBuffer4, MEMCATEGORY_GENERAL);
            break;

        default:
            OGRE_EXCEPT( 
                Exception::ERR_INTERNAL_ERROR,
                "Unknown pixel depth",
                "Image::flipAroundY" );
            break;
        }

        return *this;

    }
Example #30
0
 void OgreZfree(void* opaque, void* address)
 {
     OGRE_FREE(address, MEMCATEGORY_GENERAL);
 }