Merge pull request #779 from lioncash/software-cleanup

Small software backend cleanup.
This commit is contained in:
Tony Wasserka 2014-08-12 11:59:21 +02:00
commit d03e91962e
20 changed files with 331 additions and 201 deletions

View File

@ -45,7 +45,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Clipper
{
enum { NUM_CLIPPED_VERTICES = 33, NUM_INDICES = NUM_CLIPPED_VERTICES + 3 };
enum
{
NUM_CLIPPED_VERTICES = 33,
NUM_INDICES = NUM_CLIPPED_VERTICES + 3
};
static float m_ViewOffset[2];
@ -72,7 +76,8 @@ namespace Clipper
}
enum {
enum
{
SKIP_FLAG = -1,
CLIP_POS_X_BIT = 0x01,
CLIP_NEG_X_BIT = 0x02,
@ -86,12 +91,25 @@ namespace Clipper
{
int cmask = 0;
Vec4 pos = v->projectedPosition;
if (pos.w - pos.x < 0) cmask |= CLIP_POS_X_BIT;
if (pos.x + pos.w < 0) cmask |= CLIP_NEG_X_BIT;
if (pos.w - pos.y < 0) cmask |= CLIP_POS_Y_BIT;
if (pos.y + pos.w < 0) cmask |= CLIP_NEG_Y_BIT;
if (pos.w * pos.z > 0) cmask |= CLIP_POS_Z_BIT;
if (pos.z + pos.w < 0) cmask |= CLIP_NEG_Z_BIT;
if (pos.w - pos.x < 0)
cmask |= CLIP_POS_X_BIT;
if (pos.x + pos.w < 0)
cmask |= CLIP_NEG_X_BIT;
if (pos.w - pos.y < 0)
cmask |= CLIP_POS_Y_BIT;
if (pos.y + pos.w < 0)
cmask |= CLIP_NEG_Y_BIT;
if (pos.w * pos.z > 0)
cmask |= CLIP_POS_Z_BIT;
if (pos.z + pos.w < 0)
cmask |= CLIP_NEG_Z_BIT;
return cmask;
}
@ -209,7 +227,8 @@ namespace Clipper
indices[0] = inlist[0];
indices[1] = inlist[1];
indices[2] = inlist[2];
for (int j = 3; j < n; ++j) {
for (int j = 3; j < n; ++j)
{
indices[numIndices++] = inlist[0];
indices[numIndices++] = inlist[j - 1];
indices[numIndices++] = inlist[j];
@ -276,9 +295,11 @@ namespace Clipper
if (!CullTest(v0, v1, v2, backface))
return;
int indices[NUM_INDICES] = { 0, 1, 2, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG };
int indices[NUM_INDICES] = {
0, 1, 2, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG,
SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG, SKIP_FLAG
};
int numIndices = 3;
if (backface)

View File

@ -25,18 +25,18 @@ namespace DebugUtil
static bool drawingHwTriangles = false;
enum { NumObjectBuffers = 40};
static const int NUM_OBJECT_BUFFERS = 40;
static u32 *ObjectBuffer[NumObjectBuffers];
static u32 TempBuffer[NumObjectBuffers];
static u32 *ObjectBuffer[NUM_OBJECT_BUFFERS];
static u32 TempBuffer[NUM_OBJECT_BUFFERS];
static bool DrawnToBuffer[NumObjectBuffers];
static const char* ObjectBufferName[NumObjectBuffers];
static int BufferBase[NumObjectBuffers];
static bool DrawnToBuffer[NUM_OBJECT_BUFFERS];
static const char* ObjectBufferName[NUM_OBJECT_BUFFERS];
static int BufferBase[NUM_OBJECT_BUFFERS];
void Init()
{
for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
ObjectBuffer[i] = new u32[EFB_WIDTH*EFB_HEIGHT]();
DrawnToBuffer[i] = false;
@ -47,7 +47,7 @@ void Init()
void Shutdown()
{
for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
delete[] ObjectBuffer[i];
}
@ -159,7 +159,7 @@ static void DumpEfb(const std::string& filename)
static void DumpColorTexture(const std::string& filename, u32 width, u32 height)
{
TextureToPng(SWRenderer::getCurrentColorTexture(), width * 4, filename, width, height, true);
TextureToPng(SWRenderer::GetCurrentColorTexture(), width * 4, filename, width, height, true);
}
void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name)
@ -229,7 +229,7 @@ void OnObjectEnd()
drawingHwTriangles = false;
}
for (int i = 0; i < NumObjectBuffers; i++)
for (int i = 0; i < NUM_OBJECT_BUFFERS; i++)
{
if (DrawnToBuffer[i])
{

View File

@ -45,12 +45,12 @@ namespace EfbCopy
else
{
// Ask SWRenderer for the next color texture
u8 *colorTexture = SWRenderer::getNextColorTexture();
u8 *colorTexture = SWRenderer::GetNextColorTexture();
EfbInterface::BypassXFB(colorTexture, fbWidth, fbHeight, sourceRc, Gamma);
// Tell SWRenderer we are now finished with it.
SWRenderer::swapColorTexture();
SWRenderer::SwapColorTexture();
// FifoPlayer is broken and never calls BeginFrame/EndFrame.
// Hence, we manually force a swap now. This emulates the behavior

View File

@ -20,12 +20,12 @@ namespace EfbInterface
{
u32 perf_values[PQ_NUM_MEMBERS];
inline u32 GetColorOffset(u16 x, u16 y)
static inline u32 GetColorOffset(u16 x, u16 y)
{
return (x + y * EFB_WIDTH) * 3;
}
inline u32 GetDepthOffset(u16 x, u16 y)
static inline u32 GetDepthOffset(u16 x, u16 y)
{
return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START;
}
@ -498,7 +498,8 @@ namespace EfbInterface
return &efb[GetColorOffset(x, y)];
}
void CopyToXFB(yuv422_packed* xfb_in_ram, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma) {
void CopyToXFB(yuv422_packed* xfb_in_ram, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
// FIXME: We should do Gamma correction
if (!xfb_in_ram)
@ -512,7 +513,8 @@ namespace EfbInterface
// this assumes copies will always start on an even (YU) pixel and the
// copy always has an even width, which might not be true.
if (left & 1 || right & 1) {
if (left & 1 || right & 1)
{
WARN_LOG(VIDEO, "Trying to copy XFB to from unaligned EFB source");
// this will show up as wrongly encoded
}
@ -557,8 +559,10 @@ namespace EfbInterface
}
// Like CopyToXFB, but we copy directly into the opengl colour texture without going via GameCube main memory or doing a yuyv conversion
void BypassXFB(u8* texture, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma) {
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT) {
void BypassXFB(u8* texture, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
{
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT)
{
ERROR_LOG(VIDEO, "Framebuffer is too large: %ix%i", fbWidth, fbHeight);
return;
}

View File

@ -27,7 +27,13 @@ namespace EfbInterface
s8 V;
};
enum { ALP_C, BLU_C, GRN_C, RED_C };
enum
{
ALP_C,
BLU_C,
GRN_C,
RED_C
};
// color order is ABGR in order to emulate RGBA on little-endian hardware

View File

@ -37,7 +37,13 @@ struct InputVertexData
struct OutputVertexData
{
// components in color channels
enum { RED_C, GRN_C, BLU_C, ALP_C };
enum
{
RED_C,
GRN_C,
BLU_C,
ALP_C
};
Vec3 mvPosition;
Vec4 projectedPosition;

View File

@ -161,7 +161,7 @@ void RasterFont::printString(const char *s, double x, double y, double z)
void RasterFont::printCenteredString(const char *s, double y, int screen_width, double z)
{
int length = (int)strlen(s);
int x = (int)(screen_width/2.0 - (length/2.0)*char_width);
int x = (int)(screen_width/2.0 - (length/2.0) * CHAR_WIDTH);
printString(s, x, y, z);
}
@ -177,7 +177,7 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
{
*t = 0;
printString(temp, x, y, z);
y -= char_height * 2.0f / bbHeight;
y -= CHAR_HEIGHT * 2.0f / bbHeight;
x = start_x;
t = temp;
}
@ -187,12 +187,12 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
}
else if (*text == '\t')
{
//todo: add tabs every something like 4*char_width
//todo: add tabs every something like 4 * CHAR_WIDTH
*t = 0;
int cpos = (int)strlen(temp);
int newpos = (cpos + 4) & (~3);
printString(temp, x, y, z);
x = start_x + (char_width*newpos) * 2.0f / bbWidth;
x = start_x + (CHAR_WIDTH * newpos) * 2.0f / bbWidth;
t = temp;
*t++ = ' ';
}

View File

@ -11,17 +11,17 @@ public:
~RasterFont(void);
static int debug;
// some useful constants
enum {char_width = 10};
enum {char_height = 15};
// and the happy helper functions
void printString(const char *s, double x, double y, double z=0.0);
void printCenteredString(const char *s, double y, int screen_width, double z=0.0);
void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight);
private:
int fontOffset;
char *temp_buffer;
enum {TEMP_BUFFER_SIZE = 64 * 1024};
static const int TEMP_BUFFER_SIZE = 64 * 1024;
static const int CHAR_WIDTH = 10;
static const int CHAR_HEIGHT = 15;
};

View File

@ -83,11 +83,9 @@ void Init()
ZSlope.f0 = 1.f;
}
inline int iround(float x)
static inline int iround(float x)
{
int t;
t = (int)x;
int t = (int)x;
if ((x - t) >= 0.5)
return t + 1;
@ -100,16 +98,20 @@ void SetScissor()
int yoff = bpmem.scissorOffset.y * 2 - 342;
scissorLeft = bpmem.scissorTL.x - xoff - 342;
if (scissorLeft < 0) scissorLeft = 0;
if (scissorLeft < 0)
scissorLeft = 0;
scissorTop = bpmem.scissorTL.y - yoff - 342;
if (scissorTop < 0) scissorTop = 0;
if (scissorTop < 0)
scissorTop = 0;
scissorRight = bpmem.scissorBR.x - xoff - 341;
if (scissorRight > EFB_WIDTH) scissorRight = EFB_WIDTH;
if (scissorRight > EFB_WIDTH)
scissorRight = EFB_WIDTH;
scissorBottom = bpmem.scissorBR.y - yoff - 341;
if (scissorBottom > EFB_HEIGHT) scissorBottom = EFB_HEIGHT;
if (scissorBottom > EFB_HEIGHT)
scissorBottom = EFB_HEIGHT;
}
void SetTevReg(int reg, int comp, bool konst, s16 color)
@ -208,7 +210,7 @@ static void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, fl
slope->f0 = f1;
}
inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord)
static inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord)
{
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
u8 subTexmap = texmap & 3;

View File

@ -61,19 +61,30 @@ void DoState(PointerWrap &p)
}
// does it matter that there is no synchronization between threads during writes?
inline void WriteLow (u32& _reg, u16 lowbits) {_reg = (_reg & 0xFFFF0000) | lowbits;}
inline void WriteHigh(u32& _reg, u16 highbits) {_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);}
inline u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
static inline void WriteLow (u32& _reg, u16 lowbits)
{
_reg = (_reg & 0xFFFF0000) | lowbits;
}
static inline void WriteHigh(u32& _reg, u16 highbits)
{
_reg = (_reg & 0x0000FFFF) | ((u32)highbits << 16);
}
static inline u16 ReadLow(u32 _reg)
{
return (u16)(_reg & 0xFFFF);
}
static inline u16 ReadHigh(u32 _reg)
{
return (u16)(_reg >> 16);
}
static void UpdateInterrupts_Wrapper(u64 userdata, int cyclesLate)
{
UpdateInterrupts(userdata);
}
inline bool AtBreakpoint()
static inline bool AtBreakpoint()
{
return cpreg.ctrl.BPEnable && (cpreg.readptr == cpreg.breakpt);
}

View File

@ -153,27 +153,31 @@ void SWRenderer::DrawDebugText()
SWRenderer::RenderText(debugtext.c_str(), 20, 20, 0xFFFFFF00);
}
u8* SWRenderer::getNextColorTexture() {
u8* SWRenderer::GetNextColorTexture()
{
return s_xfbColorTexture[!s_currentColorTexture];
}
u8* SWRenderer::getCurrentColorTexture() {
u8* SWRenderer::GetCurrentColorTexture()
{
return s_xfbColorTexture[s_currentColorTexture];
}
void SWRenderer::swapColorTexture() {
void SWRenderer::SwapColorTexture()
{
s_currentColorTexture = !s_currentColorTexture;
}
void SWRenderer::UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidth, u32 fbHeight)
{
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT) {
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT)
{
ERROR_LOG(VIDEO, "Framebuffer is too large: %ix%i", fbWidth, fbHeight);
return;
}
u32 offset = 0;
u8 *TexturePointer = getNextColorTexture();
u8 *TexturePointer = GetNextColorTexture();
for (u16 y = 0; y < fbHeight; y++)
{
@ -199,7 +203,7 @@ void SWRenderer::UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidt
}
xfb += fbWidth;
}
swapColorTexture();
SwapColorTexture();
}
// Called on the GPU thread
@ -207,7 +211,7 @@ void SWRenderer::Swap(u32 fbWidth, u32 fbHeight)
{
GLInterface->Update(); // just updates the render window position and the backbuffer size
if (!g_SWVideoConfig.bHwRasterizer)
SWRenderer::DrawTexture(getCurrentColorTexture(), fbWidth, fbHeight);
SWRenderer::DrawTexture(GetCurrentColorTexture(), fbWidth, fbHeight);
swstats.frameCount++;
SWRenderer::SwapBuffer();

View File

@ -18,9 +18,9 @@ namespace SWRenderer
void RenderText(const char* pstr, int left, int top, u32 color);
void DrawDebugText();
u8* getNextColorTexture();
u8* getCurrentColorTexture();
void swapColorTexture();
u8* GetNextColorTexture();
u8* GetCurrentColorTexture();
void SwapColorTexture();
void UpdateColorTexture(EfbInterface::yuv422_packed *xfb, u32 fbWidth, u32 fbHeight);
void DrawTexture(u8 *texture, int width, int height);

View File

@ -54,8 +54,8 @@ void SetupUnit::SetupVertex()
}
void SetupUnit::SetupQuad()
{
void SetupUnit::SetupQuad()
{
if (m_VertexCounter < 2)
{
m_VertexCounter++;

View File

@ -123,12 +123,12 @@ void Tev::Init()
m_ScaleRShiftLUT[3] = 1;
}
inline s16 Clamp255(s16 in)
static inline s16 Clamp255(s16 in)
{
return in>255?255:(in<0?0:in);
}
inline s16 Clamp1024(s16 in)
static inline s16 Clamp1024(s16 in)
{
return in>1023?1023:(in<-1024?-1024:in);
}
@ -336,7 +336,8 @@ void Tev::DrawAlphaCompare(TevStageCombiner::AlphaCombiner& ac, const InputRegTy
static bool AlphaCompare(int alpha, int ref, AlphaTest::CompareMode comp)
{
switch (comp) {
switch (comp)
{
case AlphaTest::ALWAYS: return true;
case AlphaTest::NEVER: return false;
case AlphaTest::LEQUAL: return alpha <= ref;
@ -346,6 +347,7 @@ static bool AlphaCompare(int alpha, int ref, AlphaTest::CompareMode comp)
case AlphaTest::EQUAL: return alpha == ref;
case AlphaTest::NEQUAL: return alpha != ref;
}
return true;
}
@ -364,7 +366,7 @@ static bool TevAlphaTest(int alpha)
return true;
}
inline s32 WrapIndirectCoord(s32 coord, int wrapMode)
static inline s32 WrapIndirectCoord(s32 coord, int wrapMode)
{
switch (wrapMode)
{

View File

@ -77,13 +77,19 @@ public:
s32 TextureLod[16];
bool TextureLinear[16];
enum
{
ALP_C,
BLU_C,
GRN_C,
RED_C
};
void Init();
void Draw();
void SetRegColor(int reg, int comp, bool konst, s16 color);
enum { ALP_C, BLU_C, GRN_C, RED_C };
void DoState(PointerWrap &p);
};

View File

@ -13,7 +13,7 @@
namespace TextureEncoder
{
inline void RGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
static inline void RGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
{
u32 srcColor = *(u32*)src;
a = Convert6To8(srcColor & 0x3f);
@ -22,7 +22,7 @@ inline void RGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
r = Convert6To8((srcColor >> 18)& 0x3f);
}
inline void RGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
static inline void RGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
{
u32 srcColor = *(u32*)src;
b = Convert6To8((srcColor >> 6) & 0x3f);
@ -30,7 +30,7 @@ inline void RGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
r = Convert6To8((srcColor >> 18)& 0x3f);
}
inline u8 RGB8_to_I(u8 r, u8 g, u8 b)
static inline u8 RGB8_to_I(u8 r, u8 g, u8 b)
{
// values multiplied by 256 to keep math integer
u16 val = 4096 + 66 * r + 129 * g + 25 * b;
@ -40,7 +40,7 @@ inline u8 RGB8_to_I(u8 r, u8 g, u8 b)
// box filter sampling averages 4 samples with the source texel being the top left of the box
// components are scaled to the range 0-255 after all samples are taken
inline void boxfilterRGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
static inline void BoxfilterRGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
{
u16 r16 = 0, g16 = 0, b16 = 0, a16 = 0;
@ -66,7 +66,7 @@ inline void boxfilterRGBA_to_RGBA8(u8 *src, u8 &r, u8 &g, u8 &b, u8 &a)
a = a16 + (a16 >> 6);
}
inline void boxfilterRGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
static inline void BoxfilterRGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
{
u16 r16 = 0, g16 = 0, b16 = 0;
@ -90,7 +90,7 @@ inline void boxfilterRGBA_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
b = b16 + (b16 >> 6);
}
inline void boxfilterRGBA_to_x8(u8 *src, u8 &x8, int shift)
static inline void BoxfilterRGBA_to_x8(u8 *src, u8 &x8, int shift)
{
u16 x16 = 0;
@ -110,7 +110,7 @@ inline void boxfilterRGBA_to_x8(u8 *src, u8 &x8, int shift)
x8 = x16 + (x16 >> 6);
}
inline void boxfilterRGBA_to_xx8(u8 *src, u8 &x1, u8 &x2, int shift1, int shift2)
static inline void BoxfilterRGBA_to_xx8(u8 *src, u8 &x1, u8 &x2, int shift1, int shift2)
{
u16 x16_1 = 0;
u16 x16_2 = 0;
@ -133,7 +133,7 @@ inline void boxfilterRGBA_to_xx8(u8 *src, u8 &x1, u8 &x2, int shift1, int shift2
x2 = x16_2 + (x16_2 >> 6);
}
inline void boxfilterRGB_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
static inline void BoxfilterRGB_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
{
u16 r16 = 0, g16 = 0, b16 = 0;
@ -155,7 +155,7 @@ inline void boxfilterRGB_to_RGB8(u8 *src, u8 &r, u8 &g, u8 &b)
b = b16 >> 2;
}
inline void boxfilterRGB_to_x8(u8 *src, u8 &x8, int comp)
static inline void BoxfilterRGB_to_x8(u8 *src, u8 &x8, int comp)
{
u16 x16 = 0;
@ -174,7 +174,7 @@ inline void boxfilterRGB_to_x8(u8 *src, u8 &x8, int comp)
x8 = x16 >> 2;
}
inline void boxfilterRGB_to_xx8(u8 *src, u8 &x1, u8 &x2, int comp1, int comp2)
static inline void BoxfilterRGB_to_xx8(u8 *src, u8 &x1, u8 &x2, int comp1, int comp2)
{
u16 x16_1 = 0;
u16 x16_2 = 0;
@ -506,11 +506,11 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
sBlkSize /= 2;
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGB8(src, r, g, b);
BoxfilterRGBA_to_RGB8(src, r, g, b);
src += readStride;
*dst = RGB8_to_I(r, g, b) & 0xf0;
boxfilterRGBA_to_RGB8(src, r, g, b);
BoxfilterRGBA_to_RGB8(src, r, g, b);
src += readStride;
*dst |= RGB8_to_I(r, g, b) >> 4;
dst++;
@ -523,7 +523,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGB8(src, r, g, b);
BoxfilterRGBA_to_RGB8(src, r, g, b);
src += readStride;
*dst++ = RGB8_to_I(r, g, b);
}
@ -535,7 +535,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGBA8(src, r, g, b, a);
BoxfilterRGBA_to_RGBA8(src, r, g, b, a);
src += readStride;
*dst++ = (a & 0xf0) | (RGB8_to_I(r, g, b) >> 4);
}
@ -547,7 +547,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGBA8(src, r, g, b, a);
BoxfilterRGBA_to_RGBA8(src, r, g, b, a);
src += readStride;
*dst++ = a;
*dst++ = RGB8_to_I(r, g, b);
@ -560,7 +560,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGB8(src, r, g, b);
BoxfilterRGBA_to_RGB8(src, r, g, b);
src += readStride;
u16 val = ((r << 8) & 0xf800) | ((g << 3) & 0x07e0) | ((b >> 3) & 0x001e);
@ -575,7 +575,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGBA8(src, r, g, b, a);
BoxfilterRGBA_to_RGBA8(src, r, g, b, a);
src += readStride;
u16 val;
@ -595,7 +595,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_RGBA8(src, dst[1], dst[32], dst[33], dst[0]);
BoxfilterRGBA_to_RGBA8(src, dst[1], dst[32], dst[33], dst[0]);
src += readStride;
dst += 2;
}
@ -608,11 +608,11 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
sBlkSize /= 2;
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_x8(src, r, 18);
BoxfilterRGBA_to_x8(src, r, 18);
src += readStride;
*dst = r & 0xf0;
boxfilterRGBA_to_x8(src, r, 18);
BoxfilterRGBA_to_x8(src, r, 18);
src += readStride;
*dst |= r >> 4;
dst++;
@ -625,7 +625,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_xx8(src, r, a, 18, 0);
BoxfilterRGBA_to_xx8(src, r, a, 18, 0);
src += readStride;
*dst++ = (a & 0xf0) | (r >> 4);
}
@ -637,7 +637,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_xx8(src, r, a, 18, 0);
BoxfilterRGBA_to_xx8(src, r, a, 18, 0);
src += readStride;
*dst++ = a;
*dst++ = r;
@ -650,7 +650,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_x8(src, a, 0);
BoxfilterRGBA_to_x8(src, a, 0);
*dst++ = a;
src += readStride;
}
@ -662,7 +662,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_x8(src, r, 18);
BoxfilterRGBA_to_x8(src, r, 18);
*dst++ = r;
src += readStride;
}
@ -674,7 +674,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_x8(src, g, 12);
BoxfilterRGBA_to_x8(src, g, 12);
*dst++ = g;
src += readStride;
}
@ -686,7 +686,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_x8(src, b, 6);
BoxfilterRGBA_to_x8(src, b, 6);
*dst++ = b;
src += readStride;
}
@ -698,7 +698,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_xx8(src, r, g, 18, 12);
BoxfilterRGBA_to_xx8(src, r, g, 18, 12);
src += readStride;
*dst++ = g;
*dst++ = r;
@ -711,7 +711,7 @@ static void EncodeRGBA6halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGBA_to_xx8(src, g, b, 12, 6);
BoxfilterRGBA_to_xx8(src, g, b, 12, 6);
src += readStride;
*dst++ = b;
*dst++ = g;
@ -955,11 +955,11 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
sBlkSize /= 2;
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
*dst = RGB8_to_I(r, g, b) & 0xf0;
src += readStride;
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
*dst |= RGB8_to_I(r, g, b) >> 4;
src += readStride;
dst++;
@ -972,7 +972,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
*dst++ = RGB8_to_I(r, g, b);
src += readStride;
}
@ -984,7 +984,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
*dst++ = 0xf0 | (RGB8_to_I(r, g, b) >> 4);
src += readStride;
}
@ -996,7 +996,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
*dst++ = 0xff;
*dst++ = RGB8_to_I(r, g, b);
src += readStride;
@ -1009,7 +1009,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
u16 val = ((r << 8) & 0xf800) | ((g << 3) & 0x07e0) | ((b >> 3) & 0x001e);
*(u16*)dst = Common::swap16(val);
src += readStride;
@ -1023,7 +1023,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
u16 val = 0x8000 | ((r << 7) & 0x7c00) | ((g << 2) & 0x03e0) | ((b >> 3) & 0x001e);
*(u16*)dst = Common::swap16(val);
src += readStride;
@ -1037,7 +1037,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, r, g, b);
BoxfilterRGB_to_RGB8(src, r, g, b);
dst[0] = 0xff;
dst[1] = r;
dst[32] = g;
@ -1054,11 +1054,11 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
sBlkSize /= 2;
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, r, 2);
BoxfilterRGB_to_x8(src, r, 2);
*dst = r & 0xf0;
src += readStride;
boxfilterRGB_to_x8(src, r, 2);
BoxfilterRGB_to_x8(src, r, 2);
*dst |= r >> 4;
src += readStride;
@ -1072,7 +1072,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, r, 2);
BoxfilterRGB_to_x8(src, r, 2);
*dst++ = 0xf0 | (r >> 4);
src += readStride;
}
@ -1084,7 +1084,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, r, 2);
BoxfilterRGB_to_x8(src, r, 2);
*dst++ = 0xff;
*dst++ = r;
src += readStride;
@ -1107,7 +1107,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, r, 2);
BoxfilterRGB_to_x8(src, r, 2);
*dst++ = r;
src += readStride;
}
@ -1119,7 +1119,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, g, 1);
BoxfilterRGB_to_x8(src, g, 1);
*dst++ = g;
src += readStride;
}
@ -1131,7 +1131,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, b, 0);
BoxfilterRGB_to_x8(src, b, 0);
*dst++ = b;
src += readStride;
}
@ -1143,7 +1143,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_xx8(src, r, g, 2, 1);
BoxfilterRGB_to_xx8(src, r, g, 2, 1);
*dst++ = g;
*dst++ = r;
src += readStride;
@ -1156,7 +1156,7 @@ static void EncodeRGB8halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_xx8(src, g, b, 1, 0);
BoxfilterRGB_to_xx8(src, g, b, 1, 0);
*dst++ = b;
*dst++ = g;
src += readStride;
@ -1289,7 +1289,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, b, 2);
BoxfilterRGB_to_x8(src, b, 2);
*dst++ = b;
src += readStride;
}
@ -1301,7 +1301,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_xx8(src, g, b, 1, 2);
BoxfilterRGB_to_xx8(src, g, b, 1, 2);
*dst++ = b;
*dst++ = g;
src += readStride;
@ -1314,7 +1314,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_RGB8(src, dst[33], dst[32], dst[1]);
BoxfilterRGB_to_RGB8(src, dst[33], dst[32], dst[1]);
dst[0] = 255;
src += readStride;
dst += 2;
@ -1328,11 +1328,11 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
sBlkSize /= 2;
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, b, 2);
BoxfilterRGB_to_x8(src, b, 2);
*dst = b & 0xf0;
src += readStride;
boxfilterRGB_to_x8(src, b, 2);
BoxfilterRGB_to_x8(src, b, 2);
*dst |= b >> 4;
src += readStride;
@ -1346,7 +1346,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, g, 1);
BoxfilterRGB_to_x8(src, g, 1);
*dst++ = g;
src += readStride;
}
@ -1358,7 +1358,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_x8(src, r, 0);
BoxfilterRGB_to_x8(src, r, 0);
*dst++ = r;
src += readStride;
}
@ -1370,7 +1370,7 @@ static void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
SetSpans(sBlkSize, tBlkSize, tSpan, sBlkSpan, tBlkSpan, writeStride);
ENCODE_LOOP_BLOCKS
{
boxfilterRGB_to_xx8(src, r, g, 0, 1);
BoxfilterRGB_to_xx8(src, r, g, 0, 1);
*dst++ = g;
*dst++ = r;
src += readStride;

View File

@ -15,7 +15,7 @@
namespace TextureSampler
{
inline void WrapCoord(int &coord, int wrapMode, int imageSize)
static inline void WrapCoord(int &coord, int wrapMode, int imageSize)
{
switch (wrapMode)
{
@ -38,7 +38,7 @@ inline void WrapCoord(int &coord, int wrapMode, int imageSize)
}
}
inline void SetTexel(u8 *inTexel, u32 *outTexel, u32 fract)
static inline void SetTexel(u8 *inTexel, u32 *outTexel, u32 fract)
{
outTexel[0] = inTexel[0] * fract;
outTexel[1] = inTexel[1] * fract;
@ -46,7 +46,7 @@ inline void SetTexel(u8 *inTexel, u32 *outTexel, u32 fract)
outTexel[3] = inTexel[3] * fract;
}
inline void AddTexel(u8 *inTexel, u32 *outTexel, u32 fract)
static inline void AddTexel(u8 *inTexel, u32 *outTexel, u32 fract)
{
outTexel[0] += inTexel[0] * fract;
outTexel[1] += inTexel[1] * fract;

View File

@ -12,5 +12,11 @@ namespace TextureSampler
void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample);
enum { RED_SMP, GRN_SMP, BLU_SMP, ALP_SMP };
enum
{
RED_SMP,
GRN_SMP,
BLU_SMP,
ALP_SMP
};
}

View File

@ -95,12 +95,12 @@ void TransformNormal(const InputVertexData *src, bool nbt, OutputVertexData *dst
MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
MultiplyVec3Mat33(src->normal[1], mat, dst->normal[1]);
MultiplyVec3Mat33(src->normal[2], mat, dst->normal[2]);
dst->normal[0].normalize();
dst->normal[0].Normalize();
}
else
{
MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
dst->normal[0].normalize();
dst->normal[0].Normalize();
}
}
@ -170,7 +170,7 @@ static void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bo
else
{
if (postInfo.normalize)
tempCoord = dst->normalized();
tempCoord = dst->Normalized();
else
tempCoord = *dst;
@ -189,21 +189,21 @@ struct LightPointer
Vec3 dir;
};
inline void AddIntegerColor(const u8 *src, Vec3 &dst)
static inline void AddIntegerColor(const u8 *src, Vec3 &dst)
{
dst.x += src[1];
dst.y += src[2];
dst.z += src[3];
}
inline void AddScaledIntegerColor(const u8 *src, float scale, Vec3 &dst)
static inline void AddScaledIntegerColor(const u8 *src, float scale, Vec3 &dst)
{
dst.x += src[1] * scale;
dst.y += src[2] * scale;
dst.z += src[3] * scale;
}
inline float SafeDivide(float n, float d)
static inline float SafeDivide(float n, float d)
{
return (d==0) ? (n>0?1:0) : n/d;
}
@ -222,14 +222,14 @@ static void LightColor(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const L
break;
case LIGHTDIF_SIGN:
{
Vec3 ldir = (light->pos - pos).normalized();
Vec3 ldir = (light->pos - pos).Normalized();
float diffuse = ldir * normal;
AddScaledIntegerColor(light->color, diffuse, lightCol);
}
break;
case LIGHTDIF_CLAMP:
{
Vec3 ldir = (light->pos - pos).normalized();
Vec3 ldir = (light->pos - pos).Normalized();
float diffuse = std::max(0.0f, ldir * normal);
AddScaledIntegerColor(light->color, diffuse, lightCol);
}
@ -245,7 +245,7 @@ static void LightColor(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const L
if (chan.attnfunc == 3) // spot
{
float dist2 = ldir.length2();
float dist2 = ldir.Length2();
float dist = sqrtf(dist2);
ldir = ldir / dist;
attn = std::max(0.0f, ldir * light->dir);
@ -307,14 +307,14 @@ static void LightAlpha(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const L
break;
case LIGHTDIF_SIGN:
{
Vec3 ldir = (light->pos - pos).normalized();
Vec3 ldir = (light->pos - pos).Normalized();
float diffuse = ldir * normal;
lightCol += light->color[0] * diffuse;
}
break;
case LIGHTDIF_CLAMP:
{
Vec3 ldir = (light->pos - pos).normalized();
Vec3 ldir = (light->pos - pos).Normalized();
float diffuse = std::max(0.0f, ldir * normal);
lightCol += light->color[0] * diffuse;
}
@ -329,7 +329,7 @@ static void LightAlpha(const Vec3 &pos, const Vec3 &normal, u8 lightNum, const L
if (chan.attnfunc == 3) // spot
{
float dist2 = ldir.length2();
float dist2 = ldir.Length2();
float dist = sqrtf(dist2);
ldir = ldir / dist;
attn = std::max(0.0f, ldir * light->dir);
@ -478,7 +478,7 @@ void TransformTexCoord(const InputVertexData *src, OutputVertexData *dst, bool s
{
const LightPointer *light = (const LightPointer*)&xfmem.lights[texinfo.embosslightshift];
Vec3 ldir = (light->pos - dst->mvPosition).normalized();
Vec3 ldir = (light->pos - dst->mvPosition).Normalized();
float d1 = ldir * dst->normal[1];
float d2 = ldir * dst->normal[2];

View File

@ -12,93 +12,155 @@
class Vec3
{
public:
float x,y,z;
Vec3() { }
explicit Vec3(float f) {x=y=z=f;}
explicit Vec3(const float *f) {x=f[0]; y=f[1]; z=f[2];}
Vec3(const float _x, const float _y, const float _z) {
x=_x; y=_y; z=_z;
}
void set(const float _x, const float _y, const float _z) {
x=_x; y=_y; z=_z;
}
Vec3 operator + (const Vec3 &other) const {
return Vec3(x+other.x, y+other.y, z+other.z);
}
void operator += (const Vec3 &other) {
x+=other.x; y+=other.y; z+=other.z;
}
Vec3 operator -(const Vec3 &v) const {
return Vec3(x-v.x,y-v.y,z-v.z);
}
void operator -= (const Vec3 &other)
float x, y, z;
Vec3()
{
x-=other.x; y-=other.y; z-=other.z;
}
Vec3 operator -() const {
return Vec3(-x,-y,-z);
}
Vec3 operator * (const float f) const {
return Vec3(x*f,y*f,z*f);
explicit Vec3(float f)
{
x = y = z = f;
}
Vec3 operator / (const float f) const {
float invf = (1.0f/f);
return Vec3(x*invf,y*invf,z*invf);
explicit Vec3(const float *f)
{
x = f[0];
y = f[1];
z = f[2];
}
void operator /= (const float f)
Vec3(const float _x, const float _y, const float _z)
{
x = _x;
y = _y;
z = _z;
}
void set(const float _x, const float _y, const float _z)
{
x = _x;
y = _y;
z = _z;
}
Vec3 operator+(const Vec3 &other) const
{
return Vec3(x + other.x, y + other.y, z + other.z);
}
void operator+=(const Vec3 &other)
{
x += other.x;
y += other.y;
z += other.z;
}
Vec3 operator-(const Vec3 &v) const
{
return Vec3(x - v.x, y - v.y, z - v.z);
}
void operator-=(const Vec3 &other)
{
x -= other.x;
y -= other.y;
z -= other.z;
}
Vec3 operator-() const
{
return Vec3(-x, -y, -z);
}
Vec3 operator*(const float f) const
{
return Vec3(x * f, y * f, z * f);
}
Vec3 operator/(const float f) const
{
float invf = (1.0f / f);
return Vec3(x * invf, y * invf, z * invf);
}
void operator/=(const float f)
{
*this = *this / f;
}
float operator * (const Vec3 &other) const {
return x*other.x + y*other.y + z*other.z;
float operator*(const Vec3 &other) const
{
return (x * other.x) +
(y * other.y) +
(z * other.z);
}
void operator *= (const float f) {
void operator*=(const float f)
{
*this = *this * f;
}
Vec3 scaled_by(const Vec3 &other) const {
return Vec3(x*other.x, y*other.y, z*other.z);
}
Vec3 operator %(const Vec3 &v) const {
return Vec3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}
float length2() const {
return x*x+y*y+z*z;
}
float length() const {
return sqrtf(length2());
}
float distance2_to(Vec3 &other)
Vec3 ScaledBy(const Vec3 &other) const
{
return (other-(*this)).length2();
return Vec3(x * other.x, y * other.y, z * other.z);
}
Vec3 normalized() const {
return (*this) / length();
Vec3 operator%(const Vec3 &v) const
{
return Vec3((y * v.z) - (z * v.y),
(z * v.x) - (x * v.z),
(x * v.y) - (y * v.x));
}
void normalize() {
(*this) /= length();
float Length2() const
{
return (x * x) + (y * y) + (z * z);
}
float &operator [] (int i)
float Length() const
{
return sqrtf(Length2());
}
float Distance2To(Vec3 &other)
{
return (other - (*this)).Length2();
}
Vec3 Normalized() const
{
return (*this) / Length();
}
void Normalize()
{
(*this) /= Length();
}
float &operator[](int i)
{
return *((&x) + i);
}
float operator [] (const int i) const
float operator[](const int i) const
{
return *((&x) + i);
}
bool operator == (const Vec3 &other) const
bool operator==(const Vec3 &other) const
{
if (x==other.x && y==other.y && z==other.z)
if (x == other.x && y == other.y && z == other.z)
return true;
else
return false;
}
void setZero()
void SetZero()
{
memset((void *)this,0,sizeof(float)*3);
memset((void*)this, 0, sizeof(float) * 3);
}
void DoState(PointerWrap &p)
{
p.Do(x);