directx - directx11 - can't set Texture2D as ShaderResourceView? -


i have written little directx renderengine, render , texture simple polygons. texturing worked createddstexturefromfile(.dds) well.

now, try set texture , corresponding shaderresourceview memory buffer. creating texture2d works, then, createshaderresourceview fails. tried call 2nd param set null, fails. trying figure out what's wrong here whole week.

i hope can me here.

[code]:

    d3d11_texture2d_desc tdesc; zeromemory(&tdesc, sizeof(tdesc)); d3d11_subresource_data srinitdata; zeromemory(&srinitdata, sizeof(srinitdata)); id3d11texture2d* tex = 0; d3d11_shader_resource_view_desc srdesc; zeromemory(&srdesc, sizeof(srdesc));  // ------------------------- [check mate ] ---------------------------- int w = 512; int h = 512; int bpp = 4; int *buf = new int[w*h];  // filling image (int = 0; i<h; i++)     (int j = 0; j<w; j++)     {         if ((i & 32) == (j & 32))             buf[i*w + j] = 0x00000000;         else             buf[i*w + j] = 0xffffffff;     }  // setting d3d11_subresource_data  srinitdata.psysmem = (void *)buf; srinitdata.sysmempitch = w*bpp; srinitdata.sysmemslicepitch = w*h*bpp; // not needed since 2d texture  // setting d3d11_texture2d_desc  tdesc.width = w; tdesc.height = h; tdesc.miplevels = 1; tdesc.arraysize = 1; tdesc.sampledesc.count = 1; tdesc.sampledesc.quality = 0; tdesc.usage = d3d11_usage_default; tdesc.format = dxgi_format_r8g8b8a8_unorm; tdesc.bindflags = d3d11_bind_shader_resource; tdesc.cpuaccessflags = 0; tdesc.miscflags = 0;  // checking inputs if (device->createtexture2d(&tdesc, &srinitdata, null) == s_false)     std::cout << "inputs correct" << std::endl; else     std::cout << "wrong inputs" << std::endl;  // create texture if (failed(device->createtexture2d(&tdesc, &srinitdata, &tex))) {     std::cout << "failed" << std::endl;     return(0); } else     std::cout << "success" << std::endl;   // setup shader resource desc. srdesc.format = tdesc.format; srdesc.viewdimension = d3d11_srv_dimension_texture2d; srdesc.texture2d.mostdetailedmip = 0; srdesc.texture2d.miplevels = 1;  // ------------------ [ here fails ...] if (failed(device->createshaderresourceview(tex, &srdesc, &texture_))); {     std::cerr << "can't create shader resource view" << std::endl;     return false; }  delete[] buf; 

[sidequestion]: noticed when change d3d11_texture2d_desc.usage d3d11_usage_dynamic, createtexture2d aswell fails. why?

[debug]: ... d3d11 info: create id3d11buffer: name="unnamed", addr=0x00c31374, extref=1, intref=0 [ state_creation info #2097228: create_buffer] d3d11 info: create id3d11buffer: name="unnamed", addr=0x00c319a4, extref=1, intref=0 [ state_creation info #2097228: create_buffer] thread 'win32 thread' (0x9c8) has exited code 0 (0x0). d3d11 info: create id3d11texture2d: name="unnamed", addr=0x00c41984, extref=1, intref=0 [ state_creation info #2097234: create_texture2d] d3d11 info: create id3d11shaderresourceview: name="unnamed", addr=0x00c41f6c, extref=1, intref=0 [ state_creation info #2097240: create_shaderresourceview]

.. doesn't me, can't see of error hint here.

[note]: want use rgba8 texture camera input (stored in buffer) - not achieve that. tried example, find out why createshaderresourceview fails normal int* buffer.

i thankful help! thanks!

[solved] code above, reached output "can't create shader resource view" assuming createshaderresourceview failed. checking hresult, it's value s_ok, seemed strange me. changed condition try:

if (succeeded(device->createshaderresourceview(tex, &srdesc, &texture_))); {     std::cout << "successfully created shaderresourceview" << std::endl;     delete[] buf;     return true; } return false; 

and worked. behavior seems odd me, glad works. camera stream works now, many adam miles support! ;)

use d3d11_create_device_debug on device creation flags exact error messages printed out when function fails.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -