Back to index

nux  3.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
nux::IOpenGLSurface Class Reference

#include <IOpenGLSurface.h>

Inheritance diagram for nux::IOpenGLSurface:
Inheritance graph
[legend]
Collaboration diagram for nux::IOpenGLSurface:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual int RefCount () const
int LockRect (SURFACE_LOCKED_RECT *pLockedRect, const SURFACE_RECT *pRect)
int UnlockRect ()
BitmapFormat GetPixelFormat () const
int GetWidth () const
int GetHeight () const
int GetMipLevel () const
int GetSurfaceTarget () const
int GetDesc (SURFACE_DESC *pDesc)
void CopyRenderTarget (int x, int y, int width, int height)
 Copy the render target into the texture mip level.
unsigned char * GetSurfaceData (int &width, int &height, int &stride)
 Return the mipmap data.
 NUX_DECLARE_OBJECT_TYPE (BaseObject, Trackable)
OpenGLResourceType GetResourceType () const
int GetOpenGLID () const
bool Reference ()
 Increase reference count.
bool UnReference ()
 Decrease reference count.
virtual bool SinkReference ()
 Mark the object as owned.
virtual bool Dispose ()
 Destroy and object that has a floating reference.
int GetReferenceCount () const
 Get the reference count of this object.
std::string GetAllocationLoation () const
 NUX_DECLARE_ROOT_OBJECT_TYPE (Trackable)
bool OwnsTheReference ()
 Test if object reference is owned.
bool IsHeapAllocated ()
 Test if object was allocated dynamically.
bool IsDynamic () const
 Test if object was allocated dynamically.
virtual int GetObjectSize ()
 Return the size of allocated for this object.
bool SetProperty (std::string const &name, const char *value)
 If the property was not able to be set with the value, the method returns false.
template<typename T >
bool SetProperty (std::string const &name, T const &value)
template<typename T >
GetProperty (std::string const &name, T *foo=0)
void AddProperty (std::string const &name, PropertyBase *property)

Static Public Member Functions

static std::new_handler set_new_handler (std::new_handler handler)
static void * operator new (size_t size)
static void * operator new (size_t size, void *ptr)
static void operator delete (void *ptr)

Public Attributes

sigc::signal< void, Object * > object_destroyed
 Signal emitted immediately before the object is destroyed.

Protected Member Functions

void SetOwnedReference (bool b)

Protected Attributes

int _heap_allocated

Private Member Functions

 NUX_DECLARE_OBJECT_TYPE (IOpenGLSurface, IOpenGLResource)
virtual ~IOpenGLSurface ()
int InitializeLevel ()
 IOpenGLSurface (IOpenGLBaseTexture *DeviceBaseTexture, GLenum OpenGLID, GLenum TextureTarget, GLenum SurfaceTarget, int MipLevel, int Slice=0, NUX_FILE_LINE_PROTO)

Private Attributes

GLenum _STextureTarget
GLenum _SSurfaceTarget
int _SMipLevel
int _SSlice
SURFACE_LOCKED_RECT _LockedRect
SURFACE_RECT _Rect
int _CompressedDataSize
IOpenGLBaseTexture_BaseTexture
bool _Initialized
int _AllocatedUnpackBuffer

Friends

class IOpenGLTexture2D
class IOpenGLRectangleTexture
class IOpenGLCubeTexture
class IOpenGLVolumeTexture
class IOpenGLAnimatedTexture
class ObjectPtr< IOpenGLSurface >

Detailed Description

Definition at line 30 of file IOpenGLSurface.h.


Constructor & Destructor Documentation

nux::IOpenGLSurface::~IOpenGLSurface ( ) [private, virtual]

Definition at line 60 of file IOpenGLSurface.cpp.

  {

  }
nux::IOpenGLSurface::IOpenGLSurface ( IOpenGLBaseTexture DeviceBaseTexture,
GLenum  OpenGLID,
GLenum  TextureTarget,
GLenum  SurfaceTarget,
int  MipLevel,
int  Slice = 0,
NUX_FILE_LINE_PROTO   
) [private]

Definition at line 34 of file IOpenGLSurface.cpp.

    : IOpenGLResource(RTSURFACE, NUX_FILE_LINE_PARAM)
    , _STextureTarget(TextureTarget)
    , _SSurfaceTarget(SurfaceTarget)
    , _SMipLevel(MipLevel)
    , _SSlice(Slice)
    , _BaseTexture(DeviceBaseTexture)
    , _AllocatedUnpackBuffer(0xFFFFFFFF)
  {
    // IOpenGLSurface surfaces are created inside a IOpenGLTexture2D, IOpenGLCubeTexture and IOpenGLVolumeTexture.
    // They reside within those classes. The reference counting starts once a call to GetSurfaceLevel,
    // GetCubeMapSurface or GetVolumeLevel is made to the container object.
    _RefCount = 0;
    _OpenGLID = OpenGLID;
    _LockedRect.pBits = 0;
    _LockedRect.Pitch = 0;
    _CompressedDataSize = 0;
    _Initialized = 0;
  }

Member Function Documentation

void nux::Introspectable::AddProperty ( std::string const &  name,
PropertyBase property 
) [inline, inherited]

