locked
Screen flickers very fast after displaying a texture and shader resource view

    Question

  • void Renderer::Render()
    {
    	m_d3dContext->ClearRenderTargetView(
    		m_renderTargetView.Get(),
    		Colors::MidnightBlue
    		);
    	
    	
    	m_d3dContext->ClearDepthStencilView(
    		m_depthStencilView.Get(),
    		D3D11_CLEAR_DEPTH,
    		1.0f,
    		0
    		);
    		
    	m_d3dContext->OMSetRenderTargets(
    		1,
    		m_renderTargetView.GetAddressOf(),
    		m_depthStencilView.Get()
    		);
    	
    
    	/////////////////////////////////////////////
    	
    	UINT fred;
    	m_d3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, 16, &fred);
    
    	D3D11_TEXTURE2D_DESC desc;
    	ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
    	desc.ArraySize = 1;
    	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
    	desc.CPUAccessFlags = 0;
    	desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    	desc.MipLevels = 1;
    	desc.MiscFlags = 0;
    	desc.SampleDesc.Count = 1; // 4;
    	desc.SampleDesc.Quality = fred;
    	desc.Usage = D3D11_USAGE_DEFAULT;
    	desc.Width = 1000;
    	desc.Height = 1000;
    	
    
    	ID3D11Texture2D *pTexture = NULL;
    
    
    
    	D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDescription;
    	ZeroMemory(&renderTargetViewDescription, sizeof(renderTargetViewDescription));
    	renderTargetViewDescription.Format = desc.Format;
    	renderTargetViewDescription.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; // MS;
    	
    	D3D11_SUBRESOURCE_DATA tbsd;
    
    	byte *buf = new byte[1000*1000 * 4];
    
    
    	int cx;
    	
    	for (cx = 0; cx <= (1000000*4)-1; cx++)
    		buf[cx] = 255;
    	
    	tbsd.pSysMem = (void *) buf;
    	tbsd.SysMemPitch = 1000 * 4;
    	tbsd.SysMemSlicePitch = 1000*1000 * 4; // Not needed since this is a 2d texture
    
    	if (FAILED(m_d3dDevice->CreateTexture2D(&desc, &tbsd, &pTexture)))
    		return;
    	///////////////////////////////////////////////////////////////////////////////
    	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
    	D3D11_RESOURCE_DIMENSION type;
    	pTexture->GetType(&type);
    
    	pTexture->GetDesc(&desc);
    	srvDesc.Format = desc.Format;
    	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    	srvDesc.Texture2D.MipLevels = desc.MipLevels;
    	srvDesc.Texture2D.MostDetailedMip = desc.MipLevels - 1;
    
    	ID3D11ShaderResourceView *pSRView = NULL;
    	m_d3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &pSRView);
    
    
    	D3D11_RENDER_TARGET_VIEW_DESC rtDesc;
    	rtDesc.Format = desc.Format;
    	rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
    	rtDesc.Texture2D.MipSlice = 0;
    
    	
    	m_d3dDevice->CreateRenderTargetView(pTexture, &rtDesc, &m_renderTargetView);
    	
    
    	// Draw sprite
    	m_sprites->Begin();
    	m_sprites->Draw(pSRView, XMFLOAT2(0, 0), nullptr, Colors::White);
    
    	m_font->DrawString(m_sprites.get(), L"DirectXTK Simple Sample", XMFLOAT2(100, 10), Colors::Red);
    	m_sprites->End();
    
    
    
    
    	///////////////////////////////////////////////////////////////////////////////
    
    		
    		delete [] buf;
    
    
    
    	}
    creatrendertarget view needed to be taken out .

    n.Wright


    Monday, September 16, 2013 4:45 PM

Answers

  • So, is this a question or are you just stating that you figured out a problem and this is the solution?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, September 17, 2013 1:20 PM
    Moderator