-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathImguiSession.cpp
More file actions
70 lines (56 loc) · 2.23 KB
/
Copy pathImguiSession.cpp
File metadata and controls
70 lines (56 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @fb-only
#include <shell/renderSessions/ImguiSession.h>
#include <shell/shared/platform/DisplayContext.h>
#include <shell/shared/renderSession/ShellParams.h>
#include <igl/CommandBuffer.h>
#include <igl/RenderPass.h>
namespace igl::shell {
void ImguiSession::initialize() noexcept {
commandQueue_ = getPlatform().getDevice().createCommandQueue({}, nullptr);
// Create the ImGui session
imguiSession_ = std::make_unique<iglu::imgui::Session>(getPlatform().getDevice(),
getPlatform().getInputDispatcher());
}
// NOLINTNEXTLINE(bugprone-exception-escape)
void ImguiSession::update(SurfaceTextures surfaceTextures) noexcept {
// Per IGL guidelines, surfaceTextures.color may be null on some platforms
// before the surface is ready (e.g., during window resize on Android/iOS).
if (!surfaceTextures.color) {
return;
}
const igl::DeviceScope deviceScope(getPlatform().getDevice());
auto cmdBuffer = commandQueue_->createCommandBuffer({}, nullptr);
const FramebufferDesc framebufferDesc = {
.colorAttachments = {{.texture = surfaceTextures.color}},
};
if (outputFramebuffer_) {
outputFramebuffer_->updateDrawable(surfaceTextures.color);
} else {
outputFramebuffer_ = getPlatform().getDevice().createFramebuffer(framebufferDesc, nullptr);
}
const RenderPassDesc renderPassDesc = {
.colorAttachments = {{
.loadAction = igl::LoadAction::Clear,
.storeAction = igl::StoreAction::Store,
.clearColor = getPreferredClearColor(),
}},
};
auto encoder = cmdBuffer->createRenderCommandEncoder(renderPassDesc, outputFramebuffer_);
{ // Draw using ImGui every frame
imguiSession_->beginFrame(framebufferDesc, getPlatform().getDisplayContext().pixelsPerPoint);
ImGui::ShowDemoWindow();
imguiSession_->endFrame(getPlatform().getDevice(), *encoder);
}
encoder->endEncoding();
if (shellParams().shouldPresent) {
cmdBuffer->present(surfaceTextures.color);
}
commandQueue_->submit(*cmdBuffer);
}
} // namespace igl::shell