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 |
#include "fsCTexture.h"
#include <fsCore/fsSColour.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/src/fsNCoreUtils.h>
#include <fsCore/fsPoint.h>
#include "../../src/fsCBrush.h"
#include "fsCImage.h"
fsU32 fsCTexture::filterModes(fsFilterMode pNewMode) const<--- The member function 'fsCTexture::filterModes' can be static.
{
switch(pNewMode)
{
case fsFilterMode::eNEAREST: return BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT;
case fsFilterMode::eNEAREST_MIPMAP_NEAREST: return BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT;
case fsFilterMode::eNEAREST_MIPMAP_LINEAR: return BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT;
case fsFilterMode::eLINEAR: return 0; // bgfx default is bilinear
case fsFilterMode::eLINEAR_MIPMAP_LINEAR: return 0;
case fsFilterMode::eLINEAR_MIPMAP_NEAREST: return BGFX_SAMPLER_MIP_POINT;
case fsFilterMode::eDONT_CARE: return 0;
}
return 0;
}
fsU32 fsCTexture::wrapModes(fsWrapMode pNewMode) const<--- The member function 'fsCTexture::wrapModes' can be static.
{
switch(pNewMode)
{
case fsWrapMode::eREPEAT: return 0; // bgfx default is repeat
case fsWrapMode::eMIRROR_REPEAT: return BGFX_SAMPLER_U_MIRROR | BGFX_SAMPLER_V_MIRROR;
case fsWrapMode::eCLAMP_TO_EDGE: return BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP;
case fsWrapMode::eDONT_CARE: return 0;
}
return 0;
}
void fsCTexture::filterModeSetDo(fsFilterMode pNewMode)
{
mFilterFlags = filterModes(pNewMode);
mSamplerFlags = mFilterFlags | mWrapFlags;
}
void fsCTexture::wrapModeSetDo(fsWrapMode pNewMode)
{
mWrapFlags = wrapModes(pNewMode);
mSamplerFlags = mFilterFlags | mWrapFlags;
}
fsBool fsCTexture::hasAlphaChannelGet() const
{
return false;
}
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 mTexWidth;
}
fsS32 fsCTexture::textureHeightGet() const
{
return mTexHeight;
}
void fsCTexture::textureRelease()
{
if (bgfx::isValid(mTexture))
{
bgfx::destroy(mTexture);
mTexture = BGFX_INVALID_HANDLE;
}
}
void fsCTexture::createFromImage(fsIImage const* pImage)
{
textureRelease();
auto* const impl = static_cast<fsCImage const*>(pImage);
mTexWidth = impl->mWidth;
mTexHeight = impl->mHeight;
mTexture = bgfx::createTexture2D(
static_cast<uint16_t>(impl->mWidth),
static_cast<uint16_t>(impl->mHeight),
false, 1, bgfx::TextureFormat::RGBA8, 0,
bgfx::copy(impl->mPixels.data(), static_cast<uint32_t>(impl->mPixels.size())));
wrapModeSetDo(fsWrapMode::eCLAMP_TO_EDGE);
filterModeSetDo(fsFilterMode::eLINEAR);
}
fsU8 fsCTexture::alphaValueGet(fsS32 pImgX, fsS32 pImgY)
{
return mImage->alphaGet({pImgX, pImgY});
}
void fsCTexture::doBlend(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
}
std::shared_ptr<fsITexture> fsCTexture::doCloneSubSection(fsCBrush const* const pBlend, fsPoint const& pOffset) const
{
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)
{
textureRelease();
fsS32 const bytesPerPixel = {4};
fsS32 const stride = {pPOTDimenions.x * bytesPerPixel};
fsS32 const alphaStride = {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 * alphaStride)];
imgData[newIndex + 0] = imgData[newIndex + 1] = imgData[newIndex + 2] = imgData[newIndex + 3] = alphaValue;
}
}
mTexWidth = pPOTDimenions.x;
mTexHeight = pPOTDimenions.y;
mTexture = bgfx::createTexture2D(
static_cast<uint16_t>(pPOTDimenions.x),
static_cast<uint16_t>(pPOTDimenions.y),
false, 1, bgfx::TextureFormat::RGBA8, 0,
bgfx::copy(imgData.data(), static_cast<uint32_t>(imgData.size())));
wrapModeSetDo(fsWrapMode::eCLAMP_TO_EDGE);
filterModeSetDo(fsFilterMode::eLINEAR);
mWidth = pImgW;
mHeight = pImgH;
}
fsCTexture::fsCTexture()
{
}
fsCTexture::~fsCTexture()
{
textureRelease();
}
|