Exemplo n.º 1
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.º 2
0
void HackerContext::FrameAnalysisClearUAV(ID3D11UnorderedAccessView *uav)
{
	UINT values[4] = {0,0,0,0};
	ID3D11Resource *resource = NULL;

	// FIXME: Do this before each draw/dispatch call instead of when UAVs
	// are assigned to fix assigned render targets not being cleared, and
	// work better with frame analysis triggers

	if (!(G->cur_analyse_options & FrameAnalysisOptions::CLEAR_RT))
		return;

	// Use the address of the resource rather than the view to determine if
	// we have seen it before so we don't clear a render target that is
	// simply used as several different types of views:
	uav->GetResource(&resource);
	if (!resource)
		return;
	resource->Release(); // Don't need the object, only the address

	if (G->frame_analysis_seen_rts.count(resource))
		return;
	G->frame_analysis_seen_rts.insert(resource);

	mOrigContext->ClearUnorderedAccessViewUint(uav, values);
}
Exemplo n.º 3
0
	void screenshot(const string& name)
	{
#ifndef WINSTORE_SUPPORT
		CreateDirectoryA("screenshots", 0);
		time_t t = std::time(nullptr);
		struct tm time_info;
		localtime_s(&time_info, &t);
		stringstream ss("");
		if (name.length() <= 0)
			ss << "screenshots/sc_" << std::put_time(&time_info, "%d-%m-%Y %H-%M-%S") << ".png";
		else
			ss << name;
		wstringstream wss(L"");
		wss << ss.str().c_str();
		ID3D11Resource* res = nullptr;
		wiRenderer::renderTargetView->GetResource(&res);
		HRESULT h = SaveWICTextureToFile(wiRenderer::immediateContext, res, GUID_ContainerFormatPng, wss.str().c_str());
		if (FAILED(h))
			wiBackLog::post("Screenshot failed");
		else
		{
			ss << " Saved successfully!";
			wiBackLog::post(ss.str().c_str());
		}
		res->Release();
#endif
	}
Exemplo n.º 4
0
void HackerContext::FrameAnalysisClearRT(ID3D11RenderTargetView *target)
{
	FLOAT colour[4] = {0,0,0,0};
	ID3D11Resource *resource = NULL;

	// FIXME: Do this before each draw call instead of when render targets
	// are assigned to fix assigned render targets not being cleared, and
	// work better with frame analysis triggers

	if (!(G->cur_analyse_options & FrameAnalysisOptions::CLEAR_RT))
		return;

	// Use the address of the resource rather than the view to determine if
	// we have seen it before so we don't clear a render target that is
	// simply used as several different types of views:
	target->GetResource(&resource);
	if (!resource)
		return;
	resource->Release(); // Don't need the object, only the address

	if (G->frame_analysis_seen_rts.count(resource))
		return;
	G->frame_analysis_seen_rts.insert(resource);

	mOrigContext->ClearRenderTargetView(target, colour);
}
Exemplo n.º 5
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.º 6
0
void MyD3DAssets::loadPSTexture(int textureIndex)
{
    ID3D11ShaderResourceView *view = nullptr;
    context->base->PSGetShaderResources(textureIndex, 1, &view);

    if (view == nullptr)
    {
        PSTexture.free();
    }
    else
    {
        ID3D11Resource *textureResource = nullptr;
        view->GetResource(&textureResource);

        ID3D11Texture2D* texture = nullptr;
        HRESULT hr = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
        if (texture == nullptr || FAILED(hr))
        {
            PSTexture.free();
            g_logger->logErrorFile << "textureResource->QueryInterface failed" << endl;
        }
        else
        {
            readTexture(texture, PSTexture);
            texture->Release();
        }

        textureResource->Release();
        view->Release();
    }
}
Exemplo n.º 7
0
    void initAll(ID3D11Device& device, 
                 ID3D11DeviceContext& context, 
                 ShaderResources& shaderResources)
    {
        assert(shaderResources.mDiffuseMapSRV == nullptr);
        assert(shaderResources.mCSResultsSRV == nullptr);
        assert(shaderResources.mCSResultsUAV == nullptr);

        ID3D11Resource* texture = nullptr;

        //
        // Diffuse Map
        //
        HRESULT result = CreateDDSTextureFromFile(&device, 
            L"Resources/Textures/brick.dds", 
            &texture, 
            &shaderResources.mDiffuseMapSRV);
        DxErrorChecker(result);  
        
        texture->Release();

        //
        // Create compute shader texture
        //        
        D3D11_TEXTURE2D_DESC groupResultsTexDesc;
        groupResultsTexDesc.Width = 512;
        groupResultsTexDesc.Height = 512;
        groupResultsTexDesc.MipLevels = 1;
        groupResultsTexDesc.ArraySize = 1;
        groupResultsTexDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
        groupResultsTexDesc.SampleDesc.Count   = 1;
        groupResultsTexDesc.SampleDesc.Quality = 0;
        groupResultsTexDesc.Usage = D3D11_USAGE_DEFAULT;
        groupResultsTexDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
        groupResultsTexDesc.CPUAccessFlags = 0;
        groupResultsTexDesc.MiscFlags = 0;

        ID3D11Texture2D* groupResultsTex = nullptr;
        assert(Globals::gDirect3DData.mDevice);
        result = device.CreateTexture2D(&groupResultsTexDesc, 0, &groupResultsTex);
        DxErrorChecker(result);

        D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
        srvDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
        srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
        srvDesc.Texture2D.MostDetailedMip = 0;
        srvDesc.Texture2D.MipLevels = 1;
        result = device.CreateTexture2D(&groupResultsTexDesc, 0, &groupResultsTex);
        result = device.CreateShaderResourceView(groupResultsTex, &srvDesc, &shaderResources.mCSResultsSRV);

        D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
        uavDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
        uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
        uavDesc.Texture2D.MipSlice = 0;
        result = device.CreateUnorderedAccessView(groupResultsTex, &uavDesc, &shaderResources.mCSResultsUAV);

        // Views save a reference to the texture so we can release our reference.
        groupResultsTex->Release();
    }
