Move SaveTexture logic to replay layer

* Expand the abilities of the GetTextureData in replay drivers
  to be able to resolve samples and render down to RGBA8 unorm
  for file export to other programs.
* Greatly improve the ability to save textures - in theory any
  texture format/type/dimension/etc should now be mappable in
  sensible & useful ways to output formats.
This commit is contained in:
baldurk
2014-09-16 01:25:13 +01:00
parent 9f62428f7f
commit 326ca2ebe8
18 changed files with 1213 additions and 55 deletions
+17
View File
@@ -128,6 +128,23 @@ namespace renderdoc
QuadOverdrawDraw,
};
public enum FileType
{
DDS,
PNG,
JPG,
BMP,
TGA,
HDR,
};
public enum AlphaMapping
{
Discard,
BlendToColour,
BlendToCheckerboard,
};
public enum SpecialFormat
{
Unknown = 0,
+49
View File
@@ -399,6 +399,55 @@ namespace renderdoc
public TextureDisplayOverlay overlay = TextureDisplayOverlay.None;
};
[StructLayout(LayoutKind.Sequential)]
public class TextureSave
{
public ResourceId id = ResourceId.Null;
public FileType destType = FileType.DDS;
public Int32 mip = -1;
public struct ComponentMapping
{
public float blackPoint;
public float whitePoint;
};
[CustomMarshalAs(CustomUnmanagedType.CustomClass)]
public ComponentMapping comp = new ComponentMapping();
[StructLayout(LayoutKind.Sequential)]
public struct SampleMapping
{
public bool mapToArray;
public UInt32 sampleIndex;
};
[CustomMarshalAs(CustomUnmanagedType.CustomClass)]
public SampleMapping sample = new SampleMapping();
[StructLayout(LayoutKind.Sequential)]
public struct SliceMapping
{
public Int32 sliceIndex;
public bool slicesAsGrid;
public Int32 sliceGridWidth;
public bool cubeCruciform;
};
[CustomMarshalAs(CustomUnmanagedType.CustomClass)]
public SliceMapping slice = new SliceMapping();
public AlphaMapping alpha = AlphaMapping.Discard;
public FloatVector alphaCol = new FloatVector();
public FloatVector alphaColSecondary = new FloatVector();
public int jpegQuality = 90;
};
[StructLayout(LayoutKind.Sequential)]
public class APIProperties
{
+3 -3
View File
@@ -226,7 +226,7 @@ namespace renderdoc
private static extern bool ReplayRenderer_GetCBufferVariableContents(IntPtr real, ResourceId shader, UInt32 cbufslot, ResourceId buffer, UInt32 offs, IntPtr outvars);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_SaveTexture(IntPtr real, ResourceId texID, UInt32 mip, string path);
private static extern bool ReplayRenderer_SaveTexture(IntPtr real, TextureSave saveData, string path);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_GetPostVSData(IntPtr real, MeshDataStage stage, IntPtr outdata);
@@ -586,8 +586,8 @@ namespace renderdoc
return ret;
}
public bool SaveTexture(ResourceId texID, UInt32 mip, string path)
{ return ReplayRenderer_SaveTexture(m_Real, texID, mip, path); }
public bool SaveTexture(TextureSave saveData, string path)
{ return ReplayRenderer_SaveTexture(m_Real, saveData, path); }
public PostVSMeshData GetPostVSData(MeshDataStage stage)
{
+35 -2
View File
@@ -2702,13 +2702,46 @@ namespace renderdocui.Windows
private void saveTex_Click(object sender, EventArgs e)
{
if (saveTextureDialog.ShowDialog() == DialogResult.OK)
//if (saveTextureDialog.ShowDialog() == DialogResult.OK)
{
TextureSave sd = new TextureSave();
sd.destType = FileType.DDS;
saveTextureDialog.FileName = "T:/tmp/a.dds";
sd.id = m_TexDisplay.texid;
sd.slice.sliceIndex = (int)m_TexDisplay.sliceFace;
if (sd.destType == FileType.DDS)
sd.slice.sliceIndex = -1;
sd.mip = (int)m_TexDisplay.mip;
if (sd.destType == FileType.DDS)
sd.mip = -1;
if (sd.destType == FileType.DDS)
{
sd.sample.mapToArray = true;
}
else
{
sd.sample.mapToArray = false;
sd.sample.sampleIndex = m_TexDisplay.sampleIdx;
}
sd.comp.blackPoint = m_TexDisplay.rangemin;
sd.comp.whitePoint = m_TexDisplay.rangemax;
sd.alphaCol = m_TexDisplay.lightBackgroundColour;
sd.alphaColSecondary = m_TexDisplay.darkBackgroundColour;
sd.alpha = m_TexDisplay.Alpha ? AlphaMapping.BlendToCheckerboard : AlphaMapping.Discard;
bool ret = false;
m_Core.Renderer.Invoke((ReplayRenderer r) =>
{
ret = r.SaveTexture(m_TexDisplay.texid, m_TexDisplay.mip, saveTextureDialog.FileName);
ret = r.SaveTexture(sd, saveTextureDialog.FileName);
});
if(!ret)