Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用metal替换cglayer #20

Open
roodkcab opened this issue Dec 22, 2020 · 6 comments
Open

使用metal替换cglayer #20

roodkcab opened this issue Dec 22, 2020 · 6 comments
Assignees

Comments

@roodkcab
Copy link
Member

roodkcab commented Dec 22, 2020

目前渲染使用的cglayer,苹果的高性能位图处理库。可以替换为新一代的metal进一步提高渲染性能

@roodkcab roodkcab self-assigned this Dec 22, 2020
@darkfall
Copy link
Collaborator

Its a big change, but pretty doable. Thanks to Gac itself handles the UI layer, its way easier than dealing with Cocoa friends without internal knowledge. You can easily get to hundreds of fps using Metal.

CoreText layer is still required to get the Glyph bitmap. It won't be perfect (exactly the same as macOS text rendering due to some missing APIs in CG / CT). Or maybe keep the NSTextStorage stuff and render to offline texture & blit (much slower though). Or switch to something like Freetype but then text will look very different from what macOS renders natively.

@roodkcab
Copy link
Member Author

我感觉CoreText是肯定要保留的,不然整个Glyph都要重新做,不太现实。换freetype的话不知道能不能通过苹果商店的审核呢。我先用metal试试渲染coretext。目前想到几个方案,得做做看才知道用哪个合适。

@darkfall
Copy link
Collaborator

darkfall commented Dec 23, 2020

FT没啥问题,游戏以前FT的多。但是效果看着差别就大了

@roodkcab
Copy link
Member Author

用ft的原因是不是保留coretext计算字符位置之类东西还要借助cpu,只是将计算出来后的位图可以用gpu来显示?如果是这样那可能没啥加速效果,不知道理解得对不对。

@darkfall
Copy link
Collaborator

本质上他们是类似的,但是FT少很多东西。
用CT/CG是因为给定一串文字,在不同字体大小,文字内容,背景前景颜色,控件大小,渲染出的结果不一定是一样的(quantization, dialation, fitting, style)。所以要用Metal获得和水果一样的文字渲染效果必然需要CT/CG。但是问题是很多东西并不是API所以从CT/CG获取的单文字的Glyph Bitmap以及给定Transform的位置不是那么容易,或者说想要兼容App Store的情况下基本上不可能。
目前的实现只是单纯的NSLayoutManager:drawGlyphsForGlyphRange。所以想完全切到Metal就有取舍了

@roodkcab
Copy link
Member Author

用sdf试了一下,英文字符倒还可以,中文就不行了。主要还是因为缺失和Glyph信息相关的api吧,所以目前还有比sdf更合适处理这个问题的办法吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants