好的,由于没有人回答我的问题,我将分享我所拥有的。
首先,我使用的是 OpenGL ES 2.0。
1)我画了两个三角形来覆盖整个屏幕
为了存储顶点和三角形,我使用以下结构(Color 值在我的情况下不使用):
typedef struct {
float Position[3];
float Color[4];
float TexCoord[2];
} Vertex;
const Vertex Vertices[] = {
{{1, -1, 0}, {1, 0, 0, 1}, {1, 0}},
{{1, 1, 0}, {0, 1, 0, 1}, {1, 1}},
{{-1, 1, 0}, {0, 0, 1, 1}, {0, 1}},
{{-1, -1, 0}, {0, 0, 0, 1}, {0, 0}}
};
const GLubyte Indices[] = {
0, 1, 2,
2, 3, 0
};
2) 完成后,我等待整个远程屏幕加载图像,然后使用以下代码将整个屏幕的图像设置为 texture:
-(void)setupTextureFromCGImage:(CGImageRef)imageRef{
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:_snapshot.isImageMirrored],
GLKTextureLoaderOriginBottomLeft,
nil];
NSError * error;
GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:imageRef options:options error:&error];
if (info == nil) {
NSLog(@"Error loading file: %@", [error localizedDescription]);
return;
}
self.effect.texture2d0.name = info.name;
self.effect.texture2d0.enabled = true;
_bigTexture = info.name;
glBindTexture(GL_TEXTURE_2D, self.effect.texture2d0.name);
}
此代码使用 GLKit 的 GLKTextureLoader,但是可以简单地将其替换为 glteximage2d()。
之后的视图看起来像这样:
3) 当收到更新时,我们需要更新图像和矩形来知道要更新哪个部分:
-(void)loadSubImageTextureImageBuffer:(const char *)buffer inRect:(CGRect)rect
{
CGRect rectGL = rect;
rectGL.origin.y = _snapshot.imageRect.size.height - (rectGL.origin.y + rectGL.size.height);// convert coordinates from UIView's upper left to OpenGL's lower left
glTexSubImage2D(GL_TEXTURE_2D,
0,
rectGL.origin.x,
rectGL.origin.y,
rectGL.size.width,
rectGL.size.height,
GL_BGRA,
GL_UNSIGNED_BYTE,
buffer);
}
对于绘图,我使用自定义着色器而不是 GLKView,它们只会将纹理映射到顶点。
OpenGL 绘图的工作速度比 CATiledLayer 快,不是特别快,但仍然。有一些小故障,我将在未来进行调查。
希望这对某人有用。如果您需要更多详细信息,请随时与我联系
haawaplus@gmail.com
附言
现在我暂停了我的 CATiledLayer -> OpenGL ES 调查,因为我还有其他工作要做,但我会在返回 OpenGL 时更新我的答案。