Definition at line 254 of file Property-inl.h.

{
  // check to see if it exists and if it does barf horribly as we can't
  // have two properties with the same name;
  properties_[name] = property;
}

Here is the caller graph for this function:

void nux::IOpenGLSurface::CopyRenderTarget ( int  x,
int  y,
int  width,
int  height 
)

Copy the render target into the texture mip level.

Definition at line 632 of file IOpenGLSurface.cpp.

  {
    CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, _BaseTexture->GetFormatRowMemoryAlignment()));

#ifndef NUX_OPENGLES_20
    if (_STextureTarget == GL_TEXTURE_2D || _STextureTarget == GL_TEXTURE_RECTANGLE_ARB || _STextureTarget == GL_TEXTURE_CUBE_MAP || _STextureTarget == GL_TEXTURE_3D)
#else
    if (_STextureTarget == GL_TEXTURE_2D)
#endif
    {
      CHECKGL(glBindTexture(_STextureTarget, _BaseTexture->_OpenGLID));


#ifndef NUX_OPENGLES_20
      if (_STextureTarget != GL_TEXTURE_3D)
      {
        CHECKGL(glCopyTexImage2D(_SSurfaceTarget,
          _SMipLevel,
          GPixelFormats [_BaseTexture->_PixelFormat].Format,
          x,
          y,
          width,
          height,
          0));
      }
      else
      {
        CHECKGL(glCopyTexSubImage3D(_SSurfaceTarget,
          _SMipLevel,
          0,
          0,
          0,
          x,
          y,
          width,
          height));
      }
#else
      CHECKGL(glCopyTexImage2D(_SSurfaceTarget,
        _SMipLevel,
        GPixelFormats [_BaseTexture->_PixelFormat].Format,
        x,
        y,
        width,
        height,
        0));
#endif
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::Object::Dispose ( ) [virtual, inherited]

Destroy and object that has a floating reference.

Returns:
True is the object has been destroyed

Reimplemented from nux::Trackable.

Definition at line 311 of file Object.cpp.

  {
    // The intent of the Dispose call is to destroy objects with a float
    // reference (reference count is equal to 1 and the '_owns_the_reference'
    // flag is set to false). In Nux, only widgets object can have a floating
    // reference.  And widgets are only visible if added to the widget tree.
    // When an object with a floating reference is added to the widget tree,
    // it becomes "owned'. It looses it floating reference status but it still
    // has a reference count number of 1.  In practice, since widgets must be
    // added to the widget tree, there should never be a need to call Dispose
    // (except in a few cases).

    // Dispose() was designed to only destroy objects with floating
    // references, while UnReference() destroys objects that are "owned".
    // That is now relaxed. Dispose() calls UnReference().
    return UnReference();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string nux::Object::GetAllocationLoation ( ) const [inherited]

Definition at line 348 of file Object.cpp.

{
  std::ostringstream sout;
  sout << allocation_file_name_ << ":" << allocation_line_number_;
  return sout.str();
}

Here is the caller graph for this function:

Definition at line 108 of file IOpenGLSurface.cpp.

  {
    pDesc->Width    = GetWidth();
    pDesc->Height   = GetHeight();
    pDesc->PixelFormat   = GetPixelFormat();
    pDesc->Type     = _ResourceType;
    return OGL_OK;
  }

Here is the call graph for this function:

Definition at line 87 of file IOpenGLSurface.cpp.

  {
    if (_BaseTexture == 0)
    {
      nuxAssert(0);  // should not happen
      return 0;
    }

    return ImageSurface::GetLevelDim(_BaseTexture->_PixelFormat, _BaseTexture->_Height, _SMipLevel);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file IOpenGLSurface.cpp.

  {
    return _SMipLevel;
  }

Here is the caller graph for this function:

int nux::Trackable::GetObjectSize ( ) [virtual, inherited]

Return the size of allocated for this object.

Returns:
The size allocated for this object.

Definition at line 217 of file Object.cpp.

  {
    return _size_of_this_object;
  }
int nux::IOpenGLResource::GetOpenGLID ( ) const [inline, inherited]

Definition at line 101 of file IOpenGLResource.h.

    {
      return _OpenGLID;
    }

Here is the caller graph for this function:

Definition at line 65 of file IOpenGLSurface.cpp.

  {
    if (_BaseTexture == 0)
    {
      nuxAssert(0);  // should not happen
      return BITFMT_UNKNOWN;
    }

    return _BaseTexture->GetPixelFormat();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
T nux::Introspectable::GetProperty ( std::string const &  name,
T *  foo = 0 
) [inherited]

Definition at line 285 of file Property-inl.h.

{
  PropertyContainer::iterator i = properties_.find(name);
  if (i == properties_.end())
    return T();

  std::string s = i->second->GetSerializedValue();
  std::pair<T, bool> result = type::PropertyTrait<T>::from_string(s);
  // If this is called with a template type that the property does not
  // support nice conversion to, you'll get no error, but will get
  // a default constructed T.  We could use an exception here.
  return result.first;
}
int nux::Object::GetReferenceCount ( ) const [inherited]

Get the reference count of this object.

Returns:
The reference count of this object.

Definition at line 343 of file Object.cpp.

  {
    return reference_count_->GetValue();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 96 of file IOpenGLResource.h.

    {
      return _ResourceType;
    }

Here is the caller graph for this function:

unsigned char * nux::IOpenGLSurface::GetSurfaceData ( int &  width,
int &  height,
int &  stride 
)

Return the mipmap data.

Return the mipmap data.

Parameters:
widthReturns the width in pixel of the image data.
heightReturns the height in pixel of the image data.
strideReturns the row stride of the image data.

Definition at line 682 of file IOpenGLSurface.cpp.

  {
    width = 0;
    height = 0;
    stride = 0;
    
    if (_BaseTexture->_OpenGLID == 0)
    {
      return NULL;
    }

#ifndef NUX_OPENGLES_20
    CHECKGL(glBindTexture(_STextureTarget, _BaseTexture->_OpenGLID));

    // Despite a 1 byte pack alignment not being the most optimum, do it for simplicity.
    CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, 1));

    // We want RGBA data
    int mip_level_size = GetWidth() * GetHeight() * 4;
    unsigned char* img = new unsigned char[mip_level_size];

    // Internal OpenGL textures are in the RGBA format.
    // If the selected texture image does not contain four components, the following mappings are applied:
    // - Single-component textures are treated as RGBA buffers with red set to the single-component value, green set to 0, blue set to 0, and alpha set to 1.
    //   - red set to component zero
    //   - green set to 0
    //   - blue set to 0
    //   - alpha set to 1.0
    // - Two-component textures are treated as RGBA buffers with:
    //   - red set to component zero
    //   - green set to 0
    //   - blue set to 0
    //   - alpha set to component one
    // 
    // - Three-component textures are treated as RGBA buffers with:
    //   - red set to component zero
    //   - green set to component one
    //   - blue set to component two
    //   - alpha set to 1.0

    CHECKGL(glGetTexImage(_STextureTarget, _SMipLevel, GL_RGBA, GL_UNSIGNED_BYTE, img));

    width = GetWidth();
    height = GetHeight(); 
    stride = width * 4;

    return img;
#else
    //FIXME: need to render to framebuffer and use glReadPixels
    return NULL;
#endif
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 103 of file IOpenGLSurface.cpp.

  {
    return _SSurfaceTarget;
  }

Here is the caller graph for this function:

Definition at line 76 of file IOpenGLSurface.cpp.

  {
    if (_BaseTexture == 0)
    {
      nuxAssert(0);  // should not happen
      return 0;
    }

    return ImageSurface::GetLevelDim(_BaseTexture->_PixelFormat, _BaseTexture->_Width, _SMipLevel);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 516 of file IOpenGLSurface.cpp.

  {
    // Because we use SubImage when unlocking surfaces, we must first get some dummy data in the surface before we can make a lock.
    int texwidth = ImageSurface::GetLevelWidth(_BaseTexture->_PixelFormat, _BaseTexture->_Width, _SMipLevel);
    int texheight = ImageSurface::GetLevelHeight(_BaseTexture->_PixelFormat, _BaseTexture->_Height, _SMipLevel);
    int size = ImageSurface::GetLevelSize(_BaseTexture->_PixelFormat, _BaseTexture->_Width, _BaseTexture->_Height, _SMipLevel);
    int MemAlignment = ImageSurface::GetMemAlignment(_BaseTexture->_PixelFormat);

    nuxAssert( texwidth > 0 ); // Should never happen
    nuxAssert( texheight > 0 ); // Should never happen
    nuxAssert( size > 0 ); // Should never happen

    BYTE *DummyBuffer = (BYTE *) calloc(size, sizeof(BYTE));

    CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, MemAlignment));

#ifndef NUX_OPENGLES_20
    if ( _BaseTexture->_PixelFormat == BITFMT_DXT1 ||
         _BaseTexture->_PixelFormat == BITFMT_DXT2 ||
         _BaseTexture->_PixelFormat == BITFMT_DXT3 ||
         _BaseTexture->_PixelFormat == BITFMT_DXT4 ||
         _BaseTexture->_PixelFormat == BITFMT_DXT5)
    {
      if (_STextureTarget != GL_TEXTURE_3D)
      {
        glCompressedTexImage2DARB(
          _SSurfaceTarget,
          _SMipLevel,                 // level
          GPixelFormats[_BaseTexture->_PixelFormat].PlatformFormat,
          texwidth,
          texheight,
          0,                          // border
          size,                       // image Size
          DummyBuffer                           // data
        );
        CHECKGL_MSG(glCompressedTexImage2DARB);
      }
      else
      {
        //             glCompressedTexImage3DARB(
        //                 _SSurfaceTarget,
        //                 _SMipLevel,                 // level
        //                 GPixelFormats[_BaseTexture->_PixelFormat].PlatformFormat,
        //                 texwidth,
        //                 texheight,
        //                 _SSlice,
        //                 0,                          // border
        //                 size,                       // image Size
        //                 DummyBuffer                           // data
        //                 );
        //             CHECKGL_MSG(glCompressedTexImage3DARB);
      }
    }
    else
    {
      if (_STextureTarget != GL_TEXTURE_3D)
      {
#endif
        glTexImage2D(
          _SSurfaceTarget,
          _SMipLevel,                 // level
          GPixelFormats[_BaseTexture->_PixelFormat].PlatformFormat,
          texwidth,
          texheight,
          0,                          // border
          GPixelFormats[_BaseTexture->_PixelFormat].Format,
          GPixelFormats[_BaseTexture->_PixelFormat].type,
          DummyBuffer);
        CHECKGL_MSG(glTexImage2D);
#ifndef NUX_OPENGLES_20
      }
      else
      {
        //             glTexImage3D(
        //                 _SSurfaceTarget,
        //                 _SMipLevel,                 // level
        //                 GPixelFormats[PixelFormat].PlatformFormat,
        //                 texwidth,
        //                 texheight,
        //                 _SSlice,
        //                 0,                          // border
        //                 GPixelFormats[PixelFormat].Format,
        //                 GPixelFormats[PixelFormat].type,
        //                 DummyBuffer);
        //             CHECKGL_MSG(glTexImage3D);
      }
    }
#endif

    free(DummyBuffer);


    //    { //[DEBUGGING - Red Texture]
    //        // This is going to put some red in the texture.
    //        // The texture is not compressed.
    //        BYTE *color_array = new BYTE[texwidth*texheight*4];
    //        for (unsigned int i = 0; i < texwidth*texheight*4; i += 4)
    //        {
    //            color_array[i + 0] = 0xff;
    //            color_array[i + 1] = _SMipLevel * 0x3F;
    //            color_array[i + 2] = 0x0;
    //            color_array[i + 3] = 0xFF;
    //        }
    //        glTexImage2D(GL_TEXTURE_2D,
    //            _SMipLevel,
    //            GL_RGBA8, texwidth, texheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, color_array);
    //        CHECKGL_MSG(glTexImage2D);
    //        delete [] color_array;
    //    }

    CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, GetGraphicsDisplay()->GetGpuDevice()->GetPixelStoreAlignment()));

    _Initialized = true;
    return OGL_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::Trackable::IsDynamic ( ) const [inherited]

Test if object was allocated dynamically.

Definition at line 201 of file Object.cpp.

  {
    // Get pointer to beginning of the memory occupied by this.
    const void *ptr = dynamic_cast<const void *> (this);

    // Search for ptr in allocation_list
#if defined(NUX_OS_WINDOWS) && !defined(NUX_VISUAL_STUDIO_2010)
    std::list<void*>::iterator i = std::find(GObjectStats._allocation_list.begin(),
      GObjectStats._allocation_list.end(), ptr);
#else
    auto i = std::find(GObjectStats._allocation_list.begin(),
                       GObjectStats._allocation_list.end(), ptr);
#endif
    return i != GObjectStats._allocation_list.end();
  }

Here is the caller graph for this function:

bool nux::Trackable::IsHeapAllocated ( ) [inherited]

Test if object was allocated dynamically.

Definition at line 191 of file Object.cpp.

  {
    if (_heap_allocated == -1)
    {
      _heap_allocated = (IsDynamic () ? 1 : 0);
    }

    return (_heap_allocated == 1 ? true : false);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

int nux::IOpenGLSurface::LockRect ( SURFACE_LOCKED_RECT pLockedRect,
const SURFACE_RECT pRect 
)

Definition at line 126 of file IOpenGLSurface.cpp.

  {
    // If _LockedRect.pBits or _LockedRect.Pitch are not equal to zero, then we have already Locked the buffer
    // Unlock it before locking again.
    nuxAssert(_LockedRect.pBits == 0);
    nuxAssert(_LockedRect.Pitch == 0);
    nuxAssert(_CompressedDataSize == 0);

    if ((_LockedRect.pBits != 0) || (_LockedRect.Pitch != 0) || (_CompressedDataSize != 0))
    {
      // already locked;
      return OGL_INVALID_LOCK;
    }

    _Rect.bottom = _Rect.left = _Rect.right = _Rect.top = 0;

    GLint unpack_alignment = GPixelFormats[_BaseTexture->_PixelFormat].RowMemoryAlignment;
    unsigned int halfUnpack = Log2(unpack_alignment);

    CHECKGL(glBindTexture(_STextureTarget, _BaseTexture->_OpenGLID));

    unsigned int surface_size = 0;
    unsigned int BytePerPixel = 0;

    IOpenGLBaseTexture *texture = _BaseTexture;

    if (!((_BaseTexture->_ResourceType == RTTEXTURE) ||
          (_BaseTexture->_ResourceType == RTTEXTURERECTANGLE) ||
          (_BaseTexture->_ResourceType == RTCUBETEXTURE) ||
          (_BaseTexture->_ResourceType == RTVOLUMETEXTURE) ||
          (_BaseTexture->_ResourceType == RTANIMATEDTEXTURE)))
    {
      nuxAssertMsg(0, "Unknown resource type");
    }

    int texwidth, texheight;
    texwidth = ImageSurface::GetLevelDim(texture->_PixelFormat, texture->_Width, _SMipLevel);
    texheight = ImageSurface::GetLevelDim(texture->_PixelFormat, texture->_Height, _SMipLevel);

    if ( texture->_PixelFormat == BITFMT_DXT1 ||
         texture->_PixelFormat == BITFMT_DXT2 ||
         texture->_PixelFormat == BITFMT_DXT3 ||
         texture->_PixelFormat == BITFMT_DXT4 ||
         texture->_PixelFormat == BITFMT_DXT5)
    {
      if (texture->_PixelFormat == BITFMT_DXT1)
      {
        // We can conceive a 4x4 DXT1 block as if each texel uses 4 bits.
        // Actually, for DXT, we have 2 16-bits colors(5:6:5), and each texel uses 2 bits to interpolate
        // between the 2 colors.
        //    ---------------------
        //    |      COLOR0       | 16 bits
        //    ---------------------
        //    |      COLOR1       | 16 bits
        //    ---------------------
        //    | xx | xx | xx | xx | xx = 2 bits
        //    ---------------------
        //    | xx | xx | xx | xx |
        //    ---------------------
        //    | xx | xx | xx | xx |
        //    ---------------------
        //    | xx | xx | xx | xx |
        //    ---------------------

        // A line of n texel DXT1 data uses n/2 bytes(4 bits/texel). So the number of bytes used for a
        // texwidth texel, is texwidth/2 bytes.
        // Note that texwidth is divisible by 4(to to the upper rounding to 4), therefore, it is also divisible
        // by 2.

        // glCompressedTexImage2DARB, glCompressedTexImage3DARB,
        // glCompressedTexSubImage2DARB, glCompressedTexSubImage3DARB are not affected by glPixelStorei.
        surface_size = ImageSurface::GetLevelSize(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);
        _CompressedDataSize = surface_size;
        _LockedRect.Pitch = ImageSurface::GetLevelPitch(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);

        if (_Initialized == false)
        {
          InitializeLevel();
        }
      }
      else
      {
        // A line of n texel DXT3/5 data uses n bytes(1 byte/texel). So the number of bytes used for a
        // texwidth texels, is texwidth bytes.

        // glCompressedTexImage2DARB, glCompressedTexImage3DARB,
        // glCompressedTexSubImage2DARB, glCompressedTexSubImage3DARB are not affected by glPixelStorei.
        surface_size = ImageSurface::GetLevelSize(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);
        _CompressedDataSize = surface_size;
        _LockedRect.Pitch = ImageSurface::GetLevelPitch(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);

        if (_Initialized == false)
        {
          InitializeLevel();
        }
      }
    }
    else
    {
      _LockedRect.Pitch = ImageSurface::GetLevelPitch(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);
      surface_size = ImageSurface::GetLevelSize(texture->_PixelFormat, texture->_Width, texture->_Height, _SMipLevel);

      if (_Initialized == false)
      {
        InitializeLevel();
      }
    }

    _Rect.left  = 0;
    _Rect.top   = 0;
    _Rect.bottom  = texheight;
    _Rect.right   = texwidth;


    if (GetGraphicsDisplay()->GetGpuDevice()->UsePixelBufferObjects())
    {
      GetGraphicsDisplay()->GetGpuDevice()->AllocateUnpackPixelBufferIndex(&_AllocatedUnpackBuffer);
    }

    if (pRect == 0)
    {
      if (GetGraphicsDisplay()->GetGpuDevice()->UsePixelBufferObjects())
      {
        // Mapping the entire area of the surface
        _LockedRect.pBits = GetGraphicsDisplay()->GetGpuDevice()->LockUnpackPixelBufferIndex(_AllocatedUnpackBuffer, surface_size);
        pLockedRect->pBits = _LockedRect.pBits;
        pLockedRect->Pitch = _LockedRect.Pitch;
      }
      else
      {
        //[DEBUGGING - NO PBO]
        // Mapping the entire area of the surface
        _LockedRect.pBits = new BYTE[surface_size];
        pLockedRect->pBits = _LockedRect.pBits;
        pLockedRect->Pitch = _LockedRect.Pitch;
      }
    }
    else
    {
      //[WARNING]
      // this section of code is suppose to handle rectangles that are not the size of the entire surface.
      // It works for uncompressed texture. However it hasn't been tested for compressed texture.

      // reserve and lock a surface size equal  to(RectWidth * RectHeight * BytePerPixel)
      int RectWidth = pRect->right - pRect->left;
      int RectHeight = pRect->bottom - pRect->top;

      nuxAssert(RectWidth >= 0);
      nuxAssert(RectHeight >= 0);


      unsigned int RectSize = (((RectWidth * BytePerPixel + (unpack_alignment - 1)) >> (halfUnpack)) << (halfUnpack)) * RectHeight;

      if (RectSize == 0)
      {
        _LockedRect.pBits = NULL;
        _LockedRect.Pitch = 0;
        pLockedRect->pBits = NULL;
        pLockedRect->Pitch = 0;
        return OGL_INVALID_LOCK;
      }

      if (GetGraphicsDisplay()->GetGpuDevice()->UsePixelBufferObjects())
      {
        _LockedRect.pBits = GetGraphicsDisplay()->GetGpuDevice()->LockUnpackPixelBufferIndex(_AllocatedUnpackBuffer, RectSize);
        pLockedRect->pBits = ((BYTE *) _LockedRect.pBits);
        pLockedRect->Pitch = (((RectWidth * BytePerPixel + (unpack_alignment - 1)) >> (halfUnpack)) << (halfUnpack));
      }
      else
      {
        //[DEBUGGING - NO PBO]
        _LockedRect.pBits = new BYTE[RectSize];
        pLockedRect->pBits = ((BYTE *) _LockedRect.pBits);
        pLockedRect->Pitch = (((RectWidth * BytePerPixel + (unpack_alignment - 1)) >> (halfUnpack)) << (halfUnpack));
      }

      _Rect.left  = pRect->left;
      _Rect.top   = pRect->top;
      _Rect.bottom  = pRect->bottom;
      _Rect.right   = pRect->right;
    }

    return OGL_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nux::Object::NUX_DECLARE_OBJECT_TYPE ( BaseObject  ,
Trackable   
) [inherited]
void nux::Trackable::operator delete ( void *  ptr) [static, inherited]

Definition at line 178 of file Object.cpp.

  {
    ObjectStats::AllocationList::iterator i = std::find (GObjectStats._allocation_list.begin(), GObjectStats._allocation_list.end(), ptr);

    if (i != GObjectStats._allocation_list.end() )
    {
      GObjectStats._total_allocated_size -= NUX_STATIC_CAST (Trackable *, ptr)->_size_of_this_object;
      --GObjectStats._number_of_objects;
      GObjectStats._allocation_list.erase (i);
      ::operator delete (ptr);
    }
  }
void * nux::Trackable::operator new ( size_t  size) [static, inherited]

Definition at line 140 of file Object.cpp.

  {
    // Set the new_handler for this call
    std::new_handler global_handler  = std::set_new_handler (_new_current_handler);

    // If allocation fails _new_current_handler is called, if specified,
    // otherwise the global new_handler is called.
    void *ptr;

    try
    {
      ptr = ::operator new (size);

      GObjectStats._allocation_list.push_front (ptr);
      NUX_STATIC_CAST (Trackable *, ptr)->_size_of_this_object = size;
      GObjectStats._total_allocated_size += size;
      ++GObjectStats._number_of_objects;
    }
    catch (std::bad_alloc &)
    {
      std::set_new_handler (global_handler);
      throw;
    }

    //  Reset gloabal new_handler
    std::set_new_handler (global_handler);
    return ptr;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void * nux::Trackable::operator new ( size_t  size,
void *  ptr 
) [static, inherited]

Definition at line 171 of file Object.cpp.

  {
    return ::operator new (size, ptr);
  }

Here is the call graph for this function:

bool nux::Trackable::OwnsTheReference ( ) [inherited]

Test if object reference is owned.

Definition at line 117 of file Object.cpp.

  {
    return _owns_the_reference;
  }

Here is the caller graph for this function:

int nux::IOpenGLSurface::RefCount ( ) const [virtual]

Reimplemented from nux::IOpenGLResource.

Definition at line 117 of file IOpenGLSurface.cpp.

  {
    if (_BaseTexture)
      return _BaseTexture->RefCount();

    nuxAssert(0); // Surface with no underlying texture. That should not happen.
    return 0;
  }

Here is the call graph for this function:

bool nux::Object::Reference ( ) [virtual, inherited]

Increase reference count.

Returns:
True if the object has successfully referenced.

Reimplemented from nux::Trackable.

Definition at line 254 of file Object.cpp.

  {
    if (!IsHeapAllocated())
    {
      LOG_WARN(logger) << "Trying to reference an object that was not heap allocated."
                       << "\nObject allocated at: " << GetAllocationLoation() << "\n";
      return false;
    }

    if (!OwnsTheReference())
    {
      SetOwnedReference(true);
      // The ref count remains at 1. Exit the method.
      return true;
    }

    reference_count_->Increment();
    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::new_handler nux::Trackable::set_new_handler ( std::new_handler  handler) [static, inherited]

Definition at line 133 of file Object.cpp.

  {
    std::new_handler old_handler = _new_current_handler;
    _new_current_handler = handler;
    return old_handler;
  }

Here is the caller graph for this function:

void nux::Trackable::SetOwnedReference ( bool  b) [protected, inherited]

Definition at line 122 of file Object.cpp.

  {
    if (_owns_the_reference == true)
    {
      LOG_DEBUG(logger) << "Do not change the ownership if is already set to true!" << "\n";
      return;
    }

    _owns_the_reference = b;
  }

Here is the caller graph for this function:

bool nux::Introspectable::SetProperty ( std::string const &  name,
const char *  value 
) [inline, inherited]

If the property was not able to be set with the value, the method returns false.

Definition at line 262 of file Property-inl.h.

{
  PropertyContainer::iterator i = properties_.find(name);
  if (i == properties_.end())
    return false;
  else
    return i->second->SetValue(value);
}
template<typename T >
bool nux::Introspectable::SetProperty ( std::string const &  name,
T const &  value 
) [inherited]

Definition at line 273 of file Property-inl.h.

{
  PropertyContainer::iterator i = properties_.find(name);
  if (i == properties_.end())
    return false;
  else
  {
    return i->second->SetValue(type::PropertyTrait<T>::to_string(value));
  }
}
bool nux::Object::SinkReference ( ) [virtual, inherited]

Mark the object as owned.

If this object is not owned, calling SinkReference() as the same effect as calling Reference().

Returns:
True if the object was not owned previously

Reimplemented from nux::Trackable.

Definition at line 306 of file Object.cpp.

  {
    return Reference();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 313 of file IOpenGLSurface.cpp.

  {
    if (_LockedRect.pBits == 0)
    {
      return OGL_INVALID_UNLOCK;
    }

    CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, _BaseTexture->GetFormatRowMemoryAlignment()));

    BYTE *DataPtr = 0;

#ifndef NUX_OPENGLES_20
    if (_STextureTarget == GL_TEXTURE_2D || _STextureTarget == GL_TEXTURE_RECTANGLE_ARB || _STextureTarget == GL_TEXTURE_CUBE_MAP || _STextureTarget == GL_TEXTURE_3D)
#else
    if (_STextureTarget == GL_TEXTURE_2D)
#endif
    {
      int w = _Rect.right - _Rect.left;
      int h = _Rect.bottom - _Rect.top;
      CHECKGL(glBindTexture(_STextureTarget, _BaseTexture->_OpenGLID));

#ifndef NUX_OPENGLES_20
      if (GetGraphicsDisplay()->GetGpuDevice()->UsePixelBufferObjects())
      {
        // Unmap the texture image buffer
        GetGraphicsDisplay()->GetGpuDevice()->BindUnpackPixelBufferIndex(_AllocatedUnpackBuffer);
        CHECKGL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
        DataPtr = NUX_BUFFER_OFFSET(0);
      }
      else
      {
        CHECKGL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
#endif
        DataPtr = (BYTE *) _LockedRect.pBits;
#ifndef NUX_OPENGLES_20
      }
#endif

      IOpenGLTexture2D *texture = (IOpenGLTexture2D *) _BaseTexture;

#ifndef NUX_OPENGLES_20
      if ( /*texture->_PixelFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||*/
        texture->_PixelFormat == BITFMT_DXT1 ||
        texture->_PixelFormat == BITFMT_DXT2 ||
        texture->_PixelFormat == BITFMT_DXT3 ||
        texture->_PixelFormat == BITFMT_DXT4 ||
        texture->_PixelFormat == BITFMT_DXT5)
      {
        nuxAssert(_CompressedDataSize != 0);
        int width = Max<int> (1, texture->_Width >> _SMipLevel);
        int height = Max<int> (1, texture->_Height >> _SMipLevel);

        int xoffset = _Rect.left;
        int yoffset = _Rect.top;

        if (_STextureTarget != GL_TEXTURE_3D)
        {
          glCompressedTexSubImage2DARB(_SSurfaceTarget,
                                        _SMipLevel,                 // level
                                        xoffset,
                                        yoffset,
                                        width,
                                        height,
                                        GPixelFormats[texture->_PixelFormat].PlatformFormat,
                                        _CompressedDataSize,        // image Size
                                        DataPtr                     // data
                                       );
          CHECKGL_MSG(glCompressedTexSubImage2DARB);
        }
        else
        {
          glCompressedTexSubImage3DARB(_SSurfaceTarget,
                                        _SMipLevel,                 // level
                                        xoffset,
                                        yoffset,
                                        0,
                                        width,
                                        height,
                                        _SSlice,
                                        GPixelFormats[texture->_PixelFormat].PlatformFormat,
                                        _CompressedDataSize,        // image Size
                                        DataPtr                     // data
                                       );
          CHECKGL_MSG(glCompressedTexSubImage3DARB);
        }

        // We can use glCompressedTexImage2DARB if we are sure we always lock
        // the entire area of the surface.
        //            glCompressedTexImage2DARB(_SSurfaceTarget,
        //                _SMipLevel,                 // level
        //                texture->_Format,
        //                width,
        //                height,
        //                0,                          // border
        //                _CompressedDataSize,        // image Size
        //                _LockedRect.pBits           // data
        //                );
        //            CHECKGL_MSG(glCompressedTexImage2DARB);


        //            { //[DEBUGGING - Red Texture]
        //                // This is going to put some red in the texture.
        //                // The texture is not compressed.
        //                BYTE *color_array = new BYTE[width*height*4];
        //                for (int i = 0; i < width*height*4; i += 4)
        //                {
        //                    color_array[i + 0] = 0xff;
        //                    color_array[i + 1] = _SMipLevel * 0x3F;
        //                    color_array[i + 2] = 0x0;
        //                    color_array[i + 3] = 0xFF;
        //                }
        //                glTexImage2D(GL_TEXTURE_2D,
        //                    _SMipLevel,
        //                    GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, color_array);
        //                CHECKGL_MSG(glTexImage2D);
        //                delete [] color_array;
        //            }
      }
      else
      {
        //CHECKGL(glPixelStorei(GL_UNPACK_ROW_LENGTH, w));
        if (_STextureTarget != GL_TEXTURE_3D)
        {
#endif
          CHECKGL(glTexSubImage2D(_SSurfaceTarget,
                                     _SMipLevel,
                                     _Rect.left,
                                     _Rect.top,
                                     w,
                                     h,
                                     GPixelFormats[texture->_PixelFormat].Format,
                                     GPixelFormats[texture->_PixelFormat].type,
                                     DataPtr
                                    ));
#ifndef NUX_OPENGLES_20
        }
        else
        {
          CHECKGL(glTexSubImage3D(_SSurfaceTarget,
                                     _SMipLevel,
                                     _Rect.left,
                                     _Rect.top,
                                     _SSlice,          // z offset
                                     w,
                                     h,
                                     1,
                                     GPixelFormats[texture->_PixelFormat].Format,
                                     GPixelFormats[texture->_PixelFormat].type,
                                     DataPtr
                                    ));
        }

        //CHECKGL(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));

        //            CHECKGL(glTexImage2D(_SSurfaceTarget,
        //                _SMipLevel,
        //                GPixelFormats[texture->_PixelFormat].PlatformFormat,
        //                w,
        //                h,
        //                0,
        //                //### todo:
        //                //  - find the correct format matching the internal format
        //                //  - find the correct type matching the internal format
        //                GPixelFormats[texture->_PixelFormat].Format,
        //                GPixelFormats[texture->_PixelFormat].type,
        //                DataPtr
        //                ));

      }
#endif
    }
    else
    {
      nuxDebugMsg("[IOpenGLSurface::UnlockRect] Incorrect Texture Target.");
    }

#ifndef NUX_OPENGLES_20
    if (GetGraphicsDisplay()->GetGpuDevice()->UsePixelBufferObjects())
    {
      CHECKGL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
      GetGraphicsDisplay()->GetGpuDevice()->FreeUnpackPixelBufferIndex(_AllocatedUnpackBuffer);
    }
    else
    {
#endif
      //[DEBUGGING - NO PBO]
      if (_LockedRect.pBits)
      {
        delete [] ((BYTE *) _LockedRect.pBits);
      }
#ifndef NUX_OPENGLES_20
    }
#endif

    CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, GetGraphicsDisplay()->GetGpuDevice()->GetPixelStoreAlignment()));

    _LockedRect.pBits = 0;
    _LockedRect.Pitch = 0;
    _CompressedDataSize = 0;

    return OGL_OK;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::Object::UnReference ( ) [virtual, inherited]

Decrease reference count.

Returns:
True if the object reference count has reached 0 and the object has been destroyed.

Reimplemented from nux::Trackable.

Definition at line 274 of file Object.cpp.

  {
    if (!IsHeapAllocated())
    {
      LOG_WARN(logger) << "Trying to un-reference an object that was not heap allocated."
                       << "\nObject allocated at: " << GetAllocationLoation() << "\n";
      return false;
    }

    if (objectptr_count_->GetValue() == reference_count_->GetValue())
    {
      // There are ObjectPtr's hosting this object. Release all of them to
      // destroy this object.  This prevent from calling UnReference () many
      // times and destroying the object when there are ObjectPtr's hosting
      // it.  This method should not be called directly in that case.
      LOG_WARN(logger) << "There are ObjectPtr hosting this object. "
                       << "Release all of them to destroy this object. "
                       << "\nObject allocated at: " << GetAllocationLoation() << "\n";
      return false;
    }

    reference_count_->Decrement();

    if (reference_count_->GetValue() == 0)
    {
      Destroy();
      return true;
    }

    return false;
  }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class IOpenGLAnimatedTexture [friend]

Reimplemented from nux::IOpenGLResource.

Definition at line 121 of file IOpenGLSurface.h.

friend class IOpenGLCubeTexture [friend]

Reimplemented from nux::IOpenGLResource.

Definition at line 119 of file IOpenGLSurface.h.

friend class IOpenGLRectangleTexture [friend]

Reimplemented from nux::IOpenGLResource.

Definition at line 118 of file IOpenGLSurface.h.

friend class IOpenGLTexture2D [friend]

Reimplemented from nux::IOpenGLResource.

Definition at line 117 of file IOpenGLSurface.h.

friend class IOpenGLVolumeTexture [friend]

Reimplemented from nux::IOpenGLResource.

Definition at line 120 of file IOpenGLSurface.h.

friend class ObjectPtr< IOpenGLSurface > [friend]

Definition at line 122 of file IOpenGLSurface.h.


Member Data Documentation

Definition at line 116 of file IOpenGLSurface.h.

Definition at line 113 of file IOpenGLSurface.h.

Definition at line 111 of file IOpenGLSurface.h.

int nux::Trackable::_heap_allocated [protected, inherited]

Definition at line 158 of file Object.h.

Definition at line 114 of file IOpenGLSurface.h.

Definition at line 109 of file IOpenGLSurface.h.

Definition at line 110 of file IOpenGLSurface.h.

Definition at line 106 of file IOpenGLSurface.h.

Definition at line 107 of file IOpenGLSurface.h.

Definition at line 105 of file IOpenGLSurface.h.

Definition at line 93 of file IOpenGLSurface.h.

sigc::signal<void, Object *> nux::Object::object_destroyed [inherited]

Signal emitted immediately before the object is destroyed.

Definition at line 214 of file Object.h.


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