Move some shared gfx plugin code into VideoCommon. Changed "Renderer" class to use virtual functions. (setting stuff up for video plugin merging)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6433 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2010-11-18 02:21:26 +00:00
parent 054358380e
commit 159ed43f67
45 changed files with 1180 additions and 1959 deletions

View File

@ -733,10 +733,6 @@
<Filter
Name="Render"
>
<File
RelativePath=".\Src\BPFunctions.cpp"
>
</File>
<File
RelativePath=".\Src\FramebufferManager.cpp"
>
@ -765,6 +761,10 @@
RelativePath=".\Src\Render.cpp"
>
</File>
<File
RelativePath=".\Src\Render.h"
>
</File>
<File
RelativePath=".\Src\TextureCache.cpp"
>

View File

@ -1,140 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "BPFunctions.h"
#include "Globals.h"
#include "Profiler.h"
#include "VideoConfig.h"
#include "VertexManager.h"
#include "Render.h"
#include "TextureCache.h"
#include "TextureConverter.h"
#include "VertexShaderManager.h"
#include "main.h"
namespace BPFunctions
{
// ----------------------------------------------
// State translation lookup tables
// Reference: Yet Another Gamecube Documentation
// ----------------------------------------------
void FlushPipeline()
{
VertexManager::Flush();
}
void SetGenerationMode(const BPCmd &bp)
{
Renderer::SetGenerationMode();
}
void SetScissor(const BPCmd &bp)
{
Renderer::SetScissorRect();
}
void SetLineWidth(const BPCmd &bp)
{
Renderer::SetLineWidth();
}
void SetDepthMode(const BPCmd &bp)
{
Renderer::SetDepthMode();
}
void SetBlendMode(const BPCmd &bp)
{
Renderer::SetBlendMode(false);
}
void SetDitherMode(const BPCmd &bp)
{
Renderer::SetDitherMode();
}
void SetLogicOpMode(const BPCmd &bp)
{
Renderer::SetLogicOpMode();
}
void SetColorMask(const BPCmd &bp)
{
Renderer::SetColorMask();
}
void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 &copyfmt, const int &scaleByHalf)
{
// bpmem.zcontrol.pixel_format to PIXELFMT_Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
if (!g_ActiveConfig.bEFBCopyDisable)
{
TextureCache::CopyRenderTargetToTexture(address, fromZBuffer, isIntensityFmt, copyfmt, !!scaleByHalf, rc);
}
}
void ClearScreen(const BPCmd &bp, const EFBRectangle &rc)
{
bool colorEnable = bpmem.blendmode.colorupdate;
bool alphaEnable = (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24 && bpmem.blendmode.alphaupdate);
bool zEnable = bpmem.zmode.updateenable;
if (colorEnable || alphaEnable || zEnable)
{
u32 color = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
u32 z = bpmem.clearZValue;
Renderer::ClearScreen(rc, colorEnable, alphaEnable, zEnable, color, z);
}
}
void RestoreRenderState(const BPCmd &bp)
{
Renderer::RestoreAPIState();
}
bool GetConfig(const int &type)
{
switch (type)
{
case CONFIG_ISWII:
return g_VideoInitialize.bWii;
case CONFIG_DISABLEFOG:
return g_ActiveConfig.bDisableFog;
case CONFIG_SHOWEFBREGIONS:
return g_ActiveConfig.bShowEFBCopyRegions;
default:
PanicAlert("GetConfig Error: Unknown Config Type!");
return false;
}
}
u8 *GetPointer(const u32 &address)
{
return g_VideoInitialize.pGetMemoryPointer(address);
}
void SetTextureMode(const BPCmd &bp)
{
// TODO
}
void SetInterlacingMode(const BPCmd &bp)
{
// TODO
}
};

View File

@ -211,7 +211,7 @@ GLuint FramebufferManager::GetEFBColorTexture(const EFBRectangle& sourceRc)
// Transfer the EFB to a resolved texture. EXT_framebuffer_blit is
// required.
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(sourceRc);
TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
targetRc.ClampLL(0, 0, m_targetWidth, m_targetHeight);
// Resolve.
@ -241,7 +241,7 @@ GLuint FramebufferManager::GetEFBDepthTexture(const EFBRectangle& sourceRc)
// Transfer the EFB to a resolved texture. EXT_framebuffer_blit is
// required.
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(sourceRc);
TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
targetRc.ClampLL(0, 0, m_targetWidth, m_targetHeight);
// Resolve.
@ -269,7 +269,7 @@ void FramebufferManager::CopyToRealXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, c
return;
}
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(sourceRc);
TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
TextureConverter::EncodeToRamYUYV(ResolveAndGetRenderTarget(sourceRc), targetRc, xfb_in_ram, fbWidth, fbHeight);
}

