Example #1
1
HRESULT __stdcall CopyAviSynthToPlanarBuffer(const byte* srcY, const byte* srcU, const byte* srcV, int srcPitch, int clipPrecision, int width, int height, InputTexture* dst, IScriptEnvironment* env) {
	// Copies source frame into main surface buffer, or into additional input textures
	RECT SrcRect;
	SrcRect.top = 0;
	SrcRect.left = 0;
	SrcRect.right = width;
	SrcRect.bottom = height;
	D3DFORMAT fmt = GetD3DFormat(clipPrecision, true);
	HR(D3DXLoadSurfaceFromMemory(dst->SurfaceY, nullptr, nullptr, srcY, fmt, srcPitch, nullptr, &SrcRect, D3DX_FILTER_NONE, 0));
	HR(D3DXLoadSurfaceFromMemory(dst->SurfaceU, nullptr, nullptr, srcU, fmt, srcPitch, nullptr, &SrcRect, D3DX_FILTER_NONE, 0));
	HR(D3DXLoadSurfaceFromMemory(dst->SurfaceV, nullptr, nullptr, srcV, fmt, srcPitch, nullptr, &SrcRect, D3DX_FILTER_NONE, 0));
	return S_OK;
}
Example #2
0
int RendererD3D::InitializeTextureFromBits(byte* pImageBits, int width, int height)
{
	HRESULT result;

	LPDIRECT3DSURFACE9 surface=NULL;
	LPDIRECT3DTEXTURE9 texture = NULL;
	
	result = D3DXCreateTexture( m_pd3dDevice, width, height, D3DX_DEFAULT, 0, D3DFMT_R8G8B8,D3DPOOL_MANAGED, &texture);

	texture->GetSurfaceLevel(0, &surface);

	RECT rect;
	rect.top = 0;
	rect.left = 0;
	rect.bottom = height;
	rect.right = width;

	result = D3DXLoadSurfaceFromMemory(surface,NULL,NULL,pImageBits,D3DFMT_R8G8B8, width*3*sizeof(byte),NULL,&rect,D3DX_DEFAULT,0);

	surface->Release();

	assert(result == D3D_OK);

	m_textureList.push_back(texture);
	return (m_textureList.size()-1);
}	
Example #3
0
//----------------------------------------------------------------------------//
void Direct3D9Texture::loadFromMemory(const void* buffer,
                                      const Sizef& buffer_size,
                                      PixelFormat pixel_format)
{
    if (!isPixelFormatSupported(pixel_format))
        CEGUI_THROW(InvalidRequestException(
            "Data was supplied in an unsupported pixel format."));

    const D3DFORMAT pixfmt = toD3DPixelFormat(pixel_format);
    createDirect3D9Texture(buffer_size, pixfmt);

    LPDIRECT3DSURFACE9 surface = getTextureSurface();
    const PixelBuffer pixel_buffer(buffer, buffer_size, pixel_format);

    const RECT src_rect = { 0, 0,
        static_cast<LONG>(buffer_size.d_width),
        static_cast<LONG>(buffer_size.d_height) };

    HRESULT hr = D3DXLoadSurfaceFromMemory(
            surface, 0, 0, pixel_buffer.getPixelDataPtr(),
            pixfmt == D3DFMT_X8R8G8B8 ? D3DFMT_R8G8B8 : pixfmt,
            pixel_buffer.getPitch(), 0, &src_rect, D3DX_FILTER_NONE, 0);

    surface->Release();

    if (FAILED(hr))
        CEGUI_THROW(RendererException(
            "D3DXLoadSurfaceFromMemory failed."));
}
Example #4
0
HRESULT CDxtexDoc::LoadSurfaceFromVolumeSlice(LPDIRECT3DVOLUME9 pVolume, UINT iSlice, LPDIRECT3DSURFACE9 psurf)
{
    HRESULT hr;
    D3DVOLUME_DESC vd;
    D3DLOCKED_BOX lb;
    D3DBOX box;
    RECT rc;

    pVolume->GetDesc(&vd);

    box.Left = 0;
    box.Right = vd.Width;
    box.Top = 0;
    box.Bottom = vd.Height;
    box.Front = iSlice;
    box.Back = iSlice + 1;

    rc.left = 0;
    rc.right = vd.Width;
    rc.top = 0;
    rc.bottom = vd.Height;

    hr = pVolume->LockBox(&lb, &box, 0);
    if (FAILED(hr))
        return hr;

    hr = D3DXLoadSurfaceFromMemory(psurf, NULL, NULL, lb.pBits, vd.Format, lb.RowPitch, 
        NULL, &rc, D3DX_DEFAULT, 0);

    pVolume->UnlockBox();

    return hr;
}
Example #5
0
bool SprConverter::ExportNewFormatFile( const char* pszFileName )
{
	if (!SaveNewSprFile(pszFileName))
	{
		return false;
	}
	for (int  i = 0; i < m_pSprHead->Frames; i++)
	{
		BYTE* pSprExchangeBuffer = NULL;
		pSprExchangeBuffer = new BYTE[m_ppSprFrameList[i]->Width * m_ppSprFrameList[i]->Height * 4]; /* 4? Byte */
		RenderToA8R8G8B8(pSprExchangeBuffer,
			m_ppSprFrameList[i]->Width * sizeof(DWORD),
			m_ppSprFrameList[i]->Sprite,
			m_ppSprFrameList[i]->Width,
			m_ppSprFrameList[i]->Height,
			m_pSprPaList);
		IDirect3DTexture9* pTexture = NULL;
		if (!FAILED(D3DXCreateTexture(g_pd3dDevice, 
			m_ppSprFrameList[i]->Width, 
			m_ppSprFrameList[i]->Height, 
			1, 
			0, 
			D3DFMT_A8R8G8B8,
			D3DPOOL_MANAGED, 
			&pTexture)))
		{
			IDirect3DSurface9* pSurface = NULL;
			RECT rect;
			rect.left = 0;
			rect.top = 0;
			rect.right = m_ppSprFrameList[i]->Width;
			rect.bottom = m_ppSprFrameList[i]->Height;
			pTexture->GetSurfaceLevel(0, &pSurface);
 			D3DXLoadSurfaceFromMemory(pSurface, NULL, NULL, pSprExchangeBuffer,
 				D3DFMT_A8R8G8B8, m_ppSprFrameList[i]->Width * sizeof(DWORD), NULL, &rect,D3DX_DEFAULT, 0);
			SaveDdsFile(pszFileName, i, pTexture);
			pSurface->Release();
			pTexture->Release();
			SAFE_DELETE_ARRAY( pSprExchangeBuffer );
		}
		else
		{
			//Log
		}
	}
	return true;
}
Example #6
0
HRESULT ccTileMap::loadTileData(FILE *stream)
{
    if(fseek( stream, m_header.PTRTileGfx, SEEK_SET))
        return E_FAIL;

    int tileDataSize = m_header.Tiles*1024;
    unsigned char *tileLoadData = new unsigned char[tileDataSize];
    ZeroMemory(tileLoadData, tileDataSize );

    if(fread(tileLoadData, tileDataSize, 1, stream) == 0 || ferror( stream ))
        return E_FAIL;

    //
    // Create surfaces.
    //

    HRESULT hr;
    IDirect3DSurface9 *ppBackBuffer;
    if (SUCCEEDED(hr = m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
    {
        D3DSURFACE_DESC d3dsDesc;
        ppBackBuffer->GetDesc(&d3dsDesc);

        m_pTileSurface = new LPDIRECT3DSURFACE9[m_header.Tiles];

        RECT srcRect;
        srcRect.left   = srcRect.top	 = 0;
        srcRect.right  = m_tileWidth - 1;
        srcRect.bottom = m_tileHeight - 1;

        for(int i=0; i<m_header.Tiles; i++)
        {
            if (FAILED(hr = m_pd3dDevice->CreateOffscreenPlainSurface(
                                m_tileWidth, m_tileHeight, d3dsDesc.Format, D3DPOOL_DEFAULT, &m_pTileSurface[i], NULL)))
                return hr;

            if (FAILED(hr = D3DXLoadSurfaceFromMemory(
                                m_pTileSurface[i], NULL, NULL, (tileLoadData+(i*1024)), D3DFMT_P8, m_tileWidth, taPalette, &srcRect, D3DX_DEFAULT , 0)))
            {
                return hr;
            }
        }
    }

    SAFE_RELEASE(ppBackBuffer);
    return S_OK;
}
Example #7
0
	void D3D9texture::uploadSubTexture(int level, const Rect& rect, const void* pixels, TexFormat format /*= TexFormat::AUTO */)
	{
		D3D9_SCOPELOCK;

		if (!format) {
			format = m_format;
		}

		if (rect.isEmpty()) {
			return;
		}

		D3DFORMAT d3dformat;
		trTexFormat(format, d3dformat);

		if (d3dformat == D3DFMT_UNKNOWN) {
			return;
		}

		LPDIRECT3DSURFACE9 surface;
		HRESULT hr;
		V(m_object->GetSurfaceLevel(level, &surface));

		RECT d3drect;
		d3drect.left = rect.x; d3drect.top = rect.y; d3drect.right = rect.xMax(); d3drect.bottom = rect.yMax();

		RECT d3dsrcrect;
		d3dsrcrect.left = 0; d3dsrcrect.top = 0; d3dsrcrect.right = rect.width; d3dsrcrect.bottom = rect.height;

		UINT srcpitch = format.calculateDataSize(rect.width, 1);
		DWORD d3dfilter = D3DX_FILTER_NONE;

		V(D3DXLoadSurfaceFromMemory(surface, 0, &d3drect, pixels, d3dformat, srcpitch, 0, &d3dsrcrect, d3dfilter, 0));

		SAFE_RELEASE(surface);
	}
HRESULT CVMR9Subgraph::BuildAndRender(LPCVOID pSrcMemory,UINT imgtp,long bmWidthBytes,LPRECT rcSrc,DWORD ColorKey,IMultiVMR9Wizard* pWizard)
{
	HRESULT hr = S_OK;
	if(!pWizard)return E_FAIL;
	if(m_pGraph)			return E_FAIL;

    IVMRFilterConfig9		* pConfig = 0;
    IGraphBuilder			* pGb= 0;
	IDirect3DSurface9		* pTexturePrivSurf    = NULL;
	IDirect3DTexture9		* pTexture = 0;
	IBaseFilter				* pVMR9 = 0;
	VMR9AllocationInfo info;
	info.dwFlags = VMR9AllocFlag_OffscreenSurface;
	info.dwHeight = rcSrc->bottom - rcSrc->top;
	info.dwWidth =	rcSrc->bottom - rcSrc->left;
	info.Format = (D3DFORMAT)imgtp;
	info.MinBuffers = 1;
	info.Pool = D3DPOOL_SYSTEMMEM;
	info.szAspectRatio.cx = 0;//rcDest->right - rcDest->left;
	info.szAspectRatio.cy =0;// rcDest->bottom - rcDest->top;
	info.szNativeSize.cy = rcSrc->right - rcSrc->left;
	info.szNativeSize.cy = rcSrc->bottom - rcSrc->top;

    if( !pSrcMemory )
    {
        return E_POINTER;
    }

   // USES_CONVERSION;
	m_GraphType = Image_DIB;
	try
	{
		// create graph
		hr = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
			IID_IFilterGraph, (void**)&(m_pGraph) );
		
		if( FAILED(hr))throw hr;
	
		if(!m_pGraph)
			throw E_OUTOFMEMORY;
		

		// create and add VMR9
		hr = CoCreateInstance( CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
			IID_IBaseFilter, (void**)&(pVMR9) );
		if( FAILED(hr))throw hr;

		hr = m_pGraph->AddFilter( pVMR9, L"VMR9");
		if( FAILED(hr))throw hr;

		// configure VMR9
		hr = pVMR9->QueryInterface( IID_IVMRFilterConfig9, (void**)&(pConfig) );
		if( FAILED(hr))throw hr;

	    
		// if wizard is provided, set VMR to the renderless code and attach to the wizard
		if( pWizard )
		{
			// set VMR to the renderless mode
			hr = pConfig->SetRenderingMode( VMR9Mode_Renderless );
			if( FAILED(hr))throw hr;


			hr = pWizard->Attach( pVMR9, D3DFMT_A8R8G8B8,& m_dwID);
			if( FAILED(hr))throw hr;

			DWORD num = 1;
			hr = pWizard->InitializeDevice(m_dwID,&info,&num);
			if( FAILED(hr))throw hr;
			hr = pWizard->GetTexture(m_dwID,&pTexture);
			if( FAILED(hr))throw hr;

			hr = pTexture->GetSurfaceLevel(0,&pTexturePrivSurf);
			if( FAILED(hr))throw hr;
			
			//CDC::GetCurrentBitmap(imgtp	
			hr = D3DXLoadSurfaceFromMemory( pTexturePrivSurf,
											NULL,
											0,
											pSrcMemory,
											(D3DFORMAT)imgtp,
											bmWidthBytes,
											0,
											rcSrc,
											D3DX_DEFAULT,
											ColorKey
											);

			if( FAILED(hr))throw hr;
			if(!pTexturePrivSurf)throw E_OUTOFMEMORY;
			
		}
		
		// try to render media source
		hr = m_pGraph->QueryInterface( IID_IGraphBuilder, (void**)&(pGb) );
		if( FAILED(hr))throw hr;

	//	pWizard->InitializeDevice();

		// ok, all is rendered, now get MediaControl, MediaSeeking and continue
		hr = m_pGraph->QueryInterface( IID_IMediaControl, (void**)&(m_pMc) );
		if( FAILED(hr))throw hr;

		hr = m_pGraph->QueryInterface( IID_IMediaSeeking, (void**)&(m_pMs) );
		if( FAILED(hr))throw hr;

	}
	catch(HRESULT hr1)
	{
		pWizard->Detach( m_dwID );
		hr = hr1;
	}
	RELEASE(pVMR9);
	RELEASE(pConfig );
	RELEASE(pGb );
	RELEASE(pTexturePrivSurf );
	RELEASE(pTexture );
	//AddCaptureFilter(pWizard);
    return hr;
}
Example #9
0
	bool D3D9texture::loadFile2D()
	{
		D3D9_SCOPELOCK;

		HRESULT hr;
		const byte_t* data;
		int flags = 0;

		if (!(m_initFlags.isSet(IF_NoMipmap)))
			flags |= Image::Mipmap;

		flags |= Image::ExpandAlpha;

		std::auto_ptr<Image> imagefile(new Image);
		if (!imagefile->loadFile(m_name, flags)) {
//			Debugf("D3D9texture::loadFile2D: can't find image file for %s\n", m_name.c_str());
			return false;
		}

		m_width = imagefile->getWidth();
		m_height = imagefile->getHeight();
		//		mDesc.format = imagefile->getFormat();
		if (!Math::isPowerOfTwo(m_width) || !Math::isPowerOfTwo(m_height)) {
			//			if (!(mDesc.flags & TexFlag_allowNPOT))
			Errorf("GLtexture::loadFile2D: texture %s size isn't power of two", m_name.c_str());
			//			else
			//				Debugf("GLtexture::loadFile2D: texture %s size isn't power of two\n", mDesc.name.c_str());
		}

		m_format = imagefile->getFormat();

		D3DFORMAT d3dformat;

		trTexFormat(imagefile->getFormat(), d3dformat);

		DWORD d3dusage = 0;

		int mipdown = image_mip->getInteger();
		if (m_initFlags.isSet(IF_NoMipmap) || imagefile->getNumMipmapLevels() <= 1) {
			m_isMipmaped = false;
			mipdown = 0;
		} else {
			m_isMipmaped = true;
			mipdown = Math::clamp(mipdown, 0, imagefile->getNumMipmapLevels()-1);

			m_width >>= mipdown;
			m_height >>= mipdown;
			if (m_width < 1) m_width = 1;
			if (m_height < 1) m_height = 1;
		}


//		m_initFlags = 0;

		if (m_initFlags.isSet(Texture::IF_RenderTarget)) {
			Errorf("Can't load render target from a file");
		}

		if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
			d3dusage |= D3DUSAGE_AUTOGENMIPMAP;
			m_isMipmaped = true;
			m_hardwareGenMipmap = checkIfSupportHardwareMipmapGeneration(d3dformat, d3dusage);

			if (!m_hardwareGenMipmap) {
				d3dusage &= ~D3DUSAGE_AUTOGENMIPMAP;
			}
		}

		if (m_object == 0) {
			V(d3d9Device->CreateTexture(m_width, m_height, !m_isMipmaped, d3dusage, d3dformat, D3DPOOL_MANAGED, &m_object, 0));
		}

		int width, height;
		width = m_width;
		height = m_height;
		for (DWORD i = 0; i < m_object->GetLevelCount(); i++) {
			if (i + mipdown >= (DWORD)imagefile->getNumMipmapLevels()) {
				// if no image for this level, break
				break;
			}

			uint_t datasize = imagefile->getFormat().calculateDataSize(width, height);
			m_videoMemoryUsed += datasize;

			data = imagefile->getData(i + mipdown);
#if 0
			LPDIRECT3DSURFACE9 surface;

			V(m_object->GetSurfaceLevel(i, &surface));

			D3DXLoadSurfaceFromMemory(surface, 0, 0, data, d3dformat, pitch, 0, rect, D3DX_FILTER_NONE, 0);
#else
			D3DLOCKED_RECT lockedRect;
			V(m_object->LockRect(i, &lockedRect, 0, 0));
			int mypitch = m_format.calculateDataSize(width, 1);
			if (mypitch != lockedRect.Pitch) {
				Errorf("mypitch != lockedRect.Pitch");
			}
			memcpy(lockedRect.pBits, data, datasize);
			V(m_object->UnlockRect(i));
#endif
			width >>= 1;
			height >>= 1;
			if (width < 1) width = 1;
			if (height < 1) height = 1;

			if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
//				break;
			}
		}

		if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) {
			generateMipmap();
		}

		if (m_isMipmaped) {
			setFilterMode(FM_Trilinear);
		} else {
			setFilterMode(FM_Linear);
		}

		setClampMode(CM_Repeat);

		setPrivateData();

		g_statistic->addValue(stat_textureMemory, m_videoMemoryUsed);

		return true;
	}
