summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software/TransformUnit.cpp
diff options
context:
space:
mode:
authorLeo Lam <leolino.lam@gmail.com>2017-08-07 14:18:35 +0800
committerGitHub <noreply@github.com>2017-08-07 14:18:35 +0800
commitf64b189850f7665f90787829253f74818f1372aa (patch)
treefe6872eefd654e3e075bcf229d9ca3045e01d500 /Source/Core/VideoBackends/Software/TransformUnit.cpp
parent9e51a7f8d442c5c3bb80ba84165086d10d15747e (diff)
parent745f92b4e586b544fb82a1d2084cd2d57227bb64 (diff)
Merge pull request #5895 from lioncash/sw
TransformUnit: Get rid of most pointer casting in TransformColor()
Diffstat (limited to 'Source/Core/VideoBackends/Software/TransformUnit.cpp')
-rw-r--r--Source/Core/VideoBackends/Software/TransformUnit.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/Source/Core/VideoBackends/Software/TransformUnit.cpp b/Source/Core/VideoBackends/Software/TransformUnit.cpp
index 8fff7ded27..0b1d28c27b 100644
--- a/Source/Core/VideoBackends/Software/TransformUnit.cpp
+++ b/Source/Core/VideoBackends/Software/TransformUnit.cpp
@@ -5,7 +5,9 @@
#include "VideoBackends/Software/TransformUnit.h"
#include <algorithm>
+#include <array>
#include <cmath>
+#include <cstring>
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
@@ -265,7 +267,7 @@ static float CalculateLightAttn(const LightPointer* light, Vec3* _ldir, const Ve
return attn;
}
-static void LightColor(const Vec3& pos, const Vec3& normal, u8 lightNum, LitChannel& chan,
+static void LightColor(const Vec3& pos, const Vec3& normal, u8 lightNum, const LitChannel& chan,
Vec3& lightCol)
{
const LightPointer* light = (const LightPointer*)&xfmem.lights[lightNum];
@@ -322,15 +324,15 @@ void TransformColor(const InputVertexData* src, OutputVertexData* dst)
for (u32 chan = 0; chan < xfmem.numChan.numColorChans; chan++)
{
// abgr
- u8 matcolor[4];
- u8 chancolor[4];
+ std::array<u8, 4> matcolor;
+ std::array<u8, 4> chancolor;
// color
- LitChannel& colorchan = xfmem.color[chan];
+ const LitChannel& colorchan = xfmem.color[chan];
if (colorchan.matsource)
- *(u32*)matcolor = *(u32*)src->color[chan]; // vertex
+ std::memcpy(matcolor.data(), src->color[chan], sizeof(u32)); // vertex
else
- *(u32*)matcolor = xfmem.matColor[chan];
+ std::memcpy(matcolor.data(), &xfmem.matColor[chan], sizeof(u32));
if (colorchan.enablelighting)
{
@@ -344,7 +346,7 @@ void TransformColor(const InputVertexData* src, OutputVertexData* dst)
}
else
{
- u8* ambColor = (u8*)&xfmem.ambColor[chan];
+ const u8* ambColor = reinterpret_cast<u8*>(&xfmem.ambColor[chan]);
lightCol.x = ambColor[1];
lightCol.y = ambColor[2];
lightCol.z = ambColor[3];
@@ -366,11 +368,11 @@ void TransformColor(const InputVertexData* src, OutputVertexData* dst)
}
else
{
- *(u32*)chancolor = *(u32*)matcolor;
+ chancolor = matcolor;
}
// alpha
- LitChannel& alphachan = xfmem.alpha[chan];
+ const LitChannel& alphachan = xfmem.alpha[chan];
if (alphachan.matsource)
matcolor[0] = src->color[chan][0]; // vertex
else
@@ -382,7 +384,7 @@ void TransformColor(const InputVertexData* src, OutputVertexData* dst)
if (alphachan.ambsource)
lightCol = src->color[chan][0]; // vertex
else
- lightCol = (float)(xfmem.ambColor[chan] & 0xff);
+ lightCol = static_cast<float>(xfmem.ambColor[chan] & 0xff);
u8 mask = alphachan.GetFullLightMask();
for (int i = 0; i < 8; ++i)
@@ -400,7 +402,8 @@ void TransformColor(const InputVertexData* src, OutputVertexData* dst)
}
// abgr -> rgba
- *(u32*)dst->color[chan] = Common::swap32(*(u32*)chancolor);
+ const u32 rgba_color = Common::swap32(chancolor.data());
+ std::memcpy(dst->color[chan], &rgba_color, sizeof(u32));
}
}