diff options
Diffstat (limited to 'libs/cocos2d/CCTextureAtlas.h')
| -rwxr-xr-x | libs/cocos2d/CCTextureAtlas.h | 147 |
1 files changed, 147 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCTextureAtlas.h b/libs/cocos2d/CCTextureAtlas.h new file mode 100755 index 0000000..f70bb54 --- /dev/null +++ b/libs/cocos2d/CCTextureAtlas.h | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2008-2010 Ricardo Quesada | ||
| 5 | * Copyright (c) 2011 Zynga Inc. | ||
| 6 | * | ||
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 8 | * of this software and associated documentation files (the "Software"), to deal | ||
| 9 | * in the Software without restriction, including without limitation the rights | ||
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 11 | * copies of the Software, and to permit persons to whom the Software is | ||
| 12 | * furnished to do so, subject to the following conditions: | ||
| 13 | * | ||
| 14 | * The above copyright notice and this permission notice shall be included in | ||
| 15 | * all copies or substantial portions of the Software. | ||
| 16 | * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 23 | * THE SOFTWARE. | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | |||
| 27 | #import "CCTexture2D.h" | ||
| 28 | #import "ccTypes.h" | ||
| 29 | #import "ccConfig.h" | ||
| 30 | |||
| 31 | /** A class that implements a Texture Atlas. | ||
| 32 | Supported features: | ||
| 33 | * The atlas file can be a PVRTC, PNG or any other fomrat supported by Texture2D | ||
| 34 | * Quads can be udpated in runtime | ||
| 35 | * Quads can be added in runtime | ||
| 36 | * Quads can be removed in runtime | ||
| 37 | * Quads can be re-ordered in runtime | ||
| 38 | * The TextureAtlas capacity can be increased or decreased in runtime | ||
| 39 | * OpenGL component: V3F, C4B, T2F. | ||
| 40 | The quads are rendered using an OpenGL ES VBO. | ||
| 41 | To render the quads using an interleaved vertex array list, you should modify the ccConfig.h file | ||
| 42 | */ | ||
| 43 | @interface CCTextureAtlas : NSObject | ||
| 44 | { | ||
| 45 | NSUInteger totalQuads_; | ||
| 46 | NSUInteger capacity_; | ||
| 47 | ccV3F_C4B_T2F_Quad *quads_; // quads to be rendered | ||
| 48 | GLushort *indices_; | ||
| 49 | CCTexture2D *texture_; | ||
| 50 | #if CC_USES_VBO | ||
| 51 | GLuint buffersVBO_[2]; //0: vertex 1: indices | ||
| 52 | BOOL dirty_; //indicates whether or not the array buffer of the VBO needs to be updated | ||
| 53 | #endif // CC_USES_VBO | ||
| 54 | } | ||
| 55 | |||
| 56 | /** quantity of quads that are going to be drawn */ | ||
| 57 | @property (nonatomic,readonly) NSUInteger totalQuads; | ||
| 58 | /** quantity of quads that can be stored with the current texture atlas size */ | ||
| 59 | @property (nonatomic,readonly) NSUInteger capacity; | ||
| 60 | /** Texture of the texture atlas */ | ||
| 61 | @property (nonatomic,retain) CCTexture2D *texture; | ||
| 62 | /** Quads that are going to be rendered */ | ||
| 63 | @property (nonatomic,readwrite) ccV3F_C4B_T2F_Quad *quads; | ||
| 64 | |||
| 65 | /** creates a TextureAtlas with an filename and with an initial capacity for Quads. | ||
| 66 | * The TextureAtlas capacity can be increased in runtime. | ||
| 67 | */ | ||
| 68 | +(id) textureAtlasWithFile:(NSString*)file capacity:(NSUInteger)capacity; | ||
| 69 | |||
| 70 | /** initializes a TextureAtlas with a filename and with a certain capacity for Quads. | ||
| 71 | * The TextureAtlas capacity can be increased in runtime. | ||
| 72 | * | ||
| 73 | * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) | ||
| 74 | */ | ||
| 75 | -(id) initWithFile: (NSString*) file capacity:(NSUInteger)capacity; | ||
| 76 | |||
| 77 | /** creates a TextureAtlas with a previously initialized Texture2D object, and | ||
| 78 | * with an initial capacity for n Quads. | ||
| 79 | * The TextureAtlas capacity can be increased in runtime. | ||
| 80 | */ | ||
| 81 | +(id) textureAtlasWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; | ||
| 82 | |||
| 83 | /** initializes a TextureAtlas with a previously initialized Texture2D object, and | ||
| 84 | * with an initial capacity for Quads. | ||
| 85 | * The TextureAtlas capacity can be increased in runtime. | ||
| 86 | * | ||
| 87 | * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) | ||
| 88 | */ | ||
| 89 | -(id) initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity; | ||
| 90 | |||
| 91 | /** updates a Quad (texture, vertex and color) at a certain index | ||
| 92 | * index must be between 0 and the atlas capacity - 1 | ||
| 93 | @since v0.8 | ||
| 94 | */ | ||
| 95 | -(void) updateQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index; | ||
| 96 | |||
| 97 | /** Inserts a Quad (texture, vertex and color) at a certain index | ||
| 98 | index must be between 0 and the atlas capacity - 1 | ||
| 99 | @since v0.8 | ||
| 100 | */ | ||
| 101 | -(void) insertQuad:(ccV3F_C4B_T2F_Quad*)quad atIndex:(NSUInteger)index; | ||
| 102 | |||
| 103 | /** Removes the quad that is located at a certain index and inserts it at a new index | ||
| 104 | This operation is faster than removing and inserting in a quad in 2 different steps | ||
| 105 | @since v0.7.2 | ||
| 106 | */ | ||
| 107 | -(void) insertQuadFromIndex:(NSUInteger)fromIndex atIndex:(NSUInteger)newIndex; | ||
| 108 | |||
| 109 | /** removes a quad at a given index number. | ||
| 110 | The capacity remains the same, but the total number of quads to be drawn is reduced in 1 | ||
| 111 | @since v0.7.2 | ||
| 112 | */ | ||
| 113 | -(void) removeQuadAtIndex:(NSUInteger) index; | ||
| 114 | |||
| 115 | /** removes all Quads. | ||
| 116 | The TextureAtlas capacity remains untouched. No memory is freed. | ||
| 117 | The total number of quads to be drawn will be 0 | ||
| 118 | @since v0.7.2 | ||
| 119 | */ | ||
| 120 | -(void) removeAllQuads; | ||
| 121 | |||
| 122 | /** resize the capacity of the CCTextureAtlas. | ||
| 123 | * The new capacity can be lower or higher than the current one | ||
| 124 | * It returns YES if the resize was successful. | ||
| 125 | * If it fails to resize the capacity it will return NO with a new capacity of 0. | ||
| 126 | */ | ||
| 127 | -(BOOL) resizeCapacity: (NSUInteger) n; | ||
| 128 | |||
| 129 | |||
| 130 | /** draws n quads | ||
| 131 | * n can't be greater than the capacity of the Atlas | ||
| 132 | */ | ||
| 133 | -(void) drawNumberOfQuads: (NSUInteger) n; | ||
| 134 | |||
| 135 | |||
| 136 | /** draws n quads from an index (offset). | ||
| 137 | n + start can't be greater than the capacity of the atlas | ||
| 138 | |||
| 139 | @since v1.0 | ||
| 140 | */ | ||
| 141 | -(void) drawNumberOfQuads: (NSUInteger) n fromIndex: (NSUInteger) start; | ||
| 142 | |||
| 143 | /** draws all the Atlas's Quads | ||
| 144 | */ | ||
| 145 | -(void) drawQuads; | ||
| 146 | |||
| 147 | @end | ||
