Triton
Visual simulation library for ocean rendering.
Public Member Functions | List of all members
Triton::ResourceLoader Class Reference

This class is used whenever Triton needs to load textures, data files, or shaders from mass storage; you may extend this class to override our default use of POSIX filesystem calls with your own resource management if you wish. More...

#include <ResourceLoader.h>

Inheritance diagram for Triton::ResourceLoader:
Inheritance graph
[legend]
Collaboration diagram for Triton::ResourceLoader:
Collaboration graph
[legend]

Public Member Functions

 ResourceLoader (const char *resourceDirPath, bool useAddDllDirectory=false)
 Constructor.
 
virtual ~ResourceLoader ()
 Virtual destructor; frees the memory of the resource path string.
 
virtual void TRITONAPI SetResourceDirPath (const char *path, bool useAddDllDirectory=false)
 Sets the path to the Triton resources folder, which will be pre-pended to all resource filenames passed into LoadResource().
 
virtual const char *TRITONAPI GetResourceDirPath () const
 Retrieves the path set by SetResourceDirPath().
 
virtual bool TRITONAPI LoadResource (const char *pathName, char *&data, unsigned int &dataLen, bool text)
 Load a resource from mass storage; the default implementation uses the POSIX functions fopen(), fread(), and fclose() to do this, but you may override this method to load resources however you wish.
 
virtual void TRITONAPI FreeResource (char *data)
 Frees the resource data memory that was returned from LoadResource().
 

Detailed Description

This class is used whenever Triton needs to load textures, data files, or shaders from mass storage; you may extend this class to override our default use of POSIX filesystem calls with your own resource management if you wish.

If you have your own system of packed files, you can include Triton's resources directory into it and implement your own ResourceLoader to access our resources within your pack files.

Constructor & Destructor Documentation

◆ ResourceLoader()

Triton::ResourceLoader::ResourceLoader ( const char *  resourceDirPath,
bool  useAddDllDirectory = false 
)

Constructor.

Parameters
resourceDirPathThe path to Triton's resources folder. Avoid using relative paths if at all possible.
useAddDllDirectoryOnly applicable to Windows; controls whether we attempt to add the resources/dll directory to the DLL search path using the Windows AddDLLDirectory function instead of SetDLLDirectory. AddDllDirectory is less destructive to the exisiting DLL search path, but is not well supported on older systems.

Member Function Documentation

◆ FreeResource()

virtual void TRITONAPI Triton::ResourceLoader::FreeResource ( char *  data)
virtual

Frees the resource data memory that was returned from LoadResource().

The data pointer will be invalid following this call.

◆ LoadResource()

virtual bool TRITONAPI Triton::ResourceLoader::LoadResource ( const char *  pathName,
char *&  data,
unsigned int &  dataLen,
bool  text 
)
virtual

Load a resource from mass storage; the default implementation uses the POSIX functions fopen(), fread(), and fclose() to do this, but you may override this method to load resources however you wish.

The caller is responsible for calling FreeResource() when it's done consuming the resource data in order to free its memory.

Parameters
pathNameThe path to the desired resource, relative to the location of the resources folder previously specified in SetResourceDirPath().
dataA reference to a char * that will return the resource's data upon a successful load.
dataLenA reference to an unsigned int that will return the number of bytes loaded upon a successful load.
textTrue if the resource is a text file, such as a shader. If true, a terminating null character will be appended to the resulting data and the file will be opened in text mode.
Returns
True if the resource was located and loaded successfully, false otherwise.
See also
SetResourceDirPath

◆ SetResourceDirPath()

virtual void TRITONAPI Triton::ResourceLoader::SetResourceDirPath ( const char *  path,
bool  useAddDllDirectory = false 
)
virtual

Sets the path to the Triton resources folder, which will be pre-pended to all resource filenames passed into LoadResource().

This method also calls the Win32 function AddDllDirectory in order to add the dll subdirectory to the application's DLL search path. This should be a fully qualified path and not a relative one if at all possible.

Parameters
pathThe path to Triton's Resources folder; avoid using relative paths.
useAddDllDirectoryOn Windows, controls whether we attempt to use the AddDllDirectory function instead of SetDLLDirectory in order to add our runtime dependencies into the DLL search path.

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