Back to index

unity  6.0.0
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
unity::ScreenEffectFramebufferObject Class Reference

#include <ScreenEffectFramebufferObject.h>

List of all members.

Public Types

typedef boost::shared_ptr
< ScreenEffectFramebufferObject
Ptr
typedef void(* FuncPtr )(void)
typedef FuncPtr(* GLXGetProcAddressProc )(const GLubyte *procName)

Public Member Functions

 ScreenEffectFramebufferObject (GLXGetProcAddressProc, const nux::Geometry &geom)
 ~ScreenEffectFramebufferObject ()
void bind (const nux::Geometry &geom)
void unbind ()
bool status ()
void paint (const nux::Geometry &geom)
bool bound ()
GLuint texture ()
void onScreenSizeChanged (const nux::Geometry &screenSize)

Private Types

typedef void(* GLActiveTextureProc )(GLenum texture)
typedef void(* GLGenFramebuffersProc )(GLsizei n, GLuint *framebuffers)
typedef void(* GLDeleteFramebuffersProc )(GLsizei n, GLuint *framebuffers)
typedef void(* GLBindFramebufferProc )(GLenum target, GLuint framebuffer)
typedef GLenum(* GLCheckFramebufferStatusProc )(GLenum target)
typedef void(* GLFramebufferTexture2DProc )(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)

Private Member Functions

FuncPtr getProcAddr (const std::string &)

Private Attributes

GLXGetProcAddressProc getProcAddressGLX
GLActiveTextureProc activeTexture
GLGenFramebuffersProc genFramebuffers
GLDeleteFramebuffersProc deleteFramebuffers
GLBindFramebufferProc bindFramebuffer
GLCheckFramebufferStatusProc checkFramebufferStatus
GLFramebufferTexture2DProc framebufferTexture2D
GLuint mFboHandle
bool mFboStatus
GLuint mFBTexture
nux::Geometry mGeometry
unsigned int mBoundCnt
nux::Geometry mScreenSize

Detailed Description

Definition at line 28 of file ScreenEffectFramebufferObject.h.


Member Typedef Documentation

Definition at line 33 of file ScreenEffectFramebufferObject.h.

Definition at line 56 of file ScreenEffectFramebufferObject.h.

typedef void(* unity::ScreenEffectFramebufferObject::GLBindFramebufferProc)(GLenum target, GLuint framebuffer) [private]

Definition at line 61 of file ScreenEffectFramebufferObject.h.

typedef GLenum(* unity::ScreenEffectFramebufferObject::GLCheckFramebufferStatusProc)(GLenum target) [private]

Definition at line 63 of file ScreenEffectFramebufferObject.h.

typedef void(* unity::ScreenEffectFramebufferObject::GLDeleteFramebuffersProc)(GLsizei n, GLuint *framebuffers) [private]

Definition at line 59 of file ScreenEffectFramebufferObject.h.

typedef void(* unity::ScreenEffectFramebufferObject::GLFramebufferTexture2DProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) [private]

Definition at line 64 of file ScreenEffectFramebufferObject.h.

typedef void(* unity::ScreenEffectFramebufferObject::GLGenFramebuffersProc)(GLsizei n, GLuint *framebuffers) [private]

Definition at line 57 of file ScreenEffectFramebufferObject.h.

Definition at line 34 of file ScreenEffectFramebufferObject.h.

Definition at line 32 of file ScreenEffectFramebufferObject.h.


Constructor & Destructor Documentation

