iphone - IOS replace CATiledLayer with OpenGL -


i have remote controller app, using catiledlayer display remote desktop. drawing made drawrect: method. have rare crashes when resizing remote screen's resolution.

i trying debug issue nothing helped, (after receiving advices smarter colleges) decided rewrite code using caeagllayer instead of catiledlayer.

i learning opengl es 2.0, tutorials building 3d models. want able apply texture appropriate area on view.

from reading , thinking consider that, when image redraw received, need convert texture, rect should redrew , generate verteces it, path varteces , texture vertex shader.

any ideas or advices welcome.

(please don't write like:"why want use opengl instead of catiledlayer?" if it's not best option want figure out how make work way).

ok, since there no responses question share i've got. first of using opengl es 2.0.

1) draw 2 triangles cover whole screen

enter image description here

to store vertices , triangles use following structs (color value not used in case):

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) after done wait whole remote screen load image , set image of whole screen texture using following code:

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

this code uses glkit's glktextureloader, can replaced glteximage2d().

after view looks similar this:

enter image description here

3) when update received need image of update , rect know part update:

-(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 uiview's upper left 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); } 

for drawing use custom shaders not glkview, nothing mapping texture vertices.

opengl drawing works faster catiledlayer, not extremely still. there few glitches investigate in future.

hope useful somebody. if need more details feel free contact me haawaplus@gmail.com

p.s

for paused catiledlayer -> opengl es investigation since got other work update answer when return opengl.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -