为什么 D3DX11CreateShaderResourceViewFromMemory 只上传纹理的部分副本?
我对 D3DX11CreateShaderResourceViewFromMemory 辅助函数有疑问。
我从文件或 ZIP 中读取一些纹理,并将原始字节和长度传递给辅助函数,但是仅上传了部分纹理(由 PIX 确认)。 我尝试手动调整长度但无济于事。 这是从文件加载纹理的代码:
struct FileDataLoader
{
void Load()
{
std::ifstream file(mFileName);
if (file)
{
file.seekg(0,std::ios::end);
std::streampos length = file.tellg();
file.seekg(0,std::ios::beg);
mBuffer.resize(length);
file.read(&mBuffer[0],length);
file.close();
}
}
void Decompress(void*& data, std::size_t& numBytes)
{
data = &mBuffer[0];
numBytes = mBuffer.size();
}
std::wstring mFileName;
std::vector<char> mBuffer;
};
FileDataLoader fdl;
fdl.mFileName = L"Content\\Textures\\Smoke.dds";
fdl.Load();
void* bytes;
std::size_t size;
fdl.Decompress(bytes, size);
DXCall(D3DX11CreateShaderResourceViewFromMemory(device, bytes, size, NULL, NULL, &particleTexture, NULL));
这只是我用来调试此问题的示例代码,我将其范围缩小到文件加载和 D3DX 辅助函数。 现在,如果我这样做:
DXCall(D3DX11CreateShaderResourceViewFromFileW(device, L"Content\\Textures\\Smoke.dds", NULL, NULL, &particleTexture, NULL));
它工作得很好。
知道为什么它不会完全上传纹理吗?
I have a problem with the D3DX11CreateShaderResourceViewFromMemory helper function.
I read some texture from a file or ZIP and pass the raw bytes and length to the helper function, however only part of the texture is uploaded (as confirmed by PIX).
I tried fiddling with the length manually but to no avail.
Here is the code that loads the texture from file:
struct FileDataLoader
{
void Load()
{
std::ifstream file(mFileName);
if (file)
{
file.seekg(0,std::ios::end);
std::streampos length = file.tellg();
file.seekg(0,std::ios::beg);
mBuffer.resize(length);
file.read(&mBuffer[0],length);
file.close();
}
}
void Decompress(void*& data, std::size_t& numBytes)
{
data = &mBuffer[0];
numBytes = mBuffer.size();
}
std::wstring mFileName;
std::vector<char> mBuffer;
};
FileDataLoader fdl;
fdl.mFileName = L"Content\\Textures\\Smoke.dds";
fdl.Load();
void* bytes;
std::size_t size;
fdl.Decompress(bytes, size);
DXCall(D3DX11CreateShaderResourceViewFromMemory(device, bytes, size, NULL, NULL, &particleTexture, NULL));
That is only a sample code that I am using to debug this problem, and I narrowed it down to the file loading and the D3DX helper function.
Now if I do this instead:
DXCall(D3DX11CreateShaderResourceViewFromFileW(device, L"Content\\Textures\\Smoke.dds", NULL, NULL, &particleTexture, NULL));
it works perfectly fine.
Any idea on why it would not upload the texture entirely ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
打开文件时,您需要指定该文件是二进制文件:
如果没有
std::ios::binary
标志,您默认会以纯文本形式读取,这不是 D3DX11CreateShaderResourceViewFromMemory 所期望的。When opening the file, you need to specify that the file is binary:
Without the
std::ios::binary
flag you're reading in plain text by default, which is not what D3DX11CreateShaderResourceViewFromMemory expects.