Ocular Engine
Ocular::Graphics::TextureResourceLoader Class Referenceabstract

#include <TextureResourceLoader.hpp>

Inheritance diagram for Ocular::Graphics::TextureResourceLoader:
Ocular::Core::AResourceLoader Ocular::Graphics::TextureResourceLoader_BMP Ocular::Graphics::TextureResourceLoader_PNG Ocular::Graphics::TextureResourceLoader_TGA

Public Member Functions

 TextureResourceLoader (std::string const &extension)
 
virtual bool loadResource (Core::Resource *&resource, Core::File const &file, std::string const &mappingName) override
 
- Public Member Functions inherited from Ocular::Core::AResourceLoader
 AResourceLoader (std::string const &extension, ResourceType type)
 
virtual std::string getSupportedFileType () const
 
virtual bool loadSubResource (Resource *&resource, File const &file, std::string const &mappingName)
 
virtual bool exploreResource (File const &file)
 
ResourceType getResourceType () const
 

Protected Member Functions

virtual bool readFile (Core::File const &file, std::vector< Core::Color > &pixels, unsigned &width, unsigned &height)=0
 
virtual bool createResource (Core::Resource *&resource, Core::File const &file, std::vector< Core::Color > const &pixels, unsigned const &width, unsigned const &height)
 
virtual void loadFileIntoBuffer (Core::File const &file, std::vector< unsigned char > &buffer, Endianness fileEndianness)
 
- Protected Member Functions inherited from Ocular::Core::AResourceLoader
bool isFileValid (Core::File const &file) const
 

Additional Inherited Members

- Protected Attributes inherited from Ocular::Core::AResourceLoader
std::string m_SupportedExtension
 
ResourceType m_Type
 

Detailed Description

This is a common base implementation for all other ResourceLoaders that deal with creating and loading Texture2D resources. It provides a common base loadResource method as well as multiple utility helper methods.

By inheriting from TextureResourceLoader instead of AResourceLoader, the developer needs to only worry about their specific readFile implementation.

Member Function Documentation

bool Ocular::Graphics::TextureResourceLoader::createResource ( Core::Resource *&  resource,
Core::File const &  file,
std::vector< Core::Color > const &  pixels,
unsigned const &  width,
unsigned const &  height 
)
protectedvirtual

Creates the new Texture2D resource from provided pixel data.

Parameters
[out]resourceThe newly created resource.
[in]fileSource file for the resource.
[in]pixelsPixel data for the texture arranged by rows.
[in]widthWidth of the texture.
[in]heightHeight of the texture.
Returns
TRUE if creation was successful.
void Ocular::Graphics::TextureResourceLoader::loadFileIntoBuffer ( Core::File const &  file,
std::vector< unsigned char > &  buffer,
Endianness  fileEndianness 
)
protectedvirtual

Attempts to load the binary contents of the specified file into the provided empty buffer. If the data was properly retrieved, it will then be converted to the current system's native endianness.

Parameters
[in]fileSource file of the resource texture.
[out]bufferRaw binary data of the file.
[in]fileEndiannessThe endianness of the file.
bool Ocular::Graphics::TextureResourceLoader::loadResource ( Core::Resource *&  resource,
Core::File const &  file,
std::string const &  mappingName 
)
overridevirtual
Parameters
[out]resource
[in]file
[in]mappingName

Reimplemented from Ocular::Core::AResourceLoader.

virtual bool Ocular::Graphics::TextureResourceLoader::readFile ( Core::File const &  file,
std::vector< Core::Color > &  pixels,
unsigned &  width,
unsigned &  height 
)
protectedpure virtual

Each TextureResourceLoader must provide a custom implementation for it's specific file type.

Parameters
[in]fileSource file to read from.
[out]pixelsTexture pixel data read in from the file.
[out]widthWidth of the texture.
[out]heightHeight of the texture.
Returns
TRUE if file was read in successfully.

Implemented in Ocular::Graphics::TextureResourceLoader_BMP, Ocular::Graphics::TextureResourceLoader_PNG, and Ocular::Graphics::TextureResourceLoader_TGA.


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