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
nux::TextureCube Class Reference

#include <GLTextureResourceManager.h>

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

List of all members.

Public Member Functions

 TextureCube (NUX_FILE_LINE_PROTO)
 TextureCube (const TextureCube &texture)
TextureCubeoperator= (const TextureCube &texture)
 ~TextureCube ()
virtual bool Update (const NBitmapData *BitmapData, bool UpdateAndCacheResource=true)
 Update the texture with the provided Bitmap data.
virtual bool Update (const char *filename, bool UpdateAndCacheResource=true)
 Update the texture with the provided filename.
virtual bool IsNull () const
void GetData (void *Buffer, int MipIndex, int StrideY, int face=0)
int GetNumMipLevel () const
int GetWidth () const
int GetHeight () const
BitmapFormat GetFormat () const
bool IsPowerOfTwo () const
virtual BaseTextureClone () const
 Clone the texture.
 NUX_DECLARE_OBJECT_TYPE (BaseObject, Trackable)
int GetResourceIndex () 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 (TextureCube, BaseTexture)

Private Attributes

NCubemapData _image

Detailed Description

Definition at line 339 of file GLTextureResourceManager.h.


Constructor & Destructor Documentation

Here is the caller graph for this function:

Definition at line 632 of file GLTextureResourceManager.cpp.

  {
    _image = texture._image;
  }

Definition at line 646 of file GLTextureResourceManager.cpp.

  {

  }

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:

BaseTexture * nux::TextureCube::Clone ( ) const [virtual]

Clone the texture.

Returns:
A cloned version of this texture.

Implements nux::BaseTexture.

Definition at line 698 of file GLTextureResourceManager.cpp.

  {
    TextureCube* texture = new TextureCube(*this);
    return texture;
  }

Here is the call 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:

void nux::TextureCube::GetData ( void *  Buffer,
int  MipIndex,
int  StrideY,
int  face = 0 
) [virtual]

Implements nux::BaseTexture.

Definition at line 683 of file GLTextureResourceManager.cpp.

  {
    BYTE              *Dest        = (BYTE *) Buffer;
    const BYTE         *Src         = _image.GetSurface(face, MipIndex).GetPtrRawData();
    int                 RowByteSize = _image.GetSurface(face, MipIndex).GetPitch();
    int                 NumRows     = _image.GetSurface(face, MipIndex).GetBlockHeight();

    for ( int Y = 0; Y < NumRows; Y++ )
    {
      // Take Min(RowByteSize, StrideY): the source and the destination may not have the same Pitch but
      // they contain the same amount of valid data since they have the same width, height and format.
      Memcpy(Dest + Y * StrideY, &Src[Y * RowByteSize], Min(RowByteSize, StrideY));
    }
  }

Here is the call graph for this function:

BitmapFormat nux::TextureCube::GetFormat ( ) const [inline, virtual]
Returns:
The texture data format.

Implements nux::BaseTexture.

Definition at line 389 of file GLTextureResourceManager.h.

    {
      return _image.GetFormat();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

int nux::TextureCube::GetHeight ( ) const [inline, virtual]
Returns:
The texture height.

Implements nux::BaseTexture.

Definition at line 381 of file GLTextureResourceManager.h.

    {
      return _image.GetHeight();
    }

Here is the call graph for this function:

int nux::TextureCube::GetNumMipLevel ( ) const [inline, virtual]
Returns:
The number of mip maps in the texture.

Implements nux::BaseTexture.

Definition at line 365 of file GLTextureResourceManager.h.

    {
      return _image.GetNumMipmap();
    }

Here is the call graph for this function:

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;
  }
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:

int nux::ResourceData::GetResourceIndex ( ) const [inherited]

Definition at line 56 of file GLResourceManager.cpp.

  {
    return m_ResourceIndex;
  }

Here is the caller graph for this function:

int nux::TextureCube::GetWidth ( ) const [inline, virtual]
Returns:
The texture width.

Implements nux::BaseTexture.

Definition at line 373 of file GLTextureResourceManager.h.

    {
      return _image.GetWidth();
    }

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:

virtual bool nux::TextureCube::IsNull ( ) const [inline, virtual]
Returns:
True if the texture storage contains valid bitmap data.

Implements nux::BaseTexture.

Definition at line 356 of file GLTextureResourceManager.h.

    {
      return _image.IsNull();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::TextureCube::IsPowerOfTwo ( ) const [inline, virtual]
Returns:
True if the width and height of the texture are powers of two.

Implements nux::BaseTexture.

Definition at line 397 of file GLTextureResourceManager.h.

Here is the call 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:

TextureCube & nux::TextureCube::operator= ( const TextureCube texture)

Definition at line 637 of file GLTextureResourceManager.cpp.

  {
    if (this == &texture)
      return *this;   // Handle self assignment

    _image = texture._image;
    return *this;
  }
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:

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:

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:

bool nux::TextureCube::Update ( const NBitmapData BitmapData,
bool  UpdateAndCacheResource = true 
) [virtual]

Update the texture with the provided Bitmap data.

In doing so, if the texture as been cached in the resource manager, then the the DeviceTexture inside the CachedTexture will no longer be returned by GetDeviceTexture(). Instead a new device texture will be returned.

Pointer to the bitmap data. If true, then the texture is cached immediately. If false, the texture will be cached the first time GetDeviceTexture() or GetCachedTexture() is called.

Returns:
True if there was no error during the update.

Implements nux::BaseTexture.

Definition at line 651 of file GLTextureResourceManager.cpp.

  {
    nuxAssertMsg(BitmapData, "[TextureCube::Update] Argument BitmapData is NULL.");
    NUX_RETURN_VALUE_IF_NULL(BitmapData, false);

    if (!BitmapData->IsCubemapTextureData())
    {
      nuxAssertMsg(0, "[TextureCube::Update] Argument BitmapData is not a Cube texture");
      return false;
    }

    _image = *static_cast<const NCubemapData*> (BitmapData);

    if (UpdateAndCacheResource)
    {
      // call the texture manager and recreate the texture(CachedTexture2D) associated with this object if any.
      GetGraphicsDisplay()->GetGraphicsEngine()->UpdateResource(this);
    }

    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::TextureCube::Update ( const char *  filename,
bool  UpdateAndCacheResource = true 
) [virtual]

Update the texture with the provided filename.

In doing so, if the texture as been cached in the resource manager, then the the DeviceTexture inside the CachedTexture will no longer be returned by GetDeviceTexture(). Instead a new device texture will be returned.

Pointer to the bitmap data. If true, then the texture is cached immediately. If false, the texture will be cached the first time GetDeviceTexture() or GetCachedTexture() is called.

Returns:
True if there was no error during the update.

Implements nux::BaseTexture.

Definition at line 673 of file GLTextureResourceManager.cpp.

  {
    NBitmapData* BitmapData = LoadImageFile(filename);
    nuxAssertMsg(BitmapData, "[TextureCube::Update] Bitmap for file(%s) is NULL.", filename);
    NUX_RETURN_VALUE_IF_NULL(BitmapData, false);
    bool ret = Update(BitmapData);
    NUX_SAFE_DELETE(BitmapData);
    return ret;
  }

Here is the call graph for this function:


Member Data Documentation

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

Definition at line 158 of file Object.h.

Definition at line 409 of file GLTextureResourceManager.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: