204 {
206 return true;
207 }
208
209 if (!render_callback) {
210 return true;
211 }
212
213 if (!renderer_ || !renderer_->IsValid()) {
214 return false;
215 }
216
217 IMGUI_CHECKVERSION();
218 ImGui::CreateContext();
220 []() { ImGui::DestroyContext(); });
221 ImGui::StyleColorsDark();
222
223 auto& io = ImGui::GetIO();
224 io.IniFilename = nullptr;
225 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
226 io.ConfigWindowsResizeFromEdges = true;
227
228 auto window =
reinterpret_cast<GLFWwindow*
>(impl_->GetWindowHandle());
230 return false;
231 }
233 ::glfwSetWindowUserPointer(
window,
this);
234 ::glfwSetWindowSizeCallback(
236 auto playground =
238 if (!playground) {
239 return;
240 }
242 });
244 ::glfwSetCursorPosCallback(
window, [](GLFWwindow*
window,
double x,
247 ->SetCursorPosition({
static_cast<Scalar>(
x),
static_cast<Scalar>(
y)});
248 });
249
250 ImGui_ImplGlfw_InitForOther(
window,
true);
252
256
257 ImGui::SetNextWindowPos({10, 10});
258
260 ::glfwSetWindowPos(
window, 200, 100);
262
263 while (true) {
264#if FML_OS_MACOSX
266#endif
267 ::glfwPollEvents();
268
269 if (::glfwWindowShouldClose(
window)) {
270 return true;
271 }
272
273 ImGui_ImplGlfw_NewFrame();
274
276 [render_callback,
278 ImGui::NewFrame();
279 ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(),
280 ImGuiDockNodeFlags_PassthruCentralNode);
281 bool result = render_callback(render_target);
282 ImGui::Render();
283
284
285 {
288 return false;
289 }
290 buffer->SetLabel(
"ImGui Command Buffer");
291
292 if (render_target.GetColorAttachments().empty()) {
293 return false;
294 }
295
296 auto color0 = render_target.GetColorAttachments().find(0)->second;
298 if (color0.resolve_texture) {
299 color0.texture = color0.resolve_texture;
300 color0.resolve_texture = nullptr;
302 }
303 render_target.SetColorAttachment(color0, 0);
304
305 render_target.SetStencilAttachment(std::nullopt);
306 render_target.SetDepthAttachment(std::nullopt);
307
308 auto pass =
buffer->CreateRenderPass(render_target);
309 if (!pass) {
310 return false;
311 }
312 pass->SetLabel("ImGui Render Pass");
313
315
316 pass->EncodeCommands();
317 if (!
renderer->GetContext()->GetCommandQueue()->Submit({buffer}).ok()) {
318 return false;
319 }
320 }
321
323 };
324
325 if (!renderer_->Render(impl_->AcquireSurfaceFrame(renderer_->GetContext()),
326 wrapped_callback)) {
328 return false;
329 }
330
332 break;
333 }
334 }
335
337
338 return true;
339}
Wraps a closure that is invoked in the destructor unless released by the caller.
Playground(PlaygroundSwitches switches)
virtual bool ShouldKeepRendering() const
ISize GetWindowSize() const
virtual std::string GetWindowTitle() const =0
std::function< bool(RenderTarget &render_target)> RenderCallback
static const uint8_t buffer[]
bool ImGui_ImplImpeller_Init(const std::shared_ptr< impeller::Context > &context)
void ImGui_ImplImpeller_RenderDrawData(ImDrawData *draw_data, impeller::RenderPass &render_pass)
void ImGui_ImplImpeller_Shutdown()
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static void PlaygroundKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
constexpr TSize Max(const TSize &o) const