openGL ES 视网膜支持

发布于 2024-10-08 09:41:12 字数 850 浏览 3 评论 0原文

我正在尝试让 avTouch 示例代码应用程序在视网膜显示屏上运行。有人这样做过吗?

在 CALevelMeter 类中,我尝试了以下操作:

- (id)initWithCoder:(NSCoder *)coder {
 if (self = [super initWithCoder:coder]) {
      CGFloat f = self.contentScaleFactor;
      if ([self respondsToSelector:@selector(contentScaleFactor)])
      {
           self.contentScaleFactor = [[UIScreen mainScreen] scale];
      }
      f = self.contentScaleFactor;

      _showsPeaks = YES;
      _channelNumbers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:0], nil];
      _vertical = NO;
      _useGL = YES;
      _meterTable = new MeterTable(kMinDBvalue);
      [self layoutSubLevelMeters];
      [self registerForBackgroundNotifications];
 }
 return self;

}

并将 contentScaleFactor 设置为“2”。太好了,这是预料之中的。但在layoutSubviews中,CALevelMeter框架仍然是应有的1/2。

有什么想法吗?

I'm trying to get the avTouch sample code app to run on the retina display. Has anyone done this?

In the CALevelMeter class, I've tried the following:

- (id)initWithCoder:(NSCoder *)coder {
 if (self = [super initWithCoder:coder]) {
      CGFloat f = self.contentScaleFactor;
      if ([self respondsToSelector:@selector(contentScaleFactor)])
      {
           self.contentScaleFactor = [[UIScreen mainScreen] scale];
      }
      f = self.contentScaleFactor;

      _showsPeaks = YES;
      _channelNumbers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:0], nil];
      _vertical = NO;
      _useGL = YES;
      _meterTable = new MeterTable(kMinDBvalue);
      [self layoutSubLevelMeters];
      [self registerForBackgroundNotifications];
 }
 return self;

}

and it sets the contentScaleFactor to "2". Great, that was expected. But then in the layoutSubviews, CALevelMeter frame is still 1/2 of what it should be.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-10-15 09:41:12

帧以点为单位,而不是像素。当比例因子应用于托管 CAEAGLLayer 的 UIView 时,它将是像素的两倍,但其帧点大小将保持不变。

如果您使用如下代码查看附加到 CAEAGLLayer 的颜色渲染缓冲区的背景宽度和高度:

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

您应该看到 Retina 显示器上渲染缓冲区的宽度和高度是标准 iPhone 显示器上的值的两倍。

上面显示的代码应该会在 Retina 显示屏上产生漂亮、清晰的渲染效果。

编辑(12/22/2010):为了回答您的进一步问题,查看 avTouch 示例代码表明该代码的当前版本在查找 OpenGL 托管视图的边界时出错,而不是使用支持渲染缓冲区的宽度和高度。使用非 1.0 比例因子时,这将导致 OpenGL 内容以一半大小绘制。

要解决此问题,请将 GLLevelMeter 中的 _drawView 中的相应部分替换为以下代码:

if (_vertical)
{
    glTranslatef(0., _backingWidth, 0.);
    glScalef(1., -1., 1.);
    bds = CGRectMake(0., 0., _backingWidth, _backingHeight);
} else {
    glTranslatef(0., _backingHeight, 0.);
    glRotatef(-90., 0., 0., 1.);
    bds = CGRectMake(0., 0., _backingHeight, _backingWidth);
}

这将使所有内容在适当的像素空间中工作,并导致在均衡器中以正确的尺寸进行清晰的渲染。我已就此提交了错误报告。

Frames are in points, not pixels. When a scale factor is applied to the UIView hosting your CAEAGLLayer, it will be double the pixels, but its frame point size will remain the same.

If you look at the backing width and height for the color renderbuffer attached to the CAEAGLLayer using code like the following:

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

you should see that the width and height of the renderbuffer on a Retina display are twice the values they are on a standard iPhone display.

The code you show above should cause nice, sharp rendering on a Retina display.

EDIT (12/22/2010): In response to your further question, looking at the avTouch sample code shows that the current version of that code makes a mistake in looking up the bounds of the OpenGL-hosting view, rather than using the backing width and height of the renderbuffer. With a non-1.0 scale factor, this will cause the OpenGL content to be drawn at half size.

To fix this, replace the appropriate section within _drawView in GLLevelMeter with the following code:

if (_vertical)
{
    glTranslatef(0., _backingWidth, 0.);
    glScalef(1., -1., 1.);
    bds = CGRectMake(0., 0., _backingWidth, _backingHeight);
} else {
    glTranslatef(0., _backingHeight, 0.);
    glRotatef(-90., 0., 0., 1.);
    bds = CGRectMake(0., 0., _backingHeight, _backingWidth);
}

This will cause everything to work in the appropriate pixel space, and lead to crisp rendering at the correct size in the equalizer. I've filed a bug report on this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文