Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL ES Multisample anti-aliasing issues
    text
    copied!<p>I added in multisample anti-aliasing to my OpenGL ES iOS app, but I'm noticing a few strange things. </p> <p>I followed the steps here: <a href="https://developer.apple.com/library/ios/documentation/3ddrawing/conceptual/opengles_programmingguide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html" rel="nofollow noreferrer">https://developer.apple.com/library/ios/documentation/3ddrawing/conceptual/opengles_programmingguide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html</a></p> <ol> <li>The anti-aliasing works awesome in the simulator. I notice a major difference in line jags when enabling and disabling it (in iOS simulator). It does not seem to work on my iPad mini though. The lines are still jagged. Any ideas?</li> </ol> <p><img src="https://i.stack.imgur.com/lx7FT.png" alt="ick!"></p> <ol start="2"> <li>After implementing the MSAA, in the OpenGL ES Analyzer I'm noticing this occurring quite a bit: "Unoptimized MSAA Resolve"</li> </ol> <p>The two lines below seems to fix the "Unoptimized MSAA Resolve", but the color attachment discard seems to make my lines no longer black and they disappear: </p> <pre><code>const GLenum discards[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES}; glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, discards); </code></pre> <p>MSAA creation: </p> <pre><code>// Generate IDs for a framebuffer object and a color renderbuffer glGenFramebuffersOES(1, &amp;viewFramebuffer); glGenRenderbuffersOES(1, &amp;viewRenderbuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer) // allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view). [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id&lt;EAGLDrawable&gt;)self.layer]; glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &amp;backingWidth); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &amp;backingHeight); // For this sample, we also need a depth buffer, so we'll create and attach one via another renderbuffer. glGenRenderbuffersOES(1, &amp;depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); if(isMsaaEnabled) { glGenFramebuffersOES(1, &amp;msaaFramebuffer); glGenRenderbuffersOES(1, &amp;msaaRenderbuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaRenderbuffer); // 4X MSAA glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_RGBA8_OES, backingWidth, backingHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaRenderbuffer); glGenRenderbuffersOES(1, &amp;msaaDepthbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaDepthbuffer); glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, msaaDepthbuffer); if (glCheckFramebufferStatus(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) { NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER_OES)); return NO; } } </code></pre> <p>Resolve:</p> <pre><code>if (isMsaaEnabled) { glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, msaaFramebuffer); glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, viewFramebuffer); glResolveMultisampleFramebufferAPPLE(); const GLenum discards[] = {GL_COLOR_ATTACHMENT0_OES, GL_DEPTH_ATTACHMENT_OES}; glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, discards); } glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); [context presentRenderbuffer:GL_RENDERBUFFER_OES]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload