Added menu option for toggling true color output on and off

This commit is contained in:
Magnus Norddahl 2016-05-30 13:32:24 +02:00
commit 7080180d47
6 changed files with 218 additions and 196 deletions

View file

@ -187,6 +187,7 @@ EXTERN_CVAR (Float, Gamma)
EXTERN_CVAR (Bool, vid_vsync)
EXTERN_CVAR (Float, transsouls)
EXTERN_CVAR (Int, vid_refreshrate)
EXTERN_CVAR (Bool, r_swtruecolor)
extern IDirect3D9 *D3D;
@ -765,11 +766,7 @@ void D3DFB::KillNativeTexs()
bool D3DFB::CreateFBTexture ()
{
#ifndef PALETTEOUTPUT
D3DFORMAT FBFormat = D3DFMT_A8R8G8B8;
#else
D3DFORMAT FBFormat = D3DFMT_L8;
#endif
FBFormat = r_swtruecolor ? D3DFMT_A8R8G8B8 : D3DFMT_L8;
if (FAILED(D3DDevice->CreateTexture(Width, Height, 1, D3DUSAGE_DYNAMIC, FBFormat, D3DPOOL_DEFAULT, &FBTexture, NULL)))
{
@ -1310,20 +1307,45 @@ void D3DFB::Draw3DPart(bool copy3d)
SUCCEEDED(FBTexture->LockRect (0, &lockrect, NULL, D3DLOCK_DISCARD))) ||
SUCCEEDED(FBTexture->LockRect (0, &lockrect, &texrect, 0)))
{
if (lockrect.Pitch == Pitch * sizeof(canvas_pixel_t) && Pitch == Width)
if (r_swtruecolor && FBFormat == D3DFMT_A8R8G8B8)
{
memcpy (lockrect.pBits, MemBuffer, Width * Height * sizeof(canvas_pixel_t));
if (lockrect.Pitch == Pitch * sizeof(uint32_t) && Pitch == Width)
{
memcpy(lockrect.pBits, MemBuffer, Width * Height * sizeof(uint32_t));
}
else
{
uint32_t *dest = (uint32_t *)lockrect.pBits;
uint32_t *src = MemBuffer;
for (int y = 0; y < Height; y++)
{
memcpy(dest, src, Width * sizeof(uint32_t));
dest = reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(dest) + lockrect.Pitch);
src += Pitch;
}
}
}
else if (!r_swtruecolor && FBFormat == D3DFMT_L8)
{
if (lockrect.Pitch == Pitch && Pitch == Width)
{
memcpy(lockrect.pBits, MemBuffer, Width * Height);
}
else
{
BYTE *dest = (BYTE *)lockrect.pBits;
BYTE *src = (BYTE *)MemBuffer;
for (int y = 0; y < Height; y++)
{
memcpy(dest, src, Width);
dest = reinterpret_cast<BYTE*>(reinterpret_cast<uint8_t*>(dest) + lockrect.Pitch);
src += Pitch;
}
}
}
else
{
canvas_pixel_t *dest = (canvas_pixel_t *)lockrect.pBits;
canvas_pixel_t *src = MemBuffer;
for (int y = 0; y < Height; y++)
{
memcpy (dest, src, Width * sizeof(canvas_pixel_t));
dest = reinterpret_cast<canvas_pixel_t*>(reinterpret_cast<uint8_t*>(dest) + lockrect.Pitch);
src += Pitch;
}
memset(lockrect.pBits, 0, lockrect.Pitch * Height);
}
FBTexture->UnlockRect (0);
}
@ -1355,11 +1377,10 @@ void D3DFB::Draw3DPart(bool copy3d)
memset(Constant, 0, sizeof(Constant));
SetAlphaBlend(D3DBLENDOP(0));
EnableAlphaTest(FALSE);
#ifndef PALETTEOUTPUT
SetPixelShader(Shaders[SHADER_NormalColor]);
#else
SetPixelShader(Shaders[SHADER_NormalColorPal]);
#endif
if (r_swtruecolor)
SetPixelShader(Shaders[SHADER_NormalColor]);
else
SetPixelShader(Shaders[SHADER_NormalColorPal]);
if (copy3d)
{
FBVERTEX verts[4];
@ -1377,11 +1398,10 @@ void D3DFB::Draw3DPart(bool copy3d)
realfixedcolormap->ColorizeStart[1]/2, realfixedcolormap->ColorizeStart[2]/2, 0);
color1 = D3DCOLOR_COLORVALUE(realfixedcolormap->ColorizeEnd[0]/2,
realfixedcolormap->ColorizeEnd[1]/2, realfixedcolormap->ColorizeEnd[2]/2, 1);
#ifndef PALETTEOUTPUT
SetPixelShader(Shaders[SHADER_SpecialColormap]);
#else
SetPixelShader(Shaders[SHADER_SpecialColormapPal]);
#endif
if (r_swtruecolor)
SetPixelShader(Shaders[SHADER_SpecialColormap]);
else
SetPixelShader(Shaders[SHADER_SpecialColormapPal]);
}
}
else
@ -1392,11 +1412,10 @@ void D3DFB::Draw3DPart(bool copy3d)
CalcFullscreenCoords(verts, Accel2D, false, color0, color1);
D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX));
}
#ifndef PALETTEOUTPUT
SetPixelShader(Shaders[SHADER_NormalColor]);
#else
SetPixelShader(Shaders[SHADER_NormalColorPal]);
#endif
if (r_swtruecolor)
SetPixelShader(Shaders[SHADER_NormalColor]);
else
SetPixelShader(Shaders[SHADER_NormalColorPal]);
}
//==========================================================================