Line data Source code
1 0 : /*
2 :
3 : OOTextureLoader.h
4 :
5 : Abstract base class for asynchronous texture loaders, which are dispatched by
6 : OOTextureLoadDispatcher. In general, this should be used through OOTexture.
7 :
8 : Note: interface is likely to change in future to support other buffer types
9 : (like S3TC/DXT#).
10 :
11 :
12 : Copyright (C) 2007-2014 Jens Ayton
13 :
14 : Permission is hereby granted, free of charge, to any person obtaining a copy
15 : of this software and associated documentation files (the "Software"), to deal
16 : in the Software without restriction, including without limitation the rights
17 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 : copies of the Software, and to permit persons to whom the Software is
19 : furnished to do so, subject to the following conditions:
20 :
21 : The above copyright notice and this permission notice shall be included in all
22 : copies or substantial portions of the Software.
23 :
24 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 : SOFTWARE.
31 :
32 : */
33 :
34 : #import "OOTexture.h"
35 : #import "OOAsyncWorkManager.h"
36 :
37 :
38 0 : @interface OOTextureLoader: NSObject <OOAsyncWorkTask>
39 : {
40 : @protected
41 : NSString *_path;
42 0 :
43 : OOTextureFlags _options;
44 0 : uint8_t _generateMipMaps: 1,
45 0 : _scaleAsNormalMap: 1,
46 0 : _avoidShrinking: 1,
47 0 : _noScalingWhatsoever: 1,
48 0 : _extractChannel: 1,
49 0 : _allowCubeMap: 1,
50 0 : _isCubeMap: 1,
51 0 : _ready: 1;
52 0 : uint8_t _extractChannelIndex;
53 0 : OOTextureDataFormat _format;
54 0 :
55 : void *_data;
56 0 : uint32_t _width,
57 0 : _height,
58 0 : _originalWidth,
59 0 : _originalHeight,
60 0 : _shrinkThreshold,
61 0 : _maxSize;
62 0 : size_t _rowBytes;
63 0 : }
64 :
65 : + (id)loaderWithPath:(NSString *)path options:(uint32_t)options;
66 0 :
67 : /* Convenience method to load images not destined for normal texture use.
68 : Specifier is a string or a dictionary as with textures. ExtraOptions is
69 : ored into the option flags interpreted from the specifier. Folder is the
70 : directory to look in, typically Textures or Images. Options in the
71 : specifier which are applied at the OOTexture level will be ignored.
72 : */
73 : + (id)loaderWithTextureSpecifier:(id)specifier extraOptions:(uint32_t)extraOptions folder:(NSString *)folder;
74 0 :
75 : - (BOOL)isReady;
76 0 :
77 : /* Return value indicates success. This may only be called once (subsequent
78 : attempts will return failure), and only on the main thread.
79 : */
80 : - (BOOL) getResult:(OOPixMap *)result
81 0 : format:(OOTextureDataFormat *)outFormat
82 : originalWidth:(uint32_t *)outWidth
83 : originalHeight:(uint32_t *)outHeight;
84 :
85 : /* Hopefully-unique string for texture loader; analagous, but not identical,
86 : to corresponding texture cacheKey.
87 : */
88 : - (NSString *) cacheKey;
89 0 :
90 :
91 :
92 : /*** Subclass interface; do not use on pain of pain. Unless you're subclassing. ***/
93 :
94 : // Subclasses shouldn't do much on init, because of the whole asynchronous thing.
95 : - (id)initWithPath:(NSString *)path options:(uint32_t)options;
96 0 :
97 : - (NSString *)path;
98 0 :
99 : /* Load data, setting up _data, _format, _width, and _height; also _rowBytes
100 : if it's not _width * OOTextureComponentsForFormat(_format), and
101 : _originalWidth/_originalHeight if _width and _height for some reason aren't
102 : the original pixel dimensions.
103 :
104 : Thread-safety concerns: this will be called in a worker thread, and there
105 : may be several worker threads. The caller takes responsibility for
106 : autorelease pools and exception safety.
107 :
108 : Superclass will handle scaling and mip-map generation. Data must be
109 : allocated with malloc() family.
110 : */
111 : - (void)loadTexture;
112 0 :
113 : @end
|