I'm trying to create a texture for screen capture so I can grab the 1x1 mipmap to get the average color of the screen.
However, when I try to create the texture, it tells me I'm passing an invalid parameter (See error handling below), and I can't quite figure out what I'm missing here.
For those who know, it should be quick to spot.
//Create Texture
D3D10_TEXTURE2D_DESC tBufferDesc;
ID3D10Texture2D *tBuffer = NULL;
DXGI_SAMPLE_DESC iBufferSamples = {1,0};
tBufferDesc.Width = iScreenSizeX;
tBufferDesc.Height = iScreenSizeY;
tBufferDesc.MipLevels = 0;
tBufferDesc.ArraySize = 1;
tBufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
tBufferDesc.SampleDesc = iBufferSamples;
tBufferDesc.Usage = D3D10_USAGE_DEFAULT;
tBufferDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET;
tBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
tBufferDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
HRESULT tBufferResult = pDevice->CreateTexture2D(&tBufferDesc, NULL , &tBuffer);
switch(tBufferResult)
{
case E_FAIL:
::MessageBoxA(NULL, "Attempted to create a device with the debug layer enabled and the layer is not installed.", "E_FAIL", NULL);
return E_FAIL;
case D3D10_ERROR_FILE_NOT_FOUND:
::MessageBoxA(NULL, "The file was not found.", "D3D10_ERROR_FILE_NOT_FOUND", NULL);
return E_FAIL;
case D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS:
::MessageBoxA(NULL, "There are too many unique instances of a particular type of state object.", "D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS", NULL);
return E_FAIL;
case E_INVALIDARG:
::MessageBoxA(NULL, "An invalid parameter was passed to the returning function.", "E_INVALIDARG", NULL);
return E_FAIL;
case E_OUTOFMEMORY:
::MessageBoxA(NULL, "Direct3D could not allocate sufficient memory to complete the call.", "E_OUTOFMEMORY", NULL);
return E_FAIL;
case S_FALSE:
::MessageBoxA(NULL, "Alternate success value, indicating a successful but nonstandard completion (the precise meaning depends on context).", "S_FALSE", NULL);
return E_FAIL;
case S_OK:
::MessageBoxA(NULL, "No error occurred.", "S_OK", NULL);
break;
}