Making CColor use floats instead of u8s

This commit is contained in:
parax0
2015-12-16 03:28:40 -07:00
parent f11a8b938b
commit 6b8966f0b9
24 changed files with 267 additions and 269 deletions

View File

@@ -36,8 +36,6 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f
GLuint ModelMtxLoc = pTextShader->GetUniformLocation("ModelMtx");
GLuint ColorLoc = pTextShader->GetUniformLocation("FontColor");
GLuint LayerLoc = pTextShader->GetUniformLocation("RGBALayer");
CVector4f FillColor4f = FillColor.ToVector4f();
CVector4f StrokeColor4f = StrokeColor.ToVector4f();
mpFontTexture->Bind(0);
smGlyphVertices.Bind();
glDisable(GL_DEPTH_TEST);
@@ -117,7 +115,7 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f
// Draw fill
glUniform1i(LayerLoc, GlyphLayer);
glUniform4fv(ColorLoc, 1, &FillColor4f.x);
glUniform4fv(ColorLoc, 1, &FillColor.r);
smGlyphIndices.DrawElements();
// Draw stroke
@@ -129,7 +127,7 @@ CVector2f CFont::RenderString(const TString& String, CRenderer* /*pRenderer*/, f
else if (mTextureFormat == 8) StrokeLayer = GlyphLayer - 2;
glUniform1i(LayerLoc, StrokeLayer);
glUniform4fv(ColorLoc, 1, &StrokeColor4f.x);
glUniform4fv(ColorLoc, 1, &StrokeColor.r);
smGlyphIndices.DrawElements();
}

View File

@@ -200,21 +200,21 @@ void CLight::Load() const
case eDirectional:
Light->Position = CVector4f(-mDirection * 1048576.f, 1.f);
Light->Direction = CVector4f(mDirection, 0.f);
Light->Color = mColor.ToVector4f() * CGraphics::sWorldLightMultiplier;
Light->Color = mColor * CGraphics::sWorldLightMultiplier;
Light->DistAtten = CVector4f(1.f, 0.f, 0.f, 0.f);
Light->AngleAtten = CVector4f(1.f, 0.f, 0.f, 0.f);
break;
case eSpot:
Light->Position = CVector4f(mPosition, 1.f);
Light->Direction = CVector4f(mDirection, 0.f);
Light->Color = mColor.ToVector4f() * CGraphics::sWorldLightMultiplier;
Light->Color = mColor * CGraphics::sWorldLightMultiplier;
Light->DistAtten = mDistAttenCoefficients;
Light->AngleAtten = mAngleAttenCoefficients;
break;
case eCustom:
Light->Position = CVector4f(mPosition, 1.f);
Light->Direction = CVector4f(mDirection, 0.f);
Light->Color = mColor.ToVector4f() * CGraphics::sWorldLightMultiplier;
Light->Color = mColor * CGraphics::sWorldLightMultiplier;
Light->DistAtten = mDistAttenCoefficients;
Light->AngleAtten = mAngleAttenCoefficients;
break;

View File

@@ -131,11 +131,11 @@ bool CMaterial::SetCurrent(ERenderOptions Options)
// Set konst inputs
for (u32 iKonst = 0; iKonst < 4; iKonst++)
CGraphics::sPixelBlock.Konst[iKonst] = mKonstColors[iKonst].ToVector4f();
CGraphics::sPixelBlock.Konst[iKonst] = mKonstColors[iKonst];
// Set color channels
// COLOR0_Amb is initialized by the node instead of by the material
CGraphics::sVertexBlock.COLOR0_Mat = CColor::skWhite.ToVector4f();
CGraphics::sVertexBlock.COLOR0_Mat = CColor::skWhite;
// Set depth write - force on if alpha is disabled (lots of weird depth issues otherwise)
if ((mOptions & eDepthWrite) || (Options & eNoAlpha)) glDepthMask(GL_TRUE);

View File

@@ -173,7 +173,7 @@ void CMaterialCooker::WriteMaterialPrime(COutputStream& Out)
{
Out.WriteLong(NumKonst);
for (u32 iKonst = 0; iKonst < NumKonst; iKonst++)
Out.WriteLong( mpMat->Konst(iKonst).AsLongRGBA() );
Out.WriteLong( mpMat->Konst(iKonst).ToLongRGBA() );
}
// Blend Mode

View File

