mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
Merge branch 'master' into perfqueries.
Conflicts: Source/Core/VideoCommon/Src/VideoConfig.h Source/Core/VideoCommon/VideoCommon.vcxproj.filters Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
add_subdirectory(Plugin_VideoOGL)
|
||||
if(NOT USE_GLES)
|
||||
add_subdirectory(Plugin_VideoOGL)
|
||||
endif()
|
||||
add_subdirectory(Plugin_VideoSoftware)
|
||||
# TODO: Add other backends here!
|
||||
|
@ -181,15 +181,12 @@ XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, un
|
||||
|
||||
void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
|
||||
{
|
||||
const float scaleX = Renderer::GetXFBScaleX();
|
||||
const float scaleY = Renderer::GetXFBScaleY();
|
||||
|
||||
TargetRectangle targetSource;
|
||||
|
||||
targetSource.top = (int)(sourceRc.top *scaleY);
|
||||
targetSource.bottom = (int)(sourceRc.bottom *scaleY);
|
||||
targetSource.left = (int)(sourceRc.left *scaleX);
|
||||
targetSource.right = (int)(sourceRc.right * scaleX);
|
||||
targetSource.top = ScaleToVirtualXfbHeight(sourceRc.top, Renderer::GetBackbufferHeight());
|
||||
targetSource.bottom = ScaleToVirtualXfbHeight(sourceRc.bottom, Renderer::GetBackbufferHeight());
|
||||
targetSource.left = ScaleToVirtualXfbWidth(sourceRc.left, Renderer::GetBackbufferWidth());
|
||||
targetSource.right = ScaleToVirtualXfbWidth(sourceRc.right, Renderer::GetBackbufferWidth());
|
||||
|
||||
*width = targetSource.right - targetSource.left;
|
||||
*height = targetSource.bottom - targetSource.top;
|
||||
|
@ -16,7 +16,6 @@
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <math.h>
|
||||
#include <strsafe.h>
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
@ -44,6 +43,9 @@
|
||||
#include "Host.h"
|
||||
#include "BPFunctions.h"
|
||||
#include "AVIDump.h"
|
||||
#include "FPSCounter.h"
|
||||
#include "ConfigManager.h"
|
||||
#include <strsafe.h>
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
@ -52,8 +54,6 @@ static int s_fps = 0;
|
||||
|
||||
static u32 s_LastAA = 0;
|
||||
|
||||
static u32 s_blendMode;
|
||||
|
||||
static Television s_television;
|
||||
|
||||
ID3D11Buffer* access_efb_cbuf = NULL;
|
||||
@ -87,151 +87,6 @@ struct
|
||||
D3D11_RASTERIZER_DESC rastdc;
|
||||
} gx_state;
|
||||
|
||||
// State translation lookup tables
|
||||
static const D3D11_BLEND d3dSrcFactors[8] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_DEST_COLOR,
|
||||
D3D11_BLEND_INV_DEST_COLOR,
|
||||
D3D11_BLEND_SRC_ALPHA,
|
||||
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
|
||||
D3D11_BLEND_DEST_ALPHA,
|
||||
D3D11_BLEND_INV_DEST_ALPHA
|
||||
};
|
||||
|
||||
static const D3D11_BLEND d3dDestFactors[8] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_SRC_COLOR,
|
||||
D3D11_BLEND_INV_SRC_COLOR,
|
||||
D3D11_BLEND_SRC_ALPHA,
|
||||
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
|
||||
D3D11_BLEND_DEST_ALPHA,
|
||||
D3D11_BLEND_INV_DEST_ALPHA
|
||||
};
|
||||
|
||||
// 0 0x00
|
||||
// 1 Source & destination
|
||||
// 2 Source & ~destination
|
||||
// 3 Source
|
||||
// 4 ~Source & destination
|
||||
// 5 Destination
|
||||
// 6 Source ^ destination = Source & ~destination | ~Source & destination
|
||||
// 7 Source | destination
|
||||
|
||||
// 8 ~(Source | destination)
|
||||
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
|
||||
// 10 ~Destination
|
||||
// 11 Source | ~destination
|
||||
// 12 ~Source
|
||||
// 13 ~Source | destination
|
||||
// 14 ~(Source & destination)
|
||||
// 15 0xff
|
||||
|
||||
static const D3D11_BLEND_OP d3dLogicOps[16] =
|
||||
{
|
||||
D3D11_BLEND_OP_ADD,//0
|
||||
D3D11_BLEND_OP_ADD,//1
|
||||
D3D11_BLEND_OP_SUBTRACT,//2
|
||||
D3D11_BLEND_OP_ADD,//3
|
||||
D3D11_BLEND_OP_REV_SUBTRACT,//4
|
||||
D3D11_BLEND_OP_ADD,//5
|
||||
D3D11_BLEND_OP_MAX,//6
|
||||
D3D11_BLEND_OP_ADD,//7
|
||||
|
||||
D3D11_BLEND_OP_MAX,//8
|
||||
D3D11_BLEND_OP_MAX,//9
|
||||
D3D11_BLEND_OP_ADD,//10
|
||||
D3D11_BLEND_OP_ADD,//11
|
||||
D3D11_BLEND_OP_ADD,//12
|
||||
D3D11_BLEND_OP_ADD,//13
|
||||
D3D11_BLEND_OP_ADD,//14
|
||||
D3D11_BLEND_OP_ADD//15
|
||||
};
|
||||
|
||||
static const D3D11_BLEND d3dLogicOpSrcFactors[16] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,//0
|
||||
D3D11_BLEND_DEST_COLOR,//1
|
||||
D3D11_BLEND_ONE,//2
|
||||
D3D11_BLEND_ONE,//3
|
||||
D3D11_BLEND_DEST_COLOR,//4
|
||||
D3D11_BLEND_ZERO,//5
|
||||
D3D11_BLEND_INV_DEST_COLOR,//6
|
||||
D3D11_BLEND_INV_DEST_COLOR,//7
|
||||
|
||||
D3D11_BLEND_INV_SRC_COLOR,//8
|
||||
D3D11_BLEND_INV_SRC_COLOR,//9
|
||||
D3D11_BLEND_INV_DEST_COLOR,//10
|
||||
D3D11_BLEND_ONE,//11
|
||||
D3D11_BLEND_INV_SRC_COLOR,//12
|
||||
D3D11_BLEND_INV_SRC_COLOR,//13
|
||||
D3D11_BLEND_INV_DEST_COLOR,//14
|
||||
D3D11_BLEND_ONE//15
|
||||
};
|
||||
|
||||
static const D3D11_BLEND d3dLogicOpDestFactors[16] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,//0
|
||||
D3D11_BLEND_ZERO,//1
|
||||
D3D11_BLEND_INV_SRC_COLOR,//2
|
||||
D3D11_BLEND_ZERO,//3
|
||||
D3D11_BLEND_ONE,//4
|
||||
D3D11_BLEND_ONE,//5
|
||||
D3D11_BLEND_INV_SRC_COLOR,//6
|
||||
D3D11_BLEND_ONE,//7
|
||||
|
||||
D3D11_BLEND_INV_DEST_COLOR,//8
|
||||
D3D11_BLEND_SRC_COLOR,//9
|
||||
D3D11_BLEND_INV_DEST_COLOR,//10
|
||||
D3D11_BLEND_INV_DEST_COLOR,//11
|
||||
D3D11_BLEND_INV_SRC_COLOR,//12
|
||||
D3D11_BLEND_ONE,//13
|
||||
D3D11_BLEND_INV_SRC_COLOR,//14
|
||||
D3D11_BLEND_ONE//15
|
||||
};
|
||||
|
||||
static const D3D11_CULL_MODE d3dCullModes[4] =
|
||||
{
|
||||
D3D11_CULL_NONE,
|
||||
D3D11_CULL_BACK,
|
||||
D3D11_CULL_FRONT,
|
||||
D3D11_CULL_BACK
|
||||
};
|
||||
|
||||
static const D3D11_COMPARISON_FUNC d3dCmpFuncs[8] =
|
||||
{
|
||||
D3D11_COMPARISON_NEVER,
|
||||
D3D11_COMPARISON_LESS,
|
||||
D3D11_COMPARISON_EQUAL,
|
||||
D3D11_COMPARISON_LESS_EQUAL,
|
||||
D3D11_COMPARISON_GREATER,
|
||||
D3D11_COMPARISON_NOT_EQUAL,
|
||||
D3D11_COMPARISON_GREATER_EQUAL,
|
||||
D3D11_COMPARISON_ALWAYS
|
||||
};
|
||||
|
||||
#define TEXF_NONE 0
|
||||
#define TEXF_POINT 1
|
||||
#define TEXF_LINEAR 2
|
||||
static const unsigned int d3dMipFilters[4] =
|
||||
{
|
||||
TEXF_NONE,
|
||||
TEXF_POINT,
|
||||
TEXF_LINEAR,
|
||||
TEXF_NONE, //reserved
|
||||
};
|
||||
|
||||
static const D3D11_TEXTURE_ADDRESS_MODE d3dClamps[4] =
|
||||
{
|
||||
D3D11_TEXTURE_ADDRESS_CLAMP,
|
||||
D3D11_TEXTURE_ADDRESS_WRAP,
|
||||
D3D11_TEXTURE_ADDRESS_MIRROR,
|
||||
D3D11_TEXTURE_ADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
|
||||
void SetupDeviceObjects()
|
||||
{
|
||||
@ -358,7 +213,8 @@ void CreateScreenshotTexture()
|
||||
Renderer::Renderer()
|
||||
{
|
||||
int x, y, w_temp, h_temp;
|
||||
s_blendMode = 0;
|
||||
|
||||
InitFPSCounter();
|
||||
|
||||
Host_GetRenderWindowSize(x, y, w_temp, h_temp);
|
||||
|
||||
@ -367,17 +223,14 @@ Renderer::Renderer()
|
||||
s_backbuffer_width = D3D::GetBackBufferWidth();
|
||||
s_backbuffer_height = D3D::GetBackBufferHeight();
|
||||
|
||||
s_XFB_width = MAX_XFB_WIDTH;
|
||||
s_XFB_height = MAX_XFB_HEIGHT;
|
||||
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
|
||||
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
|
||||
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
s_LastAA = g_ActiveConfig.iMultisampleMode;
|
||||
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
||||
CalculateTargetSize();
|
||||
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
pixel_perf_query_index = 0;
|
||||
pixel_perf = 0;
|
||||
@ -497,10 +350,13 @@ void Renderer::SetColorMask()
|
||||
{
|
||||
// Only enable alpha channel if it's supported by the current EFB format
|
||||
UINT8 color_mask = 0;
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
color_mask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
color_mask |= D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
|
||||
if (bpmem.alpha_test.TestResult() != AlphaTest::FAIL)
|
||||
{
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
color_mask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
color_mask |= D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
|
||||
}
|
||||
gx_state.blenddc.RenderTarget[0].RenderTargetWriteMask = color_mask;
|
||||
}
|
||||
|
||||
@ -962,6 +818,32 @@ void SetBlendOp(D3D11_BLEND_OP val)
|
||||
|
||||
void Renderer::SetBlendMode(bool forceUpdate)
|
||||
{
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
const D3D11_BLEND d3dSrcFactors[8] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_DEST_COLOR,
|
||||
D3D11_BLEND_INV_DEST_COLOR,
|
||||
D3D11_BLEND_SRC_ALPHA,
|
||||
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
|
||||
(target_has_alpha) ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_ONE,
|
||||
(target_has_alpha) ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_ZERO
|
||||
};
|
||||
const D3D11_BLEND d3dDestFactors[8] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_SRC_COLOR,
|
||||
D3D11_BLEND_INV_SRC_COLOR,
|
||||
D3D11_BLEND_SRC_ALPHA,
|
||||
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
|
||||
(target_has_alpha) ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_ONE,
|
||||
(target_has_alpha) ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_ZERO
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable && !forceUpdate)
|
||||
return;
|
||||
|
||||
@ -974,8 +856,8 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
}
|
||||
else
|
||||
{
|
||||
gx_state.blenddc.RenderTarget[0].BlendEnable = bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0));
|
||||
if (bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)))
|
||||
gx_state.blenddc.RenderTarget[0].BlendEnable = bpmem.blendmode.blendenable;
|
||||
if (bpmem.blendmode.blendenable)
|
||||
{
|
||||
SetBlendOp(D3D11_BLEND_OP_ADD);
|
||||
SetSrcBlend(d3dSrcFactors[bpmem.blendmode.srcfactor]);
|
||||
@ -1012,11 +894,11 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
void formatBufferDump(const char *in, char *out, int w, int h, int p)
|
||||
void formatBufferDump(const u8* in, u8* out, int w, int h, int p)
|
||||
{
|
||||
for (int y = 0; y < h; ++y)
|
||||
{
|
||||
const u8 *line = (u8*)(in + (h - y - 1) * p);
|
||||
auto line = (in + (h - y - 1) * p);
|
||||
for (int x = 0; x < w; ++x)
|
||||
{
|
||||
out[0] = line[2];
|
||||
@ -1031,24 +913,22 @@ void formatBufferDump(const char *in, char *out, int w, int h, int p)
|
||||
// This function has the final picture. We adjust the aspect ratio here.
|
||||
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
|
||||
{
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight)
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
AVIDump::AddFrame(frame_data);
|
||||
if (g_ActiveConfig.bDumpFrames && !frame_data.empty())
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
}
|
||||
// this function is called after the XFB field is changed, not after
|
||||
// EFB is copied to XFB. In this way, flickering is reduced in games
|
||||
// and seems to also give more FPS in ZTP
|
||||
|
||||
if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2;
|
||||
u32 xfbCount = 0;
|
||||
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
||||
if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB)
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
AVIDump::AddFrame(frame_data);
|
||||
if (g_ActiveConfig.bDumpFrames && !frame_data.empty())
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
@ -1057,18 +937,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
ResetAPIState();
|
||||
|
||||
// Prepare to copy the XFBs to our backbuffer
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)s_backbuffer_width, (float)s_backbuffer_height);
|
||||
D3D::context->RSSetViewports(1, &vp);
|
||||
float ClearColor[4] = { 0.f, 0.f, 0.f, 1.f };
|
||||
D3D::context->ClearRenderTargetView(D3D::GetBackBuffer()->GetRTV(), ClearColor);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
int X = dst_rect.left;
|
||||
int Y = dst_rect.top;
|
||||
int Width = dst_rect.right - dst_rect.left;
|
||||
int Height = dst_rect.bottom - dst_rect.top;
|
||||
int X = GetTargetRectangle().left;
|
||||
int Y = GetTargetRectangle().top;
|
||||
int Width = GetTargetRectangle().right - GetTargetRectangle().left;
|
||||
int Height = GetTargetRectangle().bottom - GetTargetRectangle().top;
|
||||
|
||||
// TODO: Redundant checks...
|
||||
if (X < 0) X = 0;
|
||||
if (Y < 0) Y = 0;
|
||||
if (X > s_backbuffer_width) X = s_backbuffer_width;
|
||||
@ -1077,10 +953,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (Height < 0) Height = 0;
|
||||
if (Width > (s_backbuffer_width - X)) Width = s_backbuffer_width - X;
|
||||
if (Height > (s_backbuffer_height - Y)) Height = s_backbuffer_height - Y;
|
||||
vp = CD3D11_VIEWPORT((float)X, (float)Y, (float)Width, (float)Height);
|
||||
D3D11_VIEWPORT vp = CD3D11_VIEWPORT((float)X, (float)Y, (float)Width, (float)Height);
|
||||
D3D::context->RSSetViewports(1, &vp);
|
||||
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL);
|
||||
|
||||
float ClearColor[4] = { 0.f, 0.f, 0.f, 1.f };
|
||||
D3D::context->ClearRenderTargetView(D3D::GetBackBuffer()->GetRTV(), ClearColor);
|
||||
|
||||
// activate linear filtering for the buffer copies
|
||||
D3D::SetLinearCopySampler();
|
||||
|
||||
@ -1107,7 +986,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
MathUtil::Rectangle<float> drawRc;
|
||||
|
||||
if (g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB)
|
||||
if (g_ActiveConfig.bUseRealXFB)
|
||||
{
|
||||
drawRc.top = 1;
|
||||
drawRc.bottom = -1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use virtual xfb with offset
|
||||
int xfbHeight = xfbSource->srcHeight;
|
||||
@ -1128,13 +1014,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
//drawRc.left *= hScale;
|
||||
//drawRc.right *= hScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawRc.top = 1;
|
||||
drawRc.bottom = -1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
|
||||
xfbSource->Draw(sourceRc, drawRc, 0, 0);
|
||||
}
|
||||
@ -1151,7 +1030,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
// done with drawing the game stuff, good moment to save a screenshot
|
||||
if (s_bScreenshot)
|
||||
{
|
||||
SaveScreenshot(s_sScreenshotName, dst_rect);
|
||||
SaveScreenshot(s_sScreenshotName, GetTargetRectangle());
|
||||
s_bScreenshot = false;
|
||||
}
|
||||
|
||||
@ -1168,8 +1047,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::context->CopyResource(s_screenshot_texture, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex());
|
||||
if (!bLastFrameDumped)
|
||||
{
|
||||
s_recordWidth = dst_rect.GetWidth();
|
||||
s_recordHeight = dst_rect.GetHeight();
|
||||
s_recordWidth = GetTargetRectangle().GetWidth();
|
||||
s_recordHeight = GetTargetRectangle().GetHeight();
|
||||
bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight);
|
||||
if (!bAVIDumping)
|
||||
{
|
||||
@ -1188,16 +1067,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ, 0, &map);
|
||||
|
||||
if (!frame_data || w != s_recordWidth || h != s_recordHeight)
|
||||
if (frame_data.empty() || w != s_recordWidth || h != s_recordHeight)
|
||||
{
|
||||
delete[] frame_data;
|
||||
frame_data = new char[3 * s_recordWidth * s_recordHeight];
|
||||
frame_data.resize(3 * s_recordWidth * s_recordHeight);
|
||||
w = s_recordWidth;
|
||||
h = s_recordHeight;
|
||||
}
|
||||
char* source_ptr = (char*)map.pData + dst_rect.left*4 + dst_rect.top*map.RowPitch;
|
||||
formatBufferDump(source_ptr, frame_data, s_recordWidth, s_recordHeight, map.RowPitch);
|
||||
AVIDump::AddFrame(frame_data);
|
||||
auto source_ptr = (const u8*)map.pData + GetTargetRectangle().left*4 + GetTargetRectangle().top*map.RowPitch;
|
||||
formatBufferDump(source_ptr, &frame_data[0], s_recordWidth, s_recordHeight, map.RowPitch);
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
D3D::context->Unmap(s_screenshot_texture, 0);
|
||||
}
|
||||
bLastFrameDumped = true;
|
||||
@ -1206,7 +1084,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
if (bLastFrameDumped && bAVIDumping)
|
||||
{
|
||||
SAFE_DELETE_ARRAY(frame_data);
|
||||
std::vector<u8>().swap(frame_data);
|
||||
w = h = 0;
|
||||
|
||||
AVIDump::Stop();
|
||||
@ -1224,11 +1102,18 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::font.DrawTextScaled(0, 0, 20, 0.0f, 0xFF00FFFF, fps);
|
||||
}
|
||||
|
||||
if (SConfig::GetInstance().m_ShowLag)
|
||||
{
|
||||
char lag[10];
|
||||
StringCchPrintfA(lag, 1000, "Lag: %llu\n", Movie::g_currentLagCount);
|
||||
D3D::font.DrawTextScaled(0, 18, 20, 0.0f, 0xFF00FFFF, lag);
|
||||
}
|
||||
|
||||
if (g_ActiveConfig.bShowInputDisplay)
|
||||
{
|
||||
char inputDisplay[1000];
|
||||
StringCchPrintfA(inputDisplay, 1000, Movie::GetInputDisplay().c_str());
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 0.0f, 0xFF00FFFF, inputDisplay);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 0.0f, 0xFF00FFFF, inputDisplay);
|
||||
}
|
||||
Renderer::DrawDebugText();
|
||||
|
||||
@ -1236,13 +1121,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
char buf[32768];
|
||||
Statistics::ToString(buf);
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 0.0f, 0xFF00FFFF, buf);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 0.0f, 0xFF00FFFF, buf);
|
||||
}
|
||||
else if (g_ActiveConfig.bOverlayProjStats)
|
||||
{
|
||||
char buf[32768];
|
||||
Statistics::ToStringProj(buf);
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 0.0f, 0xFF00FFFF, buf);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 0.0f, 0xFF00FFFF, buf);
|
||||
}
|
||||
|
||||
OSD::DrawMessages();
|
||||
@ -1264,28 +1149,18 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
bool xfbchanged = false;
|
||||
|
||||
if (s_XFB_width != fbWidth || s_XFB_height != fbHeight)
|
||||
if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
|
||||
{
|
||||
xfbchanged = true;
|
||||
s_XFB_width = fbWidth;
|
||||
s_XFB_height = fbHeight;
|
||||
if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
||||
unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
||||
FramebufferManagerBase::SetLastXfbWidth(w);
|
||||
FramebufferManagerBase::SetLastXfbHeight(h);
|
||||
}
|
||||
|
||||
// update FPS counter
|
||||
static int fpscount = 0;
|
||||
static unsigned long lasttime = 0;
|
||||
if (Common::Timer::GetTimeMs() - lasttime >= 1000)
|
||||
{
|
||||
lasttime = Common::Timer::GetTimeMs();
|
||||
s_fps = fpscount;
|
||||
fpscount = 0;
|
||||
}
|
||||
if (XFBWrited)
|
||||
++fpscount;
|
||||
s_fps = UpdateFPSCounter();
|
||||
|
||||
// Begin new frame
|
||||
// Set default viewport and scissor, for the clear to work correctly
|
||||
@ -1313,12 +1188,10 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
s_backbuffer_height = D3D::GetBackBufferHeight();
|
||||
}
|
||||
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
||||
CalculateTargetSize();
|
||||
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL);
|
||||
|
||||
@ -1468,12 +1341,32 @@ void Renderer::RestoreCull()
|
||||
|
||||
void Renderer::SetGenerationMode()
|
||||
{
|
||||
const D3D11_CULL_MODE d3dCullModes[4] =
|
||||
{
|
||||
D3D11_CULL_NONE,
|
||||
D3D11_CULL_BACK,
|
||||
D3D11_CULL_FRONT,
|
||||
D3D11_CULL_BACK
|
||||
};
|
||||
|
||||
// rastdc.FrontCounterClockwise must be false for this to work
|
||||
gx_state.rastdc.CullMode = d3dCullModes[bpmem.genMode.cullmode];
|
||||
}
|
||||
|
||||
void Renderer::SetDepthMode()
|
||||
{
|
||||
const D3D11_COMPARISON_FUNC d3dCmpFuncs[8] =
|
||||
{
|
||||
D3D11_COMPARISON_NEVER,
|
||||
D3D11_COMPARISON_LESS,
|
||||
D3D11_COMPARISON_EQUAL,
|
||||
D3D11_COMPARISON_LESS_EQUAL,
|
||||
D3D11_COMPARISON_GREATER,
|
||||
D3D11_COMPARISON_NOT_EQUAL,
|
||||
D3D11_COMPARISON_GREATER_EQUAL,
|
||||
D3D11_COMPARISON_ALWAYS
|
||||
};
|
||||
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
gx_state.depthdc.DepthEnable = TRUE;
|
||||
@ -1490,9 +1383,85 @@ void Renderer::SetDepthMode()
|
||||
|
||||
void Renderer::SetLogicOpMode()
|
||||
{
|
||||
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
|
||||
// D3D11 doesn't support logic blending, so this is a huge hack
|
||||
// TODO: Make use of D3D11.1's logic blending support
|
||||
|
||||
// 0 0x00
|
||||
// 1 Source & destination
|
||||
// 2 Source & ~destination
|
||||
// 3 Source
|
||||
// 4 ~Source & destination
|
||||
// 5 Destination
|
||||
// 6 Source ^ destination = Source & ~destination | ~Source & destination
|
||||
// 7 Source | destination
|
||||
// 8 ~(Source | destination)
|
||||
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
|
||||
// 10 ~Destination
|
||||
// 11 Source | ~destination
|
||||
// 12 ~Source
|
||||
// 13 ~Source | destination
|
||||
// 14 ~(Source & destination)
|
||||
// 15 0xff
|
||||
const D3D11_BLEND_OP d3dLogicOps[16] =
|
||||
{
|
||||
D3D11_BLEND_OP_ADD,//0
|
||||
D3D11_BLEND_OP_ADD,//1
|
||||
D3D11_BLEND_OP_SUBTRACT,//2
|
||||
D3D11_BLEND_OP_ADD,//3
|
||||
D3D11_BLEND_OP_REV_SUBTRACT,//4
|
||||
D3D11_BLEND_OP_ADD,//5
|
||||
D3D11_BLEND_OP_MAX,//6
|
||||
D3D11_BLEND_OP_ADD,//7
|
||||
D3D11_BLEND_OP_MAX,//8
|
||||
D3D11_BLEND_OP_MAX,//9
|
||||
D3D11_BLEND_OP_ADD,//10
|
||||
D3D11_BLEND_OP_ADD,//11
|
||||
D3D11_BLEND_OP_ADD,//12
|
||||
D3D11_BLEND_OP_ADD,//13
|
||||
D3D11_BLEND_OP_ADD,//14
|
||||
D3D11_BLEND_OP_ADD//15
|
||||
};
|
||||
const D3D11_BLEND d3dLogicOpSrcFactors[16] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,//0
|
||||
D3D11_BLEND_DEST_COLOR,//1
|
||||
D3D11_BLEND_ONE,//2
|
||||
D3D11_BLEND_ONE,//3
|
||||
D3D11_BLEND_DEST_COLOR,//4
|
||||
D3D11_BLEND_ZERO,//5
|
||||
D3D11_BLEND_INV_DEST_COLOR,//6
|
||||
D3D11_BLEND_INV_DEST_COLOR,//7
|
||||
D3D11_BLEND_INV_SRC_COLOR,//8
|
||||
D3D11_BLEND_INV_SRC_COLOR,//9
|
||||
D3D11_BLEND_INV_DEST_COLOR,//10
|
||||
D3D11_BLEND_ONE,//11
|
||||
D3D11_BLEND_INV_SRC_COLOR,//12
|
||||
D3D11_BLEND_INV_SRC_COLOR,//13
|
||||
D3D11_BLEND_INV_DEST_COLOR,//14
|
||||
D3D11_BLEND_ONE//15
|
||||
};
|
||||
const D3D11_BLEND d3dLogicOpDestFactors[16] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,//0
|
||||
D3D11_BLEND_ZERO,//1
|
||||
D3D11_BLEND_INV_SRC_COLOR,//2
|
||||
D3D11_BLEND_ZERO,//3
|
||||
D3D11_BLEND_ONE,//4
|
||||
D3D11_BLEND_ONE,//5
|
||||
D3D11_BLEND_INV_SRC_COLOR,//6
|
||||
D3D11_BLEND_ONE,//7
|
||||
D3D11_BLEND_INV_DEST_COLOR,//8
|
||||
D3D11_BLEND_SRC_COLOR,//9
|
||||
D3D11_BLEND_INV_DEST_COLOR,//10
|
||||
D3D11_BLEND_INV_DEST_COLOR,//11
|
||||
D3D11_BLEND_INV_SRC_COLOR,//12
|
||||
D3D11_BLEND_ONE,//13
|
||||
D3D11_BLEND_INV_SRC_COLOR,//14
|
||||
D3D11_BLEND_ONE//15
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable)
|
||||
{
|
||||
s_blendMode = 0;
|
||||
gx_state.blenddc.RenderTarget[0].BlendEnable = true;
|
||||
SetBlendOp(d3dLogicOps[bpmem.blendmode.logicmode]);
|
||||
SetSrcBlend(d3dLogicOpSrcFactors[bpmem.blendmode.logicmode]);
|
||||
@ -1516,18 +1485,32 @@ void Renderer::SetLineWidth()
|
||||
|
||||
void Renderer::SetSamplerState(int stage, int texindex)
|
||||
{
|
||||
#define TEXF_NONE 0
|
||||
#define TEXF_POINT 1
|
||||
#define TEXF_LINEAR 2
|
||||
const unsigned int d3dMipFilters[4] =
|
||||
{
|
||||
TEXF_NONE,
|
||||
TEXF_POINT,
|
||||
TEXF_LINEAR,
|
||||
TEXF_NONE, //reserved
|
||||
};
|
||||
const D3D11_TEXTURE_ADDRESS_MODE d3dClamps[4] =
|
||||
{
|
||||
D3D11_TEXTURE_ADDRESS_CLAMP,
|
||||
D3D11_TEXTURE_ADDRESS_WRAP,
|
||||
D3D11_TEXTURE_ADDRESS_MIRROR,
|
||||
D3D11_TEXTURE_ADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
const FourTexUnits &tex = bpmem.tex[texindex];
|
||||
const TexMode0 &tm0 = tex.texMode0[stage];
|
||||
const TexMode1 &tm1 = tex.texMode1[stage];
|
||||
|
||||
unsigned int mip;
|
||||
mip = (tm0.min_filter == 8) ? TEXF_NONE:d3dMipFilters[tm0.min_filter & 3];
|
||||
if ((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 4) == 0)) mip = TEXF_NONE;
|
||||
unsigned int mip = d3dMipFilters[tm0.min_filter & 3];
|
||||
|
||||
if (texindex) stage += 4;
|
||||
|
||||
// TODO: Clarify whether these values are correct
|
||||
// NOTE: since there's no "no filter" in DX11 we're using point filters in these cases
|
||||
if (g_ActiveConfig.bForceFiltering)
|
||||
{
|
||||
gx_state.sampdc[stage].Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
@ -1569,7 +1552,7 @@ void Renderer::SetSamplerState(int stage, int texindex)
|
||||
// When mipfilter is set to "none", just disable mipmapping altogether
|
||||
gx_state.sampdc[stage].MaxLOD = (mip == TEXF_NONE) ? 0.0f : (float)tm1.max_lod/16.f;
|
||||
gx_state.sampdc[stage].MinLOD = (float)tm1.min_lod/16.f;
|
||||
gx_state.sampdc[stage].MipLODBias = (float)tm0.lod_bias/32.0f;
|
||||
gx_state.sampdc[stage].MipLODBias = (s32)tm0.lod_bias/32.0f;
|
||||
}
|
||||
|
||||
void Renderer::SetInterlacingMode()
|
||||
|
@ -59,12 +59,9 @@ bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips)
|
||||
unsigned int expanded_width, unsigned int level)
|
||||
{
|
||||
D3D::ReplaceRGBATexture2D(texture->GetTex(), TextureCache::temp, width, height, expanded_width, level, usage);
|
||||
|
||||
if (autogen_mips)
|
||||
PD3DX11FilterTexture(D3D::context, texture->GetTex(), 0, D3DX11_DEFAULT);
|
||||
}
|
||||
|
||||
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||
@ -101,6 +98,9 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)entry->texture->GetSRV(), "shader resource view of a texture of the TextureCache");
|
||||
|
||||
SAFE_RELEASE(pTexture);
|
||||
|
||||
if (tex_levels != 1)
|
||||
entry->Load(width, height, expanded_width, 0);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ private:
|
||||
~TCacheEntry();
|
||||
|
||||
void Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int levels, bool autogen_mips = false);
|
||||
unsigned int expanded_width, unsigned int levels);
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
|
@ -39,33 +39,41 @@ namespace DX11
|
||||
{
|
||||
|
||||
// TODO: Find sensible values for these two
|
||||
const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE*2 * 16;
|
||||
const UINT IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16 * sizeof(u16);
|
||||
const UINT VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16;
|
||||
const UINT MAXVBUFFER_COUNT = 2;
|
||||
|
||||
void VertexManager::CreateDeviceObjects()
|
||||
{
|
||||
D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(IBUFFER_SIZE,
|
||||
D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_indexBuffer)),
|
||||
"Failed to create index buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_indexBuffer, "index buffer of VertexManager");
|
||||
|
||||
bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bufdesc.ByteWidth = VBUFFER_SIZE;
|
||||
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertexBuffer)),
|
||||
"Failed to create vertex buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertexBuffer, "vertex buffer of VertexManager");
|
||||
|
||||
m_indexBufferCursor = 0;
|
||||
m_vertexBufferCursor = 0;
|
||||
m_vertexDrawOffset = 0;
|
||||
|
||||
m_triangleDrawIndex = 0;
|
||||
m_lineDrawIndex = 0;
|
||||
m_pointDrawIndex = 0;
|
||||
|
||||
m_indexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT];
|
||||
m_vertexBuffers = new PID3D11Buffer[MAXVBUFFER_COUNT];
|
||||
for (m_activeIndexBuffer = 0; m_activeIndexBuffer < MAXVBUFFER_COUNT; m_activeIndexBuffer++)
|
||||
{
|
||||
m_indexBuffers[m_activeIndexBuffer] = NULL;
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_indexBuffers[m_activeIndexBuffer])),
|
||||
"Failed to create index buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_indexBuffers[m_activeIndexBuffer], "index buffer of VertexManager");
|
||||
}
|
||||
bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bufdesc.ByteWidth = VBUFFER_SIZE;
|
||||
for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++)
|
||||
{
|
||||
m_vertexBuffers[m_activeVertexBuffer] = NULL;
|
||||
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, &m_vertexBuffers[m_activeVertexBuffer])),
|
||||
"Failed to create vertex buffer.");
|
||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vertexBuffers[m_activeVertexBuffer], "Vertex buffer of VertexManager");
|
||||
}
|
||||
m_activeVertexBuffer = 0;
|
||||
m_activeIndexBuffer = 0;
|
||||
m_indexBufferCursor = IBUFFER_SIZE;
|
||||
m_vertexBufferCursor = VBUFFER_SIZE;
|
||||
m_lineShader.Init();
|
||||
m_pointShader.Init();
|
||||
}
|
||||
@ -74,9 +82,12 @@ void VertexManager::DestroyDeviceObjects()
|
||||
{
|
||||
m_pointShader.Shutdown();
|
||||
m_lineShader.Shutdown();
|
||||
|
||||
SAFE_RELEASE(m_vertexBuffer);
|
||||
SAFE_RELEASE(m_indexBuffer);
|
||||
for (m_activeVertexBuffer = 0; m_activeVertexBuffer < MAXVBUFFER_COUNT; m_activeVertexBuffer++)
|
||||
{
|
||||
SAFE_RELEASE(m_vertexBuffers[m_activeVertexBuffer]);
|
||||
SAFE_RELEASE(m_indexBuffers[m_activeVertexBuffer]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VertexManager::VertexManager()
|
||||
@ -94,42 +105,41 @@ void VertexManager::LoadBuffers()
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
|
||||
UINT vSize = UINT(s_pCurBufferPointer - LocalVBuffer);
|
||||
D3D11_MAP MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
if (m_vertexBufferCursor + vSize >= VBUFFER_SIZE)
|
||||
{
|
||||
// Wrap around
|
||||
D3D::context->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
m_activeVertexBuffer = (m_activeVertexBuffer + 1) % MAXVBUFFER_COUNT;
|
||||
m_vertexBufferCursor = 0;
|
||||
MapType = D3D11_MAP_WRITE_DISCARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Append data
|
||||
D3D::context->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
}
|
||||
|
||||
D3D::context->Map(m_vertexBuffers[m_activeVertexBuffer], 0, MapType, 0, &map);
|
||||
|
||||
memcpy((u8*)map.pData + m_vertexBufferCursor, LocalVBuffer, vSize);
|
||||
D3D::context->Unmap(m_vertexBuffer, 0);
|
||||
D3D::context->Unmap(m_vertexBuffers[m_activeVertexBuffer], 0);
|
||||
m_vertexDrawOffset = m_vertexBufferCursor;
|
||||
m_vertexBufferCursor += vSize;
|
||||
|
||||
UINT iCount = IndexGenerator::GetTriangleindexLen() +
|
||||
IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
||||
if (m_indexBufferCursor + iCount >= IBUFFER_SIZE/2)
|
||||
MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
if (m_indexBufferCursor + iCount >= (IBUFFER_SIZE / sizeof(u16)))
|
||||
{
|
||||
// Wrap around
|
||||
D3D::context->Map(m_indexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
m_activeIndexBuffer = (m_activeIndexBuffer + 1) % MAXVBUFFER_COUNT;
|
||||
m_indexBufferCursor = 0;
|
||||
MapType = D3D11_MAP_WRITE_DISCARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Append data
|
||||
D3D::context->Map(m_indexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
}
|
||||
D3D::context->Map(m_indexBuffers[m_activeIndexBuffer], 0, MapType, 0, &map);
|
||||
|
||||
m_triangleDrawIndex = m_indexBufferCursor;
|
||||
m_lineDrawIndex = m_triangleDrawIndex + IndexGenerator::GetTriangleindexLen();
|
||||
m_pointDrawIndex = m_lineDrawIndex + IndexGenerator::GetLineindexLen();
|
||||
memcpy((u16*)map.pData + m_triangleDrawIndex, TIBuffer, 2*IndexGenerator::GetTriangleindexLen());
|
||||
memcpy((u16*)map.pData + m_lineDrawIndex, LIBuffer, 2*IndexGenerator::GetLineindexLen());
|
||||
memcpy((u16*)map.pData + m_pointDrawIndex, PIBuffer, 2*IndexGenerator::GetPointindexLen());
|
||||
D3D::context->Unmap(m_indexBuffer, 0);
|
||||
memcpy((u16*)map.pData + m_triangleDrawIndex, TIBuffer, sizeof(u16) * IndexGenerator::GetTriangleindexLen());
|
||||
memcpy((u16*)map.pData + m_lineDrawIndex, LIBuffer, sizeof(u16) * IndexGenerator::GetLineindexLen());
|
||||
memcpy((u16*)map.pData + m_pointDrawIndex, PIBuffer, sizeof(u16) * IndexGenerator::GetPointindexLen());
|
||||
D3D::context->Unmap(m_indexBuffers[m_activeIndexBuffer], 0);
|
||||
m_indexBufferCursor += iCount;
|
||||
}
|
||||
|
||||
@ -139,9 +149,9 @@ static const float LINE_PT_TEX_OFFSETS[8] = {
|
||||
|
||||
void VertexManager::Draw(UINT stride)
|
||||
{
|
||||
D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &m_vertexDrawOffset);
|
||||
D3D::context->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
|
||||
D3D::context->IASetVertexBuffers(0, 1, &m_vertexBuffers[m_activeVertexBuffer], &stride, &m_vertexDrawOffset);
|
||||
D3D::context->IASetIndexBuffer(m_indexBuffers[m_activeIndexBuffer], DXGI_FORMAT_R16_UINT, 0);
|
||||
|
||||
if (IndexGenerator::GetNumTriangles() > 0)
|
||||
{
|
||||
D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
@ -226,8 +236,8 @@ void VertexManager::vFlush()
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8),
|
||||
tex.texMode1[i&3].max_lod >> 4,
|
||||
(tex.texMode0[i&3].min_filter & 3),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
tex.texImage1[i&3].image_type);
|
||||
|
||||
if (tentry)
|
||||
@ -259,12 +269,11 @@ void VertexManager::vFlush()
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||
goto shader_fail;
|
||||
}
|
||||
|
||||
LoadBuffers();
|
||||
unsigned int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
||||
g_renderer->ApplyState(useDstAlpha);
|
||||
LoadBuffers();
|
||||
|
||||
g_renderer->ResumePixelPerf(false);
|
||||
Draw(stride);
|
||||
g_renderer->PausePixelPerf(false);
|
||||
|
@ -32,10 +32,11 @@ public:
|
||||
~VertexManager();
|
||||
|
||||
NativeVertexFormat* CreateNativeVertexFormat();
|
||||
|
||||
private:
|
||||
void CreateDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
|
||||
private:
|
||||
|
||||
void LoadBuffers();
|
||||
void Draw(UINT stride);
|
||||
// temp
|
||||
@ -46,9 +47,12 @@ private:
|
||||
UINT m_vertexDrawOffset;
|
||||
UINT m_triangleDrawIndex;
|
||||
UINT m_lineDrawIndex;
|
||||
UINT m_pointDrawIndex;
|
||||
ID3D11Buffer* m_indexBuffer;
|
||||
ID3D11Buffer* m_vertexBuffer;
|
||||
UINT m_pointDrawIndex;
|
||||
UINT m_activeVertexBuffer;
|
||||
UINT m_activeIndexBuffer;
|
||||
typedef ID3D11Buffer* PID3D11Buffer;
|
||||
PID3D11Buffer* m_indexBuffers;
|
||||
PID3D11Buffer* m_vertexBuffers;
|
||||
|
||||
LineGeometryShader m_lineShader;
|
||||
PointGeometryShader m_pointShader;
|
||||
|
@ -90,6 +90,7 @@ void InitBackendInfo()
|
||||
|
||||
g_Config.backend_info.APIType = API_D3D11;
|
||||
g_Config.backend_info.bUseRGBATextures = true; // the GX formats barely match any D3D11 formats
|
||||
g_Config.backend_info.bUseMinimalMipCount = true;
|
||||
g_Config.backend_info.bSupports3DVision = false;
|
||||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
||||
|
@ -149,15 +149,12 @@ XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, un
|
||||
|
||||
void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
|
||||
{
|
||||
const float scaleX = Renderer::GetXFBScaleX();
|
||||
const float scaleY = Renderer::GetXFBScaleY();
|
||||
|
||||
TargetRectangle targetSource;
|
||||
|
||||
targetSource.top = (int)(sourceRc.top *scaleY);
|
||||
targetSource.bottom = (int)(sourceRc.bottom *scaleY);
|
||||
targetSource.left = (int)(sourceRc.left *scaleX);
|
||||
targetSource.right = (int)(sourceRc.right * scaleX);
|
||||
targetSource.top = ScaleToVirtualXfbHeight(sourceRc.top, Renderer::GetBackbufferHeight());
|
||||
targetSource.bottom = ScaleToVirtualXfbHeight(sourceRc.bottom, Renderer::GetBackbufferHeight());
|
||||
targetSource.left = ScaleToVirtualXfbWidth(sourceRc.left, Renderer::GetBackbufferWidth());
|
||||
targetSource.right = ScaleToVirtualXfbWidth(sourceRc.right, Renderer::GetBackbufferWidth());
|
||||
|
||||
*width = targetSource.right - targetSource.left;
|
||||
*height = targetSource.bottom - targetSource.top;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "D3DBase.h"
|
||||
|
||||
#include "x64Emitter.h"
|
||||
#include "ABI.h"
|
||||
#include "x64ABI.h"
|
||||
#include "MemoryUtil.h"
|
||||
#include "VertexShaderGen.h"
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include <list>
|
||||
#include <d3dx9.h>
|
||||
#include <strsafe.h>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "Common.h"
|
||||
@ -54,6 +53,11 @@
|
||||
#include "Core.h"
|
||||
#include "Movie.h"
|
||||
#include "BPFunctions.h"
|
||||
#include "FPSCounter.h"
|
||||
#include "ConfigManager.h"
|
||||
|
||||
#include <strsafe.h>
|
||||
|
||||
|
||||
namespace DX9
|
||||
{
|
||||
@ -69,148 +73,6 @@ static char *st;
|
||||
static LPDIRECT3DSURFACE9 ScreenShootMEMSurface = NULL;
|
||||
|
||||
|
||||
// State translation lookup tables
|
||||
static const D3DBLEND d3dSrcFactors[8] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_SRCALPHA,
|
||||
D3DBLEND_INVSRCALPHA,
|
||||
D3DBLEND_DESTALPHA,
|
||||
D3DBLEND_INVDESTALPHA
|
||||
};
|
||||
|
||||
static const D3DBLEND d3dDestFactors[8] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_SRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_SRCALPHA,
|
||||
D3DBLEND_INVSRCALPHA,
|
||||
D3DBLEND_DESTALPHA,
|
||||
D3DBLEND_INVDESTALPHA
|
||||
};
|
||||
|
||||
// 0 0x00
|
||||
// 1 Source & destination
|
||||
// 2 Source & ~destination
|
||||
// 3 Source
|
||||
// 4 ~Source & destination
|
||||
// 5 Destination
|
||||
// 6 Source ^ destination = Source & ~destination | ~Source & destination
|
||||
// 7 Source | destination
|
||||
|
||||
// 8 ~(Source | destination)
|
||||
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
|
||||
// 10 ~Destination
|
||||
// 11 Source | ~destination
|
||||
// 12 ~Source
|
||||
// 13 ~Source | destination
|
||||
// 14 ~(Source & destination)
|
||||
// 15 0xff
|
||||
|
||||
static const D3DBLENDOP d3dLogicOpop[16] =
|
||||
{
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_SUBTRACT,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_REVSUBTRACT,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_ADD,
|
||||
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD
|
||||
};
|
||||
|
||||
static const D3DBLEND d3dLogicOpSrcFactors[16] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_ONE
|
||||
};
|
||||
|
||||
static const D3DBLEND d3dLogicOpDestFactors[16] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_SRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE
|
||||
};
|
||||
|
||||
static const D3DCULL d3dCullModes[4] =
|
||||
{
|
||||
D3DCULL_NONE,
|
||||
D3DCULL_CCW,
|
||||
D3DCULL_CW,
|
||||
D3DCULL_CCW
|
||||
};
|
||||
|
||||
static const D3DCMPFUNC d3dCmpFuncs[8] =
|
||||
{
|
||||
D3DCMP_NEVER,
|
||||
D3DCMP_LESS,
|
||||
D3DCMP_EQUAL,
|
||||
D3DCMP_LESSEQUAL,
|
||||
D3DCMP_GREATER,
|
||||
D3DCMP_NOTEQUAL,
|
||||
D3DCMP_GREATEREQUAL,
|
||||
D3DCMP_ALWAYS
|
||||
};
|
||||
|
||||
static const D3DTEXTUREFILTERTYPE d3dMipFilters[4] =
|
||||
{
|
||||
D3DTEXF_NONE,
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_NONE, //reserved
|
||||
};
|
||||
|
||||
static const D3DTEXTUREADDRESS d3dClamps[4] =
|
||||
{
|
||||
D3DTADDRESS_CLAMP,
|
||||
D3DTADDRESS_WRAP,
|
||||
D3DTADDRESS_MIRROR,
|
||||
D3DTADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
void SetupDeviceObjects()
|
||||
{
|
||||
D3D::font.Init();
|
||||
@ -224,6 +86,7 @@ void SetupDeviceObjects()
|
||||
// To avoid shader compilation stutters, read back all shaders from cache.
|
||||
VertexShaderCache::Init();
|
||||
PixelShaderCache::Init();
|
||||
g_vertex_manager->CreateDeviceObjects();
|
||||
// Texture cache will recreate themselves over time.
|
||||
}
|
||||
|
||||
@ -242,11 +105,14 @@ void TeardownDeviceObjects()
|
||||
VertexShaderCache::Shutdown();
|
||||
PixelShaderCache::Shutdown();
|
||||
TextureConverter::Shutdown();
|
||||
g_vertex_manager->DestroyDeviceObjects();
|
||||
}
|
||||
|
||||
// Init functions
|
||||
Renderer::Renderer()
|
||||
{
|
||||
InitFPSCounter();
|
||||
|
||||
st = new char[32768];
|
||||
|
||||
int fullScreenRes, x, y, w_temp, h_temp;
|
||||
@ -274,19 +140,16 @@ Renderer::Renderer()
|
||||
s_backbuffer_width = D3D::GetBackBufferWidth();
|
||||
s_backbuffer_height = D3D::GetBackBufferHeight();
|
||||
|
||||
s_XFB_width = MAX_XFB_WIDTH;
|
||||
s_XFB_height = MAX_XFB_HEIGHT;
|
||||
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
|
||||
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
|
||||
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
s_LastAA = g_ActiveConfig.iMultisampleMode;
|
||||
int SupersampleCoeficient = (s_LastAA % 3) + 1;
|
||||
|
||||
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
||||
CalculateTargetSize(SupersampleCoeficient);
|
||||
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height, SupersampleCoeficient);
|
||||
|
||||
// Make sure to use valid texture sizes
|
||||
D3D::FixTextureSize(s_target_width, s_target_height);
|
||||
@ -353,11 +216,11 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
|
||||
}
|
||||
|
||||
void formatBufferDump(const char *in, char *out, int w, int h, int p)
|
||||
void formatBufferDump(const u8* in, u8* out, int w, int h, int p)
|
||||
{
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
const char *line = in + (h - y - 1) * p;
|
||||
auto line = in + (h - y - 1) * p;
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
memcpy(out, line, 3);
|
||||
@ -423,10 +286,13 @@ void Renderer::SetColorMask()
|
||||
{
|
||||
// Only enable alpha channel if it's supported by the current EFB format
|
||||
DWORD color_mask = 0;
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
color_mask = D3DCOLORWRITEENABLE_ALPHA;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
color_mask |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
||||
if (bpmem.alpha_test.TestResult() != AlphaTest::FAIL)
|
||||
{
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
color_mask = D3DCOLORWRITEENABLE_ALPHA;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
color_mask |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
||||
}
|
||||
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, color_mask);
|
||||
}
|
||||
|
||||
@ -701,8 +567,8 @@ void Renderer::UpdateViewport(Matrix44& vpCorrection)
|
||||
// If GX viewport is off the render target, we must clamp our viewport
|
||||
// within the bounds. Use the correction matrix to compensate.
|
||||
ViewportCorrectionMatrix(vpCorrection,
|
||||
intendedX, intendedY, intendedWd, intendedHt,
|
||||
X, Y, Wd, Ht);
|
||||
(float)intendedX, (float)intendedY, (float)intendedWd, (float)intendedHt,
|
||||
(float)X, (float)Y, (float)Wd, (float)Ht);
|
||||
|
||||
D3DVIEWPORT9 vp;
|
||||
vp.X = X;
|
||||
@ -788,6 +654,32 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
|
||||
|
||||
void Renderer::SetBlendMode(bool forceUpdate)
|
||||
{
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
const D3DBLEND d3dSrcFactors[8] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_SRCALPHA,
|
||||
D3DBLEND_INVSRCALPHA,
|
||||
(target_has_alpha) ? D3DBLEND_DESTALPHA : D3DBLEND_ONE,
|
||||
(target_has_alpha) ? D3DBLEND_INVDESTALPHA : D3DBLEND_ZERO
|
||||
};
|
||||
const D3DBLEND d3dDestFactors[8] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_SRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_SRCALPHA,
|
||||
D3DBLEND_INVSRCALPHA,
|
||||
(target_has_alpha) ? D3DBLEND_DESTALPHA : D3DBLEND_ONE,
|
||||
(target_has_alpha) ? D3DBLEND_INVDESTALPHA : D3DBLEND_ZERO
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable && !forceUpdate)
|
||||
return;
|
||||
|
||||
@ -800,8 +692,8 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)));
|
||||
if (bpmem.blendmode.blendenable && (!( bpmem.blendmode.srcfactor == 1 && bpmem.blendmode.dstfactor == 0)))
|
||||
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, bpmem.blendmode.blendenable);
|
||||
if (bpmem.blendmode.blendenable)
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
||||
D3D::SetRenderState(D3DRS_SRCBLEND, d3dSrcFactors[bpmem.blendmode.srcfactor]);
|
||||
@ -831,25 +723,22 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
|
||||
// This function has the final picture. We adjust the aspect ratio here.
|
||||
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
|
||||
{
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight)
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
AVIDump::AddFrame(frame_data);
|
||||
if (g_ActiveConfig.bDumpFrames && !frame_data.empty())
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
}
|
||||
// this function is called after the XFB field is changed, not after
|
||||
// EFB is copied to XFB. In this way, flickering is reduced in games
|
||||
// and seems to also give more FPS in ZTP
|
||||
|
||||
if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2;
|
||||
u32 xfbCount = 0;
|
||||
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
||||
if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB)
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
AVIDump::AddFrame(frame_data);
|
||||
if (g_ActiveConfig.bDumpFrames && !frame_data.empty())
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
@ -882,8 +771,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::dev->SetDepthStencilSurface(NULL);
|
||||
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
||||
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
D3DVIEWPORT9 vp;
|
||||
|
||||
// Clear full target screen (edges, borders etc)
|
||||
@ -903,10 +791,10 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
|
||||
}
|
||||
|
||||
int X = dst_rect.left;
|
||||
int Y = dst_rect.top;
|
||||
int Width = dst_rect.right - dst_rect.left;
|
||||
int Height = dst_rect.bottom - dst_rect.top;
|
||||
int X = GetTargetRectangle().left;
|
||||
int Y = GetTargetRectangle().top;
|
||||
int Width = GetTargetRectangle().right - GetTargetRectangle().left;
|
||||
int Height = GetTargetRectangle().bottom - GetTargetRectangle().top;
|
||||
|
||||
// Sanity check
|
||||
if (X < 0) X = 0;
|
||||
@ -949,7 +837,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
MathUtil::Rectangle<float> drawRc;
|
||||
|
||||
if (!g_ActiveConfig.bUseRealXFB)
|
||||
if (g_ActiveConfig.bUseRealXFB)
|
||||
{
|
||||
drawRc.top = -1;
|
||||
drawRc.bottom = 1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use virtual xfb with offset
|
||||
int xfbHeight = xfbSource->srcHeight;
|
||||
@ -963,20 +858,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
// The following code disables auto stretch. Kept for reference.
|
||||
// scale draw area for a 1 to 1 pixel mapping with the draw target
|
||||
//float vScale = (float)fbHeight / (float)dst_rect.GetHeight();
|
||||
//float hScale = (float)fbWidth / (float)dst_rect.GetWidth();
|
||||
//float vScale = (float)fbHeight / (float)GetTargetRectangle().GetHeight();
|
||||
//float hScale = (float)fbWidth / (float)GetTargetRectangle().GetWidth();
|
||||
//drawRc.top *= vScale;
|
||||
//drawRc.bottom *= vScale;
|
||||
//drawRc.left *= hScale;
|
||||
//drawRc.right *= hScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawRc.top = -1;
|
||||
drawRc.bottom = 1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
|
||||
xfbSource->Draw(sourceRc, drawRc, Width, Height);
|
||||
}
|
||||
@ -1013,7 +901,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (s_bScreenshot)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||
SaveScreenshot(s_sScreenshotName, dst_rect);
|
||||
SaveScreenshot(s_sScreenshotName, GetTargetRectangle());
|
||||
s_bScreenshot = false;
|
||||
}
|
||||
|
||||
@ -1027,8 +915,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
HRESULT hr = D3D::dev->GetRenderTargetData(D3D::GetBackBufferSurface(),ScreenShootMEMSurface);
|
||||
if (!bLastFrameDumped)
|
||||
{
|
||||
s_recordWidth = dst_rect.GetWidth();
|
||||
s_recordHeight = dst_rect.GetHeight();
|
||||
s_recordWidth = GetTargetRectangle().GetWidth();
|
||||
s_recordHeight = GetTargetRectangle().GetHeight();
|
||||
bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight);
|
||||
if (!bAVIDumping)
|
||||
{
|
||||
@ -1045,17 +933,16 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (bAVIDumping)
|
||||
{
|
||||
D3DLOCKED_RECT rect;
|
||||
if (SUCCEEDED(ScreenShootMEMSurface->LockRect(&rect, dst_rect.AsRECT(), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY)))
|
||||
if (SUCCEEDED(ScreenShootMEMSurface->LockRect(&rect, GetTargetRectangle().AsRECT(), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY)))
|
||||
{
|
||||
if (!frame_data || w != s_recordWidth || h != s_recordHeight)
|
||||
if (frame_data.empty() || w != s_recordWidth || h != s_recordHeight)
|
||||
{
|
||||
delete[] frame_data;
|
||||
frame_data = new char[3 * s_recordWidth * s_recordHeight];
|
||||
frame_data.resize(3 * s_recordWidth * s_recordHeight);
|
||||
w = s_recordWidth;
|
||||
h = s_recordHeight;
|
||||
}
|
||||
formatBufferDump((const char*)rect.pBits, frame_data, s_recordWidth, s_recordHeight, rect.Pitch);
|
||||
AVIDump::AddFrame(frame_data);
|
||||
formatBufferDump((const u8*)rect.pBits, &frame_data[0], s_recordWidth, s_recordHeight, rect.Pitch);
|
||||
AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight);
|
||||
ScreenShootMEMSurface->UnlockRect();
|
||||
}
|
||||
}
|
||||
@ -1065,12 +952,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
if (bLastFrameDumped && bAVIDumping)
|
||||
{
|
||||
if (frame_data)
|
||||
{
|
||||
delete[] frame_data;
|
||||
frame_data = 0;
|
||||
w = h = 0;
|
||||
}
|
||||
std::vector<u8>().swap(frame_data);
|
||||
w = h = 0;
|
||||
AVIDump::Stop();
|
||||
bAVIDumping = false;
|
||||
OSD::AddMessage("Stop dumping frames to AVI", 2000);
|
||||
@ -1086,28 +969,36 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::font.DrawTextScaled(0, 0, 20, 20, 0.0f, 0xFF00FFFF, fps);
|
||||
}
|
||||
|
||||
if (SConfig::GetInstance().m_ShowLag)
|
||||
{
|
||||
char lag[10];
|
||||
StringCchPrintfA(lag, 1000, "Lag: %llu\n", Movie::g_currentLagCount);
|
||||
D3D::font.DrawTextScaled(0, 18, 20, 20, 0.0f, 0xFF00FFFF, lag);
|
||||
}
|
||||
|
||||
if (g_ActiveConfig.bShowInputDisplay)
|
||||
{
|
||||
char inputDisplay[1000];
|
||||
StringCchPrintfA(inputDisplay, 1000, Movie::GetInputDisplay().c_str());
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 20, 0.0f, 0xFF00FFFF, inputDisplay);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 20, 0.0f, 0xFF00FFFF, inputDisplay);
|
||||
}
|
||||
|
||||
Renderer::DrawDebugText();
|
||||
|
||||
if (g_ActiveConfig.bOverlayStats)
|
||||
{
|
||||
Statistics::ToString(st);
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 20, 0.0f, 0xFF00FFFF, st);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 20, 0.0f, 0xFF00FFFF, st);
|
||||
}
|
||||
else if (g_ActiveConfig.bOverlayProjStats)
|
||||
{
|
||||
Statistics::ToStringProj(st);
|
||||
D3D::font.DrawTextScaled(0, 30, 20, 20, 0.0f, 0xFF00FFFF, st);
|
||||
D3D::font.DrawTextScaled(0, 36, 20, 20, 0.0f, 0xFF00FFFF, st);
|
||||
}
|
||||
|
||||
OSD::DrawMessages();
|
||||
D3D::EndFrame();
|
||||
frameCount++;
|
||||
++frameCount;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true);
|
||||
|
||||
@ -1124,15 +1015,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
bool xfbchanged = false;
|
||||
|
||||
if (s_XFB_width != fbWidth || s_XFB_height != fbHeight)
|
||||
if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
|
||||
{
|
||||
xfbchanged = true;
|
||||
s_XFB_width = fbWidth;
|
||||
s_XFB_height = fbHeight;
|
||||
if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
||||
unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
||||
FramebufferManagerBase::SetLastXfbWidth(w);
|
||||
FramebufferManagerBase::SetLastXfbHeight(h);
|
||||
}
|
||||
|
||||
u32 newAA = g_ActiveConfig.iMultisampleMode;
|
||||
@ -1141,14 +1030,12 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
s_LastAA = newAA;
|
||||
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
int SupersampleCoeficient = (s_LastAA % 3) + 1;
|
||||
|
||||
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
||||
CalculateTargetSize(SupersampleCoeficient);
|
||||
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height, SupersampleCoeficient);
|
||||
|
||||
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
||||
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
|
||||
@ -1168,20 +1055,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
|
||||
}
|
||||
|
||||
// Place messages on the picture, then copy it to the screen
|
||||
// ---------------------------------------------------------------------
|
||||
// Count FPS.
|
||||
// -------------
|
||||
static int fpscount = 0;
|
||||
static unsigned long lasttime = 0;
|
||||
if (Common::Timer::GetTimeMs() - lasttime >= 1000)
|
||||
{
|
||||
lasttime = Common::Timer::GetTimeMs();
|
||||
s_fps = fpscount;
|
||||
fpscount = 0;
|
||||
}
|
||||
if (XFBWrited)
|
||||
++fpscount;
|
||||
s_fps = UpdateFPSCounter();
|
||||
|
||||
// Begin new frame
|
||||
// Set default viewport and scissor, for the clear to work correctly
|
||||
@ -1205,8 +1080,17 @@ void Renderer::ApplyState(bool bUseDstAlpha)
|
||||
{
|
||||
if (bUseDstAlpha)
|
||||
{
|
||||
// TODO: WTF is this crap? We're enabling color writing regardless of the actual GPU state here...
|
||||
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
||||
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
|
||||
if(bpmem.zmode.testenable && bpmem.zmode.updateenable)
|
||||
{
|
||||
//This is needed to draw to the correct pixels in multi-pass algorithms
|
||||
//this avoid z-figthing and grants that you write to the same pixels
|
||||
//affected by the last pass
|
||||
D3D::ChangeRenderState(D3DRS_ZWRITEENABLE, false);
|
||||
D3D::ChangeRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1214,7 +1098,11 @@ void Renderer::RestoreState()
|
||||
{
|
||||
D3D::RefreshRenderState(D3DRS_COLORWRITEENABLE);
|
||||
D3D::RefreshRenderState(D3DRS_ALPHABLENDENABLE);
|
||||
|
||||
if(bpmem.zmode.testenable && bpmem.zmode.updateenable)
|
||||
{
|
||||
D3D::RefreshRenderState(D3DRS_ZWRITEENABLE);
|
||||
D3D::RefreshRenderState(D3DRS_ZFUNC);
|
||||
}
|
||||
// TODO: Enable this code. Caused glitches for me however (neobrain)
|
||||
// for (unsigned int i = 0; i < 8; ++i)
|
||||
// D3D::dev->SetTexture(i, NULL);
|
||||
@ -1252,11 +1140,31 @@ void Renderer::RestoreAPIState()
|
||||
|
||||
void Renderer::SetGenerationMode()
|
||||
{
|
||||
const D3DCULL d3dCullModes[4] =
|
||||
{
|
||||
D3DCULL_NONE,
|
||||
D3DCULL_CCW,
|
||||
D3DCULL_CW,
|
||||
D3DCULL_CCW
|
||||
};
|
||||
|
||||
D3D::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
||||
}
|
||||
|
||||
void Renderer::SetDepthMode()
|
||||
{
|
||||
const D3DCMPFUNC d3dCmpFuncs[8] =
|
||||
{
|
||||
D3DCMP_NEVER,
|
||||
D3DCMP_LESS,
|
||||
D3DCMP_EQUAL,
|
||||
D3DCMP_LESSEQUAL,
|
||||
D3DCMP_GREATER,
|
||||
D3DCMP_NOTEQUAL,
|
||||
D3DCMP_GREATEREQUAL,
|
||||
D3DCMP_ALWAYS
|
||||
};
|
||||
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_ZENABLE, TRUE);
|
||||
@ -1273,7 +1181,83 @@ void Renderer::SetDepthMode()
|
||||
|
||||
void Renderer::SetLogicOpMode()
|
||||
{
|
||||
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
|
||||
// D3D9 doesn't support logic blending, so this is a huge hack
|
||||
|
||||
// 0 0x00
|
||||
// 1 Source & destination
|
||||
// 2 Source & ~destination
|
||||
// 3 Source
|
||||
// 4 ~Source & destination
|
||||
// 5 Destination
|
||||
// 6 Source ^ destination = Source & ~destination | ~Source & destination
|
||||
// 7 Source | destination
|
||||
// 8 ~(Source | destination)
|
||||
// 9 ~(Source ^ destination) = ~Source & ~destination | Source & destination
|
||||
// 10 ~Destination
|
||||
// 11 Source | ~destination
|
||||
// 12 ~Source
|
||||
// 13 ~Source | destination
|
||||
// 14 ~(Source & destination)
|
||||
// 15 0xff
|
||||
const D3DBLENDOP d3dLogicOpop[16] =
|
||||
{
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_SUBTRACT,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_REVSUBTRACT,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_MAX,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD,
|
||||
D3DBLENDOP_ADD
|
||||
};
|
||||
const D3DBLEND d3dLogicOpSrcFactors[16] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_DESTCOLOR,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_ONE
|
||||
};
|
||||
const D3DBLEND d3dLogicOpDestFactors[16] =
|
||||
{
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ZERO,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_SRCCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVDESTCOLOR,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE,
|
||||
D3DBLEND_INVSRCCOLOR,
|
||||
D3DBLEND_ONE
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable)
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, true);
|
||||
D3D::SetRenderState(D3DRS_BLENDOP, d3dLogicOpop[bpmem.blendmode.logicmode]);
|
||||
@ -1301,6 +1285,21 @@ void Renderer::SetLineWidth()
|
||||
|
||||
void Renderer::SetSamplerState(int stage, int texindex)
|
||||
{
|
||||
const D3DTEXTUREFILTERTYPE d3dMipFilters[4] =
|
||||
{
|
||||
D3DTEXF_NONE,
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_NONE, //reserved
|
||||
};
|
||||
const D3DTEXTUREADDRESS d3dClamps[4] =
|
||||
{
|
||||
D3DTADDRESS_CLAMP,
|
||||
D3DTADDRESS_WRAP,
|
||||
D3DTADDRESS_MIRROR,
|
||||
D3DTADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
const FourTexUnits &tex = bpmem.tex[texindex];
|
||||
const TexMode0 &tm0 = tex.texMode0[stage];
|
||||
const TexMode1 &tm1 = tex.texMode1[stage];
|
||||
@ -1314,13 +1313,11 @@ void Renderer::SetSamplerState(int stage, int texindex)
|
||||
{
|
||||
min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mip = (tm0.min_filter == 8) ? D3DTEXF_NONE : d3dMipFilters[tm0.min_filter & 3];
|
||||
if((tm0.min_filter & 3) && (tm0.min_filter != 8) && ((tm1.max_lod >> 4) == 0))
|
||||
mip = D3DTEXF_NONE;
|
||||
mip = d3dMipFilters[tm0.min_filter & 3];
|
||||
}
|
||||
if (texindex)
|
||||
stage += 4;
|
||||
|
||||
|
||||
if (mag == D3DTEXF_LINEAR && min == D3DTEXF_LINEAR && g_ActiveConfig.iMaxAnisotropy)
|
||||
{
|
||||
min = D3DTEXF_ANISOTROPIC;
|
||||
@ -1331,8 +1328,8 @@ void Renderer::SetSamplerState(int stage, int texindex)
|
||||
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
|
||||
//float SuperSampleCoeficient = (s_LastAA < 3)? s_LastAA + 1 : s_LastAA - 1;// uncoment this changes to conserve detail when incresing ssaa level
|
||||
float lodbias = (tm0.lod_bias / 32.0f);// + (s_LastAA)?(log(SuperSampleCoeficient) / log(2.0f)):0;
|
||||
|
||||
float lodbias = (s32)tm0.lod_bias / 32.0f;
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MIPMAPLODBIAS, *(DWORD*)&lodbias);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MAXMIPLEVEL, tm1.min_lod >> 4);
|
||||
}
|
||||
|
@ -72,10 +72,9 @@ bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips)
|
||||
unsigned int expanded_width, unsigned int level)
|
||||
{
|
||||
D3D::ReplaceTexture2D(texture, temp, width, height, expanded_width, d3d_fmt, swap_r_b, level);
|
||||
// D3D9 will automatically generate mip maps if necessary
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
@ -227,6 +226,8 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, u
|
||||
TCacheEntry* entry = new TCacheEntry(D3D::CreateTexture2D(temp, width, height, expanded_width, d3d_fmt, swap_r_b, tex_levels));
|
||||
entry->swap_r_b = swap_r_b;
|
||||
entry->d3d_fmt = d3d_fmt;
|
||||
|
||||
entry->Load(width, height, expanded_width, 0);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ private:
|
||||
~TCacheEntry();
|
||||
|
||||
void Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int levels, bool autogen_mips = false);
|
||||
unsigned int expanded_width, unsigned int levels);
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
|
@ -39,9 +39,12 @@
|
||||
|
||||
// internal state for loading vertices
|
||||
extern NativeVertexFormat *g_nativeVertexFmt;
|
||||
|
||||
namespace DX9
|
||||
{
|
||||
//This are the initially requeted size for the buffers expresed in elements
|
||||
const u32 IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * 16;
|
||||
const u32 VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE * 16;
|
||||
const u32 MAXVBUFFER_COUNT = 2;
|
||||
|
||||
inline void DumpBadShaders()
|
||||
{
|
||||
@ -62,8 +65,202 @@ inline void DumpBadShaders()
|
||||
#endif
|
||||
}
|
||||
|
||||
void VertexManager::Draw(int stride)
|
||||
void VertexManager::CreateDeviceObjects()
|
||||
{
|
||||
NumVBuffers = 0;
|
||||
VBuffers = NULL;
|
||||
IBuffers = NULL;
|
||||
D3DCAPS9 DeviceCaps = D3D::GetCaps();
|
||||
u32 devicevMaxBufferSize = DeviceCaps.MaxPrimitiveCount * 3 * DeviceCaps.MaxStreamStride;
|
||||
//Calculate Device Dependant size
|
||||
CurrentVBufferSize = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE;
|
||||
CurrentIBufferSize = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE;
|
||||
//if device caps are not enough for Vbuffer fall back to vertex arrays
|
||||
if (CurrentIBufferSize < MAXIBUFFERSIZE || CurrentVBufferSize < MAXVBUFFERSIZE) return;
|
||||
|
||||
VBuffers = new LPDIRECT3DVERTEXBUFFER9[MAXVBUFFER_COUNT];
|
||||
IBuffers = new LPDIRECT3DINDEXBUFFER9[MAXVBUFFER_COUNT];
|
||||
|
||||
bool Fail = false;
|
||||
for (CurrentVBuffer = 0; CurrentVBuffer < MAXVBUFFER_COUNT; CurrentVBuffer++)
|
||||
{
|
||||
VBuffers[CurrentVBuffer] = NULL;
|
||||
IBuffers[CurrentVBuffer] = NULL;
|
||||
}
|
||||
for (CurrentVBuffer = 0; CurrentVBuffer < MAXVBUFFER_COUNT; CurrentVBuffer++)
|
||||
{
|
||||
if(FAILED( D3D::dev->CreateVertexBuffer( CurrentVBufferSize, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &VBuffers[CurrentVBuffer], NULL ) ) )
|
||||
{
|
||||
Fail = true;
|
||||
break;
|
||||
}
|
||||
if( FAILED( D3D::dev->CreateIndexBuffer( CurrentIBufferSize * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &IBuffers[CurrentVBuffer], NULL ) ) )
|
||||
{
|
||||
Fail = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
NumVBuffers = CurrentVBuffer;
|
||||
CurrentVBuffer = 0;
|
||||
CurrentIBuffer = 0;
|
||||
CurrentIBufferIndex = CurrentIBufferSize;
|
||||
CurrentVBufferIndex = CurrentVBufferSize;
|
||||
|
||||
if (Fail)
|
||||
{
|
||||
NumVBuffers--;
|
||||
if (NumVBuffers < 2)
|
||||
{
|
||||
//Error creating Vertex buffers. clean and fall to Vertex arrays
|
||||
NumVBuffers = MAXVBUFFER_COUNT;
|
||||
DestroyDeviceObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
void VertexManager::DestroyDeviceObjects()
|
||||
{
|
||||
D3D::dev->SetStreamSource( 0, NULL, 0, 0);
|
||||
D3D::dev->SetIndices(NULL);
|
||||
for (int i = 0; i < MAXVBUFFER_COUNT; i++)
|
||||
{
|
||||
if(VBuffers)
|
||||
{
|
||||
if (VBuffers[i])
|
||||
{
|
||||
VBuffers[i]->Release();
|
||||
VBuffers[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (IBuffers[i])
|
||||
{
|
||||
IBuffers[i]->Release();
|
||||
IBuffers[i] = NULL;
|
||||
}
|
||||
}
|
||||
if(VBuffers)
|
||||
delete [] VBuffers;
|
||||
if(IBuffers)
|
||||
delete [] IBuffers;
|
||||
VBuffers = NULL;
|
||||
IBuffers = NULL;
|
||||
}
|
||||
|
||||
void VertexManager::PrepareVBuffers(int stride)
|
||||
{
|
||||
if (!NumVBuffers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
u8* pVertices;
|
||||
u16* pIndices;
|
||||
int datasize = IndexGenerator::GetNumVerts() * stride;
|
||||
int TdataSize = IndexGenerator::GetTriangleindexLen();
|
||||
int LDataSize = IndexGenerator::GetLineindexLen();
|
||||
int PDataSize = IndexGenerator::GetPointindexLen();
|
||||
int IndexDataSize = TdataSize + LDataSize + PDataSize;
|
||||
DWORD LockMode = D3DLOCK_NOOVERWRITE;
|
||||
|
||||
if (CurrentVBufferIndex > CurrentVBufferSize - datasize)
|
||||
{
|
||||
LockMode = D3DLOCK_DISCARD;
|
||||
CurrentVBufferIndex = 0;
|
||||
CurrentVBuffer = (CurrentVBuffer + 1) % NumVBuffers;
|
||||
}
|
||||
|
||||
if(FAILED(VBuffers[CurrentVBuffer]->Lock(CurrentVBufferIndex, datasize,(VOID**)(&pVertices), LockMode)))
|
||||
{
|
||||
DestroyDeviceObjects();
|
||||
return;
|
||||
}
|
||||
memcpy(pVertices, LocalVBuffer, datasize);
|
||||
VBuffers[CurrentVBuffer]->Unlock();
|
||||
|
||||
LockMode = D3DLOCK_NOOVERWRITE;
|
||||
|
||||
if (CurrentIBufferIndex > CurrentIBufferSize - IndexDataSize)
|
||||
{
|
||||
LockMode = D3DLOCK_DISCARD;
|
||||
CurrentIBufferIndex = 0;
|
||||
CurrentIBuffer = (CurrentIBuffer + 1) % NumVBuffers;
|
||||
}
|
||||
|
||||
if(FAILED(IBuffers[CurrentIBuffer]->Lock(CurrentIBufferIndex * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode )))
|
||||
{
|
||||
DestroyDeviceObjects();
|
||||
return;
|
||||
}
|
||||
if(TdataSize)
|
||||
{
|
||||
memcpy(pIndices, TIBuffer, TdataSize * sizeof(u16));
|
||||
pIndices += TdataSize;
|
||||
}
|
||||
if(LDataSize)
|
||||
{
|
||||
memcpy(pIndices, LIBuffer, LDataSize * sizeof(u16));
|
||||
pIndices += LDataSize;
|
||||
}
|
||||
if(PDataSize)
|
||||
{
|
||||
memcpy(pIndices, PIBuffer, PDataSize * sizeof(u16));
|
||||
}
|
||||
IBuffers[CurrentIBuffer]->Unlock();
|
||||
D3D::dev->SetStreamSource( 0, VBuffers[CurrentVBuffer], CurrentVBufferIndex, stride);
|
||||
if(CurrentIBufferIndex == 0)
|
||||
{
|
||||
D3D::dev->SetIndices(IBuffers[CurrentIBuffer]);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexManager::DrawVB(int stride)
|
||||
{
|
||||
if (IndexGenerator::GetNumTriangles() > 0)
|
||||
{
|
||||
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
||||
D3DPT_TRIANGLELIST,
|
||||
0,
|
||||
0,
|
||||
IndexGenerator::GetNumVerts(),
|
||||
CurrentIBufferIndex,
|
||||
IndexGenerator::GetNumTriangles())))
|
||||
{
|
||||
DumpBadShaders();
|
||||
}
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
if (IndexGenerator::GetNumLines() > 0)
|
||||
{
|
||||
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
||||
D3DPT_LINELIST,
|
||||
0,
|
||||
0,
|
||||
IndexGenerator::GetNumVerts(),
|
||||
CurrentIBufferIndex + IndexGenerator::GetTriangleindexLen(),
|
||||
IndexGenerator::GetNumLines())))
|
||||
{
|
||||
DumpBadShaders();
|
||||
}
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
if (IndexGenerator::GetNumPoints() > 0)
|
||||
{
|
||||
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
||||
D3DPT_POINTLIST,
|
||||
0,
|
||||
0,
|
||||
IndexGenerator::GetNumVerts(),
|
||||
CurrentIBufferIndex + IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen(),
|
||||
IndexGenerator::GetNumPoints())))
|
||||
{
|
||||
DumpBadShaders();
|
||||
}
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VertexManager::DrawVA(int stride)
|
||||
{
|
||||
if (IndexGenerator::GetNumTriangles() > 0)
|
||||
{
|
||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||
@ -105,7 +302,7 @@ void VertexManager::Draw(int stride)
|
||||
DumpBadShaders();
|
||||
}
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VertexManager::vFlush()
|
||||
@ -136,8 +333,8 @@ void VertexManager::vFlush()
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8),
|
||||
tex.texMode1[i&3].max_lod >> 4,
|
||||
(tex.texMode0[i&3].min_filter & 3),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
tex.texImage1[i&3].image_type);
|
||||
|
||||
if (tentry)
|
||||
@ -153,7 +350,7 @@ void VertexManager::vFlush()
|
||||
// set global constants
|
||||
VertexShaderManager::SetConstants();
|
||||
PixelShaderManager::SetConstants();
|
||||
|
||||
int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
if (!PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components))
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||
@ -165,17 +362,14 @@ void VertexManager::vFlush()
|
||||
goto shader_fail;
|
||||
|
||||
}
|
||||
|
||||
int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
||||
Draw(stride);
|
||||
PrepareVBuffers(stride);
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
if(NumVBuffers){ DrawVB(stride);} else { DrawVA(stride);}
|
||||
|
||||
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
||||
bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
if (useDstAlpha)
|
||||
{
|
||||
DWORD write = 0;
|
||||
if (!PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS, g_nativeVertexFmt->m_components))
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||
@ -183,12 +377,17 @@ void VertexManager::vFlush()
|
||||
}
|
||||
// update alpha only
|
||||
g_renderer->ApplyState(true);
|
||||
Draw(stride);
|
||||
if(NumVBuffers){ DrawVB(stride);} else { DrawVA(stride);}
|
||||
g_renderer->RestoreState();
|
||||
}
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
||||
|
||||
shader_fail:
|
||||
if(NumVBuffers)
|
||||
{
|
||||
CurrentIBufferIndex += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
||||
CurrentVBufferIndex += IndexGenerator::GetNumVerts() * stride;
|
||||
}
|
||||
ResetBuffer();
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,21 @@ class VertexManager : public ::VertexManager
|
||||
public:
|
||||
NativeVertexFormat* CreateNativeVertexFormat();
|
||||
void GetElements(NativeVertexFormat* format, D3DVERTEXELEMENT9** elems, int* num);
|
||||
|
||||
void CreateDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
private:
|
||||
void Draw(int stride);
|
||||
u32 CurrentVBufferIndex;
|
||||
u32 CurrentVBufferSize;
|
||||
u32 CurrentIBufferIndex;
|
||||
u32 CurrentIBufferSize;
|
||||
u32 NumVBuffers;
|
||||
u32 CurrentVBuffer;
|
||||
u32 CurrentIBuffer;
|
||||
LPDIRECT3DVERTEXBUFFER9 *VBuffers;
|
||||
LPDIRECT3DINDEXBUFFER9 *IBuffers;
|
||||
void PrepareVBuffers(int stride);
|
||||
void DrawVB(int stride);
|
||||
void DrawVA(int stride);
|
||||
// temp
|
||||
void vFlush();
|
||||
};
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include "D3DUtil.h"
|
||||
#include "EmuWindow.h"
|
||||
#include "VideoState.h"
|
||||
#include "render.h"
|
||||
#include "Render.h"
|
||||
#include "DLCache.h"
|
||||
#include "IniFile.h"
|
||||
#include "Core.h"
|
||||
@ -93,6 +93,7 @@ void InitBackendInfo()
|
||||
const int maxConstants = (shaderModel < 3) ? 32 : ((shaderModel < 4) ? 224 : 65536);
|
||||
g_Config.backend_info.APIType = shaderModel < 3 ? API_D3D9_SM20 :API_D3D9_SM30;
|
||||
g_Config.backend_info.bUseRGBATextures = false;
|
||||
g_Config.backend_info.bUseMinimalMipCount = true;
|
||||
g_Config.backend_info.bSupports3DVision = true;
|
||||
g_Config.backend_info.bSupportsDualSourceBlend = false;
|
||||
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
||||
@ -169,9 +170,9 @@ void VideoBackend::Video_Prepare()
|
||||
s_swapRequested = FALSE;
|
||||
|
||||
// internal interfaces
|
||||
g_renderer = new Renderer;
|
||||
g_texture_cache = new TextureCache;
|
||||
g_vertex_manager = new VertexManager;
|
||||
g_renderer = new Renderer;
|
||||
g_texture_cache = new TextureCache;
|
||||
// VideoCommon
|
||||
BPInit();
|
||||
Fifo_Init();
|
||||
@ -209,9 +210,9 @@ void VideoBackend::Shutdown()
|
||||
// internal interfaces
|
||||
PixelShaderCache::Shutdown();
|
||||
VertexShaderCache::Shutdown();
|
||||
delete g_vertex_manager;
|
||||
delete g_texture_cache;
|
||||
delete g_renderer;
|
||||
delete g_vertex_manager;
|
||||
g_renderer = NULL;
|
||||
g_texture_cache = NULL;
|
||||
}
|
||||
|
@ -13,11 +13,22 @@ set(SRCS Src/FramebufferManager.cpp
|
||||
Src/VertexManager.cpp)
|
||||
|
||||
set(LIBS videocommon
|
||||
GLEW
|
||||
SOIL
|
||||
common
|
||||
${OPENGL_LIBRARIES}
|
||||
${X11_LIBRARIES})
|
||||
if(USE_EGL)
|
||||
set(LIBS ${LIBS}
|
||||
EGL)
|
||||
endif()
|
||||
|
||||
if(USE_GLES)
|
||||
set(LIBS ${LIBS}
|
||||
GLESv2)
|
||||
else()
|
||||
set(LIBS ${LIBS}
|
||||
GLEW
|
||||
${OPENGL_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(wxWidgets_FOUND)
|
||||
set(LIBS ${LIBS} ${wxWidgets_LIBRARIES})
|
||||
|
@ -249,4 +249,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "Globals.h"
|
||||
#include "VideoConfig.h"
|
||||
#include "IniFile.h"
|
||||
#include "Setup.h"
|
||||
#include "Core.h"
|
||||
#include "Host.h"
|
||||
#include "VideoBackend.h"
|
||||
@ -29,59 +28,8 @@
|
||||
|
||||
#include "GLUtil.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "EmuWindow.h"
|
||||
static HDC hDC = NULL; // Private GDI Device Context
|
||||
static HGLRC hRC = NULL; // Permanent Rendering Context
|
||||
#else
|
||||
GLWindow GLWin;
|
||||
#endif
|
||||
|
||||
// Handles OpenGL and the window
|
||||
|
||||
// Window dimensions.
|
||||
static int s_backbuffer_width;
|
||||
static int s_backbuffer_height;
|
||||
|
||||
void OpenGL_SwapBuffers()
|
||||
{
|
||||
#if defined(USE_WX) && USE_WX
|
||||
GLWin.glCanvas->SwapBuffers();
|
||||
#elif defined(__APPLE__)
|
||||
[GLWin.cocoaCtx flushBuffer];
|
||||
#elif defined(_WIN32)
|
||||
SwapBuffers(hDC);
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
glXSwapBuffers(GLWin.dpy, GLWin.win);
|
||||
#endif
|
||||
}
|
||||
|
||||
u32 OpenGL_GetBackbufferWidth()
|
||||
{
|
||||
return s_backbuffer_width;
|
||||
}
|
||||
|
||||
u32 OpenGL_GetBackbufferHeight()
|
||||
{
|
||||
return s_backbuffer_height;
|
||||
}
|
||||
|
||||
void OpenGL_SetWindowText(const char *text)
|
||||
{
|
||||
#if defined(USE_WX) && USE_WX
|
||||
// Handled by Host_UpdateTitle()
|
||||
#elif defined(__APPLE__)
|
||||
[GLWin.cocoaWin setTitle: [NSString stringWithUTF8String: text]];
|
||||
#elif defined(_WIN32)
|
||||
TCHAR temp[512];
|
||||
swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs"), text);
|
||||
EmuWindow::SetWindowText(temp);
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
// Tell X to ask the window manager to set the window title.
|
||||
// (X itself doesn't provide window title functionality.)
|
||||
XStoreName(GLWin.dpy, GLWin.win, text);
|
||||
#endif
|
||||
}
|
||||
cInterfaceBase *GLInterface;
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
@ -89,20 +37,7 @@ namespace OGL
|
||||
// Draw messages on top of the screen
|
||||
unsigned int VideoBackend::PeekMessages()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// TODO: peekmessage
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
||||
{
|
||||
if (msg.message == WM_QUIT)
|
||||
return FALSE;
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return TRUE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return GLInterface->PeekMessages();
|
||||
}
|
||||
|
||||
// Show the current FPS
|
||||
@ -110,538 +45,105 @@ void VideoBackend::UpdateFPSDisplay(const char *text)
|
||||
{
|
||||
char temp[100];
|
||||
snprintf(temp, sizeof temp, "%s | OpenGL | %s", scm_rev_str, text);
|
||||
OpenGL_SetWindowText(temp);
|
||||
return GLInterface->UpdateFPSDisplay(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if defined(HAVE_X11) && HAVE_X11
|
||||
void XEventThread();
|
||||
|
||||
void CreateXWindow(void)
|
||||
void InitInterface()
|
||||
{
|
||||
Atom wmProtocols[1];
|
||||
|
||||
// Setup window attributes
|
||||
GLWin.attr.colormap = XCreateColormap(GLWin.evdpy,
|
||||
GLWin.parent, GLWin.vi->visual, AllocNone);
|
||||
GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask;
|
||||
GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen);
|
||||
GLWin.attr.border_pixel = 0;
|
||||
|
||||
// Create the window
|
||||
GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent,
|
||||
GLWin.x, GLWin.y, GLWin.width, GLWin.height, 0,
|
||||
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
|
||||
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
|
||||
wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True);
|
||||
XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1);
|
||||
XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, NULL, 0, NULL);
|
||||
XMapRaised(GLWin.evdpy, GLWin.win);
|
||||
XSync(GLWin.evdpy, True);
|
||||
|
||||
GLWin.xEventThread = std::thread(XEventThread);
|
||||
#ifdef ANDROID
|
||||
GLInterface = new cInterfaceBase;
|
||||
#elif defined(USE_EGL) && USE_EGL
|
||||
GLInterface = new cInterfaceEGL;
|
||||
#elif defined(USE_WX) && USE_WX
|
||||
GLInterface = new cInterfaceWX;
|
||||
#elif defined(__APPLE__)
|
||||
GLInterface = new cInterfaceAGL;
|
||||
#elif defined(_WIN32)
|
||||
GLInterface = new cInterfaceWGL;
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
GLInterface = new cInterfaceGLX;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DestroyXWindow(void)
|
||||
GLuint OpenGL_CompileProgram ( const char* vertexShader, const char* fragmentShader )
|
||||
{
|
||||
XUnmapWindow(GLWin.dpy, GLWin.win);
|
||||
GLWin.win = 0;
|
||||
if (GLWin.xEventThread.joinable())
|
||||
GLWin.xEventThread.join();
|
||||
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
|
||||
}
|
||||
|
||||
void XEventThread()
|
||||
{
|
||||
// Free look variables
|
||||
static bool mouseLookEnabled = false;
|
||||
static bool mouseMoveEnabled = false;
|
||||
static float lastMouse[2];
|
||||
while (GLWin.win)
|
||||
{
|
||||
XEvent event;
|
||||
KeySym key;
|
||||
for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--)
|
||||
{
|
||||
XNextEvent(GLWin.evdpy, &event);
|
||||
switch(event.type) {
|
||||
case KeyPress:
|
||||
key = XLookupKeysym((XKeyEvent*)&event, 0);
|
||||
switch (key)
|
||||
{
|
||||
case XK_3:
|
||||
OSDChoice = 1;
|
||||
// Toggle native resolution
|
||||
g_Config.iEFBScale = g_Config.iEFBScale + 1;
|
||||
if (g_Config.iEFBScale > 7) g_Config.iEFBScale = 0;
|
||||
break;
|
||||
case XK_4:
|
||||
OSDChoice = 2;
|
||||
// Toggle aspect ratio
|
||||
g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
|
||||
break;
|
||||
case XK_5:
|
||||
OSDChoice = 3;
|
||||
// Toggle EFB copy
|
||||
if (!g_Config.bEFBCopyEnable || g_Config.bCopyEFBToTexture)
|
||||
{
|
||||
g_Config.bEFBCopyEnable ^= true;
|
||||
g_Config.bCopyEFBToTexture = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture;
|
||||
}
|
||||
break;
|
||||
case XK_6:
|
||||
OSDChoice = 4;
|
||||
g_Config.bDisableFog = !g_Config.bDisableFog;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (g_Config.bFreeLook)
|
||||
{
|
||||
static float debugSpeed = 1.0f;
|
||||
switch (key)
|
||||
{
|
||||
case XK_parenleft:
|
||||
debugSpeed /= 2.0f;
|
||||
break;
|
||||
case XK_parenright:
|
||||
debugSpeed *= 2.0f;
|
||||
break;
|
||||
case XK_w:
|
||||
VertexShaderManager::TranslateView(0.0f, debugSpeed);
|
||||
break;
|
||||
case XK_s:
|
||||
VertexShaderManager::TranslateView(0.0f, -debugSpeed);
|
||||
break;
|
||||
case XK_a:
|
||||
VertexShaderManager::TranslateView(debugSpeed, 0.0f);
|
||||
break;
|
||||
case XK_d:
|
||||
VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
|
||||
break;
|
||||
case XK_r:
|
||||
VertexShaderManager::ResetView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ButtonPress:
|
||||
if (g_Config.bFreeLook)
|
||||
{
|
||||
switch (event.xbutton.button)
|
||||
{
|
||||
case 2: // Middle button
|
||||
lastMouse[0] = event.xbutton.x;
|
||||
lastMouse[1] = event.xbutton.y;
|
||||
mouseMoveEnabled = true;
|
||||
break;
|
||||
case 3: // Right button
|
||||
lastMouse[0] = event.xbutton.x;
|
||||
lastMouse[1] = event.xbutton.y;
|
||||
mouseLookEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ButtonRelease:
|
||||
if (g_Config.bFreeLook)
|
||||
{
|
||||
switch (event.xbutton.button)
|
||||
{
|
||||
case 2: // Middle button
|
||||
mouseMoveEnabled = false;
|
||||
break;
|
||||
case 3: // Right button
|
||||
mouseLookEnabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
if (g_Config.bFreeLook)
|
||||
{
|
||||
if (mouseLookEnabled)
|
||||
{
|
||||
VertexShaderManager::RotateView((event.xmotion.x - lastMouse[0]) / 200.0f,
|
||||
(event.xmotion.y - lastMouse[1]) / 200.0f);
|
||||
lastMouse[0] = event.xmotion.x;
|
||||
lastMouse[1] = event.xmotion.y;
|
||||
}
|
||||
|
||||
if (mouseMoveEnabled)
|
||||
{
|
||||
VertexShaderManager::TranslateView((event.xmotion.x - lastMouse[0]) / 50.0f,
|
||||
(event.xmotion.y - lastMouse[1]) / 50.0f);
|
||||
lastMouse[0] = event.xmotion.x;
|
||||
lastMouse[1] = event.xmotion.y;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
Window winDummy;
|
||||
unsigned int borderDummy, depthDummy;
|
||||
XGetGeometry(GLWin.evdpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
|
||||
&GLWin.width, &GLWin.height, &borderDummy, &depthDummy);
|
||||
s_backbuffer_width = GLWin.width;
|
||||
s_backbuffer_height = GLWin.height;
|
||||
break;
|
||||
case ClientMessage:
|
||||
if ((unsigned long) event.xclient.data.l[0] ==
|
||||
XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", False))
|
||||
Host_Message(WM_USER_STOP);
|
||||
if ((unsigned long) event.xclient.data.l[0] ==
|
||||
XInternAtom(GLWin.evdpy, "RESIZE", False))
|
||||
XMoveResizeWindow(GLWin.evdpy, GLWin.win,
|
||||
event.xclient.data.l[1], event.xclient.data.l[2],
|
||||
event.xclient.data.l[3], event.xclient.data.l[4]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Common::SleepCurrentThread(20);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create rendering window.
|
||||
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
||||
bool OpenGL_Create(void *&window_handle)
|
||||
{
|
||||
int _tx, _ty, _twidth, _theight;
|
||||
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
|
||||
|
||||
// Control window size and picture scaling
|
||||
s_backbuffer_width = _twidth;
|
||||
s_backbuffer_height = _theight;
|
||||
|
||||
#if defined(USE_WX) && USE_WX
|
||||
GLWin.panel = (wxPanel *)window_handle;
|
||||
GLWin.glCanvas = new wxGLCanvas(GLWin.panel, wxID_ANY, NULL,
|
||||
wxPoint(0, 0), wxSize(_twidth, _theight));
|
||||
GLWin.glCanvas->Show(true);
|
||||
if (GLWin.glCtxt == NULL) // XXX dirty hack
|
||||
GLWin.glCtxt = new wxGLContext(GLWin.glCanvas);
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
NSRect size;
|
||||
NSUInteger style = NSMiniaturizableWindowMask;
|
||||
NSOpenGLPixelFormatAttribute attr[2] = { NSOpenGLPFADoubleBuffer, 0 };
|
||||
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
|
||||
initWithAttributes: attr];
|
||||
if (fmt == nil) {
|
||||
ERROR_LOG(VIDEO, "failed to create pixel format");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLWin.cocoaCtx = [[NSOpenGLContext alloc]
|
||||
initWithFormat: fmt shareContext: nil];
|
||||
[fmt release];
|
||||
if (GLWin.cocoaCtx == nil) {
|
||||
ERROR_LOG(VIDEO, "failed to create context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen) {
|
||||
size = [[NSScreen mainScreen] frame];
|
||||
style |= NSBorderlessWindowMask;
|
||||
} else {
|
||||
size = NSMakeRect(_tx, _ty, _twidth, _theight);
|
||||
style |= NSResizableWindowMask | NSTitledWindowMask;
|
||||
}
|
||||
|
||||
GLWin.cocoaWin = [[NSWindow alloc] initWithContentRect: size
|
||||
styleMask: style backing: NSBackingStoreBuffered defer: NO];
|
||||
if (GLWin.cocoaWin == nil) {
|
||||
ERROR_LOG(VIDEO, "failed to create window");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen) {
|
||||
CGDisplayCapture(CGMainDisplayID());
|
||||
[GLWin.cocoaWin setLevel: CGShieldingWindowLevel()];
|
||||
}
|
||||
|
||||
[GLWin.cocoaCtx setView: [GLWin.cocoaWin contentView]];
|
||||
[GLWin.cocoaWin makeKeyAndOrderFront: nil];
|
||||
|
||||
#elif defined(_WIN32)
|
||||
window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Please wait..."));
|
||||
if (window_handle == NULL)
|
||||
{
|
||||
Host_SysMessage("failed to create window");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show the window
|
||||
EmuWindow::Show();
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
|
||||
{
|
||||
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
||||
1, // Version Number
|
||||
PFD_DRAW_TO_WINDOW | // Format Must Support Window
|
||||
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
|
||||
PFD_DOUBLEBUFFER, // Must Support Double Buffering
|
||||
PFD_TYPE_RGBA, // Request An RGBA Format
|
||||
32, // Select Our Color Depth
|
||||
0, 0, 0, 0, 0, 0, // Color Bits Ignored
|
||||
0, // 8bit Alpha Buffer
|
||||
0, // Shift Bit Ignored
|
||||
0, // No Accumulation Buffer
|
||||
0, 0, 0, 0, // Accumulation Bits Ignored
|
||||
24, // 24Bit Z-Buffer (Depth Buffer)
|
||||
8, // 8bit Stencil Buffer
|
||||
0, // No Auxiliary Buffer
|
||||
PFD_MAIN_PLANE, // Main Drawing Layer
|
||||
0, // Reserved
|
||||
0, 0, 0 // Layer Masks Ignored
|
||||
};
|
||||
|
||||
GLuint PixelFormat; // Holds The Results After Searching For A Match
|
||||
|
||||
if (!(hDC=GetDC(EmuWindow::GetWnd()))) {
|
||||
PanicAlert("(1) Can't create an OpenGL Device context. Fail.");
|
||||
return false;
|
||||
}
|
||||
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) {
|
||||
PanicAlert("(2) Can't find a suitable PixelFormat.");
|
||||
return false;
|
||||
}
|
||||
if (!SetPixelFormat(hDC, PixelFormat, &pfd)) {
|
||||
PanicAlert("(3) Can't set the PixelFormat.");
|
||||
return false;
|
||||
}
|
||||
if (!(hRC = wglCreateContext(hDC))) {
|
||||
PanicAlert("(4) Can't create an OpenGL rendering context.");
|
||||
return false;
|
||||
}
|
||||
// --------------------------------------
|
||||
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
int glxMajorVersion, glxMinorVersion;
|
||||
|
||||
// attributes for a single buffered visual in RGBA format with at least
|
||||
// 8 bits per color and a 24 bit depth buffer
|
||||
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_DEPTH_SIZE, 24,
|
||||
None};
|
||||
|
||||
// attributes for a double buffered visual in RGBA format with at least
|
||||
// 8 bits per color and a 24 bit depth buffer
|
||||
int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_DEPTH_SIZE, 24,
|
||||
GLX_SAMPLE_BUFFERS_ARB, g_Config.iMultisampleMode != MULTISAMPLE_OFF?1:0,
|
||||
GLX_SAMPLES_ARB, g_Config.iMultisampleMode != MULTISAMPLE_OFF?1:0,
|
||||
None };
|
||||
|
||||
int attrListDefault[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
None };
|
||||
|
||||
GLWin.dpy = XOpenDisplay(0);
|
||||
GLWin.evdpy = XOpenDisplay(0);
|
||||
GLWin.parent = (Window)window_handle;
|
||||
GLWin.screen = DefaultScreen(GLWin.dpy);
|
||||
if (GLWin.parent == 0)
|
||||
GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen);
|
||||
|
||||
glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion);
|
||||
NOTICE_LOG(VIDEO, "glX-Version %d.%d", glxMajorVersion, glxMinorVersion);
|
||||
|
||||
// Get an appropriate visual
|
||||
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl);
|
||||
if (GLWin.vi == NULL)
|
||||
{
|
||||
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListSgl);
|
||||
if (GLWin.vi != NULL)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Only single buffered visual!");
|
||||
}
|
||||
else
|
||||
{
|
||||
GLWin.vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDefault);
|
||||
if (GLWin.vi == NULL)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Could not choose visual (glXChooseVisual)");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
NOTICE_LOG(VIDEO, "Got double buffered visual!");
|
||||
|
||||
// Create a GLX context.
|
||||
GLWin.ctx = glXCreateContext(GLWin.dpy, GLWin.vi, 0, GL_TRUE);
|
||||
if (!GLWin.ctx)
|
||||
{
|
||||
PanicAlert("Unable to create GLX context.");
|
||||
return false;
|
||||
}
|
||||
|
||||
GLWin.x = _tx;
|
||||
GLWin.y = _ty;
|
||||
GLWin.width = _twidth;
|
||||
GLWin.height = _theight;
|
||||
|
||||
CreateXWindow();
|
||||
window_handle = (void *)GLWin.win;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenGL_MakeCurrent()
|
||||
{
|
||||
// connect the glx-context to the window
|
||||
#if defined(USE_WX) && USE_WX
|
||||
return GLWin.glCanvas->SetCurrent(*GLWin.glCtxt);
|
||||
#elif defined(__APPLE__)
|
||||
[GLWin.cocoaCtx makeCurrentContext];
|
||||
#elif defined(_WIN32)
|
||||
return wglMakeCurrent(hDC, hRC) ? true : false;
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
#if defined(HAVE_WX) && (HAVE_WX)
|
||||
Host_GetRenderWindowSize(GLWin.x, GLWin.y,
|
||||
(int&)GLWin.width, (int&)GLWin.height);
|
||||
XMoveResizeWindow(GLWin.dpy, GLWin.win, GLWin.x, GLWin.y,
|
||||
GLWin.width, GLWin.height);
|
||||
#endif
|
||||
return glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update window width, size and etc. Called from Render.cpp
|
||||
void OpenGL_Update()
|
||||
{
|
||||
#if defined(USE_WX) && USE_WX
|
||||
int width, height;
|
||||
|
||||
GLWin.panel->GetSize(&width, &height);
|
||||
if (width == s_backbuffer_width && height == s_backbuffer_height)
|
||||
return;
|
||||
|
||||
GLWin.glCanvas->SetFocus();
|
||||
GLWin.glCanvas->SetSize(0, 0, width, height);
|
||||
GLWin.glCtxt->SetCurrent(*GLWin.glCanvas);
|
||||
s_backbuffer_width = width;
|
||||
s_backbuffer_height = height;
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
int width, height;
|
||||
|
||||
width = [[GLWin.cocoaWin contentView] frame].size.width;
|
||||
height = [[GLWin.cocoaWin contentView] frame].size.height;
|
||||
if (width == s_backbuffer_width && height == s_backbuffer_height)
|
||||
return;
|
||||
|
||||
[GLWin.cocoaCtx setView: [GLWin.cocoaWin contentView]];
|
||||
[GLWin.cocoaCtx update];
|
||||
[GLWin.cocoaCtx makeCurrentContext];
|
||||
s_backbuffer_width = width;
|
||||
s_backbuffer_height = height;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
RECT rcWindow;
|
||||
if (!EmuWindow::GetParentWnd())
|
||||
{
|
||||
// We are not rendering to a child window - use client size.
|
||||
GetClientRect(EmuWindow::GetWnd(), &rcWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We are rendering to a child window - use parent size.
|
||||
GetWindowRect(EmuWindow::GetParentWnd(), &rcWindow);
|
||||
}
|
||||
|
||||
// Get the new window width and height
|
||||
// See below for documentation
|
||||
int width = rcWindow.right - rcWindow.left;
|
||||
int height = rcWindow.bottom - rcWindow.top;
|
||||
|
||||
// If we are rendering to a child window
|
||||
if (EmuWindow::GetParentWnd() != 0 &&
|
||||
(s_backbuffer_width != width || s_backbuffer_height != height) &&
|
||||
width >= 4 && height >= 4)
|
||||
{
|
||||
::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE);
|
||||
s_backbuffer_width = width;
|
||||
s_backbuffer_height = height;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Close backend
|
||||
void OpenGL_Shutdown()
|
||||
{
|
||||
#if defined(USE_WX) && USE_WX
|
||||
GLWin.glCanvas->Hide();
|
||||
// XXX GLWin.glCanvas->Destroy();
|
||||
// XXX delete GLWin.glCtxt;
|
||||
#elif defined(__APPLE__)
|
||||
[GLWin.cocoaWin close];
|
||||
[GLWin.cocoaCtx clearDrawable];
|
||||
[GLWin.cocoaCtx release];
|
||||
#elif defined(_WIN32)
|
||||
if (hRC)
|
||||
{
|
||||
if (!wglMakeCurrent(NULL, NULL))
|
||||
NOTICE_LOG(VIDEO, "Could not release drawing context.");
|
||||
|
||||
if (!wglDeleteContext(hRC))
|
||||
ERROR_LOG(VIDEO, "Release Rendering Context Failed.");
|
||||
|
||||
hRC = NULL;
|
||||
}
|
||||
|
||||
if (hDC && !ReleaseDC(EmuWindow::GetWnd(), hDC))
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Release Device Context Failed.");
|
||||
hDC = NULL;
|
||||
}
|
||||
// generate objects
|
||||
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
||||
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
GLuint programID = glCreateProgram();
|
||||
GLint Result = GL_FALSE;
|
||||
char stringBuffer[1024];
|
||||
GLsizei stringBufferUsage = 0;
|
||||
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
DestroyXWindow();
|
||||
if (GLWin.ctx && !glXMakeCurrent(GLWin.dpy, None, NULL))
|
||||
NOTICE_LOG(VIDEO, "Could not release drawing context.");
|
||||
if (GLWin.ctx)
|
||||
{
|
||||
glXDestroyContext(GLWin.dpy, GLWin.ctx);
|
||||
XCloseDisplay(GLWin.dpy);
|
||||
XCloseDisplay(GLWin.evdpy);
|
||||
GLWin.ctx = NULL;
|
||||
// compile vertex shader
|
||||
glShaderSource(vertexShaderID, 1, &vertexShader, NULL);
|
||||
glCompileShader(vertexShaderID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result);
|
||||
glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer);
|
||||
if(Result && stringBufferUsage) {
|
||||
ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader);
|
||||
} else if(!Result) {
|
||||
ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader);
|
||||
} else {
|
||||
DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader);
|
||||
}
|
||||
bool shader_errors = !Result;
|
||||
#endif
|
||||
|
||||
// compile fragment shader
|
||||
glShaderSource(fragmentShaderID, 1, &fragmentShader, NULL);
|
||||
glCompileShader(fragmentShaderID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
|
||||
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
|
||||
if(Result && stringBufferUsage) {
|
||||
ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader);
|
||||
} else if(!Result) {
|
||||
ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader);
|
||||
} else {
|
||||
DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader);
|
||||
}
|
||||
shader_errors |= !Result;
|
||||
#endif
|
||||
|
||||
// link them
|
||||
glAttachShader(programID, vertexShaderID);
|
||||
glAttachShader(programID, fragmentShaderID);
|
||||
glLinkProgram(programID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
glGetProgramiv(programID, GL_LINK_STATUS, &Result);
|
||||
glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer);
|
||||
if(Result && stringBufferUsage) {
|
||||
ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
||||
} else if(!Result && !shader_errors) {
|
||||
ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
||||
}
|
||||
#endif
|
||||
|
||||
// cleanup
|
||||
glDeleteShader(vertexShaderID);
|
||||
glDeleteShader(fragmentShaderID);
|
||||
|
||||
return programID;
|
||||
}
|
||||
|
||||
|
||||
GLuint OpenGL_ReportGLError(const char *function, const char *file, int line)
|
||||
{
|
||||
GLint err = glGetError();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL error 0x%x - %s\n",
|
||||
file, line, function, err, gluErrorString(err));
|
||||
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL error 0x%x\n",
|
||||
file, line, function, err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void OpenGL_ReportARBProgramError()
|
||||
{
|
||||
#ifndef USE_GLES
|
||||
const GLubyte* pstr = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
||||
if (pstr != NULL && pstr[0] != 0)
|
||||
{
|
||||
@ -651,10 +153,12 @@ void OpenGL_ReportARBProgramError()
|
||||
ERROR_LOG(VIDEO, "%s", (char*)pstr);
|
||||
ERROR_LOG(VIDEO, "\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
|
||||
{
|
||||
#ifndef USE_GLES
|
||||
unsigned int fbo_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||
if (fbo_status != GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||
{
|
||||
@ -687,6 +191,7 @@ bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
|
||||
file, line, function, error);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -20,26 +20,7 @@
|
||||
|
||||
#include "VideoConfig.h"
|
||||
#include "MathUtil.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
#include <GL/wglew.h>
|
||||
#elif defined HAVE_X11 && HAVE_X11
|
||||
#include <GL/glxew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
#elif defined __APPLE__
|
||||
#include <GL/glew.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#endif
|
||||
|
||||
#if defined USE_WX && USE_WX
|
||||
#include "wx/wx.h"
|
||||
#include "wx/glcanvas.h"
|
||||
#endif
|
||||
#include "GLInterface.h"
|
||||
|
||||
#ifndef GL_DEPTH24_STENCIL8_EXT // allows FBOs to support stencils
|
||||
#define GL_DEPTH_STENCIL_EXT 0x84F9
|
||||
@ -48,53 +29,28 @@
|
||||
#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLES
|
||||
#define TEX2D GL_TEXTURE_2D
|
||||
#define PREC "highp"
|
||||
#define TEXTYPE "sampler2D"
|
||||
#define TEXFUNC "texture2D"
|
||||
#else
|
||||
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
|
||||
#define PREC
|
||||
#define TEXTYPE "sampler2DRect"
|
||||
#define TEXFUNC "texture2DRect"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct {
|
||||
#if defined(USE_WX) && USE_WX
|
||||
wxGLCanvas *glCanvas;
|
||||
wxGLContext *glCtxt;
|
||||
wxPanel *panel;
|
||||
#elif defined(__APPLE__)
|
||||
NSWindow *cocoaWin;
|
||||
NSOpenGLContext *cocoaCtx;
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
int screen;
|
||||
Window win;
|
||||
Window parent;
|
||||
// dpy used for glx stuff, evdpy for window events etc.
|
||||
// evdpy is to be used by XEventThread only
|
||||
Display *dpy, *evdpy;
|
||||
XVisualInfo *vi;
|
||||
GLXContext ctx;
|
||||
XSetWindowAttributes attr;
|
||||
std::thread xEventThread;
|
||||
int x, y;
|
||||
unsigned int width, height;
|
||||
#endif
|
||||
} GLWindow;
|
||||
void InitInterface();
|
||||
|
||||
extern GLWindow GLWin;
|
||||
|
||||
#endif
|
||||
|
||||
// Public OpenGL util
|
||||
|
||||
// Initialization / upkeep
|
||||
bool OpenGL_Create(void *&);
|
||||
void OpenGL_Shutdown();
|
||||
void OpenGL_Update();
|
||||
bool OpenGL_MakeCurrent();
|
||||
void OpenGL_SwapBuffers();
|
||||
|
||||
// Get status
|
||||
u32 OpenGL_GetBackbufferWidth();
|
||||
u32 OpenGL_GetBackbufferHeight();
|
||||
|
||||
// Set things
|
||||
void OpenGL_SetWindowText(const char *text);
|
||||
// Helpers
|
||||
GLuint OpenGL_CompileProgram(const char *vertexShader, const char *fragmentShader);
|
||||
|
||||
// Error reporting - use the convenient macros.
|
||||
void OpenGL_ReportARBProgramError();
|
||||
@ -126,4 +82,7 @@ extern CGprofile g_cgvProf, g_cgfProf;
|
||||
// use GLSL shaders across the whole pipeline. Yikes!
|
||||
//#define USE_DUAL_SOURCE_BLEND
|
||||
|
||||
// TODO: should be removed if we use glsl a lot
|
||||
#define DEBUG_GLSL
|
||||
|
||||
#endif // _GLINIT_H_
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "GLUtil.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "ABI.h"
|
||||
#include "x64ABI.h"
|
||||
#include "MemoryUtil.h"
|
||||
#include "VertexShaderGen.h"
|
||||
|
||||
|
@ -61,6 +61,8 @@
|
||||
#include "Movie.h"
|
||||
#include "Host.h"
|
||||
#include "BPFunctions.h"
|
||||
#include "FPSCounter.h"
|
||||
#include "ConfigManager.h"
|
||||
|
||||
#include "main.h" // Local
|
||||
#ifdef _WIN32
|
||||
@ -130,58 +132,6 @@ const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_
|
||||
static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
|
||||
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
|
||||
|
||||
static const GLenum glSrcFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_DST_COLOR,
|
||||
GL_ONE_MINUS_DST_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
GL_DST_ALPHA,
|
||||
GL_ONE_MINUS_DST_ALPHA
|
||||
};
|
||||
|
||||
static const GLenum glDestFactors[8] = {
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_SRC_COLOR,
|
||||
GL_ONE_MINUS_SRC_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
GL_DST_ALPHA,
|
||||
GL_ONE_MINUS_DST_ALPHA
|
||||
};
|
||||
|
||||
static const GLenum glCmpFuncs[8] = {
|
||||
GL_NEVER,
|
||||
GL_LESS,
|
||||
GL_EQUAL,
|
||||
GL_LEQUAL,
|
||||
GL_GREATER,
|
||||
GL_NOTEQUAL,
|
||||
GL_GEQUAL,
|
||||
GL_ALWAYS
|
||||
};
|
||||
|
||||
static const GLenum glLogicOpCodes[16] = {
|
||||
GL_CLEAR,
|
||||
GL_AND,
|
||||
GL_AND_REVERSE,
|
||||
GL_COPY,
|
||||
GL_AND_INVERTED,
|
||||
GL_NOOP,
|
||||
GL_XOR,
|
||||
GL_OR,
|
||||
GL_NOR,
|
||||
GL_EQUIV,
|
||||
GL_INVERT,
|
||||
GL_OR_REVERSE,
|
||||
GL_COPY_INVERTED,
|
||||
GL_OR_INVERTED,
|
||||
GL_NAND,
|
||||
GL_SET
|
||||
};
|
||||
|
||||
#if defined HAVE_CG && HAVE_CG
|
||||
void HandleCgError(CGcontext ctx, CGerror err, void* appdata)
|
||||
@ -251,6 +201,8 @@ Renderer::Renderer()
|
||||
s_fps=0;
|
||||
s_blendMode = 0;
|
||||
|
||||
InitFPSCounter();
|
||||
|
||||
#if defined HAVE_CG && HAVE_CG
|
||||
g_cgcontext = cgCreateContext();
|
||||
cgGetError();
|
||||
@ -319,29 +271,12 @@ Renderer::Renderer()
|
||||
return; // TODO: fail
|
||||
|
||||
// Decide frambuffer size
|
||||
s_backbuffer_width = (int)OpenGL_GetBackbufferWidth();
|
||||
s_backbuffer_height = (int)OpenGL_GetBackbufferHeight();
|
||||
s_backbuffer_width = (int)GLInterface->GetBackBufferWidth();
|
||||
s_backbuffer_height = (int)GLInterface->GetBackBufferHeight();
|
||||
|
||||
// Handle VSync on/off
|
||||
#ifdef __APPLE__
|
||||
int swapInterval = g_ActiveConfig.bVSync ? 1 : 0;
|
||||
#if defined USE_WX && USE_WX
|
||||
NSOpenGLContext *ctx = GLWin.glCtxt->GetWXGLContext();
|
||||
#else
|
||||
NSOpenGLContext *ctx = GLWin.cocoaCtx;
|
||||
#endif
|
||||
[ctx setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
|
||||
#elif defined _WIN32
|
||||
if (WGLEW_EXT_swap_control)
|
||||
wglSwapIntervalEXT(g_ActiveConfig.bVSync ? 1 : 0);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
if (glXSwapIntervalSGI)
|
||||
glXSwapIntervalSGI(g_ActiveConfig.bVSync ? 1 : 0);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "No support for SwapInterval (framerate clamped to monitor refresh rate).");
|
||||
#endif
|
||||
GLInterface->SwapInterval(swapInterval);
|
||||
|
||||
// check the max texture width and height
|
||||
GLint max_texture_size;
|
||||
@ -359,16 +294,14 @@ Renderer::Renderer()
|
||||
if (!GLEW_ARB_texture_non_power_of_two)
|
||||
WARN_LOG(VIDEO, "ARB_texture_non_power_of_two not supported.");
|
||||
|
||||
s_XFB_width = MAX_XFB_WIDTH;
|
||||
s_XFB_height = MAX_XFB_HEIGHT;
|
||||
// TODO: Move these somewhere else?
|
||||
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
|
||||
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
|
||||
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
s_LastEFBScale = g_ActiveConfig.iEFBScale;
|
||||
CalculateTargetSize();
|
||||
CalculateTargetSize(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
// Because of the fixed framebuffer size we need to disable the resolution
|
||||
// options while running
|
||||
@ -519,7 +452,7 @@ Renderer::~Renderer()
|
||||
void Renderer::DrawDebugInfo()
|
||||
{
|
||||
// Reset viewport for drawing text
|
||||
glViewport(0, 0, OpenGL_GetBackbufferWidth(), OpenGL_GetBackbufferHeight());
|
||||
glViewport(0, 0, GLInterface->GetBackBufferWidth(), GLInterface->GetBackBufferHeight());
|
||||
// Draw various messages on the screen, like FPS, statistics, etc.
|
||||
char debugtext_buffer[8192];
|
||||
char *p = debugtext_buffer;
|
||||
@ -528,6 +461,9 @@ void Renderer::DrawDebugInfo()
|
||||
if (g_ActiveConfig.bShowFPS)
|
||||
p+=sprintf(p, "FPS: %d\n", s_fps);
|
||||
|
||||
if (SConfig::GetInstance().m_ShowLag)
|
||||
p+=sprintf(p, "Lag: %llu\n", Movie::g_currentLagCount);
|
||||
|
||||
if (g_ActiveConfig.bShowInputDisplay)
|
||||
p+=sprintf(p, "%s", Movie::GetInputDisplay().c_str());
|
||||
|
||||
@ -593,18 +529,23 @@ void Renderer::DrawDebugInfo()
|
||||
|
||||
void Renderer::RenderText(const char *text, int left, int top, u32 color)
|
||||
{
|
||||
const int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth();
|
||||
const int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight();
|
||||
const int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
|
||||
const int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
|
||||
|
||||
glColor4f(((color>>16) & 0xff)/255.0f, ((color>> 8) & 0xff)/255.0f,
|
||||
((color>> 0) & 0xff)/255.0f, ((color>>24) & 0xFF)/255.0f);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
s_pfont->printMultilineText(text,
|
||||
left * 2.0f / (float)nBackbufferWidth - 1,
|
||||
1 - top * 2.0f / (float)nBackbufferHeight,
|
||||
0, nBackbufferWidth, nBackbufferHeight);
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
@ -636,10 +577,13 @@ void Renderer::SetColorMask()
|
||||
{
|
||||
// Only enable alpha channel if it's supported by the current EFB format
|
||||
GLenum ColorMask = GL_FALSE, AlphaMask = GL_FALSE;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
ColorMask = GL_TRUE;
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
AlphaMask = GL_TRUE;
|
||||
if (bpmem.alpha_test.TestResult() != AlphaTest::FAIL)
|
||||
{
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
ColorMask = GL_TRUE;
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
AlphaMask = GL_TRUE;
|
||||
}
|
||||
glColorMask(ColorMask, ColorMask, ColorMask, AlphaMask);
|
||||
}
|
||||
|
||||
@ -912,6 +856,32 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
|
||||
|
||||
void Renderer::SetBlendMode(bool forceUpdate)
|
||||
{
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
const GLenum glSrcFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_DST_COLOR,
|
||||
GL_ONE_MINUS_DST_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
(target_has_alpha) ? GL_DST_ALPHA : (GLenum)GL_ONE,
|
||||
(target_has_alpha) ? GL_ONE_MINUS_DST_ALPHA : (GLenum)GL_ZERO
|
||||
};
|
||||
const GLenum glDestFactors[8] =
|
||||
{
|
||||
GL_ZERO,
|
||||
GL_ONE,
|
||||
GL_SRC_COLOR,
|
||||
GL_ONE_MINUS_SRC_COLOR,
|
||||
GL_SRC_ALPHA,
|
||||
GL_ONE_MINUS_SRC_ALPHA, // NOTE: If dual-source blending is enabled, use SRC1_ALPHA
|
||||
(target_has_alpha) ? GL_DST_ALPHA : (GLenum)GL_ONE,
|
||||
(target_has_alpha) ? GL_ONE_MINUS_DST_ALPHA : (GLenum)GL_ZERO
|
||||
};
|
||||
|
||||
// blend mode bit mask
|
||||
// 0 - blend enable
|
||||
// 2 - reverse subtract enable (else add)
|
||||
@ -955,10 +925,10 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
|
||||
if (changes & 0x1F8)
|
||||
{
|
||||
#ifdef USE_DUAL_SOURCE_BLEND
|
||||
GLenum srcFactor = glSrcFactors[(newval >> 3) & 7];
|
||||
GLenum srcFactorAlpha = srcFactor;
|
||||
GLenum dstFactor = glDestFactors[(newval >> 6) & 7];
|
||||
#ifdef USE_DUAL_SOURCE_BLEND
|
||||
GLenum srcFactorAlpha = srcFactor;
|
||||
GLenum dstFactorAlpha = dstFactor;
|
||||
if (useDualSource)
|
||||
{
|
||||
@ -979,53 +949,53 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
// blend RGB change
|
||||
glBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
|
||||
#else
|
||||
glBlendFunc(glSrcFactors[(newval >> 3) & 7], glDestFactors[(newval >> 6) & 7]);
|
||||
glBlendFunc(srcFactor, dstFactor);
|
||||
#endif
|
||||
}
|
||||
|
||||
s_blendMode = newval;
|
||||
}
|
||||
|
||||
void DumpFrame(const std::vector<u8>& data, int w, int h)
|
||||
{
|
||||
#if defined(HAVE_LIBAV) || defined(_WIN32)
|
||||
if (g_ActiveConfig.bDumpFrames && !data.empty())
|
||||
{
|
||||
AVIDump::AddFrame(&data[0], w, h);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// This function has the final picture. We adjust the aspect ratio here.
|
||||
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
|
||||
{
|
||||
static int w = 0, h = 0;
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight)
|
||||
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
#ifdef _WIN32
|
||||
AVIDump::AddFrame(frame_data);
|
||||
#elif defined HAVE_LIBAV
|
||||
AVIDump::AddFrame((u8*)frame_data, w, h);
|
||||
#endif
|
||||
DumpFrame(frame_data, w, h);
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
}
|
||||
// this function is called after the XFB field is changed, not after
|
||||
// EFB is copied to XFB. In this way, flickering is reduced in games
|
||||
// and seems to also give more FPS in ZTP
|
||||
|
||||
if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2;
|
||||
u32 xfbCount = 0;
|
||||
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
|
||||
if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB)
|
||||
if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0))
|
||||
{
|
||||
if (g_ActiveConfig.bDumpFrames && frame_data)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
AVIDump::AddFrame(frame_data);
|
||||
#elif defined HAVE_LIBAV
|
||||
AVIDump::AddFrame((u8*)frame_data, w, h);
|
||||
#endif
|
||||
}
|
||||
DumpFrame(frame_data, w, h);
|
||||
Core::Callback_VideoCopiedToXFB(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ResetAPIState();
|
||||
|
||||
TargetRectangle dst_rect;
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, true, &dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
TargetRectangle flipped_trc = GetTargetRectangle();
|
||||
|
||||
// Flip top and bottom for some reason; TODO: Fix the code to suck less?
|
||||
int tmp = flipped_trc.top;
|
||||
flipped_trc.top = flipped_trc.bottom;
|
||||
flipped_trc.bottom = tmp;
|
||||
|
||||
// Textured triangles are necessary because of post-processing shaders
|
||||
|
||||
@ -1034,7 +1004,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
OGL::TextureCache::DisableStage(i);
|
||||
|
||||
// Update GLViewPort
|
||||
glViewport(dst_rect.left, dst_rect.bottom, dst_rect.GetWidth(), dst_rect.GetHeight());
|
||||
glViewport(flipped_trc.left, flipped_trc.bottom, flipped_trc.GetWidth(), flipped_trc.GetHeight());
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
@ -1065,7 +1035,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
MathUtil::Rectangle<float> drawRc;
|
||||
|
||||
if (!g_ActiveConfig.bUseRealXFB)
|
||||
if (g_ActiveConfig.bUseRealXFB)
|
||||
{
|
||||
drawRc.top = 1;
|
||||
drawRc.bottom = -1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use virtual xfb with offset
|
||||
int xfbHeight = xfbSource->srcHeight;
|
||||
@ -1079,21 +1056,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
// The following code disables auto stretch. Kept for reference.
|
||||
// scale draw area for a 1 to 1 pixel mapping with the draw target
|
||||
//float vScale = (float)fbHeight / (float)dst_rect.GetHeight();
|
||||
//float hScale = (float)fbWidth / (float)dst_rect.GetWidth();
|
||||
//float vScale = (float)fbHeight / (float)flipped_trc.GetHeight();
|
||||
//float hScale = (float)fbWidth / (float)flipped_trc.GetWidth();
|
||||
//drawRc.top *= vScale;
|
||||
//drawRc.bottom *= vScale;
|
||||
//drawRc.left *= hScale;
|
||||
//drawRc.right *= hScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawRc.top = 1;
|
||||
drawRc.bottom = -1;
|
||||
drawRc.left = -1;
|
||||
drawRc.right = 1;
|
||||
}
|
||||
|
||||
// Tell the OSD Menu about the current internal resolution
|
||||
OSDInternalW = xfbSource->sourceRc.GetWidth(); OSDInternalH = xfbSource->sourceRc.GetHeight();
|
||||
|
||||
@ -1165,7 +1134,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (s_bScreenshot)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||
SaveScreenshot(s_sScreenshotName, dst_rect);
|
||||
SaveScreenshot(s_sScreenshotName, flipped_trc);
|
||||
// Reset settings
|
||||
s_sScreenshotName.clear();
|
||||
s_bScreenshot = false;
|
||||
@ -1176,16 +1145,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
if (g_ActiveConfig.bDumpFrames)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||
if (!frame_data || w != dst_rect.GetWidth() ||
|
||||
h != dst_rect.GetHeight())
|
||||
if (frame_data.empty() || w != flipped_trc.GetWidth() ||
|
||||
h != flipped_trc.GetHeight())
|
||||
{
|
||||
if (frame_data) delete[] frame_data;
|
||||
w = dst_rect.GetWidth();
|
||||
h = dst_rect.GetHeight();
|
||||
frame_data = new char[3 * w * h];
|
||||
w = flipped_trc.GetWidth();
|
||||
h = flipped_trc.GetHeight();
|
||||
frame_data.resize(3 * w * h);
|
||||
}
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(dst_rect.left, dst_rect.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
|
||||
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
|
||||
if (GL_REPORT_ERROR() == GL_NO_ERROR && w > 0 && h > 0)
|
||||
{
|
||||
if (!bLastFrameDumped)
|
||||
@ -1206,12 +1174,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
}
|
||||
if (bAVIDumping)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
AVIDump::AddFrame(frame_data);
|
||||
#else
|
||||
FlipImageData((u8*)frame_data, w, h);
|
||||
AVIDump::AddFrame((u8*)frame_data, w, h);
|
||||
#ifndef _WIN32
|
||||
FlipImageData(&frame_data[0], w, h);
|
||||
#endif
|
||||
|
||||
AVIDump::AddFrame(&frame_data[0], w, h);
|
||||
}
|
||||
|
||||
bLastFrameDumped = true;
|
||||
@ -1223,12 +1190,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
if (bLastFrameDumped && bAVIDumping)
|
||||
{
|
||||
if (frame_data)
|
||||
{
|
||||
delete[] frame_data;
|
||||
frame_data = NULL;
|
||||
w = h = 0;
|
||||
}
|
||||
std::vector<u8>().swap(frame_data);
|
||||
w = h = 0;
|
||||
AVIDump::Stop();
|
||||
bAVIDumping = false;
|
||||
OSD::AddMessage("Stop dumping frames", 2000);
|
||||
@ -1240,11 +1203,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||
std::string movie_file_name;
|
||||
w = dst_rect.GetWidth();
|
||||
h = dst_rect.GetHeight();
|
||||
frame_data = new char[3 * w * h];
|
||||
w = GetTargetRectangle().GetWidth();
|
||||
h = GetTargetRectangle().GetHeight();
|
||||
frame_data.resize(3 * w * h);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(dst_rect.left, dst_rect.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
|
||||
glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
|
||||
if (GL_REPORT_ERROR() == GL_NO_ERROR)
|
||||
{
|
||||
if (!bLastFrameDumped)
|
||||
@ -1255,21 +1218,17 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
|
||||
else
|
||||
{
|
||||
char msg [255];
|
||||
sprintf(msg, "Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h);
|
||||
OSD::AddMessage(msg, 2000);
|
||||
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h).c_str(), 2000);
|
||||
}
|
||||
}
|
||||
if (pFrameDump)
|
||||
{
|
||||
FlipImageData((u8*)frame_data, w, h);
|
||||
pFrameDump.WriteBytes(frame_data, w * 3 * h);
|
||||
FlipImageData(&frame_data[0], w, h);
|
||||
pFrameDump.WriteBytes(&frame_data[0], w * 3 * h);
|
||||
pFrameDump.Flush();
|
||||
}
|
||||
bLastFrameDumped = true;
|
||||
}
|
||||
|
||||
delete[] frame_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1283,24 +1242,22 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
SetWindowSize(fbWidth, fbHeight);
|
||||
|
||||
OpenGL_Update(); // just updates the render window position and the backbuffer size
|
||||
GLInterface->Update(); // just updates the render window position and the backbuffer size
|
||||
|
||||
bool xfbchanged = false;
|
||||
|
||||
if (s_XFB_width != fbWidth || s_XFB_height != fbHeight)
|
||||
if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight)
|
||||
{
|
||||
xfbchanged = true;
|
||||
s_XFB_width = fbWidth;
|
||||
s_XFB_height = fbHeight;
|
||||
if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH;
|
||||
if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT;
|
||||
unsigned int const last_w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth;
|
||||
unsigned int const last_h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
||||
FramebufferManagerBase::SetLastXfbWidth(last_w);
|
||||
FramebufferManagerBase::SetLastXfbHeight(last_h);
|
||||
}
|
||||
|
||||
bool WindowResized = false;
|
||||
int W = (int)OpenGL_GetBackbufferWidth();
|
||||
int H = (int)OpenGL_GetBackbufferHeight();
|
||||
int W = (int)GLInterface->GetBackBufferWidth();
|
||||
int H = (int)GLInterface->GetBackBufferHeight();
|
||||
if (W != s_backbuffer_width || H != s_backbuffer_height || s_LastEFBScale != g_ActiveConfig.iEFBScale)
|
||||
{
|
||||
WindowResized = true;
|
||||
@ -1311,11 +1268,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
|
||||
if (xfbchanged || WindowResized || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode))
|
||||
{
|
||||
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
||||
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
|
||||
|
||||
CalculateXYScale(dst_rect);
|
||||
|
||||
if (CalculateTargetSize() || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode))
|
||||
if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode)
|
||||
{
|
||||
s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode;
|
||||
s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode);
|
||||
@ -1328,20 +1283,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
}
|
||||
}
|
||||
|
||||
// Place messages on the picture, then copy it to the screen
|
||||
// ---------------------------------------------------------------------
|
||||
// Count FPS.
|
||||
// -------------
|
||||
static int fpscount = 0;
|
||||
static unsigned long lasttime = 0;
|
||||
if (Common::Timer::GetTimeMs() - lasttime >= 1000)
|
||||
{
|
||||
lasttime = Common::Timer::GetTimeMs();
|
||||
s_fps = fpscount;
|
||||
fpscount = 0;
|
||||
}
|
||||
if (XFBWrited)
|
||||
++fpscount;
|
||||
s_fps = UpdateFPSCounter();
|
||||
// ---------------------------------------------------------------------
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
@ -1359,7 +1302,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
// Copy the rendered frame to the real window
|
||||
OpenGL_SwapBuffers();
|
||||
GLInterface->Swap();
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
@ -1455,6 +1398,18 @@ void Renderer::SetGenerationMode()
|
||||
|
||||
void Renderer::SetDepthMode()
|
||||
{
|
||||
const GLenum glCmpFuncs[8] =
|
||||
{
|
||||
GL_NEVER,
|
||||
GL_LESS,
|
||||
GL_EQUAL,
|
||||
GL_LEQUAL,
|
||||
GL_GREATER,
|
||||
GL_NOTEQUAL,
|
||||
GL_GEQUAL,
|
||||
GL_ALWAYS
|
||||
};
|
||||
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@ -1472,7 +1427,27 @@ void Renderer::SetDepthMode()
|
||||
|
||||
void Renderer::SetLogicOpMode()
|
||||
{
|
||||
if (bpmem.blendmode.logicopenable && bpmem.blendmode.logicmode != 3)
|
||||
const GLenum glLogicOpCodes[16] =
|
||||
{
|
||||
GL_CLEAR,
|
||||
GL_AND,
|
||||
GL_AND_REVERSE,
|
||||
GL_COPY,
|
||||
GL_AND_INVERTED,
|
||||
GL_NOOP,
|
||||
GL_XOR,
|
||||
GL_OR,
|
||||
GL_NOR,
|
||||
GL_EQUIV,
|
||||
GL_INVERT,
|
||||
GL_OR_REVERSE,
|
||||
GL_COPY_INVERTED,
|
||||
GL_OR_INVERTED,
|
||||
GL_NAND,
|
||||
GL_SET
|
||||
};
|
||||
|
||||
if (bpmem.blendmode.logicopenable)
|
||||
{
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
|
||||
|
@ -58,24 +58,6 @@ namespace OGL
|
||||
|
||||
static u32 s_TempFramebuffer = 0;
|
||||
|
||||
static const GLint c_MinLinearFilter[8] = {
|
||||
GL_NEAREST,
|
||||
GL_NEAREST_MIPMAP_NEAREST,
|
||||
GL_NEAREST_MIPMAP_LINEAR,
|
||||
GL_NEAREST,
|
||||
GL_LINEAR,
|
||||
GL_LINEAR_MIPMAP_NEAREST,
|
||||
GL_LINEAR_MIPMAP_LINEAR,
|
||||
GL_LINEAR,
|
||||
};
|
||||
|
||||
static const GLint c_WrapSettings[4] = {
|
||||
GL_CLAMP_TO_EDGE,
|
||||
GL_REPEAT,
|
||||
GL_MIRRORED_REPEAT,
|
||||
GL_REPEAT,
|
||||
};
|
||||
|
||||
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
|
||||
{
|
||||
int width = std::max(virtual_width >> level, 1);
|
||||
@ -196,12 +178,14 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||
entry.pcfmt = pcfmt;
|
||||
|
||||
entry.bHaveMipMaps = tex_levels != 1;
|
||||
|
||||
entry.Load(width, height, expanded_width, 0);
|
||||
|
||||
return &entry;
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips)
|
||||
unsigned int expanded_width, unsigned int level)
|
||||
{
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
@ -212,16 +196,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
||||
if (expanded_width != width)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
||||
|
||||
if (bHaveMipMaps && autogen_mips)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
||||
|
||||
if (expanded_width != width)
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
@ -330,15 +305,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
srcRect);
|
||||
|
||||
u8* dst = Memory::GetPointer(addr);
|
||||
u64 hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
||||
u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
||||
|
||||
// Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
|
||||
if (!g_ActiveConfig.bEFBCopyCacheEnable)
|
||||
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
||||
else if (!TextureCache::Find(addr, hash))
|
||||
else if (!TextureCache::Find(addr, new_hash))
|
||||
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
||||
|
||||
this->hash = hash;
|
||||
hash = new_hash;
|
||||
}
|
||||
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
@ -357,35 +332,43 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
|
||||
void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1)
|
||||
{
|
||||
// TODO: not used anywhere
|
||||
TexMode0 mode = newmode;
|
||||
//mode1 = newmode1;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
if (bHaveMipMaps)
|
||||
const GLint c_MinLinearFilter[8] =
|
||||
{
|
||||
// TODO: not used anywhere
|
||||
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
|
||||
mode.min_filter += 4; // take equivalent forced linear
|
||||
GL_NEAREST,
|
||||
GL_NEAREST_MIPMAP_NEAREST,
|
||||
GL_NEAREST_MIPMAP_LINEAR,
|
||||
GL_NEAREST,
|
||||
GL_LINEAR,
|
||||
GL_LINEAR_MIPMAP_NEAREST,
|
||||
GL_LINEAR_MIPMAP_LINEAR,
|
||||
GL_LINEAR,
|
||||
};
|
||||
const GLint c_WrapSettings[4] =
|
||||
{
|
||||
GL_CLAMP_TO_EDGE,
|
||||
GL_REPEAT,
|
||||
GL_MIRRORED_REPEAT,
|
||||
GL_REPEAT,
|
||||
};
|
||||
|
||||
int filt = newmode.min_filter;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod >> 4);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod >> 4);
|
||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (newmode.lod_bias / 32.0f));
|
||||
}
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(g_ActiveConfig.bForceFiltering || newmode.min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
|
||||
int filt = newmode.min_filter;
|
||||
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
|
||||
filt += 4; // take equivalent forced linear
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod / 16.f);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod / 16.f);
|
||||
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (s32)newmode.lod_bias / 32.0f);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, c_WrapSettings[newmode.wrap_s]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, c_WrapSettings[newmode.wrap_t]);
|
||||
|
||||
// TODO: Reset anisotrop when changed to 1
|
||||
if (g_Config.iMaxAnisotropy >= 1)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
(float)(1 << g_ActiveConfig.iMaxAnisotropy));
|
||||
(float)(1 << g_ActiveConfig.iMaxAnisotropy));
|
||||
}
|
||||
|
||||
TextureCache::~TextureCache()
|
||||
|
@ -54,7 +54,7 @@ private:
|
||||
~TCacheEntry();
|
||||
|
||||
void Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level, bool autogen_mips = false);
|
||||
unsigned int expanded_width, unsigned int level);
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
|
@ -70,6 +70,16 @@ VertexManager::VertexManager()
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
void VertexManager::CreateDeviceObjects()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
void VertexManager::DestroyDeviceObjects()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VertexManager::Draw()
|
||||
{
|
||||
if (IndexGenerator::GetNumTriangles() > 0)
|
||||
@ -119,8 +129,8 @@ void VertexManager::vFlush()
|
||||
xfregs.postMtxInfo[i].index, xfregs.postMtxInfo[i].normalize);
|
||||
}
|
||||
|
||||
PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
|
||||
bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alphaFunc.hex>>16)&0xff);
|
||||
PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
|
||||
bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff);
|
||||
#endif
|
||||
|
||||
(void)GL_REPORT_ERROR();
|
||||
@ -155,8 +165,8 @@ void VertexManager::vFlush()
|
||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||
tex.texTlut[i&3].tlut_format,
|
||||
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8),
|
||||
tex.texMode1[i&3].max_lod >> 4,
|
||||
(tex.texMode0[i&3].min_filter & 3),
|
||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||
tex.texImage1[i&3].image_type);
|
||||
|
||||
if (tentry)
|
||||
|
@ -33,7 +33,8 @@ public:
|
||||
VertexManager();
|
||||
|
||||
NativeVertexFormat* CreateNativeVertexFormat();
|
||||
|
||||
void CreateDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
private:
|
||||
void Draw();
|
||||
// temp
|
||||
|
@ -88,7 +88,6 @@ Make AA apply instantly during gameplay if possible
|
||||
#include "TextureConverter.h"
|
||||
#include "PostProcessing.h"
|
||||
#include "OnScreenDisplay.h"
|
||||
#include "Setup.h"
|
||||
#include "DLCache.h"
|
||||
#include "FramebufferManager.h"
|
||||
#include "Core.h"
|
||||
@ -132,6 +131,7 @@ void InitBackendInfo()
|
||||
{
|
||||
g_Config.backend_info.APIType = API_OPENGL;
|
||||
g_Config.backend_info.bUseRGBATextures = false;
|
||||
g_Config.backend_info.bUseMinimalMipCount = false;
|
||||
g_Config.backend_info.bSupports3DVision = false;
|
||||
g_Config.backend_info.bSupportsDualSourceBlend = false; // supported, but broken
|
||||
g_Config.backend_info.bSupportsFormatReinterpretation = false;
|
||||
@ -168,7 +168,8 @@ bool VideoBackend::Initialize(void *&window_handle)
|
||||
g_Config.VerifyValidity();
|
||||
UpdateActiveConfig();
|
||||
|
||||
if (!OpenGL_Create(window_handle))
|
||||
InitInterface();
|
||||
if (!GLInterface->Create(window_handle))
|
||||
return false;
|
||||
|
||||
s_BackendInitialized = true;
|
||||
@ -180,7 +181,7 @@ bool VideoBackend::Initialize(void *&window_handle)
|
||||
// Run from the graphics thread
|
||||
void VideoBackend::Video_Prepare()
|
||||
{
|
||||
OpenGL_MakeCurrent();
|
||||
GLInterface->MakeCurrent();
|
||||
|
||||
g_renderer = new Renderer;
|
||||
|
||||
@ -206,7 +207,9 @@ void VideoBackend::Video_Prepare()
|
||||
GL_REPORT_ERRORD();
|
||||
VertexLoaderManager::Init();
|
||||
TextureConverter::Init();
|
||||
#ifndef _M_GENERIC
|
||||
DLCache::Init();
|
||||
#endif
|
||||
|
||||
// Notify the core that the video backend is ready
|
||||
Host_Message(WM_USER_CREATE);
|
||||
@ -221,7 +224,9 @@ void VideoBackend::Shutdown()
|
||||
s_efbAccessRequested = false;
|
||||
s_FifoShuttingDown = false;
|
||||
s_swapRequested = false;
|
||||
#ifndef _M_GENERIC
|
||||
DLCache::Shutdown();
|
||||
#endif
|
||||
Fifo_Shutdown();
|
||||
PostProcessing::Shutdown();
|
||||
|
||||
@ -240,7 +245,7 @@ void VideoBackend::Shutdown()
|
||||
g_renderer = NULL;
|
||||
g_texture_cache = NULL;
|
||||
}
|
||||
OpenGL_Shutdown();
|
||||
GLInterface->Shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,13 +26,25 @@ if(wxWidgets_FOUND)
|
||||
endif(wxWidgets_FOUND)
|
||||
|
||||
set(LIBS videocommon
|
||||
GLEW
|
||||
SOIL
|
||||
common
|
||||
${OPENGL_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${wxWidgets_LIBRARIES})
|
||||
if(USE_EGL)
|
||||
set(LIBS ${LIBS}
|
||||
EGL)
|
||||
endif()
|
||||
|
||||
if(USE_GLES)
|
||||
set(SRCS ${SRCS}
|
||||
../Plugin_VideoOGL/Src/GLUtil.cpp)
|
||||
set(LIBS ${LIBS}
|
||||
GLESv2)
|
||||
else()
|
||||
set(LIBS ${LIBS}
|
||||
GLEW
|
||||
${OPENGL_LIBRARIES})
|
||||
endif()
|
||||
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
|
||||
set(LIBS ${LIBS} clrun)
|
||||
endif()
|
||||
|
@ -126,7 +126,46 @@ void SWBPWritten(int address, int newvalue)
|
||||
PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case BPMEM_PRELOAD_MODE:
|
||||
if (newvalue != 0)
|
||||
{
|
||||
// TODO: Not quite sure if this is completely correct (likely not)
|
||||
// NOTE: libogc's implementation of GX_PreloadEntireTexture seems flawed, so it's not necessarily a good reference for RE'ing this feature.
|
||||
|
||||
BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
|
||||
u8* src_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5); // TODO: Should we add mask here on GC?
|
||||
u32 size = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE;
|
||||
u32 tmem_addr_even = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
|
||||
|
||||
if (tmem_cfg.preload_tile_info.type != 3)
|
||||
{
|
||||
if (tmem_addr_even + size > TMEM_SIZE)
|
||||
size = TMEM_SIZE - tmem_addr_even;
|
||||
|
||||
memcpy(texMem + tmem_addr_even, src_ptr, size);
|
||||
}
|
||||
else // RGBA8 tiles (and CI14, but that might just be stupid libogc!)
|
||||
{
|
||||
// AR and GB tiles are stored in separate TMEM banks => can't use a single memcpy for everything
|
||||
u32 tmem_addr_odd = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE;
|
||||
|
||||
for (unsigned int i = 0; i < tmem_cfg.preload_tile_info.count; ++i)
|
||||
{
|
||||
if (tmem_addr_even + TMEM_LINE_SIZE > TMEM_SIZE ||
|
||||
tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE)
|
||||
break;
|
||||
|
||||
memcpy(texMem + tmem_addr_even, src_ptr, TMEM_LINE_SIZE);
|
||||
memcpy(texMem + tmem_addr_odd, src_ptr + TMEM_LINE_SIZE, TMEM_LINE_SIZE);
|
||||
tmem_addr_even += TMEM_LINE_SIZE;
|
||||
tmem_addr_odd += TMEM_LINE_SIZE;
|
||||
src_ptr += TMEM_LINE_SIZE * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BPMEM_TEV_REGISTER_L: // Reg 1
|
||||
case BPMEM_TEV_REGISTER_L+2: // Reg 2
|
||||
case BPMEM_TEV_REGISTER_L+4: // Reg 3
|
||||
|
@ -65,6 +65,13 @@ namespace Clipper
|
||||
OutputVertexData ClippedVertices[NUM_CLIPPED_VERTICES];
|
||||
OutputVertexData *Vertices[NUM_INDICES];
|
||||
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(m_ViewOffset,2);
|
||||
for (int i = 0; i< NUM_CLIPPED_VERTICES; ++i)
|
||||
ClippedVertices[i].DoState(p);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
for (int i = 0; i < NUM_CLIPPED_VERTICES; ++i)
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "NativeVertexFormat.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
|
||||
namespace Clipper
|
||||
@ -36,6 +37,8 @@ namespace Clipper
|
||||
bool CullTest(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2, bool &backface);
|
||||
|
||||
void PerspectiveDivide(OutputVertexData *vertex);
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,8 +62,8 @@ void SaveTexture(const char* filename, u32 texmap, s32 mip)
|
||||
|
||||
TexImage0& ti0 = texUnit.texImage0[subTexmap];
|
||||
|
||||
int width = ti0.width + 1;
|
||||
int height = ti0.height + 1;
|
||||
u32 width = ti0.width + 1;
|
||||
u32 height = ti0.height + 1;
|
||||
|
||||
u8 *data = new u8[width * height * 4];
|
||||
|
||||
@ -74,19 +74,23 @@ void SaveTexture(const char* filename, u32 texmap, s32 mip)
|
||||
delete []data;
|
||||
}
|
||||
|
||||
void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, int width, int height)
|
||||
void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height)
|
||||
{
|
||||
u8 sample[4];
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (u32 y = 0; y < height; y++)
|
||||
{
|
||||
for (u32 x = 0; x < width; x++)
|
||||
{
|
||||
TextureSampler::SampleMip(x << 7, y << 7, mip, false, texmap, sample);
|
||||
// rgba to bgra
|
||||
|
||||
// RGBA to BGRA
|
||||
*(dst++) = sample[2];
|
||||
*(dst++) = sample[1];
|
||||
*(dst++) = sample[0];
|
||||
*(dst++) = sample[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s32 GetMaxTextureLod(u32 texmap)
|
||||
|
@ -22,7 +22,7 @@ namespace DebugUtil
|
||||
{
|
||||
void Init();
|
||||
|
||||
void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, int width, int height);
|
||||
void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height);
|
||||
|
||||
void DumpActiveTextures();
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "DebugUtil.h"
|
||||
#include "HwRasterizer.h"
|
||||
#include "SWCommandProcessor.h"
|
||||
#include "../../Plugin_VideoOGL/Src/GLUtil.h"
|
||||
#include "HW/Memmap.h"
|
||||
#include "Core.h"
|
||||
|
||||
@ -33,7 +32,7 @@ namespace EfbCopy
|
||||
{
|
||||
void CopyToXfb()
|
||||
{
|
||||
OpenGL_Update(); // just updates the render window position and the backbuffer size
|
||||
GLInterface->Update(); // just updates the render window position and the backbuffer size
|
||||
|
||||
if (!g_SWVideoConfig.bHwRasterizer)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ u8 efb[EFB_WIDTH*EFB_HEIGHT*6];
|
||||
|
||||
namespace EfbInterface
|
||||
{
|
||||
|
||||
u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4];
|
||||
|
||||
inline u32 GetColorOffset(u16 x, u16 y)
|
||||
@ -40,6 +41,12 @@ namespace EfbInterface
|
||||
return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START;
|
||||
}
|
||||
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(efb, EFB_WIDTH*EFB_HEIGHT*6);
|
||||
p.DoArray(efbColorTexture, EFB_WIDTH*EFB_HEIGHT*4);
|
||||
}
|
||||
|
||||
void SetPixelAlphaOnly(u32 offset, u8 a)
|
||||
{
|
||||
switch (bpmem.zcontrol.pixel_format)
|
||||
@ -355,7 +362,7 @@ namespace EfbInterface
|
||||
dstClr = (~srcClr) & dstClr;
|
||||
break;
|
||||
case 5: // noop
|
||||
dstClr = dstClr;
|
||||
// Do nothing
|
||||
break;
|
||||
case 6: // xor
|
||||
dstClr = srcClr ^ dstClr;
|
||||
|
@ -47,6 +47,7 @@ namespace EfbInterface
|
||||
|
||||
void UpdateColorTexture();
|
||||
extern u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; // RGBA format
|
||||
void DoState(PointerWrap &p);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -29,163 +29,354 @@
|
||||
|
||||
namespace HwRasterizer
|
||||
{
|
||||
float efbHalfWidth;
|
||||
float efbHalfHeight;
|
||||
bool hasTexture;
|
||||
float efbHalfWidth;
|
||||
float efbHalfHeight;
|
||||
bool hasTexture;
|
||||
|
||||
u8 *temp;
|
||||
u8 *temp;
|
||||
|
||||
void Init()
|
||||
{
|
||||
efbHalfWidth = EFB_WIDTH / 2.0f;
|
||||
efbHalfHeight = 480 / 2.0f;
|
||||
// Programs
|
||||
static GLuint colProg, texProg, clearProg;
|
||||
|
||||
temp = (u8*)AllocateMemoryPages(TEMP_SIZE);
|
||||
}
|
||||
// Color
|
||||
static GLint col_apos = -1, col_atex = -1;
|
||||
// Tex
|
||||
static GLint tex_apos = -1, tex_atex = -1, tex_utex = -1;
|
||||
// Clear shader
|
||||
static GLint clear_apos = -1, clear_ucol = -1;
|
||||
|
||||
void LoadTexture()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
u32 imageAddr = texUnit.texImage3[0].image_base;
|
||||
void CreateShaders()
|
||||
{
|
||||
// Color Vertices
|
||||
static const char *fragcolText =
|
||||
"varying " PREC " vec4 TexCoordOut;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = TexCoordOut;\n"
|
||||
"}\n";
|
||||
// Texture Vertices
|
||||
static const char *fragtexText =
|
||||
"varying " PREC " vec4 TexCoordOut;\n"
|
||||
"uniform " TEXTYPE " Texture;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = " TEXFUNC "(Texture, TexCoordOut.xy);\n"
|
||||
"}\n";
|
||||
// Clear shader
|
||||
static const char *fragclearText =
|
||||
"uniform " PREC " vec4 Color;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = Color;\n"
|
||||
"}\n";
|
||||
// Generic passthrough vertice shaders
|
||||
static const char *vertShaderText =
|
||||
"attribute vec4 pos;\n"
|
||||
"attribute vec4 TexCoordIn;\n "
|
||||
"varying vec4 TexCoordOut;\n "
|
||||
"void main() {\n"
|
||||
" gl_Position = pos;\n"
|
||||
" TexCoordOut = TexCoordIn;\n"
|
||||
"}\n";
|
||||
static const char *vertclearText =
|
||||
"attribute vec4 pos;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = pos;\n"
|
||||
"}\n";
|
||||
|
||||
TexCacheEntry &cacheEntry = textures[imageAddr];
|
||||
cacheEntry.Update();
|
||||
// Color Program
|
||||
colProg = OpenGL_CompileProgram(vertShaderText, fragcolText);
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, cacheEntry.texture);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
|
||||
}
|
||||
// Texture Program
|
||||
texProg = OpenGL_CompileProgram(vertShaderText, fragtexText);
|
||||
|
||||
void BeginTriangles()
|
||||
{
|
||||
// disabling depth test sometimes allows more things to be visible
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
// Clear Program
|
||||
clearProg = OpenGL_CompileProgram(vertclearText, fragclearText);
|
||||
|
||||
hasTexture = bpmem.tevorders[0].enable0;
|
||||
// Color attributes
|
||||
col_apos = glGetAttribLocation(colProg, "pos");
|
||||
col_atex = glGetAttribLocation(colProg, "TexCoordIn");
|
||||
// Texture attributes
|
||||
tex_apos = glGetAttribLocation(texProg, "pos");
|
||||
tex_atex = glGetAttribLocation(texProg, "TexCoordIn");
|
||||
tex_utex = glGetUniformLocation(texProg, "Texture");
|
||||
// Clear attributes
|
||||
clear_apos = glGetAttribLocation(clearProg, "pos");
|
||||
clear_ucol = glGetUniformLocation(clearProg, "Color");
|
||||
}
|
||||
|
||||
if (hasTexture)
|
||||
LoadTexture();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
efbHalfWidth = EFB_WIDTH / 2.0f;
|
||||
efbHalfHeight = 480 / 2.0f;
|
||||
|
||||
void EndTriangles()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
temp = (u8*)AllocateMemoryPages(TEMP_SIZE);
|
||||
}
|
||||
void Shutdown()
|
||||
{
|
||||
glDeleteProgram(colProg);
|
||||
glDeleteProgram(texProg);
|
||||
glDeleteProgram(clearProg);
|
||||
}
|
||||
void Prepare()
|
||||
{
|
||||
//legacy multitexturing: select texture channel only.
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
|
||||
#ifndef USE_GLES
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDisable(GL_BLEND);
|
||||
glClearDepth(1.0f);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||
glStencilFunc(GL_ALWAYS, 0, 0);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
#endif
|
||||
// used by hw rasterizer if it enables blending and depth test
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
void DrawColorVertex(OutputVertexData *v)
|
||||
{
|
||||
glColor3ub(v->color[0][OutputVertexData::RED_C], v->color[0][OutputVertexData::GRN_C], v->color[0][OutputVertexData::BLU_C]);
|
||||
glVertex3f(v->screenPosition.x / efbHalfWidth - 1.0f, 1.0f - v->screenPosition.y / efbHalfHeight, v->screenPosition.z / (float)0x00ffffff);
|
||||
}
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
CreateShaders();
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
static float width, height;
|
||||
void LoadTexture()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
u32 imageAddr = texUnit.texImage3[0].image_base;
|
||||
// Texture Rectangle uses pixel coordinates
|
||||
// While GLES uses texture coordinates
|
||||
#ifdef USE_GLES
|
||||
width = texUnit.texImage0[0].width;
|
||||
height = texUnit.texImage0[0].height;
|
||||
#else
|
||||
width = 1;
|
||||
height = 1;
|
||||
#endif
|
||||
TexCacheEntry &cacheEntry = textures[imageAddr];
|
||||
cacheEntry.Update();
|
||||
|
||||
void DrawTextureVertex(OutputVertexData *v)
|
||||
{
|
||||
float s = v->texCoords[0].x;
|
||||
float t = v->texCoords[0].y;
|
||||
glTexCoord2f(s, t);
|
||||
glBindTexture(TEX2D, cacheEntry.texture);
|
||||
glTexParameteri(TEX2D, GL_TEXTURE_MAG_FILTER, texUnit.texMode0[0].mag_filter ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(TEX2D, GL_TEXTURE_MIN_FILTER, (texUnit.texMode0[0].min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
float x = (v->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y = 1.0f - (v->screenPosition.y / efbHalfHeight);
|
||||
float z = v->screenPosition.z;
|
||||
glVertex3f(x, y, z);
|
||||
}
|
||||
void BeginTriangles()
|
||||
{
|
||||
// disabling depth test sometimes allows more things to be visible
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
if (hasTexture)
|
||||
{
|
||||
DrawTextureVertex(v0);
|
||||
DrawTextureVertex(v1);
|
||||
DrawTextureVertex(v2);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawColorVertex(v0);
|
||||
DrawColorVertex(v1);
|
||||
DrawColorVertex(v2);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
hasTexture = bpmem.tevorders[0].enable0;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
u8 r = (bpmem.clearcolorAR & 0x00ff);
|
||||
u8 g = (bpmem.clearcolorGB & 0xff00) >> 8;
|
||||
u8 b = (bpmem.clearcolorGB & 0x00ff);
|
||||
u8 a = (bpmem.clearcolorAR & 0xff00) >> 8;
|
||||
if (hasTexture)
|
||||
LoadTexture();
|
||||
}
|
||||
|
||||
GLfloat left = (GLfloat)bpmem.copyTexSrcXY.x / efbHalfWidth - 1.0f;
|
||||
GLfloat top = 1.0f - (GLfloat)bpmem.copyTexSrcXY.y / efbHalfHeight;
|
||||
GLfloat right = (GLfloat)(left + bpmem.copyTexSrcWH.x + 1) / efbHalfWidth - 1.0f;
|
||||
GLfloat bottom = 1.0f - (GLfloat)(top + bpmem.copyTexSrcWH.y + 1) / efbHalfHeight;
|
||||
GLfloat depth = (GLfloat)bpmem.clearZValue / (GLfloat)0x00ffffff;
|
||||
void EndTriangles()
|
||||
{
|
||||
glBindTexture(TEX2D, 0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor4ub(r, g, b, a);
|
||||
glVertex3f(left, top, depth);
|
||||
glColor4ub(r, g, b, a);
|
||||
glVertex3f(right, top, depth);
|
||||
glColor4ub(r, g, b, a);
|
||||
glVertex3f(right, bottom, depth);
|
||||
glColor4ub(r, g, b, a);
|
||||
glVertex3f(left, bottom, depth);
|
||||
glEnd();
|
||||
}
|
||||
void DrawColorVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
|
||||
{
|
||||
float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight);
|
||||
float z0 = v0->screenPosition.z / (float)0x00ffffff;
|
||||
|
||||
TexCacheEntry::TexCacheEntry()
|
||||
{
|
||||
Create();
|
||||
}
|
||||
float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight);
|
||||
float z1 = v1->screenPosition.z / (float)0x00ffffff;
|
||||
|
||||
void TexCacheEntry::Create()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight);
|
||||
float z2 = v2->screenPosition.z / (float)0x00ffffff;
|
||||
|
||||
texImage0.hex = texUnit.texImage0[0].hex;
|
||||
texImage1.hex = texUnit.texImage1[0].hex;
|
||||
texImage2.hex = texUnit.texImage2[0].hex;
|
||||
texImage3.hex = texUnit.texImage3[0].hex;
|
||||
texTlut.hex = texUnit.texTlut[0].hex;
|
||||
float r0 = v0->color[0][OutputVertexData::RED_C] / 255.0f;
|
||||
float g0 = v0->color[0][OutputVertexData::GRN_C] / 255.0f;
|
||||
float b0 = v0->color[0][OutputVertexData::BLU_C] / 255.0f;
|
||||
|
||||
int width = texImage0.width;
|
||||
int height = texImage0.height;
|
||||
float r1 = v1->color[0][OutputVertexData::RED_C] / 255.0f;
|
||||
float g1 = v1->color[0][OutputVertexData::GRN_C] / 255.0f;
|
||||
float b1 = v1->color[0][OutputVertexData::BLU_C] / 255.0f;
|
||||
|
||||
DebugUtil::GetTextureBGRA(temp, 0, 0, width, height);
|
||||
float r2 = v2->color[0][OutputVertexData::RED_C] / 255.0f;
|
||||
float g2 = v2->color[0][OutputVertexData::GRN_C] / 255.0f;
|
||||
float b2 = v2->color[0][OutputVertexData::BLU_C] / 255.0f;
|
||||
|
||||
glGenTextures(1, (GLuint *)&texture);
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp);
|
||||
}
|
||||
static const GLfloat verts[3][3] = {
|
||||
{ x0, y0, z0 },
|
||||
{ x1, y1, z1 },
|
||||
{ x2, y2, z2 }
|
||||
};
|
||||
static const GLfloat col[3][4] = {
|
||||
{ r0, g0, b0, 1.0f },
|
||||
{ r1, g1, b1, 1.0f },
|
||||
{ r2, g2, b2, 1.0f }
|
||||
};
|
||||
{
|
||||
glUseProgram(colProg);
|
||||
glEnableVertexAttribArray(col_apos);
|
||||
glEnableVertexAttribArray(col_atex);
|
||||
|
||||
void TexCacheEntry::Destroy()
|
||||
{
|
||||
if (texture == 0)
|
||||
return;
|
||||
glVertexAttribPointer(col_apos, 3, GL_FLOAT, GL_FALSE, 0, verts);
|
||||
glVertexAttribPointer(col_atex, 4, GL_FLOAT, GL_FALSE, 0, col);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glDisableVertexAttribArray(col_atex);
|
||||
glDisableVertexAttribArray(col_apos);
|
||||
}
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &texture);
|
||||
texture = 0;
|
||||
}
|
||||
void DrawTextureVertex(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
|
||||
{
|
||||
float x0 = (v0->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y0 = 1.0f - (v0->screenPosition.y / efbHalfHeight);
|
||||
float z0 = v0->screenPosition.z;
|
||||
|
||||
void TexCacheEntry::Update()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
float x1 = (v1->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y1 = 1.0f - (v1->screenPosition.y / efbHalfHeight);
|
||||
float z1 = v1->screenPosition.z;
|
||||
|
||||
// extra checks cause textures to be reloaded much more
|
||||
if (texUnit.texImage0[0].hex != texImage0.hex ||
|
||||
//texUnit.texImage1[0].hex != texImage1.hex ||
|
||||
//texUnit.texImage2[0].hex != texImage2.hex ||
|
||||
texUnit.texImage3[0].hex != texImage3.hex ||
|
||||
texUnit.texTlut[0].hex != texTlut.hex)
|
||||
{
|
||||
Destroy();
|
||||
Create();
|
||||
}
|
||||
}
|
||||
float x2 = (v2->screenPosition.x / efbHalfWidth) - 1.0f;
|
||||
float y2 = 1.0f - (v2->screenPosition.y / efbHalfHeight);
|
||||
float z2 = v2->screenPosition.z;
|
||||
|
||||
float s0 = v0->texCoords[0].x / width;
|
||||
float t0 = v0->texCoords[0].y / height;
|
||||
|
||||
float s1 = v1->texCoords[0].x / width;
|
||||
float t1 = v1->texCoords[0].y / height;
|
||||
|
||||
float s2 = v2->texCoords[0].x / width;
|
||||
float t2 = v2->texCoords[0].y / height;
|
||||
|
||||
static const GLfloat verts[3][3] = {
|
||||
{ x0, y0, z0 },
|
||||
{ x1, y1, z1 },
|
||||
{ x2, y2, z2 }
|
||||
};
|
||||
static const GLfloat tex[3][2] = {
|
||||
{ s0, t0 },
|
||||
{ s1, t1 },
|
||||
{ s2, t2 }
|
||||
};
|
||||
{
|
||||
glUseProgram(texProg);
|
||||
glEnableVertexAttribArray(tex_apos);
|
||||
glEnableVertexAttribArray(tex_atex);
|
||||
|
||||
glVertexAttribPointer(tex_apos, 3, GL_FLOAT, GL_FALSE, 0, verts);
|
||||
glVertexAttribPointer(tex_atex, 2, GL_FLOAT, GL_FALSE, 0, tex);
|
||||
glUniform1i(tex_utex, 0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glDisableVertexAttribArray(tex_atex);
|
||||
glDisableVertexAttribArray(tex_apos);
|
||||
}
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2)
|
||||
{
|
||||
if (hasTexture)
|
||||
DrawTextureVertex(v0, v1, v2);
|
||||
else
|
||||
DrawColorVertex(v0, v1, v2);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
u8 r = (bpmem.clearcolorAR & 0x00ff);
|
||||
u8 g = (bpmem.clearcolorGB & 0xff00) >> 8;
|
||||
u8 b = (bpmem.clearcolorGB & 0x00ff);
|
||||
u8 a = (bpmem.clearcolorAR & 0xff00) >> 8;
|
||||
|
||||
GLfloat left = (GLfloat)bpmem.copyTexSrcXY.x / efbHalfWidth - 1.0f;
|
||||
GLfloat top = 1.0f - (GLfloat)bpmem.copyTexSrcXY.y / efbHalfHeight;
|
||||
GLfloat right = (GLfloat)(left + bpmem.copyTexSrcWH.x + 1) / efbHalfWidth - 1.0f;
|
||||
GLfloat bottom = 1.0f - (GLfloat)(top + bpmem.copyTexSrcWH.y + 1) / efbHalfHeight;
|
||||
GLfloat depth = (GLfloat)bpmem.clearZValue / (GLfloat)0x00ffffff;
|
||||
static const GLfloat verts[4][3] = {
|
||||
{ left, top, depth },
|
||||
{ right, top, depth },
|
||||
{ right, bottom, depth },
|
||||
{ left, bottom, depth }
|
||||
};
|
||||
{
|
||||
glUseProgram(clearProg);
|
||||
glVertexAttribPointer(clear_apos, 3, GL_FLOAT, GL_FALSE, 0, verts);
|
||||
glUniform4f(clear_ucol, r, g, b, a);
|
||||
glEnableVertexAttribArray(col_apos);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableVertexAttribArray(col_apos);
|
||||
}
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
TexCacheEntry::TexCacheEntry()
|
||||
{
|
||||
Create();
|
||||
}
|
||||
|
||||
void TexCacheEntry::Create()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
|
||||
texImage0.hex = texUnit.texImage0[0].hex;
|
||||
texImage1.hex = texUnit.texImage1[0].hex;
|
||||
texImage2.hex = texUnit.texImage2[0].hex;
|
||||
texImage3.hex = texUnit.texImage3[0].hex;
|
||||
texTlut.hex = texUnit.texTlut[0].hex;
|
||||
|
||||
int image_width = texImage0.width;
|
||||
int image_height = texImage0.height;
|
||||
|
||||
DebugUtil::GetTextureBGRA(temp, 0, 0, image_width, image_height);
|
||||
|
||||
glGenTextures(1, (GLuint *)&texture);
|
||||
glBindTexture(TEX2D, texture);
|
||||
#ifdef USE_GLES
|
||||
glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)image_width, (GLsizei)image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
|
||||
#else
|
||||
glTexImage2D(TEX2D, 0, GL_RGBA8, (GLsizei)image_width, (GLsizei)image_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp);
|
||||
#endif
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
void TexCacheEntry::Destroy()
|
||||
{
|
||||
if (texture == 0)
|
||||
return;
|
||||
|
||||
glDeleteTextures(1, &texture);
|
||||
texture = 0;
|
||||
}
|
||||
|
||||
void TexCacheEntry::Update()
|
||||
{
|
||||
FourTexUnits &texUnit = bpmem.tex[0];
|
||||
|
||||
// extra checks cause textures to be reloaded much more
|
||||
if (texUnit.texImage0[0].hex != texImage0.hex ||
|
||||
//texUnit.texImage1[0].hex != texImage1.hex ||
|
||||
//texUnit.texImage2[0].hex != texImage2.hex ||
|
||||
texUnit.texImage3[0].hex != texImage3.hex ||
|
||||
texUnit.texTlut[0].hex != texTlut.hex)
|
||||
{
|
||||
Destroy();
|
||||
Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,9 @@ struct OutputVertexData;
|
||||
namespace HwRasterizer
|
||||
{
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
void Prepare();
|
||||
|
||||
void BeginTriangles();
|
||||
void EndTriangles();
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define _NATIVEVERTEXFORMAT_H
|
||||
|
||||
#include "Vec3.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define LOADERDECL __cdecl
|
||||
@ -92,6 +93,18 @@ struct OutputVertexData
|
||||
#undef LINTERP
|
||||
#undef LINTERP_INT
|
||||
}
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
mvPosition.DoState(p);
|
||||
p.Do(projectedPosition);
|
||||
screenPosition.DoState(p);
|
||||
for (int i = 0; i < 3;++i)
|
||||
normal[i].DoState(p);
|
||||
p.DoArray(color, sizeof color);
|
||||
for (int i = 0; i < 8;++i)
|
||||
texCoords[i].DoState(p);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,6 @@ typedef void (*DecodingFunction)(u32);
|
||||
|
||||
namespace OpcodeDecoder
|
||||
{
|
||||
|
||||
static DecodingFunction currentFunction = NULL;
|
||||
static u32 minCommandSize;
|
||||
static u16 streamSize;
|
||||
@ -46,6 +45,20 @@ static bool inObjectStream;
|
||||
static u8 lastPrimCmd;
|
||||
|
||||
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(minCommandSize);
|
||||
// Not sure what is wrong with this. Something(s) in here is causing dolphin to crash/hang when loading states saved from another run of dolphin. Doesn't seem too important anyway...
|
||||
//vertexLoader.DoState(p);
|
||||
p.Do(readOpcode);
|
||||
p.Do(inObjectStream);
|
||||
p.Do(lastPrimCmd);
|
||||
p.Do(streamSize);
|
||||
p.Do(streamAddress);
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
ResetDecoding();
|
||||
}
|
||||
|
||||
void DecodePrimitiveStream(u32 iBufferSize)
|
||||
{
|
||||
u32 vertexSize = vertexLoader.GetVertexSize();
|
||||
@ -125,7 +138,9 @@ void DecodeStandard(u32 bufferSize)
|
||||
|
||||
if (Cmd == GX_NOP)
|
||||
return;
|
||||
|
||||
// Causes a SIGBUS error on Android
|
||||
// XXX: Investigate
|
||||
#ifndef ANDROID
|
||||
// check if switching in or out of an object
|
||||
// only used for debuggging
|
||||
if (inObjectStream && (Cmd & 0x87) != lastPrimCmd)
|
||||
@ -139,7 +154,7 @@ void DecodeStandard(u32 bufferSize)
|
||||
lastPrimCmd = Cmd & 0x87;
|
||||
DebugUtil::OnObjectBegin();
|
||||
}
|
||||
|
||||
#endif
|
||||
switch(Cmd)
|
||||
{
|
||||
case GX_NOP:
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define _OPCODEDECODER_H_
|
||||
|
||||
#include "CommonTypes.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
namespace OpcodeDecoder
|
||||
{
|
||||
@ -57,6 +58,8 @@ namespace OpcodeDecoder
|
||||
bool CommandRunnable(u32 iBufferSize);
|
||||
|
||||
void Run(u32 iBufferSize);
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -63,6 +63,28 @@ s32 scissorBottom = 0;
|
||||
Tev tev;
|
||||
RasterBlock rasterBlock;
|
||||
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
ZSlope.DoState(p);
|
||||
WSlope.DoState(p);
|
||||
for (int i=0;i<2;++i)
|
||||
for (int n=0; n<4; ++n)
|
||||
ColorSlopes[i][n].DoState(p);
|
||||
for (int i=0;i<8;++i)
|
||||
for (int n=0; n<3; ++n)
|
||||
TexSlopes[i][n].DoState(p);
|
||||
p.Do(vertex0X);
|
||||
p.Do(vertex0Y);
|
||||
p.Do(vertexOffsetX);
|
||||
p.Do(vertexOffsetY);
|
||||
p.Do(scissorLeft);
|
||||
p.Do(scissorTop);
|
||||
p.Do(scissorRight);
|
||||
p.Do(scissorBottom);
|
||||
tev.DoState(p);
|
||||
p.Do(rasterBlock);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
tev.Init();
|
||||
@ -126,7 +148,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi)
|
||||
if (z < 0 || z > 0x00ffffff)
|
||||
return;
|
||||
|
||||
if (bpmem.zcontrol.zcomploc)
|
||||
if (bpmem.zcontrol.early_ztest && bpmem.zmode.testenable && g_SWVideoConfig.bZComploc)
|
||||
{
|
||||
// TODO: Verify that perf regs are being incremented even if test is disabled
|
||||
if (++SWPixelEngine::pereg.perfZcompInputZcomplocLo == 0)
|
||||
@ -379,7 +401,7 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer
|
||||
float w[3] = { 1.0f / v0->projectedPosition.w, 1.0f / v1->projectedPosition.w, 1.0f / v2->projectedPosition.w };
|
||||
InitSlope(&WSlope, w[0], w[1], w[2], fltdx31, fltdx12, fltdy12, fltdy31);
|
||||
|
||||
if (!bpmem.genMode.zfreeze)
|
||||
if (!bpmem.genMode.zfreeze || !g_SWVideoConfig.bZFreeze)
|
||||
InitSlope(&ZSlope, v0->screenPosition[2], v1->screenPosition[2], v2->screenPosition[2], fltdx31, fltdx12, fltdy12, fltdy31);
|
||||
|
||||
for(unsigned int i = 0; i < bpmem.genMode.numcolchans; i++)
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define _RASTERIZER_H_
|
||||
|
||||
#include "NativeVertexFormat.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
namespace Rasterizer
|
||||
{
|
||||
@ -37,6 +38,12 @@ namespace Rasterizer
|
||||
float f0;
|
||||
|
||||
float GetValue(float dx, float dy) { return f0 + (dfdx * dx) + (dfdy * dy); }
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(dfdx);
|
||||
p.Do(dfdy);
|
||||
p.Do(f0);
|
||||
}
|
||||
};
|
||||
|
||||
struct RasterBlockPixel
|
||||
@ -53,6 +60,8 @@ namespace Rasterizer
|
||||
s32 TextureLod[16];
|
||||
bool TextureLinear[16];
|
||||
};
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,15 @@ CPReg cpreg; // shared between gfx and emulator thread
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(cpreg);
|
||||
p.DoArray(commandBuffer, commandBufferSize);
|
||||
p.Do(readPos);
|
||||
p.Do(writePos);
|
||||
p.Do(et_UpdateInterrupts);
|
||||
p.Do(interruptSet);
|
||||
p.Do(interruptWaiting);
|
||||
|
||||
// Is this right?
|
||||
p.DoArray(g_pVideoData,writePos);
|
||||
}
|
||||
|
||||
// does it matter that there is no synchronization between threads during writes?
|
||||
@ -115,15 +124,15 @@ void RunGpu()
|
||||
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
|
||||
{
|
||||
// We are going to do FP math on the main thread so have to save the current state
|
||||
SaveSSEState();
|
||||
LoadDefaultSSEState();
|
||||
FPURoundMode::SaveSIMDState();
|
||||
FPURoundMode::LoadDefaultSIMDState();
|
||||
|
||||
// run the opcode decoder
|
||||
do {
|
||||
RunBuffer();
|
||||
} while (cpreg.ctrl.GPReadEnable && !AtBreakpoint() && cpreg.readptr != cpreg.writeptr);
|
||||
|
||||
LoadSSEState();
|
||||
FPURoundMode::LoadSIMDState();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ void DoState(PointerWrap &p)
|
||||
p.Do(pereg);
|
||||
p.Do(g_bSignalTokenInterrupt);
|
||||
p.Do(g_bSignalFinishInterrupt);
|
||||
p.Do(et_SetTokenOnMainThread);
|
||||
p.Do(et_SetFinishOnMainThread);
|
||||
}
|
||||
|
||||
void UpdateInterrupts();
|
||||
|
@ -16,17 +16,23 @@
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Common.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "../../Plugin_VideoOGL/Src/GLUtil.h"
|
||||
#include "../../Plugin_VideoOGL/Src/RasterFont.h"
|
||||
#include "SWRenderer.h"
|
||||
#include "SWStatistics.h"
|
||||
#include "../../Plugin_VideoOGL/Src/RasterFont.h"
|
||||
|
||||
#define VSYNC_ENABLED 0
|
||||
|
||||
static GLuint s_RenderTarget = 0;
|
||||
|
||||
static GLint attr_pos = -1, attr_tex = -1;
|
||||
static GLint uni_tex = -1;
|
||||
static GLuint program;
|
||||
|
||||
// Rasterfont isn't compatible with GLES
|
||||
#ifndef USE_GLES
|
||||
RasterFont* s_pfont = NULL;
|
||||
#endif
|
||||
|
||||
void SWRenderer::Init()
|
||||
{
|
||||
@ -34,84 +40,76 @@ void SWRenderer::Init()
|
||||
|
||||
void SWRenderer::Shutdown()
|
||||
{
|
||||
glDeleteTextures(1, &s_RenderTarget);
|
||||
glDeleteProgram(program);
|
||||
glDeleteTextures(1, &s_RenderTarget);
|
||||
#ifndef USE_GLES
|
||||
delete s_pfont;
|
||||
s_pfont = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
delete s_pfont;
|
||||
s_pfont = 0;
|
||||
void CreateShaders()
|
||||
{
|
||||
static const char *fragShaderText =
|
||||
"varying " PREC " vec2 TexCoordOut;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"void main() {\n"
|
||||
" " PREC " vec4 tmpcolor;\n"
|
||||
" tmpcolor = texture2D(Texture, TexCoordOut);\n"
|
||||
" gl_FragColor = tmpcolor;\n"
|
||||
"}\n";
|
||||
static const char *vertShaderText =
|
||||
"attribute vec4 pos;\n"
|
||||
"attribute vec2 TexCoordIn;\n "
|
||||
"varying vec2 TexCoordOut;\n "
|
||||
"void main() {\n"
|
||||
" gl_Position = pos;\n"
|
||||
" TexCoordOut = TexCoordIn;\n"
|
||||
"}\n";
|
||||
|
||||
program = OpenGL_CompileProgram(vertShaderText, fragShaderText);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
uni_tex = glGetUniformLocation(program, "Texture");
|
||||
attr_pos = glGetAttribLocation(program, "pos");
|
||||
attr_tex = glGetAttribLocation(program, "TexCoordIn");
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SWRenderer::Prepare()
|
||||
{
|
||||
OpenGL_MakeCurrent();
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
|
||||
glGenTextures(1, &s_RenderTarget);
|
||||
|
||||
// Init extension support.
|
||||
if (glewInit() != GLEW_OK) {
|
||||
ERROR_LOG(VIDEO, "glewInit() failed!Does your video card support OpenGL 2.x?");
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle VSync on/off
|
||||
#ifdef _WIN32
|
||||
if (WGLEW_EXT_swap_control)
|
||||
wglSwapIntervalEXT(VSYNC_ENABLED);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "no support for SwapInterval (framerate clamped to monitor refresh rate)Does your video card support OpenGL 2.x?");
|
||||
#elif defined(HAVE_X11) && HAVE_X11
|
||||
if (glXSwapIntervalSGI)
|
||||
glXSwapIntervalSGI(VSYNC_ENABLED);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "no support for SwapInterval (framerate clamped to monitor refresh rate)");
|
||||
CreateShaders();
|
||||
// TODO: Enable for GLES once RasterFont supports GLES
|
||||
#ifndef USE_GLES
|
||||
s_pfont = new RasterFont();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
glStencilFunc(GL_ALWAYS, 0, 0);
|
||||
// used by hw rasterizer if it enables blending and depth test
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(1.0f);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
//glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
s_pfont = new RasterFont();
|
||||
|
||||
// legacy multitexturing: select texture channel only.
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glGenTextures(1, &s_RenderTarget);
|
||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||
GL_REPORT_ERRORD();
|
||||
}
|
||||
|
||||
void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
|
||||
{
|
||||
int nBackbufferWidth = (int)OpenGL_GetBackbufferWidth();
|
||||
int nBackbufferHeight = (int)OpenGL_GetBackbufferHeight();
|
||||
#ifndef USE_GLES
|
||||
int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
|
||||
int nBackbufferHeight = (int)GLInterface->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(pstr,
|
||||
left * 2.0f / (float)nBackbufferWidth - 1,
|
||||
1 - top * 2.0f / (float)nBackbufferHeight,
|
||||
0, nBackbufferWidth, nBackbufferHeight);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SWRenderer::DrawDebugText()
|
||||
{
|
||||
char debugtext_buffer[8192];
|
||||
char debugtext_buffer[8192];
|
||||
char *p = debugtext_buffer;
|
||||
p[0] = 0;
|
||||
|
||||
@ -139,48 +137,57 @@ void SWRenderer::DrawDebugText()
|
||||
|
||||
void SWRenderer::DrawTexture(u8 *texture, int width, int height)
|
||||
{
|
||||
GLsizei glWidth = (GLsizei)OpenGL_GetBackbufferWidth();
|
||||
GLsizei glHeight = (GLsizei)OpenGL_GetBackbufferHeight();
|
||||
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
|
||||
GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
|
||||
|
||||
// Update GLViewPort
|
||||
glViewport(0, 0, glWidth, glHeight);
|
||||
glScissor(0, 0, glWidth, glHeight);
|
||||
glScissor(0, 0, glWidth, glHeight);
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_RenderTarget);
|
||||
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, s_RenderTarget);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
glUseProgram(program);
|
||||
static const GLfloat verts[4][2] = {
|
||||
{ -1, -1}, // Left top
|
||||
{ -1, 1}, // left bottom
|
||||
{ 1, 1}, // right bottom
|
||||
{ 1, -1} // right top
|
||||
};
|
||||
static const GLfloat texverts[4][2] = {
|
||||
{0, 1},
|
||||
{0, 0},
|
||||
{1, 0},
|
||||
{1, 1}
|
||||
};
|
||||
|
||||
glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
|
||||
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts);
|
||||
glEnableVertexAttribArray(attr_pos);
|
||||
glEnableVertexAttribArray(attr_tex);
|
||||
glUniform1i(uni_tex, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableVertexAttribArray(attr_pos);
|
||||
glDisableVertexAttribArray(attr_tex);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
GLfloat u_max = (GLfloat)width;
|
||||
GLfloat v_max = (GLfloat)glHeight;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, v_max); glVertex2f(-1, -1);
|
||||
glTexCoord2f(0, 0); glVertex2f(-1, 1);
|
||||
glTexCoord2f(u_max, 0); glVertex2f( 1, 1);
|
||||
glTexCoord2f(u_max, v_max); glVertex2f( 1, -1);
|
||||
glEnd();
|
||||
|
||||
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
}
|
||||
|
||||
void SWRenderer::SwapBuffer()
|
||||
{
|
||||
DrawDebugText();
|
||||
DrawDebugText();
|
||||
|
||||
glFlush();
|
||||
glFlush();
|
||||
|
||||
OpenGL_SwapBuffers();
|
||||
GLInterface->Swap();
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
swstats.ResetFrame();
|
||||
swstats.ResetFrame();
|
||||
|
||||
// Clear framebuffer
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClearDepth(1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL_REPORT_ERRORD();
|
||||
|
@ -72,27 +72,27 @@ void SWVertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType)
|
||||
tcScale[7] = 1.0f / float(1 << m_CurrentVat->g2.Tex7Frac);
|
||||
|
||||
//TexMtx
|
||||
const int tmDesc[8] = {
|
||||
const u32 tmDesc[8] = {
|
||||
g_VtxDesc.Tex0MatIdx, g_VtxDesc.Tex1MatIdx, g_VtxDesc.Tex2MatIdx, g_VtxDesc.Tex3MatIdx,
|
||||
g_VtxDesc.Tex4MatIdx, g_VtxDesc.Tex5MatIdx, g_VtxDesc.Tex6MatIdx, g_VtxDesc.Tex7MatIdx
|
||||
};
|
||||
// Colors
|
||||
const int colDesc[2] = {g_VtxDesc.Color0, g_VtxDesc.Color1};
|
||||
const u32 colDesc[2] = {g_VtxDesc.Color0, g_VtxDesc.Color1};
|
||||
colElements[0] = m_CurrentVat->g0.Color0Elements;
|
||||
colElements[1] = m_CurrentVat->g0.Color1Elements;
|
||||
const int colComp[2] = {m_CurrentVat->g0.Color0Comp, m_CurrentVat->g0.Color1Comp};
|
||||
const u32 colComp[2] = {m_CurrentVat->g0.Color0Comp, m_CurrentVat->g0.Color1Comp};
|
||||
// TextureCoord
|
||||
const int tcDesc[8] = {
|
||||
const u32 tcDesc[8] = {
|
||||
g_VtxDesc.Tex0Coord, g_VtxDesc.Tex1Coord, g_VtxDesc.Tex2Coord, g_VtxDesc.Tex3Coord,
|
||||
g_VtxDesc.Tex4Coord, g_VtxDesc.Tex5Coord, g_VtxDesc.Tex6Coord, (const int)((g_VtxDesc.Hex >> 31) & 3)
|
||||
g_VtxDesc.Tex4Coord, g_VtxDesc.Tex5Coord, g_VtxDesc.Tex6Coord, (const u32)((g_VtxDesc.Hex >> 31) & 3)
|
||||
};
|
||||
const int tcElements[8] = {
|
||||
const u32 tcElements[8] = {
|
||||
m_CurrentVat->g0.Tex0CoordElements, m_CurrentVat->g1.Tex1CoordElements, m_CurrentVat->g1.Tex2CoordElements,
|
||||
m_CurrentVat->g1.Tex3CoordElements, m_CurrentVat->g1.Tex4CoordElements, m_CurrentVat->g2.Tex5CoordElements,
|
||||
m_CurrentVat->g2.Tex6CoordElements, m_CurrentVat->g2.Tex7CoordElements
|
||||
};
|
||||
|
||||
const int tcFormat[8] = {
|
||||
const u32 tcFormat[8] = {
|
||||
m_CurrentVat->g0.Tex0CoordFormat, m_CurrentVat->g1.Tex1CoordFormat, m_CurrentVat->g1.Tex2CoordFormat,
|
||||
m_CurrentVat->g1.Tex3CoordFormat, m_CurrentVat->g1.Tex4CoordFormat, m_CurrentVat->g2.Tex5CoordFormat,
|
||||
m_CurrentVat->g2.Tex6CoordFormat, m_CurrentVat->g2.Tex7CoordFormat
|
||||
@ -328,4 +328,15 @@ void SWVertexLoader::LoadTexCoord(SWVertexLoader *vertexLoader, InputVertexData
|
||||
vertexLoader->m_texCoordLoader[index]();
|
||||
}
|
||||
|
||||
|
||||
void SWVertexLoader::DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(m_AttributeLoaders, sizeof m_AttributeLoaders);
|
||||
p.Do(m_VertexSize);
|
||||
p.Do(*m_CurrentVat);
|
||||
p.Do(m_positionLoader);
|
||||
p.Do(m_normalLoader);
|
||||
p.DoArray(m_colorLoader, sizeof m_colorLoader);
|
||||
p.Do(m_NumAttributeLoaders);
|
||||
m_SetupUnit->DoState(p);
|
||||
p.Do(m_TexGenSpecialCase);
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "NativeVertexFormat.h"
|
||||
#include "CPMemLoader.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
class SetupUnit;
|
||||
|
||||
@ -69,7 +70,7 @@ public:
|
||||
u32 GetVertexSize() { return m_VertexSize; }
|
||||
|
||||
void LoadVertex();
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -35,6 +35,9 @@ SWVideoConfig::SWVideoConfig()
|
||||
bDumpObjects = false;
|
||||
bDumpFrames = false;
|
||||
|
||||
bZComploc = true;
|
||||
bZFreeze = true;
|
||||
|
||||
bDumpTevStages = false;
|
||||
bDumpTevTextureFetches = false;
|
||||
|
||||
@ -52,6 +55,8 @@ void SWVideoConfig::Load(const char* ini_file)
|
||||
iniFile.Get("Hardware", "RenderToMainframe", &renderToMainframe, false);
|
||||
|
||||
iniFile.Get("Rendering", "HwRasterizer", &bHwRasterizer, false);
|
||||
iniFile.Get("Rendering", "ZComploc", &bZComploc, true);
|
||||
iniFile.Get("Rendering", "ZFreeze", &bZFreeze, true);
|
||||
|
||||
iniFile.Get("Info", "ShowStats", &bShowStats, false);
|
||||
|
||||
@ -74,6 +79,8 @@ void SWVideoConfig::Save(const char* ini_file)
|
||||
iniFile.Set("Hardware", "RenderToMainframe", renderToMainframe);
|
||||
|
||||
iniFile.Set("Rendering", "HwRasterizer", bHwRasterizer);
|
||||
iniFile.Set("Rendering", "ZComploc", &bZComploc);
|
||||
iniFile.Set("Rendering", "ZFreeze", &bZFreeze);
|
||||
|
||||
iniFile.Set("Info", "ShowStats", bShowStats);
|
||||
|
||||
|
@ -36,6 +36,10 @@ struct SWVideoConfig : NonCopyable
|
||||
|
||||
bool bHwRasterizer;
|
||||
|
||||
// Emulation features
|
||||
bool bZComploc;
|
||||
bool bZFreeze;
|
||||
|
||||
bool bShowStats;
|
||||
|
||||
bool bDumpTextures;
|
||||
|
@ -39,6 +39,11 @@
|
||||
#include "FileUtil.h"
|
||||
#include "VideoBackend.h"
|
||||
#include "Core.h"
|
||||
#include "OpcodeDecoder.h"
|
||||
#include "SWVertexLoader.h"
|
||||
#include "SWStatistics.h"
|
||||
|
||||
#define VSYNC_ENABLED 0
|
||||
|
||||
namespace SW
|
||||
{
|
||||
@ -68,31 +73,61 @@ void VideoSoftware::ShowConfig(void *_hParent)
|
||||
|
||||
bool VideoSoftware::Initialize(void *&window_handle)
|
||||
{
|
||||
g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str());
|
||||
g_SWVideoConfig.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_software.ini").c_str());
|
||||
InitInterface();
|
||||
|
||||
if (!OpenGL_Create(window_handle))
|
||||
if (!GLInterface->Create(window_handle))
|
||||
{
|
||||
INFO_LOG(VIDEO, "%s", "SWRenderer::Create failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
InitBPMemory();
|
||||
InitXFMemory();
|
||||
SWCommandProcessor::Init();
|
||||
SWPixelEngine::Init();
|
||||
OpcodeDecoder::Init();
|
||||
Clipper::Init();
|
||||
Rasterizer::Init();
|
||||
HwRasterizer::Init();
|
||||
SWRenderer::Init();
|
||||
DebugUtil::Init();
|
||||
InitBPMemory();
|
||||
InitXFMemory();
|
||||
SWCommandProcessor::Init();
|
||||
SWPixelEngine::Init();
|
||||
OpcodeDecoder::Init();
|
||||
Clipper::Init();
|
||||
Rasterizer::Init();
|
||||
HwRasterizer::Init();
|
||||
SWRenderer::Init();
|
||||
DebugUtil::Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VideoSoftware::DoState(PointerWrap&)
|
||||
void VideoSoftware::DoState(PointerWrap& p)
|
||||
{
|
||||
// NYI
|
||||
bool software = true;
|
||||
p.Do(software);
|
||||
if (p.GetMode() == PointerWrap::MODE_READ && software == false)
|
||||
// change mode to abort load of incompatible save state.
|
||||
p.SetMode(PointerWrap::MODE_VERIFY);
|
||||
|
||||
// TODO: incomplete?
|
||||
SWCommandProcessor::DoState(p);
|
||||
SWPixelEngine::DoState(p);
|
||||
EfbInterface::DoState(p);
|
||||
OpcodeDecoder::DoState(p);
|
||||
Clipper::DoState(p);
|
||||
p.Do(swxfregs);
|
||||
p.Do(bpmem);
|
||||
p.Do(swstats);
|
||||
|
||||
// CP Memory
|
||||
p.DoArray(arraybases, 16);
|
||||
p.DoArray(arraystrides, 16);
|
||||
p.Do(MatrixIndexA);
|
||||
p.Do(MatrixIndexB);
|
||||
p.Do(g_VtxDesc.Hex);
|
||||
p.DoArray(g_VtxAttr, 8);
|
||||
p.DoMarker("CP Memory");
|
||||
|
||||
}
|
||||
|
||||
void VideoSoftware::CheckInvalidState()
|
||||
{
|
||||
// there is no state to invalidate
|
||||
}
|
||||
|
||||
void VideoSoftware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
|
||||
@ -124,16 +159,30 @@ void VideoSoftware::EmuStateChange(EMUSTATE_CHANGE newState)
|
||||
|
||||
void VideoSoftware::Shutdown()
|
||||
{
|
||||
HwRasterizer::Shutdown();
|
||||
SWRenderer::Shutdown();
|
||||
OpenGL_Shutdown();
|
||||
GLInterface->Shutdown();
|
||||
}
|
||||
|
||||
// This is called after Video_Initialize() from the Core
|
||||
void VideoSoftware::Video_Prepare()
|
||||
{
|
||||
SWRenderer::Prepare();
|
||||
{
|
||||
GLInterface->MakeCurrent();
|
||||
// Init extension support.
|
||||
// Required for WGL SwapInterval
|
||||
#ifndef USE_GLES
|
||||
if (glewInit() != GLEW_OK) {
|
||||
ERROR_LOG(VIDEO, "glewInit() failed!Does your video card support OpenGL 2.x?");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Handle VSync on/off
|
||||
GLInterface->SwapInterval(VSYNC_ENABLED);
|
||||
|
||||
INFO_LOG(VIDEO, "Video backend initialized.");
|
||||
HwRasterizer::Prepare();
|
||||
SWRenderer::Prepare();
|
||||
|
||||
INFO_LOG(VIDEO, "Video backend initialized.");
|
||||
}
|
||||
|
||||
// Run from the CPU thread (from VideoInterface.cpp)
|
||||
@ -279,20 +328,7 @@ writeFn32 VideoSoftware::Video_PEWrite32()
|
||||
// Draw messages on top of the screen
|
||||
unsigned int VideoSoftware::PeekMessages()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// TODO: peekmessage
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
||||
{
|
||||
if (msg.message == WM_QUIT)
|
||||
return FALSE;
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return TRUE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return GLInterface->PeekMessages();
|
||||
}
|
||||
|
||||
// Show the current FPS
|
||||
@ -300,7 +336,7 @@ void VideoSoftware::UpdateFPSDisplay(const char *text)
|
||||
{
|
||||
char temp[100];
|
||||
snprintf(temp, sizeof temp, "%s | Software | %s", scm_rev_str, text);
|
||||
OpenGL_SetWindowText(temp);
|
||||
GLInterface->UpdateFPSDisplay(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,13 +25,13 @@
|
||||
|
||||
void SetupUnit::Init(u8 primitiveType)
|
||||
{
|
||||
m_PrimType = primitiveType;
|
||||
m_PrimType = primitiveType;
|
||||
|
||||
m_VertexCounter = 0;
|
||||
m_VertPointer[0] = &m_Vertices[0];
|
||||
m_VertPointer[1] = &m_Vertices[1];
|
||||
m_VertPointer[2] = &m_Vertices[2];
|
||||
m_VertWritePointer = m_VertPointer[0];
|
||||
m_VertexCounter = 0;
|
||||
m_VertPointer[0] = &m_Vertices[0];
|
||||
m_VertPointer[1] = &m_Vertices[1];
|
||||
m_VertPointer[2] = &m_Vertices[2];
|
||||
m_VertWritePointer = m_VertPointer[0];
|
||||
}
|
||||
|
||||
void SetupUnit::SetupVertex()
|
||||
@ -169,3 +169,21 @@ void SetupUnit::SetupLineStrip()
|
||||
|
||||
void SetupUnit::SetupPoint()
|
||||
{}
|
||||
|
||||
void SetupUnit::DoState(PointerWrap &p)
|
||||
{
|
||||
// TODO: some or all of this is making the save states stop working once dolphin is closed...sometimes (usually)
|
||||
// I have no idea what specifically is wrong, or if this is even important. Disabling it doesn't seem to make any noticible difference...
|
||||
/* p.Do(m_PrimType);
|
||||
p.Do(m_VertexCounter);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
m_Vertices[i].DoState(p);
|
||||
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
{
|
||||
m_VertPointer[0] = &m_Vertices[0];
|
||||
m_VertPointer[1] = &m_Vertices[1];
|
||||
m_VertPointer[2] = &m_Vertices[2];
|
||||
m_VertWritePointer = m_VertPointer[0];
|
||||
}*/
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "NativeVertexFormat.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
class SetupUnit
|
||||
{
|
||||
@ -45,6 +46,7 @@ public:
|
||||
OutputVertexData* GetVertex() { return m_VertWritePointer; }
|
||||
|
||||
void SetupVertex();
|
||||
void DoState(PointerWrap &p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -432,12 +432,12 @@ static bool AlphaCompare(int alpha, int ref, int comp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool AlphaTest(int alpha)
|
||||
static bool TevAlphaTest(int alpha)
|
||||
{
|
||||
bool comp0 = AlphaCompare(alpha, bpmem.alphaFunc.ref0, bpmem.alphaFunc.comp0);
|
||||
bool comp1 = AlphaCompare(alpha, bpmem.alphaFunc.ref1, bpmem.alphaFunc.comp1);
|
||||
bool comp0 = AlphaCompare(alpha, bpmem.alpha_test.ref0, bpmem.alpha_test.comp0);
|
||||
bool comp1 = AlphaCompare(alpha, bpmem.alpha_test.ref1, bpmem.alpha_test.comp1);
|
||||
|
||||
switch (bpmem.alphaFunc.logic) {
|
||||
switch (bpmem.alpha_test.logic) {
|
||||
case 0: return comp0 && comp1; // and
|
||||
case 1: return comp0 || comp1; // or
|
||||
case 2: return comp0 ^ comp1; // xor
|
||||
@ -701,7 +701,7 @@ void Tev::Draw()
|
||||
// convert to 8 bits per component
|
||||
u8 output[4] = {(u8)Reg[0][ALP_C], (u8)Reg[0][BLU_C], (u8)Reg[0][GRN_C], (u8)Reg[0][RED_C]};
|
||||
|
||||
if (!AlphaTest(output[ALP_C]))
|
||||
if (!TevAlphaTest(output[ALP_C]))
|
||||
return;
|
||||
|
||||
// z texture
|
||||
@ -785,15 +785,16 @@ void Tev::Draw()
|
||||
output[BLU_C] = (output[BLU_C] * invFog + fogInt * bpmem.fog.color.b) >> 8;
|
||||
}
|
||||
|
||||
if (!bpmem.zcontrol.zcomploc)
|
||||
bool late_ztest = !bpmem.zcontrol.early_ztest || !g_SWVideoConfig.bZComploc;
|
||||
if (late_ztest && bpmem.zmode.testenable)
|
||||
{
|
||||
// TODO: Check against hw if these values get incremented even if depth testing is disabled
|
||||
if (++SWPixelEngine::pereg.perfZcompInputLo == 0)
|
||||
SWPixelEngine::pereg.perfZcompInputHi++;
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
if (!EfbInterface::ZCompare(Position[0], Position[1], Position[2]))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EfbInterface::ZCompare(Position[0], Position[1], Position[2]))
|
||||
return;
|
||||
|
||||
if (++SWPixelEngine::pereg.perfZcompOutputLo == 0)
|
||||
SWPixelEngine::pereg.perfZcompOutputHi++;
|
||||
}
|
||||
@ -837,3 +838,31 @@ void Tev::SetRegColor(int reg, int comp, bool konst, s16 color)
|
||||
Reg[reg][comp] = color;
|
||||
}
|
||||
}
|
||||
|
||||
void Tev::DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(Reg, sizeof(Reg));
|
||||
|
||||
p.DoArray(KonstantColors, sizeof(KonstantColors));
|
||||
p.DoArray(TexColor,4);
|
||||
p.DoArray(RasColor,4);
|
||||
p.DoArray(StageKonst,4);
|
||||
p.DoArray(Zero16,4);
|
||||
|
||||
p.DoArray(FixedConstants,9);
|
||||
p.Do(AlphaBump);
|
||||
p.DoArray(IndirectTex, sizeof(IndirectTex));
|
||||
p.Do(TexCoord);
|
||||
|
||||
p.DoArray(m_BiasLUT,4);
|
||||
p.DoArray(m_ScaleLShiftLUT,4);
|
||||
p.DoArray(m_ScaleRShiftLUT,4);
|
||||
|
||||
p.DoArray(Position,3);
|
||||
p.DoArray(Color, sizeof(Color));
|
||||
p.DoArray(Uv, 8);
|
||||
p.DoArray(IndirectLod,4);
|
||||
p.DoArray(IndirectLinear,4);
|
||||
p.DoArray(TextureLod,16);
|
||||
p.DoArray(TextureLinear,16);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define _TEV_H_
|
||||
|
||||
#include "BPMemLoader.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
class Tev
|
||||
{
|
||||
@ -96,6 +97,8 @@ public:
|
||||
void SetRegColor(int reg, int comp, bool konst, s16 color);
|
||||
|
||||
enum { ALP_C, BLU_C, GRN_C, RED_C };
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -120,8 +120,18 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample)
|
||||
TexImage0& ti0 = texUnit.texImage0[subTexmap];
|
||||
TexTLUT& texTlut = texUnit.texTlut[subTexmap];
|
||||
|
||||
u32 imageBase = texUnit.texImage3[subTexmap].image_base << 5;
|
||||
u8 *imageSrc = Memory::GetPointer(imageBase);
|
||||
u8 *imageSrc, *imageSrcOdd = NULL;
|
||||
if (texUnit.texImage1[subTexmap].image_type)
|
||||
{
|
||||
imageSrc = &texMem[texUnit.texImage1[subTexmap].tmem_even * TMEM_LINE_SIZE];
|
||||
if (ti0.format == GX_TF_RGBA8)
|
||||
imageSrcOdd = &texMem[texUnit.texImage2[subTexmap].tmem_odd * TMEM_LINE_SIZE];
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 imageBase = texUnit.texImage3[subTexmap].image_base << 5;
|
||||
imageSrc = Memory::GetPointer(imageBase);
|
||||
}
|
||||
|
||||
int imageWidth = ti0.width;
|
||||
int imageHeight = ti0.height;
|
||||
@ -182,17 +192,34 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample)
|
||||
WrapCoord(imageSPlus1, tm0.wrap_s, imageWidth);
|
||||
WrapCoord(imageTPlus1, tm0.wrap_t, imageHeight);
|
||||
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageS, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
SetTexel(sampledTex, texel, (128 - fractS) * (128 - fractT));
|
||||
if (!(ti0.format == GX_TF_RGBA8 && texUnit.texImage1[subTexmap].image_type))
|
||||
{
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageS, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
SetTexel(sampledTex, texel, (128 - fractS) * (128 - fractT));
|
||||
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageSPlus1, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (fractS) * (128 - fractT));
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageSPlus1, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (fractS) * (128 - fractT));
|
||||
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageS, imageTPlus1, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (128 - fractS) * (fractT));
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageS, imageTPlus1, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (128 - fractS) * (fractT));
|
||||
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageSPlus1, imageTPlus1, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (fractS) * (fractT));
|
||||
TexDecoder_DecodeTexel(sampledTex, imageSrc, imageSPlus1, imageTPlus1, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
AddTexel(sampledTex, texel, (fractS) * (fractT));
|
||||
}
|
||||
else
|
||||
{
|
||||
TexDecoder_DecodeTexelRGBA8FromTmem(sampledTex, imageSrc, imageSrcOdd, imageS, imageT, imageWidth);
|
||||
SetTexel(sampledTex, texel, (128 - fractS) * (128 - fractT));
|
||||
|
||||
TexDecoder_DecodeTexelRGBA8FromTmem(sampledTex, imageSrc, imageSrcOdd, imageSPlus1, imageT, imageWidth);
|
||||
AddTexel(sampledTex, texel, (fractS) * (128 - fractT));
|
||||
|
||||
TexDecoder_DecodeTexelRGBA8FromTmem(sampledTex, imageSrc, imageSrcOdd, imageS, imageTPlus1, imageWidth);
|
||||
AddTexel(sampledTex, texel, (128 - fractS) * (fractT));
|
||||
|
||||
TexDecoder_DecodeTexelRGBA8FromTmem(sampledTex, imageSrc, imageSrcOdd, imageSPlus1, imageTPlus1, imageWidth);
|
||||
AddTexel(sampledTex, texel, (fractS) * (fractT));
|
||||
}
|
||||
|
||||
sample[0] = (u8)(texel[0] >> 14);
|
||||
sample[1] = (u8)(texel[1] >> 14);
|
||||
@ -209,7 +236,10 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample)
|
||||
WrapCoord(imageS, tm0.wrap_s, imageWidth);
|
||||
WrapCoord(imageT, tm0.wrap_t, imageHeight);
|
||||
|
||||
TexDecoder_DecodeTexel(sample, imageSrc, imageS, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
if (!(ti0.format == GX_TF_RGBA8 && texUnit.texImage1[subTexmap].image_type))
|
||||
TexDecoder_DecodeTexel(sample, imageSrc, imageS, imageT, imageWidth, ti0.format, tlutAddress, texTlut.tlut_format);
|
||||
else
|
||||
TexDecoder_DecodeTexelRGBA8FromTmem(sample, imageSrc, imageSrcOdd, imageS, imageT, imageWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "ChunkFile.h"
|
||||
|
||||
class Vec3
|
||||
{
|
||||
@ -111,6 +112,12 @@ public:
|
||||
{
|
||||
memset((void *)this,0,sizeof(float)*3);
|
||||
}
|
||||
void DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(x);
|
||||
p.Do(y);
|
||||
p.Do(z);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -52,6 +52,9 @@ class VideoSoftware : public VideoBackend
|
||||
|
||||
void PauseAndLock(bool doLock, bool unpauseOnUnlock=true);
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
public:
|
||||
void CheckInvalidState();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "FileUtil.h"
|
||||
#include "Core.h"
|
||||
|
||||
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
|
||||
|
||||
template <typename T>
|
||||
IntegerSetting<T>::IntegerSetting(wxWindow* parent, const wxString& label, T& setting, int minVal, int maxVal, long style) :
|
||||
wxSpinCtrl(parent, -1, label, wxDefaultPosition, wxDefaultSize, style),
|
||||
@ -30,7 +28,7 @@ IntegerSetting<T>::IntegerSetting(wxWindow* parent, const wxString& label, T& se
|
||||
{
|
||||
SetRange(minVal, maxVal);
|
||||
SetValue(m_setting);
|
||||
_connect_macro_(this, IntegerSetting::UpdateValue, wxEVT_COMMAND_SPINCTRL_UPDATED, this);
|
||||
Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &IntegerSetting::UpdateValue, this);
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +68,7 @@ VideoConfigDialog::VideoConfigDialog(wxWindow* parent, const std::string& title,
|
||||
|
||||
// TODO: How to get the translated plugin name?
|
||||
choice_backend->SetStringSelection(wxString::FromAscii(g_video_backend->GetName().c_str()));
|
||||
_connect_macro_(choice_backend, VideoConfigDialog::Event_Backend, wxEVT_COMMAND_CHOICE_SELECTED, this);
|
||||
choice_backend->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &VideoConfigDialog::Event_Backend, this);
|
||||
|
||||
szr_rendering->Add(label_backend, 1, wxALIGN_CENTER_VERTICAL, 5);
|
||||
szr_rendering->Add(choice_backend, 1, 0, 0);
|
||||
|
Reference in New Issue
Block a user