iDevGames Forums
glCopyTexSubImage2D vs antialiasing on iPhone? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: glCopyTexSubImage2D vs antialiasing on iPhone? (/thread-7863.html)



glCopyTexSubImage2D vs antialiasing on iPhone? - Mark Levin - Jul 15, 2010 09:35 AM

Trying to grab an antialiased framebuffer into a texture throws GL_INVALID_OPERATION (and turning off AA with no other changes works). Is there some trick to doing it?


RE: glCopyTexSubImage2D vs antialiasing on iPhone? - Bersaelor - Jul 15, 2010 10:06 AM

(Jul 15, 2010 09:35 AM)Mark Levin Wrote:  Trying to grab an antialiased framebuffer into a texture throws GL_INVALID_OPERATION (and turning off AA with no other changes works). Is there some trick to doing it?

Well I use glReadPixels to read my screen, and after I added AA I had to change my code because I couldn't read straight away from the "msaaFrameBuffer".
So before I read the Image I added:
Code:
- (void) prepareForPicture {
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, resolveFramebuffer);
}
to bind the buffer.

What I do to read the Pixels of the screen
Code:
    glReadPixels(1, 30, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pxlData);
    
    CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
    CGContextRef context=CGBitmapContextCreate(pxlData, width, height, 8, width*sizeof(uint32_t), colorSpace, kCGImageAlphaNoneSkipLast);
    //CGContextRef context=CGBitmapContextCreate(pxlData, 300, 300, 8, 300*sizeof(uint32_t), colorSpace, kCGImageAlphaLast);
    CGImageRef image=CGBitmapContextCreateImage(context);
    CGImageRef smallIm=[self resizeCGImage:image toWidth:96 andHeight:126];
    
    UIImage *resultUIImage=[UIImage imageWithCGImage:smallIm];
I guess you could use that imagedata for a tex.


RE: glCopyTexSubImage2D vs antialiasing on iPhone? - Frogblast - Jul 15, 2010 04:04 PM

You cannot read directly from a multisample renderbuffer. You must use ResolveFramebuffer() to produce a non-multisampled image first. This applies to both ReadPixels and CopyTexImage.

That being said, why are you using CopyTexImage instead of rendering directly to the texture?


RE: glCopyTexSubImage2D vs antialiasing on iPhone? - Mark Levin - Jul 15, 2010 06:11 PM

Thanks. This effect was a last-minute addition to the render pipeline that grabs the current screen image and transforms it (it's the zoom-and-blur effect when starting a fight in Warpgate). Seemed more efficient than repeating the entire render process, and it worked fine without AA.


RE: glCopyTexSubImage2D vs antialiasing on iPhone? - Bersaelor - Jul 16, 2010 01:46 AM

(Jul 15, 2010 06:11 PM)Mark Levin Wrote:  Seemed more efficient than repeating the entire render process, and it worked fine without AA.

Well even with rebinding the resolve-framebuffer you don't rerender everything. AFAIK bot the msaabuffer and the resolvebuffer still have their rendered data in ram, binding either just tells OpenGL where you want to read your pixels/image data.