/// Load a texture from a proper DDSFile instance.
bool GFXD3D9TextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
{
   PROFILE_SCOPE(GFXD3D9TextureManager_loadTextureDDS);

   GFXD3D9TextureObject *texture = static_cast<GFXD3D9TextureObject*>(aTexture);

   // Fill the texture...
   for( int i = 0; i < aTexture->mMipLevels; i++ )
   {
      PROFILE_SCOPE(GFXD3DTexMan_loadSurface);

      LPDIRECT3DSURFACE9 surf = NULL;
      D3D9Assert(texture->get2DTex()->GetSurfaceLevel( i, &surf ), "Failed to get surface");

#if defined(TORQUE_OS_XENON)
      XGTEXTURE_DESC surfDesc;
      dMemset(&surfDesc, 0, sizeof(XGTEXTURE_DESC));
      XGGetSurfaceDesc(surf, &surfDesc);

      RECT srcRect;
      srcRect.top = srcRect.left = 0;
      srcRect.bottom = dds->getHeight(i);
      srcRect.right = dds->getWidth(i);

      D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i],
         (D3DFORMAT)MAKELINFMT(GFXD3D9TextureFormat[dds->mFormat]), dds->getSurfacePitch(i), 
         NULL, &srcRect, false, 0, 0, D3DX_FILTER_NONE, 0);