View File

@ -82,7 +82,6 @@ CGprofile g_cgfProf;
RasterFont* s_pfont = NULL;
static bool s_bLastFrameDumped = false;
#if defined _WIN32 || defined HAVE_AVCODEC
static bool s_bAVIDumping = false;
#else
@ -96,40 +95,10 @@ static int s_MSAACoverageSamples = 0;
bool s_bHaveFramebufferBlit = false; // export to FramebufferManager.cpp
static bool s_bHaveCoverageMSAA = false;
static u32 s_blendMode;
static int s_LastEFBScale;
static volatile bool s_bScreenshot = false;
#if defined(HAVE_WX) && HAVE_WX
static Common::Thread *scrshotThread = 0;
#endif
static Common::CriticalSection s_criticalScreenshot;
static std::string s_sScreenshotName;
int frameCount;
// The custom resolution
static int s_Fulltarget_width;
static int s_Fulltarget_height;
// TODO: Add functionality to reinit all the render targets when the window is resized.
static int s_backbuffer_width;
static int s_backbuffer_height;
// The framebuffer size
static int s_target_width;
static int s_target_height;
static unsigned int s_XFB_width;
static unsigned int s_XFB_height;
static float xScale;
static float yScale;
static float EFBxScale;
static float EFByScale;
static bool s_skipSwap = false;
static bool XFBWrited = false;
int OSDChoice = 0 , OSDTime = 0, OSDInternalW = 0, OSDInternalH = 0;
@ -215,10 +184,12 @@ void VideoConfig::UpdateProjectionHack()
::UpdateProjectionHack(g_Config.iPhackvalue);
}
// Init functions
bool Renderer::Init()
namespace OGL
{
// Init functions
Renderer::Renderer()
{
UpdateActiveConfig();
bool bSuccess = true;
s_blendMode = 0;
s_MSAACoverageSamples = 0;
@ -226,20 +197,37 @@ bool Renderer::Init()
switch (g_ActiveConfig.iMultisampleMode)
{
case MULTISAMPLE_OFF: s_MSAASamples = 1; break;
case MULTISAMPLE_2X: s_MSAASamples = 2; break;
case MULTISAMPLE_4X: s_MSAASamples = 4; break;
case MULTISAMPLE_8X: s_MSAASamples = 8; break;
case MULTISAMPLE_OFF:
s_MSAASamples = 1;
break;
case MULTISAMPLE_2X:
s_MSAASamples = 2;
break;
case MULTISAMPLE_4X:
s_MSAASamples = 4;
break;
case MULTISAMPLE_8X:
s_MSAASamples = 8;
break;
case MULTISAMPLE_CSAA_8X:
s_MSAASamples = 4; s_MSAACoverageSamples = 8; break;
s_MSAASamples = 4;
s_MSAACoverageSamples = 8;
break;
case MULTISAMPLE_CSAA_8XQ:
s_MSAASamples = 8; s_MSAACoverageSamples = 8; break;
s_MSAASamples = 8;
s_MSAACoverageSamples = 8;
break;
case MULTISAMPLE_CSAA_16X:
s_MSAASamples = 4; s_MSAACoverageSamples = 16; break;
s_MSAASamples = 4;
s_MSAACoverageSamples = 16;
break;
case MULTISAMPLE_CSAA_16XQ:
s_MSAASamples = 8; s_MSAACoverageSamples = 16; break;
s_MSAASamples = 8;
s_MSAACoverageSamples = 16;
break;
default:
s_MSAASamples = 1;
s_MSAASamples = 1;
break;
}
#if defined HAVE_CG && HAVE_CG
@ -255,7 +243,7 @@ bool Renderer::Init()
PanicAlert("Your OpenGL Driver seems to be not working.\n"
"Please make sure your drivers are up-to-date and\n"
"that your video hardware is OpenGL 2.x compatible.");
return false;
return; // TODO: fail
}
INFO_LOG(VIDEO, "Supported OpenGL Extensions:");
@ -280,7 +268,7 @@ bool Renderer::Init()
if (glewInit() != GLEW_OK)
{
ERROR_LOG(VIDEO, "glewInit() failed! Does your video card support OpenGL 2.x?");
return false;
return; // TODO: fail
}
if (!GLEW_EXT_framebuffer_object)
@ -311,7 +299,7 @@ bool Renderer::Init()
}
if (!bSuccess)
return false;
return; // TODO: fail
// Decide frambuffer size
s_backbuffer_width = (int)OpenGL_GetBackbufferWidth();
@ -366,27 +354,7 @@ bool Renderer::Init()
}
s_LastEFBScale = g_ActiveConfig.iEFBScale;
switch(s_LastEFBScale)
{
case 0:
EFBxScale = xScale;
EFByScale = yScale;
break;
case 1:
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
break;
default:
EFBxScale = (float)(g_ActiveConfig.iEFBScale - 1);
EFByScale = EFBxScale;
break;
};
s_target_width = EFB_WIDTH * EFBxScale;
s_target_height = EFB_HEIGHT * EFByScale;
s_Fulltarget_width = s_target_width;
s_Fulltarget_height = s_target_height;
CalculateTargetSize();
// Because of the fixed framebuffer size we need to disable the resolution
// options while running
@ -411,13 +379,13 @@ bool Renderer::Init()
if (cgGLIsProfileSupported(CG_PROFILE_ARBVP1) != CG_TRUE)
{
ERROR_LOG(VIDEO, "arbvp1 not supported");
return false;
return; // TODO: fail
}
if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) != CG_TRUE)
{
ERROR_LOG(VIDEO, "arbfp1 not supported");
return false;
return; // TODO: fail
}
g_cgvProf = cgGLGetLatestProfile(CG_GL_VERTEX);
@ -505,10 +473,12 @@ bool Renderer::Init()
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
UpdateActiveConfig();
return GL_REPORT_ERROR() == GL_NO_ERROR && bSuccess;
//return GL_REPORT_ERROR() == GL_NO_ERROR && bSuccess;
return;
}
void Renderer::Shutdown()
Renderer::~Renderer()
{
g_Config.bRunning = false;
UpdateActiveConfig();
@ -539,49 +509,8 @@ void Renderer::Shutdown()
#endif
}
// Return the rendering target width and height
int Renderer::GetTargetWidth()
{
return s_target_width;
}
int Renderer::GetTargetHeight()
{
return s_target_height;
}
int Renderer::GetFullTargetWidth()
{
return s_Fulltarget_width;
}
int Renderer::GetFullTargetHeight()
{
return s_Fulltarget_height;
}
float Renderer::GetTargetScaleX()
{
return EFBxScale;
}
float Renderer::GetTargetScaleY()
{
return EFByScale;
}
float Renderer::GetXFBScaleX()
{
return xScale;
}
float Renderer::GetXFBScaleY()
{
return yScale;
}
// Create On-Screen-Messages
void Renderer::DrawDebugText()
void Renderer::DrawDebugInfo()
{
// Reset viewport for drawing text
glViewport(0, 0, OpenGL_GetBackbufferWidth(), OpenGL_GetBackbufferHeight());
@ -651,108 +580,21 @@ void Renderer::DrawDebugText()
Renderer::RenderText(debugtext_buffer, 21, 21, 0xDD000000);
Renderer::RenderText(debugtext_buffer, 20, 20, 0xFF00FFFF);
}
// OSD Menu messages
if (g_ActiveConfig.bOSDHotKey)
{
if (OSDChoice > 0)
{
OSDTime = Common::Timer::GetTimeMs() + 3000;
OSDChoice = -OSDChoice;
}
if ((u32)OSDTime > Common::Timer::GetTimeMs())
{
std::string T1 = "", T2 = "";
std::vector<std::string> T0;
std::string OSDM1;
switch(g_ActiveConfig.iEFBScale)
{
case 0:
OSDM1 = "Auto (fractional)";
break;
case 1:
OSDM1 = "Auto (integral)";
break;
case 2:
OSDM1 = "Native";
break;
case 3:
OSDM1 = "2x";
break;
case 4:
OSDM1 = "3x";
break;
}
std::string OSDM21;
switch(g_ActiveConfig.iAspectRatio)
{
case ASPECT_AUTO:
OSDM21 = "Auto";
break;
case ASPECT_FORCE_16_9:
OSDM21 = "16:9";
break;
case ASPECT_FORCE_4_3:
OSDM21 = "4:3";
break;
case ASPECT_STRETCH:
OSDM21 = "Stretch";
break;
}
std::string OSDM22 =
g_ActiveConfig.bCrop ? " (crop)" : "";
std::string OSDM3 = g_ActiveConfig.bEFBCopyDisable ? "Disabled" :
g_ActiveConfig.bCopyEFBToTexture ? "To Texture" : "To RAM";
// If there is more text than this we will have a collision
if (g_ActiveConfig.bShowFPS)
{
T1 += "\n\n";
T2 += "\n\n";
}
// The rows
T0.push_back(StringFromFormat("3: Internal Resolution: %s\n", OSDM1.c_str()));
T0.push_back(StringFromFormat("4: Aspect Ratio: %s%s\n", OSDM21.c_str(), OSDM22.c_str()));
T0.push_back(StringFromFormat("5: Copy EFB: %s\n", OSDM3.c_str()));
T0.push_back(StringFromFormat("6: Fog: %s\n", g_ActiveConfig.bDisableFog ? "Disabled" : "Enabled"));
T0.push_back(StringFromFormat("7: Material Lighting: %s\n", g_ActiveConfig.bDisableLighting ? "Disabled" : "Enabled"));
// The latest changed setting in yellow
T1 += (OSDChoice == -1) ? T0.at(0) : "\n";
T1 += (OSDChoice == -2) ? T0.at(1) : "\n";
T1 += (OSDChoice == -3) ? T0.at(2) : "\n";
T1 += (OSDChoice == -4) ? T0.at(3) : "\n";
T1 += (OSDChoice == -5) ? T0.at(4) : "\n";
// The other settings in cyan
T2 += (OSDChoice != -1) ? T0.at(0) : "\n";
T2 += (OSDChoice != -2) ? T0.at(1) : "\n";
T2 += (OSDChoice != -3) ? T0.at(2) : "\n";
T2 += (OSDChoice != -4) ? T0.at(3) : "\n";
T2 += (OSDChoice != -5) ? T0.at(4) : "\n";
// Render a shadow, and then the text
Renderer::RenderText(T1.c_str(), 21, 21, 0xDD000000);
Renderer::RenderText(T1.c_str(), 20, 20, 0xFFffff00);
Renderer::RenderText(T2.c_str(), 21, 21, 0xDD000000);
Renderer::RenderText(T2.c_str(), 20, 20, 0xFF00FFFF);
}
}
}
void Renderer::RenderText(const char *text, int left, int top, u32 color)
{
int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth();
int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight();
const int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth();
const int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight();
glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f,
((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f);
s_pfont->printMultilineText(text,
left * 2.0f / (float)nBackbufferWidth - 1,
1 - top * 2.0f / (float)nBackbufferHeight,
0, nBackbufferWidth, nBackbufferHeight);
GL_REPORT_ERRORD();
}
@ -768,27 +610,6 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
return result;
}
void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
{
if (!fbWidth || !fbHeight)
return;
s_skipSwap = g_bSkipCurrentFrame;
VideoFifo_CheckEFBAccess();
VideoFifo_CheckSwapRequestAt(xfbAddr, fbWidth, fbHeight);
XFBWrited = true;
// XXX: Without the VI, how would we know what kind of field this is? So
// just use progressive.
if (g_ActiveConfig.bUseXFB)
{
FramebufferManager::CopyToXFB(xfbAddr, fbWidth, fbHeight, sourceRc);
}
else
{
Renderer::Swap(xfbAddr, FIELD_PROGRESSIVE, fbWidth, fbHeight,sourceRc);
Common::AtomicStoreRelease(s_swapRequested, FALSE);
}
}
// Function: This function handles the OpenGL glScissor() function
// ----------------------------
// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
@ -801,39 +622,38 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
// therefore the width and height are (scissorBR + 1) - scissorTL
bool Renderer::SetScissorRect()
{
int xoff = bpmem.scissorOffset.x * 2 - 342;
int yoff = bpmem.scissorOffset.y * 2 - 342;
float rc_left = (float)bpmem.scissorTL.x - xoff - 342; // left = 0
float rc_top = (float)bpmem.scissorTL.y - yoff - 342; // right = 0
float rc_right = (float)bpmem.scissorBR.x - xoff - 341; // right = 640
float rc_bottom = (float)bpmem.scissorBR.y - yoff - 341; // bottom = 480
MathUtil::Rectangle<float> rc;
GetScissorRect(rc);
if (rc_left < 0) rc_left = 0;
if (rc_right > EFB_WIDTH) rc_right = EFB_WIDTH;
if (rc_top < 0) rc_top = 0;
if (rc_bottom > EFB_HEIGHT) rc_bottom = EFB_HEIGHT;
if (rc.left < 0) rc.left = 0;
if (rc_left > rc_right)
if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
if (rc.top < 0) rc.top = 0;
if (rc.bottom > EFB_HEIGHT) rc.bottom = EFB_HEIGHT;
if (rc.left > rc.right)
{
int temp = rc_right;
rc_right = rc_left;
rc_left = temp;
int temp = rc.right;
rc.right = rc.left;
rc.left = temp;
}
if (rc_top > rc_bottom)
if (rc.top > rc.bottom)
{
int temp = rc_bottom;
rc_bottom = rc_top;
rc_top = temp;
int temp = rc.bottom;
rc.bottom = rc.top;
rc.top = temp;
}
// Check that the coordinates are good
if (rc_right != rc_left && rc_bottom != rc_top)
if (rc.right != rc.left && rc.bottom != rc.top)
{
glScissor(
(int)(rc_left * EFBxScale), // x = 0 for example
(int)((EFB_HEIGHT - rc_bottom) * EFByScale), // y = 0 for example
(int)((rc_right - rc_left)* EFBxScale), // width = 640 for example
(int)((rc_bottom - rc_top) * EFByScale) // height = 480 for example
(int)(rc.left * EFBxScale), // x = 0 for example
(int)((EFB_HEIGHT - rc.bottom) * EFByScale), // y = 0 for example
(int)((rc.right - rc.left)* EFBxScale), // width = 640 for example
(int)((rc.bottom - rc.top) * EFByScale) // height = 480 for example
);
return true;
}
@ -962,7 +782,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
}
// Called from VertexShaderManager
void UpdateViewport()
void Renderer::UpdateViewport()
{
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
// [0] = width/2
@ -979,10 +799,10 @@ void UpdateViewport()
// int Ystride = (s_Fulltarget_height - s_target_height) / 2;
// Stretch picture with increased internal resolution
int X = (int)ceil((xfregs.rawViewport[3] - xfregs.rawViewport[0] - float(scissorXOff)) * EFBxScale);
int Y = (int)ceil((float(EFB_HEIGHT) - xfregs.rawViewport[4] + xfregs.rawViewport[1] + float(scissorYOff)) * EFByScale);
int Width = (int)ceil(2.0f * xfregs.rawViewport[0] * EFBxScale);
int Height = (int)ceil(-2.0f * xfregs.rawViewport[1] * EFByScale);
int X = (int)ceil((xfregs.rawViewport[3] - xfregs.rawViewport[0] - float(scissorXOff)) * Renderer::GetTargetScaleX());
int Y = (int)ceil((float(EFB_HEIGHT) - xfregs.rawViewport[4] + xfregs.rawViewport[1] + float(scissorYOff)) * Renderer::GetTargetScaleY());
int Width = (int)ceil(2.0f * xfregs.rawViewport[0] * Renderer::GetTargetScaleX());
int Height = (int)ceil(-2.0f * xfregs.rawViewport[1] * Renderer::GetTargetScaleY());
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
double GLFar = xfregs.rawViewport[5] / 16777216.0f;
if (Width < 0)
@ -1131,8 +951,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
return;
}
DVSTARTPROFILE();
ResetAPIState();
DVSTARTPROFILE();
TargetRectangle dst_rect;
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, true, &dst_rect);
@ -1281,10 +1102,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
if (s_bScreenshot)
{
s_criticalScreenshot.Enter();
// Save screenshot
SaveRenderTarget(s_sScreenshotName.c_str(), dst_rect);
SaveScreenshot(s_sScreenshotName, dst_rect);
// Reset settings
s_sScreenshotName = "";
s_sScreenshotName.clear();
s_bScreenshot = false;
s_criticalScreenshot.Leave();
}
@ -1438,33 +1258,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
yScale = (float)(dst_rect.bottom - dst_rect.top) / (float)s_XFB_height;
}
switch(s_LastEFBScale)
if (CalculateTargetSize())
{
case 0:
EFBxScale = xScale;
EFByScale = yScale;
break;
case 1:
EFBxScale = ceilf(xScale);
EFByScale = ceilf(yScale);
break;
default:
EFBxScale = (float)(g_ActiveConfig.iEFBScale - 1);
EFByScale = EFBxScale;
break;
};
int m_newFrameBufferWidth = EFB_WIDTH * EFBxScale;
int m_newFrameBufferHeight = EFB_HEIGHT * EFByScale;
if(m_newFrameBufferWidth != s_target_width ||
m_newFrameBufferHeight != s_target_height )
{
s_target_width = m_newFrameBufferWidth;
s_target_height = m_newFrameBufferHeight;
s_Fulltarget_width = s_target_width;
s_Fulltarget_height = s_target_height;
delete g_framebuffer_manager;
g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height,
s_MSAASamples, s_MSAACoverageSamples);
@ -1559,7 +1354,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// For testing zbuffer targets.
// Renderer::SetZBufferRender();
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget,
// GetTargetWidth(), GetTargetHeight());
// GetTargetWidth(), GetTargetHeight());
g_VideoInitialize.pCopiedToXFB(XFBWrited || g_ActiveConfig.bUseRealXFB);
XFBWrited = false;
}
@ -1668,15 +1463,6 @@ void Renderer::SetInterlacingMode()
// TODO
}
// Save screenshot
void Renderer::SetScreenshot(const char *filename)
{
s_criticalScreenshot.Enter();
s_sScreenshotName = filename;
s_bScreenshot = true;
s_criticalScreenshot.Leave();
}
void Renderer::FlipImageData(u8 *data, int w, int h)
{
// Flip image upside down. Damn OpenGL.
@ -1691,6 +1477,8 @@ void Renderer::FlipImageData(u8 *data, int w, int h)
}
}
}
#if defined(HAVE_WX) && HAVE_WX
THREAD_RETURN TakeScreenshot(void *pArgs)
{
@ -1739,7 +1527,10 @@ THREAD_RETURN TakeScreenshot(void *pArgs)
}
#endif
bool Renderer::SaveRenderTarget(const char *filename, TargetRectangle back_rc)
namespace OGL
{
bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle &back_rc)
{
u32 W = back_rc.GetWidth();
u32 H = back_rc.GetHeight();
@ -1769,7 +1560,7 @@ bool Renderer::SaveRenderTarget(const char *filename, TargetRectangle back_rc)
}
ScrStrct *threadStruct = new ScrStrct;
threadStruct->filename = std::string(filename);
threadStruct->filename = filename;
threadStruct->img = a;
threadStruct->H = H; threadStruct->W = W;
@ -1782,9 +1573,11 @@ bool Renderer::SaveRenderTarget(const char *filename, TargetRectangle back_rc)
OSD::AddMessage("Saving Screenshot... ", 2000);
#else
bool result = SaveTGA(filename, W, H, data);
bool result = SaveTGA(filename.c_str(), W, H, data);
delete[] data;
#endif
return result;
}
}