Definition at line 216 of file ScreenEffectFramebufferObject.cpp.

 : getProcAddressGLX (p)
 , mFboStatus (false)
 , mFBTexture (0)
 , mGeometry (geom)
 , mBoundCnt (0)
 , mScreenSize (geom)
{
  activeTexture = (GLActiveTextureProc) (*getProcAddressGLX) ((GLubyte *) "glActiveTexture");
  genFramebuffers = (GLGenFramebuffersProc) (*getProcAddressGLX) ((GLubyte *)"glGenFramebuffersEXT");
  deleteFramebuffers = (GLDeleteFramebuffersProc) (*getProcAddressGLX) ((GLubyte *)"glDeleteFramebuffersEXT");
  bindFramebuffer = (GLBindFramebufferProc) (*getProcAddressGLX) ((GLubyte *)"glBindFramebufferEXT");
  checkFramebufferStatus = (GLCheckFramebufferStatusProc) (*getProcAddressGLX) ((GLubyte *) "glCheckFramebufferStatusEXT");
  framebufferTexture2D = (GLFramebufferTexture2DProc) (*getProcAddressGLX) ((GLubyte *) "glFramebufferTexture2DEXT");
  
  (*genFramebuffers) (1, &mFboHandle);
}

Definition at line 234 of file ScreenEffectFramebufferObject.cpp.

{
  (*deleteFramebuffers) (1, &mFboHandle);

  if (mFBTexture)
    glDeleteTextures (1, &mFBTexture);
}

Member Function Documentation

void unity::ScreenEffectFramebufferObject::bind ( const nux::Geometry &  geom)

Definition at line 102 of file ScreenEffectFramebufferObject.cpp.

{
  /* Very important!
   * Don't bind unless BackgroundEffectHelper says it's necessary.
   * Because binding has a severe impact on graphics performance and we
   * can't afford to do it every frame. (LP: #861061) (LP: #987304)
   */
  if (!BackgroundEffectHelper::HasDirtyHelpers())
    return;

  /* Clear the error bit */
  glGetError ();

  if (!mFBTexture)
  {
    glGenTextures (1, &mFBTexture);

    glBindTexture (GL_TEXTURE_2D, mFBTexture);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, mGeometry.width, mGeometry.height, 0, GL_BGRA,
#if IMAGE_BYTE_ORDER == MSBFirst
                 GL_UNSIGNED_INT_8_8_8_8_REV,
#else
                 GL_UNSIGNED_BYTE,
#endif
                 NULL);

    glBindTexture (GL_TEXTURE_2D, 0);

    if (glGetError () != GL_NO_ERROR)
    {
      mFboHandle = 0;
      mFboStatus = false;
      return;
    }
  }

  (*bindFramebuffer) (GL_FRAMEBUFFER_EXT, mFboHandle);

  (*framebufferTexture2D) (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                               GL_TEXTURE_2D, mFBTexture, 0);

  (*framebufferTexture2D) (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                               GL_TEXTURE_2D, 0, 0);

  /* Ensure that a framebuffer is actually available */
  if (!mFboStatus)
  {
    GLint status = (*checkFramebufferStatus) (GL_DRAW_FRAMEBUFFER);

    if (status != GL_FRAMEBUFFER_COMPLETE)
    {
      switch (status)
      {
        case GL_FRAMEBUFFER_UNDEFINED:
          LOG_WARN (logger) <<  "no window";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
          LOG_WARN (logger) <<  "attachment incomplete";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
          LOG_WARN (logger) <<  "no buffers attached to fbo";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
          LOG_WARN (logger) <<  "some attachment in glDrawBuffers doesn't exist in FBO";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
          LOG_WARN (logger) <<  "some attachment in glReadBuffers doesn't exist in FBO";
          break;
        case GL_FRAMEBUFFER_UNSUPPORTED:
          LOG_WARN (logger) <<  "unsupported internal format";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
          LOG_WARN (logger) <<  "different levels of sampling for each attachment";
          break;
        case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
          LOG_WARN (logger) <<  "number of layers is different";
          break;
        default:
          LOG_WARN (logger) <<  "unable to bind the framebuffer for an unknown reason";
          break;
      }

      bindFramebuffer (GL_FRAMEBUFFER_EXT, 0);
      deleteFramebuffers (1, &mFboHandle);

      glDrawBuffer (GL_BACK);
      glReadBuffer (GL_BACK);

      mFboHandle = 0;

      mFboStatus = false;
    }
    else
      mFboStatus = true;
  }

  if (mFboStatus)
  {
    glPushAttrib (GL_VIEWPORT_BIT);

    glViewport (output.x,
              mScreenSize.height - (output.y + output.height),
              output.width,
              output.height);
  }

  mBoundCnt++;
}

