2013-04-17 21:29:41 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
#include "BPMemLoader.h"
|
|
|
|
#include "EfbCopy.h"
|
|
|
|
#include "EfbInterface.h"
|
2011-02-03 12:55:30 -07:00
|
|
|
#include "SWRenderer.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
#include "TextureEncoder.h"
|
2011-02-03 12:55:30 -07:00
|
|
|
#include "SWStatistics.h"
|
2011-01-28 23:26:03 -07:00
|
|
|
#include "SWVideoConfig.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
#include "DebugUtil.h"
|
|
|
|
#include "HwRasterizer.h"
|
2011-02-03 12:55:30 -07:00
|
|
|
#include "SWCommandProcessor.h"
|
2011-01-30 18:28:32 -07:00
|
|
|
#include "HW/Memmap.h"
|
|
|
|
#include "Core.h"
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
namespace EfbCopy
|
|
|
|
{
|
2013-04-13 21:54:02 -06:00
|
|
|
void CopyToXfb()
|
|
|
|
{
|
|
|
|
GLInterface->Update(); // just updates the render window position and the backbuffer size
|
2010-12-01 22:38:48 -07:00
|
|
|
|
2011-01-28 21:52:19 -07:00
|
|
|
if (!g_SWVideoConfig.bHwRasterizer)
|
2013-04-13 21:54:02 -06:00
|
|
|
{
|
|
|
|
// copy to open gl for rendering
|
|
|
|
EfbInterface::UpdateColorTexture();
|
|
|
|
SWRenderer::DrawTexture(EfbInterface::efbColorTexture, EFB_WIDTH, EFB_HEIGHT);
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2013-04-13 21:54:02 -06:00
|
|
|
SWRenderer::SwapBuffer();
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2013-04-13 21:54:02 -06:00
|
|
|
void CopyToRam()
|
|
|
|
{
|
|
|
|
if (!g_SWVideoConfig.bHwRasterizer)
|
2010-12-01 22:38:48 -07:00
|
|
|
{
|
2011-01-30 18:28:32 -07:00
|
|
|
u8 *dest_ptr = Memory::GetPointer(bpmem.copyTexDest << 5);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2010-12-01 22:38:48 -07:00
|
|
|
TextureEncoder::Encode(dest_ptr);
|
|
|
|
}
|
2013-04-13 21:54:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearEfb()
|
|
|
|
{
|
|
|
|
u32 clearColor = (bpmem.clearcolorAR & 0xff) << 24 | bpmem.clearcolorGB << 8 | (bpmem.clearcolorAR & 0xff00) >> 8;
|
|
|
|
|
|
|
|
int left = bpmem.copyTexSrcXY.x;
|
|
|
|
int top = bpmem.copyTexSrcXY.y;
|
|
|
|
int right = left + bpmem.copyTexSrcWH.x;
|
|
|
|
int bottom = top + bpmem.copyTexSrcWH.y;
|
|
|
|
|
|
|
|
for (u16 y = top; y <= bottom; y++)
|
|
|
|
{
|
|
|
|
for (u16 x = left; x <= right; x++)
|
|
|
|
{
|
|
|
|
EfbInterface::SetColor(x, y, (u8*)(&clearColor));
|
|
|
|
EfbInterface::SetDepth(x, y, bpmem.clearZValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyEfb()
|
|
|
|
{
|
|
|
|
if (bpmem.triggerEFBCopy.copy_to_xfb)
|
|
|
|
DebugUtil::OnFrameEnd();
|
|
|
|
|
|
|
|
if (!g_bSkipCurrentFrame)
|
|
|
|
{
|
|
|
|
if (bpmem.triggerEFBCopy.copy_to_xfb)
|
|
|
|
{
|
|
|
|
CopyToXfb();
|
|
|
|
Core::Callback_VideoCopiedToXFB(true);
|
|
|
|
|
|
|
|
swstats.frameCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyToRam();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpmem.triggerEFBCopy.clear)
|
|
|
|
{
|
|
|
|
if (g_SWVideoConfig.bHwRasterizer)
|
|
|
|
HwRasterizer::Clear();
|
|
|
|
else
|
|
|
|
ClearEfb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bpmem.triggerEFBCopy.copy_to_xfb)
|
|
|
|
{
|
|
|
|
// no frame rendered but tell that a frame has finished for frame skip counter
|
|
|
|
Core::Callback_VideoCopiedToXFB(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|