View File

@ -0,0 +1,49 @@
#ifndef _RENDER_H_
#define _RENDER_H_
#include "RenderBase.h"
namespace OGL
{
class Renderer : public ::Renderer
{
public:
Renderer();
~Renderer();
void SetColorMask();
void SetBlendMode(bool forceUpdate);
bool SetScissorRect();
void SetGenerationMode();
void SetDepthMode();
void SetLogicOpMode();
void SetDitherMode();
void SetLineWidth();
void SetSamplerState(int stage,int texindex);
void SetInterlacingMode();
void RenderText(const char* pstr, int left, int top, u32 color);
void DrawDebugInfo();
void FlipImageData(u8 *data, int w, int h);
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data);
void ResetAPIState();
void RestoreAPIState();
TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc);
void Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc);
void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z);
void UpdateViewport();
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
};
}
#endif

View File

@ -7,7 +7,6 @@ import sys
name = os.sep + "Plugin_VideoOGL"
files = [
'BPFunctions.cpp',
'RasterFont.cpp',
'Render.cpp',
'TextureCache.cpp',

View File

@ -305,7 +305,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool bFromZBuffer, bool bScaleB
PixelShaderManager::SetColorMatrix(colmat, fConstAdd); // set transformation
GL_REPORT_ERRORD();
TargetRectangle targetSource = Renderer::ConvertEFBRectangle(source_rect);
TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(source_rect);
glBegin(GL_QUADS);
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.bottom); glVertex2f(-1, 1);

