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