简体   繁体   中英

Create Cubemap from QOpenGLFramebuffer

I want to implement cubemap convolution for IBL using a Qt widget.

When implementing conversion from an equirectangular map to a cubemap I ran into an error I do not understand:

Here is how I create my renderbuffer:

QOpenGLFramebufferObjectFormat format;

format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
format.setInternalTextureFormat(GL_RGBA32F_ARB);

envTarget = new QOpenGLFramebufferObject(QSize(256, 256), format);

Here is how I create my cubemap texture:

envCubemap = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
envCubemap->create();
envCubemap->bind();

envCubemap->setSize(256, 256, 4);
envCubemap->setFormat(QOpenGLTexture::RGBAFormat);
envCubemap->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::Float32);
envCubemap->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Linear);

I then proceed to render the different cubemap views to the corresponding parts of the texture:

envCubemap->bind(9);

glViewport(0, 0, 256, 256);
envTarget->bind();

for (unsigned int i = 0; i < 6; ++i)
{
    ActiveScene->ActiveCamera->View = captureViews[i];
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 9, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawBackground();
}

envTarget->release();

The drawBackground() method draws an environment sphere which works fine with my default buffer.

The openGL error I get is 1282. This turns to 0 if I comment out the glFramebufferTexture2D line. 1282 corresponds to GL_INVALID_OPERATION or GL_INVALID_VALUE , where both of these have multiple errors attached to them according to the glFramebufferTexture2D documentation.

What did I get wrong? I tried iterating over each parameter in order to solve this error but did not come up with a solution. As this should be fairly standard stuff I hope to find a solution here :D Help?

You need to actually tell the framebuffer, which texture to render to using its ID, and not '9':

glFramebufferTexture2D(
     GL_FRAMEBUFFER,
     GL_COLOR_ATTACHMENT0,
     GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
     envCubemap->textureId(), // <--- The change
     0);

The same goes for envCubemap->bind(9); , which can be simply removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM