Back to index

nux  3.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
nux::GLFramebufferObject Class Reference

#include <GLDeviceFrameBufferObject.h>

List of all members.

Public Member Functions

 GLFramebufferObject ()
 Ctor/Dtor.
virtual ~GLFramebufferObject ()
void Bind ()
 Bind this FBO as current render target.
virtual void AttachTexture (GLenum attachment, GLenum texType, GLuint texId, int mipLevel=0, int zSlice=0)
 Bind a texture to the "attachment" point of this FBO.
virtual void AttachTextures (int numTextures, GLenum texTarget[], GLuint texId[], GLenum attachment[]=NULL, int mipLevel[]=NULL, int zSlice[]=NULL)
 Bind an array of textures to multiple "attachment" points of this FBO.
virtual void AttachRenderBuffer (GLenum attachment, GLuint buffId)
 Bind a render buffer to the "attachment" point of this FBO.
void Unattach (GLenum attachment)
 Free any resource bound to the "attachment" point of this FBO.
bool IsValid ()
 Is this FBO currently a valid render target?
GLenum GetAttachedType (GLenum attachment)
 BEGIN : Accessors Is attached type GL_RENDERBUFFER_EXT or GL_TEXTURE?
GLuint GetAttachedId (GLenum attachment)
 What is the Id of Renderbuffer/texture currently attached to "attachement?".
GLint GetAttachedMipLevel (GLenum attachment)
 Which mipmap level is currently attached to "attachement?".
GLint GetAttachedCubeFace (GLenum attachment)
 Which cube face is currently attached to "attachment?".
GLint GetAttachedZSlice (GLenum attachment)
 Which z-slice is currently attached to "attachment?".

Static Public Member Functions

static int GetMaxColorAttachments ()
 END : Accessors.
static void Disable ()
 Disable all FBO rendering and return to traditional, windowing-system controlled framebuffer NOTE: This is NOT an "unbind" for this specific FBO, but rather disables all FBO rendering. This call is intentionally "static" and named "Disable" instead of "Unbind" for this reason. The motivation for this strange semantic is performance. Providing "Unbind" would likely lead to a large number of unnecessary FBO enablings/disabling.

Private Member Functions

void _GuardedBind ()
void _GuardedUnbind ()
void _FramebufferTextureND (GLenum attachment, GLenum texType, GLuint texId, int mipLevel, int zSlice)

Static Private Member Functions

static GLuint _GenerateFboId ()

Private Attributes

GLint m_fboId
 END : Static methods global to all FBOs.
GLint m_savedFboId

Detailed Description

Definition at line 85 of file GLDeviceFrameBufferObject.h.


Constructor & Destructor Documentation

Ctor/Dtor.

Definition at line 51 of file GLDeviceFrameBufferObject.cpp.

    :   m_fboId(0)
    ,   m_savedFboId(0)
  {
    m_fboId = _GenerateFboId();
    // Bind this FBO so that it actually gets created now
    _GuardedBind();
    _GuardedUnbind();
  }

Here is the call graph for this function:

Definition at line 61 of file GLDeviceFrameBufferObject.cpp.

  {
    CHECKGL(glDeleteFramebuffersEXT(1, (const GLuint *) &m_fboId));
  }

Member Function Documentation

void nux::GLFramebufferObject::_FramebufferTextureND ( GLenum  attachment,
GLenum  texType,
GLuint  texId,
int  mipLevel,
int  zSlice 
) [private]

Definition at line 200 of file GLDeviceFrameBufferObject.cpp.

  {
    if (texType == GL_TEXTURE_2D)
    {
      // Default is GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB, or cube faces
      CHECKGL(glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                            texType, texId, mipLevel ));
    }
#ifndef NUX_OPENGLES_20
    else if (texType == GL_TEXTURE_1D)
    {
      CHECKGL(glFramebufferTexture1DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                            GL_TEXTURE_1D, texId, mipLevel ));
    }
    else if (texType == GL_TEXTURE_3D)
    {
      CHECKGL(glFramebufferTexture3DEXT( GL_FRAMEBUFFER_EXT, attachment,
                                            GL_TEXTURE_3D, texId, mipLevel, zSlice ));
    }
#endif
  }

Here is the caller graph for this function:

GLuint nux::GLFramebufferObject::_GenerateFboId ( ) [static, private]