Exemplo n.º 8
0
void LoadSkybox(ID3D11Device* d3dDevice, LPCWSTR fileName)
{
    ID3D11Resource* resource = 0;
    HRESULT hr;
    hr = D3DX11CreateTextureFromFile(d3dDevice, fileName, 0, 0, &resource, 0);
    assert(SUCCEEDED(hr));

    d3dDevice->CreateShaderResourceView(resource, 0, &gSkyboxSRV);
    resource->Release();
}
Exemplo n.º 9
0
	//-------------------------------------------------------------------------------
	void D3D11RenderSystem::CopyFrameBufferToTexture( D3D11Texture* pTexture )
	{
		ID3D11Resource* pSrcTex = nullptr;
		m_pRenderTargetView->GetResource(&pSrcTex);

		m_pDeviceContext->CopyResource(pTexture->GetInternalTex(), pSrcTex);
		pSrcTex->Release();

		pTexture->CreateSRV();
	}
Exemplo n.º 10
0
int32 CGameObject::Initialize()
{
	ApplyShader();

	D3D11_BLEND_DESC blendDesc = {};
	blendDesc.RenderTarget[0].BlendEnable = true;
	blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
	blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	blendDesc.RenderTarget[0].RenderTargetWriteMask = 0x0F;

	float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

	theDevice->CreateBlendState( &blendDesc, &m_alphaBlendState );
	theContext->OMSetBlendState( m_alphaBlendState, blendFactor, 0xFFFFFFFF );

	D3D11_SAMPLER_DESC samplerDesc = {};
	samplerDesc.AddressU = samplerDesc.AddressV = samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	//	samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
	//	samplerDesc.MaxAnisotropy = 4;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
	HR( theDevice->CreateSamplerState( &samplerDesc, &m_pTextureSampler ) );

	ID3D11Resource* pcolorTex = 00;
	m_material.GetDiffuse()->GetResource( &pcolorTex );

	D3D11_TEXTURE2D_DESC colorTexDesc = {};
	(reinterpret_cast<ID3D11Texture2D*>(pcolorTex))->GetDesc( &colorTexDesc );
	pcolorTex->Release();

	BuildBuffers();

	D3D11_SAMPLER_DESC colorMapDesc = {};
	colorMapDesc.AddressU = colorMapDesc.AddressV = colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	//	colorMapDesc.Filter = D3D11_FILTER_ANISOTROPIC;
	//	colorMapDesc.MaxAnisotropy = 4;
	colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX;
	HR( theDevice->CreateSamplerState( &colorMapDesc, &m_pTextureSampler ) );

	m_pFXWorld = m_effect->GetVariableByName( "gWorld" )->AsMatrix();
	m_pFXTexture = m_effect->GetVariableByName( "gTexture" )->AsShaderResource();
	m_pFXTextureSampler = m_effect->GetVariableByName( "gTextureSampler" )->AsSampler();

	return 0;
}
Exemplo n.º 11
0
bool  xD11BaseTexture::saveToFile(const wchar_t* fileName)
{
	D3DX11_IMAGE_FILE_FORMAT fFormat = xD11ConstLexer::GetDX11ImageFileFormat(fileName);
	if((int)fFormat == -1)
		return false;

	ID3D11Resource* pResource = this->GetD11Resource();
	if(pResource == NULL)
		return false;

	HRESULT hr = D3DX11SaveTextureToFileW(m_pD11RenderApi->d11DeviceContext() ,  pResource ,  fFormat , fileName);
	pResource->Release();
	return SUCCEEDED(hr);
}
Exemplo n.º 12
0
HRESULT LoadSkyboxFromFile(LPCSTR file, ID3D11Device* pd3dDevice)
{

	HRESULT hr;
		
	D3DX11_IMAGE_INFO SrcInfo;
	hr = D3DX11GetImageInfoFromFile(file, NULL, &SrcInfo, NULL);

	D3DX11_IMAGE_LOAD_INFO texLoadInfo;
	texLoadInfo.Width          = SrcInfo.Width;
	texLoadInfo.Height         = SrcInfo.Height;
	texLoadInfo.Depth          = SrcInfo.Depth;
	texLoadInfo.FirstMipLevel  = 0;
	texLoadInfo.MipLevels      = SrcInfo.MipLevels;
	texLoadInfo.Usage          = D3D11_USAGE_DEFAULT;
	texLoadInfo.BindFlags      = D3D11_BIND_SHADER_RESOURCE;
	texLoadInfo.CpuAccessFlags = 0;
	texLoadInfo.MiscFlags      = SrcInfo.MiscFlags;
	texLoadInfo.Format         = SrcInfo.Format;
	texLoadInfo.Filter         = D3DX11_FILTER_TRIANGLE;
	texLoadInfo.MipFilter      = D3DX11_FILTER_TRIANGLE;
	texLoadInfo.pSrcInfo       = &SrcInfo;
	ID3D11Resource *pRes = NULL;

	D3DX11CreateTextureFromFile(pd3dDevice, file, &texLoadInfo, NULL, &pRes, NULL);
	if (pRes)
	{
		ID3D11Texture2D* texture;

		pRes->QueryInterface(__uuidof(ID3D11Texture2D), (LPVOID*)&texture);
		D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
		ZeroMemory(&SRVDesc, sizeof(SRVDesc));
		SRVDesc.Format = texLoadInfo.Format;
		SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
		SRVDesc.Texture2D.MostDetailedMip = 0;
		SRVDesc.Texture2D.MipLevels = texLoadInfo.MipLevels;

		ID3D11ShaderResourceView* textureRview;
		pd3dDevice->CreateShaderResourceView(texture, &SRVDesc, &textureRview);

		g_Skybox.OnD3D11CreateDevice(pd3dDevice, 1, texture, textureRview);

		// Sky box class holds references.
		//SAFE_RELEASE(texture);
		//SAFE_RELEASE(textureRview);
	}

	SAFE_RELEASE(pRes);
	return S_OK;
}
Exemplo n.º 13
0
void Tiles::Init(ID3D11Device* dev, std::wstring fileName, XMFLOAT2 tileSize)
{
	ID3D11Resource*  resource = 0;
	ID3D11Texture2D* texture2D = 0;

	dev_ = dev;
	D3DX11CreateShaderResourceViewFromFile(dev, fileName.c_str(), NULL, NULL, &texture_, NULL);

	texture_->GetResource(&resource);
	resource->QueryInterface(&texture2D);
	D3D11_TEXTURE2D_DESC desc;
	texture2D->GetDesc(&desc);
	TextureHeight = desc.Height / tileSize.y;
	TextureWidth = desc.Width / tileSize.x;
}
void FD3D12CommandContext::CheckIfSRVIsResolved(FD3D12ShaderResourceView* SRV)
{
	// MSFT: Seb: TODO: Make this work on 12
#if CHECK_SRV_TRANSITIONS
	if (GRHIThread || !SRV)
	{
		return;
	}

	static const auto CheckSRVCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.CheckSRVTransitions"));
	if (!CheckSRVCVar->GetValueOnRenderThread())
	{
		return;
	}

	ID3D11Resource* SRVResource = nullptr;
	SRV->GetResource(&SRVResource);

	int32 MipLevel;
	int32 NumMips;
	int32 ArraySlice;
	int32 NumSlices;
	GetMipAndSliceInfoFromSRV(SRV, MipLevel, NumMips, ArraySlice, NumSlices);

	//d3d uses -1 to mean 'all mips'
	int32 LastMip = MipLevel + NumMips - 1;
	int32 LastSlice = ArraySlice + NumSlices - 1;

	TArray<FUnresolvedRTInfo> RTInfoArray;
	UnresolvedTargets.MultiFind(SRVResource, RTInfoArray);

	for (int32 InfoIndex = 0; InfoIndex < RTInfoArray.Num(); ++InfoIndex)
	{
		const FUnresolvedRTInfo& RTInfo = RTInfoArray[InfoIndex];
		int32 RTLastMip = RTInfo.MipLevel + RTInfo.NumMips - 1;
		ensureMsgf((MipLevel == -1 || NumMips == -1) || (LastMip < RTInfo.MipLevel || MipLevel > RTLastMip), TEXT("SRV is set to read mips in range %i to %i.  Target %s is unresolved for mip %i"), MipLevel, LastMip, *RTInfo.ResourceName.ToString(), RTInfo.MipLevel);
		ensureMsgf(NumMips != -1, TEXT("SRV is set to read all mips.  Target %s is unresolved for mip %i"), *RTInfo.ResourceName.ToString(), RTInfo.MipLevel);

		int32 RTLastSlice = RTInfo.ArraySlice + RTInfo.ArraySize - 1;
		ensureMsgf((ArraySlice == -1 || LastSlice == -1) || (LastSlice < RTInfo.ArraySlice || ArraySlice > RTLastSlice), TEXT("SRV is set to read slices in range %i to %i.  Target %s is unresolved for mip %i"), ArraySlice, LastSlice, *RTInfo.ResourceName.ToString(), RTInfo.ArraySlice);
		ensureMsgf(ArraySlice == -1 || NumSlices != -1, TEXT("SRV is set to read all slices.  Target %s is unresolved for slice %i"));
	}
	SRVResource->Release();
#endif
}
Exemplo n.º 15
0
void Entity::LoadTexture(ID3D11Device* device , std::wstring texFilename)
{
	HR(D3DX11CreateShaderResourceViewFromFile(device, texFilename.c_str(), 0, 0, &mTexSRV, 0));
	
	//GRAB TEXTURES WIDTH AND HEIGHT .. USED LATER FOR ANIMATION PURPOSES
	ID3D11Resource*  resource  = 0;
	ID3D11Texture2D* texture2D = 0;

	mTexSRV->GetResource(&resource);
	resource->QueryInterface(&texture2D);
	D3D11_TEXTURE2D_DESC desc;

	texture2D->GetDesc(&desc);
	mTexWidth = desc.Width;
	mTexHeight = desc.Height;

	ReleaseCOM(resource);
	ReleaseCOM(texture2D);
}
Exemplo n.º 16
0
//-----------------------------------------------------------------------------
CPUTTexture *CPUTTextureDX11::CreateTexture( const cString &name, const cString &absolutePathAndFilename, bool loadAsSRGB )
{
    // TODO:  Delegate to derived class.  We don't currently have CPUTTextureDX11
    ID3D11ShaderResourceView *pShaderResourceView = NULL;
    ID3D11Resource *pTexture = NULL;
    ID3D11Device *pD3dDevice= CPUT_DX11::GetDevice();
    CPUTResult result = CreateNativeTexture( pD3dDevice, absolutePathAndFilename, &pShaderResourceView, &pTexture, loadAsSRGB );
    ASSERT( CPUTSUCCESS(result), _L("Error loading texture: '")+absolutePathAndFilename );

    CPUTTextureDX11 *pNewTexture = new CPUTTextureDX11();
    pNewTexture->mName = name;
    pNewTexture->SetTextureAndShaderResourceView( pTexture, pShaderResourceView );
    pTexture->Release();
    pShaderResourceView->Release();

    CPUTAssetLibrary::GetAssetLibrary()->AddTexture( absolutePathAndFilename, pNewTexture);

    return pNewTexture;
}
Exemplo n.º 17
0
//----------------------------------------------------------------------------//
void Direct3D11Texture::initialiseShaderResourceView()
{
    if (!d_texture)
        return;

    D3D11_TEXTURE2D_DESC tex_desc;
    d_texture->GetDesc(&tex_desc);

    ID3D11Resource* resource = 0;
    d_texture->QueryInterface(__uuidof(ID3D11Resource),
                              reinterpret_cast<LPVOID*>(&resource));

    D3D11_SHADER_RESOURCE_VIEW_DESC srvd;
    srvd.Format = tex_desc.Format;
    srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    srvd.Texture2D.MostDetailedMip = 0;
    srvd.Texture2D.MipLevels = tex_desc.MipLevels;
    d_device.d_device->CreateShaderResourceView(resource, &srvd, &d_resourceView);
    resource->Release();
}
Exemplo n.º 18
0
void HackerContext::DumpUAVs(bool compute)
{
	UINT i;
	NvAPI_Status nvret;
	ID3D11UnorderedAccessView *uavs[D3D11_PS_CS_UAV_REGISTER_COUNT];
	ID3D11Resource *resource;
	wchar_t filename[MAX_PATH];
	HRESULT hr;

	if (analyse_options & FrameAnalysisOptions::STEREO) {
		// Enable reverse stereo blit for all resources we are about to dump:
		nvret = NvAPI_Stereo_ReverseStereoBlitControl(mHackerDevice->mStereoHandle, true);
		if (nvret != NVAPI_OK) {
			LogInfo("DumpStereoResource failed to enable reverse stereo blit\n");
			// Continue anyway, we should still be able to dump in 2D...
		}
	}

	mOrigContext->CSGetUnorderedAccessViews(0, D3D11_PS_CS_UAV_REGISTER_COUNT, uavs);

	for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i) {
		if (!uavs[i])
			continue;

		uavs[i]->GetResource(&resource);
		if (!resource) {
			uavs[i]->Release();
			continue;
		}

		hr = FrameAnalysisFilename(filename, MAX_PATH, compute, true, false, i);
		if (SUCCEEDED(hr))
			DumpResource(resource, filename);

		resource->Release();
		uavs[i]->Release();
	}

	if (analyse_options & FrameAnalysisOptions::STEREO)
		NvAPI_Stereo_ReverseStereoBlitControl(mHackerDevice->mStereoHandle, false);
}
Exemplo n.º 19
0
    void ResourcesManager::initAll(ID3D11Device* device, ID3D11DeviceContext* context)
    {
        assert(device);
        assert(context);

        ID3D11Resource* texture = nullptr;

        // Create grass texture shader resource view
        HRESULT result = CreateDDSTextureFromFile(device, L"Resources/Textures/sand.dds", &texture, &mSandSRV);
        DxErrorChecker(result);  

        // Create sky cube map shader resource view
        result = CreateDDSTextureFromFile(device, L"Resources/Textures/desertcube1024.dds", &texture, &mSkyCubeMapSRV);
        DxErrorChecker(result);  

        // Create sphere diffuse map texture
        result = CreateDDSTextureFromFile(device, L"Resources/Textures/stone.dds", &texture, &mSphereDiffuseMapSRV);
        DxErrorChecker(result);

        texture->Release();
    }
