Exemplo n.º 1
16
Texture2D::Texture2D( Device& _Device, ID3D11Texture2D& _Texture, const IPixelFormatDescriptor& _Format )
	: Component( _Device )
	, m_Format( _Format )
	, m_bIsDepthStencil( false )
	, m_bIsCubeMap( false )
	, m_pCachedDepthStencilView( NULL )
{
	D3D11_TEXTURE2D_DESC	Desc;
	_Texture.GetDesc( &Desc );

	m_Width = Desc.Width;
	m_Height = Desc.Height;
	m_ArraySize = Desc.ArraySize;
	m_MipLevelsCount = Desc.MipLevels;

	for ( int ShaderStageIndex=0; ShaderStageIndex < 6; ShaderStageIndex++ )
		m_LastAssignedSlots[ShaderStageIndex] = -1;
	m_LastAssignedSlotsUAV = -1;

	m_pTexture = &_Texture;
}
Exemplo n.º 2
0
void ml::D3D11GraphicsDevice::captureBackBufferInternal(Bitmap &result)
{
    ID3D11Texture2D* frameBuffer;

    D3D_VALIDATE(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&frameBuffer));

    D3D11_TEXTURE2D_DESC desc;
    frameBuffer->GetDesc(&desc);

    if(m_captureBuffer == nullptr)
    {
        desc.BindFlags = 0;
        desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
        desc.Usage = D3D11_USAGE_STAGING;
        D3D_VALIDATE(m_device->CreateTexture2D(&desc, nullptr, &m_captureBuffer));
    }

    m_context->CopyResource( m_captureBuffer, frameBuffer );

    result.allocate(desc.Height, desc.Width);
    
    D3D11_MAPPED_SUBRESOURCE resource;
    UINT subresource = D3D11CalcSubresource( 0, 0, 0 );
    HRESULT hr = m_context->Map( m_captureBuffer, subresource, D3D11_MAP_READ_WRITE, 0, &resource );
    const BYTE *data = (BYTE *)resource.pData;
    //resource.pData; // TEXTURE DATA IS HERE

    for( UINT row = 0; row < desc.Height; row++ )
    {
        memcpy( &result(row, 0), data + resource.RowPitch * row, desc.Width * sizeof(RGBColor) );
    }

    m_context->Unmap(m_captureBuffer, subresource);
}
Exemplo n.º 3
0
Vector2f CTextureManager::GetTextureSize( ID3D11ShaderResourceView* aResourceView, bool aNormalize) const
{
	ID3D11Resource* resource = nullptr;
	aResourceView->GetResource(&resource);
	if (!resource)
	{
		return Vector2f(0, 0);
	}
	ID3D11Texture2D* txt = reinterpret_cast<ID3D11Texture2D*>( resource );
	D3D11_TEXTURE2D_DESC desc;
	txt->GetDesc( &desc );

	Vector2f size(static_cast<float>(desc.Width), static_cast<float>(desc.Height));
	resource->Release();

	Vector2<float> windowSize;
	windowSize.x = static_cast<float>(CEngine::GetInstance()->GetWindowSize().y);
	windowSize.y = static_cast<float>(CEngine::GetInstance()->GetWindowSize().y);

	if (aNormalize)
	{
		return size / windowSize;
	}
	return size;
}
Exemplo n.º 4
0
HRESULT getWindowSize(ComPtr<IUnknown>& iWindow, int& width, int& height)
{
	ComPtr<IWinPhone8XamlD3DWindow> iPhoneWindow;
	HRESULT result = getIPhoneXamlWindow(iWindow, &iPhoneWindow);
  
    if (SUCCEEDED(result))
    {
		ID3D11Texture2D* backBuffer;
		result = iPhoneWindow->getBackBuffer(&backBuffer);

		if(SUCCEEDED(result))
		{
			D3D11_TEXTURE2D_DESC backBufferDesc;
			backBuffer->GetDesc(&backBufferDesc);
			width = backBufferDesc.Width;
			height = backBufferDesc.Height;
		}
        backBuffer->Release();
    }
	else
	{
		 winrt::getCurrentWindowDimensions(width, height);
	}

	return result;
}
// テクスチャロード
int LoadTexture( TCHAR *szFileName, TEX_PICTURE *pTexPic, int nWidth, int nHeight,
				 int nTexWidth, int nTexHeight )
{
    HRESULT						hr;
	D3DX11_IMAGE_LOAD_INFO		liLoadInfo;
	ID3D11Texture2D				*pTexture;

	ZeroMemory( &liLoadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );
	liLoadInfo.Width = nTexWidth;
	liLoadInfo.Height = nTexHeight;
	liLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	liLoadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	hr = D3DX11CreateShaderResourceViewFromFile( g_pd3dDevice, szFileName, &liLoadInfo,
												 NULL, &( pTexPic->pSRViewTexture ), NULL );
    if ( FAILED( hr ) ) {
        return hr;
    }
	pTexPic->pSRViewTexture->GetResource( ( ID3D11Resource ** )&( pTexture ) );
	pTexture->GetDesc( &( pTexPic->tdDesc ) );
	pTexture->Release();

	pTexPic->nWidth = nWidth;
	pTexPic->nHeight = nHeight;

	return S_OK;
}
unsigned Texture2D::GetSizeInBytes()
{
    ID3D11Texture2D *texture = GetTexture();
    D3D11_TEXTURE2D_DESC desc;
    texture->GetDesc(&desc);
    return desc.Width * desc.Height * GetFormatSize(desc.Format) * desc.SampleDesc.Count;
}
Exemplo n.º 7
0
void MyD3DAssets::readTexture(ID3D11Texture2D *inputTexture, Bitmap &result)
{
    ID3D11Texture2D *stagingTexture = getStagingTexture(inputTexture);

    D3D11_TEXTURE2D_DESC desc;
    stagingTexture->GetDesc(&desc);
    if (result.getWidth() != desc.Width || result.getHeight() != desc.Height)
        result.allocate(desc.Width, desc.Height);

    for (auto &p : result)
        p.value = ml::vec4uc(50, 100, 150, 255);

    context->base->CopyResource(stagingTexture, inputTexture);

    D3D11_MAPPED_SUBRESOURCE resource;
    UINT subresource = D3D11CalcSubresource(0, 0, 0);
    HRESULT hr = context->base->Map(stagingTexture, subresource, D3D11_MAP_READ, 0, &resource);
    const BYTE *data = (BYTE *)resource.pData;

    for (UINT y = 0; y < desc.Height; y++)
    {
        memcpy(&result(0U, y), data + resource.RowPitch * y, desc.Width * sizeof(ml::vec4uc));
    }

    context->base->Unmap(stagingTexture, subresource);
}
Exemplo n.º 8
0
HRESULT	D3D11Object::CreateEnvironmentMap( LPCSTR sFileName, ID3D11ShaderResourceView** ppSRV )
{
	HRESULT hr = S_OK;

    ID3D11Resource* pRes = NULL;
    ID3D11Texture2D* pCubeTexture = NULL;
    ID3D11ShaderResourceView* pCubeRV = NULL;

    D3DX11_IMAGE_LOAD_INFO LoadInfo;
    LoadInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;

	D3DX11CreateTextureFromFileA( m_pDevice, sFileName, &LoadInfo, NULL, &pRes, NULL );
    if( pRes )
    {
		printf("Create environment mapping %s\n", sFileName);
        D3D11_TEXTURE2D_DESC desc;
        ZeroMemory( &desc, sizeof( D3D11_TEXTURE2D_DESC ) );
        pRes->QueryInterface( __uuidof( ID3D11Texture2D ), ( LPVOID* )&pCubeTexture );
        pCubeTexture->GetDesc( &desc );
        SAFE_RELEASE( pRes );

        D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
        ZeroMemory( &SRVDesc, sizeof( SRVDesc ) );
        SRVDesc.Format = desc.Format;
        SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
        SRVDesc.TextureCube.MipLevels = desc.MipLevels;
        SRVDesc.TextureCube.MostDetailedMip = 0;
		hr = m_pDevice->CreateShaderResourceView( pCubeTexture, &SRVDesc, ppSRV );
    }

	return hr;
}
Exemplo n.º 9
0
	// ********************************************************************* //
	// Fill this rendertarget with an already existing resources.
	RenderTarget::RenderTarget( ID3D11RenderTargetView* _targetView,
					ID3D11DepthStencilView* _depthStencil,
					uint _flags ) :
		m_textureView(nullptr),
		m_DSTextureView(nullptr),
		m_targetView(_targetView),
		m_depthBufferRef(_depthStencil),
		m_lastTextureSlot(0xffffffff),
		m_DSLastTextureSlot(0xffffffff)
	{
		Assert((_targetView!=nullptr) ^ ((_flags & CREATION_FLAGS::NO_TARGET) == CREATION_FLAGS::NO_TARGET));
		Assert((_depthStencil!=nullptr) ^ ((_flags & CREATION_FLAGS::NO_DEPTH) == CREATION_FLAGS::NO_DEPTH));

		// Not implemented, yet...
		Assert( (_flags & CREATION_FLAGS::DEPTH_TEXTURE_VIEW) != CREATION_FLAGS::DEPTH_TEXTURE_VIEW );
		Assert( (_flags & CREATION_FLAGS::TARGET_TEXTURE_VIEW) != CREATION_FLAGS::TARGET_TEXTURE_VIEW );

		ID3D11Texture2D* pTex;
		_targetView->GetResource( (ID3D11Resource**)&pTex );
		D3D11_TEXTURE2D_DESC Desc;
		pTex->GetDesc( &Desc );
		pTex->Release();
		
		CreateViewPort( Desc.Width, Desc.Height );
	}