View File

@ -308,13 +308,13 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
cacheBytes = 64;
int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format);
Renderer::ResetAPIState();
g_renderer->ResetAPIState();
EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0);
FramebufferManager::SetFramebuffer(0);
VertexShaderManager::SetViewportChanged();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
TextureCache::DisableStage(0);
Renderer::RestoreAPIState();
g_renderer->RestoreAPIState();
GL_REPORT_ERRORD();
}
@ -386,13 +386,13 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight)
{
Renderer::ResetAPIState();
g_renderer->ResetAPIState();
EncodeToRamUsingShader(s_rgbToYuyvProgram, srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, false);
FramebufferManager::SetFramebuffer(0);
VertexShaderManager::SetViewportChanged();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
TextureCache::DisableStage(0);
Renderer::RestoreAPIState();
g_renderer->RestoreAPIState();
GL_REPORT_ERRORD();
}
@ -409,7 +409,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
int srcFmtWidth = srcWidth / 2;
Renderer::ResetAPIState(); // reset any game specific settings
g_renderer->ResetAPIState(); // reset any game specific settings
// switch to texture converter frame buffer
// attach destTexture as color destination
@ -462,7 +462,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
FramebufferManager::SetFramebuffer(0);
Renderer::RestoreAPIState();
g_renderer->RestoreAPIState();
GL_REPORT_ERRORD();
}

