GL Studio C++ Runtime 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) 2017 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 "image.h"
45 #include "list.h"
46 #include "plugin.h"
47 
48 namespace disti
49 {
50 class TextureLoader;
51 
52 /**
53  A list of (pointers to) texture loader objects.
54 */
55 class TextureLoaderList : public List_c
56 {
57  static GLS_EXPORT TextureLoaderList* _instance; /** A singleton interface */
58 
59 public:
60  GLS_EXPORT TextureLoaderList();
61 
62  /** A singleton interface
63  * \return A pointer to the one and only instance
64  */
65  static GLS_EXPORT TextureLoaderList* Instance();
66 
67  /** enable / disable texture loading optimization (defaults to enabled)
68  * \param enable true to enable else false
69  */
70  static GLS_EXPORT void SetOptimizeTextureLoading( const bool enable );
71 
72  /** determine if texture loading optimization is enabled
73  * \return true if enabled else false
74  */
75  static GLS_EXPORT bool IsOptimizeTextureLoading();
76 
77  /** Insert the loader into the list at the specified location
78  * \param importer
79  */
80  GLS_EXPORT void InsertObject( TextureLoader* importer );
81 
82  /** Creates and returns a file filter string for all of the file types that have been
83  * registered by Texture Loaders
84  * \return Filter string */
85  GLS_EXPORT char* FilterString();
86 
87  /** Load the specified texture file. Try all loaders to see if any of them support
88  * the given file type.
89  * \param filename The file to load the image from
90  * \param options Options to load the image with
91  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
92  * \return NULL if the file type isn't supported or if loading fails
93  */
94  GLS_EXPORT Image* LoadTexture( const char* filename, const Image::LoadOptions& options, bool allowNPOT = true );
95 
96  /** Load the specified texture file optionally attempting to optimize the load by looking at
97  * previously loaded images. Try all loaders to see if any of them support
98  * the given file type.
99  * \param filename The file to load the image from
100  * \param options Options to load the image with
101  * \param optimizeTextureLoad true to attempt loading optimization else false to force a load
102  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
103  * \return NULL if the file type isn't supported or if loading fails
104  */
105  GLS_EXPORT Image* LoadTextureWithOptimization( const char* filename, const Image::LoadOptions& options, const bool optimizeTextureLoad, bool allowNPOT = true );
106 
107 #ifdef __APPLE__
108  /** Load the specified texture file optionally attempting to optimize the load by looking at
109  * previously loaded images.
110  *
111  * This method uses the iOS image loader classes to load the textures and thus supports whatever platform native loaders
112  * are supported by the iOS SDK.
113  *
114  * NOTE: This code will also give preference to texture files compressed using PowerVR Texture compression.
115  * The way that works is that if this code is asked to load 'xyz.png' and 'xyz.pvr' is found, then the .pvr
116  * file will be loaded instead.
117  *
118  * \return NULL if the file type isn't supported or if loading fails */
119  GLS_EXPORT Image* LoadTextureIOS( const char* filename, const Image::LoadOptions& options, const bool optimizeTextureLoad );
120 #endif
121 
122  /** Finds the registered texture loader, if any, that supports the given file
123  * extension.
124  * \param ext The (case insensitive) file extension
125  * \return A pointer to the registered loader, or NULL if no loader exists
126  */
127  GLS_EXPORT TextureLoader* SupportsExtension( const char* ext );
128 };
129 
130 /** The TextureLoader class
131  */
132 class TextureLoader : public Plugin
133 {
134 protected:
135  GLS_EXPORT TextureLoader();
136 
137 public:
138  /** \return A filter string that is used by the windows FileBrowser to build the list of files to
139  * display in the browser
140  */
141  virtual const char* FilterString() = 0;
142 
143  /** \return A filter string description that is used by the windows FileBrowser to build the list
144  * of files to display in the browser
145  */
146  virtual const char* FilterDescription() = 0;
147 
148  /** \return The name of the header file to include when generating code
149  * for this plugin
150  */
151  virtual const char* GenerateHeader() = 0;
152 
153  /** \return The string to be generated to generate an instance of this object
154  */
155  virtual const char* GenerateDeclaration() = 0;
156 
157  /** \return The type of plugin
158  */
159  virtual GLS_EXPORT const char* PluginType();
160 
161  /** \returns TRUE if the file pointer appears to contain an image that can be loaded by this class.
162  * This method must close the file if it returns TRUE. It must rewind the file if it returns
163  * FALSE */
164  virtual bool IsFileType( const char* filename ) = 0;
165 
166  /** \return TRUE if the class can load files with the given extension. */
167  virtual bool SupportsExtension( const char* ext ) = 0;
168 
169  /** Load the specified texture file. Try all loaders to see if any of them support
170  * the given file type.
171  * \param filename The file to load the image from
172  * \param options Options to load the image with
173  * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
174  * \return NULL if the file type isn't supported or if loading fails
175  */
176  virtual Image* LoadTexture( const char* filename, const Image::LoadOptions& options, bool allowNPOT = true ) = 0;
177 
178  /** Adds this file importer to a texture loader list
179  * \param list The texture loader list to add to
180  */
181  void GLS_EXPORT AddToList( TextureLoaderList* list = TextureLoaderList::Instance() );
182 };
183 
184 } // namespace disti
185 
186 #endif
virtual bool IsFileType(const char *filename)=0
Definition: image.h:162
virtual const char * GenerateDeclaration()=0
Image * LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT=true)
Definition: texture_loader.h:132
virtual const char * GenerateHeader()=0
The base class for GL Studio plugin file loaders, disti::Plugin.
Definition: texture_loader.h:55
Definition: image.h:272
TextureLoader * SupportsExtension(const char *ext)
Definition: plugin.h:54
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:134
static void SetOptimizeTextureLoading(const bool enable)
Image * LoadTextureWithOptimization(const char *filename, const Image::LoadOptions &options, const bool optimizeTextureLoad, bool allowNPOT=true)