Exemplo n.º 20
0
void Texture2D::Load(D3DRenderer* renderer, const wchar_t* filePath)
{
	ID3D11Resource* textureResource;
	ID3D11ShaderResourceView* textureSRV;

	DirectX::CreateDDSTextureFromFile(renderer->device(), NULL, filePath, &textureResource, &textureSRV);

	if (textureResource == NULL || textureSRV == NULL)
	{
		char errStr[256];
		std::wstring errorPathw(filePath);
		std::string errorPath(errorPathw.begin(), errorPathw.end());

		sprintf(errStr, "Failed to load texture %s.", errorPath.c_str());

		NE_CRITICAL(errStr, "Texture2D");
		return;
	}

	D3D11_RESOURCE_DIMENSION dimension;
	textureResource->GetType(&dimension);

	if (dimension != D3D11_RESOURCE_DIMENSION_TEXTURE2D)
	{
		ReleaseCOM(textureSRV);
		ReleaseCOM(textureResource);

		NE_CRITICAL("Invalid texture dimension.", "Texture2D");
	}

	mpTexture = static_cast<ID3D11Texture2D*>(textureResource);
	mpResourceView = textureSRV;

	D3D11_TEXTURE2D_DESC texDesc;

	mpTexture->GetDesc(&texDesc);//This should just be switched out for a get file data function when I get DirectXTex set up 

	mWidth = texDesc.Width;
	mHeight = texDesc.Height;
}
Exemplo n.º 21
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
Exemplo n.º 22
0
    void ResourcesManager::initAll(ID3D11Device* device, ID3D11DeviceContext* context)
    {
        assert(device);
        assert(context);

        ID3D11Resource* texture = nullptr;

        // Create diffuse and normal maps
        HRESULT result = CreateDDSTextureFromFile(device, L"Resources/Textures/wood1.dds", &texture, &mFloorDiffuseMapSRV);
        DxErrorChecker(result);  
        
        result = CreateDDSTextureFromFile(device, L"Resources/Textures/wood1Normal.dds", &texture, &mFloorNormalMapSRV);
        DxErrorChecker(result);  

        result = CreateDDSTextureFromFile(device, L"Resources/Textures/brick.dds", &texture, &mCylinderDiffuseMapSRV);
        DxErrorChecker(result);

        result = CreateDDSTextureFromFile(device, L"Resources/Textures/brickNormal.dds", &texture, &mCylinderNormalMapSRV);
        DxErrorChecker(result);       

        texture->Release();
    }
