25 {
27 [[maybe_unused]] int result = glfwInit();
29
30 if (glfwGetPlatform() != GLFW_PLATFORM_COCOA) {
31
32 fprintf(stderr,
33 "Metal is only available on macOS. Please try either Vulkan or "
34 "OpenGL (ES).\n");
35 fflush(stderr);
36 return -1;
37 }
38
39 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
40
42 glfwCreateWindow(800, 600, "Impeller Example (Metal)", NULL, NULL);
44
45 int framebuffer_width, framebuffer_height;
46 glfwGetFramebufferSize(
window, &framebuffer_width, &framebuffer_height);
47
49 assert(context != NULL);
50
51
52
53 NSWindow* cocoa_window = glfwGetCocoaWindow(
window);
54 assert(cocoa_window != NULL);
55 CAMetalLayer* layer = [CAMetalLayer layer];
56 layer.framebufferOnly = NO;
57 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
58 layer.device = MTLCreateSystemDefaultDevice();
59 cocoa_window.contentView.layer = layer;
60 cocoa_window.contentView.wantsLayer = YES;
61
62 ImpellerDisplayList dl = NULL;
63
64 {
67
68
72
73
78
80
83 }
84
85 assert(dl != NULL);
86
87 while (!glfwWindowShouldClose(
window)) {
88 glfwWaitEvents();
89
90
91 layer.drawableSize = layer.bounds.size;
92
94 context, (__bridge void*)layer.nextDrawable);
95 assert(surface != NULL);
99 }
100
103
104 glfwMakeContextCurrent(NULL);
105
106 glfwDestroyWindow(
window);
107
108 glfwTerminate();
109 return 0;
110}
void GLFWErrorCallback(int error, const char *description)
IMPELLER_EXPORT void ImpellerPaintRelease(ImpellerPaint IMPELLER_NULLABLE paint)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_EXPORT bool ImpellerSurfacePresent(ImpellerSurface IMPELLER_NONNULL surface)
Present the surface to the underlying window system.
IMPELLER_EXPORT void ImpellerSurfaceRelease(ImpellerSurface IMPELLER_NULLABLE surface)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerContext IMPELLER_NULLABLE ImpellerContextCreateMetalNew(uint32_t version)
Create a Metal context using the system default Metal device.
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawRect(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, const ImpellerRect *IMPELLER_NONNULL rect, ImpellerPaint IMPELLER_NONNULL paint)
Draws a rectangle.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerPaint IMPELLER_NULLABLE ImpellerPaintNew()
Create a new paint with default values.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayList IMPELLER_NULLABLE ImpellerDisplayListBuilderCreateDisplayListNew(ImpellerDisplayListBuilder IMPELLER_NONNULL builder)
Create a new display list using the rendering intent already encoded in the builder....
IMPELLER_EXPORT void ImpellerDisplayListBuilderRelease(ImpellerDisplayListBuilder IMPELLER_NULLABLE builder)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_EXPORT void ImpellerPaintSetColor(ImpellerPaint IMPELLER_NONNULL paint, const ImpellerColor *IMPELLER_NONNULL color)
Set the paint color.
IMPELLER_EXPORT void ImpellerDisplayListRelease(ImpellerDisplayList IMPELLER_NULLABLE display_list)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_EXPORT bool ImpellerSurfaceDrawDisplayList(ImpellerSurface IMPELLER_NONNULL surface, ImpellerDisplayList IMPELLER_NONNULL display_list)
Draw a display list onto the surface. The same display list can be drawn multiple times to different ...
IMPELLER_EXPORT void ImpellerDisplayListBuilderDrawPaint(ImpellerDisplayListBuilder IMPELLER_NONNULL builder, ImpellerPaint IMPELLER_NONNULL paint)
Fills the current clip with the specified paint.
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerSurface IMPELLER_NULLABLE ImpellerSurfaceCreateWrappedMetalDrawableNew(ImpellerContext IMPELLER_NONNULL context, void *IMPELLER_NONNULL metal_drawable)
Create a surface by wrapping a Metal drawable. This is useful during WSI when the drawable is the bac...
IMPELLER_EXPORT void ImpellerContextRelease(ImpellerContext IMPELLER_NULLABLE context)
Release a previously retained reference to the object. The object can be NULL in which case this meth...
IMPELLER_EXPORT IMPELLER_NODISCARD ImpellerDisplayListBuilder IMPELLER_NULLABLE ImpellerDisplayListBuilderNew(const ImpellerRect *IMPELLER_NULLABLE cull_rect)
Create a new display list builder.