mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-07-08 08:40:55 +00:00
Fix custom shader edits to write the exact editor contents to disk
This commit is contained in:
@@ -963,6 +963,14 @@ QWidget.
|
||||
)");
|
||||
virtual void AddWatch(const rdcstr &expression) = 0;
|
||||
|
||||
DOCUMENT(R"(Return the current text of source files within the viewer. Primarily useful for
|
||||
returning any edits applied when editing a shader.
|
||||
|
||||
:return: The current file contents as a list of (filename, contents) pairs.
|
||||
:rtype: List[Tuple[str,str]]
|
||||
)");
|
||||
virtual rdcstrpairs GetCurrentFileContents() = 0;
|
||||
|
||||
protected:
|
||||
IShaderViewer() = default;
|
||||
~IShaderViewer() = default;
|
||||
|
||||
@@ -4086,6 +4086,22 @@ void ShaderViewer::AddWatch(const rdcstr &variable)
|
||||
ui->watch->QWidget::setFocus();
|
||||
}
|
||||
|
||||
rdcstrpairs ShaderViewer::GetCurrentFileContents()
|
||||
{
|
||||
rdcstrpairs files;
|
||||
for(ScintillaEdit *s : m_Scintillas)
|
||||
{
|
||||
// don't include the disassembly view
|
||||
if(m_DisassemblyView == s)
|
||||
continue;
|
||||
|
||||
QWidget *w = (QWidget *)s;
|
||||
files.push_back(
|
||||
{w->property("filename").toString(), QString::fromUtf8(s->getText(s->textLength() + 1))});
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
int ShaderViewer::snippetPos()
|
||||
{
|
||||
ShaderEncoding encoding = currentEncoding();
|
||||
|
||||
@@ -128,6 +128,8 @@ public:
|
||||
|
||||
virtual void AddWatch(const rdcstr &variable) override;
|
||||
|
||||
virtual rdcstrpairs GetCurrentFileContents() override;
|
||||
|
||||
// ICaptureViewer
|
||||
void OnCaptureLoaded() override;
|
||||
void OnCaptureClosed() override;
|
||||
|
||||
@@ -4528,16 +4528,24 @@ void TextureViewer::on_customEdit_clicked()
|
||||
// Save Callback
|
||||
[thisPointer, key, filename, path](ICaptureContext *ctx, IShaderViewer *viewer, ResourceId,
|
||||
ShaderStage, ShaderEncoding, ShaderCompileFlags, rdcstr,
|
||||
bytebuf bytes) {
|
||||
bytebuf) {
|
||||
{
|
||||
// don't trigger a full refresh
|
||||
if(thisPointer)
|
||||
thisPointer->m_CustomShaderWriteTime = thisPointer->m_CustomShaderTimer.elapsed();
|
||||
|
||||
rdcstrpairs files = viewer->GetCurrentFileContents();
|
||||
|
||||
if(files.size() != 1)
|
||||
qCritical() << "Unexpected number of files in custom shader viewer" << files.count();
|
||||
|
||||
if(files.empty())
|
||||
return;
|
||||
|
||||
QFile fileHandle(path);
|
||||
if(fileHandle.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
||||
{
|
||||
fileHandle.write(QByteArray(bytes));
|
||||
fileHandle.write(files[0].second.c_str(), files[0].second.size());
|
||||
fileHandle.close();
|
||||
|
||||
// watcher doesn't trigger on internal modifications
|
||||
|
||||
Reference in New Issue
Block a user