void myD3D11DeviceContext::readRenderTarget(Bitmap &result)
{
    ID3D11RenderTargetView *view;
    assets->context->base->OMGetRenderTargets(1, &view, nullptr);

    ID3D11Resource *resource;
    view->GetResource(&resource);

    ID3D11Texture2D *inputTexture;

    HRESULT hr = resource->QueryInterface(__uuidof(ID3D11Texture2D), (void **)&inputTexture);
    if (FAILED(hr))
    {
        g_logger->logErrorFile << "QueryInterface failed to cast to a texture" << endl;
    }
    else
    {
        readTexture(inputTexture, result);
    }

    view->Release();
}
Exemplo n.º 24
0
ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view) 
{
  ID3D11VideoProcessorInputView* inputView = nullptr;
  if (m_context) // we have own context so the view will be processor input view
  {
    inputView = reinterpret_cast<ID3D11VideoProcessorInputView*>(view);
    inputView->AddRef(); // it will be released in Render method

    return inputView;
  }

  // the view came from decoder
  ID3D11VideoDecoderOutputView* decoderView = reinterpret_cast<ID3D11VideoDecoderOutputView*>(view);
  if (!decoderView) 
  {
    CLog::Log(LOGERROR, __FUNCTION__" - cannot get view.");
    return nullptr;
  }

  ID3D11Resource* resource = nullptr;
  D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC vdovd;
  decoderView->GetDesc(&vdovd);
  decoderView->GetResource(&resource);

  D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC vpivd = { 0 };
  vpivd.FourCC = 0; // if zero, the driver uses the DXGI format; must be 0 on level 9.x
  vpivd.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
  vpivd.Texture2D.ArraySlice = vdovd.Texture2D.ArraySlice;
  vpivd.Texture2D.MipSlice = 0;

  if (FAILED(m_pVideoDevice->CreateVideoProcessorInputView(resource, m_pEnumerator, &vpivd, &inputView)))
  {
    CLog::Log(LOGERROR, __FUNCTION__" - cannot create processor view.");
  }
  resource->Release();

  return inputView;
}
Exemplo n.º 25
0
 // ----------------------------------------------------------------------------------------------  
 Texture* TextureLib::LoadEmbeddedTexture(ID3D11Device* device, const wchar_t* name)
 {
     assert(s_Inst != NULL);
     Imple* pImple = s_Inst->m_pImple;

     typedef std::pair<std::wstring, Texture*> NameTexPair;
     const wchar_t* resType = L"Texture";
     HRESULT hr = E_FAIL;

     Texture* tex = NULL;
     ID3D11Resource* dxresource = NULL;
     ID3D11ShaderResourceView* dxTexView = NULL;
     uint32_t  resSize = 0;
     uint8_t* data = (uint8_t*)ResUtil::LoadResource(resType, name, &resSize);
     hr = CreateWICTextureFromMemory(device,
         NULL,
         data,
         resSize,
         &dxresource,
         &dxTexView);
     free(data);
     if (!Logger::IsFailureLog(hr, L"Error loading %s\n", name))
     {
         D3D11_RESOURCE_DIMENSION resDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
         dxresource->GetType(&resDim);
         assert(resDim == D3D11_RESOURCE_DIMENSION_TEXTURE2D);
         ID3D11Texture2D* dxTex = NULL;
         hr = dxresource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&dxTex);
         dxresource->Release();
         assert(dxTex);
         tex = new Texture(dxTex, dxTexView);
         auto insertResult = pImple->m_textures.insert(NameTexPair(name, tex));
         assert(insertResult.second);
     }
     return tex;
 }
