Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试在OSX(而不是Linux)中创建多个帧缓冲区对象时出现问题_C++_Macos_Opengl - Fatal编程技术网

C++ 尝试在OSX(而不是Linux)中创建多个帧缓冲区对象时出现问题

C++ 尝试在OSX(而不是Linux)中创建多个帧缓冲区对象时出现问题,c++,macos,opengl,C++,Macos,Opengl,我正在编写一个应用程序,其中包含一组小散点图(称为ProjectionAxes)。我创建了纹理并渲染到该纹理,然后将纹理渲染到四边形,而不是在获取新数据时重新渲染整个绘图。每个绘图都是一个对象,并具有自己的纹理、渲染缓冲区对象和帧缓冲区对象 这在Linux下工作得很好,但在OSX下却不行。当我在Linux上运行该程序时,每个对象都会创建自己的纹理、FBO和RBO,所有对象都会渲染得很好。但是,当我在OSX上运行相同的代码时,对象不会生成单独的FBO,而是似乎都使用相同的FBO 在我的测试程序中,

我正在编写一个应用程序,其中包含一组小散点图(称为
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 projectonaxes::createFBO(){

std::cout尝试暂时注释掉
glDelete*
函数调用。你可能对句柄做了一些奇怪的事情。

为什么要在
createFBO
函数中删除
fbo
?很好的问题,如果窗口被重新调整大小,那么我会声明纹理无效,并创建新的调整大小的纹理、rbos和fbos。然后我删除以前使用的纹理、FBO和RBO。我找到的文档说删除一个不存在的对象没有任何问题,所以我在生成之前调用delete。我会尝试暂时注释掉
glDelete*
调用(是的,这会泄漏),然后查看问题是否仍然存在。如果没有问题,您的手柄有点奇怪。@AndreasBrinck解决了问题,您能否将其作为答案发布,以便我可以接受它?此外,如果我创建一个新纹理,我可以简单地将该纹理绑定到旧帧缓冲区中,还是也必须创建一个新的帧缓冲区?我不记得了,您“我必须试一试:)
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;

}