尝试在 OSX 中创建多个帧缓冲区对象而不是 Linux 时出现问题
Problems trying to create multiple Frame Buffer Objects in OSX but not Linux
我正在编写一个包含小散点图集合的应用程序(称为 ProjectionAxes
)。每当获取新数据时,我都会重新渲染整个绘图,而是创建了一个纹理并渲染到该纹理,然后将纹理渲染为四边形。 每个绘图都是一个对象,并具有自己的纹理、渲染缓冲区对象和帧缓冲区对象。
这在Linux下运行良好,但在OSX下则不然。 当我在 Linux 上运行该程序时,每个对象都会创建自己的纹理、FBO 和 RBO,并且一切都很好。但是,当我在OSX上运行相同的代码时,对象不会生成单独的FBO,但似乎都使用相同的FBO。
在我的测试程序中,我创建了两个ProjectionAxes
实例。在第一次调用plot()
时,轴会检测到纹理尚未创建,然后生成它们。在此生成过程中,我显示 textureId、RBOid 和 FBOid 的整数值。当我运行我的代码时,这是我在 Linux 下运行程序时得到的输出:
ProjectionAxes::plot() --> Texture is invalid regenerating it!
Creating a new texture, textureId:1
Creating a new frame buffer object fboID:1 rboID:1
ProjectionAxes::plot() --> Texture is invalid regenerating it!
Creating a new texture, textureId:2
Creating a new frame buffer object fboID:2 rboID:2
对于 OSX:
ProjectionAxes::plot() --> Texture is invalid regenerating it!
Creating a new texture, textureId:1
Creating a new frame buffer object fboID:1 rboID:1
ProjectionAxes::plot() --> Texture is invalid regenerating it!
Creating a new texture, textureId:2
Creating a new frame buffer object fboID:1 rboID:2
请注意,在 Linux 下,两个 FBO 具有不同的 ID,而在 OSX 下则没有。我需要做什么才能向OSX表明我希望每个对象使用自己的FBO?
以下是我用来创建FBO的代码:
void ProjectionAxes::createFBO(){
std::cout<<"Creating a new frame buffer object";//<<std::endl;
glDeleteFramebuffers(1, &fboId);
glDeleteRenderbuffers(1, &rboId);
// Generate and Bind the frame buffer
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// Generate and bind the new Render Buffer
glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
std::cout<<" fboID:"<<fboId<<" rboID:"<<rboId<<std::endl;
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texWidth, texHeight);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
// Attach the texture to the framebuffer
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);
// If the FrameBuffer wasn't created then we have a bigger problem. Abort the program.
if(!checkFramebufferStatus()){
std::cout<<"FrameBufferObject not created! Are you running the newest version of OpenGL?"<<std::endl;
std::cout<<"FrameBufferObjects are REQUIRED! Quitting!"<<std::endl;
exit(1);
}
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
这是我用来创建纹理的代码:
void ProjectionAxes::createTexture(){
texWidth = BaseUIElement::width;
texHeight = BaseUIElement::height;
std::cout<<"Creating a new texture,";
// Delete the old texture
glDeleteTextures(1, &textureId);
// Generate a new texture
glGenTextures(1, &textureId);
std::cout<<" textureId:"<<textureId<<std::endl;
// Bind the texture, and set the appropriate parameters
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glGenerateMipmap(GL_TEXTURE_2D);
// generate a new FrameBufferObject
createFBO();
// the texture should now be valid, set the flag appropriately
isTextureValid = true;
}
尝试暂时注释掉glDelete*
函数调用。你可能正在用手柄做一些奇怪的事情。
相关文章:
- 如何在 Mac 上正确编译C++,当它在 Linux 上编译没有问题时?
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 编译问题与 Ubuntu Linux
- 获取处理器相关性(linux)时出现问题
- C++ Linux 上的插件 ABI 问题
- Linux 测量时间问题! std::chrono, QueryPerformanceCounter, clock_ge
- 在 64 位 Linux armv8 计算机上编译 32 位二进制文件时遇到问题
- 为什么我的C 代码在Linux上运行,而在Windows上不运行,是否有RAM内存的问题
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- Vulkan + GLFW + Cmake在Linux环境下的链接问题
- Visual Studio 2017问题编译了C 代码,而该代码则在Linux中编译
- 在 Linux 中从单独的单线程进程生成多线程进程时出现问题
- 尝试模拟Linux shell.使用模拟MKDIR的问题
- 在程序中获取 Linux 'dd' 命令的输出时遇到问题C++
- Linux 中 gcc 4.3 版本的编译问题
- 调试基于 Linux 的 C++ 代码 Visual Studio 代码时出现问题
- VS2017 Linux C 线程问题
- Linux问题中的分段11