| 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 /// \return 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 FALSE.
163 /// \param filename The file name to check.
164 virtual bool IsFileType( const char* filename ) = 0;
165
166 /// \return TRUE if the class can load files with the given extension.
167 /// \param ext The file extension to check.
168 virtual bool SupportsExtension( const char* ext ) = 0;
169
170 /** Load the specified texture file. Try all loaders to see if any of them support
171 * the given file type.
172 * \param filename The file to load the image from
173 * \param options Options to load the image with
174 * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
175 * \return NULL if the file type isn't supported or if loading fails
176 */
177 virtual Image* LoadTexture( const char* filename, const Image::LoadOptions& options, bool allowNPOT = true ) = 0;
178
179 /** Adds this file importer to a texture loader list
180 * \param list The texture loader list to add to
181 */
182 void GLS_EXPORT AddToList( TextureLoaderList* list = TextureLoaderList::Instance() );
183};
184
185} // namespace disti
186
187#endif
disti::Image::LoadOptions
Definition: image.h:286
disti::Image
Definition: image.h:178
disti::List_c
Definition: list.h:135
disti::Plugin
Definition: plugin.h:55
disti::TextureLoaderList
Definition: texture_loader.h:56
disti::TextureLoaderList::SupportsExtension
TextureLoader * SupportsExtension(const char *ext)
disti::TextureLoaderList::LoadTexture
Image * LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT=true)
disti::TextureLoaderList::IsOptimizeTextureLoading
static bool IsOptimizeTextureLoading()
disti::TextureLoaderList::LoadTextureWithOptimization
Image * LoadTextureWithOptimization(const char *filename, const Image::LoadOptions &options, const bool optimizeTextureLoad, bool allowNPOT=true)
disti::TextureLoaderList::InsertObject
void InsertObject(TextureLoader *importer)
disti::TextureLoaderList::FilterString
char * FilterString()
disti::TextureLoaderList::SetOptimizeTextureLoading
static void SetOptimizeTextureLoading(const bool enable)
disti::TextureLoaderList::Instance
static TextureLoaderList * Instance()
disti::TextureLoaderList::TextureLoaderList
TextureLoaderList()
disti::TextureLoader
Definition: texture_loader.h:133
disti::TextureLoader::GenerateHeader
virtual const char * GenerateHeader()=0
disti::TextureLoader::AddToList
void AddToList(TextureLoaderList *list=TextureLoaderList::Instance())
disti::TextureLoader::FilterDescription
virtual const char * FilterDescription()=0
disti::TextureLoader::GenerateDeclaration
virtual const char * GenerateDeclaration()=0
disti::TextureLoader::PluginType
virtual const char * PluginType()
disti::TextureLoader::LoadTexture
virtual Image * LoadTexture(const char *filename, const Image::LoadOptions &options, bool allowNPOT=true)=0
disti::TextureLoader::IsFileType
virtual bool IsFileType(const char *filename)=0
disti::TextureLoader::FilterString
virtual const char * FilterString()=0
disti::TextureLoader::SupportsExtension
virtual bool SupportsExtension(const char *ext)=0
gls_include.h
A file for all GL Studio files to include.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
image.h
The Image class. All textures are converted internally into Images.
list.h
The List_c class. Generic linked list.
disti
Definition: bmpimage.h:47
plugin.h
The base class for GL Studio plugin file loaders, disti::Plugin.