c++ - How to create texture using DirectX-11 with DXGI_FORMAT_420_OPAQUE format? -
i facing problems creating directx texture i420 data. program crashes when try add texture. working on windows 8.0 on winrt metro app. can me please? code follows:
d3d11_texture2d_desc texdesc = {}; texdesc.width = 352; texdesc.height = 288; texdesc.miplevels = 1; byte *bitmapdata; int datasize = read_whole_file_into_array(&bitmapdata , "1.i420"); //bitmapdata contains i420 frame d3d11_subresource_data framedata; framedata.psysmem = bitmapdata; framedata.sysmemslicepitch = 0; //framedata.sysmempitch = texdesc.width; //unsure texdesc.arraysize = 1; texdesc.format = dxgi_format_420_opaque; texdesc.sampledesc.count = 1; texdesc.sampledesc.quality = 0; texdesc.bindflags = d3d11_bind_decoder; texdesc.miscflags = 0; texdesc.usage = d3d11_usage_default; texdesc.cpuaccessflags = 0; m_d3ddevice->createtexture2d (&texdesc, &framedata, &m_background); m_spritebatch->addtexture(m_background.get());
please help. in advance.
additional information: msdn link contains similar problem, in case have byte array containing frame. asked similar question forum.
as per documentation here
applications cannot use cpu map resource , access data within resource. cannot use shaders format.
when create texture, if need have access in shader, need set flag:
texdesc.bindflags = d3d11_bind_decoder | d3d11_bind_shader_resource;
then when create textures, make sure check result see if texture created:
hresult hr = m_d3ddevice->createtexture2d (&texdesc, &framedata, &m_background);
in case warn texture can't created (and debug layer on have message):
d3d11 error: id3d11device::createtexture2d: format (0x6a, 420_opaque) cannot bound shaderresource or cast format bound shaderresource. therefore format cannot support d3d11_bind_shader_resource. [ state_creation error #92: createtexture2d_unsupportedformat]
d3d11 error: id3d11device::createtexture2d: returning e_invalidarg, meaning invalid parameters passed. [ state_creation error #104: createtexture2d_invalidarg_return]
Comments
Post a Comment