forked from xfangfang/borealis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
library/include/borealis/platforms/glfw/glfw_video_metal.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <GLFW/glfw3.h> | ||
#define GLFW_EXPOSE_NATIVE_COCOA | ||
#include <GLFW/glfw3native.h> | ||
|
||
#include <nanovg_mtl.h> | ||
|
||
// 创建一个 metal 上下文 | ||
void *CreateMetalContext(GLFWwindow* window); | ||
// 从 metal 上下文里取出 MetalLayer | ||
void *GetMetalLayer(void *ctx); | ||
// MetalLayer 画布缩放 | ||
void ResizeMetalDrawable(void *ctx, int width, int height); | ||
// 获取窗口 dpi | ||
float GetMetalScaleFactor(void *ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#import <Metal/Metal.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
#include <borealis/platforms/glfw/glfw_video_metal.hpp> | ||
|
||
|
||
struct context_mtl { | ||
id<MTLDevice> device; | ||
CAMetalLayer* layer; | ||
NSWindow* win; | ||
}; | ||
|
||
void *GetMetalLayer(void *ctx) { | ||
struct context_mtl *c = (struct context_mtl *)ctx; | ||
return (__bridge void *)c->layer; | ||
} | ||
|
||
void *CreateMetalContext(GLFWwindow* window) { | ||
struct context_mtl* mtl = (struct context_mtl*)calloc(1, sizeof(struct context_mtl)); | ||
NSWindow* nswin = glfwGetCocoaWindow(window); | ||
mtl->win = nswin; | ||
mtl->device = MTLCreateSystemDefaultDevice(); | ||
mtl->layer = [CAMetalLayer layer]; | ||
mtl->layer.device = mtl->device; | ||
mtl->layer.pixelFormat = MTLPixelFormatBGRA8Unorm; | ||
nswin.contentView.layer = mtl->layer; | ||
nswin.contentView.wantsLayer = YES; | ||
return (void *)mtl; | ||
} | ||
|
||
void ResizeMetalDrawable(void *ctx, int width, int height) { | ||
struct context_mtl *c = (struct context_mtl *)ctx; | ||
CGSize sz; | ||
sz.width = width; | ||
sz.height = height; | ||
c->layer.drawableSize = sz; | ||
} | ||
|
||
float GetMetalScaleFactor(void *ctx) { | ||
struct context_mtl *c = (struct context_mtl *)ctx; | ||
float scaleFactor = [c->win backingScaleFactor]; | ||
return scaleFactor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters