问题
[Prologue] I am gonna try to render a Video stream from IDS uEye Cameras to DirectX Scene. The camera's colormode is currently set to IS_CM_RGBA8_PACKED. For now, I just capture a single Picture from the cam, freeze it to a char* cameraBufferLeft_ and try to use this as a ShaderResourceView (which should replace a previously used .dds File).
Previously, I had Problems on CreateTexture2D function aswell, because the camera mode was set to IS_CM_RGB8_PACKED, which means there was no Alpha channel back there. Of course, this did not work with the D3D11_TEXTURE2D_DESC.FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM of DirectX and CreateTexture2D crashed.
[Current Status] For now, create now the ID3D11Texture2D Object, but when I want to create the ShaderResourceView it fails. I can not figure out why and what's the Problem is.
So I researched, and created also my DirectX RenderDevice with Debug-Flag, but I just get "info" Output, nothing specific about the fail or something...
I hope anybody can help me out here, I am lost here for now.
[Relevant Code]
D3D11_TEXTURE2D_DESC tdesc;
ZeroMemory(&tdesc, sizeof(tdesc));
D3D11_SUBRESOURCE_DATA srInitData;
ZeroMemory(&srInitData, sizeof(srInitData));
ID3D11Texture2D* tex = 0;
// NOTE: Just for dirty Synchronisation. If Camera Stream works, doing better solution for this..
// TODO: implement Camera and Graphics Synchronisation - using Condition Variables | WakeConditionVariable()
Sleep(1500);
tdesc.ArraySize = 1;
tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tdesc.Usage = D3D11_USAGE_DYNAMIC;
tdesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
tdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
tdesc.Height = CAMERA_HEIGHT;
tdesc.Width = CAMERA_WIDTH;
tdesc.MipLevels = 1;
tdesc.MiscFlags = 0;
tdesc.SampleDesc.Count = 1;
tdesc.SampleDesc.Quality = 0;
// NOTE: "cameraBufferLeft_" contains RGBA8 Data. ColorMode of Camera set to IS_CM_RGBA8_PACKED
srInitData.pSysMem = arift_control->cameraBufferLeft_;
srInitData.SysMemPitch = CAMERA_WIDTH * 4;
// works
if (device->CreateTexture2D(&tdesc, &srInitData, NULL) == S_FALSE)
std::cout << "Inputs correct" << std::endl;
else
std::cout << "wrong inputs" << std::endl;
if (FAILED(device->CreateTexture2D(&tdesc, &srInitData, &tex)))
{
std::cout << "Failed" << std::endl;
return(false);
}
else
std::cout << "Sucess" << std::endl;
// Create the shader-resource view
D3D11_SHADER_RESOURCE_VIEW_DESC srDesc;
srDesc.Format = tdesc.Format;
srDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
// srDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
srDesc.Texture2D.MostDetailedMip = 0;
srDesc.Texture2D.MipLevels = 1;
// this crashes with access violation
if (FAILED(device->CreateShaderResourceView(tex, &srDesc, &texture_)));
{
std::cerr << "Can't create Shader Resource View" << std::endl;
return false;
}
return true;
[Relevant Output] ... D3D11 INFO: Create ID3D11Texture2D: Name="unnamed", Addr=0x00E0A6B4, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #2097234: CREATE_TEXTURE2D] D3D11 INFO: Create ID3D11ShaderResourceView: Name="unnamed", Addr=0x00E0AC9C, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #2097240: CREATE_SHADERRESOURCEVIEW]
Furthermore, I have also tried to create the ShaderResourceView with NULL as 2nd param - still failed. I am stuck here for quite a while with that. Many thanks for your help! :)
[Update 1] So, now I have tried to use CreateDDSTextureFromMemory and CreateWICTextureFromMemory (loading a .png worked but that's not my goal here) - both of them failed aswell since it'is neither a .jpg / .png nor .dds file. It is just a char* buffer containing RGBA8 data. I have tried now so many different approaches, Now I really don't know what else to do here.
来源:https://stackoverflow.com/questions/29265034/directx11-render-camerastream-to-texture-devicecreateshaderresourceview-fail