1
\$\begingroup\$

As of late I've been trying to implement Cubemaps in my engine, and have managed to get the rendering side of them working. Currently, I'm trying to implement a function for creating them, but I somehow hit a road block.

The way I'm trying to implement this is by rendering my scene once into an FBO from the perspective of the cubemap node (x6 times, one in each direction), and cycle the format of the texture bound to the color attachment as:

GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, etc

For whatever reason, I haven't been getting any expected results.

All I want to do is take snapshots from the camera's perspective, but I need them in texture units I can use multiple frames over.

I've tried so many ways that I couldn't possibly recount them all here, but the general gist of how I've been trying to go about doing this, is this:

DTextureCubemapComponent *cubemap = getTexture(); // My Texture Component
GLuint target = cubemap->textureObj();            // CUBEMAP texture handle
glBindTexture(GL_TEXTURE_CUBE_MAP, target);       // Make cubemap active

for (int x = 0; x < 6; x++)                       // Render from 6 different angles
{        
    gbuffercube->swapFinalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X + x);
    gbuffercube->StartFrame();                    // my FBO Class, binds itself, etc

    /*... RENDER SCENE ...*/                      // Draw into my FBO, etc

    gbuffercube->BindForFinalPass();              // Read buffer == my FBO        
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

Where "SwapFinalFormat()" is:

void GBuffer::swapFinalFormat(GLuint format)
{
    format = fmt;
    glTexImage2D(format, 0, GL_RGBA32F, size.width(), size.height(), 0, GL_RGBA,     GL_UNSIGNED_BYTE, NULL);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT6, format, m_finalTexture, 0);
}

I know that my FBO class works (labeld GBufferCube above) , as it is the same class I use normally for my deferred shading system.

\$\endgroup\$
1
\$\begingroup\$

First of all don't use glCopyTexImage2D with FBOs, the whole point of using FBO is to avoid copying, and have multirender target support on the GPU side without copying.

FBO acts as a container of buffers and redirect rendering output to those buffers, without copying anything.

For instance you can attach a texture object or pixel buffer object to the FBO and all the rendering will be automatically redirected to the attached buffer. You can attach a texture to Color attachement 0 and then bind that texture to the current texture unit and use it as ordinary texture, the whole point is to avoid copying, everything happens on the GPU side. The steps roughly are:

  1. Create an FBO
  2. Create a texture object.
  3. Attach the texture object to the FBO using glFramebufferTexture
  4. Before rendering bind the FBO, rendering will be redirected to the FBO attachements.
  5. Bind your created texture object, and use it in shaders like an ordinary texture in a different pass.

Oh, and before drawing anything to the FBO don't forget to clear it.

Finally this is just a rough guideline, for more details see this tutorial.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the clarification, however I forgot to add that I tried doing that with cubemap textures as well, but I must have failed. Does glFramebufferTexture2D support attaching parts of cubemap textures? I've revised and updated the opening post. \$\endgroup\$ – Yattabyte Sep 13 '15 at 14:54
  • \$\begingroup\$ @Yattabyte check this stackoverflow.com/questions/13744476/…. You need to use 6 cube 2D textures and then use them as a cube map. \$\endgroup\$ – concept3d Sep 13 '15 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.