openGL ES视网膜支持 [英] openGL ES retina support
问题描述
我正试图让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.
编辑(12/22/2010):回答您的进一步问题,查看avTouch示例代码显示该代码的当前版本在查找时出错提升OpenGL托管视图的范围,而不是使用renderbuffer的支持宽度和高度。使用非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.
要解决此问题,请替换,代码如下:
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屋!