src/video/windowsrt/SDL_winrtrenderer.cpp
changeset 8367 df577bb2f2d7
parent 8350 ecc8c88ed82e
child 8369 6dfc4ba22640
     1.1 --- a/src/video/windowsrt/SDL_winrtrenderer.cpp	Sun Nov 25 14:45:22 2012 -0500
     1.2 +++ b/src/video/windowsrt/SDL_winrtrenderer.cpp	Sun Nov 25 17:34:41 2012 -0500
     1.3 @@ -82,48 +82,7 @@
     1.4  			);
     1.5  	});
     1.6  
     1.7 -	auto createMainTextureTask = createCubeTask.then([this] () {
     1.8 -		D3D11_TEXTURE2D_DESC textureDesc = {0};
     1.9 -		textureDesc.Width = (int)m_windowBounds.Width;
    1.10 -		textureDesc.Height = (int)m_windowBounds.Height;
    1.11 -		textureDesc.MipLevels = 1;
    1.12 -		textureDesc.ArraySize = 1;
    1.13 -		textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    1.14 -		textureDesc.SampleDesc.Count = 1;
    1.15 -		textureDesc.SampleDesc.Quality = 0;
    1.16 -		textureDesc.Usage = D3D11_USAGE_DYNAMIC;
    1.17 -		textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    1.18 -		textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    1.19 -		textureDesc.MiscFlags = 0;
    1.20 -
    1.21 -		const int numPixels = (int)m_windowBounds.Width * (int)m_windowBounds.Height;
    1.22 -		std::vector<uint8> initialTexturePixels(numPixels * 4, 0x00);
    1.23 -		D3D11_SUBRESOURCE_DATA initialTextureData = {0};
    1.24 -		initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
    1.25 -		initialTextureData.SysMemPitch = (int)m_windowBounds.Width * 4;
    1.26 -		initialTextureData.SysMemSlicePitch = numPixels * 4;
    1.27 -		DX::ThrowIfFailed(
    1.28 -			m_d3dDevice->CreateTexture2D(
    1.29 -				&textureDesc,
    1.30 -				&initialTextureData,
    1.31 -				&m_mainTexture
    1.32 -				)
    1.33 -			);
    1.34 -
    1.35 -		D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
    1.36 -		resourceViewDesc.Format = textureDesc.Format;
    1.37 -		resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    1.38 -		resourceViewDesc.Texture2D.MostDetailedMip = 0;
    1.39 -		resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
    1.40 -		DX::ThrowIfFailed(
    1.41 -			m_d3dDevice->CreateShaderResourceView(
    1.42 -				m_mainTexture.Get(),
    1.43 -				&resourceViewDesc,
    1.44 -				&m_mainTextureResourceView)
    1.45 -			);
    1.46 -	});
    1.47 -
    1.48 -	auto createMainSamplerTask = createMainTextureTask.then([this] () {
    1.49 +    auto createMainSamplerTask = createCubeTask.then([this] () {
    1.50  		D3D11_SAMPLER_DESC samplerDesc;
    1.51  		samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    1.52  		samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
    1.53 @@ -151,6 +110,48 @@
    1.54  	});
    1.55  }
    1.56  
    1.57 +void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
    1.58 +{
    1.59 +    D3D11_TEXTURE2D_DESC textureDesc = {0};
    1.60 +	textureDesc.Width = w;
    1.61 +	textureDesc.Height = h;
    1.62 +	textureDesc.MipLevels = 1;
    1.63 +	textureDesc.ArraySize = 1;
    1.64 +	textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    1.65 +	textureDesc.SampleDesc.Count = 1;
    1.66 +	textureDesc.SampleDesc.Quality = 0;
    1.67 +	textureDesc.Usage = D3D11_USAGE_DYNAMIC;
    1.68 +	textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    1.69 +	textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    1.70 +	textureDesc.MiscFlags = 0;
    1.71 +
    1.72 +	const int numPixels = textureDesc.Width * textureDesc.Height;
    1.73 +	std::vector<uint8> initialTexturePixels(numPixels * 4, 0x00);
    1.74 +	D3D11_SUBRESOURCE_DATA initialTextureData = {0};
    1.75 +	initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
    1.76 +	initialTextureData.SysMemPitch = textureDesc.Width * 4;
    1.77 +	initialTextureData.SysMemSlicePitch = numPixels * 4;
    1.78 +	DX::ThrowIfFailed(
    1.79 +		m_d3dDevice->CreateTexture2D(
    1.80 +			&textureDesc,
    1.81 +			&initialTextureData,
    1.82 +			&m_mainTexture
    1.83 +			)
    1.84 +		);
    1.85 +
    1.86 +	D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
    1.87 +	resourceViewDesc.Format = textureDesc.Format;
    1.88 +	resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    1.89 +	resourceViewDesc.Texture2D.MostDetailedMip = 0;
    1.90 +	resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
    1.91 +	DX::ThrowIfFailed(
    1.92 +		m_d3dDevice->CreateShaderResourceView(
    1.93 +			m_mainTexture.Get(),
    1.94 +			&resourceViewDesc,
    1.95 +			&m_mainTextureResourceView)
    1.96 +		);
    1.97 +}
    1.98 +
    1.99  void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
   1.100  {
   1.101  	const float blackColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
   1.102 @@ -171,6 +172,10 @@
   1.103  	{
   1.104  		return;
   1.105  	}
   1.106 +    if (!m_mainTextureResourceView)
   1.107 +    {
   1.108 +        return;
   1.109 +    }
   1.110  
   1.111  	// Update the main texture (for SDL usage):
   1.112  	D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
   1.113 @@ -185,7 +190,9 @@
   1.114  
   1.115  	// TODO, WinRT: only copy over the requested rects (via SDL_BlitSurface, perhaps?)
   1.116  	// TODO, WinRT: do a sanity check on the src and dest data when updating the window surface
   1.117 -	const unsigned int numBytes = (int)m_windowBounds.Width * (int)m_windowBounds.Height * 4;
   1.118 +    D3D11_TEXTURE2D_DESC textureDesc = {0};
   1.119 +    m_mainTexture->GetDesc(&textureDesc);
   1.120 +	const unsigned int numBytes = textureDesc.Width * textureDesc.Height * 4;
   1.121  	memcpy(textureMemory.pData, surface->pixels, numBytes);
   1.122  
   1.123  	m_d3dContext->Unmap(