Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
CTextureConverter Class Reference

Texture conversion helper class. More...

#include <TextureConverter.h>

Classes

struct  ConversionRequest
 Request for worker thread to process. More...
 
struct  ConversionResult
 Result from worker thread. More...
 
struct  Match
 Representation of <File> line from settings XML file. More...
 
struct  Settings
 Texture conversion settings. More...
 
struct  SettingsFile
 Representation of settings XML file. More...
 

Public Types

enum  EFormat {
  FMT_UNSPECIFIED, FMT_DXT1, FMT_DXT3, FMT_DXT5,
  FMT_RGBA
}
 
enum  EMipmap { MIP_UNSPECIFIED, MIP_TRUE, MIP_FALSE }
 
enum  ENormalMap { NORMAL_UNSPECIFIED, NORMAL_TRUE, NORMAL_FALSE }
 
enum  EAlpha { ALPHA_UNSPECIFIED, ALPHA_NONE, ALPHA_PLAYER, ALPHA_TRANSPARENCY }
 
enum  EFilter { FILTER_UNSPECIFIED, FILTER_BOX, FILTER_TRIANGLE, FILTER_KAISER }
 

Public Member Functions

 CTextureConverter (PIVFS vfs, bool highQuality)
 Construct texture converter, for use with files in the given vfs. More...
 
 ~CTextureConverter ()
 Destroy texture converter and wait to shut down worker thread. More...
 
SettingsFileLoadSettings (const VfsPath &path) const
 Load a texture conversion settings XML file. More...
 
Settings ComputeSettings (const std::wstring &filename, const std::vector< SettingsFile * > &settingsFiles) const
 Match a sequence of settings files against a given texture filename, and return the resulting settings. More...
 
bool ConvertTexture (const CTexturePtr &texture, const VfsPath &src, const VfsPath &dest, const Settings &settings)
 Begin converting a texture, using the given settings. More...
 
bool Poll (CTexturePtr &texture, VfsPath &dest, bool &ok)
 Returns the result of a successful ConvertTexture call. More...
 
bool IsBusy ()
 Returns whether there is currently a queued request from ConvertTexture(). More...
 

Static Private Member Functions

static void * RunThread (void *data)
 

Private Attributes

PIVFS m_VFS
 
bool m_HighQuality
 
pthread_t m_WorkerThread
 
pthread_mutex_t m_WorkerMutex
 
SDL_semm_WorkerSem
 
std::deque< shared_ptr
< ConversionRequest > > 
m_RequestQueue
 
std::deque< shared_ptr
< ConversionResult > > 
m_ResultQueue
 
bool m_Shutdown
 

Detailed Description

Texture conversion helper class.

Provides an asynchronous API to convert input image files into compressed DDS, given various conversion settings. (The (potentially very slow) compression is a performed in a background thread, so the game can remain responsive). Also provides an API to load conversion settings from XML files.

XML files are of the form:

* <Textures>
* <File pattern="*" format="dxt5" mipmap="false" alpha="transparency"/>
* <File pattern="button_wood.*" format="rgba"/>
* </Entity>
*

'pattern' is a wildcard expression, matching on filenames. All other attributes are optional. Later elements override attributes from earlier elements.

'format' is 'dxt1', 'dxt3', 'dxt5' or 'rgba'.

'mipmap' is 'true' or 'false'.

'normal' is 'true' or 'false'.

'alpha' is 'transparency' or 'player' (it determines whether the colour value of 0-alpha pixels is significant or not).

'filter' is 'box', 'triangle' or 'kaiser'.

