Updating a 3D texture volume

May 6, 2014 at 8:15 PM
I added my own map / unmap functions for a 3D volume to be updated but was wondering if there was anything in the engine already built in to do this.

I found the uploadData function for constant buffers but nothing for 3d textures.

May 7, 2014 at 1:26 AM
There isn't anything right now. If you would like to post your implementations and a short description of what you are doing, I can probably add it in to the next commit.
May 7, 2014 at 10:56 AM
Edited May 7, 2014 at 11:08 AM
You may want to rename it to fit your engine standard / move the code to somewhere you feel may be better but here it is. I should note that the 3D texture configuration from the VolumeActor needs to be changed to allow for CPU manipulation.

Here are the config settings I changed and added (might be worth putting that in its own method to be called if the volume needs CPU manipulation);
    m_Config.SetUsage( D3D11_USAGE_DYNAMIC );
    m_Config.SetBindFlags( D3D11_BIND_SHADER_RESOURCE );
    m_Config.SetCPUAccessFlags( D3D11_CPU_ACCESS_WRITE );
And the code.
void RendererDX11::Update3DTexture( ResourcePtr m_VolumeTexture, float*& data, int DIM )
    D3D11_MAPPED_SUBRESOURCE mappedResource;

    mappedResource = pImmPipeline->MapResource( m_VolumeTexture, 0, D3D11_MAP_WRITE_DISCARD, 0 );

    //memcpy(mappedResource.pData, data, sizeof(float) * dataSize);

    float* fData = new float[DIM * DIM * DIM];

    for ( int x = 0; x < DIM; x++ ) {
        for ( int y = 0; y < DIM; y++ ) {
            for ( int z = 0; z < DIM; z++ ) {
                fData[x*DIM*DIM+y*DIM+z] = data[x*DIM*DIM+y*DIM+z];

    memcpy(mappedResource.pData, fData, sizeof(float) * DIM * DIM * DIM);

    pImmPipeline->UnMapResource( m_VolumeTexture, 0 );