Home Game Development directx – Reading from a staging 2D texture array in DirectX10

directx – Reading from a staging 2D texture array in DirectX10

0
directx – Reading from a staging 2D texture array in DirectX10

[ad_1]

You’re forgetting to consider mipLevels.
When creating a texture, usually miplevels will be generated so you will not find texture element 2 at subresource 2 (there is a mipLevel in it, which is half of original texture and so on).

Use this function to get the right subresource index.

    ID3D11Texture2D *cpuTexture = NULL;

    D3D11_TEXTURE2D_DESC cputextdesc;
    memset(&cputextdesc,0,sizeof(cputextdesc));

    cputextdesc.Width = cputextdesc.Height = 16;
    cputextdesc.ArraySize = 3;
    cputextdesc.MipLevels = 1;
    cputextdesc.Format = DXGI_FORMAT_R32_FLOAT;
    cputextdesc.Usage = D3D11_USAGE_STAGING;
    cputextdesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    cputextdesc.SampleDesc.Count = 1;
    cputextdesc.SampleDesc.Quality = 0;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

    int text1 = D3D11CalcSubresource(0,0,1);
    int text2 = D3D11CalcSubresource(0,1,1);
    int text3 = D3D11CalcSubresource(0,2,1);

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3);

    // (assert row and depth pitch are equals)

    icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);

[ad_2]

Previous article The Last of Us Season 2 May Contain Deleted Scenes From the Game
Next article Mario Kart 8 Deluxe – US Version Review
Hello there! My name is YoleeTeam, and I am thrilled to welcome you to AmazonianGames.com. As the premier destination for all things related to Amazon Games' universe, we are dedicated to providing you with the most exciting and immersive gaming experiences out there. From captivating visuals to exhilarating gameplay, our website is packed with comprehensive insights, updates, and reviews to keep you ahead of the game. Whether you're a seasoned gamer or new to the scene, I am here to guide you through this virtual frontier. If you have any questions or suggestions, feel free to reach out to me at john@yoleesolutions.com. Embark on your Amazon gaming journey today with AmazonianGames.com and let the adventure begin!