summary refs log tree commit diff stats
path: root/libs/cocos2d/CCTexture2D.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cocos2d/CCTexture2D.h')
-rwxr-xr-xlibs/cocos2d/CCTexture2D.h328
1 files changed, 328 insertions, 0 deletions
diff --git a/libs/cocos2d/CCTexture2D.h b/libs/cocos2d/CCTexture2D.h new file mode 100755 index 0000000..45eea9c --- /dev/null +++ b/libs/cocos2d/CCTexture2D.h
@@ -0,0 +1,328 @@
1/*
2
3===== IMPORTANT =====
4
5This is sample code demonstrating API, technology or techniques in development.
6Although this sample code has been reviewed for technical accuracy, it is not
7final. Apple is supplying this information to help you plan for the adoption of
8the technologies and programming interfaces described herein. This information
9is subject to change, and software implemented based on this sample code should
10be tested with final operating system software and final documentation. Newer
11versions of this sample code may be provided with future seeds of the API or
12technology. For information about updates to this and other developer
13documentation, view the New & Updated sidebars in subsequent documentation
14seeds.
15
16=====================
17
18File: Texture2D.h
19Abstract: Creates OpenGL 2D textures from images or text.
20
21Version: 1.6
22
23Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
24("Apple") in consideration of your agreement to the following terms, and your
25use, installation, modification or redistribution of this Apple software
26constitutes acceptance of these terms. If you do not agree with these terms,
27please do not use, install, modify or redistribute this Apple software.
28
29In consideration of your agreement to abide by the following terms, and subject
30to these terms, Apple grants you a personal, non-exclusive license, under
31Apple's copyrights in this original Apple software (the "Apple Software"), to
32use, reproduce, modify and redistribute the Apple Software, with or without
33modifications, in source and/or binary forms; provided that if you redistribute
34the Apple Software in its entirety and without modifications, you must retain
35this notice and the following text and disclaimers in all such redistributions
36of the Apple Software.
37Neither the name, trademarks, service marks or logos of Apple Inc. may be used
38to endorse or promote products derived from the Apple Software without specific
39prior written permission from Apple. Except as expressly stated in this notice,
40no other rights or licenses, express or implied, are granted by Apple herein,
41including but not limited to any patent rights that may be infringed by your
42derivative works or by other works in which the Apple Software may be
43incorporated.
44
45The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
46WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
47WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
49COMBINATION WITH YOUR PRODUCTS.
50
51IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
52CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
53GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
55DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
56CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
57APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
59Copyright (C) 2008 Apple Inc. All Rights Reserved.
60
61*/
62
63#import <Availability.h>
64
65#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
66#import <UIKit/UIKit.h> // for UIImage
67#endif
68
69#import <Foundation/Foundation.h> // for NSObject
70
71#import "Platforms/CCGL.h" // OpenGL stuff
72#import "Platforms/CCNS.h" // Next-Step stuff
73
74//CONSTANTS:
75
76/** @typedef CCTexture2DPixelFormat
77 Possible texture pixel formats
78 */
79typedef enum {
80 kCCTexture2DPixelFormat_Automatic = 0,
81 //! 32-bit texture: RGBA8888
82 kCCTexture2DPixelFormat_RGBA8888,
83 //! 16-bit texture without Alpha channel
84 kCCTexture2DPixelFormat_RGB565,
85 //! 8-bit textures used as masks
86 kCCTexture2DPixelFormat_A8,
87 //! 8-bit intensity texture
88 kCCTexture2DPixelFormat_I8,
89 //! 16-bit textures used as masks
90 kCCTexture2DPixelFormat_AI88,
91 //! 16-bit textures: RGBA4444
92 kCCTexture2DPixelFormat_RGBA4444,
93 //! 16-bit textures: RGB5A1
94 kCCTexture2DPixelFormat_RGB5A1,
95 //! 4-bit PVRTC-compressed texture: PVRTC4
96 kCCTexture2DPixelFormat_PVRTC4,
97 //! 2-bit PVRTC-compressed texture: PVRTC2
98 kCCTexture2DPixelFormat_PVRTC2,
99
100 //! Default texture format: RGBA8888
101 kCCTexture2DPixelFormat_Default = kCCTexture2DPixelFormat_RGBA8888,
102
103 // backward compatibility stuff
104 kTexture2DPixelFormat_Automatic = kCCTexture2DPixelFormat_Automatic,
105 kTexture2DPixelFormat_RGBA8888 = kCCTexture2DPixelFormat_RGBA8888,
106 kTexture2DPixelFormat_RGB565 = kCCTexture2DPixelFormat_RGB565,
107 kTexture2DPixelFormat_A8 = kCCTexture2DPixelFormat_A8,
108 kTexture2DPixelFormat_RGBA4444 = kCCTexture2DPixelFormat_RGBA4444,
109 kTexture2DPixelFormat_RGB5A1 = kCCTexture2DPixelFormat_RGB5A1,
110 kTexture2DPixelFormat_Default = kCCTexture2DPixelFormat_Default
111
112} CCTexture2DPixelFormat;
113
114//CLASS INTERFACES:
115
116/** CCTexture2D class.
117 * This class allows to easily create OpenGL 2D textures from images, text or raw data.
118 * The created CCTexture2D object will always have power-of-two dimensions.
119 * Depending on how you create the CCTexture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0).
120 * Be aware that the content of the generated textures will be upside-down!
121 */
122@interface CCTexture2D : NSObject
123{
124 GLuint name_;
125 CGSize size_;
126 NSUInteger width_,
127 height_;
128 CCTexture2DPixelFormat format_;
129 GLfloat maxS_,
130 maxT_;
131 BOOL hasPremultipliedAlpha_;
132}
133/** Intializes with a texture2d with data */
134- (id) initWithData:(const void*)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size;
135
136/** These functions are needed to create mutable textures */
137- (void) releaseData:(void*)data;
138- (void*) keepData:(void*)data length:(NSUInteger)length;
139
140/** pixel format of the texture */
141@property(nonatomic,readonly) CCTexture2DPixelFormat pixelFormat;
142/** width in pixels */
143@property(nonatomic,readonly) NSUInteger pixelsWide;
144/** hight in pixels */
145@property(nonatomic,readonly) NSUInteger pixelsHigh;
146
147/** texture name */
148@property(nonatomic,readonly) GLuint name;
149
150/** returns content size of the texture in pixels */
151@property(nonatomic,readonly, nonatomic) CGSize contentSizeInPixels;
152
153/** texture max S */
154@property(nonatomic,readwrite) GLfloat maxS;
155/** texture max T */
156@property(nonatomic,readwrite) GLfloat maxT;
157/** whether or not the texture has their Alpha premultiplied */
158@property(nonatomic,readonly) BOOL hasPremultipliedAlpha;
159
160/** returns the content size of the texture in points */
161-(CGSize) contentSize;
162@end
163
164/**
165Drawing extensions to make it easy to draw basic quads using a CCTexture2D object.
166These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled.
167*/
168@interface CCTexture2D (Drawing)
169/** draws a texture at a given point */
170- (void) drawAtPoint:(CGPoint)point;
171/** draws a texture inside a rect */
172- (void) drawInRect:(CGRect)rect;
173@end
174
175/**
176Extensions to make it easy to create a CCTexture2D object from an image file.
177Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).
178*/
179@interface CCTexture2D (Image)
180/** Initializes a texture from a UIImage object */
181#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
182- (id) initWithImage:(UIImage *)uiImage;
183#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
184- (id) initWithImage:(CGImageRef)cgImage;
185#endif
186@end
187
188/**
189Extensions to make it easy to create a CCTexture2D object from a string of text.
190Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
191*/
192@interface CCTexture2D (Text)
193/** Initializes a texture from a string with dimensions, alignment, line break mode, font name and font size
194 Supported lineBreakModes:
195 - iOS: all UILineBreakMode supported modes
196 - Mac: Only NSLineBreakByWordWrapping is supported.
197 @since v1.0
198 */
199- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment lineBreakMode:(CCLineBreakMode)lineBreakMode fontName:(NSString*)name fontSize:(CGFloat)size;
200/** Initializes a texture from a string with dimensions, alignment, font name and font size */
201- (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size;
202/** Initializes a texture from a string with font name and font size */
203- (id) initWithString:(NSString*)string fontName:(NSString*)name fontSize:(CGFloat)size;
204@end
205
206
207/**
208 Extensions to make it easy to create a CCTexture2D object from a PVRTC file
209 Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
210 */
211@interface CCTexture2D (PVRSupport)
212/** Initializes a texture from a PVR Texture Compressed (PVRTC) buffer
213 *
214 * IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version.
215 */
216#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
217-(id) initWithPVRTCData: (const void*)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length pixelFormat:(CCTexture2DPixelFormat)pixelFormat;
218#endif // __IPHONE_OS_VERSION_MAX_ALLOWED
219/** Initializes a texture from a PVR file.
220
221 Supported PVR formats:
222 - BGRA 8888
223 - RGBA 8888
224 - RGBA 4444
225 - RGBA 5551
226 - RBG 565
227 - A 8
228 - I 8
229 - AI 8
230 - PVRTC 2BPP
231 - PVRTC 4BPP
232
233 By default PVR images are treated as if they alpha channel is NOT premultiplied. You can override this behavior with this class method:
234 - PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied;
235
236 IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version.
237
238 */
239-(id) initWithPVRFile: (NSString*) file;
240
241/** treats (or not) PVR files as if they have alpha premultiplied.
242 Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is
243 possible load them as if they have (or not) the alpha channel premultiplied.
244
245 By default it is disabled.
246
247 @since v0.99.5
248 */
249+(void) PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied;
250@end
251
252/**
253 Extension to set the Min / Mag filter
254 */
255typedef struct _ccTexParams {
256 GLuint minFilter;
257 GLuint magFilter;
258 GLuint wrapS;
259 GLuint wrapT;
260} ccTexParams;
261
262@interface CCTexture2D (GLFilter)
263/** sets the min filter, mag filter, wrap s and wrap t texture parameters.
264 If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
265 @since v0.8
266 */
267-(void) setTexParameters: (ccTexParams*) texParams;
268
269/** sets antialias texture parameters:
270 - GL_TEXTURE_MIN_FILTER = GL_LINEAR
271 - GL_TEXTURE_MAG_FILTER = GL_LINEAR
272
273 @since v0.8
274 */
275- (void) setAntiAliasTexParameters;
276
277/** sets alias texture parameters:
278 - GL_TEXTURE_MIN_FILTER = GL_NEAREST
279 - GL_TEXTURE_MAG_FILTER = GL_NEAREST
280
281 @since v0.8
282 */
283- (void) setAliasTexParameters;
284
285
286/** Generates mipmap images for the texture.
287 It only works if the texture size is POT (power of 2).
288 @since v0.99.0
289 */
290-(void) generateMipmap;
291
292
293@end
294
295@interface CCTexture2D (PixelFormat)
296/** sets the default pixel format for UIImages that contains alpha channel.
297 If the UIImage contains alpha channel, then the options are:
298 - generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one)
299 - generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444
300 - generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1
301 - generate 16-bit textures: kCCTexture2DPixelFormat_RGB565
302 - generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color)
303
304 How does it work ?
305 - If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture)
306 - If the image is an RGB (without Alpha) then an RGB565 texture will be used (16-bit texture)
307
308 This parameter is not valid for PVR images.
309
310 @since v0.8
311 */
312+(void) setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format;
313
314/** returns the alpha pixel format
315 @since v0.8
316 */
317+(CCTexture2DPixelFormat) defaultAlphaPixelFormat;
318
319/** returns the bits-per-pixel of the in-memory OpenGL texture
320 @since v1.0
321 */
322-(NSUInteger) bitsPerPixelForFormat;
323@end
324
325
326
327
328