2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-03-29 02:22:15 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-09-19 04:17:41 +00:00
|
|
|
#include "Common/CommonFuncs.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/Memmap.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/Software/BPMemLoader.h"
|
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/LookUpTables.h"
|
2014-03-29 02:22:15 +00:00
|
|
|
#include "VideoCommon/PixelEngine.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
|
2014-07-08 13:58:25 +00:00
|
|
|
static u8 efb[EFB_WIDTH*EFB_HEIGHT*6];
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
namespace EfbInterface
|
|
|
|
{
|
2014-03-29 02:22:15 +00:00
|
|
|
u32 perf_values[PQ_NUM_MEMBERS];
|
|
|
|
|
2014-08-11 01:51:05 +00:00
|
|
|
static inline u32 GetColorOffset(u16 x, u16 y)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
return (x + y * EFB_WIDTH) * 3;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-08-11 01:51:05 +00:00
|
|
|
static inline u32 GetDepthOffset(u16 x, u16 y)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-02-26 01:05:02 +00:00
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
|
|
|
p.DoArray(efb, EFB_WIDTH*EFB_HEIGHT*6);
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelAlphaOnly(u32 offset, u8 a)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::Z24:
|
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
// do nothing
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGBA6_Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 a32 = a;
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = *dst & 0xffffffc0;
|
|
|
|
val |= (a32 >> 2) & 0x0000003f;
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelColorOnly(u32 offset, u8 *rgb)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)rgb;
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGBA6_Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)rgb;
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = *dst & 0xff00003f;
|
2014-02-17 04:51:41 +00:00
|
|
|
val |= (src >> 4) & 0x00000fc0; // blue
|
|
|
|
val |= (src >> 6) & 0x0003f000; // green
|
|
|
|
val |= (src >> 8) & 0x00fc0000; // red
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
INFO_LOG(VIDEO, "RGB565_Z16 is not supported correctly yet");
|
2013-04-14 03:54:02 +00:00
|
|
|
u32 src = *(u32*)rgb;
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelAlphaColor(u32 offset, u8 *color)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)color;
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGBA6_Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)color;
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2014-02-17 04:51:41 +00:00
|
|
|
val |= (src >> 2) & 0x0000003f; // alpha
|
|
|
|
val |= (src >> 4) & 0x00000fc0; // blue
|
|
|
|
val |= (src >> 6) & 0x0003f000; // green
|
|
|
|
val |= (src >> 8) & 0x00fc0000; // red
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
INFO_LOG(VIDEO, "RGB565_Z16 is not supported correctly yet");
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)color;
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
2010-12-31 06:45:18 +00:00
|
|
|
val |= src >> 8;
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void GetPixelColor(u32 offset, u8 *color)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 src = *(u32*)&efb[offset];
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 *dst = (u32*)color;
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = 0xff | ((src & 0x00ffffff) << 8);
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGBA6_Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)&efb[offset];
|
2010-12-31 06:45:18 +00:00
|
|
|
color[ALP_C] = Convert6To8(src & 0x3f);
|
|
|
|
color[BLU_C] = Convert6To8((src >> 6) & 0x3f);
|
|
|
|
color[GRN_C] = Convert6To8((src >> 12) & 0x3f);
|
|
|
|
color[RED_C] = Convert6To8((src >> 18) & 0x3f);
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
INFO_LOG(VIDEO, "RGB565_Z16 is not supported correctly yet");
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 src = *(u32*)&efb[offset];
|
|
|
|
u32 *dst = (u32*)color;
|
2010-12-31 06:45:18 +00:00
|
|
|
u32 val = 0xff | ((src & 0x00ffffff) << 8);
|
2010-06-09 01:37:08 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SetPixelDepth(u32 offset, u32 depth)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::RGBA6_Z24:
|
|
|
|
case PEControl::Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 *dst = (u32*)&efb[offset];
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 val = *dst & 0xff000000;
|
|
|
|
val |= depth & 0x00ffffff;
|
2013-10-29 05:23:17 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
INFO_LOG(VIDEO, "RGB565_Z16 is not supported correctly yet");
|
2010-06-09 01:37:08 +00:00
|
|
|
u32 *dst = (u32*)&efb[offset];
|
|
|
|
u32 val = *dst & 0xff000000;
|
|
|
|
val |= depth & 0x00ffffff;
|
2013-10-29 05:23:17 +00:00
|
|
|
*dst = val;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static u32 GetPixelDepth(u32 offset)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 depth = 0;
|
|
|
|
|
|
|
|
switch (bpmem.zcontrol.pixel_format)
|
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB8_Z24:
|
|
|
|
case PEControl::RGBA6_Z24:
|
|
|
|
case PEControl::Z24:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
depth = (*(u32*)&efb[offset]) & 0x00ffffff;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-23 20:44:23 +00:00
|
|
|
case PEControl::RGB565_Z16:
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-23 20:44:23 +00:00
|
|
|
INFO_LOG(VIDEO, "RGB565_Z16 is not supported correctly yet");
|
2010-06-09 01:37:08 +00:00
|
|
|
depth = (*(u32*)&efb[offset]) & 0x00ffffff;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-23 20:44:23 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unsupported pixel format: %i", static_cast<int>(bpmem.zcontrol.pixel_format));
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static u32 GetSourceFactor(u8 *srcClr, u8 *dstClr, BlendMode::BlendFactor mode)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case BlendMode::ZERO:
|
|
|
|
return 0;
|
|
|
|
case BlendMode::ONE:
|
|
|
|
return 0xffffffff;
|
|
|
|
case BlendMode::DSTCLR:
|
|
|
|
return *(u32*)dstClr;
|
|
|
|
case BlendMode::INVDSTCLR:
|
|
|
|
return 0xffffffff - *(u32*)dstClr;
|
|
|
|
case BlendMode::SRCALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::INVSRCALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = 0xff - srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::DSTALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::INVDSTALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = 0xff - dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static u32 GetDestinationFactor(u8 *srcClr, u8 *dstClr, BlendMode::BlendFactor mode)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case BlendMode::ZERO:
|
|
|
|
return 0;
|
|
|
|
case BlendMode::ONE:
|
|
|
|
return 0xffffffff;
|
|
|
|
case BlendMode::SRCCLR:
|
|
|
|
return *(u32*)srcClr;
|
|
|
|
case BlendMode::INVSRCCLR:
|
|
|
|
return 0xffffffff - *(u32*)srcClr;
|
|
|
|
case BlendMode::SRCALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::INVSRCALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = 0xff - srcClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::DSTALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = dstClr[ALP_C] & 0xff;
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
case BlendMode::INVDSTALPHA:
|
|
|
|
{
|
|
|
|
u8 alpha = 0xff - dstClr[ALP_C];
|
|
|
|
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
|
|
|
|
return factor;
|
|
|
|
}
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void BlendColor(u8 *srcClr, u8 *dstClr)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
u32 srcFactor = GetSourceFactor(srcClr, dstClr, bpmem.blendmode.srcfactor);
|
|
|
|
u32 dstFactor = GetDestinationFactor(srcClr, dstClr, bpmem.blendmode.dstfactor);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
// add MSB of factors to make their range 0 -> 256
|
|
|
|
u32 sf = (srcFactor & 0xff);
|
|
|
|
sf += sf >> 7;
|
|
|
|
|
|
|
|
u32 df = (dstFactor & 0xff);
|
|
|
|
df += df >> 7;
|
|
|
|
|
|
|
|
u32 color = (srcClr[i] * sf + dstClr[i] * df) >> 8;
|
|
|
|
dstClr[i] = (color>255)?255:color;
|
|
|
|
|
|
|
|
dstFactor >>= 8;
|
|
|
|
srcFactor >>= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 06:20:46 +00:00
|
|
|
static void LogicBlend(u32 srcClr, u32* dstClr, BlendMode::LogicOp op)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
case BlendMode::CLEAR:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = 0;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::AND:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr & *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::AND_REVERSE:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr & (~*dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::COPY:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::AND_INVERTED:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = (~srcClr) & *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::NOOP:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
case BlendMode::XOR:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr ^ *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::OR:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr | *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::NOR:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr | *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::EQUIV:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr ^ *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::INVERT:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~*dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::OR_REVERSE:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = srcClr | (~*dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::COPY_INVERTED:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~srcClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::OR_INVERTED:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = (~srcClr) | *dstClr;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::NAND:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = ~(srcClr & *dstClr);
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
|
|
|
case BlendMode::SET:
|
2014-10-02 06:20:46 +00:00
|
|
|
*dstClr = 0xffffffff;
|
2014-03-24 19:21:34 +00:00
|
|
|
break;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void SubtractBlend(u8 *srcClr, u8 *dstClr)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
int c = (int)dstClr[i] - (int)srcClr[i];
|
|
|
|
dstClr[i] = (c < 0)?0:c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlendTev(u16 x, u16 y, u8 *color)
|
|
|
|
{
|
|
|
|
u32 dstClr;
|
|
|
|
u32 offset = GetColorOffset(x, y);
|
|
|
|
|
|
|
|
u8 *dstClrPtr = (u8*)&dstClr;
|
|
|
|
|
|
|
|
GetPixelColor(offset, dstClrPtr);
|
|
|
|
|
|
|
|
if (bpmem.blendmode.blendenable)
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.subtract)
|
|
|
|
SubtractBlend(color, dstClrPtr);
|
|
|
|
else
|
|
|
|
BlendColor(color, dstClrPtr);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.logicopenable)
|
|
|
|
{
|
2014-10-02 06:20:46 +00:00
|
|
|
LogicBlend(*((u32*)color), &dstClr, bpmem.blendmode.logicmode);
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dstClrPtr = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpmem.dstalpha.enable)
|
|
|
|
dstClrPtr[ALP_C] = bpmem.dstalpha.alpha;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
if (bpmem.blendmode.colorupdate)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
SetPixelAlphaColor(offset, dstClrPtr);
|
|
|
|
else
|
|
|
|
SetPixelColorOnly(offset, dstClrPtr);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.alphaupdate)
|
|
|
|
{
|
|
|
|
SetPixelAlphaOnly(offset, dstClrPtr[ALP_C]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetColor(u16 x, u16 y, u8 *color)
|
|
|
|
{
|
|
|
|
u32 offset = GetColorOffset(x, y);
|
|
|
|
if (bpmem.blendmode.colorupdate)
|
|
|
|
{
|
|
|
|
if (bpmem.blendmode.alphaupdate)
|
|
|
|
SetPixelAlphaColor(offset, color);
|
|
|
|
else
|
|
|
|
SetPixelColorOnly(offset, color);
|
|
|
|
}
|
|
|
|
else if (bpmem.blendmode.alphaupdate)
|
|
|
|
{
|
|
|
|
SetPixelAlphaOnly(offset, color[ALP_C]);
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-03-14 13:08:36 +00:00
|
|
|
void SetDepth(u16 x, u16 y, u32 depth)
|
|
|
|
{
|
|
|
|
if (bpmem.zmode.updateenable)
|
|
|
|
SetPixelDepth(GetDepthOffset(x, y), depth);
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
void GetColor(u16 x, u16 y, u8 *color)
|
|
|
|
{
|
|
|
|
u32 offset = GetColorOffset(x, y);
|
|
|
|
GetPixelColor(offset, color);
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// For internal used only, return a non-normalized value, which saves work later.
|
|
|
|
void GetColorYUV(u16 x, u16 y, yuv444 *out)
|
|
|
|
{
|
|
|
|
u8 color[4];
|
|
|
|
GetColor(x, y, color);
|
|
|
|
|
|
|
|
// GameCube/Wii uses the BT.601 standard algorithm for converting to YCbCr; see
|
|
|
|
// http://www.equasys.de/colorconversion.html#YCbCr-RGBColorFormatConversion
|
2014-02-16 15:59:26 +00:00
|
|
|
out->Y = (u8)( 0.257f * color[RED_C] + 0.504f * color[GRN_C] + 0.098f * color[BLU_C]);
|
|
|
|
out->U = (u8)(-0.148f * color[RED_C] + -0.291f * color[GRN_C] + 0.439f * color[BLU_C]);
|
|
|
|
out->V = (u8)( 0.439f * color[RED_C] + -0.368f * color[GRN_C] + -0.071f * color[BLU_C]);
|
2013-08-20 11:51:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
u32 GetDepth(u16 x, u16 y)
|
|
|
|
{
|
|
|
|
u32 offset = GetDepthOffset(x, y);
|
|
|
|
return GetPixelDepth(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *GetPixelPointer(u16 x, u16 y, bool depth)
|
|
|
|
{
|
|
|
|
if (depth)
|
|
|
|
return &efb[GetDepthOffset(x, y)];
|
|
|
|
return &efb[GetColorOffset(x, y)];
|
|
|
|
}
|
|
|
|
|
2014-08-11 01:18:38 +00:00
|
|
|
void CopyToXFB(yuv422_packed* xfb_in_ram, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
|
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
// FIXME: We should do Gamma correction
|
2013-04-14 03:54:02 +00:00
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
if (!xfb_in_ram)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
WARN_LOG(VIDEO, "Tried to copy to invalid XFB address");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int left = sourceRc.left;
|
|
|
|
int right = sourceRc.right;
|
|
|
|
|
|
|
|
// this assumes copies will always start on an even (YU) pixel and the
|
|
|
|
// copy always has an even width, which might not be true.
|
2014-08-11 01:18:38 +00:00
|
|
|
if (left & 1 || right & 1)
|
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
WARN_LOG(VIDEO, "Trying to copy XFB to from unaligned EFB source");
|
|
|
|
// this will show up as wrongly encoded
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scanline buffer, leave room for borders
|
2013-11-23 10:44:05 +00:00
|
|
|
yuv444 scanline[EFB_WIDTH+2];
|
2013-08-20 11:51:39 +00:00
|
|
|
|
|
|
|
// our internal yuv444 type is not normalized, so black is {0, 0, 0} instead of {16, 128, 128}
|
2013-08-20 13:18:30 +00:00
|
|
|
yuv444 black;
|
|
|
|
black.Y = 0;
|
|
|
|
black.U = 0;
|
|
|
|
black.V = 0;
|
|
|
|
|
|
|
|
scanline[0] = black; // black border at start
|
|
|
|
scanline[right+1] = black; // black border at end
|
2013-08-20 11:51:39 +00:00
|
|
|
|
|
|
|
for (u16 y = sourceRc.top; y < sourceRc.bottom; y++)
|
|
|
|
{
|
|
|
|
// Get a scanline of YUV pixels in 4:4:4 format
|
|
|
|
|
|
|
|
for (int i = 1, x = left; x < right; i++, x++)
|
|
|
|
{
|
|
|
|
GetColorYUV(x, y, &scanline[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And Downsample them to 4:2:2
|
|
|
|
for (int i = 1, x = left; x < right; i+=2, x+=2)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2013-08-20 11:51:39 +00:00
|
|
|
// YU pixel
|
2013-11-23 05:38:15 +00:00
|
|
|
xfb_in_ram[x].Y = scanline[i].Y + 16;
|
2013-08-22 12:07:21 +00:00
|
|
|
// we mix our color difrences in 10 bit space so it will round more accurately
|
|
|
|
// U[i] = 1/4 * U[i-1] + 1/2 * U[i] + 1/4 * U[i+1]
|
2013-08-20 11:51:39 +00:00
|
|
|
xfb_in_ram[x].UV = 128 + ((scanline[i-1].U + (scanline[i].U << 1) + scanline[i+1].U) >> 2);
|
|
|
|
|
|
|
|
// YV pixel
|
2013-11-23 05:38:15 +00:00
|
|
|
xfb_in_ram[x+1].Y = scanline[i+1].Y + 16;
|
2013-08-22 12:07:21 +00:00
|
|
|
// V[i] = 1/4 * V[i-1] + 1/2 * V[i] + 1/4 * V[i+1]
|
2013-08-20 11:51:39 +00:00
|
|
|
xfb_in_ram[x+1].UV = 128 + ((scanline[i].V + (scanline[i+1].V << 1) + scanline[i+2].V) >> 2);
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
2013-11-23 05:38:15 +00:00
|
|
|
xfb_in_ram += fbWidth;
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-07 02:30:39 +00:00
|
|
|
// Like CopyToXFB, but we copy directly into the opengl colour texture without going via GameCube main memory or doing a yuyv conversion
|
2014-08-11 01:18:38 +00:00
|
|
|
void BypassXFB(u8* texture, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc, float Gamma)
|
|
|
|
{
|
|
|
|
if (fbWidth*fbHeight > MAX_XFB_WIDTH*MAX_XFB_HEIGHT)
|
|
|
|
{
|
2013-11-23 11:15:08 +00:00
|
|
|
ERROR_LOG(VIDEO, "Framebuffer is too large: %ix%i", fbWidth, fbHeight);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-23 07:04:37 +00:00
|
|
|
u32 color;
|
|
|
|
u8* colorPtr = (u8*)&color;
|
|
|
|
u32* texturePtr = (u32*)texture;
|
|
|
|
u32 textureAddress = 0;
|
|
|
|
|
|
|
|
int left = sourceRc.left;
|
|
|
|
int right = sourceRc.right;
|
|
|
|
|
|
|
|
for (u16 y = sourceRc.top; y < sourceRc.bottom; y++)
|
|
|
|
{
|
|
|
|
for (u16 x = left; x < right; x++)
|
|
|
|
{
|
|
|
|
GetColor(x, y, colorPtr);
|
|
|
|
texturePtr[textureAddress++] = Common::swap32(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
bool ZCompare(u16 x, u16 y, u32 z)
|
|
|
|
{
|
|
|
|
u32 offset = GetDepthOffset(x, y);
|
|
|
|
u32 depth = GetPixelDepth(offset);
|
|
|
|
|
|
|
|
bool pass;
|
|
|
|
|
|
|
|
switch (bpmem.zmode.func)
|
|
|
|
{
|
2014-03-24 19:21:34 +00:00
|
|
|
case ZMode::NEVER:
|
|
|
|
pass = false;
|
|
|
|
break;
|
|
|
|
case ZMode::LESS:
|
|
|
|
pass = z < depth;
|
|
|
|
break;
|
|
|
|
case ZMode::EQUAL:
|
|
|
|
pass = z == depth;
|
|
|
|
break;
|
|
|
|
case ZMode::LEQUAL:
|
|
|
|
pass = z <= depth;
|
|
|
|
break;
|
|
|
|
case ZMode::GREATER:
|
|
|
|
pass = z > depth;
|
|
|
|
break;
|
|
|
|
case ZMode::NEQUAL:
|
|
|
|
pass = z != depth;
|
|
|
|
break;
|
|
|
|
case ZMode::GEQUAL:
|
|
|
|
pass = z >= depth;
|
|
|
|
break;
|
|
|
|
case ZMode::ALWAYS:
|
|
|
|
pass = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pass = false;
|
|
|
|
ERROR_LOG(VIDEO, "Bad Z compare mode %i", (int)bpmem.zmode.func);
|
2013-04-14 03:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pass && bpmem.zmode.updateenable)
|
|
|
|
{
|
|
|
|
SetPixelDepth(offset, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pass;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|