The Nebula Device 3: Resources::D3D9TextureStreamer Class Reference

The Nebula Device 3

Resources::D3D9TextureStreamer Class Reference

#include <d3d9texturestreamer.h>

Inheritance diagram for Resources::D3D9TextureStreamer:

Resources::StreamResourceLoader Resources::ResourceLoader Core::RefCounted Resources::TextureStreamer

Detailed Description

Resource loader for loading texture data from a Nebula3 stream. Supports synchronous and asynchronous loading. Specialized for DirectX 9.

(C) 2010 Radon Labs GmbH

Public Member Functions

virtual bool SetupResourceFromStream (const Ptr< IO::Stream > &stream)
 setup the texture from a Nebula3 stream
void SetReuseTexture (const Ptr< CoreGraphics::Texture > &tex)
 sets the texture to reuse on load
const Ptr< CoreGraphics::Texture > & GetReuseTexture () const
 get the texture to reuse on load (may return 0!)
virtual void Reset ()
 resets loader-stats e.g. state and reuseTexture (does not cut connection to Resource!)
virtual bool OnLoadRequested ()
 called by resource when a load is requested
virtual bool CanLoadAsync () const
 override in subclass: return true if asynchronous loading is supported (default is true)
virtual void OnLoadCancelled ()
 called by resource to cancel a pending load
virtual bool OnPending ()
 call frequently while after OnLoadRequested() to put Resource into loaded state
virtual void OnAttachToResource (const Ptr< Resource > &res)
 called when the resource loader is attached to its resource
virtual void OnRemoveFromResource ()
 called when the resource loader is removed from its resource
bool IsAttachedToResource () const
 return true if attached to resource
const Ptr< Resource > & GetResource () const
 get pointer to resource
Resource::State GetState () const
 return current state
int GetRefCount () const
 get the current refcount
void AddRef ()
 increment refcount by one
void Release ()
 decrement refcount and destroy object if refcount is zero
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
const Util::StringGetClassName () const
 get the class name
Util::FourCC GetClassFourCC () const
 get the class FourCC code

Static Public Member Functions

static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

Protected Member Functions

virtual bool SetupTexture2DFromStream (const Ptr< IO::Stream > &stream)
 setup a 2D texture from a Nebula3 stream
virtual bool SetupTextureCubeFromStream (const Ptr< IO::Stream > &stream)
 setup a cube texture from a Nebula3 stream
virtual bool ReuseMips ()
 copies mips from reuseTexture to targeted texture
virtual void LockSurfaces (Util::Array< D3DLOCKED_RECT > &lockedRects, const Ptr< CoreGraphics::Texture > &tex, SizeT numMipsToLock=-1)
 locks all surfaces of given texture
virtual void UnlockSurfaces (const Ptr< CoreGraphics::Texture > &tex)
 unlocks all surfaces of given texture
void GetSurfaceInfo (uint width, uint height, D3DFORMAT fmt, uint *pNumBytes, uint *pRowBytes, uint *pNumRows) const
 calculates surface information depending on given width, height and pixel format
uint BitsPerPixel (D3DFORMAT fmt) const
 returns appropriate bit-per-pixel-count of given pixel format by looking it up in a table
uint GetNumRows (uint height, D3DFORMAT fmt) const
 returns the number of rows in a line (may depend on format)
void SetState (Resource::State s)
 set current state

Member Function Documentation

bool Resources::D3D9TextureStreamer::SetupResourceFromStream ( const Ptr< IO::Stream > &  stream  )  [virtual]

setup the texture from a Nebula3 stream

This method actually setups the Texture object from the data in the stream.

Reimplemented from Resources::StreamResourceLoader.

bool Resources::D3D9TextureStreamer::OnLoadRequested (  )  [virtual]

called by resource when a load is requested

If we can copy the Texture' data totally from another Texture in memory we don't need to create a file stream.

Reimplemented from Resources::StreamResourceLoader.

bool Resources::D3D9TextureStreamer::SetupTexture2DFromStream ( const Ptr< IO::Stream > &  stream  )  [protected, virtual]

setup a 2D texture from a Nebula3 stream

Call this method if something has to be loaded from disk. This may include total reuse of another texture but not partial reuse as this can be done by calling D3D9TextureStreamer::ReuseMips which doesn't require a file stream.

bool Resources::D3D9TextureStreamer::ReuseMips (  )  [protected, virtual]

copies mips from reuseTexture to targeted texture

NOTE: Ensure surfaces which are overwritten by this method are NOT LOCKED otherwise D3DXLoadSurfaceFromSurface may not work correctly (HRESULT is S_OK but texture is incorrect anyway).

void Resources::D3D9TextureStreamer::GetSurfaceInfo ( uint  width,
uint  height,
D3DFORMAT  fmt,
uint *  pNumBytes,
uint *  pRowBytes,
uint *  pNumRows 
) const [protected]

calculates surface information depending on given width, height and pixel format

This method is taken from DirectX SDK Aug 2007 (contained in newer SDKs, too).

bool Resources::StreamResourceLoader::CanLoadAsync (  )  const [virtual, inherited]

override in subclass: return true if asynchronous loading is supported (default is true)

Indicate whether this resource loader supports asynchronous loading. The default is true. Override this method in a subclass and return false otherwise.

Reimplemented from Resources::ResourceLoader.

Reimplemented in Direct3D9::D3D9StreamShaderLoader.

void Resources::StreamResourceLoader::OnLoadCancelled (  )  [virtual, inherited]

called by resource to cancel a pending load

This method is called when the currently pending asynchronous load request should be cancelled.

Reimplemented from Resources::ResourceLoader.

bool Resources::StreamResourceLoader::OnPending (  )  [virtual, inherited]

call frequently while after OnLoadRequested() to put Resource into loaded state

This method is called periodically by the client when the resource is in pending state. The pending ReadStream message will be checked, and if it has been handled successfully the SetupResourceFromStream() method will be called and the Resource will go into Loaded state. If anything goes wrong, the resource will go into Failed state.

Reimplemented from Resources::ResourceLoader.

int Core::RefCounted::GetRefCount (  )  const [inline, inherited]

get the current refcount

Return the current refcount of the object.

void Core::RefCounted::AddRef (  )  [inline, inherited]

increment refcount by one

Increment the refcount of the object.

void Core::RefCounted::Release (  )  [inline, inherited]

decrement refcount and destroy object if refcount is zero

Decrement the refcount and destroy object if refcount is zero.

const Util::String & Core::RefCounted::GetClassName (  )  const [inline, inherited]

get the class name

Get the class name of the object.

Util::FourCC Core::RefCounted::GetClassFourCC (  )  const [inline, inherited]

get the class FourCC code

Get the class FourCC of the object.

void Core::RefCounted::DumpRefCountingLeaks (  )  [static, inherited]

dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

This method should be called as the very last before an application exits.