Exemplo n.º 10
0
static bool grabFrameD3D11(IDXGISwapChain *swap)
{
  ID3D11Device *device = 0;
  ID3D11DeviceContext *context = 0;
  ID3D11Texture2D *tex = 0, *captureTex = 0;

  if (FAILED(swap->GetBuffer(0, IID_ID3D11Texture2D, (void**)&tex)))
    return false;

  D3D11_TEXTURE2D_DESC desc;
  tex->GetDevice(&device);
  tex->GetDesc(&desc);

  // re-creating the capture staging texture each frame is definitely not the most efficient
  // way to handle things, but it frees me of all kind of resource management trouble, so
  // here goes...
  desc.MipLevels = 1;
  desc.ArraySize = 1;
  desc.SampleDesc.Count = 1;
  desc.SampleDesc.Quality = 0;
  desc.Usage = D3D11_USAGE_STAGING;
  desc.BindFlags = 0;
  desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
  desc.MiscFlags = 0;

  if(FAILED(device->CreateTexture2D(&desc,0,&captureTex)))
    printLog("video/d3d11: couldn't create staging texture for gpu->cpu download!\n");
  else
    setCaptureResolution(desc.Width,desc.Height);

  device->GetImmediateContext(&context);
  context->CopySubresourceRegion(captureTex,0,0,0,0,tex,0,0);

  D3D11_MAPPED_SUBRESOURCE mapped;
  bool grabOk = false;

  if(captureTex && SUCCEEDED(context->Map(captureTex,0,D3D11_MAP_READ,0,&mapped)))
  {
    switch(desc.Format)
    {
    case DXGI_FORMAT_R8G8B8A8_UNORM:
      blitAndFlipRGBAToCaptureData((unsigned char *) mapped.pData,mapped.RowPitch);
      grabOk = true;
      break;

    default:
      printLog("video/d3d11: unsupported backbuffer format, can't grab pixels!\n");
      break;
    }

    context->Unmap(captureTex,0);
  }

  tex->Release();
  if(captureTex) captureTex->Release();
  context->Release();
  device->Release();

  return grabOk;
}
Exemplo n.º 11
0
void Renderer::createRenderTarget() {
	ID3D11Texture2D* backBuffer;
	m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**) &backBuffer);
	m_device->CreateRenderTargetView(backBuffer, nullptr, &m_renderTargetView);

	backBuffer->GetDesc(&m_backBufferDesc);
	backBuffer->Release();
}
Exemplo n.º 12
0
void GFXD3D11TextureTarget::attachTexture( RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel/*=0*/ )
{
   GFXDEBUGEVENT_SCOPE( GFXPCD3D11TextureTarget_attachTexture_Cubemap, ColorI::RED );

   AssertFatal(slot < MaxRenderSlotId, "GFXD3D11TextureTarget::attachTexture - out of range slot.");

   // Mark state as dirty so device can know to update.
   invalidateState();

   // Release what we had, it's definitely going to change.
   SAFE_RELEASE(mTargetViews[slot]);
   SAFE_RELEASE(mTargets[slot]);
   SAFE_RELEASE(mTargetSRViews[slot]);

   mResolveTargets[slot] = NULL;

   // Cast the texture object to D3D...
   AssertFatal(!tex || static_cast<GFXD3D11Cubemap*>(tex), "GFXD3DTextureTarget::attachTexture - invalid cubemap object.");

   if(slot == Color0)
   {
      mTargetSize = Point2I::Zero;
      mTargetFormat = GFXFormatR8G8B8A8;
   }

   // Are we clearing?
   if(!tex)
   {
      // Yup - just exit, it'll stay NULL.      
      return;
   }

   GFXD3D11Cubemap *cube = static_cast<GFXD3D11Cubemap*>(tex);

   mTargets[slot] = cube->get2DTex();
   mTargets[slot]->AddRef();
   mTargetViews[slot] = cube->getRTView(face);
   mTargetViews[slot]->AddRef();
   mTargetSRViews[slot] = cube->getSRView();
   mTargetSRViews[slot]->AddRef();
   
   // Update surface size
   if(slot == Color0)
   {
      ID3D11Texture2D *surface = mTargets[Color0];
      if ( surface )
      {
         D3D11_TEXTURE2D_DESC sd;
         surface->GetDesc(&sd);
         mTargetSize = Point2I(sd.Width, sd.Height);

         S32 format = sd.Format;
         GFXREVERSE_LOOKUP( GFXD3D11TextureFormat, GFXFormat, format );
         mTargetFormat = (GFXFormat)format;
      }
   }

}
Exemplo n.º 13
0
Arquivo: gfx.cpp Projeto: amecky/DT
	BYTE* getImageData(ID3D11ShaderResourceView* shaderResourceView,int* nWidth,int*  nHeight) {
		ID3D11Resource* resource = NULL;;
		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;

		if (shaderResourceView)	{
			shaderResourceView->GetResource(&resource);
			shaderResourceView->GetDesc(&srvDesc);
		}
		else {
			return NULL;
		}
		ID3D11Texture2D* tex = (ID3D11Texture2D*)resource;
		if (tex) {
			D3D11_TEXTURE2D_DESC description;
			tex->GetDesc(&description);
			description.BindFlags = 0;
			description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
			description.Usage = D3D11_USAGE_STAGING;

			ID3D11Texture2D* texTemp = NULL;

			HRESULT hr = ctx->device->CreateTexture2D(&description, NULL, &texTemp);
			if (FAILED(hr))	{
				if (texTemp) {
					texTemp->Release();
					texTemp = NULL;
				}
				return NULL;
			}
			ctx->deviceContext->CopyResource(texTemp, tex);

			D3D11_MAPPED_SUBRESOURCE  mapped;
			unsigned int subresource = 0;
			hr = ctx->deviceContext->Map(texTemp, 0, D3D11_MAP_READ, 0, &mapped);
			if (FAILED(hr)) {
				texTemp->Release();
				texTemp = NULL;
				return NULL;
			}

			*nWidth = description.Width;
			*nHeight = description.Height;
			const int pitch = mapped.RowPitch;
			BYTE* source = (BYTE*)(mapped.pData);
			BYTE* dest = new BYTE[(*nWidth)*(*nHeight) * 4];
			BYTE* destTemp = dest;
			for (int i = 0; i < *nHeight; ++i)
			{
				memcpy(destTemp, source, *nWidth * 4);
				source += pitch;
				destTemp += *nWidth * 4;
			}
			ctx->deviceContext->Unmap(texTemp, 0);
			return dest;
		}
		else
			return NULL;
	}
