Add SkSL viewing/editing to viewer
Still only works with the GL backend. For other backends,
need to add similar logic to the shader caching, and some
extra checks in Viewer to force the SkSL flag on.
But in GL, this lets you toggle the checkbox and see the
SkSL / GLSL at will (and edit in either form).
Change-Id: I6d392113aa9cbcbd6e64589b849de70d0ac3beeb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209165
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 3e20c0f..c2a3595 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -1977,7 +1977,12 @@
// Defer actually doing the load/save logic so that we can trigger a save when we
// start or finish hovering on a tree node in the list below:
bool doLoad = ImGui::Button("Load"); ImGui::SameLine();
- bool doSave = ImGui::Button("Save");
+ bool doSave = ImGui::Button("Save"); ImGui::SameLine();
+ if (ImGui::Checkbox("SkSL", ¶ms.fGrContextOptions.fCacheSKSL)) {
+ paramsChanged = true;
+ doLoad = true;
+ fDeferredActions.push_back([=]() { fPersistentCache.reset(); });
+ }
ImGui::BeginChild("##ScrollingRegion");
for (auto& entry : fCachedGLSL) {
@@ -2008,8 +2013,10 @@
if (doSave) {
// The hovered item (if any) gets a special shader to make it identifiable
SkSL::String highlight = ctx->priv().caps()->shaderCaps()->versionDeclString();
- highlight.append("out vec4 sk_FragColor;\n"
- "void main() { sk_FragColor = vec4(1, 0, 1, 0.5); }");
+ const char* f4Type = params.fGrContextOptions.fCacheSKSL ? "half4" : "vec4";
+ highlight.appendf("out %s sk_FragColor;\n"
+ "void main() { sk_FragColor = %s(1, 0, 1, 0.5); }",
+ f4Type, f4Type);
fPersistentCache.reset();
fWindow->getGrContext()->priv().getGpu()->resetShaderCacheForTesting();