glCopyTexSubImage2D vs antialiasing on iPhone?

Member
Posts: 177
Joined: 2002.08
Post: #1
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?
Quote this message in a reply
Member
Posts: 95
Joined: 2009.09
Post: #2
(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.
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #3
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?
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #4
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.
Quote this message in a reply
Member
Posts: 95
Joined: 2009.09
Post: #5
(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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Antialiasing and NSOpenGLView attributes Jar445 2 6,593 Jan 20, 2009 10:42 AM
Last Post: maximile
  Trouble with glCopyTexSubImage2D when using multisampled rendering TomorrowPlusX 11 5,303 Nov 1, 2006 02:54 PM
Last Post: OneSadCookie
  Quick question, will glCopyTexSubImage2D with with RECT textures? TomorrowPlusX 28 9,195 Jun 8, 2006 07:04 PM
Last Post: akb825
  antialiasing polygons honkFactory 37 16,088 Apr 3, 2006 09:19 AM
Last Post: akb825
  glCopyTexSubImage2D pkraft 3 3,936 Mar 8, 2005 01:59 PM
Last Post: pkraft