Exemplo n.º 14
0
void GFXD3D11WindowTarget::resolveTo(GFXTextureObject *tex)
{
	GFXDEBUGEVENT_SCOPE(GFXPCD3D11WindowTarget_resolveTo, ColorI::RED);

	D3D11_TEXTURE2D_DESC desc;
	ID3D11Texture2D* surf = ((GFXD3D11TextureObject*)(tex))->get2DTex();
	surf->GetDesc(&desc);
	D3D11DEVICECONTEXT->ResolveSubresource(surf, 0, D3D11->mDeviceBackbuffer, 0, desc.Format);
}
Exemplo n.º 15
0
void FXAA::PreRender(Shader* shader, GraphicsEngineParams engParams)
{
	HRESULT hr = S_OK;

	//get the surface/texture from the swap chain
	ID3D11Texture2D* backBufferTex;
	this->gSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTex);
	
	//get texture description
	D3D11_TEXTURE2D_DESC texDesc;
	backBufferTex->GetDesc(&texDesc);
	
	//change bindflag for use as a shader resource
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 

	//create texture
	ID3D11Texture2D* sceneTex;
	hr = this->gDevice->CreateTexture2D(&texDesc, NULL, &sceneTex);	
	if(FAILED(hr))
	{
		MaloW::Debug("FXAA: Failed to create texture");
	}
	
	//get resource from the render target view of the backbuffer
	ID3D11RenderTargetView* backBufferRTV = NULL;
	this->gDeviceContext->OMGetRenderTargets(1, &backBufferRTV, NULL);
	ID3D11Resource* backBufferRTVResource = NULL;
	backBufferRTV->GetResource(&backBufferRTVResource);

	//copy data from the resource to the scene texture
	this->gDeviceContext->CopyResource(sceneTex, backBufferRTVResource);

	//create shader resource view
	ID3D11ShaderResourceView* sceneSRV;
	hr = this->gDevice->CreateShaderResourceView(sceneTex, NULL, &sceneSRV);
	if(FAILED(hr))
	{
		MaloW::Debug("FXAA: Failed to create shader resource view");
	}

	//set shader variables
	shader->SetResource("sceneTex", sceneSRV);
	shader->SetInt("FXAAPreset", this->mPreset);
	shader->SetFloat4("rcpFrame", D3DXVECTOR4(1.0f / engParams.windowWidth, 1.0f / engParams.windowHeight, 0.0f, 0.0f));
	
	//apply pass
	shader->Apply(0);

	//release
	SAFE_RELEASE(backBufferTex); 
	SAFE_RELEASE(sceneTex);
	SAFE_RELEASE(backBufferRTV);
	SAFE_RELEASE(backBufferRTVResource);
	SAFE_RELEASE(sceneSRV);
}
Exemplo n.º 16
0
	void ColorBuffer::InitializeDisplayBuffer(ID3D11RenderTargetView* renderTarget)
	{
		rtv_ = renderTarget;
		rtv_->GetResource(&resource_);
		ID3D11Texture2D* texture = (ID3D11Texture2D*)resource_;
		D3D11_TEXTURE2D_DESC desc;
		texture->GetDesc(&desc);
		width_ = desc.Width;
		height_ = desc.Height;
		depth_ = desc.ArraySize;
	}
