2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
#include <list>
|
2008-12-08 05:25:12 +00:00
|
|
|
#include <d3dx9.h>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Statistics.h"
|
|
|
|
|
2009-09-13 09:23:30 +00:00
|
|
|
#include "VideoConfig.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "Render.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "XFStructs.h"
|
|
|
|
#include "D3DUtil.h"
|
2008-12-25 15:56:36 +00:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "PixelShaderManager.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "VertexShaderCache.h"
|
2008-12-26 19:39:12 +00:00
|
|
|
#include "PixelShaderCache.h"
|
2009-09-13 17:46:33 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "TextureCache.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include "EmuWindow.h"
|
2009-03-28 21:07:16 +00:00
|
|
|
#include "AVIDump.h"
|
2009-09-03 20:37:35 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2009-09-13 17:46:33 +00:00
|
|
|
#include "FramebufferManager.h"
|
2009-09-04 06:09:21 +00:00
|
|
|
#include "Fifo.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-02 06:33:41 +00:00
|
|
|
#include "debugger/debugger.h"
|
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
static int s_target_width;
|
|
|
|
static int s_target_height;
|
2009-09-13 08:21:35 +00:00
|
|
|
|
|
|
|
static int s_backbuffer_width;
|
|
|
|
static int s_backbuffer_height;
|
|
|
|
|
2009-09-03 20:37:35 +00:00
|
|
|
static float xScale;
|
|
|
|
static float yScale;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
static int s_recordWidth;
|
|
|
|
static int s_recordHeight;
|
2009-03-28 21:07:16 +00:00
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
static bool s_LastFrameDumped;
|
|
|
|
static bool s_AVIDumping;
|
2009-03-28 21:07:16 +00:00
|
|
|
|
2009-10-10 23:36:18 +00:00
|
|
|
static u32 s_blendMode;
|
|
|
|
|
2009-09-13 21:18:04 +00:00
|
|
|
char st[32768];
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
|
2009-10-10 23:36:18 +00:00
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
void SetupDeviceObjects()
|
|
|
|
{
|
|
|
|
D3D::font.Init();
|
|
|
|
VertexLoaderManager::Init();
|
|
|
|
FBManager::Create();
|
2009-09-15 21:05:31 +00:00
|
|
|
|
2009-09-15 21:49:15 +00:00
|
|
|
VertexShaderManager::Dirty();
|
|
|
|
PixelShaderManager::Dirty();
|
2009-09-15 21:05:31 +00:00
|
|
|
|
2009-09-15 19:53:22 +00:00
|
|
|
// Tex and shader caches will recreate themselves over time.
|
2009-11-08 20:35:11 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kill off all POOL_DEFAULT device objects.
|
|
|
|
void TeardownDeviceObjects()
|
|
|
|
{
|
2009-09-15 19:53:22 +00:00
|
|
|
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
|
|
|
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
|
2009-09-13 17:46:33 +00:00
|
|
|
FBManager::Destroy();
|
|
|
|
D3D::font.Shutdown();
|
|
|
|
TextureCache::Invalidate(false);
|
|
|
|
VertexManager::DestroyDeviceObjects();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
VertexShaderCache::Clear();
|
|
|
|
PixelShaderCache::Clear();
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:37:35 +00:00
|
|
|
bool Renderer::Init()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-13 08:21:35 +00:00
|
|
|
UpdateActiveConfig();
|
2009-09-15 18:00:16 +00:00
|
|
|
int fullScreenRes, w_temp, h_temp;
|
2009-10-10 23:36:18 +00:00
|
|
|
s_blendMode = 0;
|
2009-09-13 17:46:33 +00:00
|
|
|
int backbuffer_ms_mode = 0; // g_ActiveConfig.iMultisampleMode;
|
2009-09-15 08:13:45 +00:00
|
|
|
|
|
|
|
sscanf(g_Config.cFSResolution, "%dx%d", &w_temp, &h_temp);
|
|
|
|
|
2009-11-08 02:28:06 +00:00
|
|
|
for (fullScreenRes = 0; fullScreenRes < (int)D3D::GetAdapter(g_ActiveConfig.iAdapter).resolutions.size(); fullScreenRes++)
|
2009-09-15 08:13:45 +00:00
|
|
|
{
|
2009-09-17 05:07:16 +00:00
|
|
|
if ((D3D::GetAdapter(g_ActiveConfig.iAdapter).resolutions[fullScreenRes].xres == w_temp) &&
|
|
|
|
(D3D::GetAdapter(g_ActiveConfig.iAdapter).resolutions[fullScreenRes].yres == h_temp))
|
2009-09-15 08:13:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-17 05:57:38 +00:00
|
|
|
if (fullScreenRes == D3D::GetAdapter(g_ActiveConfig.iAdapter).resolutions.size())
|
|
|
|
fullScreenRes = 0;
|
|
|
|
|
2009-09-15 08:13:45 +00:00
|
|
|
D3D::Create(g_ActiveConfig.iAdapter, EmuWindow::GetWnd(), g_ActiveConfig.bFullscreen,
|
2009-09-15 19:53:22 +00:00
|
|
|
fullScreenRes, backbuffer_ms_mode, false);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
s_backbuffer_width = D3D::GetBackBufferWidth();
|
|
|
|
s_backbuffer_height = D3D::GetBackBufferHeight();
|
2009-03-01 01:09:32 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
// TODO: Grab target width from configured resolution?
|
|
|
|
s_target_width = s_backbuffer_width * EFB_WIDTH / 640;
|
|
|
|
s_target_height = s_backbuffer_height * EFB_HEIGHT / 480;
|
2009-03-01 12:07:34 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
xScale = (float)s_target_width / (float)EFB_WIDTH;
|
|
|
|
yScale = (float)s_target_height / (float)EFB_HEIGHT;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
s_LastFrameDumped = false;
|
|
|
|
s_AVIDumping = false;
|
2009-03-28 21:07:16 +00:00
|
|
|
|
2009-09-03 19:24:16 +00:00
|
|
|
// We're not using fixed function, except for some 2D.
|
|
|
|
// Let's just set the matrices to identity to be sure.
|
2009-02-28 22:10:38 +00:00
|
|
|
D3DXMATRIX mtx;
|
|
|
|
D3DXMatrixIdentity(&mtx);
|
|
|
|
D3D::dev->SetTransform(D3DTS_VIEW, &mtx);
|
|
|
|
D3D::dev->SetTransform(D3DTS_WORLD, &mtx);
|
2009-09-13 17:46:33 +00:00
|
|
|
|
|
|
|
SetupDeviceObjects();
|
2009-09-03 20:37:35 +00:00
|
|
|
|
2009-09-15 21:05:31 +00:00
|
|
|
for (int stage = 0; stage < 8; stage++)
|
|
|
|
D3D::SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);
|
2009-11-08 20:35:11 +00:00
|
|
|
D3DVIEWPORT9 vp;
|
|
|
|
vp.X = 0;
|
|
|
|
vp.Y = 0;
|
|
|
|
vp.Width = s_backbuffer_width;
|
|
|
|
vp.Height = s_backbuffer_height;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 0.0f;
|
|
|
|
D3D::dev->SetViewport(&vp);
|
2009-09-13 17:46:33 +00:00
|
|
|
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);
|
2009-11-08 20:35:11 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
2009-11-08 20:35:11 +00:00
|
|
|
D3D::dev->SetRenderTarget(1, FBManager::GetEFBDepthEncodedSurface());
|
2009-09-13 17:46:33 +00:00
|
|
|
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
2009-11-08 20:35:11 +00:00
|
|
|
vp.Width = s_target_width;
|
|
|
|
vp.Height = s_target_height;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 0.0f;
|
|
|
|
D3D::dev->SetViewport(&vp);
|
2009-10-02 21:23:56 +00:00
|
|
|
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
2009-09-13 17:46:33 +00:00
|
|
|
D3D::BeginFrame();
|
2009-10-30 04:14:43 +00:00
|
|
|
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, true);
|
2009-09-03 20:37:35 +00:00
|
|
|
return true;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
void Renderer::Shutdown()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-13 17:46:33 +00:00
|
|
|
TeardownDeviceObjects();
|
2008-12-08 05:25:12 +00:00
|
|
|
D3D::EndFrame();
|
2009-09-20 03:29:43 +00:00
|
|
|
D3D::Present();
|
2008-12-08 05:25:12 +00:00
|
|
|
D3D::Close();
|
2009-03-28 21:07:16 +00:00
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
if (s_AVIDumping)
|
2009-09-03 20:37:35 +00:00
|
|
|
{
|
2009-03-28 21:07:16 +00:00
|
|
|
AVIDump::Stop();
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
int Renderer::GetTargetWidth() { return s_target_width; }
|
|
|
|
int Renderer::GetTargetHeight() { return s_target_height; }
|
|
|
|
float Renderer::GetTargetScaleX() { return xScale; }
|
|
|
|
float Renderer::GetTargetScaleY() { return yScale; }
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-03 19:42:45 +00:00
|
|
|
void Renderer::RenderText(const char *text, int left, int top, u32 color)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-03 19:42:45 +00:00
|
|
|
D3D::font.DrawTextScaled((float)left, (float)top, 20, 20, 0.0f, color, text, false);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dumpMatrix(D3DXMATRIX &mtx)
|
|
|
|
{
|
2009-03-01 12:07:34 +00:00
|
|
|
for (int y = 0; y < 4; y++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
char temp[256];
|
|
|
|
sprintf(temp,"%4.4f %4.4f %4.4f %4.4f",mtx.m[y][0],mtx.m[y][1],mtx.m[y][2],mtx.m[y][3]);
|
|
|
|
g_VideoInitialize.pLog(temp, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 21:56:08 +00:00
|
|
|
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
|
|
|
{
|
|
|
|
TargetRectangle result;
|
2009-11-08 20:35:11 +00:00
|
|
|
result.left = (rc.left * s_target_width) / EFB_WIDTH ;
|
2009-09-13 17:46:33 +00:00
|
|
|
result.top = (rc.top * s_target_height) / EFB_HEIGHT;
|
2009-11-08 20:35:11 +00:00
|
|
|
result.right = (rc.right * s_target_width) / EFB_WIDTH ;
|
2009-09-13 17:46:33 +00:00
|
|
|
result.bottom = (rc.bottom * s_target_height) / EFB_HEIGHT;
|
2009-09-03 21:56:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:24:16 +00:00
|
|
|
void formatBufferDump(const char *in, char *out, int w, int h, int p)
|
2009-03-28 21:07:16 +00:00
|
|
|
{
|
2009-09-03 21:56:08 +00:00
|
|
|
for (int y = 0; y < h; y++)
|
|
|
|
{
|
2009-09-03 19:24:16 +00:00
|
|
|
const char *line = in + (h - y - 1) * p;
|
2009-09-03 21:56:08 +00:00
|
|
|
for (int x = 0; x < w; x++)
|
|
|
|
{
|
2009-03-28 21:07:16 +00:00
|
|
|
memcpy(out, line, 3);
|
|
|
|
out += 3;
|
|
|
|
line += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-15 19:53:22 +00:00
|
|
|
// With D3D, we have to resize the backbuffer if the window changed
|
|
|
|
// size.
|
|
|
|
void CheckForResize()
|
|
|
|
{
|
|
|
|
while (EmuWindow::IsSizing())
|
|
|
|
{
|
|
|
|
Sleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
RECT rcWindow;
|
|
|
|
GetClientRect(EmuWindow::GetWnd(), &rcWindow);
|
|
|
|
int client_width = rcWindow.right - rcWindow.left;
|
|
|
|
int client_height = rcWindow.bottom - rcWindow.top;
|
|
|
|
// Sanity check.
|
|
|
|
if ((client_width != s_backbuffer_width ||
|
|
|
|
client_height != s_backbuffer_height) &&
|
|
|
|
client_width >= 4 && client_height >= 4)
|
|
|
|
{
|
|
|
|
TeardownDeviceObjects();
|
|
|
|
|
|
|
|
D3D::Reset();
|
|
|
|
|
|
|
|
SetupDeviceObjects();
|
|
|
|
s_backbuffer_width = D3D::GetBackBufferWidth();
|
|
|
|
s_backbuffer_height = D3D::GetBackBufferHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
static void EFBTextureToD3DBackBuffer(const EFBRectangle& sourceRc)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-20 05:04:45 +00:00
|
|
|
// Set the backbuffer as the rendering target
|
|
|
|
D3D::dev->SetDepthStencilSurface(NULL);
|
2009-11-08 20:35:11 +00:00
|
|
|
D3D::dev->SetRenderTarget(1, NULL);
|
|
|
|
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
|
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
TargetRectangle src_rect, dst_rect;
|
|
|
|
src_rect = Renderer::ConvertEFBRectangle(sourceRc);
|
|
|
|
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
|
2009-11-08 20:35:11 +00:00
|
|
|
D3DVIEWPORT9 vp;
|
|
|
|
vp.X = 0;
|
|
|
|
vp.Y = 0;
|
|
|
|
vp.Width = s_backbuffer_width;
|
|
|
|
vp.Height = s_backbuffer_height;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 0.0f;
|
|
|
|
D3D::dev->SetViewport(&vp);
|
2009-09-20 05:04:45 +00:00
|
|
|
|
2009-10-28 02:00:13 +00:00
|
|
|
D3D::dev->Clear(0,NULL, D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
|
2009-11-08 20:35:11 +00:00
|
|
|
vp.X = dst_rect.left;
|
|
|
|
vp.Y = dst_rect.top;
|
|
|
|
vp.Width = dst_rect.right - dst_rect.left;
|
|
|
|
vp.Height = dst_rect.bottom - dst_rect.top;
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
vp.MaxZ = 0.0f;
|
|
|
|
D3D::dev->SetViewport(&vp);
|
2009-09-20 05:04:45 +00:00
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
EFBRectangle efbRect;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LPDIRECT3DTEXTURE9 read_texture = FBManager::GetEFBColorTexture(efbRect);
|
|
|
|
RECT destinationrect;
|
|
|
|
destinationrect.bottom = dst_rect.bottom;
|
|
|
|
destinationrect.left = dst_rect.left;
|
|
|
|
destinationrect.right = dst_rect.right;
|
|
|
|
destinationrect.top = dst_rect.top;
|
|
|
|
RECT sourcerect;
|
|
|
|
sourcerect.bottom = src_rect.bottom;
|
|
|
|
sourcerect.left = src_rect.left;
|
|
|
|
sourcerect.right = src_rect.right;
|
|
|
|
sourcerect.top = src_rect.top;
|
|
|
|
|
|
|
|
D3D::drawShadedTexQuad(read_texture,&sourcerect,Renderer::GetTargetWidth(),Renderer::GetTargetHeight(),&destinationrect,PixelShaderCache::GetColorCopyProgram(),VertexShaderCache::GetSimpleVertexSahder());
|
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
// Finish up the current frame, print some stats
|
|
|
|
if (g_ActiveConfig.bOverlayStats)
|
2009-09-13 19:13:07 +00:00
|
|
|
{
|
2009-09-20 05:04:45 +00:00
|
|
|
Statistics::ToString(st);
|
|
|
|
D3D::font.DrawTextScaled(0,30,20,20,0.0f,0xFF00FFFF,st,false);
|
|
|
|
}
|
|
|
|
else if (g_ActiveConfig.bOverlayProjStats)
|
|
|
|
{
|
|
|
|
Statistics::ToStringProj(st);
|
|
|
|
D3D::font.DrawTextScaled(0,30,20,20,0.0f,0xFF00FFFF,st,false);
|
2009-09-13 19:13:07 +00:00
|
|
|
}
|
2009-09-04 06:09:21 +00:00
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
OSD::DrawMessages();
|
|
|
|
|
|
|
|
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
2009-11-08 20:35:11 +00:00
|
|
|
D3D::dev->SetRenderTarget(1, FBManager::GetEFBDepthEncodedSurface());
|
2009-09-20 05:04:45 +00:00
|
|
|
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
2009-11-08 20:35:11 +00:00
|
|
|
|
|
|
|
VertexShaderManager::SetViewportChanged();
|
2009-09-20 05:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void D3DDumpFrame()
|
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
if (EmuWindow::GetParentWnd())
|
|
|
|
{
|
2009-09-13 17:46:33 +00:00
|
|
|
// Re-stretch window to parent window size again, if it has a parent window.
|
2008-12-08 05:25:12 +00:00
|
|
|
RECT rcWindow;
|
|
|
|
GetWindowRect(EmuWindow::GetParentWnd(), &rcWindow);
|
|
|
|
|
|
|
|
int width = rcWindow.right - rcWindow.left;
|
|
|
|
int height = rcWindow.bottom - rcWindow.top;
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
// Frame dumping routine - seems buggy and wrong, esp. regarding buffer sizes
|
2009-09-13 08:21:35 +00:00
|
|
|
if (g_ActiveConfig.bDumpFrames) {
|
2009-03-28 21:07:16 +00:00
|
|
|
D3DDISPLAYMODE DisplayMode;
|
|
|
|
if (SUCCEEDED(D3D::dev->GetDisplayMode(0, &DisplayMode))) {
|
|
|
|
LPDIRECT3DSURFACE9 surf;
|
|
|
|
if (SUCCEEDED(D3D::dev->CreateOffscreenPlainSurface(DisplayMode.Width, DisplayMode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surf, NULL))) {
|
2009-09-13 08:21:35 +00:00
|
|
|
if (!s_LastFrameDumped) {
|
2009-03-28 21:07:16 +00:00
|
|
|
RECT windowRect;
|
2009-09-13 08:21:35 +00:00
|
|
|
GetClientRect(EmuWindow::GetWnd(), &windowRect);
|
|
|
|
s_recordWidth = windowRect.right - windowRect.left;
|
|
|
|
s_recordHeight = windowRect.bottom - windowRect.top;
|
|
|
|
s_AVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight);
|
|
|
|
if (!s_AVIDumping) {
|
2009-03-28 21:07:16 +00:00
|
|
|
PanicAlert("Error dumping frames to AVI.");
|
|
|
|
} else {
|
|
|
|
char msg [255];
|
2009-09-13 08:21:35 +00:00
|
|
|
sprintf(msg, "Dumping Frames to \"%s/framedump0.avi\" (%dx%d RGB24)", FULL_FRAMES_DIR, s_recordWidth, s_recordHeight);
|
2009-09-03 20:37:35 +00:00
|
|
|
OSD::AddMessage(msg, 2000);
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-13 08:21:35 +00:00
|
|
|
if (s_AVIDumping) {
|
2009-03-28 21:07:16 +00:00
|
|
|
if (SUCCEEDED(D3D::dev->GetFrontBufferData(0, surf))) {
|
|
|
|
RECT windowRect;
|
|
|
|
GetWindowRect(EmuWindow::GetWnd(), &windowRect);
|
|
|
|
D3DLOCKED_RECT rect;
|
|
|
|
if (SUCCEEDED(surf->LockRect(&rect, &windowRect, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY))) {
|
2009-09-13 08:21:35 +00:00
|
|
|
char *data = (char *)malloc(3 * s_recordWidth * s_recordHeight);
|
|
|
|
formatBufferDump((const char *)rect.pBits, data, s_recordWidth, s_recordHeight, rect.Pitch);
|
2009-03-28 21:07:16 +00:00
|
|
|
AVIDump::AddFrame(data);
|
|
|
|
free(data);
|
|
|
|
surf->UnlockRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-13 08:21:35 +00:00
|
|
|
s_LastFrameDumped = true;
|
2009-03-28 21:07:16 +00:00
|
|
|
surf->Release();
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 19:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-13 17:46:33 +00:00
|
|
|
if (s_LastFrameDumped && s_AVIDumping) {
|
2009-03-28 21:07:16 +00:00
|
|
|
AVIDump::Stop();
|
2009-09-13 08:21:35 +00:00
|
|
|
s_AVIDumping = false;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
s_LastFrameDumped = false;
|
2009-03-28 21:07:16 +00:00
|
|
|
}
|
2009-09-20 05:04:45 +00:00
|
|
|
}
|
2009-03-28 21:07:16 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
|
|
|
|
{
|
|
|
|
if (g_bSkipCurrentFrame)
|
|
|
|
{
|
|
|
|
g_VideoInitialize.pCopiedToXFB(false);
|
|
|
|
DEBUGGER_PAUSE_LOG_AT(NEXT_XFB_CMD,false,{printf("RenderToXFB - disabled");});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
Renderer::ResetAPIState();
|
2009-09-20 05:04:45 +00:00
|
|
|
D3DDumpFrame();
|
|
|
|
EFBTextureToD3DBackBuffer(sourceRc);
|
2009-11-08 20:35:11 +00:00
|
|
|
D3D::EndFrame();
|
|
|
|
|
2009-09-20 05:04:45 +00:00
|
|
|
|
2009-09-20 03:29:43 +00:00
|
|
|
DEBUGGER_LOG_AT((NEXT_XFB_CMD|NEXT_EFB_CMD|NEXT_FRAME),
|
|
|
|
{printf("StretchRect, EFB->XFB\n");});
|
|
|
|
DEBUGGER_PAUSE_LOG_AT(
|
|
|
|
(NEXT_XFB_CMD),false,
|
|
|
|
{printf("RenderToXFB: addr = %08X, %d x %d, sourceRc = (%d,%d,%d,%d)\n",
|
|
|
|
xfbAddr, fbWidth, fbHeight,
|
|
|
|
sourceRc.left, sourceRc.top, sourceRc.right, sourceRc.bottom);}
|
|
|
|
);
|
2009-09-20 13:00:25 +00:00
|
|
|
Swap(0,FIELD_PROGRESSIVE,0,0); // we used to swap the buffer here, now we will wait
|
2009-11-08 20:35:11 +00:00
|
|
|
// until the XFB pointer is updated by VI
|
|
|
|
D3D::BeginFrame();
|
|
|
|
Renderer::RestoreAPIState();
|
|
|
|
UpdateViewport();
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 19:42:45 +00:00
|
|
|
bool Renderer::SetScissorRect()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-06-22 09:31:30 +00:00
|
|
|
int xoff = bpmem.scissorOffset.x * 2 - 342;
|
|
|
|
int yoff = bpmem.scissorOffset.y * 2 - 342;
|
2009-03-08 18:45:39 +00:00
|
|
|
RECT rc;
|
2009-06-22 09:31:30 +00:00
|
|
|
rc.left = (int)((float)bpmem.scissorTL.x - xoff - 342);
|
|
|
|
rc.top = (int)((float)bpmem.scissorTL.y - yoff - 342);
|
|
|
|
rc.right = (int)((float)bpmem.scissorBR.x - xoff - 341);
|
|
|
|
rc.bottom = (int)((float)bpmem.scissorBR.y - yoff - 341);
|
2009-03-08 18:45:39 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
rc.left = (int)(rc.left * xScale);
|
|
|
|
rc.top = (int)(rc.top * yScale);
|
|
|
|
rc.right = (int)(rc.right * xScale);
|
|
|
|
rc.bottom = (int)(rc.bottom * yScale);
|
2009-09-13 17:46:33 +00:00
|
|
|
|
|
|
|
if (rc.left < 0) rc.left = 0;
|
2009-11-08 20:35:11 +00:00
|
|
|
if (rc.right < 0) rc.right = 0;
|
|
|
|
if (rc.left > s_target_width) rc.left = s_target_width;
|
|
|
|
if (rc.right > s_target_width) rc.right = s_target_width;
|
2009-09-13 17:46:33 +00:00
|
|
|
if (rc.top < 0) rc.top = 0;
|
2009-11-08 20:35:11 +00:00
|
|
|
if (rc.bottom < 0) rc.bottom = 0;
|
|
|
|
if (rc.top > s_target_height) rc.top = s_target_height;
|
2009-09-13 17:46:33 +00:00
|
|
|
if (rc.bottom > s_target_height) rc.bottom = s_target_height;
|
2009-11-08 20:35:11 +00:00
|
|
|
/*LONG temprc = 0;
|
|
|
|
if(rc.right < rc.left)
|
|
|
|
{
|
|
|
|
temprc = rc.right;
|
|
|
|
rc.right = rc.left;
|
|
|
|
rc.left = temprc;
|
|
|
|
}
|
|
|
|
if(rc.bottom < rc.top)
|
|
|
|
{
|
|
|
|
temprc = rc.bottom;
|
|
|
|
rc.bottom = rc.top;
|
|
|
|
rc.top = temprc;
|
|
|
|
}
|
|
|
|
D3D::dev->SetScissorRect(&rc);*/
|
2009-09-13 08:21:35 +00:00
|
|
|
if (rc.right >= rc.left && rc.bottom >= rc.top)
|
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
D3D::dev->SetScissorRect(&rc);
|
2009-09-03 19:42:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
else
|
2009-09-03 19:42:45 +00:00
|
|
|
{
|
2009-11-08 20:35:11 +00:00
|
|
|
WARN_LOG(VIDEO, "Bad scissor rectangle: %i %i %i %i", rc.left, rc.top, rc.right, rc.bottom);
|
2009-09-03 19:42:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-08 20:35:11 +00:00
|
|
|
return true;
|
2009-09-03 19:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::SetColorMask()
|
|
|
|
{
|
2009-09-13 08:21:35 +00:00
|
|
|
DWORD color_mask = 0;
|
2009-09-03 19:42:45 +00:00
|
|
|
if (bpmem.blendmode.alphaupdate)
|
2009-09-13 08:21:35 +00:00
|
|
|
color_mask = D3DCOLORWRITEENABLE_ALPHA;
|
2009-09-03 19:42:45 +00:00
|
|
|
if (bpmem.blendmode.colorupdate)
|
2009-09-13 08:21:35 +00:00
|
|
|
color_mask |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
|
|
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, color_mask);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 17:29:16 +00:00
|
|
|
u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
|
|
|
|
{
|
2009-10-10 23:36:18 +00:00
|
|
|
//Get the working buffer
|
2009-10-06 14:24:10 +00:00
|
|
|
LPDIRECT3DSURFACE9 pBuffer = (type == PEEK_Z || type == POKE_Z) ?
|
2009-11-08 20:35:11 +00:00
|
|
|
FBManager::GetEFBDepthEncodedSurface() : FBManager::GetEFBColorRTSurface();
|
2009-10-10 23:36:18 +00:00
|
|
|
//get the temporal buffer to move 1pixel data
|
|
|
|
LPDIRECT3DSURFACE9 RBuffer = (type == PEEK_Z || type == POKE_Z) ?
|
|
|
|
FBManager::GetEFBDepthReadSurface() : FBManager::GetEFBColorReadSurface();
|
|
|
|
//get the memory buffer that can be locked
|
2009-10-08 00:35:47 +00:00
|
|
|
LPDIRECT3DSURFACE9 pOffScreenBuffer = (type == PEEK_Z || type == POKE_Z) ?
|
2009-10-10 23:36:18 +00:00
|
|
|
FBManager::GetEFBDepthOffScreenRTSurface() : FBManager::GetEFBColorOffScreenRTSurface();
|
|
|
|
//get the buffer format
|
2009-10-06 14:24:10 +00:00
|
|
|
D3DFORMAT BufferFormat = (type == PEEK_Z || type == POKE_Z) ?
|
|
|
|
FBManager::GetEFBDepthRTSurfaceFormat() : FBManager::GetEFBColorRTSurfaceFormat();
|
2009-10-10 23:36:18 +00:00
|
|
|
|
|
|
|
D3DLOCKED_RECT drect;
|
|
|
|
|
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
//Buffer not found alert
|
|
|
|
if(!pBuffer) {
|
|
|
|
PanicAlert("No %s!", (type == PEEK_Z || type == POKE_Z) ? "Z-Buffer" : "Color EFB");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-04 17:29:16 +00:00
|
|
|
// Get the rectangular target region covered by the EFB pixel.
|
2009-10-06 14:24:10 +00:00
|
|
|
|
2009-09-04 17:29:16 +00:00
|
|
|
EFBRectangle efbPixelRc;
|
|
|
|
efbPixelRc.left = x;
|
|
|
|
efbPixelRc.top = y;
|
|
|
|
efbPixelRc.right = x + 1;
|
|
|
|
efbPixelRc.bottom = y + 1;
|
|
|
|
|
|
|
|
TargetRectangle targetPixelRc = Renderer::ConvertEFBRectangle(efbPixelRc);
|
|
|
|
|
2009-10-03 02:12:24 +00:00
|
|
|
u32 z = 0;
|
|
|
|
float val = 0.0f;
|
|
|
|
HRESULT hr;
|
|
|
|
RECT RectToLock;
|
|
|
|
RectToLock.bottom = targetPixelRc.bottom;
|
|
|
|
RectToLock.left = targetPixelRc.left;
|
|
|
|
RectToLock.right = targetPixelRc.right;
|
|
|
|
RectToLock.top = targetPixelRc.top;
|
2009-10-06 14:24:10 +00:00
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
hr = D3D::dev->StretchRect(pBuffer,&RectToLock,RBuffer,NULL, D3DTEXF_NONE);
|
|
|
|
if(FAILED(hr))
|
2009-10-08 00:35:47 +00:00
|
|
|
{
|
2009-11-08 20:35:11 +00:00
|
|
|
PanicAlert("Unable to stretch data to buffer");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//retriebe the pixel data to the local memory buffer
|
|
|
|
D3D::dev->GetRenderTargetData(RBuffer,pOffScreenBuffer);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
PanicAlert("Unable to copy data to mem buffer");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//change the rect to lock the entire one pixel buffer
|
|
|
|
RectToLock.bottom = 1;
|
|
|
|
RectToLock.left = 0;
|
|
|
|
RectToLock.right = 1;
|
|
|
|
RectToLock.top = 0;
|
|
|
|
|
2009-10-10 23:36:18 +00:00
|
|
|
//the surface is good.. lock it
|
2009-10-08 00:35:47 +00:00
|
|
|
if((hr = pOffScreenBuffer->LockRect(&drect, &RectToLock, D3DLOCK_READONLY)) != D3D_OK)
|
2009-10-10 23:36:18 +00:00
|
|
|
{
|
2009-10-03 02:12:24 +00:00
|
|
|
PanicAlert("ERROR: %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
|
|
|
|
hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");
|
2009-10-10 23:36:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-10-02 14:03:07 +00:00
|
|
|
|
2009-10-03 02:12:24 +00:00
|
|
|
switch(type) {
|
|
|
|
case PEEK_Z:
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
2009-11-08 20:35:11 +00:00
|
|
|
static float ffrac = 255.0f/254.0f;
|
|
|
|
z = ((u32 *)drect.pBits)[0];
|
|
|
|
float fvalue = (((float)(z & 0xFF)) / 255.0f) * ffrac;
|
|
|
|
fvalue += (((float)((z>>8) & 0xFF)) / 255.0f) * (ffrac/255.0f);
|
|
|
|
fvalue += (((float)((z>>16) & 0xFF)) / 255.0f) * (ffrac/(255.0f*255.0f));
|
|
|
|
fvalue += (((float)((z>>24) & 0xFF)) / 255.0f) * (ffrac/(255.0f*255.0f*255.0f));
|
|
|
|
if(fvalue>1.0f)fvalue=1.0f;
|
|
|
|
if(fvalue<0.0f)fvalue=0.0f;
|
|
|
|
z = ((u32)(fvalue * 0xffffff));
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
2009-11-08 20:35:11 +00:00
|
|
|
break;
|
2009-10-03 02:12:24 +00:00
|
|
|
case POKE_Z:
|
|
|
|
// TODO: Get that Z value to poke from somewhere
|
|
|
|
//((float *)drect.pBits)[0] = val;
|
|
|
|
PanicAlert("Poke Z-buffer not implemented");
|
|
|
|
break;
|
2009-09-24 13:52:45 +00:00
|
|
|
|
2009-10-03 02:12:24 +00:00
|
|
|
case PEEK_COLOR:
|
|
|
|
z = ((u32 *)drect.pBits)[0];
|
|
|
|
break;
|
|
|
|
case POKE_COLOR:
|
|
|
|
// TODO: Get that ARGB value to poke from somewhere
|
|
|
|
//((float *)drect.pBits)[0] = val;
|
|
|
|
PanicAlert("Poke color EFB not implemented");
|
|
|
|
break;
|
2009-09-04 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
pOffScreenBuffer->UnlockRect();
|
2009-10-03 02:12:24 +00:00
|
|
|
// TODO: in RE0 this value is often off by one, which causes lighting to disappear
|
2009-10-10 23:36:18 +00:00
|
|
|
return z;
|
2009-10-03 02:12:24 +00:00
|
|
|
|
2009-09-04 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
// mtx.m[0][3] = pMatrix[1]; // -0.5f/s_target_width; <-- fix d3d pixel center?
|
|
|
|
// mtx.m[1][3] = pMatrix[3]; // +0.5f/s_target_height; <-- fix d3d pixel center?
|
2009-03-08 18:45:39 +00:00
|
|
|
|
2009-11-02 21:09:48 +00:00
|
|
|
// Called from VertexShaderManager
|
2009-02-28 22:10:38 +00:00
|
|
|
// Called from VertexShaderManager
|
|
|
|
void UpdateViewport()
|
|
|
|
{
|
2009-09-03 19:24:16 +00:00
|
|
|
int scissorXOff = bpmem.scissorOffset.x * 2;
|
|
|
|
int scissorYOff = bpmem.scissorOffset.y * 2;
|
2009-02-28 22:10:38 +00:00
|
|
|
|
2009-09-03 19:42:45 +00:00
|
|
|
float MValueX = Renderer::GetTargetScaleX();
|
|
|
|
float MValueY = Renderer::GetTargetScaleY();
|
2009-09-02 04:10:40 +00:00
|
|
|
|
2009-09-03 19:24:16 +00:00
|
|
|
D3DVIEWPORT9 vp;
|
2009-02-28 22:10:38 +00:00
|
|
|
|
2009-09-03 19:24:16 +00:00
|
|
|
// Stretch picture with increased internal resolution
|
|
|
|
vp.X = (int)(ceil(xfregs.rawViewport[3] - xfregs.rawViewport[0] - (scissorXOff)) * MValueX);
|
|
|
|
vp.Y = (int)(ceil(xfregs.rawViewport[4] + xfregs.rawViewport[1] - (scissorYOff)) * MValueY);
|
|
|
|
vp.Width = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX);
|
|
|
|
vp.Height = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
|
2009-11-08 20:35:11 +00:00
|
|
|
if(vp.X < 0) vp.X = 0;
|
|
|
|
if(vp.Y < 0) vp.Y = 0;
|
|
|
|
if(vp.X > s_target_width) vp.X = s_target_width;
|
|
|
|
if(vp.Y > s_target_height) vp.Y = s_target_height;
|
|
|
|
if(vp.Width < 0) vp.Width = 0;
|
|
|
|
if(vp.Height < 0) vp.Height = 0;
|
|
|
|
if(vp.Width > (s_target_width - vp.X)) vp.Width = s_target_width - vp.X;
|
|
|
|
if(vp.Height > (s_target_height - vp.Y)) vp.Height = s_target_height - vp.Y;
|
2009-11-02 21:09:48 +00:00
|
|
|
//some games set invalids values for z min and z max so fix them to the max an min alowed and let the shaders do this work
|
|
|
|
vp.MinZ = 0.0f;//(xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
|
|
|
|
vp.MaxZ = 1.0f;//xfregs.rawViewport[5] / 16777216.0f;
|
2009-02-28 22:10:38 +00:00
|
|
|
D3D::dev->SetViewport(&vp);
|
2009-09-02 04:10:40 +00:00
|
|
|
}
|
2009-09-20 03:29:43 +00:00
|
|
|
|
2009-10-02 21:23:56 +00:00
|
|
|
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z)
|
|
|
|
{
|
|
|
|
// Update the view port for clearing the picture
|
|
|
|
D3DVIEWPORT9 vp;
|
|
|
|
vp.X = 0;
|
|
|
|
vp.Y = 0;
|
|
|
|
vp.Width = Renderer::GetTargetWidth();
|
|
|
|
vp.Height = Renderer::GetTargetHeight();
|
|
|
|
vp.MinZ = 0.0;
|
|
|
|
vp.MaxZ = 1.0;
|
|
|
|
D3D::dev->SetViewport(&vp);
|
|
|
|
|
|
|
|
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(rc);
|
|
|
|
|
|
|
|
// Always set the scissor in case it was set by the game and has not been reset
|
|
|
|
RECT sirc;
|
|
|
|
sirc.left = targetRc.left;
|
|
|
|
sirc.top = targetRc.top;
|
|
|
|
sirc.right = targetRc.right;
|
|
|
|
sirc.bottom = targetRc.bottom;
|
|
|
|
D3D::dev->SetScissorRect(&sirc);
|
|
|
|
|
|
|
|
VertexShaderManager::SetViewportChanged();
|
|
|
|
|
|
|
|
DWORD clearflags = 0;
|
|
|
|
if(colorEnable)
|
|
|
|
{
|
|
|
|
clearflags |= D3DCLEAR_TARGET;
|
|
|
|
}
|
|
|
|
if (zEnable)
|
|
|
|
{
|
|
|
|
clearflags |= D3DCLEAR_ZBUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D::dev->Clear(0, NULL, clearflags, color,(z & 0xFFFFFF) / float(0xFFFFFF), 0);
|
|
|
|
}
|
|
|
|
|
2009-10-10 23:36:18 +00:00
|
|
|
void Renderer::SetBlendMode(bool forceUpdate)
|
|
|
|
{
|
|
|
|
// blend mode bit mask
|
|
|
|
// 0 - blend enable
|
|
|
|
// 2 - reverse subtract enable (else add)
|
|
|
|
// 3-5 - srcRGB function
|
|
|
|
// 6-8 - dstRGB function
|
|
|
|
|
|
|
|
u32 newval = bpmem.blendmode.subtract << 2;
|
|
|
|
|
|
|
|
if (bpmem.blendmode.subtract) {
|
|
|
|
newval |= 0x0049; // enable blending src 1 dst 1
|
|
|
|
} else if (bpmem.blendmode.blendenable) {
|
|
|
|
newval |= 1; // enable blending
|
|
|
|
newval |= bpmem.blendmode.srcfactor << 3;
|
|
|
|
newval |= bpmem.blendmode.dstfactor << 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 changes = forceUpdate ? 0xFFFFFFFF : newval ^ s_blendMode;
|
|
|
|
|
|
|
|
if (changes & 1) {
|
|
|
|
// blend enable change
|
|
|
|
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, (newval & 1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes & 4) {
|
|
|
|
// subtract enable change
|
|
|
|
D3D::SetRenderState(D3DRS_BLENDOP, newval & 4 ? D3DBLENDOP_REVSUBTRACT : D3DBLENDOP_ADD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes & 0x1F8) {
|
|
|
|
// blend RGB change
|
|
|
|
D3D::SetRenderState(D3DRS_SRCBLEND, d3dSrcFactors[(newval >> 3) & 7]);
|
|
|
|
D3D::SetRenderState(D3DRS_DESTBLEND, d3dDestFactors[(newval >> 6) & 7]);
|
|
|
|
}
|
|
|
|
|
|
|
|
s_blendMode = newval;
|
|
|
|
}
|
2009-10-02 21:23:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-20 03:29:43 +00:00
|
|
|
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// D3D frame is now over
|
|
|
|
// Clean out old stuff from caches.
|
|
|
|
frameCount++;
|
|
|
|
PixelShaderCache::Cleanup();
|
|
|
|
VertexShaderCache::Cleanup();
|
|
|
|
TextureCache::Cleanup();
|
|
|
|
|
|
|
|
// Make any new configuration settings active.
|
|
|
|
UpdateActiveConfig();
|
|
|
|
|
|
|
|
//TODO: Resize backbuffer if window size has changed. This code crashes, debug it.
|
|
|
|
g_VideoInitialize.pCopiedToXFB(false);
|
|
|
|
|
|
|
|
CheckForResize();
|
|
|
|
|
|
|
|
|
|
|
|
// Begin new frame
|
|
|
|
// Set default viewport and scissor, for the clear to work correctly
|
|
|
|
stats.ResetFrame();
|
|
|
|
|
|
|
|
// Flip/present backbuffer to frontbuffer here
|
|
|
|
D3D::Present();
|
|
|
|
}
|
2009-11-08 20:35:11 +00:00
|
|
|
|
|
|
|
void Renderer::ResetAPIState()
|
|
|
|
{
|
|
|
|
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
|
|
|
|
D3D::SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
|
|
|
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
|
|
|
D3D::SetRenderState(D3DRS_ZENABLE, FALSE);
|
|
|
|
D3D::SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
|
|
|
DWORD color_mask = D3DCOLORWRITEENABLE_ALPHA| D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
|
|
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, color_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RestoreAPIState()
|
|
|
|
{
|
|
|
|
// Gets us back into a more game-like state.
|
|
|
|
|
|
|
|
UpdateViewport();
|
|
|
|
|
|
|
|
if (bpmem.zmode.testenable) D3D::SetRenderState(D3DRS_ZENABLE, TRUE);
|
|
|
|
if (bpmem.zmode.updateenable) D3D::SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
|
|
|
|
|
|
|
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
|
|
|
|
SetScissorRect();
|
|
|
|
SetColorMask();
|
|
|
|
SetBlendMode(true);
|
|
|
|
}
|