GL Studio API
texture_loader.h
Go to the documentation of this file.
1 /*! \file
2  \brief The TextureLoader and TextureLoaderList classes.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2015 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef INCLUDED_TEXTURE_LOADER_H
41 #define INCLUDED_TEXTURE_LOADER_H
42 
43 #include "gls_include.h"
44 #include "list.h"
45 #include "image.h"
46 #include "plugin.h"
47 
48 namespace disti
49 {
50 
51 class TextureLoader;
52 
53 /**
54  A list of (pointers to) texture loader objects.
55 */
56 class TextureLoaderList : public List_c
57 {
58  static GLS_EXPORT TextureLoaderList *_instance; /** A singleton interface */
59 
60  public:
61 
62  GLS_EXPORT TextureLoaderList();
63 
64  /** A singleton interface
65  * \return A pointer to the one and only instance
66  */
67  static GLS_EXPORT TextureLoaderList *Instance();
68 
69  /** enable / disable texture loading optimization (defaults to enabled)
70  * \param enable true to enable else false
71  */
72  static GLS_EXPORT void SetOptimizeTextureLoading( const bool enable );
73 
74  /** determine if texture loading optimization is enabled
75  * \return true if enabled else false
76  */
77  static GLS_EXPORT bool IsOptimizeTextureLoading();
78 
79  /** Insert the loader into the list at the specified location
80  * \param importer
81  */
82  GLS_EXPORT void InsertObject(TextureLoader *importer);
83 
84  /** Creates and returns a file filter string for all of the file types that have been
85  * registered by Texture Loaders
86  * \return Filter string */
87  GLS_EXPORT char *FilterString();
88 
89  /** Load the specified texture file. Try all loaders to see if any of them support
90  * the given file type.
91  * \param filename The file to load the image from
92  * \param options Options to load the image with
93  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
94  * \return NULL if the file type isn't supported or if loading fails
95  */
96  GLS_EXPORT Image *LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT = true);
97 
98  /** Load the specified texture file optionally attempting to optimize the load by looking at
99  * previously loaded images. Try all loaders to see if any of them support
100  * the given file type.
101  * \param filename The file to load the image from
102  * \param options Options to load the image with
103  * \param optimizeTextureLoad true to attempt loading optimization else false to force a load
104  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
105  * \return NULL if the file type isn't supported or if loading fails
106  */
107  GLS_EXPORT Image *LoadTextureWithOptimization(const char *filename, const Image::LoadOptions &options, const bool optimizeTextureLoad, bool allowNPOT = true);
108 
109 
110 #ifdef __APPLE__
111  /** Load the specified texture file optionally attempting to optimize the load by looking at
112  * previously loaded images.
113  *
114  * This method uses the iOS image loader classes to load the textures and thus supports whatever platform native loaders
115  * are supported by the iOS SDK.
116  *
117  * NOTE: This code will also give preference to texture files compressed using PowerVR Texture compression.
118  * The way that works is that if this code is asked to load 'xyz.png' and 'xyz.pvr' is found, then the .pvr
119  * file will be loaded instead.
120  *
121  * \return NULL if the file type isn't supported or if loading fails */
122  GLS_EXPORT Image *LoadTextureIOS(const char *filename, const Image::LoadOptions &options, const bool optimizeTextureLoad);
123 #endif
124 
125  /** Finds the registered texture loader, if any, that supports the given file
126  * extension.
127  * \param ext The (case insensitive) file extension
128  * \return A pointer to the registered loader, or NULL if no loader exists
129  */
130  GLS_EXPORT TextureLoader *SupportsExtension(const char *ext);
131 };
132 
133 /** The TextureLoader class
134  */
135 class TextureLoader : public Plugin
136 {
137  protected:
138  GLS_EXPORT TextureLoader();
139 
140  public:
141 
142  /** \return A filter string that is used by the windows FileBrowser to build the list of files to
143  * display in the browser
144  */
145  virtual const char *FilterString() = 0;
146 
147  /** \return A filter string description that is used by the windows FileBrowser to build the list
148  * of files to display in the browser
149  */
150  virtual const char *FilterDescription() = 0;
151 
152  /** \return The name of the header file to include when generating code
153  * for this plugin
154  */
155  virtual const char *GenerateHeader() = 0;
156 
157  /** \return The string to be generated to generate an instance of this object
158  */
159  virtual const char *GenerateDeclaration() = 0;
160 
161  /** \return The type of plugin
162  */
163  virtual GLS_EXPORT const char *PluginType();
164 
165  /** \returns TRUE if the file pointer appears to contain an image that can be loaded by this class.
166  * This method must close the file if it returns TRUE. It must rewind the file if it returns
167  * FALSE */
168  virtual bool IsFileType(const char *filename) = 0;
169 
170  /** \return TRUE if the class can load files with the given extension. */
171  virtual bool SupportsExtension(const char *ext) = 0;
172 
173  /** Load the specified texture file. Try all loaders to see if any of them support
174  * the given file type.
175  * \param filename The file to load the image from
176  * \param options Options to load the image with
177  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
178  * \return NULL if the file type isn't supported or if loading fails
179  */
180  virtual Image *LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT = true) = 0;
181 
182  /** Adds this file importer to a texture loader list
183  * \param list The texture loader list to add to
184  */
185  void GLS_EXPORT AddToList(TextureLoaderList *list = TextureLoaderList::Instance());
186 };
187 
188 } // namespace disti
189 
190 #endif
virtual bool IsFileType(const char *filename)=0
Definition: image.h:160
virtual const char * GenerateDeclaration()=0
Image * LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT=true)
Definition: texture_loader.h:135
virtual const char * GenerateHeader()=0
The base class for GL Studio plugin file loaders, disti::Plugin.
Definition: texture_loader.h:56
Definition: image.h:271
TextureLoader * SupportsExtension(const char *ext)
Definition: plugin.h:55
A file for all GL Studio files to include.
static TextureLoaderList * Instance()
The Image class. All textures are converted internally into Images.
void AddToList(TextureLoaderList *list=TextureLoaderList::Instance())
The List_c class. Generic linked list.
virtual const char * PluginType()
static bool IsOptimizeTextureLoading()
virtual bool SupportsExtension(const char *ext)=0
virtual const char * FilterString()=0
virtual const char * FilterDescription()=0
void InsertObject(TextureLoader *importer)
virtual Image * LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT=true)=0
Definition: bmpimage.h:46
Definition: list.h:135
static void SetOptimizeTextureLoading(const bool enable)
Image * LoadTextureWithOptimization(const char *filename, const Image::LoadOptions &options, const bool optimizeTextureLoad, bool allowNPOT=true)