olveMultisampleFramebufferAPPLE生

olveMultisampleFramebufferAPPLE生

本文介绍了ResolveMultisampleFramebufferAPPLE生成INVALID_OPERATION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么glResolveMultisampleFramebufferAPPLE会产生错误1282(0x0502,GL_INVALID_OPERATION).

I can't figure out, why glResolveMultisampleFramebufferAPPLE generates error 1282 (0x0502, GL_INVALID_OPERATION).

设置代码:

glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

glGenRenderbuffers(1, &colorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(id<EAGLDrawable>)self.layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);

glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE) {
    NSLog(@"failed to make complete framebuffer object %x", status);
}

glGenFramebuffers(1, &sampleFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);

glGenRenderbuffers(1, &sampleColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleColorRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_RGBA8_OES, backingWidth, backingWidth);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, sampleColorRenderbuffer);

glGenRenderbuffers(1, &sampleDepthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, sampleDepthRenderbuffer);
glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16_OES, backingWidth, backingWidth);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, sampleDepthRenderbuffer);

渲染代码:

glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

GLfloat vertices[] = {
    1.0f, 1.0f, 0.0f,
    2.0f, 4.0f, 0.0f,
    1.0f, 3.0f, 0.0f
};
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);

glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, sampleFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, framebuffer);
glResolveMultisampleFramebufferAPPLE();
NSLog(@"Error: %d", glGetError()); // <<< Here I get 1282

const GLenum discards[]  = { GL_DEPTH_ATTACHMENT };
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, discards);

glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];

可以在Bitbucket上找到完整的源代码: https://bitbucket.org/amjaliks/gl2/src

Full source can be found at Bitbucket: https://bitbucket.org/amjaliks/gl2/src

推荐答案

我将backingWidth两次传递给glRenderbufferStorageMultisampleAPPLE.因此,我得到了具有不同大小的渲染缓冲区,这会导致INVALID_OPERATION.

I pass backingWidth twice to glRenderbufferStorageMultisampleAPPLE. Thus, I get renderbuffers with different size, and it causes INVALID_OPERATION.

这篇关于ResolveMultisampleFramebufferAPPLE生成INVALID_OPERATION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:28