Definition at line 162 of file GLDeviceFrameBufferObject.cpp.

  {
    GLuint id = 0;
    CHECKGL(glGenFramebuffersEXT(1, &id));
    return id;
  }

Here is the caller graph for this function:

Definition at line 169 of file GLDeviceFrameBufferObject.cpp.

  {
#ifndef NUX_OPENGLES_20
    // Only binds if m_fboId is different than the currently bound FBO
    CHECKGL(glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &m_savedFboId ));

    if (m_fboId != m_savedFboId)
    {
      CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboId));
    }
#else
    // Only binds if m_fboId is different than the currently bound FBO
    CHECKGL(glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &m_savedFboId ));

    if (m_fboId != m_savedFboId)
    {
      CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboId));
    }
#endif
  }

Here is the caller graph for this function:

Definition at line 190 of file GLDeviceFrameBufferObject.cpp.

  {
    // Returns FBO binding to the previously enabled FBO
    if (m_savedFboId != m_fboId)
    {
      CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint) m_savedFboId));
    }
  }

Here is the caller graph for this function:

void nux::GLFramebufferObject::AttachRenderBuffer ( GLenum  attachment,
GLuint  buffId 
) [virtual]

Bind a render buffer to the "attachment" point of this FBO.

Definition at line 110 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();

    if ( GetAttachedId(attachment) != buffId )
    {
      CHECKGL(glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, attachment,
                GL_RENDERBUFFER_EXT, buffId));
    }
    else
    {
//        nuxError(TEXT("GLFramebufferObject::AttachRenderBuffer PERFORMANCE WARNING:\n
//            \tRedundant bind of GLRenderbuffer(id = %d).\n"), buffId);
    }

    _GuardedUnbind();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::GLFramebufferObject::AttachTexture ( GLenum  attachment,
GLenum  texType,
GLuint  texId,
int  mipLevel = 0,
int  zSlice = 0 
) [virtual]

Bind a texture to the "attachment" point of this FBO.

Definition at line 77 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();

    if ( GetAttachedId(attachment) != texId )
    {
      _FramebufferTextureND( attachment, texType,
                              texId, mipLevel, zSlice );
    }
    else
    {
//        nuxError("GLFramebufferObject::AttachTexture PERFORMANCE WARNING:\n
//            \tRedundant bind of texture(id = %d).\n"), texId);
    }

    _GuardedUnbind();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::GLFramebufferObject::AttachTextures ( int  numTextures,
GLenum  texTarget[],
GLuint  texId[],
GLenum  attachment[] = NULL,
int  mipLevel[] = NULL,
int  zSlice[] = NULL 
) [virtual]

Bind an array of textures to multiple "attachment" points of this FBO.

  • By default, the first 'numTextures' attachments are used, starting with GL_COLOR_ATTACHMENT0_EXT

Definition at line 96 of file GLDeviceFrameBufferObject.cpp.

  {
    for (int i = 0; i < numTextures; ++i)
    {
      AttachTexture( texTarget[i], texId[i],
                      attachment ? attachment[i] : (GL_COLOR_ATTACHMENT0_EXT + i),
                      mipLevel ? mipLevel[i] : 0,
                      zSlice ? zSlice[i] : 0 );
    }
  }

Here is the call graph for this function:

Bind this FBO as current render target.

Definition at line 66 of file GLDeviceFrameBufferObject.cpp.

Here is the caller graph for this function:

Disable all FBO rendering and return to traditional, windowing-system controlled framebuffer NOTE: This is NOT an "unbind" for this specific FBO, but rather disables all FBO rendering. This call is intentionally "static" and named "Disable" instead of "Unbind" for this reason. The motivation for this strange semantic is performance. Providing "Unbind" would likely lead to a large number of unnecessary FBO enablings/disabling.

Definition at line 71 of file GLDeviceFrameBufferObject.cpp.

GLint nux::GLFramebufferObject::GetAttachedCubeFace ( GLenum  attachment)

Which cube face is currently attached to "attachment?".

Definition at line 322 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();
    GLint level = 0;
#ifndef NUX_OPENGLES_20
    CHECKGL(glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER_EXT, attachment,
              GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT,
              &level));
#endif
    _GuardedUnbind();
    return level;
  }

