[英]CreateTexture2D fail… (d3d)
I'm trying to create D3D texture 2d with STAGING usage. 我正在尝试使用STAGING用法创建D3D纹理2d。
Always, it fails with error : "Incorrect parameter" (code 0x80070057)... 总是失败,并显示错误:“参数不正确”(代码0x80070057)...
I don't understand, I can create other than staging no problem, but can't succeed with this... Please help me before my computer goes flying through the window... Please... 我不明白,除了暂无问题外,我还可以创建其他文件,但无法成功完成此操作...请在计算机飞过窗口之前帮助我...请...
Here is the problematic piece of code : 这是有问题的代码:
int w = 128;
int h = 128;
ID3D11Texture2D * tex;
D3D11_TEXTURE2D_DESC tdesc;
D3D11_SUBRESOURCE_DATA tbsd;
ZeroMemory(&tdesc, sizeof(D3D10_TEXTURE2D_DESC));
WORD *buf = new WORD[128*128];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
{
buf[i*128 + j] = (WORD) 0xffffffff;
}
tbsd.pSysMem = (void *)buf;
tbsd.SysMemPitch = w * 4;
tbsd.SysMemSlicePitch = w * h * 4;
tdesc.Width = w;
tdesc.Height = h;
tdesc.MipLevels = 1;
tdesc.ArraySize = 1;
tdesc.SampleDesc.Count = 1;
tdesc.SampleDesc.Quality = 0;
tdesc.Usage = D3D11_USAGE_STAGING;
tdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tdesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
// tdesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; // Does'nt work either...
tdesc.MiscFlags = 0;
HRESULT eblah = 0; char tmpstr[128];
eblah = device->CreateTexture2D(&tdesc, &tbsd, &tex);
if (FAILED(eblah))
{
wsprintfA(tmpstr, "Error code : %lX", eblah); OutputDebugStringA(tmpstr);
ErrorMessage(eblah);
}
I've got this as device, earlier in code, in case of : ID3D11Device* device = nullptr; 在以下代码中,我将其作为设备使用:ID3D11Device * device = nullptr; D3D_FEATURE_LEVEL level; D3D_FEATURE_LEVEL级别; ID3D11DeviceContext* context = nullptr; ID3D11DeviceContext * context = nullptr;
HRESULT hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_NULL, // Tried D3D_DRIVER_TYPE_HARDWARE too
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
&device,
&level,
&context
);
Found it : 找到了 :
_ I used D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG flag when creating the device, which gave me very useful debug info. _我在创建设备时使用了D3D11_CREATE_DEVICE_FLAG :: D3D11_CREATE_DEVICE_DEBUG标志,这为我提供了非常有用的调试信息。 A must have for every beginner !!! 每个初学者都必须拥有!
_ tdesc.BindFlags MUST be 0 when creating a ID3D11Texture2D for staging. 创建用于暂存的ID3D11Texture2D时,_ tdesc.BindFlags必须为0。
_ My computer didn't fly through the window !!! _我的电脑没有从窗户飞过!
Nice day to everyone :) 祝大家有美好的一天:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.