#else

      GFXD3D9Device* dev = static_cast<GFXD3D9Device *>(GFX);

      if (dev->isD3D9Ex())
      {
         RECT r;
         r.top = r.left = 0;
         r.bottom = dds->getHeight(i);
         r.right = dds->getWidth(i);
         D3DXLoadSurfaceFromMemory(surf, NULL, NULL, dds->mSurfaces[0]->mMips[i], GFXD3D9TextureFormat[dds->mFormat], dds->getSurfacePitch(i), NULL, &r, D3DX_DEFAULT, 0);
      }
      else
      {
         D3DLOCKED_RECT lockedRect;
         D3D9Assert( surf->LockRect( &lockedRect, NULL, 0 ), "Failed to lock surface level for load" );

         AssertFatal( dds->mSurfaces.size() > 0, "Assumption failed. DDSFile has no surfaces." );

         if ( dds->getSurfacePitch( i ) != lockedRect.Pitch )
         {
            // Do a row-by-row copy.
            U32 srcPitch = dds->getSurfacePitch( i );
            U32 srcHeight = dds->getHeight();
            U8* srcBytes = dds->mSurfaces[0]->mMips[i];
            U8* dstBytes = (U8*)lockedRect.pBits;
            for (U32 i = 0; i<srcHeight; i++)          
            {
               dMemcpy( dstBytes, srcBytes, srcPitch );
               dstBytes += lockedRect.Pitch;
               srcBytes += srcPitch;
            }           
            surf->UnlockRect();
            surf->Release();

            return true;
         }

         dMemcpy( lockedRect.pBits, dds->mSurfaces[0]->mMips[i], dds->getSurfaceSize(i) );

         surf->UnlockRect();
      }