Here is the call graph for this function:

GLuint nux::GLFramebufferObject::GetAttachedId ( GLenum  attachment)

What is the Id of Renderbuffer/texture currently attached to "attachement?".

Definition at line 300 of file GLDeviceFrameBufferObject.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

GLint nux::GLFramebufferObject::GetAttachedMipLevel ( GLenum  attachment)

Which mipmap level is currently attached to "attachement?".

Definition at line 311 of file GLDeviceFrameBufferObject.cpp.

Here is the call graph for this function:

GLenum nux::GLFramebufferObject::GetAttachedType ( GLenum  attachment)

BEGIN : Accessors Is attached type GL_RENDERBUFFER_EXT or GL_TEXTURE?

Accessors.

Definition at line 288 of file GLDeviceFrameBufferObject.cpp.

  {
    // Returns GL_RENDERBUFFER_EXT or GL_TEXTURE
    _GuardedBind();
    GLint type = 0;
    CHECKGL(glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER_EXT, attachment,
              GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT,
              &type));
    _GuardedUnbind();
    return GLenum(type);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

GLint nux::GLFramebufferObject::GetAttachedZSlice ( GLenum  attachment)

Which z-slice is currently attached to "attachment?".

Definition at line 335 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();
    GLint slice = 0;
#ifndef NUX_OPENGLES_20
    CHECKGL(glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER_EXT, attachment,
              GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT,
              &slice));
#endif
    _GuardedUnbind();
    return slice;
  }

Here is the call graph for this function:

END : Accessors.

BEGIN : Static methods global to all FBOs Return number of color attachments permitted

Definition at line 151 of file GLDeviceFrameBufferObject.cpp.

  {
#ifndef NUX_OPENGLES_20
    GLint maxAttach = 0;
    CHECKGL(glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxAttach ));
    return maxAttach;
#else
    return 1;
#endif
  }

Is this FBO currently a valid render target?

  • Sends output to std::cerr by default but can be a user-defined C++ stream

NOTE : This function works correctly in debug build mode but always returns "true" if NDEBUG is is defined(optimized builds)

Definition at line 224 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();

    bool isOK = false;

    GLenum status;
    status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    CHECKGL_MSG(glCheckFramebufferStatusEXT);

    switch(status)
    {
      case GL_FRAMEBUFFER_COMPLETE_EXT: // Everything's OK
        isOK = true;
        break;
      case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
        isOK = false;
        break;
      case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
        isOK = false;
        break;
// See issue(87) of http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
//  case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
//      nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT");
//      isOK = false;
//      break;
      case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");
        isOK = false;
        break;
#ifndef NUX_OPENGLES_20
      case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
        isOK = false;
        break;
      case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
        isOK = false;
        break;
      case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
        isOK = false;
        break;
#endif
//  case GL_FRAMEBUFFER_STATUS_ERROR_EXT:
//      nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_STATUS_ERROR_EXT");
//      isOK = false;
//      break;
      case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
        nuxError("[GLFramebufferObject::IsValid] GL_FRAMEBUFFER_UNSUPPORTED_EXT");
        isOK = false;
        break;
      default:
        nuxError("[GLFramebufferObject::IsValid] Unknown ERROR");
        isOK = false;
    }

    _GuardedUnbind();
    return isOK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::GLFramebufferObject::Unattach ( GLenum  attachment)

Free any resource bound to the "attachment" point of this FBO.

Definition at line 129 of file GLDeviceFrameBufferObject.cpp.

  {
    _GuardedBind();
    GLenum type = GetAttachedType(attachment);

    switch(type)
    {
      case GL_NONE:
        break;
      case GL_RENDERBUFFER_EXT:
        AttachRenderBuffer( attachment, 0 );
        break;
      case GL_TEXTURE:
        AttachTexture( attachment, GL_TEXTURE_2D, 0 );
        break;
      default:
        std::cout << "GLFramebufferObject::unbind_attachment ERROR: Unknown attached resource type\n";
    }

    _GuardedUnbind();
  }

Here is the call graph for this function:


Member Data Documentation

END : Static methods global to all FBOs.

Definition at line 160 of file GLDeviceFrameBufferObject.h.

Definition at line 161 of file GLDeviceFrameBufferObject.h.


The documentation for this class was generated from the following files: