-
-
Save notedit/91b214eae1f5eba9f6d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Framebuffer | |
Multisampled colour render buffer attached to a texture | |
Multisampled depth buffer | |
But you cannot do this. D: You have to have the following: | |
Multisampled framebuffer: | |
Multisampled colour render buffer (Not attached to a texture) | |
Multisampled depth render buffer | |
Normal framebuffer: | |
Colour render buffer attached to a texture. This is what will be written to by glResolveMultisampleFramebufferAPPLE() and what we will use to render the result. | |
No depth buffer. | |
I.e. you have to copy the results of the multisampled render to a whole new framebuffer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
glGenTextures(1, &texture); | |
glBindTexture(GL_TEXTURE_2D, texture); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
glGenFramebuffers(1, &resolved_framebuffer); | |
glBindFramebuffer(GL_FRAMEBUFFER, resolved_framebuffer); | |
glGenRenderbuffers(1, &resolvedColorRenderbuffer); | |
glBindRenderbuffer(GL_RENDERBUFFER, resolvedColorRenderbuffer); | |
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | |
glGenFramebuffers(1, &framebuffer); | |
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
glGenRenderbuffers(1, &colorRenderbuffer); | |
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); | |
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_RGBA8_OES, width, height); | |
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer); | |
glGenRenderbuffers(1, &depthRenderbuffer); | |
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); | |
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, width, height); | |
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer); | |
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER) ; | |
if(status != GL_FRAMEBUFFER_COMPLETE) { | |
NSLog(@"failed to make complete framebuffer object %x", status); | |
} | |
// Render my scene | |
glBindFramebuffer( GL_FRAMEBUFFER, framebuffer ); | |
glViewport(0,0,width,height); | |
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); | |
// Draw scene | |
// Then bind default framebuffer | |
glBindFramebuffer( GL_FRAMEBUFFER, 1 ); | |
// Draw other things | |
// Now resolve the multisampling into the other fbo | |
glBindFramebuffer( GL_READ_FRAMEBUFFER_APPLE, framebuffer ); | |
glBindFramebuffer( GL_DRAW_FRAMEBUFFER_APPLE, resolved_framebuffer ); | |
glResolveMultisampleFramebufferAPPLE(); | |
glUseTexture( GL_TEXTURE_2D, texture ); | |
// Draw with texture |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment