openGL ES 视网膜支持 [英] openGL ES retina support

查看:18
本文介绍了openGL ES 视网膜支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在 CALevelMeter 类中,我尝试了以下方法:

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;

}

并将 contentScaleFactor 设置为2".太好了,这是意料之中的.但随后在 layoutSubviews 中,CALevelMeter 框架仍然是应有的 1/2.

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.

有什么想法吗?

推荐答案

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

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.

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

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);

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

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.

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

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

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

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.

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

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.

这篇关于openGL ES 视网膜支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