这是简短的问题:
对于某些图层合成,我必须在CGContext中渲染OpenGL纹理.最快的方法是什么?
思念至今:
显然,调用renderInContext不会捕获OpenGL内容,并且glReadPixels太慢了.
对于某些"上下文",我在一个图层的委托类中调用此方法:
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
Run Code Online (Sandbox Code Playgroud)
我考虑使用CVOpenGLESTextureCache,但这需要额外的渲染,似乎在渲染后需要进行一些复杂的转换.
这是我(可怕的)现在的实施:
glBindRenderbuffer(GL_RENDERBUFFER, displayRenderbuffer);
NSInteger x = 0, y = 0, width = backingWidth, height = backingHeight;
NSInteger dataLength = width * height * 4;
GLubyte *data = (GLubyte *) malloc(dataLength * sizeof(GLubyte));
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
ref, NULL, true, …Run Code Online (Sandbox Code Playgroud)