@@ -81,7 +81,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
for (u32 iKonst = 0; iKonst < KonstCount; iKonst++)
{
if (iKonst >= 4) break;
pMat->mKonstColors[iKonst] = CColor(*mpFile);
pMat->mKonstColors[iKonst] = CColor(*mpFile, true);
}
if (KonstCount > 4) mpFile->Seek(0x4 * (KonstCount - 4), SEEK_CUR);
}
@@ -303,7 +303,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
if (Type == "CLR ")
{
CFourCC ClrType = mpFile->ReadLong();
CColor ClrVal(*mpFile);
CColor ClrVal(*mpFile, true);
if (ClrType == "DIFB")
{

View File

@@ -97,8 +97,7 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat
break;
}
case eColorProperty: {
CVector4f color(SCLY);
CColor v(color.x, color.y, color.z, color.w);
CColor v(SCLY);
pProp = new CColorProperty(v);
break;
}
@@ -334,8 +333,7 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct,
case eColorProperty: {
CColorProperty *pColorCast = static_cast<CColorProperty*>(pProp);
CVector4f Color(SCLY);
pColorCast->Set(CColor(Color.x, Color.y, Color.z, Color.w));
pColorCast->Set(CColor(SCLY));
break;
}

View File

@@ -339,7 +339,7 @@ void CTextureDecoder::FullDecodeGXTexture(CInputStream& TXTR)
else if (mTexelFormat == eGX_C8) Pixel = DecodePixelC8(TXTR.ReadByte(), mPaletteInput);
else if (mTexelFormat == eGX_RGB565) Pixel = DecodePixelRGB565(TXTR.ReadShort());
else if (mTexelFormat == eGX_RGB5A3) Pixel = DecodePixelRGB5A3(TXTR.ReadShort());
else if (mTexelFormat == eGX_RGBA8) Pixel = CColor(TXTR);
else if (mTexelFormat == eGX_RGBA8) Pixel = CColor(TXTR, true);
Out.WriteLong(Pixel.ToLongARGB());
}
@@ -558,25 +558,26 @@ void CTextureDecoder::ReadPixelRGB565(CInputStream& src, COutputStream& dst)
void CTextureDecoder::ReadPixelRGB5A3(CInputStream& src, COutputStream& dst)
{
u16 px = src.ReadShort();
CColor c;
u8 r, g, b, a;
if (px & 0x8000) // RGB5
{
c.b = Extend5to8(px >> 10);
c.g = Extend5to8(px >> 5);
c.r = Extend5to8(px >> 0);
c.a = 0xFF;
b = Extend5to8(px >> 10);
g = Extend5to8(px >> 5);
r = Extend5to8(px >> 0);
a = 255;
}
else // RGB4A3
{
c.a = Extend3to8(px >> 12);
c.b = Extend4to8(px >> 8);
c.g = Extend4to8(px >> 4);
c.r = Extend4to8(px >> 0);
a = Extend3to8(px >> 12);
b = Extend4to8(px >> 8);
g = Extend4to8(px >> 4);
r = Extend4to8(px >> 0);
}
dst.WriteLong(c.ToLongARGB());
u32 c = (a << 24) | (r << 16) | (g << 8) | b;
dst.WriteLong(c);
}
void CTextureDecoder::ReadPixelRGBA8(CInputStream& src, COutputStream& dst)
@@ -606,26 +607,26 @@ CColor CTextureDecoder::DecodePixelI4(u8 Byte, u8 WhichPixel)
{
if (WhichPixel == 1) Byte >>= 4;
u8 px = Extend4to8(Byte);
return CColor(px, px, px, 0xFF);
return CColor::Integral(px, px, px);
}
CColor CTextureDecoder::DecodePixelI8(u8 Byte)
{
return CColor(Byte, Byte, Byte, 0xFF);
return CColor::Integral(Byte, Byte, Byte);
}
CColor CTextureDecoder::DecodePixelIA4(u8 Byte)
{
u8 Alpha = Extend4to8(Byte >> 4);
u8 Lum = Extend4to8(Byte);
return CColor(Lum, Lum, Lum, Alpha);
return CColor::Integral(Lum, Lum, Lum, Alpha);
}
CColor CTextureDecoder::DecodePixelIA8(u16 Short)
{
u8 Alpha = (Short >> 8) & 0xFF;
u8 Lum = Short & 0xFF;
return CColor(Lum, Lum, Lum, Alpha);
return CColor::Integral(Lum, Lum, Lum, Alpha);
}
CColor CTextureDecoder::DecodePixelC4(u8 Byte, u8 WhichPixel, CInputStream& PaletteStream)
@@ -654,7 +655,7 @@ CColor CTextureDecoder::DecodePixelRGB565(u16 Short)
u8 b = Extend5to8( (u8) (Short >> 11) );
u8 g = Extend6to8( (u8) (Short >> 5) );
u8 r = Extend5to8( (u8) (Short) );
return CColor(r, g, b, 0xFF);
return CColor::Integral(r, g, b, 0xFF);
}
CColor CTextureDecoder::DecodePixelRGB5A3(u16 Short)
@@ -664,7 +665,7 @@ CColor CTextureDecoder::DecodePixelRGB5A3(u16 Short)
u8 b = Extend5to8( (u8) (Short >> 10));
u8 g = Extend5to8( (u8) (Short >> 5));
u8 r = Extend5to8( (u8) (Short) );
return CColor(r, g, b, 0xFF);
return CColor::Integral(r, g, b, 0xFF);
}
else // RGB4A3
@@ -673,7 +674,7 @@ CColor CTextureDecoder::DecodePixelRGB5A3(u16 Short)
u8 b = Extend4to8( (u8) (Short >> 8) );
u8 g = Extend4to8( (u8) (Short >> 4) );
u8 r = Extend4to8( (u8) (Short) );
return CColor(r, g, b, a);
return CColor::Integral(r, g, b, a);
}
}
@@ -819,9 +820,8 @@ void CTextureDecoder::DecodeBlockBC3(CInputStream& src, COutputStream& dst, u32
}
}
CColor CTextureDecoder::DecodeDDSPixel(CInputStream&)
CColor CTextureDecoder::DecodeDDSPixel(CInputStream& /*DDS*/)
{
// Not using parameter 1 (CInputStream& - DDS)
return CColor::skWhite;
}