2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-11-17 19:21:26 -07:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
// GC graphics pipeline
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2015-01-10 22:17:29 -07:00
|
|
|
// 3d commands are issued through the fifo. The GPU draws to the 2MB EFB.
|
2010-11-17 19:21:26 -07:00
|
|
|
// The efb can be copied back into ram in two forms: as textures or as XFB.
|
|
|
|
// The XFB is the region in RAM that the VI chip scans out to the television.
|
|
|
|
// So, after all rendering to EFB is done, the image is copied into one of two XFBs in RAM.
|
|
|
|
// Next frame, that one is scanned out and the other one gets the copy. = double buffering.
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
2014-12-20 04:14:33 -07:00
|
|
|
#include <cinttypes>
|
2010-11-17 19:21:26 -07:00
|
|
|
#include <cmath>
|
2015-12-20 19:49:49 -07:00
|
|
|
#include <memory>
|
2010-11-17 19:21:26 -07:00
|
|
|
#include <string>
|
|
|
|
|
2015-06-18 19:28:40 -06:00
|
|
|
#include "Common/Event.h"
|
2014-12-20 04:14:33 -07:00
|
|
|
#include "Common/Profiler.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Common/Timer.h"
|
|
|
|
|
2014-10-12 21:53:10 -06:00
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
2014-12-20 04:14:33 -07:00
|
|
|
#include "Core/Movie.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/FifoPlayer/FifoRecorder.h"
|
|
|
|
|
2015-07-20 18:12:29 -06:00
|
|
|
#include "Core/HW/VideoInterface.h"
|
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/AVIDump.h"
|
|
|
|
#include "VideoCommon/BPMemory.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
|
|
#include "VideoCommon/Debugger.h"
|
2014-07-09 15:18:11 -06:00
|
|
|
#include "VideoCommon/FPSCounter.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/FramebufferManagerBase.h"
|
2015-12-22 16:47:20 -07:00
|
|
|
#include "VideoCommon/PostProcessing.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
#include "VideoCommon/Statistics.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/XFMemory.h"
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
// TODO: Move these out of here.
|
|
|
|
int frameCount;
|
2014-07-08 07:58:25 -06:00
|
|
|
int OSDChoice;
|
|
|
|
static int OSDTime;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2015-12-20 19:49:49 -07:00
|
|
|
std::unique_ptr<Renderer> g_renderer;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2011-03-04 23:11:26 -07:00
|
|
|
std::mutex Renderer::s_criticalScreenshot;
|
2010-11-17 19:21:26 -07:00
|
|
|
std::string Renderer::s_sScreenshotName;
|
|
|
|
|
2015-06-18 19:28:40 -06:00
|
|
|
Common::Event Renderer::s_screenshotCompleted;
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
volatile bool Renderer::s_bScreenshot;
|
|
|
|
|
|
|
|
// The framebuffer size
|
2013-01-16 13:46:11 -07:00
|
|
|
int Renderer::s_target_width;
|
|
|
|
int Renderer::s_target_height;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
|
|
|
// TODO: Add functionality to reinit all the render targets when the window is resized.
|
2013-01-16 13:46:11 -07:00
|
|
|
int Renderer::s_backbuffer_width;
|
|
|
|
int Renderer::s_backbuffer_height;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2015-12-22 16:47:20 -07:00
|
|
|
std::unique_ptr<PostProcessingShaderImplementation> Renderer::m_post_processor;
|
2014-07-29 10:47:56 -06:00
|
|
|
|
2012-09-28 16:04:55 -06:00
|
|
|
TargetRectangle Renderer::target_rc;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-28 10:35:23 -07:00
|
|
|
int Renderer::s_last_efb_scale;
|
2010-11-17 19:21:26 -07:00
|
|
|
|
|
|
|
bool Renderer::XFBWrited;
|
|
|
|
|
2014-03-27 21:52:27 -06:00
|
|
|
PEControl::PixelFormat Renderer::prev_efb_format = PEControl::INVALID_FMT;
|
2012-10-02 14:11:15 -06:00
|
|
|
unsigned int Renderer::efb_scale_numeratorX = 1;
|
|
|
|
unsigned int Renderer::efb_scale_numeratorY = 1;
|
|
|
|
unsigned int Renderer::efb_scale_denominatorX = 1;
|
|
|
|
unsigned int Renderer::efb_scale_denominatorY = 1;
|
2010-12-27 14:56:20 -07:00
|
|
|
|
2016-01-07 17:31:48 -07:00
|
|
|
static float AspectToWidescreen(float aspect) { return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f)); }
|
2012-05-28 03:31:37 -06:00
|
|
|
|
2013-02-26 18:47:48 -07:00
|
|
|
Renderer::Renderer()
|
|
|
|
: frame_data()
|
|
|
|
, bLastFrameDumped(false)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
|
|
|
UpdateActiveConfig();
|
2015-11-05 17:28:05 -07:00
|
|
|
TextureCacheBase::OnConfigChanged(g_ActiveConfig);
|
2015-01-25 18:35:29 -07:00
|
|
|
|
2011-09-08 09:09:24 -06:00
|
|
|
#if defined _WIN32 || defined HAVE_LIBAV
|
|
|
|
bAVIDumping = false;
|
|
|
|
#endif
|
2012-12-31 08:21:23 -07:00
|
|
|
|
|
|
|
OSDChoice = 0;
|
|
|
|
OSDTime = 0;
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::~Renderer()
|
|
|
|
{
|
2010-12-27 14:56:20 -07:00
|
|
|
// invalidate previous efb format
|
2014-03-27 21:52:27 -06:00
|
|
|
prev_efb_format = PEControl::INVALID_FMT;
|
2011-09-08 09:09:24 -06:00
|
|
|
|
2013-10-29 11:20:07 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = efb_scale_denominatorX = efb_scale_denominatorY = 1;
|
2011-09-08 09:09:24 -06:00
|
|
|
#if defined _WIN32 || defined HAVE_LIBAV
|
2014-10-12 21:53:10 -06:00
|
|
|
if (SConfig::GetInstance().m_DumpFrames && bLastFrameDumped && bAVIDumping)
|
2011-09-08 09:09:24 -06:00
|
|
|
AVIDump::Stop();
|
|
|
|
#endif
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
2015-07-07 07:09:25 -06:00
|
|
|
void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbStride, u32 fbHeight, float Gamma)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-03-26 20:55:08 -06:00
|
|
|
CheckFifoRecording();
|
|
|
|
|
2015-07-07 07:09:25 -06:00
|
|
|
if (!fbStride || !fbHeight)
|
2010-11-17 19:21:26 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
XFBWrited = true;
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bUseXFB)
|
|
|
|
{
|
2015-07-07 07:09:25 -06:00
|
|
|
FramebufferManagerBase::CopyToXFB(xfbAddr, fbStride, fbHeight, sourceRc, Gamma);
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-25 10:59:00 -06:00
|
|
|
// below div two to convert from bytes to pixels - it expects width, not stride
|
|
|
|
Swap(xfbAddr, fbStride/2, fbStride/2, fbHeight, sourceRc, Gamma);
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 14:11:15 -06:00
|
|
|
int Renderer::EFBToScaledX(int x)
|
2011-01-06 21:57:59 -07:00
|
|
|
{
|
|
|
|
switch (g_ActiveConfig.iEFBScale)
|
|
|
|
{
|
2014-11-13 15:26:49 -07:00
|
|
|
case SCALE_AUTO: // fractional
|
2014-12-24 16:58:16 -07:00
|
|
|
return FramebufferManagerBase::ScaleToVirtualXfbWidth(x);
|
2012-10-02 14:11:15 -06:00
|
|
|
|
|
|
|
default:
|
2013-10-29 11:20:07 -06:00
|
|
|
return x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX;
|
2012-10-02 14:11:15 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::EFBToScaledY(int y)
|
2011-01-06 21:57:59 -07:00
|
|
|
{
|
|
|
|
switch (g_ActiveConfig.iEFBScale)
|
|
|
|
{
|
2013-04-05 23:48:00 -06:00
|
|
|
case SCALE_AUTO: // fractional
|
2014-12-24 16:58:16 -07:00
|
|
|
return FramebufferManagerBase::ScaleToVirtualXfbHeight(y);
|
2012-10-02 14:11:15 -06:00
|
|
|
|
|
|
|
default:
|
2013-10-29 11:20:07 -06:00
|
|
|
return y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY;
|
2012-10-02 14:11:15 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-10-02 00:20:46 -06:00
|
|
|
void Renderer::CalculateTargetScale(int x, int y, int* scaledX, int* scaledY)
|
2012-10-02 14:11:15 -06:00
|
|
|
{
|
2013-04-05 23:48:00 -06:00
|
|
|
if (g_ActiveConfig.iEFBScale == SCALE_AUTO || g_ActiveConfig.iEFBScale == SCALE_AUTO_INTEGRAL)
|
2012-10-02 14:11:15 -06:00
|
|
|
{
|
2014-10-02 00:20:46 -06:00
|
|
|
*scaledX = x;
|
|
|
|
*scaledY = y;
|
2012-10-02 14:11:15 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-02 00:20:46 -06:00
|
|
|
*scaledX = x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX;
|
|
|
|
*scaledY = y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY;
|
2012-10-02 14:11:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if target size changed
|
2013-10-29 11:20:07 -06:00
|
|
|
bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height)
|
2012-10-02 14:11:15 -06:00
|
|
|
{
|
2013-01-16 13:46:11 -07:00
|
|
|
int newEFBWidth, newEFBHeight;
|
2014-09-30 09:43:53 -06:00
|
|
|
newEFBWidth = newEFBHeight = 0;
|
2012-10-02 14:11:15 -06:00
|
|
|
|
|
|
|
// TODO: Ugly. Clean up
|
2014-12-28 10:35:23 -07:00
|
|
|
switch (s_last_efb_scale)
|
2012-10-02 14:11:15 -06:00
|
|
|
{
|
2014-09-25 17:50:25 -06:00
|
|
|
case SCALE_AUTO:
|
|
|
|
case SCALE_AUTO_INTEGRAL:
|
2014-12-24 16:58:16 -07:00
|
|
|
newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH);
|
|
|
|
newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT);
|
2014-09-25 17:50:25 -06:00
|
|
|
|
2014-12-28 10:35:23 -07:00
|
|
|
if (s_last_efb_scale == SCALE_AUTO_INTEGRAL)
|
2014-09-25 17:50:25 -06:00
|
|
|
{
|
|
|
|
newEFBWidth = ((newEFBWidth-1) / EFB_WIDTH + 1) * EFB_WIDTH;
|
|
|
|
newEFBHeight = ((newEFBHeight-1) / EFB_HEIGHT + 1) * EFB_HEIGHT;
|
|
|
|
}
|
|
|
|
efb_scale_numeratorX = newEFBWidth;
|
|
|
|
efb_scale_denominatorX = EFB_WIDTH;
|
|
|
|
efb_scale_numeratorY = newEFBHeight;
|
|
|
|
efb_scale_denominatorY = EFB_HEIGHT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCALE_1X:
|
2012-10-02 14:11:15 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = 1;
|
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 1;
|
|
|
|
break;
|
|
|
|
|
2014-09-25 17:50:25 -06:00
|
|
|
case SCALE_1_5X:
|
2012-10-02 14:11:15 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = 3;
|
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 2;
|
2011-07-04 19:11:03 -06:00
|
|
|
break;
|
2012-10-02 14:11:15 -06:00
|
|
|
|
2014-09-25 17:50:25 -06:00
|
|
|
case SCALE_2X:
|
2012-10-02 14:11:15 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = 2;
|
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 1;
|
2011-01-06 21:57:59 -07:00
|
|
|
break;
|
2012-10-02 14:11:15 -06:00
|
|
|
|
2014-09-25 17:50:25 -06:00
|
|
|
case SCALE_2_5X:
|
2012-10-02 14:11:15 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = 5;
|
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 2;
|
2011-07-04 19:11:03 -06:00
|
|
|
break;
|
2012-10-02 14:11:15 -06:00
|
|
|
|
2014-09-25 17:50:25 -06:00
|
|
|
default:
|
2014-12-28 10:35:23 -07:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = s_last_efb_scale - 3;
|
2012-10-02 14:11:15 -06:00
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 1;
|
2011-01-06 21:57:59 -07:00
|
|
|
|
2012-09-28 16:19:28 -06:00
|
|
|
|
2014-09-25 17:50:25 -06:00
|
|
|
int maxSize;
|
|
|
|
maxSize = GetMaxTextureSize();
|
|
|
|
if ((unsigned)maxSize < EFB_WIDTH * efb_scale_numeratorX / efb_scale_denominatorX)
|
2012-09-28 16:19:28 -06:00
|
|
|
{
|
2014-09-25 17:50:25 -06:00
|
|
|
efb_scale_numeratorX = efb_scale_numeratorY = (maxSize / EFB_WIDTH);
|
|
|
|
efb_scale_denominatorX = efb_scale_denominatorY = 1;
|
2012-09-28 16:19:28 -06:00
|
|
|
}
|
|
|
|
|
2011-07-04 19:11:03 -06:00
|
|
|
break;
|
2011-01-06 21:57:59 -07:00
|
|
|
}
|
2014-12-28 10:35:23 -07:00
|
|
|
if (s_last_efb_scale > SCALE_AUTO_INTEGRAL)
|
2014-10-02 00:20:46 -06:00
|
|
|
CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT, &newEFBWidth, &newEFBHeight);
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2010-12-10 08:54:14 -07:00
|
|
|
if (newEFBWidth != s_target_width || newEFBHeight != s_target_height)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-05-11 20:14:45 -06:00
|
|
|
s_target_width = newEFBWidth;
|
|
|
|
s_target_height = newEFBHeight;
|
2010-11-17 19:21:26 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-31 09:24:35 -06:00
|
|
|
void Renderer::ConvertStereoRectangle(const TargetRectangle& rc, TargetRectangle& leftRc, TargetRectangle& rightRc)
|
|
|
|
{
|
|
|
|
// Resize target to half its original size
|
|
|
|
TargetRectangle drawRc = rc;
|
|
|
|
if (g_ActiveConfig.iStereoMode == STEREO_TAB)
|
|
|
|
{
|
|
|
|
// The height may be negative due to flipped rectangles
|
|
|
|
int height = rc.bottom - rc.top;
|
|
|
|
drawRc.top += height / 4;
|
|
|
|
drawRc.bottom -= height / 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int width = rc.right - rc.left;
|
|
|
|
drawRc.left += width / 4;
|
|
|
|
drawRc.right -= width / 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create two target rectangle offset to the sides of the backbuffer
|
|
|
|
leftRc = drawRc, rightRc = drawRc;
|
|
|
|
if (g_ActiveConfig.iStereoMode == STEREO_TAB)
|
|
|
|
{
|
|
|
|
leftRc.top -= s_backbuffer_height / 4;
|
|
|
|
leftRc.bottom -= s_backbuffer_height / 4;
|
|
|
|
rightRc.top += s_backbuffer_height / 4;
|
|
|
|
rightRc.bottom += s_backbuffer_height / 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leftRc.left -= s_backbuffer_width / 4;
|
|
|
|
leftRc.right -= s_backbuffer_width / 4;
|
|
|
|
rightRc.left += s_backbuffer_width / 4;
|
|
|
|
rightRc.right += s_backbuffer_width / 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
void Renderer::SetScreenshot(const std::string& filename)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2011-03-04 23:11:26 -07:00
|
|
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
2010-12-10 08:54:14 -07:00
|
|
|
s_sScreenshotName = filename;
|
|
|
|
s_bScreenshot = true;
|
2010-11-17 19:21:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create On-Screen-Messages
|
|
|
|
void Renderer::DrawDebugText()
|
|
|
|
{
|
2014-12-20 05:02:00 -07:00
|
|
|
std::string final_yellow, final_cyan;
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bShowFPS || SConfig::GetInstance().m_ShowFrameCount)
|
2010-11-17 19:21:26 -07:00
|
|
|
{
|
2014-12-20 05:02:00 -07:00
|
|
|
if (g_ActiveConfig.bShowFPS)
|
2015-09-29 07:43:03 -06:00
|
|
|
final_cyan += StringFromFormat("FPS: %u", g_renderer->m_fps_counter.GetFPS());
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
if (g_ActiveConfig.bShowFPS && SConfig::GetInstance().m_ShowFrameCount)
|
|
|
|
final_cyan += " - ";
|
|
|
|
if (SConfig::GetInstance().m_ShowFrameCount)
|
|
|
|
{
|
|
|
|
final_cyan += StringFromFormat("Frame: %llu", (unsigned long long) Movie::g_currentFrame);
|
|
|
|
if (Movie::IsPlayingInput())
|
|
|
|
final_cyan += StringFromFormat(" / %llu", (unsigned long long) Movie::g_totalFrames);
|
|
|
|
}
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
final_cyan += "\n";
|
|
|
|
final_yellow += "\n";
|
2012-12-31 08:21:23 -07:00
|
|
|
}
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
if (SConfig::GetInstance().m_ShowLag)
|
2012-12-31 08:21:23 -07:00
|
|
|
{
|
2015-09-07 23:44:37 -06:00
|
|
|
final_cyan += StringFromFormat("Lag: %" PRIu64 "\n", Movie::g_currentLagCount);
|
2014-12-20 05:02:00 -07:00
|
|
|
final_yellow += "\n";
|
2012-12-31 08:21:23 -07:00
|
|
|
}
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
if (SConfig::GetInstance().m_ShowInputDisplay)
|
2012-12-31 08:21:23 -07:00
|
|
|
{
|
2014-12-20 05:02:00 -07:00
|
|
|
final_cyan += Movie::GetInputDisplay();
|
|
|
|
final_yellow += "\n";
|
2012-12-31 08:21:23 -07:00
|
|
|
}
|
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
// OSD Menu messages
|
|
|
|
if (OSDChoice > 0)
|
2012-12-31 08:21:23 -07:00
|
|
|
{
|
2014-12-20 05:02:00 -07:00
|
|
|
OSDTime = Common::Timer::GetTimeMs() + 3000;
|
|
|
|
OSDChoice = -OSDChoice;
|
2012-12-31 08:21:23 -07:00
|
|
|
}
|
2010-11-17 19:21:26 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
if ((u32)OSDTime > Common::Timer::GetTimeMs())
|
2012-12-31 08:21:23 -07:00
|
|
|
{
|
2015-02-08 19:27:53 -07:00
|
|
|
std::string res_text;
|
2014-12-20 05:02:00 -07:00
|
|
|
switch (g_ActiveConfig.iEFBScale)
|
|
|
|
{
|
|
|
|
case SCALE_AUTO:
|
|
|
|
res_text = "Auto (fractional)";
|
|
|
|
break;
|
|
|
|
case SCALE_AUTO_INTEGRAL:
|
|
|
|
res_text = "Auto (integral)";
|
|
|
|
break;
|
|
|
|
case SCALE_1X:
|
|
|
|
res_text = "Native";
|
|
|
|
break;
|
|
|
|
case SCALE_1_5X:
|
|
|
|
res_text = "1.5x";
|
|
|
|
break;
|
|
|
|
case SCALE_2X:
|
|
|
|
res_text = "2x";
|
|
|
|
break;
|
|
|
|
case SCALE_2_5X:
|
|
|
|
res_text = "2.5x";
|
|
|
|
break;
|
2015-02-08 19:27:53 -07:00
|
|
|
default:
|
|
|
|
res_text = StringFromFormat("%dx", g_ActiveConfig.iEFBScale - 3);
|
2014-12-20 05:02:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char* ar_text = "";
|
|
|
|
switch (g_ActiveConfig.iAspectRatio)
|
2014-12-20 04:14:33 -07:00
|
|
|
{
|
2014-12-20 05:02:00 -07:00
|
|
|
case ASPECT_AUTO:
|
|
|
|
ar_text = "Auto";
|
|
|
|
break;
|
|
|
|
case ASPECT_STRETCH:
|
|
|
|
ar_text = "Stretch";
|
|
|
|
break;
|
2015-07-20 18:12:29 -06:00
|
|
|
case ASPECT_ANALOG:
|
|
|
|
ar_text = "Force 4:3";
|
|
|
|
break;
|
|
|
|
case ASPECT_ANALOG_WIDE:
|
|
|
|
ar_text = "Force 16:9";
|
2014-12-20 04:14:33 -07:00
|
|
|
}
|
|
|
|
|
2015-02-21 04:08:47 -07:00
|
|
|
const char* const efbcopy_text = g_ActiveConfig.bSkipEFBCopyToRam ? "to Texture" : "to RAM";
|
2014-12-20 04:14:33 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
// The rows
|
|
|
|
const std::string lines[] =
|
|
|
|
{
|
|
|
|
std::string("Internal Resolution: ") + res_text,
|
|
|
|
std::string("Aspect Ratio: ") + ar_text + (g_ActiveConfig.bCrop ? " (crop)" : ""),
|
|
|
|
std::string("Copy EFB: ") + efbcopy_text,
|
|
|
|
std::string("Fog: ") + (g_ActiveConfig.bDisableFog ? "Disabled" : "Enabled"),
|
2015-12-15 16:10:47 -07:00
|
|
|
SConfig::GetInstance().m_EmulationSpeed <= 0 ? "Speed Limit: Unlimited" :
|
|
|
|
StringFromFormat("Speed Limit: %li%%", std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)),
|
2014-12-20 05:02:00 -07:00
|
|
|
};
|
2014-12-20 04:14:33 -07:00
|
|
|
|
2015-02-15 12:43:31 -07:00
|
|
|
enum { lines_count = sizeof(lines) / sizeof(*lines) };
|
2014-12-20 04:14:33 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
// The latest changed setting in yellow
|
|
|
|
for (int i = 0; i != lines_count; ++i)
|
|
|
|
{
|
|
|
|
if (OSDChoice == -i - 1)
|
|
|
|
final_yellow += lines[i];
|
|
|
|
final_yellow += '\n';
|
|
|
|
}
|
2014-12-20 04:14:33 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
// The other settings in cyan
|
|
|
|
for (int i = 0; i != lines_count; ++i)
|
|
|
|
{
|
|
|
|
if (OSDChoice != -i - 1)
|
|
|
|
final_cyan += lines[i];
|
|
|
|
final_cyan += '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 03:41:49 -06:00
|
|
|
final_cyan += Common::Profiler::ToString();
|
2014-12-20 04:14:33 -07:00
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayStats)
|
2014-12-20 05:02:00 -07:00
|
|
|
final_cyan += Statistics::ToString();
|
2014-12-20 04:14:33 -07:00
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayProjStats)
|
2014-12-20 05:02:00 -07:00
|
|
|
final_cyan += Statistics::ToStringProj();
|
2014-12-20 04:14:33 -07:00
|
|
|
|
2014-12-20 05:02:00 -07:00
|
|
|
//and then the text
|
|
|
|
g_renderer->RenderText(final_cyan, 20, 20, 0xFF00FFFF);
|
|
|
|
g_renderer->RenderText(final_yellow, 20, 20, 0xFFFFFF00);
|
2014-12-20 04:14:33 -07:00
|
|
|
}
|
|
|
|
|
2013-01-16 13:46:11 -07:00
|
|
|
void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height)
|
2010-11-17 20:50:50 -07:00
|
|
|
{
|
2012-09-28 16:04:55 -06:00
|
|
|
float FloatGLWidth = (float)backbuffer_width;
|
|
|
|
float FloatGLHeight = (float)backbuffer_height;
|
|
|
|
float FloatXOffset = 0;
|
|
|
|
float FloatYOffset = 0;
|
|
|
|
|
|
|
|
// The rendering window size
|
|
|
|
const float WinWidth = FloatGLWidth;
|
|
|
|
const float WinHeight = FloatGLHeight;
|
|
|
|
|
|
|
|
// Update aspect ratio hack values
|
|
|
|
// Won't take effect until next frame
|
|
|
|
// Don't know if there is a better place for this code so there isn't a 1 frame delay
|
2015-02-15 12:43:31 -07:00
|
|
|
if (g_ActiveConfig.bWidescreenHack)
|
2010-11-17 20:50:50 -07:00
|
|
|
{
|
2016-01-07 17:31:48 -07:00
|
|
|
float source_aspect = VideoInterface::GetAspectRatio();
|
|
|
|
if (Core::g_aspect_wide)
|
|
|
|
source_aspect = AspectToWidescreen(source_aspect);
|
2012-09-28 16:04:55 -06:00
|
|
|
float target_aspect;
|
|
|
|
|
2015-02-15 12:43:31 -07:00
|
|
|
switch (g_ActiveConfig.iAspectRatio)
|
2012-09-28 16:04:55 -06:00
|
|
|
{
|
2015-02-15 12:43:31 -07:00
|
|
|
case ASPECT_STRETCH:
|
2012-09-28 16:04:55 -06:00
|
|
|
target_aspect = WinWidth / WinHeight;
|
|
|
|
break;
|
2015-07-20 18:12:29 -06:00
|
|
|
case ASPECT_ANALOG:
|
2016-01-07 17:31:48 -07:00
|
|
|
target_aspect = VideoInterface::GetAspectRatio();
|
2015-07-20 18:12:29 -06:00
|
|
|
break;
|
|
|
|
case ASPECT_ANALOG_WIDE:
|
2016-01-07 17:31:48 -07:00
|
|
|
target_aspect = AspectToWidescreen(VideoInterface::GetAspectRatio());
|
2015-07-20 18:12:29 -06:00
|
|
|
break;
|
2015-02-15 12:43:31 -07:00
|
|
|
default:
|
2015-07-20 18:12:29 -06:00
|
|
|
// ASPECT_AUTO
|
2012-09-28 16:04:55 -06:00
|
|
|
target_aspect = source_aspect;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float adjust = source_aspect / target_aspect;
|
2015-02-15 12:43:31 -07:00
|
|
|
if (adjust > 1)
|
2012-09-28 16:04:55 -06:00
|
|
|
{
|
|
|
|
// Vert+
|
|
|
|
g_Config.fAspectRatioHackW = 1;
|
2015-02-15 12:43:31 -07:00
|
|
|
g_Config.fAspectRatioHackH = 1 / adjust;
|
2012-09-28 16:04:55 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Hor+
|
|
|
|
g_Config.fAspectRatioHackW = adjust;
|
|
|
|
g_Config.fAspectRatioHackH = 1;
|
|
|
|
}
|
2010-11-17 20:50:50 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-28 16:04:55 -06:00
|
|
|
// Hack is disabled
|
|
|
|
g_Config.fAspectRatioHackW = 1;
|
|
|
|
g_Config.fAspectRatioHackH = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for force-settings and override.
|
|
|
|
|
2015-07-20 18:12:29 -06:00
|
|
|
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
|
|
|
|
float Ratio;
|
2016-01-07 17:31:48 -07:00
|
|
|
if (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE || (g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && Core::g_aspect_wide))
|
2015-07-29 19:48:08 -06:00
|
|
|
{
|
2016-01-07 17:31:48 -07:00
|
|
|
Ratio = (WinWidth / WinHeight) / AspectToWidescreen(VideoInterface::GetAspectRatio());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio();
|
2015-07-20 18:12:29 -06:00
|
|
|
}
|
2015-07-29 19:48:08 -06:00
|
|
|
|
2012-09-28 16:04:55 -06:00
|
|
|
if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH)
|
|
|
|
{
|
|
|
|
if (Ratio > 1.0f)
|
2010-11-17 20:50:50 -07:00
|
|
|
{
|
2012-09-28 16:04:55 -06:00
|
|
|
// Scale down and center in the X direction.
|
|
|
|
FloatGLWidth /= Ratio;
|
|
|
|
FloatXOffset = (WinWidth - FloatGLWidth) / 2.0f;
|
2010-11-17 20:50:50 -07:00
|
|
|
}
|
2012-09-28 16:04:55 -06:00
|
|
|
// The window is too high, we have to limit the height
|
2010-11-17 20:50:50 -07:00
|
|
|
else
|
|
|
|
{
|
2012-09-28 16:04:55 -06:00
|
|
|
// Scale down and center in the Y direction.
|
|
|
|
FloatGLHeight *= Ratio;
|
|
|
|
FloatYOffset = FloatYOffset + (WinHeight - FloatGLHeight) / 2.0f;
|
2010-11-17 20:50:50 -07:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 16:04:55 -06:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
2015-07-20 18:12:29 -06:00
|
|
|
// Crop the picture from Analog to 4:3 or from Analog (Wide) to 16:9.
|
2014-02-16 21:51:41 -07:00
|
|
|
// Output: FloatGLWidth, FloatGLHeight, FloatXOffset, FloatYOffset
|
2012-09-28 16:04:55 -06:00
|
|
|
// ------------------
|
|
|
|
if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH && g_ActiveConfig.bCrop)
|
|
|
|
{
|
2016-01-07 17:31:48 -07:00
|
|
|
Ratio = (4.0f / 3.0f) / VideoInterface::GetAspectRatio();
|
2015-07-20 18:12:29 -06:00
|
|
|
if (Ratio <= 1.0f)
|
|
|
|
{
|
|
|
|
Ratio = 1.0f / Ratio;
|
|
|
|
}
|
2012-09-28 16:04:55 -06:00
|
|
|
// The width and height we will add (calculate this before FloatGLWidth and FloatGLHeight is adjusted)
|
|
|
|
float IncreasedWidth = (Ratio - 1.0f) * FloatGLWidth;
|
|
|
|
float IncreasedHeight = (Ratio - 1.0f) * FloatGLHeight;
|
|
|
|
// The new width and height
|
|
|
|
FloatGLWidth = FloatGLWidth * Ratio;
|
|
|
|
FloatGLHeight = FloatGLHeight * Ratio;
|
|
|
|
// Adjust the X and Y offset
|
|
|
|
FloatXOffset = FloatXOffset - (IncreasedWidth * 0.5f);
|
|
|
|
FloatYOffset = FloatYOffset - (IncreasedHeight * 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int XOffset = (int)(FloatXOffset + 0.5f);
|
|
|
|
int YOffset = (int)(FloatYOffset + 0.5f);
|
|
|
|
int iWhidth = (int)ceil(FloatGLWidth);
|
|
|
|
int iHeight = (int)ceil(FloatGLHeight);
|
|
|
|
iWhidth -= iWhidth % 4; // ensure divisibility by 4 to make it compatible with all the video encoders
|
|
|
|
iHeight -= iHeight % 4;
|
|
|
|
|
|
|
|
target_rc.left = XOffset;
|
|
|
|
target_rc.top = YOffset;
|
|
|
|
target_rc.right = XOffset + iWhidth;
|
|
|
|
target_rc.bottom = YOffset + iHeight;
|
2010-11-17 20:50:50 -07:00
|
|
|
}
|
|
|
|
|
2013-01-16 13:46:11 -07:00
|
|
|
void Renderer::SetWindowSize(int width, int height)
|
2011-03-15 17:09:12 -06:00
|
|
|
{
|
|
|
|
if (width < 1)
|
|
|
|
width = 1;
|
|
|
|
if (height < 1)
|
|
|
|
height = 1;
|
|
|
|
|
|
|
|
// Scale the window size by the EFB scale.
|
2014-10-02 00:20:46 -06:00
|
|
|
CalculateTargetScale(width, height, &width, &height);
|
2011-03-15 17:09:12 -06:00
|
|
|
|
|
|
|
Host_RequestRenderWindowSize(width, height);
|
|
|
|
}
|
|
|
|
|
2011-03-26 20:55:08 -06:00
|
|
|
void Renderer::CheckFifoRecording()
|
|
|
|
{
|
|
|
|
bool wasRecording = g_bRecordFifoData;
|
|
|
|
g_bRecordFifoData = FifoRecorder::GetInstance().IsRecording();
|
|
|
|
|
|
|
|
if (g_bRecordFifoData)
|
|
|
|
{
|
|
|
|
if (!wasRecording)
|
|
|
|
{
|
|
|
|
RecordVideoMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
FifoRecorder::GetInstance().EndFrame(CommandProcessor::fifo.CPBase, CommandProcessor::fifo.CPEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RecordVideoMemory()
|
|
|
|
{
|
2014-05-16 19:40:06 -06:00
|
|
|
u32 *bpmem_ptr = (u32*)&bpmem;
|
|
|
|
u32 cpmem[256];
|
|
|
|
// The FIFO recording format splits XF memory into xfmem and xfregs; follow
|
|
|
|
// that split here.
|
|
|
|
u32 *xfmem_ptr = (u32*)&xfmem;
|
|
|
|
u32 *xfregs_ptr = (u32*)&xfmem + FifoDataFile::XF_MEM_SIZE;
|
|
|
|
u32 xfregs_size = sizeof(XFMemory) / 4 - FifoDataFile::XF_MEM_SIZE;
|
|
|
|
|
|
|
|
memset(cpmem, 0, 256 * 4);
|
|
|
|
FillCPMemoryArray(cpmem);
|
|
|
|
|
|
|
|
FifoRecorder::GetInstance().SetVideoMemory(bpmem_ptr, cpmem, xfmem_ptr, xfregs_ptr, xfregs_size);
|
2011-03-26 20:55:08 -06:00
|
|
|
}
|
|
|
|
|
2014-05-02 01:08:44 -06:00
|
|
|
void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma)
|
2014-02-05 03:48:45 -07:00
|
|
|
{
|
|
|
|
// TODO: merge more generic parts into VideoCommon
|
2014-05-02 01:08:44 -06:00
|
|
|
g_renderer->SwapImpl(xfbAddr, fbWidth, fbStride, fbHeight, rc, Gamma);
|
2014-02-05 03:48:45 -07:00
|
|
|
|
2014-07-09 15:18:11 -06:00
|
|
|
if (XFBWrited)
|
2014-07-13 05:04:25 -06:00
|
|
|
g_renderer->m_fps_counter.Update();
|
2014-07-09 15:18:11 -06:00
|
|
|
|
2014-02-05 03:48:45 -07:00
|
|
|
frameCount++;
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true);
|
|
|
|
|
|
|
|
// Begin new frame
|
|
|
|
// Set default viewport and scissor, for the clear to work correctly
|
|
|
|
// New frame
|
|
|
|
stats.ResetFrame();
|
|
|
|
|
|
|
|
Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
|
|
|
|
XFBWrited = false;
|
|
|
|
}
|
2015-05-01 10:58:11 -06:00
|
|
|
|
2016-01-02 11:07:08 -07:00
|
|
|
void Renderer::FlipImageData(u8* data, int w, int h, int pixel_width)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < h / 2; ++y)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < w; ++x)
|
|
|
|
{
|
|
|
|
for (int delta = 0; delta < pixel_width; ++delta)
|
|
|
|
std::swap(data[(y * w + x) * pixel_width + delta], data[((h - 1 - y) * w + x) * pixel_width + delta]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|