Jump to content
  • Advertisement
Sign in to follow this  
Corefanatic

DX11 DX11: fail on Create Shader Resource View From Memory

This topic is 2341 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]

memset(([color=blue]void*)m_renderBuffer,0,[color=blue]sizeof([color=blue]float)*4*m_height*m_width);

D3DX11_IMAGE_LOAD_INFO info;

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(),
([color=blue]void*)m_renderBuffer,
[color=blue]sizeof([color=blue]float)*4*m_height*m_width,
&info,
NULL,
&m_d3d11Texture,
NULL);


Thx for any help ;)

Share this post


Link to post
Share on other sites
Advertisement
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!