Triton
Visual simulation library for ocean rendering.
|
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>
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(). | |
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.
Triton::ResourceLoader::ResourceLoader | ( | const char * | resourceDirPath, |
bool | useAddDllDirectory = false |
||
) |
Constructor.
resourceDirPath | The path to Triton's resources folder. Avoid using relative paths if at all possible. |
useAddDllDirectory | Only 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. |
|
virtual |
Frees the resource data memory that was returned from LoadResource().
The data pointer will be invalid following this call.
|
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.
pathName | The path to the desired resource, relative to the location of the resources folder previously specified in SetResourceDirPath(). |
data | A reference to a char * that will return the resource's data upon a successful load. |
dataLen | A reference to an unsigned int that will return the number of bytes loaded upon a successful load. |
text | True 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. |
|
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.
path | The path to Triton's Resources folder; avoid using relative paths. |
useAddDllDirectory | On 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. |