gpt4 book ai didi

c++ - CreateTexture2D 失败... (d3d)

转载 作者:太空宇宙 更新时间:2023-11-04 14:54:47 24 4
gpt4 key购买 nike

我正在尝试使用 STAGING 使用创建 D3D 纹理 2d。

总是失败并出现错误:“参数不正确”(代码 0x80070057)...

我不明白,除了暂存没问题我可以创建,但是不能成功...请在我的计算机飞出窗口之前帮助我...请...

这是有问题的代码:

    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);
}

我已经把它作为设备,在代码的前面,以防: ID3D11Device* device = nullptr; D3D_FEATURE_LEVEL 等级; 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
);

最佳答案

找到了:

_ 我在创 build 备时使用了 D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG 标志,这为我提供了非常有用的调试信息。每个初学者都必须拥有!!!

_ tdesc.BindFlags 在为暂存创建 ID3D11Texture2D 时必须为 0。

_ 我的电脑没有飞出 window !!!

祝大家今天愉快:)

关于c++ - CreateTexture2D 失败... (d3d),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21324201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com