#endif

      surf->Release();
   }

   return true;
}
//-----------------------------------------------------------------------------
// loadTexture - GBitmap
//-----------------------------------------------------------------------------
bool GFXD3D9TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL)
{
   PROFILE_SCOPE(GFXD3D9TextureManager_loadTexture);

   GFXD3D9TextureObject *texture = static_cast<GFXD3D9TextureObject*>(aTexture);

#ifdef TORQUE_OS_XENON
   // If the texture is currently bound, it needs to be unbound before modifying it
   if( texture->getTex() && texture->getTex()->IsSet( mD3DDevice ) )
   {
      mD3DDevice->SetTexture( 0, NULL );
      mD3DDevice->SetTexture( 1, NULL );
      mD3DDevice->SetTexture( 2, NULL );
      mD3DDevice->SetTexture( 3, NULL );
      mD3DDevice->SetTexture( 4, NULL );
      mD3DDevice->SetTexture( 5, NULL );
      mD3DDevice->SetTexture( 6, NULL );
      mD3DDevice->SetTexture( 7, NULL );
   }
#endif

   // Check with profiler to see if we can do automatic mipmap generation.
   const bool supportsAutoMips = GFX->getCardProfiler()->queryProfile("autoMipMapLevel", true);

   // Helper bool
   const bool isCompressedTexFmt = aTexture->mFormat >= GFXFormatDXT1 && aTexture->mFormat <= GFXFormatDXT5;

   GFXD3D9Device* dev = static_cast<GFXD3D9Device *>(GFX);

   // Settings for mipmap generation
   U32 maxDownloadMip = pDL->getNumMipLevels();
   U32 nbMipMapLevel  = pDL->getNumMipLevels();

   if( supportsAutoMips && !isCompressedTexFmt )
   {
      maxDownloadMip = 1;
      nbMipMapLevel  = aTexture->mMipLevels;
   }

   // Fill the texture...
   for( int i = 0; i < maxDownloadMip; i++ )
   {
      LPDIRECT3DSURFACE9 surf = NULL;
      D3D9Assert(texture->get2DTex()->GetSurfaceLevel( i, &surf ), "Failed to get surface");

      D3DLOCKED_RECT lockedRect;

#ifdef TORQUE_OS_XENON
      // On the 360, doing a LockRect doesn't work like it does with untiled memory
      // so instead swizzle into some temporary memory, and then later use D3DX
      // to do the upload properly.
      FrameTemp<U8> swizzleMem(pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel());
      lockedRect.pBits = (void*)~swizzleMem;
#else
      U32 waterMark = 0;
      if (!dev->isD3D9Ex())
         surf->LockRect( &lockedRect, NULL, 0 );
      else
      {
         waterMark = FrameAllocator::getWaterMark();
         lockedRect.pBits = static_cast<void*>(FrameAllocator::alloc(pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel()));
      }
#endif
      
      switch( texture->mFormat )
      {
      case GFXFormatR8G8B8:
         {
            PROFILE_SCOPE(Swizzle24_Upload);
            AssertFatal( pDL->getFormat() == GFXFormatR8G8B8, "Assumption failed" );
            GFX->getDeviceSwizzle24()->ToBuffer( lockedRect.pBits, pDL->getBits(i), 
               pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() );
         }
         break;

      case GFXFormatR8G8B8A8:
      case GFXFormatR8G8B8X8:
         {
            PROFILE_SCOPE(Swizzle32_Upload);
            GFX->getDeviceSwizzle32()->ToBuffer( lockedRect.pBits, pDL->getBits(i), 
               pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() );
         }
         break;

      default:
         {
            // Just copy the bits in no swizzle or padding
            PROFILE_SCOPE(SwizzleNull_Upload);
            AssertFatal( pDL->getFormat() == texture->mFormat, "Format mismatch" );
            dMemcpy( lockedRect.pBits, pDL->getBits(i), 
               pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel() );
         }
      }

#ifdef TORQUE_OS_XENON
      RECT srcRect;
      srcRect.bottom = pDL->getHeight(i);
      srcRect.top = 0;
      srcRect.left = 0;
      srcRect.right = pDL->getWidth(i);

      D3DXLoadSurfaceFromMemory(surf, NULL, NULL, ~swizzleMem, (D3DFORMAT)MAKELINFMT(GFXD3D9TextureFormat[pDL->getFormat()]),
         pDL->getWidth(i) * pDL->getBytesPerPixel(), NULL, &srcRect, false, 0, 0, D3DX_FILTER_NONE, 0);
#else
      if (!dev->isD3D9Ex())
         surf->UnlockRect();
      else
      {
         RECT srcRect;
         srcRect.top = 0;
         srcRect.left = 0;
         srcRect.right = pDL->getWidth(i);
         srcRect.bottom = pDL->getHeight(i);
         D3DXLoadSurfaceFromMemory(surf, NULL, NULL, lockedRect.pBits, GFXD3D9TextureFormat[pDL->getFormat()], pDL->getBytesPerPixel() * pDL->getWidth(i), NULL, &srcRect, D3DX_DEFAULT, 0);
         FrameAllocator::setWaterMark(waterMark);
      }
#endif
      
      surf->Release();
   }

   return true;          
}
Example #12
0
/*
==================
Creates a texture
==================
*/
IDirect3DTexture9 *IND_SurfaceManager::CreateTexture	(byte *pImage,
        int pBlockWidth,
        int pBlockHeight,
        int pSrcBpp,
        D3DFORMAT pSrcFormat,
        D3DFORMAT pDstFormat)
{
    HRESULT mHr;

    IDirect3DTexture9 *mNewTexture;

    // ----- Texture creation -----

    mHr = D3DXCreateTexture	(mRender->GetDevice(),
                             pBlockWidth,
                             pBlockHeight,
                             1,
                             0,
                             pDstFormat,
                             D3DPOOL_MANAGED,
                             &mNewTexture);

    if (FAILED (mHr))
    {
        Debug->Header ("Error creating the texture", 2);
        exit (0); // TODO: Free objects?
    }

    // ----- D3D Surface creation -----

    IDirect3DSurface9 *mSurface;

    // The surfaces points to the texture
    mHr = mNewTexture->GetSurfaceLevel (0, &mSurface);
    if (FAILED (mHr))
    {
        Debug->Header ("Error creating the surface", 2);
        exit (0); // TODO: free objects
    }

    // ----- Add the source image into the surface -----

    // Source image
    RECT mSrcRect;
    mSrcRect.left		= 0;
    mSrcRect.top		= 0;
    mSrcRect.right		= pBlockWidth;
    mSrcRect.bottom		= pBlockHeight;

    mHr = D3DXLoadSurfaceFromMemory (mSurface,
                                     0,
                                     0,
                                     pImage,
                                     pSrcFormat,
                                     pBlockWidth * pSrcBpp,
                                     0,
                                     &mSrcRect,
                                     D3DX_FILTER_NONE,
                                     0);

    if (FAILED (mHr))
    {
        Debug->Header ("Error loading the block to the surface", 2);
        exit (0); // TODO: free objects
    }

    // Free memory
    mSurface->Release();

    return mNewTexture;
}
/*
==================
Creates a texture
==================
*/
IDirect3DTexture9 *DirectXTextureBuilder::createTexture(BYTE *pImage,
        int pBlockWidth,
        int pBlockHeight,
        int pSrcBpp,
        D3DFORMAT pSrcFormat,
        D3DFORMAT pDstFormat) {
	HRESULT mHr;

	IDirect3DTexture9 *mNewTexture;

	// ----- Texture creation -----

	LPDIRECT3DDEVICE9 d3ddeviceptr = _render->_wrappedRenderer->GetDevice();  //Here we break encapsulation with frienship to access internal ptr!!!
	mHr = D3DXCreateTexture(d3ddeviceptr,
	                        pBlockWidth,
	                        pBlockHeight,
	                        1,
	                        0,
	                        pDstFormat,
	                        D3DPOOL_MANAGED,
	                        &mNewTexture);

	if (FAILED(mHr)) {
		g_debug->header("Error creating the texture", 2);
		exit(0);  // TODO: Free objects?
	}

	// ----- D3D Surface creation -----

	IDirect3DSurface9 *_surface;

	// The surfaces points to the texture
	mHr = mNewTexture->GetSurfaceLevel(0, &_surface);
	if (FAILED(mHr)) {
		g_debug->header("Error creating the surface", 2);
		exit(0);  // TODO: free objects
	}

	// ----- Add the source image into the surface -----

	// Source image
	RECT mSrcRect;
	mSrcRect.left       = 0;
	mSrcRect.top        = 0;
	mSrcRect.right      = pBlockWidth;
	mSrcRect.bottom     = pBlockHeight;

	mHr = D3DXLoadSurfaceFromMemory(_surface,
	                                0,
	                                0,
	                                pImage,
	                                pSrcFormat,
	                                pBlockWidth * pSrcBpp,
	                                0,
	                                &mSrcRect,
	                                D3DX_FILTER_NONE,
	                                0);

	if (FAILED(mHr)) {
		g_debug->header("Error loading the block to the surface", 2);
		exit(0);  // TODO: free objects
	}

	// Free memory
	_surface->Release();

	return mNewTexture;
}