mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-21 21:26:12 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user