Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::gfx::TextureManager Class Reference

TextureManager is an internal Ion class, and is not exported for public use. More...

#include "texturemanager.h"

Inheritance diagram for ion::gfx::TextureManager:
Collaboration diagram for ion::gfx::TextureManager:

Public Types

typedef const void * TextureType
 

Public Member Functions

 TextureManager (int max_texture_units)
 A TextureManager must be initialized with a size of at least 1. More...
 
 ~TextureManager () override
 
int GetUnit (TextureType texture, int current_unit)
 Returns the unit associated with the data pointer. More...
 
int GetBackIndex () const
 Returns the back unit. More...
 
int GetFrontIndex () const
 Returns the front unit. More...
 
TextureType GetTexture (int unit) const
 Returns the data at index unit. More...
 
void SetUnitRange (const math::Range1i &units)
 Sets the inclusive range of units that the TextureManager uses. More...
 
const AllocatorPtr & GetAllocator () const
 Returns the Allocator that was used for the instance. More...
 
const AllocatorPtr & GetNonNullAllocator () const
 Return our allocator, or the default allocator if the instance was declared on the stack. More...
 
const AllocatorPtr & GetAllocatorForLifetime (AllocationLifetime lifetime) const
 Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More...
 
void * operator new (size_t size)
 The standard no-parameter new operator uses the default Allocator. More...
 
void * operator new (size_t size, AllocationLifetime lifetime)
 This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator)
 This overloaded version of the new operator takes the Allocator to use directly as a parameter. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator, void *ptr)
 Special operator new for using placement new with Allocatables. More...
 
void * operator new (size_t size, void *ptr)
 The placement new operator is defined conventionally. More...
 
void operator delete (void *ptr)
 Define the delete operator to use specialized functions dealing with an Allocator. More...
 
void operator delete (void *ptr, AllocationLifetime lifetime)
 Windows requires these (or it issues C4291 warnings). More...
 
void operator delete (void *ptr, const AllocatorPtr &allocator)
 
void operator delete (void *ptr, void *ptr2)
 The placement delete operator does nothing, as usual. More...
 

Detailed Description

TextureManager is an internal Ion class, and is not exported for public use.

The TextureManager class associates pointers with texture unit IDs in an LRU fashion, but has a fixed number of units it can store. It attempts to preserve the mapping of data to units when possible, though that may not be possible if there are more requests for units than the TM contains. A TM must be initialized with a size of at least 2.

Definition at line 38 of file texturemanager.h.

Member Typedef Documentation

Definition at line 40 of file texturemanager.h.

Constructor & Destructor Documentation

ion::gfx::TextureManager::TextureManager ( int  max_texture_units)
explicit

A TextureManager must be initialized with a size of at least 1.

TextureManager implements an LRU queue using an linked-list implemented with an array of fixed size (no pointers).

Each item has a link to its previous and next item, though the front item's prev and the back item's next point to invalid indices (kEnd). For example, a queue of size 4 stars out looking like: front_ = 0 back_ = 3 items[0].prev = kEnd items[0].next = 1 items[1].prev = 0 items[1].next = 2 items[2].prev = 1 items[2].next = 3 items[3].prev = 2 items[3].next = kEnd and the order of items is: 0, 1, 2, 3. and all of the Texture pointers are NULL. When an item is Touch()ed, that becomes the back of the list, and the pointers update accordingly. Suppose that item 1 is Touch()ed, then the list becomes: front_ = 0 back_ = 1 items[0].prev = kEnd items[0].next = 2 items[1].prev = 3 items[1].next = kEnd items[2].prev = 1 items[2].next = 3 items[3].prev = 2 items[3].next = 1 and the order of items is now 0, 2, 3, 1. Note that since 1 is now the back of the queue, 3's next now points to 1.

Definition at line 62 of file texturemanager.cc.

References DCHECK_EQ, DCHECK_GE, and SetUnitRange().

ion::gfx::TextureManager::~TextureManager ( )
override

Definition at line 71 of file texturemanager.cc.

Member Function Documentation

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
inlineinherited

Returns the Allocator that was used for the instance.

This will be NULL if the instance was declared on the stack or created with normal placement new.

Definition at line 68 of file allocatable.h.

References allocator_.

Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
int ion::gfx::TextureManager::GetBackIndex ( ) const
inline

Returns the back unit.

Definition at line 52 of file texturemanager.h.

int ion::gfx::TextureManager::GetFrontIndex ( ) const
inline

Returns the front unit.

Definition at line 54 of file texturemanager.h.

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
inlineinherited

Return our allocator, or the default allocator if the instance was declared on the stack.

Definition at line 72 of file allocatable.h.

References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().

TextureManager::TextureType ion::gfx::TextureManager::GetTexture ( int  unit) const

Returns the data at index unit.

Definition at line 73 of file texturemanager.cc.

References DCHECK_GE, and DCHECK_LT.

int ion::gfx::TextureManager::GetUnit ( TextureType  texture,
int  current_unit 
)

Returns the unit associated with the data pointer.

current_unit contains the current association, or -1 if there is not yet one. The returned unit may not be the same as current_unit.

Definition at line 79 of file texturemanager.cc.

References DCHECK_LT, and texture.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
inlineinherited

This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.

Definition at line 88 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
inlineinherited

This overloaded version of the new operator takes the Allocator to use directly as a parameter.

If the Allocator pointer is NULL, this uses the default Allocator.

Definition at line 95 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

void ion::gfx::TextureManager::SetUnitRange ( const math::Range1i units)

Sets the inclusive range of units that the TextureManager uses.

If the range is invalid then this does nothing but log an error. Units must be non-negative, but if it extends beyond the number of units avaiable in hardware, it is clamped to the appropriate range.

Definition at line 125 of file texturemanager.cc.

References ion::port::ERROR, and LOG.

Referenced by TextureManager().


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