根据OpenGL documentation我应该能够将像素读取源设置为任何 GL_COLOR_ATTACHMENTi
。但是,当我尝试这样做时,glGetError
给我一个 GL_INVALID_ENUM
错误。随后的 glReadPixels
只是读取后台缓冲区。
glGetString(GL_VERSION)
报告的版本是 4.2.11627 Core Profile Forward-Compatible Context
。我在 Linux 上运行并安装了 fglrx ati 驱动程序(版本 8.96.7-120312a-135598C-ATI)。
我检查过我的 FBO 是否已绑定(bind)且完整。我还验证了 glGetError
不是由之前的调用设置的。
它已经失败了(我希望这里有一个错误,但是 INVALID_OPERATION
而不是 INVALID_ENUM
):
#include <iostream>
#include "Window.h" // My own class based on sfml, but I am sure context creation works fine
#include <glload/gll.hpp>
#include <glload/gl_core.hpp>
int main()
{
const unsigned int screenW = 1280, screenH = 720;
Window w(screenW, screenH, 32, false);
if (glload::LoadFunctions() == glload::LS_LOAD_FAILED)
{
std::cerr << "glload failed to load" << std::endl;
return -1;
}
gl::ReadBuffer(gl::GL_COLOR_ATTACHMENT0);
if( gl::GetError() == gl::GL_INVALID_ENUM)
{
std::cerr << "Invalid enum error" << std::endl;
return -1;
}
return 0;
}
此调用可能触发 INVALID_ENUM
是否还有其他原因,或者更有可能是我正在使用的 OpenGL 实现被窃听了?
最佳答案
However, when I try this, glGetError gives me a GL_INVALID_ENUM error. A subsequent glReadPixels simply reads the back buffer.
如果您正在从后台缓冲区读取,那么这意味着 default framebuffer 仍然绑定(bind)。和 glReadBuffer
为当前帧缓冲区设置读取缓冲区。
默认的帧缓冲区没有GL_COLOR_ATTACHMENT
。因此,将这些图像之一设置为读取缓冲区是错误的。您必须先绑定(bind) FBO ,然后设置读取缓冲区。请注意,glReadBuffer
将帧缓冲区的绑定(bind)设置为 GL_READ_FRAMEBUFFER
,而不是 GL_DRAW_FRAMEBUFFER
。因此,请确保它绑定(bind)到正确的位置。
关于linux - 将 readbuffer 设置为 FBO 颜色附件失败并出现无效枚举错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11493714/