Jump to content

  • Log In with Google      Sign In   
  • Create Account


DX11: fail on Create Shader Resource View From Memory


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Corefanatic   Members   -  Reputation: 129

Like
0Likes
Like

Posted 20 February 2012 - 03:42 PM

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:


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



Thx for any help ;)

Sponsor:

#2 MJP   Moderators   -  Reputation: 10526

Like
0Likes
Like

Posted 20 February 2012 - 04:02 PM

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.

#3 Corefanatic   Members   -  Reputation: 129

Like
0Likes
Like

Posted 20 February 2012 - 04:07 PM

Thx MJP, good answer as always. Here I have been mashing my head against the keyboard and it is so simple :). Thx again




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS