Ocular Engine
Ocular::Graphics::TextureResourceSaver Class Referenceabstract

#include <TextureResourceSaver.hpp>

Inheritance diagram for Ocular::Graphics::TextureResourceSaver:
Ocular::Core::AResourceSaver Ocular::Graphics::TextureResourceSaver_BMP Ocular::Graphics::TextureResourceSaver_PNG

Public Member Functions

 TextureResourceSaver (std::string const &extension)
virtual bool saveResource (Core::Resource *resource, Core::File const &file)
- Public Member Functions inherited from Ocular::Core::AResourceSaver
 AResourceSaver (std::string const &extension, ResourceType type)
virtual std::string getSupportedFileType () const
ResourceType getResourceType () const

Protected Member Functions

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

Additional Inherited Members

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

Detailed Description

This is a common base implementation for all other ResourceSavers that deal with saving Texture2D resources to disk. It provides a common base saveResource method as well as multiple utility helper methods.

By inheriting from TextureResourceSaver instead of AResourceSaver, the developer needs to only worry about their specific saveFile implementation.

Member Function Documentation

bool Ocular::Graphics::TextureResourceSaver::isFileValid ( Core::File file)

Checks if the specified file is valid. It can be valid in one of two ways:

  • The file exists and is writeable
  • The file did not previously exist, but it (and potentially it's parent directories) successfully created
TRUE if the file is valid.
bool Ocular::Graphics::TextureResourceSaver::isResourceValid ( Core::Resource resource)

Checks if the specified resource is valid. It is valid when the following conditions are met:

  • The resource is not NULL
  • The resource is a Texture2D
TRUE if the resource is valid.
virtual bool Ocular::Graphics::TextureResourceSaver::saveFile ( Core::File const &  file,
std::vector< Core::Color > const &  pixels,
unsigned const  width,
unsigned const  height 
protectedpure virtual

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

The input into this method is guaranteed to be valid. This means

  • The source file exists and is writeable
  • The dimensions are valid
  • There is a non-zero number of pixels, and their number is equal to (width * height)
[in]fileFile to write to. This file has already been verified to exist and be writeable.
[in]pixelsTexture pixel data to write to the file.
[in]widthWidth of the texture.
[in]heightHeight of the texture.
TRUE if the file was successfully saved.

Implemented in Ocular::Graphics::TextureResourceSaver_BMP, and Ocular::Graphics::TextureResourceSaver_PNG.

bool Ocular::Graphics::TextureResourceSaver::saveResource ( Core::Resource resource,
Core::File const &  file 

Reimplemented from Ocular::Core::AResourceSaver.

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