@@ -34,7 +34,6 @@ THE SOFTWARE.
34
34
35
35
#include " ccConfig.h"
36
36
#include " ccMacros.h"
37
- #include " CCTexture2D.h"
38
37
#include " CCConfiguration.h"
39
38
#include " platform/platform.h"
40
39
#include " CCImage.h"
@@ -47,7 +46,7 @@ THE SOFTWARE.
47
46
#endif
48
47
49
48
#if CC_ENABLE_CACHE_TEXTTURE_DATA
50
- #include < list >
49
+ #include " CCTextureCache.h "
51
50
#endif
52
51
53
52
namespace cocos2d {
@@ -58,122 +57,6 @@ namespace cocos2d {
58
57
59
58
// CLASS IMPLEMENTATIONS:
60
59
61
- #if CC_ENABLE_CACHE_TEXTTURE_DATA
62
- class VolatileTexture
63
- {
64
- protected:
65
- CCTexture2D *texture;
66
- unsigned char *data;
67
- CCTexture2DPixelFormat pixelFormat;
68
- unsigned int pixelsWide;
69
- unsigned int pixelsHigh;
70
- CCSize contentSize;
71
-
72
- public:
73
-
74
- static std::list<VolatileTexture*> textures;
75
- static bool isReloading;
76
-
77
- VolatileTexture (CCTexture2D *t) : texture(t), data(0 )
78
- {
79
- textures.push_back (this );
80
- }
81
-
82
- ~VolatileTexture ()
83
- {
84
- if (data)
85
- delete [] data;
86
- textures.remove (this );
87
- }
88
-
89
- static void addTextureWithData (CCTexture2D *tt,
90
- const void *d,
91
- CCTexture2DPixelFormat f,
92
- unsigned int w,
93
- unsigned int h,
94
- CCSize s)
95
- {
96
- if (isReloading)
97
- return ;
98
-
99
- VolatileTexture *vt = 0 ;
100
- std::list<VolatileTexture *>::iterator i = textures.begin ();
101
- while ( i != textures.end () )
102
- {
103
- VolatileTexture *v = *i++;
104
- if (v->texture == tt) {
105
- vt = v;
106
- break ;
107
- }
108
- }
109
-
110
- if (!vt)
111
- vt = new VolatileTexture (tt);
112
-
113
- vt->pixelFormat = f;
114
- vt->pixelsWide = w;
115
- vt->pixelsHigh = h;
116
- vt->contentSize = s;
117
-
118
- // CCLOGINFO("added volatile %d", textures.size());
119
-
120
- if (vt->data ) {
121
- delete [] vt->data ;
122
- vt->data = 0 ;
123
- }
124
-
125
- switch (f) {
126
- case kCCTexture2DPixelFormat_RGBA8888 :
127
- case kCCTexture2DPixelFormat_RGBA4444 :
128
- case kCCTexture2DPixelFormat_RGB5A1 :
129
- case kCCTexture2DPixelFormat_RGB565 :
130
- case kCCTexture2DPixelFormat_A8 :
131
- vt->data = new unsigned char [w * h * 4 ];
132
- memcpy (vt->data , d, w * h * 4 );
133
- break ;
134
- case kCCTexture2DPixelFormat_RGB888 :
135
- vt->data = new unsigned char [w * h * 3 ];
136
- memcpy (vt->data , d, w * h * 3 );
137
- break ;
138
- }
139
- }
140
-
141
- static void removeTexture (CCTexture2D *t) {
142
-
143
- std::list<VolatileTexture *>::iterator i = textures.begin ();
144
- while ( i != textures.end () )
145
- {
146
- VolatileTexture *vt = *i++;
147
- if (vt->texture == t) {
148
- delete vt;
149
- break ;
150
- }
151
- }
152
- }
153
-
154
- static void reloadAllTextures ()
155
- {
156
- isReloading = true ;
157
-
158
- CCLOG (" reload all texture" );
159
- std::list<VolatileTexture *>::iterator i = textures.begin ();
160
-
161
- while ( i != textures.end () )
162
- {
163
- VolatileTexture *vt = *i++;
164
- if (vt->data ) {
165
- vt->texture ->initWithData ((const void *)vt->data , vt->pixelFormat , vt->pixelsWide , vt->pixelsHigh , vt->contentSize );
166
- }
167
- }
168
-
169
- isReloading = false ;
170
- }
171
- };
172
-
173
- std::list<VolatileTexture*> VolatileTexture::textures;
174
- bool VolatileTexture::isReloading = false ;
175
- #endif // CC_ENABLE_CACHE_TEXTTURE_DATA
176
-
177
60
// If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit)
178
61
// Default is: RGBA8888 (32-bit textures)
179
62
static CCTexture2DPixelFormat g_defaultAlphaPixelFormat = kCCTexture2DPixelFormat_Default ;
@@ -273,12 +156,6 @@ bool CCTexture2D::getHasPremultipliedAlpha()
273
156
274
157
bool CCTexture2D::initWithData (const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CCSize contentSize)
275
158
{
276
-
277
- #if CC_ENABLE_CACHE_TEXTTURE_DATA
278
- // cache the texture data
279
- VolatileTexture::addTextureWithData (this , data, pixelFormat, pixelsWide, pixelsHigh, contentSize);
280
- #endif
281
-
282
159
glGenTextures (1 , &m_uName);
283
160
glBindTexture (GL_TEXTURE_2D, m_uName);
284
161
@@ -559,6 +436,11 @@ bool CCTexture2D::initWithString(const char *text, const char *fontName, float f
559
436
}
560
437
bool CCTexture2D::initWithString (const char *text, CCSize dimensions, CCTextAlignment alignment, const char *fontName, float fontSize)
561
438
{
439
+ #if CC_ENABLE_CACHE_TEXTTURE_DATA
440
+ // cache the texture data
441
+ VolatileTexture::addStringTexture (this , text, dimensions, alignment, fontName, fontSize);
442
+ #endif
443
+
562
444
CCImage image;
563
445
CCImage::ETextAlign eAlign = (CCTextAlignmentCenter == alignment) ? CCImage::kAlignCenter
564
446
: (CCTextAlignmentLeft == alignment) ? CCImage::kAlignLeft : CCImage::kAlignRight ;
@@ -742,11 +624,4 @@ CCTexture2DPixelFormat CCTexture2D::defaultAlphaPixelFormat()
742
624
return g_defaultAlphaPixelFormat;
743
625
}
744
626
745
- void CCTexture2D::reloadAllTextures ()
746
- {
747
- #if CC_ENABLE_CACHE_TEXTTURE_DATA
748
- VolatileTexture::reloadAllTextures ();
749
- #endif
750
- }
751
-
752
627
}// namespace cocos2d
0 commit comments