Overview: Coming from this, i changed to ES 3.0, and after reading and trying for a day, i'm stuck once again in achieving Antialiasing. I'm testing this on iOS simulator.
Issue: My drawings are visible, but they are the same as there is no antialiasing. I have tried using ObjC's [self.glkView setDrawableMultisample:GLKViewDrawableMultisample4X];
and the difference is notable. Meaning my multisampling isnt working at all. Is there something i'm missing?
Resources used: I've read Apple's guide(using es3 update) as a base guide. Kronos wiki as additional guide (tho it uses glEnable(GL_MULTISAMPLE)
which isnt present in ES3... something similar i found is the sample coverage
and i've tried enabling that as well, but still no luck).
Code:
/*
setting up shader program code...
*/
// initializing frame buffers
glGenFramebuffers(1, &sampleFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
glGenRenderbuffers(1, &sampleColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleColorRenderbuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, sampleColorRenderbuffer);
glGenRenderbuffers(1, &sampleDepthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleDepthRenderbuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, sampleDepthRenderbuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
printf("Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
// Making Draw FrameBuffer
glGenFramebuffers(1, &resolveFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, resolveFrameBuffer);
glGenRenderbuffers(1, &resolveColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, resolveColorRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, resolveColorRenderbuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
printf("Failed to make complete framebuffer2 object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
// Cleaning buffer steps
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
When this is done, in my drawing code, after drawing has been done i do this:
*use gl program*
*drawarrays*
glBindFramebuffer(GL_READ_FRAMEBUFFER, sampleFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveFrameBuffer);
glBlitFramebuffer(0, 0, _Width, _Height, 0, 0, _Width, _Height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
checkGLError("glBlitFramebuffer");
I figured it out, it was because of how i was testing my drawings. I had set the fragment shader to always give pure red color (r:1,g:0,b:0,a:1)
. I was doing this because my android project was set up by someone else and was not fully completed when i took a copy. To avoid work on that i improvised and set color to red so i can see what is being drawn on a black background (dumb idea).
TLDR: Overwriting the fragment shader output made sure any antialiasing that was being done was overwritten. Setting it back to what the vertex shader was giving fixed it.