Esempio n. 1
0
//===============================================================================================================================
void TextureManager::WriteDDSToFile(LPCWSTR filename, ID3D11ShaderResourceView* textureSRV)
{
    ID3D11Texture2D *textureInterface = 0;
    ID3D11Resource *textureResource;
    textureSRV->GetResource(&textureResource);
    textureResource->QueryInterface<ID3D11Texture2D>(&textureInterface);

    HRESULT result;
    result = SaveDDSTextureToFile(mD3DSystem->GetDeviceContext(), textureInterface, filename);

    if (FAILED(result))
    {
        ScratchImage image;
        result = CaptureTexture(mD3DSystem->GetDevice11(), mD3DSystem->GetDeviceContext(), textureInterface, image);

        if (SUCCEEDED(result))
        {
            result = SaveToDDSFile(image.GetImages(), image.GetImageCount(), image.GetMetadata(), DDS_FLAGS_NONE, filename);

            if (FAILED(result))
            {
                ZShadeMessageCenter::MsgBoxError(NULL, "Failed to save DDS texture !!");
            }
        }
    }

    SAFE_RELEASE(textureInterface);
    SAFE_RELEASE(textureResource);
}
Esempio n. 2
0
void SaveTextureAsDDS(ID3D11Resource* texture, const wchar* filePath)
{
    ID3D11DevicePtr device;
    texture->GetDevice(&device);

    ID3D11DeviceContextPtr context;
    device->GetImmediateContext(&context);

    ScratchImage scratchImage;
    DXCall(CaptureTexture(device, context, texture, scratchImage));
    DXCall(SaveToDDSFile(scratchImage.GetImages(), scratchImage.GetImageCount(),
                         scratchImage.GetMetadata(), DDS_FLAGS_FORCE_DX10_EXT, filePath));
}