32 ID GetID()
const override {
return m_id; }
44 static constexpr uint32_t kFrames = 2;
48 id<MTLTexture> drawTexture = nil;
50 uint64_t fenceValue = 0;
54 void Record(
IntRect rect,
bool resizing);
55 bool MakeSizedResources(uint32_t width, uint32_t height);
56 void Draw(Frame& frame, id<MTLCommandBuffer> commandBuffer);
58 double ClearAlpha()
const {
return IsTransparent() || m_toImage ? 0.0 : 1.0; }
60 MetalGraphicsContext& m_graphics;
61 MetalGraphicsContext::Impl& m_device;
66 bool m_toImage =
false;
69 CAMetalLayer* m_layer = nil;
70 id<MTLTexture> m_depth = nil;
71 std::array<Frame, kFrames> m_frames;
72 uint32_t m_frameIndex = 0;
73 uint32_t m_width = 0, m_height = 0;
74 bool m_presentPending =
false;
75 std::optional<uint32_t> m_lastFrame;
77 id<MTLBuffer> m_readback = nil;
80 std::shared_ptr<bool> m_alive = std::make_shared<bool>(
true);
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:53
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
Definition metal_graphics_context.h:45
Definition metal_window_context.h:24
std::optional< double > PresentWindowFrame() override
May wait for vsync; nothing to do for a render-to-image window.
void RecordWindowFrame(GraphicsContext *graphicsContext, IntRect rect) override
Records and submits a frame without presenting it; PresentWindowFrame presents.
bool IsTransparent() const override
Whether the window has WindowFlags::Transparent.
bool ReadPixels(std::span< uint8_t > bgra) override
The last rendered frame, BGRA8 with tightly packed rows; bgra holds width x height x 4 bytes of the w...
ID GetID() const override
The GUI window's ID; the backend passes it with the window's input.
Definition metal_window_context.h:32
~MetalWindowContext() override
static MetalWindowContext * Create(MetalGraphicsContext &graphics, void *window, OSWindowHandle osHandle, ID id, int2 size, WindowFlags flags, OnGuiFunc onGui)
window is the NSWindow, null for a render-to-image window.
OSWindowHandle GetWindowHandle() const override
The window it was created for.
Definition metal_window_context.h:33
void RenderWindowFrame(GraphicsContext *graphicsContext, IntRect rect, bool resizing) override
resizing: a live resize's redraw, which lays the window out again (its onGui) before it's drawn at th...
std::function< void()> OnGuiFunc
Definition gui_base_types.h:13
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:14
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_base_types.h:406
Integer 2D vector.
Definition gui_base_types.h:18