diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index be1ac34d2..92e460359 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -3334,34 +3334,28 @@ void TextureViewer::on_saveTex_clicked() if(!texptr || !m_Output) return; - TextureSave config; - memset(&config, 0, sizeof(config)); - config.jpegQuality = 90; - - config.id = m_TexDisplay.resourceId; - config.typeHint = m_TexDisplay.typeHint; - config.slice.sliceIndex = (int)m_TexDisplay.sliceFace; - config.mip = (int)m_TexDisplay.mip; + // overwrite save params with current texture display settings + m_SaveConfig.id = m_TexDisplay.resourceId; + m_SaveConfig.typeHint = m_TexDisplay.typeHint; + m_SaveConfig.slice.sliceIndex = (int)m_TexDisplay.sliceFace; + m_SaveConfig.mip = (int)m_TexDisplay.mip; if(texptr->depth > 1) - config.slice.sliceIndex = (int)m_TexDisplay.sliceFace >> (int)m_TexDisplay.mip; + m_SaveConfig.slice.sliceIndex = (int)m_TexDisplay.sliceFace >> (int)m_TexDisplay.mip; - config.channelExtract = -1; + m_SaveConfig.channelExtract = -1; if(m_TexDisplay.red && !m_TexDisplay.green && !m_TexDisplay.blue && !m_TexDisplay.alpha) - config.channelExtract = 0; + m_SaveConfig.channelExtract = 0; if(!m_TexDisplay.red && m_TexDisplay.green && !m_TexDisplay.blue && !m_TexDisplay.alpha) - config.channelExtract = 1; + m_SaveConfig.channelExtract = 1; if(!m_TexDisplay.red && !m_TexDisplay.green && m_TexDisplay.blue && !m_TexDisplay.alpha) - config.channelExtract = 2; + m_SaveConfig.channelExtract = 2; if(!m_TexDisplay.red && !m_TexDisplay.green && !m_TexDisplay.blue && m_TexDisplay.alpha) - config.channelExtract = 3; + m_SaveConfig.channelExtract = 3; - config.comp.blackPoint = m_TexDisplay.rangeMin; - config.comp.whitePoint = m_TexDisplay.rangeMax; - config.alphaCol = m_TexDisplay.backgroundColor; - config.alpha = m_TexDisplay.alpha ? AlphaMapping::BlendToCheckerboard : AlphaMapping::Discard; - if(m_TexDisplay.alpha && !ui->checkerBack->isChecked()) - config.alpha = AlphaMapping::BlendToColor; + m_SaveConfig.comp.blackPoint = m_TexDisplay.rangeMin; + m_SaveConfig.comp.whitePoint = m_TexDisplay.rangeMax; + m_SaveConfig.alphaCol = m_TexDisplay.backgroundColor; if(m_TexDisplay.customShaderId != ResourceId()) { @@ -3370,20 +3364,20 @@ void TextureViewer::on_saveTex_clicked() [this, &id](IReplayController *r) { id = m_Output->GetCustomShaderTexID(); }); if(id != ResourceId()) - config.id = id; + m_SaveConfig.id = id; } const ResourceId overlayTexID = m_Output->GetDebugOverlayTexID(); const bool hasSelectedOverlay = (m_TexDisplay.overlay != DebugOverlay::NoOverlay); const bool hasOverlay = (hasSelectedOverlay && overlayTexID != ResourceId()); - TextureSaveDialog saveDialog(*texptr, hasOverlay, config, this); + TextureSaveDialog saveDialog(*texptr, hasOverlay, m_SaveConfig, this); int res = RDDialog::show(&saveDialog); - config = saveDialog.config(); + m_SaveConfig = saveDialog.config(); if(saveDialog.saveOverlayInstead()) { - config.id = overlayTexID; + m_SaveConfig.id = overlayTexID; } if(res) @@ -3393,8 +3387,8 @@ void TextureViewer::on_saveTex_clicked() bool ret = false; QString fn = saveDialog.filename(); - m_Ctx.Replay().BlockInvoke([this, &ret, config, fn](IReplayController *r) { - ret = r->SaveTexture(config, fn.toUtf8().data()); + m_Ctx.Replay().BlockInvoke([this, &ret, fn](IReplayController *r) { + ret = r->SaveTexture(m_SaveConfig, fn.toUtf8().data()); }); if(!ret) diff --git a/qrenderdoc/Windows/TextureViewer.h b/qrenderdoc/Windows/TextureViewer.h index e8add6032..31ce3c9e4 100644 --- a/qrenderdoc/Windows/TextureViewer.h +++ b/qrenderdoc/Windows/TextureViewer.h @@ -309,6 +309,8 @@ private: ICaptureContext &m_Ctx; IReplayOutput *m_Output = NULL; + TextureSave m_SaveConfig; + TextureDescription *m_CachedTexture; Following m_Following = Following::Default; QMap m_TextureSettings; diff --git a/renderdoc/api/replay/control_types.h b/renderdoc/api/replay/control_types.h index c58cbd958..6fa2f11bd 100644 --- a/renderdoc/api/replay/control_types.h +++ b/renderdoc/api/replay/control_types.h @@ -277,9 +277,9 @@ DOCUMENT("How to map components to normalised ``[0, 255]`` for saving to 8-bit f struct TextureComponentMapping { DOCUMENT("The value that should be mapped to ``0``"); - float blackPoint; + float blackPoint = 0.0f; DOCUMENT("The value that should be mapped to ``255``"); - float whitePoint; + float whitePoint = 1.0f; }; DECLARE_REFLECTION_STRUCT(TextureComponentMapping); @@ -325,7 +325,7 @@ Selects the (depth/array) slice to save. If this is -1, then all slices are written out as detailed below. This is only supported in formats that don't support slices natively, and will be done in RGBA8. )"); - int32_t sliceIndex; + int32_t sliceIndex = -1; // write out the slices as a 2D grid, with the below // width. Any empty slices are writted as (0,0,0,0) @@ -333,10 +333,10 @@ that don't support slices natively, and will be done in RGBA8. If ``True``, write out the slices as a 2D grid with the width given in :data:`sliceGridWidth`. Any empty slices in the grid are written as transparent black. )"); - bool slicesAsGrid; + bool slicesAsGrid = false; DOCUMENT("The width of a grid if :data:`slicesAsGrid` is ``True``."); - int32_t sliceGridWidth; + int32_t sliceGridWidth = 1; DOCUMENT(R"(Write out 6 slices in a cruciform pattern:: @@ -353,7 +353,7 @@ empty slices in the grid are written as transparent black. With the gaps filled in with transparent black. )"); - bool cubeCruciform; + bool cubeCruciform = false; }; DECLARE_REFLECTION_STRUCT(TextureSliceMapping); @@ -365,10 +365,10 @@ struct TextureSave ResourceId id; DOCUMENT("An optional :class:`CompType` hint to use when saving a typeless texture."); - CompType typeHint; + CompType typeHint = CompType::Typeless; DOCUMENT("The :class:`FileType` to use when saving to the destination file."); - FileType destType; + FileType destType = FileType::DDS; // mip == -1 writes out all mips where allowed by file format // or writes mip 0 otherwise @@ -377,7 +377,7 @@ struct TextureSave If set to ``-1`` then all mips are written, where allowed by file format. If not allowed, mip 0 is written )"); - int32_t mip; + int32_t mip = -1; DOCUMENT(R"(Controls black/white point mapping for output formats that are normal :attr:`8-bit SRGB `, values are @@ -391,7 +391,7 @@ written TextureSliceMapping slice; DOCUMENT("Selects a single component out of a texture to save as grayscale, or -1 to save all."); - int channelExtract; + int channelExtract = -1; // for formats without an alpha channel, define how it should be // mapped. Only available for uncompressed simple formats, done @@ -401,7 +401,7 @@ alpha. It is an :class:`AlphaMapping` that controls what behaviour to use. )"); - AlphaMapping alpha; + AlphaMapping alpha = AlphaMapping::Preserve; DOCUMENT("The background color if :data:`alpha` is set to :attr:`AlphaMapping.BlendToColor`"); FloatVector alphaCol;