Here is the call graph for this function:

Definition at line 46 of file ScreenEffectFramebufferObject.h.

{ return mBoundCnt > 0; }
FuncPtr unity::ScreenEffectFramebufferObject::getProcAddr ( const std::string &  ) [private]
void unity::ScreenEffectFramebufferObject::onScreenSizeChanged ( const nux::Geometry &  screenSize)

Definition at line 74 of file ScreenEffectFramebufferObject.cpp.

{
  mScreenSize = screenSize;
}
void unity::ScreenEffectFramebufferObject::paint ( const nux::Geometry &  geom)

Definition at line 31 of file ScreenEffectFramebufferObject.cpp.

{
  /* Draw the bit of the relevant framebuffer for each output */

  glPushAttrib (GL_VIEWPORT_BIT);
  glViewport (0, 0, mScreenSize.width, mScreenSize.height);

  if (mFBTexture)
  {
    glEnable (GL_TEXTURE_2D);
    activeTexture (GL_TEXTURE0_ARB);
    glBindTexture (GL_TEXTURE_2D, mFBTexture);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glPushAttrib (GL_SCISSOR_BIT);
    glEnable (GL_SCISSOR_TEST);

    glScissor (output.x, mScreenSize.height - (output.y + output.height),
              output.width, output.height);

    /* FIXME: This needs to be GL_TRIANGLE_STRIP */
    glBegin (GL_QUADS);
    glTexCoord2f (0, 1);
    glVertex2i   (mGeometry.x, mGeometry.y);
    glTexCoord2f (0, 0);
    glVertex2i   (mGeometry.x, mGeometry.y + mGeometry.height);
    glTexCoord2f (1, 0);
    glVertex2i   (mGeometry.x + mGeometry.width, mGeometry.y + mGeometry.height);
    glTexCoord2f (1, 1);
    glVertex2i   (mGeometry.x + mGeometry.width, mGeometry.y);
    glEnd ();

    activeTexture (GL_TEXTURE0_ARB);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glBindTexture (GL_TEXTURE_2D, 0);
    glDisable (GL_TEXTURE_2D);
    glPopAttrib ();
  }
  glPopAttrib ();
}

Definition at line 97 of file ScreenEffectFramebufferObject.cpp.

{
  return mFboStatus;
}

Here is the caller graph for this function:

Definition at line 48 of file ScreenEffectFramebufferObject.h.

{ return mFBTexture; }

Definition at line 80 of file ScreenEffectFramebufferObject.cpp.

{
  if (!mBoundCnt)
    return;

  mBoundCnt--;

  (*bindFramebuffer) (GL_FRAMEBUFFER_EXT, 0);

  glDrawBuffer (GL_BACK);
  glReadBuffer (GL_BACK);

  /* Matches the viewport set we did in ::bind () */
  glPopAttrib ();

}

Member Data Documentation

Definition at line 71 of file ScreenEffectFramebufferObject.h.

Definition at line 74 of file ScreenEffectFramebufferObject.h.

Definition at line 75 of file ScreenEffectFramebufferObject.h.

Definition at line 73 of file ScreenEffectFramebufferObject.h.

Definition at line 76 of file ScreenEffectFramebufferObject.h.

Definition at line 72 of file ScreenEffectFramebufferObject.h.

Definition at line 70 of file ScreenEffectFramebufferObject.h.

Definition at line 82 of file ScreenEffectFramebufferObject.h.

Definition at line 78 of file ScreenEffectFramebufferObject.h.

Definition at line 79 of file ScreenEffectFramebufferObject.h.

Definition at line 80 of file ScreenEffectFramebufferObject.h.

Definition at line 81 of file ScreenEffectFramebufferObject.h.

Definition at line 84 of file ScreenEffectFramebufferObject.h.


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