-
Notifications
You must be signed in to change notification settings - Fork 172
/
ImguiSession.cpp
63 lines (49 loc) · 2.16 KB
/
ImguiSession.cpp
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
/*
* 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 <igl/CommandBuffer.h>
#include <igl/RenderPass.h>
#include <shell/shared/platform/DisplayContext.h>
#include <shell/shared/renderSession/ShellParams.h>
namespace igl::shell {
void ImguiSession::initialize() noexcept {
const igl::CommandQueueDesc desc{igl::CommandQueueType::Graphics};
_commandQueue = getPlatform().getDevice().createCommandQueue(desc, nullptr);
{ // Create the ImGui session
_imguiSession = std::make_unique<iglu::imgui::Session>(getPlatform().getDevice(),
getPlatform().getInputDispatcher());
}
}
void ImguiSession::update(igl::SurfaceTextures surfaceTextures) noexcept {
const igl::DeviceScope deviceScope(getPlatform().getDevice());
auto cmdBuffer = _commandQueue->createCommandBuffer(igl::CommandBufferDesc(), nullptr);
igl::FramebufferDesc framebufferDesc;
framebufferDesc.colorAttachments[0].texture = surfaceTextures.color;
if (_outputFramebuffer) {
_outputFramebuffer->updateDrawable(surfaceTextures.color);
} else {
_outputFramebuffer = getPlatform().getDevice().createFramebuffer(framebufferDesc, nullptr);
}
igl::RenderPassDesc renderPassDesc;
renderPassDesc.colorAttachments.resize(1);
renderPassDesc.colorAttachments[0].loadAction = igl::LoadAction::Clear;
renderPassDesc.colorAttachments[0].storeAction = igl::StoreAction::Store;
renderPassDesc.colorAttachments[0].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