0

我即将在 Mac 上的 Objective-C 中创建一个粒子模拟器,使用 Core Graphics 进行渲染。我已经计算出 Core Graphics 能够使用 CGContextFillRect 每秒向视图渲染大约 1.8*10^6 1x1 彩色像素,这可以计算出每帧渲染到屏幕的大约 250,000 个 1x1 粒子,以使 FPS 保持在60.

250,000 个粒子的限制并不是那么好——我希望这个数字更高。将这么多 1x1 彩色像素渲染到视图的最有效方法是什么?有没有办法更好地利用 GPU?

这是我一直在使用的代码:

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];

    CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
    CGContextSetRGBFillColor (ctx, 1, 0, 0, 1);
    CFTimeInterval t1 = CFAbsoluteTimeGetCurrent();
    CGRect point = CGRectMake(10.0f, 10.0f, 1.0f, 1.0f);

    for (int i = 0; i < 20000000; i++) {
        CGContextFillRect (ctx, point);
    }

    NSLog(@"%.10f", CFAbsoluteTimeGetCurrent() - t1);
}
4

0 回答 0