Exemplo n.º 17
0
	void Texture::LoadFromMemory(const void* data, uint32_t size)
	{
		DirectX::CreateDDSTextureFromMemory(GraphicsCore::GetDevice(), reinterpret_cast<const byte*>(data), static_cast<size_t>(size), &resource_, &srv_);
		
		// 2D only
		ID3D11Texture2D* texture = (ID3D11Texture2D*)resource_;
		D3D11_TEXTURE2D_DESC desc;
		texture->GetDesc(&desc);
		width_ = desc.Width;
		height_ = desc.Height;
		depth_ = desc.ArraySize;
	}
Exemplo n.º 18
0
//----------------------------------------------------------------------------
DX11TextureRT::DX11TextureRT(ID3D11Device* device,
    DX11TextureRT const* dxSharedTexture)
    :
    DX11Texture2(dxSharedTexture->GetTexture()),
    mRTView(nullptr)
{
    ID3D11Texture2D* dxShared = dxSharedTexture->CreateSharedDXObject(device);
    mDXObject = dxShared;
    D3D11_TEXTURE2D_DESC desc;
    dxShared->GetDesc(&desc);
    CreateRTView(device, desc);
}
Exemplo n.º 19
0
//-- SetRenderTarget ----------------------------------------------------------
//
//-----------------------------------------------------------------------------
void Renderer::SetRenderTarget(TextureDX* texture)
{
  if (texture == NULL || texture->GetRenderTarget() == NULL)
    return;

  ID3D11Texture2D* pTexture = texture->GetTexture();
  D3D11_TEXTURE2D_DESC txDesc, dtxDesc;
  pTexture->GetDesc(&txDesc);

  ID3D11Resource* pResource = NULL; ID3D11Texture2D* pDepthTexture = NULL;
  g_depthView->GetResource(&pResource);
  pResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pDepthTexture));
  pDepthTexture->GetDesc(&dtxDesc);
  pDepthTexture->Release();
  pResource->Release();

  // depth view dimension must be equals render target dimension
  if (txDesc.Width != dtxDesc.Width || txDesc.Height != dtxDesc.Height)
  {
    SAFE_RELEASE( g_depthView );

    CD3D11_TEXTURE2D_DESC depthBufferDesc(DXGI_FORMAT_D24_UNORM_S8_UINT, txDesc.Width, txDesc.Height, 1, 1, D3D11_BIND_DEPTH_STENCIL);
    m_pD3D11Device->CreateTexture2D(&depthBufferDesc, NULL, &pDepthTexture);

    CD3D11_DEPTH_STENCIL_VIEW_DESC viewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
    m_pD3D11Device->CreateDepthStencilView(pDepthTexture, &viewDesc, &g_depthView);
    pDepthTexture->Release();
  }
  else
    m_pD3D11Contex->ClearDepthStencilView(g_depthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0);

  ID3D11RenderTargetView* rtView = texture->GetRenderTarget();

  // change view port to render target dimension like dx9 does
  CD3D11_VIEWPORT vp(pTexture, rtView);
  m_pD3D11Contex->RSSetViewports(1, &vp);

  m_pD3D11Contex->OMSetRenderTargets(1, &rtView, g_depthView);

} // SetRenderTarget
//-----------------------------------------------------------------------------
void D3D11HardwarePixelBuffer::blitToMemory(const Image::Box &srcBox, const PixelBox &dst)
{
    // Decide on pixel format of temp surface
    PixelFormat tmpFormat = mFormat;
    if(D3D11Mappings::_getPF(dst.format) != DXGI_FORMAT_UNKNOWN)
    {
        tmpFormat = dst.format;
    }
    assert(srcBox.getDepth() == 1 && dst.getDepth() == 1);

    //This is a pointer to the texture we're trying to copy
    //Only implemented for 2D at the moment...
    ID3D11Texture2D *textureResource = mParentTexture->GetTex2D();

    // get the description of the texture
    D3D11_TEXTURE2D_DESC desc = {0};
    textureResource->GetDesc( &desc );
    //Alter the description to set up a staging texture
    desc.Usage = D3D11_USAGE_STAGING;
    //This texture is not bound to any part of the pipeline
    desc.BindFlags = 0;
    //Allow CPU Access
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    //No Misc Flags
    desc.MiscFlags = 0;
    //Create the staging texture
    ID3D11Texture2D* pStagingTexture = NULL;
    mDevice->CreateTexture2D( &desc, NULL, &pStagingTexture );
    //Copy our texture into the staging texture
    mDevice.GetImmediateContext()->CopyResource( pStagingTexture, textureResource );
    //Create a mapped resource and map the staging texture to the resource
    D3D11_MAPPED_SUBRESOURCE mapped = {0};
    mDevice.GetImmediateContext()->Map( pStagingTexture, 0, D3D11_MAP_READ , 0, &mapped );

    // read the data out of the texture.
    unsigned int rPitch = mapped.RowPitch;
    BYTE *data = ((BYTE *)mapped.pData);

    //Using existing OGRE functions
    DXGI_MAPPED_RECT lrect;
    lrect.pBits = data;
    lrect.Pitch = rPitch;


    PixelBox locked(dst.getWidth(), dst.getHeight(), dst.getDepth(), tmpFormat);
    fromD3DLock(locked, lrect);
    PixelUtil::bulkPixelConversion(locked, dst);

    //Release the staging texture
    mDevice.GetImmediateContext()->Unmap( pStagingTexture, 0 );
    pStagingTexture->Release();
}
Exemplo n.º 21
0
void RenderTarget::CreateViewport(ID3D11Texture2D& texture, D3D11_VIEWPORT* viewport) {
    // Set the viewport
    D3D11_TEXTURE2D_DESC textureDesc;
    texture.GetDesc(&textureDesc);
    ZeroMemory(viewport, sizeof(D3D11_VIEWPORT));

    viewport->TopLeftX = 0;
    viewport->TopLeftY = 0;
    viewport->Width = float(textureDesc.Width);
    viewport->Height = float(textureDesc.Height);
    // TODO: make sure these are the same as the values for the zbuffer
    viewport->MinDepth = 0.0f;
    viewport->MaxDepth = 1.0f;
}
Exemplo n.º 22
0
DX11Texture2::DX11Texture2(ID3D11Device* device,
    DX11Texture2 const* dxSharedTexture)
    :
    DX11TextureSingle(dxSharedTexture->GetTexture())
{
    ID3D11Texture2D* dxShared = dxSharedTexture->CreateSharedDXObject(device);
    mDXObject = dxShared;
    D3D11_TEXTURE2D_DESC desc;
    dxShared->GetDesc(&desc);
    CreateSRView(device, desc);
    if (dxSharedTexture->GetTexture()->GetUsage() == Resource::SHADER_OUTPUT)
    {
        CreateUAView(device, desc);
    }
}
Exemplo n.º 23
0
	void Texture::LoadFromFile(const char* fileName)
	{
		wchar_t buffer[255] = { 0 };
		size_t size;
		mbstowcs_s(&size, buffer, fileName, sizeof(buffer));
		auto hr = DirectX::CreateDDSTextureFromFile(GraphicsCore::GetDevice(), buffer, &resource_, &srv_);
		THROW_IF_FAILED(hr);

		// 2D only
		ID3D11Texture2D* texture = (ID3D11Texture2D*)resource_;
		D3D11_TEXTURE2D_DESC desc;
		texture->GetDesc(&desc);
		width_ = desc.Width;
		height_ = desc.Height;
		depth_ = desc.ArraySize;
	}
