8 #define GLFW_INCLUDE_NONE
9 #include "GLFW/glfw3.h"
10 #define GLFW_EXPOSE_NATIVE_COCOA
11 #import "GLFW/glfw3native.h"
15 #include <AppKit/AppKit.h>
16 #include <Metal/Metal.h>
17 #include <QuartzCore/QuartzCore.h>
21 fprintf(stderr,
"GLFW Error (%d): %s\n", error, description);
25 int main(
int argc,
char const* argv[]) {
27 [[maybe_unused]]
int result = glfwInit();
28 assert(result == GLFW_TRUE);
30 if (glfwGetPlatform() != GLFW_PLATFORM_COCOA) {
33 "Metal is only available on macOS. Please try either Vulkan or "
39 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
42 glfwCreateWindow(800, 600,
"Impeller Example (Metal)", NULL, NULL);
43 assert(window != NULL);
45 int framebuffer_width, framebuffer_height;
46 glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
49 assert(context != NULL);
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;
62 ImpellerDisplayList dl = NULL;
87 while (!glfwWindowShouldClose(window)) {
91 layer.drawableSize = layer.bounds.size;
94 context, (__bridge
void*)layer.nextDrawable);
95 assert(surface != NULL);
104 glfwMakeContextCurrent(NULL);
106 glfwDestroyWindow(window);
void GLFWErrorCallback(int error, const char *description)
int main(int argc, char const *argv[])
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.