'kaiserwidth', 'kaiseralpha', 'kaiserstretch' are floats (see http://code.google.com/p/nvidia-texture-tools/wiki/ApiDocumentation#Mipmap_Generation)

Definition at line 63 of file TextureConverter.h.

Member Enumeration Documentation

Enumerator
ALPHA_UNSPECIFIED 
ALPHA_NONE 
ALPHA_PLAYER 
ALPHA_TRANSPARENCY 

Definition at line 89 of file TextureConverter.h.

Enumerator
FILTER_UNSPECIFIED 
FILTER_BOX 
FILTER_TRIANGLE 
FILTER_KAISER 

Definition at line 97 of file TextureConverter.h.

Enumerator
FMT_UNSPECIFIED 
FMT_DXT1 
FMT_DXT3 
FMT_DXT5 
FMT_RGBA 

Definition at line 66 of file TextureConverter.h.

Enumerator
MIP_UNSPECIFIED 
MIP_TRUE 
MIP_FALSE 

Definition at line 75 of file TextureConverter.h.

Enumerator
NORMAL_UNSPECIFIED 
NORMAL_TRUE 
NORMAL_FALSE 

Definition at line 82 of file TextureConverter.h.

Constructor & Destructor Documentation

CTextureConverter::CTextureConverter ( PIVFS  vfs,
bool  highQuality 
)

Construct texture converter, for use with files in the given vfs.

Definition at line 275 of file TextureConverter.cpp.

CTextureConverter::~CTextureConverter ( )

Destroy texture converter and wait to shut down worker thread.

This might take a long time (maybe seconds) if the worker is busy processing a texture.

Definition at line 302 of file TextureConverter.cpp.

Member Function Documentation

CTextureConverter::Settings CTextureConverter::ComputeSettings ( const std::wstring &  filename,
const std::vector< SettingsFile * > &  settingsFiles 
) const

Match a sequence of settings files against a given texture filename, and return the resulting settings.

Later entries in settingsFiles override earlier entries.

Definition at line 223 of file TextureConverter.cpp.

bool CTextureConverter::ConvertTexture ( const CTexturePtr texture,
const VfsPath src,
const VfsPath dest,
const Settings settings 
)

Begin converting a texture, using the given settings.

This will load src and return false on failure. Otherwise it will return true and start an asynchronous conversion request, whose result will be returned from Poll() (with the texture and dest passed into this function).

Definition at line 320 of file TextureConverter.cpp.

bool CTextureConverter::IsBusy ( )

Returns whether there is currently a queued request from ConvertTexture().

(Note this may return false while the worker thread is still converting the last texture.)

Definition at line 504 of file TextureConverter.cpp.

CTextureConverter::SettingsFile * CTextureConverter::LoadSettings ( const VfsPath path) const

Load a texture conversion settings XML file.

Returns NULL on failure.

Definition at line 95 of file TextureConverter.cpp.

bool CTextureConverter::Poll ( CTexturePtr texture,
VfsPath dest,
bool &  ok 
)

Returns the result of a successful ConvertTexture call.

If no result is available yet, returns false. Otherwise, if the conversion succeeded, it sets ok to true and sets texture and dest to the corresponding values passed into ConvertTexture(), then returns true. If the conversion failed, it sets ok to false and doesn't touch the other arguments, then returns true.

Definition at line 454 of file TextureConverter.cpp.

void * CTextureConverter::RunThread ( void *  data)
staticprivate

Definition at line 513 of file TextureConverter.cpp.

Member Data Documentation

bool CTextureConverter::m_HighQuality
private

Definition at line 204 of file TextureConverter.h.

std::deque<shared_ptr<ConversionRequest> > CTextureConverter::m_RequestQueue
private

Definition at line 211 of file TextureConverter.h.

std::deque<shared_ptr<ConversionResult> > CTextureConverter::m_ResultQueue
private

Definition at line 214 of file TextureConverter.h.

bool CTextureConverter::m_Shutdown
private

Definition at line 215 of file TextureConverter.h.

PIVFS CTextureConverter::m_VFS
private

Definition at line 203 of file TextureConverter.h.

pthread_mutex_t CTextureConverter::m_WorkerMutex
private

Definition at line 207 of file TextureConverter.h.

SDL_sem* CTextureConverter::m_WorkerSem
private

Definition at line 208 of file TextureConverter.h.

pthread_t CTextureConverter::m_WorkerThread
private

Definition at line 206 of file TextureConverter.h.


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