Exemplo n.º 24
0
XMFLOAT2 const ShaderResourceView::CalPicSize(std::wstring filePath) const
{
	ID3D11ShaderResourceView* pISpriteSRV = GetSRV(filePath);
	ID3D11Texture2D* pISpriteTex;
	float TextureWidth = 0.0f,TextureHeight = 0.0f;

	pISpriteSRV->GetResource( (ID3D11Resource**) &pISpriteTex);
	D3D11_TEXTURE2D_DESC SpriteTexDesc;
	pISpriteTex->GetDesc(&SpriteTexDesc);

	TextureWidth = static_cast<float>(SpriteTexDesc.Width);
	TextureHeight = static_cast<float>(SpriteTexDesc.Height);

	SAFE_RELEASE(pISpriteTex);

	return XMFLOAT2(TextureWidth,TextureHeight);
}
Exemplo n.º 25
0
bool TextureCache::TCacheEntry::Save(const std::string& filename, u32 level)
{
	// TODO: Somehow implement this (D3DX11 doesn't support dumping individual LODs)
	static bool warn_once = true;
	if (level && warn_once)
	{
		WARN_LOG(VIDEO, "Dumping individual LOD not supported by D3D11 backend!");
		warn_once = false;
		return false;
	}

	ID3D11Texture2D* pNewTexture = nullptr;
	ID3D11Texture2D* pSurface = texture->GetTex();
	D3D11_TEXTURE2D_DESC desc;
	pSurface->GetDesc(&desc);
	if (desc.Format != DXGI_FORMAT_R8G8B8A8_UNORM)
	{
		// Do not support compressed texture dump right now
		return false;
	}
	desc.BindFlags = 0;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
	desc.Usage = D3D11_USAGE_STAGING;

	HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &pNewTexture);

	bool saved_png = false;

	if (SUCCEEDED(hr) && pNewTexture)
	{
		D3D::context->CopyResource(pNewTexture, pSurface);

		D3D11_MAPPED_SUBRESOURCE map;
		hr = D3D::context->Map(pNewTexture, 0, D3D11_MAP_READ_WRITE, 0, &map);
		if (SUCCEEDED(hr))
		{
			saved_png = TextureToPng((u8*)map.pData, map.RowPitch, filename, desc.Width, desc.Height);
			D3D::context->Unmap(pNewTexture, 0);
		}
		SAFE_RELEASE(pNewTexture);
	}

	return saved_png;
}
Exemplo n.º 26
0
void App::OnSizeTerrain()
{
	if (!device) return;
	if (!g_pTerrainEffect) return;

	HRESULT hr;
	ID3D11Texture2D* pBackBuffer;
	hr = swapChain->GetBuffer( 0, __uuidof( *pBackBuffer ), ( LPVOID* )&pBackBuffer );
	DXGI_SURFACE_DESC pBBufferSurfaceDesc;
	ZeroMemory( &pBBufferSurfaceDesc, sizeof( DXGI_SURFACE_DESC ) );
	if( SUCCEEDED( hr ) )
	{
		D3D11_TEXTURE2D_DESC TexDesc;
		pBackBuffer->GetDesc( &TexDesc );
		pBBufferSurfaceDesc.Width = ( UINT )TexDesc.Width;
		pBBufferSurfaceDesc.Height = ( UINT )TexDesc.Height;
		pBBufferSurfaceDesc.Format = TexDesc.Format;
		pBBufferSurfaceDesc.SampleDesc = TexDesc.SampleDesc;
		SAFE_RELEASE( pBackBuffer );
	}

	ID3DX11EffectVectorVariable* pScreenSize = g_pTerrainEffect->GetVariableByName("g_screenSize")->AsVector();
	if (pScreenSize)
	{
		D3DXVECTOR2 v((float) pBBufferSurfaceDesc.Width, (float) pBBufferSurfaceDesc.Height);		
		pScreenSize->SetFloatVector(v);
	}

	g_Skybox.OnD3D11ResizedSwapChain(&pBBufferSurfaceDesc);

	unsigned int n = 1;
	context->RSGetViewports(&n, &g_BackBufferVP);

	g_ScreenSize = D3DXVECTOR2((float) pBBufferSurfaceDesc.Width, (float) pBBufferSurfaceDesc.Height);
	float aspectRatio = g_ScreenSize.x / g_ScreenSize.y;

	ActiveCam_->setFOV(RAD2DEG(noMath::PI / 3));
	ActiveCam_->setNear(CLIP_NEAR);
	ActiveCam_->setFar(CLIP_FAR);
	ActiveCam_->SetAspect(aspectRatio);
	ActiveCam_->ComputeProjection();
	
}
Exemplo n.º 27
0
void App::ResizeSNBTerrain()
{
	if (!terrainload_) return;
	if (!device) return;

	HRESULT hr;
	ID3D11Texture2D* pBackBuffer;
	hr = swapChain->GetBuffer( 0, __uuidof( *pBackBuffer ), ( LPVOID* )&pBackBuffer );
	DXGI_SURFACE_DESC pBBufferSurfaceDesc;
	ZeroMemory( &pBBufferSurfaceDesc, sizeof( DXGI_SURFACE_DESC ) );
	if( SUCCEEDED( hr ) )
	{
		D3D11_TEXTURE2D_DESC TexDesc;
		pBackBuffer->GetDesc( &TexDesc );
		pBBufferSurfaceDesc.Width = ( UINT )TexDesc.Width;
		pBBufferSurfaceDesc.Height = ( UINT )TexDesc.Height;
		pBBufferSurfaceDesc.Format = TexDesc.Format;
		pBBufferSurfaceDesc.SampleDesc = TexDesc.SampleDesc;
		SAFE_RELEASE( pBackBuffer );
	}

	float fAspectRatio = pBBufferSurfaceDesc.Width / ( FLOAT )pBBufferSurfaceDesc.Height;
	/*pcamera_->setFOV(RAD2DEG(noMath::PI / 4));
	pcamera_->setNear(CLIP_NEAR);
	pcamera_->setFar(CLIP_FAR);*/
	ActiveCam_->SetAspect(fAspectRatio);
	ActiveCam_->ComputeProjection();

	//g_Camera.SetProjParams( noMath::PI / 4, fAspectRatio, 50.f, 250000.0f );

	g_TerrainDX11Render.OnD3D11ResizedSwapChain( device, swapChain, &pBBufferSurfaceDesc, NULL );

	BaseCamera* pCam = GetApp()->ActiveCam_;
	D3DXMATRIX mProj;
	//D3DXMATRIX mView;

	const unsigned int size16 = sizeof(float) * 16;		 
	//memcpy(&mView, pCam->getViewMatrix(), size16);
	memcpy(&mProj, pCam->getProjectionMatrix(), size16);

	g_TerrainDX11Render.SetViewFrustumParams( pBBufferSurfaceDesc.Width, pBBufferSurfaceDesc.Height, mProj );

}
Exemplo n.º 28
0
	void SetTarget(ID3D11Texture2D* pTarget)
	{
		if (pTarget == this->pTarget)
		{
			return;
		}
		else
		{
			this->pTarget = pTarget;
		}

		D3D11_TEXTURE2D_DESC texDesc;
		pTarget->GetDesc(&texDesc);
		
		sizeX = texDesc.Width; sizeY = texDesc.Height;

		pRenderTargetView = nullptr;
		D3D11_RENDER_TARGET_VIEW_DESC desc;
		ZeroMemory(&desc, sizeof(desc));
		desc.Format = texDesc.Format;
		desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
		desc.Texture2D.MipSlice = 1;
		HRESULT hr = pDevice->CreateRenderTargetView(pTarget,&desc , &pRenderTargetView);
		if (FAILED(hr))
		{
			throw std::exception("CreateRenderTargetView failed.");
		}

		ID3D11RenderTargetView* targets[] = 
		{
			pRenderTargetView
		};
		GetImmediateContext()->OMSetRenderTargets(1,targets, nullptr);

		D3D11_VIEWPORT vps[] = {
			{ 0,0,texDesc.Width,texDesc.Height,0,1 }
		};		
		GetImmediateContext()->RSSetViewports(1, vps);

		float const clearColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
		GetImmediateContext()->ClearRenderTargetView(pRenderTargetView, clearColor);
	}
