glBlitFramebuffer 无效操作
glBlitFramebuffer Invalid Operation
我一直在弄乱帧缓冲区并渲染到纹理,我遇到了需要将它们块状化。同样,在某些机器上,我在glBlitFramebuffer
呼叫后立即收到GL_INVALID_OPERATION
。绑定到帧缓冲的每个纹理都以完全相同的方式设置,所有相同的大小和参数。此外,当我尝试将整个纹理(以前成功渲染到)到另一个帧缓冲区时,只有要写入的目标"矩形"小于要读取的矩形(例如,当我想将其块传输到屏幕的四分之一时),它也抛出了一个GL_INVALID_OPERATION
。
编辑: 实际上,每当要读取和绘制的矩形具有不同的大小时,它总是会抛出错误,所以我无法快速处理不同大小的纹理,或者相同大小但大小不同的"渲染"区域......?
每次我到手动生成的帧缓冲时,状态都会通过glCheckFramebufferStatus
进行检查,并且它总是返回GL_FRAMEBUFFER_COMPLETE
.
有史以来最大的截图-,请参阅下面的较短的"源代码",显然有几个C++错误并且不完整,但它仅适用于GL调用
当我调用视口的最后一个方法(视口::blit)并将屏幕帧缓冲作为目标(通过传递 NULL)时,会发生 OpenGL 错误。它首先设置自己的帧缓冲区的读取缓冲区(已经设置了绘制缓冲区),然后调用 RenderTarget::blit 调用 glBlitFramebuffer
。在 blit 方法中,它绑定了两个缓冲区,您可以看到它在那里调用glCheckFramebufferStatus
,这不会返回错误。
我一直在一遍又一遍地阅读这篇文章,但我似乎找不到导致它的错误。当我使用颜色缓冲区时,我使用 GL_LINEAR
,否则我使用 GL_NEAREST
所有颜色缓冲区都使用 GL_RGB32F
作为内部格式,深度缓冲区(我从不 blit)使用GL_DEPTH_COMPONENT32F
EDIT,一个较短的例子,只是获取了所有 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
以及帧缓冲/纹理创建:
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
经过一番仔细阅读,我发现多重采样的差异是问题所在。"主"FBO 是由 SFML 设置的,因此只需将启动时的抗锯齿级别设置为 0,问题就部分解决了。
如果绘制/读取矩形的大小不相等,它现在会变快,但它在一些应该工作的机器上不断崩溃。
- 为什么在popback()操作之后,它仍然打印完整的矢量
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如何修复无效的API密钥,IP或操作权限错误?
- glteximage3d抛出错误1282(无效操作)
- 调用 vector.erase() 函数时指针操作无效错误
- 如何在OpenGL中使用纹理?(无效操作错误:1282)
- 无效操作数以二进制读取结构的阵列
- 无故对 glend 的操作无效
- 非逻辑代码流 /无效的向量操作
- Python扩展在操作大列表时会创建无效指针
- glBlitFramebuffer 无效操作
- 省略复制操作后对象无效
- 在 && 语句的后半部分进行无效操作是否安全?
- 无法找出错误原因 跨线程操作从回调到 C# C++无效
- 展开操作期间遇到无效或未对齐的堆栈
- 使用核心配置文件交换缓冲区使用了无效操作
- 如何在不陷入无效输入的情况下重复此操作
- 哪些操作为无效迭代器定义
- 操作无效