1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252 | #include "fsITexture.h"
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/fsPoint.h>
#include <fsCore/fsBuildConfig.h>
#include "fsIImage.h"
#if defined fsFRAMEWORK_CX
#include "impl/cocos2d-x/fsCTexture.h"
#elif defined fsFRAMEWORK_AX
#include "impl/axmol/fsCTexture.h"
#elif defined fsFRAMEWORK_MG
#include "impl/magnum/fsCTexture.h"
#elif defined fsFRAMEWORK_RL
#include "impl/raylib/fsCTexture.h"
#elif defined fsFRAMEWORK_BF
#include "impl/bgfx/fsCTexture.h"
#else
#error Unhandled platform.
#endif
void fsITexture::filterModeSet(fsFilterMode pNewMode)
{
filterModeSetDo(pNewMode);
}
void fsITexture::wrapModeSet(fsWrapMode pNewMode)
{
wrapModeSetDo(pNewMode);
}
std::shared_ptr<fsITexture> fsITexture::cloneSubSection(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
return doCloneSubSection(pBlend, pOffset);
}
void fsITexture::blend(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
return doBlend(pBlend, pOffset);
}
void fsITexture::finalise()
{
if (mImage)
{
createFromImage(mImage.get());
mImage.reset();
}
}
fsSColour4B fsITexture::pixelGet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow)
{
return pixelGetDo(pU, pV, pCol, pRow);
}
void fsITexture::pixelSet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow, fsSColour4B const& pPixel)
{
doPixelSet(pU, pV, pCol, pRow, pPixel);
}
void fsITexture::textureCopyThroughStencil(std::shared_ptr<fsITexture> pSrc, std::shared_ptr<fsITexture> pStencil,
fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY, fsS32 pAlphaHitMaskThreshold)
{
doTextureCopyThroughStencil(pSrc, pStencil, pU, pV, pX, pY, pAlphaHitMaskThreshold);
}
void fsITexture::textureCopyInto(std::shared_ptr<fsITexture> pSrc, fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY)
{
doTextureCopyInto(pSrc, pU, pV, pX, pY);
}
std::shared_ptr<fsITexture> fsITexture::createWithEmptyImage(fsS32 pWidth, fsS32 pHeight)
{
std::shared_ptr<fsITexture> ret = std::shared_ptr<fsITexture>(new fsCTexture());
ret->emptyImageCreate(pWidth, pHeight);
return ret;
}
std::shared_ptr<fsITexture> fsITexture::createFromImageFile(fsSOptions const& pOptions)
{
std::shared_ptr<fsITexture> ret = std::shared_ptr<fsITexture>(new fsCTexture());
ret->imageFileLoad(pOptions.mImageFilename, pOptions.mUVAnimation);
if (pOptions.mMultiMask)
{
ret->imageFileLoad(pOptions.mImageFilename, pOptions.mUVAnimation);
}
if (pOptions.mCreateHitMap)
{
ret->hitMapStore();
}
if (!pOptions.mDeferedUpload)
{
ret->finalise();
}
return ret;
}
std::shared_ptr<fsITexture> fsITexture::createAlpha8FromTextureWithHitmap(
std::shared_ptr<fsITexture> const pTextureWithHitmap,
fsS32 pU, fsS32 pV, fsS32 pW, fsS32 pH)
{
fsPoint potDimensions{roundToPow2(pW), roundToPow2(pH)};
std::vector<fsU8> alpha8Data(potDimensions.x * potDimensions.y, 0);
pTextureWithHitmap->alpha8TexDataGet(pTextureWithHitmap, alpha8Data, pU, pV, pW, pH, potDimensions);
std::shared_ptr<fsITexture> ret = std::shared_ptr<fsITexture>(new fsCTexture());
ret->createFromAlpha8Data(alpha8Data, pW, pH, potDimensions);
return ret;
}
void fsITexture::alpha8TexDataGet(std::shared_ptr<fsITexture> const pTextureWithHitmap, std::vector<fsU8>& pAlphaData,
fsS32 pU, fsS32 pV, fsS32 pW, fsS32 pH, fsPoint const& pPotDimensions) const
{
fsAssert(!pTextureWithHitmap->mHitMap.empty(), "Source texture does not have a hitmap.\n");
for (fsS32 row = 0; row < pH; ++row)
{
for (fsS32 col = 0; col < pW; ++col)
{
fsU8 const alphaValue = pTextureWithHitmap->hitTest(fsPoint(pU + col, pV + row)) ? 0xff : 0x00;
pAlphaData[col + (row * pPotDimensions.x)] = alphaValue;
}
}
}
fsS32 fsITexture::roundToPow2(fsS32 pDimension)
{
fsS32 pow2 = 16; // MW [11/4/2014|11:49] - Smallest texture dimension on 3DS
while (pow2 < pDimension)
{
pow2 *= 2;
}
return pow2;
}
void fsITexture::hitMapStore(fsU8 pAlphaThreshold/* = 0*/)
{
const fsS32 imgW = imageWidthGet();
const fsS32 imgH = imageHeightGet();
int pixelCount = imgW * imgH;
while ((pixelCount & mByteMask) != 0)
{
++pixelCount;
}
mHitMap.resize(scaleDownToBits(pixelCount));
fsU32 curr = 0;
unsigned char currByte = 0;
int currBit = 0;
for (int currRow = 0; currRow < imgH; ++currRow)
{
for (int currCol = 0; currCol < imgW; ++currCol)
{
if (alphaValueGet(currCol, currRow) > pAlphaThreshold)
{
currByte |= (1 << currBit);
}
if (++currBit > mByteMask)
{
mHitMap[curr++] = currByte;
currByte = currBit = 0;
}
}
}
if (currBit)
{
mHitMap[curr] = currByte;
}
}
fsBool fsITexture::hasHitMapGet() const
{
return !mHitMap.empty();
}
fsBool fsITexture::hitTest(fsPoint const& pLocalPoint) const
{
fsAssert(!mHitMap.empty(), "Attempting to perform a hit text on a fsITexture that does not have a hit map.\n");
if (pLocalPoint.x < 0 || pLocalPoint.y < 0
|| pLocalPoint.x >= imageWidthGet() || pLocalPoint.y >= imageHeightGet())
{
return false;
}
fsS32 dataOff = pLocalPoint.x + (pLocalPoint.y * imageWidthGet());
fsS32 currBit = dataOff & mByteMask;
dataOff = scaleDownToBits(dataOff);
return ((mHitMap[dataOff] & (1 << currBit)) != 0);
}
fsS32 fsITexture::scaleDownToBits(fsS32 pVal)
{
return pVal >> 3;
}
void fsITexture::emptyImageCreate(fsS32 pWidth, fsS32 pHeight)
{
mImage = fsIImage::create({pWidth, pHeight});
mWidth = pWidth;
mHeight = pHeight;
}
void fsITexture::imageLoad(const fsCResourceName& pImageFileName)
{
mImage = fsIImage::create(pImageFileName);
mWidth = mImage->dimensionsGet().x;
mHeight = mImage->dimensionsGet().y;
}
void fsITexture::imageFileLoad(const fsCResourceName& pImageFileName, fsBool pUVAnimation)
{
imageLoad(pImageFileName);
}
void fsITexture::maskFileLoad(const fsCResourceName& pImageFileName, fsBool pUVAnimation)<--- The member function 'fsITexture::maskFileLoad' can be static.
{
// fsStr filename = pImageFileName.nameGet();
// filename.replaceAll(".png", "-m");
// filename += ".png";
// if (fsIFile::fileExistsGet(fsCResourceName(filename, pImageFileName.locationGet())))
// {
// mMaskImage = new ax::Image();
// mMaskImage->initWithImageFile(filename.utf8Get());
// }
}
fsITexture::fsITexture():
mWidth(0),
mHeight(0)
{
}
fsITexture::~fsITexture()
{
}
|