c++ - Creating a Texture2DArray and populate it with solid values -


i have problems in creating , filling texture2darray in directx11.

i want render many quads onto screen, drawing done instancing, every quad should own texture. tried create texture array , added index value instances data format.

the problem is, when try create 2 different textures array, fails when try call function createtexture2d following error:

d3d11 error: id3d11device::createtexture2d: pinitialdata[4].sysmempitch cannot 0 [ state_creation error #100: createtexture2d_invalidinitialdata] d3d11 error: id3d11device::createtexture2d: pinitialdata[6].psysmem cannot null. [ state_creation error #100: createtexture2d_invalidinitialdata] d3d11 error: id3d11device::createtexture2d: pinitialdata[7].psysmem cannot null. [ state_creation error #100: createtexture2d_invalidinitialdata] d3d11 error: id3d11device::createtexture2d: returning e_invalidarg, meaning invalid parameters passed. [ state_creation error #104: createtexture2d_invalidarg_return] 

here code use generate texture:

//create array 2 textures const int size = 256 * 256 * 4; unsigned char color[size*2];  //first texture white (int = 0; < size; i++) {     color[i] = 255; }  //second texture black (int = size; < size*2; i++) {     color[i] = 0; }   //creating texture2d description d3d11_texture2d_desc desc; zeromemory(&desc, sizeof(d3d11_texture2d_desc)); desc.width = 256; desc.height = 256; desc.miplevels = 1; desc.arraysize = 2; desc.format = dxgi_format_r8g8b8a8_unorm; desc.sampledesc.count = 1; desc.sampledesc.quality = 0; desc.usage = d3d11_usage_default; desc.bindflags = d3d11_bind_shader_resource; desc.cpuaccessflags = 0; desc.miscflags = 0;  id3d11texture2d *ptexture; d3d11_subresource_data texture[2]; //zeromemory(&texture, sizeof(d3d11_subresource_data));  //defining texture start points texture[0].psysmem = color; texture[0].sysmempitch = sizeof(unsigned char) * 4; texture[0].sysmemslicepitch = 0; texture[1].psysmem = &color[size]; texture[1].sysmempitch = sizeof(unsigned char) * 4; texture[1].sysmemslicepitch = 0; result = device->createtexture2d(&desc, texture, &ptexture); 

i have no idea why error states @ array positions have @ no point defined, have 2 sized texture array. maybe i'm doing wrong initialization or filling of data.

i hope can me.

ok fixed call of function createtexture2d returns s_ok, problem occur. function createshaderresourceview returns s_ok, result first index of shaderressourceview array valid , second corrupt.

here fixed code:

//defining texture start points texture[0].psysmem = black; texture[0].sysmempitch = sizeof(unsigned char) * 4; texture[0].sysmemslicepitch = 256 * 256 * 4; texture[1].psysmem = &black[size]; texture[1].sysmempitch = sizeof(unsigned char) * 4; texture[1].sysmemslicepitch = 256*256 *4; result = device->createtexture2d(&desc, texture, &ptexture); 

and code brings problem:

d3d11_shader_resource_view_desc srdesc; srdesc.format = desc.format; srdesc.viewdimension = d3d11_srv_dimension_texture2darray; srdesc.texture2darray.mostdetailedmip = 0; srdesc.texture2darray.miplevels = 1; srdesc.texture2darray.arraysize = 2; srdesc.texture2darray.firstarrayslice = 0;  id3d11shaderresourceview *pshaderresview[2]; result = device->createshaderresourceview(ptexture, &srdesc, pshaderresview); 

it generates following error when calling pssetshaderresources(0, 2, pshaderresview);

d3d11 corruption: id3d11devicecontext::pssetshaderresources: third parameter, array index 1 corrupt or unexpectedly null. [ miscellaneous corruption #15: corrupted_parameter3] 

i hope initialized texture2d , subressource_data correctly, had problems understand sysmempitch , sysmemslicepitch.

but have no idea why second index corrupted.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -