我一直在搞乱帧缓冲区并渲染到纹理,我遇到了blit它们的需要。在某些计算机上,我在GL_INVALID_OPERATION
电话后立即获得glBlitFramebuffer
。绑定到帧缓冲区的每个纹理都以完全相同的方式设置,所有相同的大小和参数。此外,当我尝试将一个完整的纹理(先前成功渲染到)另一个帧缓冲区blit时,只有要写入的目标“矩形”小于要读取的矩形(例如,当我想将其渲染到四分之一时屏幕),它也会抛出一个GL_INVALID_OPERATION
。
编辑: 实际上,每当要读取和绘制的矩形具有不同的大小时,它总是会抛出错误,因此我无法对不同大小的纹理进行blit,或者相同的尺寸,但不同大小的'渲染到'区域......?
每次我对手动生成的帧缓冲区进行blit时,都会通过glCheckFramebufferStatus
检查状态,并始终返回GL_FRAMEBUFFER_COMPLETE
。
-BIGGEST SNIP EVER-,请参阅下面的更短'源代码',显然有几个C ++错误而且不完整,但仅适用于GL调用
当我使用屏幕帧缓冲区作为目标(通过传递NULL)调用视口的最后一个方法(Viewport :: blit)时,会发生OpenGL错误。它首先设置自己的帧缓冲区的读缓冲区(已经设置了绘制缓冲区),然后调用RenderTarget :: blit调用glBlitFramebuffer
。在blit方法中它绑定了两个缓冲区,你可以看到它调用glCheckFramebufferStatus
那里没有返回错误。
我一直在阅读this一遍又一遍,但我似乎无法找到导致它的错误。当我对颜色缓冲区进行blit时,我使用GL_LINEAR
,否则我使用GL_NEAREST
所有颜色缓冲区使用GL_RGB32F
作为内部格式,深度缓冲区(我从不blit)使用GL_DEPTH_COMPONENT32F
编辑,一个较短的例子,只是接受了所有GL调用并填写了我使用的参数
glBindFramebuffer(GL_READ_FRAMEBUFFER, _GL_Framebuffer);
glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
// OpenGL error check, does not return an error
glBindFramebuffer(GL_READ_FRAMEBUFFER, _GL_Framebuffer);
GLenum status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
// Some error checking, fortunately status always turns out to be complete
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, target, (target == GL_COLOR_BUFFER_BIT) ? GL_LINEAR : GL_NEAREST);
// If the source/destination read/draw rectangles are different in size, GL_INVALID_OPERATION is cought here
Framebuffer / Texture创建:
glGenFramebuffer(1, &_GL_Framebuffer);
glGenTextures(1, &_GL_ZBuffer);
glBindTexture(GL_TEXTURE_2D, _GL_ZBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, screenWidth, screenHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, _GL_Framebuffer);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT + 0, _GL_ZBuffer, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
int writeIndices[BUFFER_COUNT];
for(unsigned int i = 0; i < BUFFER_COUNT; ++i)
{
writeIndices[i] = i;
glGenTextures(1, &_GL_Texture);
glBindTexture(GL_TEXTURE_2D, _GL_Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, screenWidth, screenHeight, 0, GL_RGB, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, _GL_Framebuffer);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, _GL_Texture, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// In the actual code each texture is obviously saved in an object
}
GLenum *enums = new GLenum[BUFFER_COUNT];
for(unsigned int i = 0; i < BUFFER_COUNT; ++i)
{
// Get index and validate
int index = *(indices + i); // indices = writeIndices
if(index < 0 || index >= maxAttachments)
{
delete[] enums;
return false;
}
// Set index
enums[i] = GL_COLOR_ATTACHMENT0 + index;
}
// Set indices
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _GL_Framebuffer);
glDrawBuffers(BUFFER_COUNT, enums);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
delete[] enums;
// OpenGL error check, no errors
答案 0 :(得分:6)
仔细阅读后,我发现多重采样的区别在于问题。 “主要”FBO由SFML设置,因此只需将启动时的抗锯齿级别设置为0,问题就是部分解决了。
如果绘制/读取矩形的大小不相等,它现在会突然显示,但它会在某些支持它工作的机器上崩溃。