Jump to content
  • Advertisement
Sign in to follow this  

DX11 DX11: fail on Create Shader Resource View From Memory

This topic is 2800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,
I have a small problem. I have an array of floats and I need to create a dynamic, cpu-write 2D texture from it. For some reason I am getting E_FAIL.

Here's the code:

[color=black][font=Consolas]m_renderBuffer = [/font][color=blue][font=Consolas]new[/font][color=black][font=Consolas] [/font][color=blue][font=Consolas]float[/font][color=black][font=Consolas][m_width*m_height*4];[/font]



info.Width = m_width;
info.Height = m_height;
info.Depth = 1;
info.FirstMipLevel = 0;
info.MipLevels = 1;
info.BindFlags = D3D11_BIND_SHADER_RESOURCE;
info.CpuAccessFlags = D3D11_CPU_ACCESS_WRITE;
info.MipFilter = D3DX11_FILTER_NONE;
info.MiscFlags = 0;
info.Usage = D3D11_USAGE_DYNAMIC;
info.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;

HRESULT result = D3DX11CreateShaderResourceViewFromMemory(g_Renderer.GetD3D11Device(),

Thx for any help ;)

Share this post

Link to post
Share on other sites
You can't create a texture from a raw array using D3DX11CreateShaderResourceViewFromMemory. That function is intended for creating textures from image files, so you would have to have an entire .PNG/.JPG/etc. loaded into memory to pass to that function.

Just create a Texture2D directly (using a D3D11_TEXTURE2D_DESC and ID3D11Device::CreateTexture2D) and pass the appropriate creation flags. Don't try to pass any initialization data through the pInitialData, you can only do that for IMMUTABLE resources. Just Map it after you've created it and fill it with your data, and then again whenever you need to update the contents.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!