void D3D11CanvasWindowGraphics::CreateSwapChainResources()
{
	ID3D11Device* pDevice = m_driver->GetD3D11Device();

	// Get back buffer RTV

	ID3D11Texture2D* texture = NULL;
	CHECK_HR(m_swapChain->GetBuffer(0, IID_PPV_ARGS(&texture)));

	D3D11_TEXTURE2D_DESC t2dd;
	texture->GetDesc(&t2dd);

	CHECK_HR(pDevice->CreateRenderTargetView(texture, NULL, m_backBufferRTV.Receive()));

	SafeRelease(texture);

	// Create Direct2D render target

	m_d2dTarget = D2DTarget::Create(m_driver->GetD2DFactory(),
		pDevice, m_driver->GetD3D10Device(), t2dd.Width, t2dd.Height);
}
Exemplo n.º 30
0
void DxSprite::BeginBatch(ID3D11ShaderResourceView * texSRV)
{
    assert( Initialized );

    BatchTexSRV = texSRV;
    BatchTexSRV->AddRef( );

    ID3D11Resource * resource = 0;
    BatchTexSRV->GetResource(&resource);
    ID3D11Texture2D * tex = reinterpret_cast<ID3D11Texture2D*>(resource);

    D3D11_TEXTURE2D_DESC texDesc;
    tex->GetDesc(&texDesc);

    SAFE_RELEASE(resource)

    TexWidth  = texDesc.Width; 
    TexHeight = texDesc.Height;

    SpriteList.clear( );
}