Exemplo n.º 26
0
ModelDefinition *ModelFactory::create2D_Model(ID3D11ShaderResourceView *p_Texture)
{
	ModelDefinition *model = new ModelDefinition();
	ID3D11Resource *resource;
	ID3D11Texture2D *texture;
	D3D11_TEXTURE2D_DESC textureDesc;

	p_Texture->GetResource(&resource);
	resource->QueryInterface(&texture);
	texture->GetDesc(&textureDesc);
	Vector2 halfSize(textureDesc.Width * 0.5f, textureDesc.Height * 0.5f);
	SAFE_RELEASE(texture);
	SAFE_RELEASE(resource);
	create2D_VertexBuffer(model, halfSize);

	model->diffuseTexture.push_back(make_pair(std::string("Text"), p_Texture));
	model->materialSets.resize(1);
	model->materialSets[0].first = "default";
	model->materialSets[0].second.push_back(ModelDefinition::Material(0, 6, 0));
	model->is2D = true;
	model->isAnimated = false;

	return model;
}
Exemplo n.º 27
0
ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(CRenderBuffer* view) const
{
  ID3D11VideoProcessorInputView* inputView = nullptr;
  D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC vpivd = { 0, D3D11_VPIV_DIMENSION_TEXTURE2D,{ 0, 0 } };

  if (view->format == BUFFER_FMT_D3D11_BYPASS)
  {
    // the view cames from decoder
    ID3D11VideoDecoderOutputView* decoderView = reinterpret_cast<ID3D11VideoDecoderOutputView*>(view->GetHWView());
    if (!decoderView)
    {
      CLog::Log(LOGERROR, "%s: cannot get decoder view.", __FUNCTION__);
      return nullptr;
    }

    ID3D11Resource* resource = nullptr;
    D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC vdovd;
    decoderView->GetDesc(&vdovd);
    decoderView->GetResource(&resource);
    vpivd.Texture2D.ArraySlice = vdovd.Texture2D.ArraySlice;

    if (FAILED(m_pVideoDevice->CreateVideoProcessorInputView(resource, m_pEnumerator, &vpivd, &inputView)))
      CLog::Log(LOGERROR, "%s: cannot create processor input view.", __FUNCTION__);

    resource->Release();
  }
  else if (view->format == BUFFER_FMT_D3D11_NV12
        || view->format == BUFFER_FMT_D3D11_P010
        || view->format == BUFFER_FMT_D3D11_P016)
  {
    if (FAILED(m_pVideoDevice->CreateVideoProcessorInputView(view->GetResource(), m_pEnumerator, &vpivd, &inputView)))
      CLog::Log(LOGERROR, "%s: cannot create processor input view.", __FUNCTION__);
  }

  return inputView;
}
Exemplo n.º 28
0
bool PerlinFire::LoadTexture2D(ID3D11Device * pd3dDevice, LPCWSTR fileName, ID3D11Texture2D ** tex, ID3D11ShaderResourceView ** texRV)
{
	HRESULT hr;
	ID3D11Resource * pRes = NULL;

	D3DX11CreateTextureFromFile( pd3dDevice, fileName, NULL, NULL, &pRes, &hr );

	pRes->QueryInterface( __uuidof(ID3D11Texture2D), (LPVOID*) tex);

	D3D11_TEXTURE2D_DESC desc;
	(*tex)->GetDesc(& desc);

	D3D11_SHADER_RESOURCE_VIEW_DESC descSRV;
	ZeroMemory( &descSRV, sizeof(descSRV) );
	descSRV.Format = desc.Format;
	descSRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	descSRV.Texture2D.MipLevels = desc.MipLevels;

	pd3dDevice->CreateShaderResourceView( *tex, &descSRV, texRV );

	pRes->Release();

	return true;
}
Exemplo n.º 29
0
ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view) 
{
  ID3D11VideoProcessorInputView* inputView = nullptr;
  if (m_eViewType == PROCESSOR_VIEW_TYPE_PROCESSOR)
  {
    inputView = reinterpret_cast<ID3D11VideoProcessorInputView*>(view);
    inputView->AddRef(); // it will be released later
  }
  else if (m_eViewType == PROCESSOR_VIEW_TYPE_DECODER)
  {
    // the view cames from decoder
    ID3D11VideoDecoderOutputView* decoderView = reinterpret_cast<ID3D11VideoDecoderOutputView*>(view);
    if (!decoderView)
    {
      CLog::Log(LOGERROR, "%s - cannot get view.", __FUNCTION__);
      return nullptr;
    }

    ID3D11Resource* resource = nullptr;
    D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC vdovd;
    decoderView->GetDesc(&vdovd);
    decoderView->GetResource(&resource);

    D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC vpivd = { { 0 } };
    vpivd.FourCC = 0;
    vpivd.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
    vpivd.Texture2D.ArraySlice = vdovd.Texture2D.ArraySlice;
    vpivd.Texture2D.MipSlice = 0;

    if (FAILED(m_pVideoDevice->CreateVideoProcessorInputView(resource, m_pEnumerator, &vpivd, &inputView)))
      CLog::Log(LOGERROR, "%s - cannot create processor view.", __FUNCTION__);

    resource->Release();
  }
  return inputView;
}
Exemplo n.º 30
0
bool Texture::LoadTexture(const std::wstring& fileName, ID3D11Device* device)
{
	DirectX::CreateWICTextureFromFile(device, fileName.c_str(), nullptr, &mTexture);

	if (mTexture != nullptr)
	{
		ID3D11Resource* res = nullptr;
		ID3D11Texture2D* texture2d = nullptr;
		D3D11_TEXTURE2D_DESC desc;

		mTexture->GetResource(&res);
		res->QueryInterface(&texture2d);
		texture2d->GetDesc(&desc);
		mTextureDimensions.x = (float)desc.Width;
		mTextureDimensions.y = (float)desc.Height;

		ZEPHYR_RELEASEOBJECT(res);
		ZEPHYR_RELEASEOBJECT(texture2d);

		return true;
	}

	return false;
}