Reputation: 51
My Code is :
glGenFramebuffers(1, &_hFBO);
glGenRenderbuffers(1, &(_hRender[colorAttachment]));
glBindFramebuffer(GL_FRAMEBUFFER, _hFBO);
glBindRenderbuffer(GL_RENDERBUFFER, _hRender[colorAttachment]);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, format, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 +colorAttachment,GL_RENDERBUFFER, _hRender[colorAttachment]);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glGetMultisamplefv(GL_SAMPLE_POSITION, p_index[0], val);
where,
Samples =4
format=GL_RGBA
width=height=512
p_index[0]=1
In this ,it is giving me GL_INVALID_VALUE for glGetMultisamplefv.
Note: If I call glCheckFramebufferStatus before attaching default frame buffer object (glBindFramebuffer(GL_FRAMEBUFFER, 0)) also, then it is not giving any error.
Does it necessary to check glCheckFramebufferStatus before attaching default FBO.?
Upvotes: 0
Views: 147
Reputation: 54592
First of all, the glCheckFramebufferStatus()
call should not make a difference at all. It only checks the status of the current framebuffer, and returns either GL_FRAMEBUFFER_COMPLETE
if the framebuffer is ok, or one of various possible error codes otherwise. Since you're not looking at the return value, the call does not serve any purpose in your code fragment.
The way I understand your code, you're trying to query the sample positions of the multisampled FBO you just set up. But that's not what the code is doing. Since you bind the default framebuffer before the glGetMultisamplefv()
call, the query would apply to the default framebuffer. Since your default framebuffer is not multisampled, that will give an error.
The main thing you need to do is rearrange the sequence of some of the calls, primarily to call glGetMultisamplefv()
while your new FBO is bound:
glGenFramebuffers(1, &_hFBO);
glBindFramebuffer(GL_FRAMEBUFFER, _hFBO);
glGenRenderbuffers(1, &(_hRender[colorAttachment]));
glBindRenderbuffer(GL_RENDERBUFFER, _hRender[colorAttachment]);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttachment,
GL_RENDERBUFFER, _hRender[colorAttachment]);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
// we got a problem
}
GLint sampleCount = 0;
glGetIntegerv(GL_SAMPLES, &sampleCount);
if (sampleCount == 0) {
// we got a problem
}
for (int sampleIdx = 0; sampleIdx < sampleCount; ++sampleIdx) {
GLfloat val[2] = {0.0f, 0.0f};
glGetMultisamplefv(GL_SAMPLE_POSITION, sampleIdx, val);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
I would also change the format of the renderbuffer to RGBA8
, since the internalformat
for glRenderbufferStorage()
is normally supposed to be a sized format.
BTW: Starting variable names with an underscore is not recommended. Names starting with an underscore are reserved for internal use by the compiler and standard libraries.
Upvotes: 1