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 |
#include "fsCTexture.h"
#include <renderer/CCTexture2D.h>
#include <platform/CCImage.h>
#include <fsCore/fsSColour.h>
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/src/fsNCoreUtils.h>
#include <fsCore/src/debug/fsLog.h>
#include <fsCore/fsPoint.h>
#include <fsCore/fsIFile.h>
#include <fsCore/fsRect.h>
#include "fsCImage.h"
#include "../../src/fsCBrush.h"
fsU32 fsCTexture::v3FilterModes(fsFilterMode pNewMode)<--- The member function 'fsCTexture::v3FilterModes' can be static.
{
switch(pNewMode)
{
case fsFilterMode::eNEAREST: return 0x2600;
case fsFilterMode::eNEAREST_MIPMAP_NEAREST: return 0x2700;
case fsFilterMode::eNEAREST_MIPMAP_LINEAR: return 0x2702;
case fsFilterMode::eLINEAR: return 0x2601;
case fsFilterMode::eLINEAR_MIPMAP_LINEAR: return 0x2703;
case fsFilterMode::eLINEAR_MIPMAP_NEAREST: return 0x2701;
case fsFilterMode::eDONT_CARE: return 0x2600;
}
}
fsU32 fsCTexture::v3WrapModes(fsWrapMode pNewMode)<--- The member function 'fsCTexture::v3WrapModes' can be static.
{
switch(pNewMode)
{
case fsWrapMode::eREPEAT: return 0x2901;
case fsWrapMode::eMIRROR_REPEAT: return 0x2901;
case fsWrapMode::eCLAMP_TO_EDGE: return 0x2900;
case fsWrapMode::eDONT_CARE: return 0x2900;
}
}
void fsCTexture::filterModeSetDo(fsFilterMode pNewMode)
{
cocos2d::Texture2D::TexParams params;
#if defined fsFRAMEWORK_CX_V3
params.minFilter = v3FilterModes(pNewMode);
params.magFilter = v3FilterModes(pNewMode);
#else
params.minFilter = static_cast<cocos2d::backend::SamplerFilter>(pNewMode);
params.magFilter = static_cast<cocos2d::backend::SamplerFilter>(pNewMode);
#endif
mTexture->setTexParameters(params);
}
void fsCTexture::wrapModeSetDo(fsWrapMode pNewMode)
{
cocos2d::Texture2D::TexParams params;
#if defined fsFRAMEWORK_CX_V3
params.wrapS = v3WrapModes(pNewMode);
params.wrapT = v3WrapModes(pNewMode);
#else
params.sAddressMode = static_cast<cocos2d::backend::SamplerAddressMode>(pNewMode);
params.tAddressMode = static_cast<cocos2d::backend::SamplerAddressMode>(pNewMode);
#endif
mTexture->setTexParameters(params);
}
fsS32 fsCTexture::strideGet() const
{
return mImage->dimensionsGet().x;
}
fsBool fsCTexture::hasAlphaChannelGet() const
{
const cocos2d::Texture2D::PixelFormat fmt = mTexture->getPixelFormat();
return (fmt == cocos2d::Texture2D::PixelFormat::RGBA8888 ||
fmt == cocos2d::Texture2D::PixelFormat::BGRA8888);
}
fsU8 fsCTexture::alphaGet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow) const
{
return mImage->alphaGet({pU + pCol, pV + pRow});
}
fsSColour4B fsCTexture::pixelGetDo(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow)
{
return mImage->pixelGet({pU + pCol, pV + pRow});
}
void fsCTexture::doPixelSet(fsS32 pU, fsS32 pV, fsS32 pCol, fsS32 pRow, const fsSColour4B& pPixel)
{
mImage->pixelSet(pU, pV, pCol, pRow, pPixel);
}
void fsCTexture::doTextureCopyThroughStencil(std::shared_ptr<fsITexture> pSrc, std::shared_ptr<fsITexture> pStencil,
fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY, fsS32 pAlphaHitMaskThreshold)
{
mImage->textureCopyThroughStencil(
static_cast<fsCTexture*>(pSrc.get())->mImage.get(),
static_cast<fsCTexture*>(pStencil.get())->mImage.get(), pU, pV, pX, pY);
hitMapStore(pAlphaHitMaskThreshold);
finalise();
}
void fsCTexture::doTextureCopyInto(std::shared_ptr<fsITexture> pSrc, fsS32 pU, fsS32 pV, fsS32 pX, fsS32 pY)
{
mImage->textureCopyInto(
static_cast<fsCTexture*>(pSrc.get())->mImage.get(), pU, pV, pX, pY);
}
fsS32 fsCTexture::imageWidthGet() const
{
return mWidth;
}
fsS32 fsCTexture::imageHeightGet() const
{
return mHeight;
}
fsS32 fsCTexture::textureWidthGet() const
{
return mTexture->getPixelsWide();
}
fsS32 fsCTexture::textureHeightGet() const
{
return mTexture->getPixelsHigh();
}
void fsCTexture::premultipliedAlphaReverse()
{
mImage->premultipliedAlphaReverse();
}
void fsCTexture::createFromImage(fsIImage const* pImage)
{
auto imageImpl = static_cast<fsCImage const*>(pImage)->mImage.get();
mTexture = std::make_shared<cocos2d::Texture2D>();
if (imageImpl->getData())
{
// if (mMaskImage)
// {
// // alphaChannelsCombine(mMaskImage);
// // delete mMaskImage;
// // mMaskImage = nullptr;
// }
// mTexture->initWithImage(mImage.get());
mTexture->initWithImage(imageImpl);
}
// cocos2d::Texture2D::TexParams tRepeatParams;
// tRepeatParams.magFilter = cocos2d::backend::SamplerFilter::LINEAR;
// tRepeatParams.minFilter = cocos2d::backend::SamplerFilter::LINEAR;
// tRepeatParams.sAddressMode = cocos2d::backend::SamplerAddressMode::CLAMP_TO_EDGE;
// tRepeatParams.tAddressMode = cocos2d::backend::SamplerAddressMode::CLAMP_TO_EDGE;
// mTexture->setTexParameters(tRepeatParams);
}
fsU8 fsCTexture::alphaValueGet(fsS32 pImgX, fsS32 pImgY)
{
return mImage->alphaGet({pImgX, pImgY});
}
void fsCTexture::doBlend(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
auto ret = cloneSubSection(pBlend, pOffset);
alphaChannelsCombine(pBlend, pOffset);
}
void fsCTexture::alphaChannelsCombine(fsCBrush const* pBlend, fsPoint const& pOffset)
{
mImage->alphaChannelsCombine(static_cast<fsCTexture const*>(pBlend->textureGet().get())->mImage.get(), pOffset);
}
std::shared_ptr<fsITexture> fsCTexture::doCloneSubSection(fsCBrush const* const pBlend, fsPoint const& pOffset) const
{
mImage->cloneSubSection(static_cast<fsCTexture const*>(pBlend->textureGet().get())->mImage.get(), pOffset);
std::shared_ptr<fsITexture> ret = std::shared_ptr<fsITexture>(new fsCTexture());
return ret;
}
void fsCTexture::createFromAlpha8Data(std::vector<fsU8>& pAlphaData, fsS32 pImgW, fsS32 pImgH,
fsPoint const& pPOTDimenions)
{
cocos2d::Size size(pImgW, pImgH);
fsS32 const bytesPerPixel = {4};
fsS32 const stride = {pPOTDimenions.x * bytesPerPixel};
fsS32 const alpthaStride = {pPOTDimenions.x};
std::vector<fsU8> imgData(stride * pPOTDimenions.y, 0);
for (fsS32 row = 0; row < pImgH; ++row)
{
for (fsS32 col = 0; col < pImgW; ++col)
{
fsS32 const newIndex = col * 4 + (row * stride);
fsU8 const alphaValue = pAlphaData[col + (row * alpthaStride)];
imgData[newIndex + 0] = imgData[newIndex + 1] = imgData[newIndex + 2] = imgData[newIndex + 3] = alphaValue;
}
}
mTexture = std::make_shared<cocos2d::Texture2D>();
mTexture->initWithData(imgData.data(), pPOTDimenions.x * 4 * pPOTDimenions.y * sizeof(fsU8),
cocos2d::Texture2D::PixelFormat::RGBA8888, pPOTDimenions.x, pPOTDimenions.y, size);
mWidth = pImgW;
mHeight = pImgH;
}
fsCTexture::fsCTexture() :
mTexture(nullptr)
{
}
fsCTexture::~fsCTexture()
{
}
|