View File

@ -198,12 +198,12 @@ void VertexManager::vFlush()
{
// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
// the same pass as regular rendering.
Renderer::SetBlendMode(true);
g_renderer->SetBlendMode(true);
ps = PixelShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, g_nativeVertexFmt->m_components);
}
else
{
Renderer::SetBlendMode(true);
g_renderer->SetBlendMode(true);
ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components);
}
}
@ -234,7 +234,7 @@ void VertexManager::vFlush()
Draw();
// restore color mask
Renderer::SetColorMask();
g_renderer->SetColorMask();
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
glEnable(GL_BLEND);
@ -265,7 +265,7 @@ void VertexManager::vFlush()
tr.right = Renderer::GetTargetWidth();
tr.top = 0;
tr.bottom = Renderer::GetTargetHeight();
Renderer::SaveRenderTarget(str, tr);
g_renderer->SaveScreenshot(str, tr);
}
#endif
g_Config.iSaveTargetId++;

View File

@ -65,6 +65,7 @@ Make AA apply instantly during gameplay if possible
#include "Debugger/Debugger.h"
#endif // HAVE_WX
#include "MainBase.h"
#include "VideoConfig.h"
#include "LookUpTables.h"
#include "ImageWrite.h"
@ -89,33 +90,16 @@ Make AA apply instantly during gameplay if possible
#include "OnScreenDisplay.h"
#include "Setup.h"
#include "DLCache.h"
#include "FramebufferManager.h"
#include "VideoState.h"
SVideoInitialize g_VideoInitialize;
PLUGIN_GLOBALS* globals = NULL;
// Logging
int GLScissorX, GLScissorY, GLScissorW, GLScissorH;
static bool s_PluginInitialized = false;
volatile u32 s_swapRequested = FALSE;
#if defined(HAVE_X11) && HAVE_X11
static volatile u32 s_doStateRequested = FALSE;
#endif
static u32 s_efbAccessRequested = FALSE;
static volatile u32 s_FifoShuttingDown = FALSE;
static volatile struct
{
u32 xfbAddr;
FieldType field;
u32 fbWidth;
u32 fbHeight;
} s_beginFieldArgs;
static volatile EFBAccessType s_AccessEFBType;
bool IsD3D()
{
@ -236,11 +220,13 @@ void Initialize(void *init)
void Video_Prepare()
{
OpenGL_MakeCurrent();
if (!Renderer::Init()) {
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info");
exit(1);
}
//if (!Renderer::Init()) {
// g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
// PanicAlert("Can't create opengl renderer. You might be missing some required opengl extensions, check the logs for more info");
// exit(1);
//}
g_renderer = new OGL::Renderer;
s_efbAccessRequested = FALSE;
s_FifoShuttingDown = FALSE;
@ -295,7 +281,7 @@ void Shutdown()
delete g_vertex_manager;
delete g_texture_cache;
OpcodeDecoder_Shutdown();
Renderer::Shutdown();
delete g_renderer;
OpenGL_Shutdown();
}
@ -348,195 +334,3 @@ void DoState(unsigned char **ptr, int mode)
#endif
check_DoState();
}
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
Fifo_RunLoop((newState == PLUGIN_EMUSTATE_PLAY) ? true : false);
}
// Enter and exit the video loop
void Video_EnterLoop()
{
Fifo_EnterLoop(g_VideoInitialize);
}
void Video_ExitLoop()
{
Fifo_ExitLoop();
s_FifoShuttingDown = TRUE;
}
void Video_SetRendering(bool bEnabled)
{
Fifo_SetRendering(bEnabled);
}
// Run from the graphics thread (from Fifo.cpp)
void VideoFifo_CheckSwapRequest()
{
if(g_ActiveConfig.bUseXFB)
{
if (Common::AtomicLoadAcquire(s_swapRequested))
{
EFBRectangle rc;
Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.field, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight,rc);
Common::AtomicStoreRelease(s_swapRequested, FALSE);
}
}
}
static inline bool addrRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper)
{
return !((aLower >= bUpper) || (bLower >= aUpper));
}
// Run from the graphics thread (from Fifo.cpp)
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
{
if (g_ActiveConfig.bUseXFB)
{
if(Common::AtomicLoadAcquire(s_swapRequested))
{
u32 aLower = xfbAddr;
u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight;
u32 bLower = s_beginFieldArgs.xfbAddr;
u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight;
if (addrRangesOverlap(aLower, aUpper, bLower, bUpper))
VideoFifo_CheckSwapRequest();
}
}
}
// Run from the CPU thread (from VideoInterface.cpp)
void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
{
if (s_PluginInitialized && g_ActiveConfig.bUseXFB)
{
if (!g_VideoInitialize.bOnThread)
VideoFifo_CheckSwapRequest();
s_beginFieldArgs.xfbAddr = xfbAddr;
s_beginFieldArgs.field = field;
s_beginFieldArgs.fbWidth = fbWidth;
s_beginFieldArgs.fbHeight = fbHeight;
}
}
// Run from the CPU thread (from VideoInterface.cpp)
void Video_EndField()
{
if (s_PluginInitialized)
{
Common::AtomicStoreRelease(s_swapRequested, TRUE);
}
}
void Video_AddMessage(const char* pstr, u32 milliseconds)
{
OSD::AddMessage(pstr, milliseconds);
}
// Screenshot
void Video_Screenshot(const char *_szFilename)
{
Renderer::SetScreenshot(_szFilename);
}
static struct
{
EFBAccessType type;
u32 x;
u32 y;
u32 Data;
} s_accessEFBArgs;
static u32 s_AccessEFBResult = 0;
void VideoFifo_CheckEFBAccess()
{
if (Common::AtomicLoadAcquire(s_efbAccessRequested))
{
s_AccessEFBResult = Renderer::AccessEFB(s_accessEFBArgs.type, s_accessEFBArgs.x, s_accessEFBArgs.y, s_accessEFBArgs.Data);
Common::AtomicStoreRelease(s_efbAccessRequested, FALSE);
}
}
u32 Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
{
if (s_PluginInitialized)
{
s_accessEFBArgs.type = type;
s_accessEFBArgs.x = x;
s_accessEFBArgs.y = y;
s_accessEFBArgs.Data = InputData;
Common::AtomicStoreRelease(s_efbAccessRequested, TRUE);
if (g_VideoInitialize.bOnThread)
{
while (Common::AtomicLoadAcquire(s_efbAccessRequested) && !s_FifoShuttingDown)
//Common::SleepCurrentThread(1);
Common::YieldCPU();
}
else
VideoFifo_CheckEFBAccess();
return s_AccessEFBResult;
}
return 0;
}
void VideoFifo_CheckAsyncRequest() {
VideoFifo_CheckSwapRequest();
VideoFifo_CheckEFBAccess();
#if defined(HAVE_X11) && HAVE_X11
check_DoState();
#endif
}
void Video_CommandProcessorRead16(u16& _rReturnValue, const u32 _Address)
{
CommandProcessor::Read16(_rReturnValue, _Address);
}
void Video_CommandProcessorWrite16(const u16 _Data, const u32 _Address)
{
CommandProcessor::Write16(_Data, _Address);
}
void Video_PixelEngineRead16(u16& _rReturnValue, const u32 _Address)
{
PixelEngine::Read16(_rReturnValue, _Address);
}
void Video_PixelEngineWrite16(const u16 _Data, const u32 _Address)
{
PixelEngine::Write16(_Data, _Address);
}
void Video_PixelEngineWrite32(const u32 _Data, const u32 _Address)
{
PixelEngine::Write32(_Data, _Address);
}
void Video_GatherPipeBursted(void)
{
CommandProcessor::GatherPipeBursted();
}
void Video_WaitForFrameFinish(void)
{
CommandProcessor::WaitForFrameFinish();
}
bool Video_IsFifoBusy(void)
{
return CommandProcessor::isFifoBusy;
}
void Video_AbortFrame(void)
{
CommandProcessor::AbortFrame();
}

View File

@ -19,10 +19,8 @@
#define _MAIN_H_
#include "pluginspecs_video.h"
#include "MainBase.h"
extern SVideoInitialize g_VideoInitialize;
extern volatile u32 s_swapRequested;
void VideoFifo_CheckEFBAccess();
void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
#endif // _MAIN_H_