kallol
kallol

Reputation: 319

iOS: GLPaint can't draw on large frame

Apple example of freehand drawing GLPaint, painting using OpenGL ES can't draw with large frame. I need to draw on a large canvas more than about {2410, 1808}. But when I attempt to draw, get a message on console saying,

2012-06-05 14:29:40.780 GLPaint[3390:707] Frame of drawingView: {{-827.222, -567.004}, {2410, 1808}}
2012-06-05 14:29:40.884 GLPaint[3390:707] failed to make complete framebuffer object 8cd6 

On my code I have set the frame as-

//PaintingViewGL performing the freehand drawing of OpenGL ES
//drawingView is a UIView with dynamic frame size

paintingViewGL = [[PaintingViewGL alloc] initWithFrame:drawingView.frame];
paintingViewGL.backgroundColor = [UIColor clearColor];

[drawingView addSubview:paintingViewGL];
paintingViewGL.center = drawingView.center;
paintingViewGL.hidden = NO;

I am getting nice result with frame size {1435, 1076} and on a little larger frame like {1600, 1200} the drawing brush gone like a wave and start dancing on the screen. Sometimes I get Received memory warning. Level=1 on this case.

Upvotes: 1

Views: 995

Answers (2)

Brad Larson
Brad Larson

Reputation: 170319

For devices older than the iPad 2, the maximum texture size is 2048 x 2048, so you can't draw into a texture or framebuffer object larger than that. You'll just see errors and a black screen. On the newer devices (iPad 2, Retina iPad, iPhone 4S), this texture size limit has been increased to 4096 x 4096.

Your only solution for drawing on a larger canvas will be to create a tiling mechanism in OpenGL ES, like CATiledLayer does within Core Animation. Good luck with this, though, because it will be a significant undertaking if you're not all that familiar with OpenGL ES rendering.

Also, you will run into memory issues with very large scenes in OpenGL ES, particularly on older iOS devices. For the 1600x1200 image you mention seeing warnings about, every uncompressed frame takes up ~7.7 MB of memory by itself. If you have multiple layers or textures, that can quickly add up and use up your available memory on the device if you're not careful. For a 2410x1808 image, you're now looking at 17.4 MB per frame, so that's another reason you would want to tile this to only work with the tiles you need at that instant.

Upvotes: 3

Matic Oblak
Matic Oblak

Reputation: 16774

The size cap in this matter is same as for texture. Currently capped to 1<<11 (2048) and you can not create buffers larger then 2048 pixels in width or height. The only way I see to achieve the effect you want is to create more then 1 view or more then 1 frame buffer. If you really want/need to go through all that trouble, read a bit about FBO (frame buffer object).

Upvotes: 0

Related Questions