使用 glBlitFramebuffer 的多重采样不工作 opengl es 3.0
Multisampling with glBlitFramebuffer not working opengl es 3.0
概览: 来自this,我换了ES 3.0,看了一天,试了一天,又一次卡在了Antialiasing的实现上。我正在 iOS 模拟器上对此进行测试。
问题:我的画是可以看得见的,但是没有抗锯齿一样。我试过使用 ObjC 的 [self.glkView setDrawableMultisample:GLKViewDrawableMultisample4X];
并且差异很明显。这意味着我的多重采样根本不起作用。有什么我想念的吗?
使用的资源:我已经阅读了 Apple's guide(using es3 update) as a base guide. Kronos wiki 作为附加指南(它使用了 glEnable(GL_MULTISAMPLE)
,ES3 中不存在……类似的东西我找到的是 sample coverage
,我也尝试启用它,但仍然没有成功)。
代码:
/*
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);
完成后,在我的绘图代码中,完成绘图后我会这样做:
*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");
我想出来了,这是因为我测试我的图纸的方式。我已将片段着色器设置为始终提供纯红色 (r:1,g:0,b:0,a:1)
。我这样做是因为我的 android 项目是由其他人设置的,并且在我复制时没有完全完成。为了避免工作,我即兴创作并将颜色设置为红色,这样我就可以看到在黑色背景上绘制的内容(愚蠢的想法)。
TLDR:覆盖片段着色器输出可确保覆盖任何正在执行的抗锯齿。将其设置回顶点着色器提供的固定值。
概览: 来自this,我换了ES 3.0,看了一天,试了一天,又一次卡在了Antialiasing的实现上。我正在 iOS 模拟器上对此进行测试。
问题:我的画是可以看得见的,但是没有抗锯齿一样。我试过使用 ObjC 的 [self.glkView setDrawableMultisample:GLKViewDrawableMultisample4X];
并且差异很明显。这意味着我的多重采样根本不起作用。有什么我想念的吗?
使用的资源:我已经阅读了 Apple's guide(using es3 update) as a base guide. Kronos wiki 作为附加指南(它使用了 glEnable(GL_MULTISAMPLE)
,ES3 中不存在……类似的东西我找到的是 sample coverage
,我也尝试启用它,但仍然没有成功)。
代码:
/*
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);
完成后,在我的绘图代码中,完成绘图后我会这样做:
*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");
我想出来了,这是因为我测试我的图纸的方式。我已将片段着色器设置为始终提供纯红色 (r:1,g:0,b:0,a:1)
。我这样做是因为我的 android 项目是由其他人设置的,并且在我复制时没有完全完成。为了避免工作,我即兴创作并将颜色设置为红色,这样我就可以看到在黑色背景上绘制的内容(愚蠢的想法)。
TLDR:覆盖片段着色器输出可确保覆盖任何正在执行的抗锯齿。将其设置回顶点着色器提供的固定值。