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

#include "fsCTexture.h"

#include <fsCore/fsSColour.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/src/fsNCoreUtils.h>
#include <fsCore/fsPoint.h>

#include <raylib.h>
#include "../../src/fsCBrush.h"
#include "fsCImage.h"

fsU32 fsCTexture::filterModes(fsFilterMode pNewMode)<--- The member function 'fsCTexture::filterModes' can be static.
{
	switch(pNewMode)
	{
		case fsFilterMode::eNEAREST:				return TEXTURE_FILTER_POINT;
		case fsFilterMode::eNEAREST_MIPMAP_NEAREST: return TEXTURE_FILTER_POINT;
		case fsFilterMode::eNEAREST_MIPMAP_LINEAR: 	return TEXTURE_FILTER_TRILINEAR;
		case fsFilterMode::eLINEAR: 				return TEXTURE_FILTER_BILINEAR;
		case fsFilterMode::eLINEAR_MIPMAP_LINEAR: 	return TEXTURE_FILTER_TRILINEAR;
		case fsFilterMode::eLINEAR_MIPMAP_NEAREST:	return TEXTURE_FILTER_POINT;
		case fsFilterMode::eDONT_CARE:				return TEXTURE_FILTER_POINT;

		// TEXTURE_FILTER_ANISOTROPIC_4X,          // Anisotropic filtering 4x
		// TEXTURE_FILTER_ANISOTROPIC_8X,          // Anisotropic filtering 8x
		// TEXTURE_FILTER_ANISOTROPIC_16X,         // Anisotropic filtering 16x
	}
}

fsU32 fsCTexture::wrapModes(fsWrapMode pNewMode)<--- The member function 'fsCTexture::wrapModes' can be static.
{
	switch(pNewMode)
	{
		case fsWrapMode::eREPEAT:			return TEXTURE_WRAP_REPEAT;
		case fsWrapMode::eMIRROR_REPEAT:	return TEXTURE_WRAP_MIRROR_REPEAT;
		case fsWrapMode::eCLAMP_TO_EDGE:	return TEXTURE_WRAP_CLAMP;
		case fsWrapMode::eDONT_CARE:		return TEXTURE_WRAP_REPEAT;
	}
}
void fsCTexture::filterModeSetDo(fsFilterMode pNewMode)
{
	SetTextureFilter(*mTexture, filterModes(pNewMode));
}

void fsCTexture::wrapModeSetDo(fsWrapMode pNewMode)
{
	SetTextureWrap(*mTexture, wrapModes(pNewMode));
}

fsS32 fsCTexture::strideGet() const
{
	return mImage->dimensionsGet().x;
}

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 mTexture->width;
}

fsS32 fsCTexture::textureHeightGet() const
{
	return mTexture->height;
}

void fsCTexture::premultipliedAlphaReverse()<--- The member function 'fsCTexture::premultipliedAlphaReverse' can be static.
{
}

void fsCTexture::createFromImage(fsIImage const* pImage)
{
	mTexture = std::make_shared<Texture>(LoadTextureFromImage(*static_cast<fsCImage const*>(pImage)->mImage.get()));
	// GenTextureMipmaps(mTexture.get());
	SetTextureWrap(*mTexture.get(), TEXTURE_WRAP_CLAMP);
	SetTextureFilter(*mTexture.get(), TEXTURE_FILTER_BILINEAR);
}

fsU8 fsCTexture::alphaValueGet(fsS32 pImgX, fsS32 pImgY)
{
	return mImage->alphaGet({pImgX, pImgY});
}

void fsCTexture::doBlend(fsCBrush const* const pBlend, fsPoint const& pOffset)
{
}

void fsCTexture::alphaChannelsCombine(fsCBrush const* const pBlend, fsPoint const& pOffset)<--- The member function 'fsCTexture::alphaChannelsCombine' can be static.
{
}

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)
{
	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<Texture>(LoadRenderTexture(pPOTDimenions.x, pPOTDimenions.y).texture);
	UpdateTexture(*mTexture, imgData.data());

	mWidth = pImgW;
	mHeight = pImgH;

}

fsCTexture::fsCTexture()
{
}

fsCTexture::~fsCTexture()
{
}