149 ImGui::Begin(
"SkSL",
nullptr, ImGuiWindowFlags_AlwaysVerticalScrollbar);
152 ImGuiInputTextFlags
flags = ImGuiInputTextFlags_CallbackResize;
153 ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * 30);
154 if (ImGui::InputTextMultiline(
"Code", fSkSL.
data(), fSkSL.
size() + 1, boxSize,
flags,
159 if (ImGui::Checkbox(
"ShaderToy Uniforms (iResolution/iTime/iMouse)", &fShadertoyUniforms)) {
163 if (fCodeIsDirty || !fEffect) {
172 bool writeTrace =
false;
173 bool writeDump =
false;
175 ImGui::InputInt2(
"Trace Coordinate (X/Y)", fTraceCoord);
176 writeTrace = ImGui::Button(
"Write Debug Trace (JSON)");
177 writeDump = ImGui::Button(
"Write Debug Dump (Human-Readable)");
181 ImVec2 mousePos = ImGui::GetMousePos();
182 if (ImGui::IsMouseDown(0)) {
183 fMousePos.
x = mousePos.x;
184 fMousePos.
y = mousePos.y;
186 if (ImGui::IsMouseClicked(0)) {
187 fMousePos.
z = mousePos.x;
188 fMousePos.
w = mousePos.y;
190 fMousePos.
z = std::abs(fMousePos.
z) * (ImGui::IsMouseDown(0) ? 1 : -1);
191 fMousePos.
w = std::abs(fMousePos.
w) * (ImGui::IsMouseClicked(0) ? 1 : -1);
194 char* data = fInputs.
get() + v.offset;
195 if (v.name ==
"iResolution") {
196 memcpy(data, &fResolution,
sizeof(fResolution));
199 if (v.name ==
"iTime") {
200 memcpy(data, &fSeconds,
sizeof(fSeconds));
203 if (v.name ==
"iMouse") {
204 memcpy(data, &fMousePos,
sizeof(fMousePos));
213 float* f =
reinterpret_cast<float*
>(data);
214 for (
int c = 0; c < v.count; ++c, f += rows) {
216 ?
SkStringPrintf(
"%.*s[%d]", (
int)v.name.size(), v.name.data(), c)
219 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_Float, f, rows, 1.0f);
229 float* f =
reinterpret_cast<float*
>(data);
230 for (
int e = 0; e < v.count; ++e) {
231 for (
int c = 0; c < cols; ++c, f += rows) {
233 ?
SkStringPrintf(
"%.*s[%d][%d]", (
int)v.name.size(), v.name.data(), e, c)
234 :
SkStringPrintf(
"%.*s[%d]", (
int)v.name.size(), v.name.data(), c);
235 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_Float, f, rows, 1.0f);
245 int* i =
reinterpret_cast<int*
>(data);
246 for (
int c = 0; c < v.count; ++c, i += rows) {
248 ?
SkStringPrintf(
"%.*s[%d]", (
int)v.name.size(), v.name.data(), c)
251 ImGui::DragScalarN(
name.c_str(), ImGuiDataType_S32, i, rows, 1.0f);
260 auto curShader = std::find_if(
263 [tgt = fChildren[c.index]](
const std::pair<
const char*,
sk_sp<SkShader>>& p) {
264 return p.second == tgt;
268 if (ImGui::BeginCombo(std::string(c.name).c_str(), curShader->first)) {
269 for (
const auto& namedShader : fShaders) {
270 if (ImGui::Selectable(namedShader.first, curShader->second == namedShader.second)) {
271 fChildren[c.index] = namedShader.second;
278 static SkColor4f gPaintColor { 1.0f, 1.0f, 1.0f , 1.0f };
279 ImGui::ColorEdit4(
"Paint Color", gPaintColor.vec());
281 ImGui::RadioButton(
"Fill", &fGeometry, kFill); ImGui::SameLine();
282 ImGui::RadioButton(
"Circle", &fGeometry, kCircle); ImGui::SameLine();
283 ImGui::RadioButton(
"RoundRect", &fGeometry, kRoundRect); ImGui::SameLine();
284 ImGui::RadioButton(
"Capsule", &fGeometry, kCapsule); ImGui::SameLine();
285 ImGui::RadioButton(
"Text", &fGeometry, kText);
294 auto shader = fEffect->
makeShader(std::move(inputs), fChildren.
data(), fChildren.
size());
295 if (writeTrace || writeDump) {
296 SkIPoint traceCoord = {fTraceCoord[0], fTraceCoord[1]};
299 shader = std::move(traced.
shader);
313 p.setColor4f(gPaintColor);
314 p.setShader(std::move(shader));
340 if (debugTrace && writeTrace) {
342 debugTrace->writeTrace(&traceFile);
344 if (debugTrace && writeDump) {
346 debugTrace->dump(&dumpFile);