D3D: Eliminate black borders, add 4:3 and 16:9 settings, and the widescreen hack. Unfortunately this temporarily breaks MSAA (in d3d only) until I have time to fix it.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4263 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-09-13 17:46:33 +00:00
parent 5911abc600
commit a7c70ddb66
32 changed files with 2041 additions and 370 deletions

View File

@ -218,7 +218,7 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
PanicAlert("Cant read from DVD_Plugin - DVD-Interface: Fatal Error"); PanicAlert("Cant read from DVD_Plugin - DVD-Interface: Fatal Error");
} }
FileMon::CheckFile(std::string(pFilename), m_pFileSystem->GetFileSize(pFilename)); FileMon::CheckFile(std::string(pFilename), (int)m_pFileSystem->GetFileSize(pFilename));
} }
break; break;

View File

@ -46,7 +46,6 @@ void SetDitherMode(const BPCmd &bp);
void SetLogicOpMode(const BPCmd &bp); void SetLogicOpMode(const BPCmd &bp);
void SetColorMask(const BPCmd &bp); void SetColorMask(const BPCmd &bp);
void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 &copyfmt, const int &scaleByHalf); void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const bool &fromZBuffer, const bool &isIntensityFmt, const u32 &copyfmt, const int &scaleByHalf);
void RenderToXFB(const BPCmd &bp, const EFBRectangle &rc, const float &yScale, const float &xfbLines, u32 xfbAddr, const u32 &dstWidth, const u32 &dstHeight);
void ClearScreen(const BPCmd &bp, const EFBRectangle &rc); void ClearScreen(const BPCmd &bp, const EFBRectangle &rc);
void RestoreRenderState(const BPCmd &bp); void RestoreRenderState(const BPCmd &bp);
u8 *GetPointer(const u32 &address); u8 *GetPointer(const u32 &address);

View File

@ -19,6 +19,7 @@
#include "Profiler.h" #include "Profiler.h"
#include "Statistics.h" #include "Statistics.h"
#include "Render.h"
#include "VideoCommon.h" #include "VideoCommon.h"
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "BPFunctions.h" #include "BPFunctions.h"
@ -40,6 +41,12 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF; bpmem.bpMask = 0xFFFFFF;
} }
void RenderToXFB(const BPCmd &bp, const EFBRectangle &rc, float yScale, float xfbLines, u32 xfbAddr, const u32 dstWidth, const u32 dstHeight)
{
Renderer::RenderToXFB(xfbAddr, dstWidth, dstHeight, rc);
}
void BPWritten(const BPCmd& bp) void BPWritten(const BPCmd& bp)
{ {
/* /*

View File

@ -67,8 +67,8 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 texturemask, u32 dstAlphaEnable)
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[i].colorC; TevStageCombiner::ColorCombiner &cc = bpmem.combiners[i].colorC;
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[i].alphaC; TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[i].alphaC;
u32 val0 = cc.hex&0xffffff; u32 val0 = cc.hex & 0xffffff;
u32 val1 = ac.hex&0xffffff; u32 val1 = ac.hex & 0xffffff;
val0 |= bpmem.tevksel[i / 2].getKC(i & 1) << 24; val0 |= bpmem.tevksel[i / 2].getKC(i & 1) << 24;
val1 |= bpmem.tevksel[i / 2].getKA(i & 1) << 24; val1 |= bpmem.tevksel[i / 2].getKA(i & 1) << 24;
pcurvalue[0] = val0; pcurvalue[0] = val0;

View File

@ -15,7 +15,6 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
// --------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------
// GC graphics pipeline // GC graphics pipeline
// --------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------
@ -33,9 +32,13 @@
#include "MathUtil.h" #include "MathUtil.h"
#include "pluginspecs_video.h" #include "pluginspecs_video.h"
// TODO: Move these out of here.
extern int frameCount; extern int frameCount;
extern int OSDChoice, OSDTime, OSDInternalW, OSDInternalH; extern int OSDChoice, OSDTime, OSDInternalW, OSDInternalH;
// Renderer really isn't a very good name for this class - it's more like "Misc".
// The long term goal is to get rid of this class and replace it with others that make
// more sense.
class Renderer class Renderer
{ {
public: public:
@ -48,8 +51,6 @@ public:
static void ReinitView(); static void ReinitView();
static void SwapBuffers();
static void SetColorMask(); static void SetColorMask();
static void SetBlendMode(bool forceUpdate); static void SetBlendMode(bool forceUpdate);
static bool SetScissorRect(); static bool SetScissorRect();

View File

@ -17,7 +17,6 @@
#include "CommonTypes.h" #include "CommonTypes.h"
#include "VideoCommon.h" #include "VideoCommon.h"
#include "Render.h" // for EFBRectangle.h, unfortunately.
#include <vector> #include <vector>
#ifndef _STATISTICS_H #ifndef _STATISTICS_H

View File

@ -97,6 +97,7 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Hardware", "WindowedRes", &iWindowedRes, 0); iniFile.Get("Hardware", "WindowedRes", &iWindowedRes, 0);
iniFile.Get("Hardware", "VSync", &bVsync, 0); iniFile.Get("Hardware", "VSync", &bVsync, 0);
iniFile.Get("Hardware", "FullscreenRes", &iFSResolution, 0); iniFile.Get("Hardware", "FullscreenRes", &iFSResolution, 0);
iniFile.Get("Hardware", "SimpleFB", &bSimpleFB, false);
// Load common settings // Load common settings
iniFile.Load(CONFIG_FILE); iniFile.Load(CONFIG_FILE);
@ -175,12 +176,11 @@ void VideoConfig::Save(const char *ini_file)
iniFile.Set("Hardware", "WindowedRes", iWindowedRes); iniFile.Set("Hardware", "WindowedRes", iWindowedRes);
iniFile.Set("Hardware", "VSync", bVsync); iniFile.Set("Hardware", "VSync", bVsync);
iniFile.Set("Hardware", "FullscreenRes", iFSResolution); iniFile.Set("Hardware", "FullscreenRes", iFSResolution);
iniFile.Set("Hardware", "SimpleFB", bSimpleFB);
iniFile.Save(ini_file); iniFile.Save(ini_file);
} }
// TODO: Figure out a better place for this function. // TODO: Figure out a better place for this function.
void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip, TargetRectangle *rc) void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip, TargetRectangle *rc)
{ {
@ -198,8 +198,8 @@ void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip
{ {
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
float Ratio = (WinWidth / WinHeight) / (g_Config.bKeepAR43 ? (4.0f / 3.0f) : (16.0f / 9.0f)); float Ratio = (WinWidth / WinHeight) / (g_Config.bKeepAR43 ? (4.0f / 3.0f) : (16.0f / 9.0f));
// Check if height or width is the limiting factor. If ratio > 1 the picture is to wide and have to limit the width. // Check if height or width is the limiting factor. If ratio > 1 the picture is too wide and have to limit the width.
if (Ratio > 1) if (Ratio > 1.0f)
{ {
// Scale down and center in the X direction. // Scale down and center in the X direction.
FloatGLWidth /= Ratio; FloatGLWidth /= Ratio;
@ -230,12 +230,8 @@ void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip
// Adjust the X and Y offset // Adjust the X and Y offset
FloatXOffset = FloatXOffset - (IncreasedWidth * 0.5f); FloatXOffset = FloatXOffset - (IncreasedWidth * 0.5f);
FloatYOffset = FloatYOffset - (IncreasedHeight * 0.5f); FloatYOffset = FloatYOffset - (IncreasedHeight * 0.5f);
//NOTICE_LOG(OSREPORT, "Crop Ratio:%1.2f IncreasedHeight:%3.0f YOffset:%3.0f", Ratio, IncreasedHeight, FloatYOffset);
//NOTICE_LOG(OSREPORT, "Crop FloatGLWidth:%1.2f FloatGLHeight:%3.0f", (float)FloatGLWidth, (float)FloatGLHeight);
//NOTICE_LOG(OSREPORT, "");
} }
// round(float) = floor(float + 0.5)
int XOffset = (int)(FloatXOffset + 0.5f); int XOffset = (int)(FloatXOffset + 0.5f);
int YOffset = (int)(FloatYOffset + 0.5f); int YOffset = (int)(FloatYOffset + 0.5f);
rc->left = XOffset; rc->left = XOffset;

View File

@ -131,9 +131,6 @@ struct VideoConfig
// With this enabled, the plugin renders directly to the backbuffer. Many features are // With this enabled, the plugin renders directly to the backbuffer. Many features are
// disabled but it might be faster on really old GPUs. // disabled but it might be faster on really old GPUs.
bool bSimpleFB; bool bSimpleFB;
// Runtime detection config
bool bOldCard;
}; };
extern VideoConfig g_Config; extern VideoConfig g_Config;

View File

@ -1190,6 +1190,14 @@
<Filter <Filter
Name="Render" Name="Render"
> >
<File
RelativePath=".\Src\FramebufferManager.cpp"
>
</File>
<File
RelativePath=".\Src\FramebufferManager.h"
>
</File>
<File <File
RelativePath=".\Src\NativeVertexFormat.cpp" RelativePath=".\Src\NativeVertexFormat.cpp"
> >

View File

@ -217,13 +217,6 @@ void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const
} }
} }
void RenderToXFB(const BPCmd &bp, const EFBRectangle &rc, const float &yScale, const float &xfbLines, u32 xfbAddr, const u32 &dstWidth, const u32 &dstHeight)
{
Renderer::SwapBuffers();
PRIM_LOG("Renderer::SwapBuffers()");
g_VideoInitialize.pCopiedToXFB(false);
}
void ClearScreen(const BPCmd &bp, const EFBRectangle &rc) void ClearScreen(const BPCmd &bp, const EFBRectangle &rc)
{ {
// TODO: Scale EFBRectangle correctly // TODO: Scale EFBRectangle correctly
@ -306,7 +299,7 @@ void SetSamplerState(const BPCmd &bp)
if (g_ActiveConfig.iMaxAnisotropy > 1) if (g_ActiveConfig.iMaxAnisotropy > 1)
{ {
mag = D3DTEXF_ANISOTROPIC; mag = D3DTEXF_LINEAR;
min = D3DTEXF_ANISOTROPIC; min = D3DTEXF_ANISOTROPIC;
mip = D3DTEXF_LINEAR; mip = D3DTEXF_LINEAR;
} }

View File

@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "D3DBase.h" #include "D3DBase.h"
#include "VideoConfig.h"
#include "Render.h" #include "Render.h"
#include "XFStructs.h" #include "XFStructs.h"
@ -24,7 +25,8 @@ namespace D3D
LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
LPDIRECT3DSURFACE9 backBuffer; LPDIRECT3DSURFACE9 back_buffer;
LPDIRECT3DSURFACE9 back_buffer_z;
D3DCAPS9 caps; D3DCAPS9 caps;
HWND hWnd; HWND hWnd;
@ -117,7 +119,7 @@ void EnableAlphaToCoverage()
xres = pp->BackBufferWidth = client.right - client.left; xres = pp->BackBufferWidth = client.right - client.left;
yres = pp->BackBufferHeight = client.bottom - client.top; yres = pp->BackBufferHeight = client.bottom - client.top;
pp->SwapEffect = D3DSWAPEFFECT_DISCARD; pp->SwapEffect = D3DSWAPEFFECT_DISCARD;
pp->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; pp->PresentationInterval = g_Config.bVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
pp->Windowed = TRUE; pp->Windowed = TRUE;
} }
} }
@ -251,7 +253,8 @@ void EnableAlphaToCoverage()
} }
} }
dev->GetDeviceCaps(&caps); dev->GetDeviceCaps(&caps);
dev->GetRenderTarget(0, &backBuffer); dev->GetRenderTarget(0, &back_buffer);
dev->GetDepthStencilSurface(&back_buffer_z);
// Device state would normally be set here // Device state would normally be set here
return S_OK; return S_OK;
@ -284,7 +287,12 @@ const char *PixelShaderVersionString()
LPDIRECT3DSURFACE9 GetBackBufferSurface() LPDIRECT3DSURFACE9 GetBackBufferSurface()
{ {
return backBuffer; return back_buffer;
}
LPDIRECT3DSURFACE9 GetBackBufferDepthSurface()
{
return back_buffer_z;
} }
void ShowD3DError(HRESULT err) void ShowD3DError(HRESULT err)
@ -305,10 +313,17 @@ void ShowD3DError(HRESULT err)
{ {
if (dev) if (dev)
{ {
// Can't keep a pointer around to the backbuffer surface when resetting.
back_buffer_z->Release();
back_buffer->Release();
D3DPRESENT_PARAMETERS d3dpp; D3DPRESENT_PARAMETERS d3dpp;
InitPP(cur_adapter, resolution, multisample, &d3dpp); InitPP(cur_adapter, resolution, multisample, &d3dpp);
HRESULT hr = dev->Reset(&d3dpp); HRESULT hr = dev->Reset(&d3dpp);
ShowD3DError(hr); ShowD3DError(hr);
dev->GetRenderTarget(0, &back_buffer);
dev->GetDepthStencilSurface(&back_buffer_z);
} }
} }
@ -317,12 +332,12 @@ void ShowD3DError(HRESULT err)
return fullScreen; return fullScreen;
} }
int GetDisplayWidth() int GetBackBufferWidth()
{ {
return xres; return xres;
} }
int GetDisplayHeight() int GetBackBufferHeight()
{ {
return yres; return yres;
} }
@ -332,7 +347,7 @@ void ShowD3DError(HRESULT err)
nextFullScreen = fullscreen; nextFullScreen = fullscreen;
} }
bool BeginFrame(bool clear, u32 color, float z) bool BeginFrame()
{ {
if (bFrameInProgress) if (bFrameInProgress)
{ {
@ -342,8 +357,6 @@ void ShowD3DError(HRESULT err)
bFrameInProgress = true; bFrameInProgress = true;
if (dev) if (dev)
{ {
if (clear)
dev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, (DWORD)color, z, 0 );
dev->BeginScene(); dev->BeginScene();
return true; return true;
} }

View File

@ -37,13 +37,16 @@ void Shutdown();
extern IDirect3DDevice9 *dev; extern IDirect3DDevice9 *dev;
void Reset(); void Reset();
bool BeginFrame(bool clear, u32 color, float z); bool BeginFrame();
void EndFrame(); void EndFrame();
void SwitchFullscreen(bool fullscreen); void SwitchFullscreen(bool fullscreen);
bool IsFullscreen(); bool IsFullscreen();
int GetDisplayWidth();
int GetDisplayHeight(); int GetBackBufferWidth();
int GetBackBufferHeight();
LPDIRECT3DSURFACE9 GetBackBufferSurface(); LPDIRECT3DSURFACE9 GetBackBufferSurface();
LPDIRECT3DSURFACE9 GetBackBufferDepthSurface();
const D3DCAPS9 &GetCaps(); const D3DCAPS9 &GetCaps();
const char *PixelShaderVersionString(); const char *PixelShaderVersionString();
const char *VertexShaderVersionString(); const char *VertexShaderVersionString();

View File

@ -36,21 +36,19 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int
} }
HRESULT hr; HRESULT hr;
// TODO(ector): allow mipmaps for non-pow textures on newer cards? // TODO(ector): Allow mipmaps for non-pow textures on newer cards?
// TODO(ector): Use the game-specified mipmaps?
if (!isPow2) if (!isPow2)
hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL); hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
else else
hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL); hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
if(FAILED(hr)) if (FAILED(hr))
return 0; return 0;
int level = 0; int level = 0;
D3DLOCKED_RECT Lock; D3DLOCKED_RECT Lock;
pTexture->LockRect(level, &Lock, NULL, 0 ); pTexture->LockRect(level, &Lock, NULL, 0);
switch (fmt)
switch(fmt)
{ {
case D3DFMT_L8: case D3DFMT_L8:
case D3DFMT_A8: case D3DFMT_A8:
@ -150,26 +148,4 @@ void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int w
pTexture->UnlockRect(level); pTexture->UnlockRect(level);
} }
LPDIRECT3DTEXTURE9 CreateRenderTarget(const int width, const int height)
{
LPDIRECT3DTEXTURE9 tex;
HRESULT hr = dev->CreateTexture(width,height,0,D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&tex,NULL);
if (FAILED(hr))
return 0;
else
return tex;
}
LPDIRECT3DSURFACE9 CreateDepthStencilSurface(const int width, const int height)
{
LPDIRECT3DSURFACE9 surf;
HRESULT hr = dev->CreateDepthStencilSurface(width,height,D3DFMT_D24S8,D3DMULTISAMPLE_NONE,0,0,&surf,0);
if (FAILED(hr))
return 0;
else
return surf;
}
} // namespace } // namespace

View File

@ -51,11 +51,14 @@ namespace D3D
int CD3DFont::Init() int CD3DFont::Init()
{ {
m_fTextScale = 1.0f; // Draw fonts into texture without scaling // Create vertex buffer for the letters
// Create a new texture for the font HRESULT hr;
HRESULT hr = dev->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &m_pTexture, NULL); if (FAILED(hr = dev->CreateVertexBuffer(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
if (FAILED(hr)) D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &m_pVB, NULL)))
{
return hr; return hr;
}
m_fTextScale = 1.0f; // Draw fonts into texture without scaling
// Prepare to create a bitmap // Prepare to create a bitmap
int *pBitmapBits; int *pBitmapBits;
@ -76,15 +79,13 @@ namespace D3D
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an // Create a font. By specifying ANTIALIASED_QUALITY, we might get an
// antialiased font, but this is not guaranteed. // antialiased font, but this is not guaranteed.
// We definitely don't want to get it cleartype'd, anyway. // We definitely don't want to get it cleartype'd, anyway.
int m_dwFontHeight = 36; int m_dwFontHeight = 24;
int nHeight = -MulDiv(m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72); int nHeight = -MulDiv(m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72);
int dwBold = FW_NORMAL; ///FW_BOLD int dwBold = FW_NORMAL; ///FW_BOLD
HFONT hFont = CreateFont(nHeight, 0, 0, 0, dwBold, 0, HFONT hFont = CreateFont(nHeight, 0, 0, 0, dwBold, 0,
FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, _T("Tahoma")); VARIABLE_PITCH, _T("Tahoma"));
if (NULL == hFont) if (NULL == hFont)
return E_FAIL; return E_FAIL;
@ -99,43 +100,48 @@ namespace D3D
// Loop through all printable character and output them to the bitmap.. // Loop through all printable character and output them to the bitmap..
// Meanwhile, keep track of the corresponding tex coords for each character. // Meanwhile, keep track of the corresponding tex coords for each character.
int x = 0, y = 0; int x = 0, y = 0;
char str[2] = "\0"; char str[2] = "\0";
SIZE size; for (int c = 0; c < 127 - 32; c++)
for (char c=0; c<127-32; c++)
{ {
str[0] = c+32; str[0] = c + 32;
SIZE size;
GetTextExtentPoint32A(hDC, str, 1, &size); GetTextExtentPoint32A(hDC, str, 1, &size);
if ((int)(x+size.cx+1) > m_dwTexWidth) if ((int)(x+size.cx+1) > m_dwTexWidth)
{ {
x = 0; x = 0;
y += size.cy+1; y += size.cy + 1;
} }
ExtTextOutA(hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL); ExtTextOutA(hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL);
m_fTexCoords[c][0] = ((float)(x+0))/m_dwTexWidth; m_fTexCoords[c][0] = ((float)(x+0))/m_dwTexWidth;
m_fTexCoords[c][1] = ((float)(y+0))/m_dwTexHeight; m_fTexCoords[c][1] = ((float)(y+0))/m_dwTexHeight;
m_fTexCoords[c][2] = ((float)(x+0+size.cx))/m_dwTexWidth; m_fTexCoords[c][2] = ((float)(x+0+size.cx))/m_dwTexWidth;
m_fTexCoords[c][3] = ((float)(y+0+size.cy))/m_dwTexHeight; m_fTexCoords[c][3] = ((float)(y+0+size.cy))/m_dwTexHeight;
x += size.cx+3; //3 to avoid annoying ij conflict (part of the j ends up with the i) x += size.cx + 3; //3 to work around annoying ij conflict (part of the j ends up with the i)
}
// Create a new texture for the font
hr = dev->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1, D3DUSAGE_DYNAMIC,
D3DFMT_A4R4G4B4, D3DPOOL_DEFAULT, &m_pTexture, NULL);
if (FAILED(hr))
{
PanicAlert("Failed to create font texture");
return hr;
} }
// Lock the surface and write the alpha values for the set pixels // Lock the surface and write the alpha values for the set pixels
D3DLOCKED_RECT d3dlr; D3DLOCKED_RECT d3dlr;
m_pTexture->LockRect(0, &d3dlr, 0, 0); m_pTexture->LockRect(0, &d3dlr, 0, D3DLOCK_DISCARD);
unsigned short* pDst16 = (unsigned short*)d3dlr.pBits;
int bAlpha; // 4-bit measure of pixel intensity int bAlpha; // 4-bit measure of pixel intensity
for (y=0; y < m_dwTexHeight; y++) for (y = 0; y < m_dwTexHeight; y++)
{ {
for (x=0; x < m_dwTexWidth; x++) u16 *pDst16 = (u16*)((u8 *)d3dlr.pBits + y * d3dlr.Pitch);
for (x = 0; x < m_dwTexWidth; x++)
{ {
bAlpha = ((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4); bAlpha = ((pBitmapBits[m_dwTexWidth * y + x] & 0xff) >> 4);
*pDst16++ = (bAlpha << 12) | 0x0fff; pDst16[x] = (bAlpha << 12) | 0x0fff;
} }
} }
@ -148,14 +154,6 @@ namespace D3D
SelectObject(hDC, hOldFont); SelectObject(hDC, hOldFont);
DeleteObject(hFont); DeleteObject(hFont);
// Create vertex buffer for the letters
if (FAILED(hr = dev->CreateVertexBuffer(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
D3DPOOL_DEFAULT, &m_pVB,NULL)))
{
return hr;
}
return S_OK; return S_OK;
} }
@ -191,13 +189,12 @@ namespace D3D
static DWORD RS_old[6]; static DWORD RS_old[6];
static DWORD TS_old[6]; static DWORD TS_old[6];
static LPDIRECT3DBASETEXTURE9 texture_old; static LPDIRECT3DBASETEXTURE9 texture_old;
static DWORD FVF_old;
static LPDIRECT3DVERTEXDECLARATION9 decl_old;
static LPDIRECT3DPIXELSHADER9 ps_old; static LPDIRECT3DPIXELSHADER9 ps_old;
static LPDIRECT3DVERTEXSHADER9 vs_old; static LPDIRECT3DVERTEXSHADER9 vs_old;
void SaveRenderStates() void SaveRenderStates()
{ {
// TODO: Get rid of these Gets so we can potentially switch to Pure Device
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
dev->GetRenderState((_D3DRENDERSTATETYPE)RS[i][0], &(RS_old[i])); dev->GetRenderState((_D3DRENDERSTATETYPE)RS[i][0], &(RS_old[i]));
@ -206,8 +203,20 @@ namespace D3D
dev->GetTexture(0, &texture_old); dev->GetTexture(0, &texture_old);
dev->GetPixelShader(&ps_old); dev->GetPixelShader(&ps_old);
dev->GetVertexShader(&vs_old); dev->GetVertexShader(&vs_old);
dev->GetVertexDeclaration(&decl_old); }
dev->GetFVF(&FVF_old);
void RestoreRenderStates()
{
D3D::SetTexture(0, texture_old);
dev->SetPixelShader(ps_old);
dev->SetVertexShader(vs_old);
for (int i = 0; i < 6; i++)
{
D3D::SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
D3D::SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
}
} }
void CD3DFont::SetRenderStates() void CD3DFont::SetRenderStates()
@ -226,24 +235,12 @@ namespace D3D
} }
} }
void RestoreRenderStates()
{
D3D::SetTexture(0, texture_old);
dev->SetPixelShader(ps_old);
dev->SetVertexShader(vs_old);
dev->SetFVF(FVF_old);
for (int i = 0; i < 6; i++)
{
D3D::SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
D3D::SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
}
}
int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText, bool center) int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText, bool center)
{ {
if (!m_pVB)
return 0;
SaveRenderStates(); SaveRenderStates();
SetRenderStates(); SetRenderStates();
dev->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX)); dev->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
@ -283,10 +280,10 @@ namespace D3D
float w = (tx2-tx1)*m_dwTexWidth; float w = (tx2-tx1)*m_dwTexWidth;
w *= (fXScale*vpHeight)*invLineHeight; w *= (fXScale*vpHeight)*invLineHeight;
mx += w + spacing*fXScale*vpWidth; mx += w + spacing*fXScale*vpWidth;
if (mx>maxx) maxx=mx; if (mx > maxx) maxx = mx;
} }
float offset=-maxx/2; float offset = -maxx/2;
strText = oldstrText; strText = oldstrText;
//Then let's draw it //Then let's draw it
if (center) if (center)
@ -295,10 +292,10 @@ namespace D3D
fStartX+=offset; fStartX+=offset;
} }
float wScale=(fXScale*vpHeight)*invLineHeight; float wScale = (fXScale*vpHeight)*invLineHeight;
float hScale=(fYScale*vpHeight)*invLineHeight; float hScale = (fYScale*vpHeight)*invLineHeight;
while(*strText) while (*strText)
{ {
char c = *strText++; char c = *strText++;
@ -322,28 +319,24 @@ namespace D3D
w *= wScale; w *= wScale;
h *= hScale; h *= hScale;
FONT2DVERTEX v[6]; FONT2DVERTEX v[6];
v[0]=InitFont2DVertex(sx, sy+h, dwColor, tx1, ty2); v[0] = InitFont2DVertex(sx, sy+h, dwColor, tx1, ty2);
v[1]=InitFont2DVertex(sx, sy, dwColor, tx1, ty1); v[1] = InitFont2DVertex(sx, sy, dwColor, tx1, ty1);
v[2]=InitFont2DVertex(sx+w, sy+h, dwColor, tx2, ty2); v[2] = InitFont2DVertex(sx+w, sy+h, dwColor, tx2, ty2);
v[3]=InitFont2DVertex(sx+w, sy, dwColor, tx2, ty1); v[3] = InitFont2DVertex(sx+w, sy, dwColor, tx2, ty1);
v[4]=v[2]; v[4] = v[2];
v[5]=v[1]; v[5] = v[1];
memcpy(pVertices,v,6*sizeof(FONT2DVERTEX)); memcpy(pVertices, v, 6*sizeof(FONT2DVERTEX));
pVertices+=6; pVertices+=6;
dwNumTriangles += 2; dwNumTriangles += 2;
if (dwNumTriangles * 3 > (MAX_NUM_VERTICES-6)) if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6))
{ {
// Unlock, render, and relock the vertex buffer // Unlock, render, and relock the vertex buffer
m_pVB->Unlock(); m_pVB->Unlock();
// dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles); dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
dwNumTriangles = 0; dwNumTriangles = 0;
} }
@ -354,10 +347,7 @@ namespace D3D
// Unlock and render the vertex buffer // Unlock and render the vertex buffer
m_pVB->Unlock(); m_pVB->Unlock();
if (dwNumTriangles > 0) if (dwNumTriangles > 0)
{
// dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles); dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
}
RestoreRenderStates(); RestoreRenderStates();
return S_OK; return S_OK;
} }

View File

@ -298,7 +298,7 @@ void DX9Debugger_Pause_Count_N(PauseEvent event,bool update)
if (update) if (update)
{ {
D3D::EndFrame(); D3D::EndFrame();
D3D::BeginFrame(false, 0x00000000, 1.0f); D3D::BeginFrame();
} }
DX9DebuggerCheckAndPause(); DX9DebuggerCheckAndPause();
} }

View File

@ -86,17 +86,34 @@ struct TabDirect3D : public W32Util::Tab
CheckDlgButton(hDlg, IDC_FULLSCREENENABLE, g_Config.bFullscreen ? TRUE : FALSE); CheckDlgButton(hDlg, IDC_FULLSCREENENABLE, g_Config.bFullscreen ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_VSYNC, g_Config.bVsync ? TRUE : FALSE); CheckDlgButton(hDlg, IDC_VSYNC, g_Config.bVsync ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_RENDER_TO_MAINWINDOW, g_Config.RenderToMainframe ? TRUE : FALSE); CheckDlgButton(hDlg, IDC_RENDER_TO_MAINWINDOW, g_Config.RenderToMainframe ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_ASPECT_16_9, g_Config.bKeepAR169 ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_ASPECT_4_3, g_Config.bKeepAR43 ? TRUE : FALSE);
CheckDlgButton(hDlg, IDC_WIDESCREEN_HACK, g_Config.bWidescreenHack ? TRUE : FALSE);
} }
void Command(HWND hDlg,WPARAM wParam) void Command(HWND hDlg,WPARAM wParam)
{ {
/*
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case IDC_ASPECT_4_3:
Button_SetCheck(GetDlgItem(hDlg, IDC_ASPECT_16_9), FALSE);
g_Config.bKeepAR43 = Button_GetCheck(GetDlgItem(hDlg, IDC_ASPECT_4_3)) ? true : false;
g_Config.bKeepAR169 = false;
break;
case IDC_ASPECT_16_9:
Button_SetCheck(GetDlgItem(hDlg, IDC_ASPECT_4_3), FALSE);
g_Config.bKeepAR169 = Button_GetCheck(GetDlgItem(hDlg, IDC_ASPECT_16_9)) ? true : false;
g_Config.bKeepAR43 = false;
break;
case IDC_WIDESCREEN_HACK:
g_Config.bWidescreenHack = Button_GetCheck(GetDlgItem(hDlg, IDC_WIDESCREEN_HACK)) ? true : false;
break;
case IDC_WIREFRAME:
g_Config.bWireFrame = Button_GetCheck(GetDlgItem(hDlg,IDC_WIREFRAME)) ? true : false;
break;
default: default:
break; break;
} }
*/
} }
void Apply(HWND hDlg) void Apply(HWND hDlg)
@ -133,9 +150,6 @@ struct TabAdvanced : public W32Util::Tab
Button_SetCheck(GetDlgItem(hDlg,IDC_TEXFMT_OVERLAY), g_Config.bTexFmtOverlayEnable); Button_SetCheck(GetDlgItem(hDlg,IDC_TEXFMT_OVERLAY), g_Config.bTexFmtOverlayEnable);
Button_SetCheck(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), g_Config.bTexFmtOverlayCenter); Button_SetCheck(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), g_Config.bTexFmtOverlayCenter);
Button_GetCheck(GetDlgItem(hDlg,IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), false); Button_GetCheck(GetDlgItem(hDlg,IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), false);
//SetWindowText(GetDlgItem(hDlg,IDC_TEXDUMPPATH),g_Config.texDumpPath.c_str()); <-- Old method
//Edit_LimitText(GetDlgItem(hDlg,IDC_TEXDUMPPATH),255); <-- Old method
} }
void Command(HWND hDlg,WPARAM wParam) void Command(HWND hDlg,WPARAM wParam)
{ {
@ -149,7 +163,7 @@ struct TabAdvanced : public W32Util::Tab
// break; // break;
case IDC_TEXFMT_OVERLAY: case IDC_TEXFMT_OVERLAY:
{ {
Button_GetCheck(GetDlgItem(hDlg,IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), false); Button_GetCheck(GetDlgItem(hDlg, IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), false);
} }
break; break;
default: default:
@ -163,7 +177,6 @@ struct TabAdvanced : public W32Util::Tab
g_Config.bOverlayStats = Button_GetCheck(GetDlgItem(hDlg,IDC_OVERLAYSTATS)) ? true : false; g_Config.bOverlayStats = Button_GetCheck(GetDlgItem(hDlg,IDC_OVERLAYSTATS)) ? true : false;
g_Config.bOverlayProjStats = Button_GetCheck(GetDlgItem(hDlg,IDC_OVERLAYPROJSTATS)) ? true : false; g_Config.bOverlayProjStats = Button_GetCheck(GetDlgItem(hDlg,IDC_OVERLAYPROJSTATS)) ? true : false;
g_Config.bWireFrame = Button_GetCheck(GetDlgItem(hDlg,IDC_WIREFRAME)) ? true : false;
g_Config.bDumpTextures = Button_GetCheck(GetDlgItem(hDlg,IDC_TEXDUMP)) ? true : false; g_Config.bDumpTextures = Button_GetCheck(GetDlgItem(hDlg,IDC_TEXDUMP)) ? true : false;
g_Config.bDumpFrames = Button_GetCheck(GetDlgItem(hDlg,IDC_DUMPFRAMES)) ? true : false; g_Config.bDumpFrames = Button_GetCheck(GetDlgItem(hDlg,IDC_DUMPFRAMES)) ? true : false;
g_Config.bShowShaderErrors = Button_GetCheck(GetDlgItem(hDlg,IDC_SHOWSHADERERRORS)) ? true : false; g_Config.bShowShaderErrors = Button_GetCheck(GetDlgItem(hDlg,IDC_SHOWSHADERERRORS)) ? true : false;
@ -240,7 +253,7 @@ void DlgSettings_Show(HINSTANCE hInstance, HWND _hParent)
#endif #endif
#endif #endif
if(( tfoe != g_Config.bTexFmtOverlayEnable) || if ((tfoe != g_Config.bTexFmtOverlayEnable) ||
((g_Config.bTexFmtOverlayEnable) && ( tfoc != g_Config.bTexFmtOverlayCenter))) ((g_Config.bTexFmtOverlayEnable) && ( tfoc != g_Config.bTexFmtOverlayCenter)))
{ {
TextureCache::Invalidate(false); TextureCache::Invalidate(false);

View File

@ -15,11 +15,18 @@ HINSTANCE m_hInstance = NULL;
WNDCLASSEX wndClass; WNDCLASSEX wndClass;
const TCHAR m_szClassName[] = _T("DolphinEmuWnd"); const TCHAR m_szClassName[] = _T("DolphinEmuWnd");
int g_winstyle; int g_winstyle;
static volatile bool s_sizing;
bool IsSizing()
{
return s_sizing;
}
HWND GetWnd() HWND GetWnd()
{ {
return m_hWnd; return m_hWnd;
} }
HWND GetParentWnd() HWND GetParentWnd()
{ {
return m_hParent; return m_hParent;
@ -38,6 +45,14 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
} }
return 0; return 0;
case WM_ENTERSIZEMOVE:
s_sizing = true;
break;
case WM_EXITSIZEMOVE:
s_sizing = false;
break;
case WM_KEYDOWN: case WM_KEYDOWN:
switch( LOWORD( wParam )) switch( LOWORD( wParam ))
{ {

View File

@ -5,12 +5,15 @@
namespace EmuWindow namespace EmuWindow
{ {
HWND GetWnd();
HWND GetParentWnd(); HWND GetWnd();
HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title); HWND GetParentWnd();
void Show(); HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title);
void Close(); void Show();
void SetSize(int displayWidth, int displayHeight); void Close();
void SetSize(int displayWidth, int displayHeight);
bool IsSizing();
} }
#endif #endif

View File

@ -0,0 +1,55 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "D3DBase.h"
#include "Render.h"
#include "FramebufferManager.h"
namespace FBManager
{
static LPDIRECT3DSURFACE9 s_efb_color_surface;
static LPDIRECT3DSURFACE9 s_efb_depth_surface;
#undef CHECK
#define CHECK(hr) if (FAILED(hr)) { PanicAlert("FAIL: " __FUNCTION__); }
LPDIRECT3DSURFACE9 GetEFBColorRTSurface() { return s_efb_color_surface; }
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface() { return s_efb_depth_surface; }
void Create()
{
// Simplest possible setup to start with.
int target_width = Renderer::GetTargetWidth();
int target_height = Renderer::GetTargetHeight();
HRESULT hr = D3D::dev->CreateRenderTarget(target_width, target_height, D3DFMT_A8R8G8B8,
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_color_surface, NULL);
CHECK(hr);
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D24S8,
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
CHECK(hr);
}
void Destroy()
{
s_efb_depth_surface->Release();
s_efb_depth_surface = NULL;
s_efb_color_surface->Release();
s_efb_color_surface = NULL;
}
} // namespace

View File

@ -0,0 +1,60 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _FRAMEBUFFERMANAGER_D3D_H_
#define _FRAMEBUFFERMANAGER_D3D_H_
#include <list>
#include "D3DBase.h"
namespace FBManager
{
void Create();
void Destroy();
// To get the EFB in texture form, these functions may have to transfer
// the EFB to a resolved texture first.
LPDIRECT3DTEXTURE9 GetEFBColorTexture(const EFBRectangle& sourceRc);
LPDIRECT3DTEXTURE9 GetEFBDepthTexture(const EFBRectangle& sourceRc);
LPDIRECT3DSURFACE9 GetEFBColorRTSurface();
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface();
/*
// Resolved framebuffer is only used in MSAA mode.
LPDIRECT3DTEXTURE9 GetResolvedFramebuffer() const { return m_resolvedFramebuffer; }
TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) const;
void SetFramebuffer(LPDIRECT3DSURFACE9 surface);
// If in MSAA mode, this will perform a resolve of the specified rectangle, and return the resolve target as a texture ID.
// Thus, this call may be expensive. Don't repeat it unnecessarily.
// If not in MSAA mode, will just return the render target texture ID.
// After calling this, before you render anything else, you MUST bind the framebuffer you want to draw to.
LPDIRECT3DTEXTURE9 ResolveAndGetRenderTarget(const EFBRectangle &rect);
// Same as above but for the depth Target.
// After calling this, before you render anything else, you MUST bind the framebuffer you want to draw to.
LPDIRECT3DTEXTURE9 ResolveAndGetDepthTarget(const EFBRectangle &rect);
*/
};
#endif

View File

@ -63,19 +63,24 @@ void SetPSConstant4fv(int const_number, const float *f)
void PixelShaderCache::Init() void PixelShaderCache::Init()
{ {
//memset(lastPSconstants,0xFF,(C_COLORMATRIX+16)*4*sizeof(float)); // why does this not work Clear();
//memset(lastPSconstants,0xFF,sizeof(lastPSconstants));
for( int i=0;i<(C_COLORMATRIX+16)*4;i++)
lastPSconstants[i/4][i%4] = -100000000.0f;
memset(&last_pixel_shader_uid,0xFF,sizeof(last_pixel_shader_uid));
} }
void PixelShaderCache::Shutdown() void PixelShaderCache::Clear()
{ {
PSCache::iterator iter = PixelShaders.begin(); PSCache::iterator iter = PixelShaders.begin();
for (; iter != PixelShaders.end(); iter++) for (; iter != PixelShaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
PixelShaders.clear(); PixelShaders.clear();
for (int i = 0; i < (C_COLORMATRIX + 16) * 4; i++)
lastPSconstants[i/4][i%4] = -100000000.0f;
memset(&last_pixel_shader_uid, 0xFF, sizeof(last_pixel_shader_uid));
}
void PixelShaderCache::Shutdown()
{
Clear();
} }
bool PixelShaderCache::SetShader(bool dstAlpha) bool PixelShaderCache::SetShader(bool dstAlpha)
@ -86,7 +91,8 @@ bool PixelShaderCache::SetShader(bool dstAlpha)
GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), dstAlpha); GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), dstAlpha);
if (uid == last_pixel_shader_uid) if (uid == last_pixel_shader_uid)
{ {
if (PixelShaders[uid].shader) PSCache::const_iterator iter = PixelShaders.find(uid);
if (iter != PixelShaders.end() && iter->second.shader)
return true; return true;
else else
return false; return false;
@ -129,7 +135,6 @@ bool PixelShaderCache::SetShader(bool dstAlpha)
INCSTAT(stats.numPixelShadersCreated); INCSTAT(stats.numPixelShadersCreated);
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size()); SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
if (shader) if (shader)
{ {
D3D::dev->SetPixelShader(shader); D3D::dev->SetPixelShader(shader);

View File

@ -44,6 +44,7 @@ private:
{ {
if (shader) if (shader)
shader->Release(); shader->Release();
shader = NULL;
} }
}; };
@ -55,6 +56,7 @@ private:
public: public:
static void Init(); static void Init();
static void Cleanup(); static void Cleanup();
static void Clear();
static void Shutdown(); static void Shutdown();
static bool SetShader(bool dstAlpha); static bool SetShader(bool dstAlpha);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)

View File

@ -33,17 +33,19 @@
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "VertexShaderCache.h" #include "VertexShaderCache.h"
#include "PixelShaderCache.h" #include "PixelShaderCache.h"
#include "VertexLoaderManager.h"
#include "TextureCache.h" #include "TextureCache.h"
#include "Utils.h" #include "Utils.h"
#include "EmuWindow.h" #include "EmuWindow.h"
#include "AVIDump.h" #include "AVIDump.h"
#include "OnScreenDisplay.h" #include "OnScreenDisplay.h"
#include "FramebufferManager.h"
#include "Fifo.h" #include "Fifo.h"
#include "debugger/debugger.h" #include "debugger/debugger.h"
static int s_targetWidth; static int s_target_width;
static int s_targetHeight; static int s_target_height;
static int s_backbuffer_width; static int s_backbuffer_width;
static int s_backbuffer_height; static int s_backbuffer_height;
@ -60,23 +62,46 @@ static bool s_AVIDumping;
#define NUMWNDRES 6 #define NUMWNDRES 6
extern int g_Res[NUMWNDRES][2]; extern int g_Res[NUMWNDRES][2];
void SetupDeviceObjects()
{
D3D::font.Init();
VertexLoaderManager::Init();
FBManager::Create();
}
// Kill off all POOL_DEFAULT device objects.
void TeardownDeviceObjects()
{
FBManager::Destroy();
D3D::font.Shutdown();
TextureCache::Invalidate(false);
VertexManager::DestroyDeviceObjects();
VertexLoaderManager::Shutdown();
VertexShaderCache::Clear();
PixelShaderCache::Clear();
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface());
}
bool Renderer::Init() bool Renderer::Init()
{ {
UpdateActiveConfig(); UpdateActiveConfig();
EmuWindow::SetSize(g_Res[g_ActiveConfig.iWindowedRes][0], g_Res[g_ActiveConfig.iWindowedRes][1]); EmuWindow::SetSize(g_Res[g_ActiveConfig.iWindowedRes][0], g_Res[g_ActiveConfig.iWindowedRes][1]);
int backbuffer_ms_mode = g_ActiveConfig.iMultisampleMode; int backbuffer_ms_mode = 0; // g_ActiveConfig.iMultisampleMode;
D3D::Create(g_ActiveConfig.iAdapter, EmuWindow::GetWnd(), g_ActiveConfig.bFullscreen, D3D::Create(g_ActiveConfig.iAdapter, EmuWindow::GetWnd(), g_ActiveConfig.bFullscreen,
g_ActiveConfig.iFSResolution, backbuffer_ms_mode); g_ActiveConfig.iFSResolution, backbuffer_ms_mode);
s_targetWidth = D3D::GetDisplayWidth(); s_backbuffer_width = D3D::GetBackBufferWidth();
s_targetHeight = D3D::GetDisplayHeight(); s_backbuffer_height = D3D::GetBackBufferHeight();
s_backbuffer_width = s_targetWidth; // TODO: Grab target width from configured resolution?
s_backbuffer_height = s_targetHeight; s_target_width = s_backbuffer_width * EFB_WIDTH / 640;
s_target_height = s_backbuffer_height * EFB_HEIGHT / 480;
xScale = (float)s_targetWidth / (float)EFB_WIDTH; xScale = (float)s_target_width / (float)EFB_WIDTH;
yScale = (float)s_targetHeight / (float)EFB_HEIGHT; yScale = (float)s_target_height / (float)EFB_HEIGHT;
s_LastFrameDumped = false; s_LastFrameDumped = false;
s_AVIDumping = false; s_AVIDumping = false;
@ -87,18 +112,26 @@ bool Renderer::Init()
D3DXMatrixIdentity(&mtx); D3DXMatrixIdentity(&mtx);
D3D::dev->SetTransform(D3DTS_VIEW, &mtx); D3D::dev->SetTransform(D3DTS_VIEW, &mtx);
D3D::dev->SetTransform(D3DTS_WORLD, &mtx); D3D::dev->SetTransform(D3DTS_WORLD, &mtx);
D3D::font.Init();
SetupDeviceObjects();
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16); D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
D3D::BeginFrame(true, 0, 1.0f); D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0x0, 1.0f, 0);
D3D::BeginFrame();
return true; return true;
} }
void Renderer::Shutdown() void Renderer::Shutdown()
{ {
D3D::font.Shutdown(); TeardownDeviceObjects();
D3D::EndFrame(); D3D::EndFrame();
D3D::Close(); D3D::Close();
@ -108,14 +141,10 @@ void Renderer::Shutdown()
} }
} }
float Renderer::GetTargetScaleX() int Renderer::GetTargetWidth() { return s_target_width; }
{ int Renderer::GetTargetHeight() { return s_target_height; }
return xScale; float Renderer::GetTargetScaleX() { return xScale; }
} float Renderer::GetTargetScaleY() { return yScale; }
float Renderer::GetTargetScaleY()
{
return yScale;
}
void Renderer::RenderText(const char *text, int left, int top, u32 color) void Renderer::RenderText(const char *text, int left, int top, u32 color)
{ {
@ -135,10 +164,10 @@ void dumpMatrix(D3DXMATRIX &mtx)
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc) TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
{ {
TargetRectangle result; TargetRectangle result;
result.left = (rc.left * s_targetWidth) / EFB_WIDTH; result.left = (rc.left * s_target_width) / EFB_WIDTH;
result.top = (rc.top * s_targetHeight) / EFB_HEIGHT; result.top = (rc.top * s_target_height) / EFB_HEIGHT;
result.right = (rc.right * s_targetWidth) / EFB_WIDTH; result.right = (rc.right * s_target_width) / EFB_WIDTH;
result.bottom = (rc.bottom * s_targetHeight) / EFB_HEIGHT; result.bottom = (rc.bottom * s_target_height) / EFB_HEIGHT;
return result; return result;
} }
@ -156,14 +185,14 @@ void formatBufferDump(const char *in, char *out, int w, int h, int p)
} }
} }
void Renderer::SwapBuffers() void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc)
{ {
if (g_bSkipCurrentFrame) if (g_bSkipCurrentFrame)
return; return;
// Center window again.
if (EmuWindow::GetParentWnd()) if (EmuWindow::GetParentWnd())
{ {
// Re-stretch window to parent window size again, if it has a parent window.
RECT rcWindow; RECT rcWindow;
GetWindowRect(EmuWindow::GetParentWnd(), &rcWindow); GetWindowRect(EmuWindow::GetParentWnd(), &rcWindow);
@ -173,7 +202,7 @@ void Renderer::SwapBuffers()
::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE); ::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE);
} }
// Frame dumping routine // Frame dumping routine - seems buggy and wrong, esp. regarding buffer sizes
if (g_ActiveConfig.bDumpFrames) { if (g_ActiveConfig.bDumpFrames) {
D3DDISPLAYMODE DisplayMode; D3DDISPLAYMODE DisplayMode;
if (SUCCEEDED(D3D::dev->GetDisplayMode(0, &DisplayMode))) { if (SUCCEEDED(D3D::dev->GetDisplayMode(0, &DisplayMode))) {
@ -214,7 +243,7 @@ void Renderer::SwapBuffers()
} }
else else
{ {
if(s_LastFrameDumped && s_AVIDumping) { if (s_LastFrameDumped && s_AVIDumping) {
AVIDump::Stop(); AVIDump::Stop();
s_AVIDumping = false; s_AVIDumping = false;
} }
@ -222,6 +251,18 @@ void Renderer::SwapBuffers()
s_LastFrameDumped = false; s_LastFrameDumped = false;
} }
D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface());
D3D::dev->SetDepthStencilSurface(NULL);
// Blit our render target onto the backbuffer.
// TODO: Change to a quad so we can do post processing.
TargetRectangle src_rect, dst_rect;
src_rect = ConvertEFBRectangle(sourceRc);
ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect);
D3D::dev->StretchRect(FBManager::GetEFBColorRTSurface(), src_rect.AsRECT(),
D3D::GetBackBufferSurface(), dst_rect.AsRECT(),
D3DTEXF_LINEAR);
char st[8192]; char st[8192];
// Finish up the current frame, print some stats // Finish up the current frame, print some stats
if (g_ActiveConfig.bOverlayStats) if (g_ActiveConfig.bOverlayStats)
@ -237,20 +278,6 @@ void Renderer::SwapBuffers()
} }
OSD::DrawMessages(); OSD::DrawMessages();
#if defined(DVPROFILE)
if (g_bWriteProfile) {
//g_bWriteProfile = 0;
static int framenum = 0;
const int UPDATE_FRAMES = 8;
if (++framenum >= UPDATE_FRAMES) {
DVProfWrite("prof.txt", UPDATE_FRAMES);
DVProfClear();
framenum = 0;
}
}
#endif
D3D::EndFrame(); D3D::EndFrame();
DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_FRAME); DEBUGGER_PAUSE_COUNT_N_WITHOUT_UPDATE(NEXT_FRAME);
@ -265,53 +292,57 @@ void Renderer::SwapBuffers()
// Make any new configuration settings active. // Make any new configuration settings active.
UpdateActiveConfig(); UpdateActiveConfig();
/* // TODO: Resize backbuffer if window size has changed. This code crashes, debug it.
TODO: Resize backbuffer if window size has changed. This code crashes, debug it.
while (EmuWindow::IsSizing())
{
Sleep(10);
}
RECT rcWindow; RECT rcWindow;
GetClientRect(EmuWindow::GetWnd(), &rcWindow); GetClientRect(EmuWindow::GetWnd(), &rcWindow);
if (rcWindow.right - rcWindow.left != s_backbuffer_width || if (rcWindow.right - rcWindow.left != s_backbuffer_width ||
rcWindow.bottom - rcWindow.top != s_backbuffer_height) rcWindow.bottom - rcWindow.top != s_backbuffer_height)
{ {
D3D::Reset(); TeardownDeviceObjects();
s_backbuffer_width = D3D::GetDisplayWidth();
s_backbuffer_height = D3D::GetDisplayHeight();
}
*/
//Begin new frame D3D::Reset();
//Set default viewport and scissor, for the clear to work correctly
SetupDeviceObjects();
s_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight();
}
g_VideoInitialize.pCopiedToXFB(false);
// Begin new frame
// Set default viewport and scissor, for the clear to work correctly
stats.ResetFrame(); stats.ResetFrame();
// u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
D3D::BeginFrame();
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 1.0f, 0);
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
D3DVIEWPORT9 vp; D3DVIEWPORT9 vp;
vp.X = 0; vp.X = 0;
vp.Y = 0; vp.Y = 0;
vp.Width = (DWORD)s_targetWidth; vp.Width = (DWORD)s_target_width;
vp.Height = (DWORD)s_targetHeight; vp.Height = (DWORD)s_target_height;
vp.MinZ = 0; vp.MinZ = 0;
vp.MaxZ = 1.0f; vp.MaxZ = 1.0f;
D3D::dev->SetViewport(&vp); D3D::dev->SetViewport(&vp);
RECT rc; RECT rc;
rc.left = 0; rc.left = 0;
rc.top = 0; rc.top = 0;
rc.right = (LONG)s_targetWidth; rc.right = (LONG)s_target_width;
rc.bottom = (LONG)s_targetHeight; rc.bottom = (LONG)s_target_height;
D3D::dev->SetScissorRect(&rc); D3D::dev->SetScissorRect(&rc);
D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false); D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
// We probably shouldn't clear here.
// D3D::dev->Clear(0, 0, D3DCLEAR_TARGET, 0x00000000, 0, 0);
u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
D3D::BeginFrame(false, clearColor, 1.0f);
// This probably causes problems, and the visual difference is tiny anyway.
// So let's keep it commented out.
// D3D::EnableAlphaToCoverage();
UpdateViewport(); UpdateViewport();
if (g_ActiveConfig.bOldCard)
D3D::font.SetRenderStates(); //compatibility with low end cards
} }
bool Renderer::SetScissorRect() bool Renderer::SetScissorRect()
@ -328,6 +359,12 @@ bool Renderer::SetScissorRect()
rc.top = (int)(rc.top * yScale); rc.top = (int)(rc.top * yScale);
rc.right = (int)(rc.right * xScale); rc.right = (int)(rc.right * xScale);
rc.bottom = (int)(rc.bottom * yScale); rc.bottom = (int)(rc.bottom * yScale);
if (rc.left < 0) rc.left = 0;
if (rc.right > s_target_width) rc.right = s_target_width;
if (rc.top < 0) rc.top = 0;
if (rc.bottom > s_target_height) rc.bottom = s_target_height;
if (rc.right >= rc.left && rc.bottom >= rc.top) if (rc.right >= rc.left && rc.bottom >= rc.top)
{ {
D3D::dev->SetScissorRect(&rc); D3D::dev->SetScissorRect(&rc);
@ -422,14 +459,13 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
// and perhaps blending. // and perhaps blending.
// WARN_LOG(VIDEOINTERFACE, "This is probably some kind of software rendering"); // WARN_LOG(VIDEOINTERFACE, "This is probably some kind of software rendering");
break; break;
} }
return 0; return 0;
} }
// mtx.m[0][3] = pMatrix[1]; // -0.5f/s_targetWidth; <-- fix d3d pixel center? // mtx.m[0][3] = pMatrix[1]; // -0.5f/s_target_width; <-- fix d3d pixel center?
// mtx.m[1][3] = pMatrix[3]; // +0.5f/s_targetHeight; <-- fix d3d pixel center? // mtx.m[1][3] = pMatrix[3]; // +0.5f/s_target_height; <-- fix d3d pixel center?
// Called from VertexShaderManager // Called from VertexShaderManager
void UpdateViewport() void UpdateViewport()
@ -452,5 +488,9 @@ void UpdateViewport()
vp.MinZ = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777215.0f; vp.MinZ = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777215.0f;
vp.MaxZ = xfregs.rawViewport[5] / 16777215.0f; vp.MaxZ = xfregs.rawViewport[5] / 16777215.0f;
// This seems to happen a lot - the above calc is probably wrong.
if (vp.MinZ < 0.0f) vp.MinZ = 0.0f;
if (vp.MaxZ > 1.0f) vp.MaxZ = 1.0f;
D3D::dev->SetViewport(&vp); D3D::dev->SetViewport(&vp);
} }

View File

@ -27,6 +27,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "D3DTexture.h" #include "D3DTexture.h"
#include "FramebufferManager.h"
#include "Render.h" #include "Render.h"
@ -104,8 +105,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width,
{ {
if (address == 0) if (address == 0)
return NULL; return NULL;
u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address); u8 *ptr = g_VideoInitialize.pGetMemoryPointer(address);
int palSize = TexDecoder_GetPaletteSize(format); int palSize = TexDecoder_GetPaletteSize(format);
@ -323,7 +323,7 @@ have_texture:
LPDIRECT3DSURFACE9 srcSurface, destSurface; LPDIRECT3DSURFACE9 srcSurface, destSurface;
tex->GetSurfaceLevel(0, &destSurface); tex->GetSurfaceLevel(0, &destSurface);
srcSurface = D3D::GetBackBufferSurface(); srcSurface = FBManager::GetEFBColorRTSurface();
D3D::dev->StretchRect(srcSurface, &source_rc, destSurface, &dest_rc, D3DTEXF_LINEAR); D3D::dev->StretchRect(srcSurface, &source_rc, destSurface, &dest_rc, D3DTEXF_LINEAR);
destSurface->Release(); destSurface->Release();
} }

View File

@ -30,6 +30,9 @@ void Shutdown();
void AddVertices(int _primitive, int _numVertices); void AddVertices(int _primitive, int _numVertices);
void Flush(); void Flush();
void CreateDeviceObjects();
void DestroyDeviceObjects();
} // namespace } // namespace
#endif #endif

View File

@ -94,19 +94,24 @@ void SetMultiVSConstant4fv(int const_number, int count, const float *f)
void VertexShaderCache::Init() void VertexShaderCache::Init()
{ {
//memset(lastVSconstants,0xFF,(C_FOGPARAMS+8)*4*sizeof(float)); // why does this not work Clear();
//memset(lastVSconstants,0xFF,sizeof(lastVSconstants)); }
for( int i=0;i<(C_FOGPARAMS+8)*4;i++)
lastVSconstants[i/4][i%4] = -100000000.0f; void VertexShaderCache::Clear()
memset(&last_vertex_shader_uid,0xFF,sizeof(last_vertex_shader_uid)); {
VSCache::iterator iter = vshaders.begin();
for (; iter != vshaders.end(); ++iter)
iter->second.Destroy();
vshaders.clear();
for (int i = 0; i < (C_FOGPARAMS + 8) * 4; i++)
lastVSconstants[i / 4][i % 4] = -100000000.0f;
memset(&last_vertex_shader_uid, 0xFF, sizeof(last_vertex_shader_uid));
} }
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
{ {
VSCache::iterator iter = vshaders.begin(); Clear();
for (; iter != vshaders.end(); iter++)
iter->second.Destroy();
vshaders.clear();
} }
bool VertexShaderCache::SetShader(u32 components) bool VertexShaderCache::SetShader(u32 components)

View File

@ -41,6 +41,7 @@ private:
{ {
if (shader) if (shader)
shader->Release(); shader->Release();
shader = NULL;
} }
}; };
@ -51,6 +52,7 @@ private:
public: public:
static void Init(); static void Init();
static void Clear();
static void Cleanup(); static void Cleanup();
static void Shutdown(); static void Shutdown();
static bool SetShader(u32 components); static bool SetShader(u32 components);

View File

@ -61,7 +61,7 @@ GFXDebuggerDX9 *m_DebuggerFrame = NULL;
HINSTANCE g_hInstance = NULL; HINSTANCE g_hInstance = NULL;
SVideoInitialize g_VideoInitialize; SVideoInitialize g_VideoInitialize;
PLUGIN_GLOBALS* globals = NULL; PLUGIN_GLOBALS* globals = NULL;
int initCount = 0; bool s_initialized;
static u32 s_efbAccessRequested = FALSE; static u32 s_efbAccessRequested = FALSE;
@ -173,57 +173,6 @@ void UpdateFPSDisplay(const char *text)
SetWindowTextA(EmuWindow::GetWnd(), temp); SetWindowTextA(EmuWindow::GetWnd(), temp);
} }
bool Init()
{
g_Config.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
g_Config.GameIniLoad(globals->game_ini);
UpdateProjectionHack(g_Config.iPhackvalue); // DX9 projection hack could be disabled by commenting out this line
if (initCount == 0)
{
// create the window
if (!g_Config.RenderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
{
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, _T("Loading - Please wait."));
}
else
{
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, _T("Loading - Please wait."));
}
if (g_VideoInitialize.pWindowHandle == NULL)
{
MessageBox(GetActiveWindow(), _T("An error has occurred while trying to create the window."), _T("Fatal Error"), MB_OK);
return false;
}
EmuWindow::Show();
g_VideoInitialize.pPeekMessages = Callback_PeekMessages;
g_VideoInitialize.pUpdateFPSDisplay = UpdateFPSDisplay;
if (FAILED(D3D::Init()))
{
MessageBox(GetActiveWindow(), _T("Unable to initialize Direct3D. Please make sure that you have DirectX 9.0c correctly installed."), _T("Fatal Error"), MB_OK);
return false;
}
InitXFBConvTables();
}
initCount++;
return true;
}
void DeInit()
{
initCount--;
if (initCount == 0)
{
D3D::Shutdown();
EmuWindow::Close();
}
}
void GetDllInfo (PLUGIN_INFO* _PluginInfo) void GetDllInfo (PLUGIN_INFO* _PluginInfo)
{ {
_PluginInfo->Version = 0x0100; _PluginInfo->Version = 0x0100;
@ -252,15 +201,9 @@ void DllAbout(HWND _hParent)
void DllConfig(HWND _hParent) void DllConfig(HWND _hParent)
{ {
// If not initialized, only init D3D so we can enumerate resolutions. // If not initialized, only init D3D so we can enumerate resolutions.
if (initCount == 0) if (!s_initialized) D3D::Init();
{
D3D::Init();
}
DlgSettings_Show(g_hInstance, _hParent); DlgSettings_Show(g_hInstance, _hParent);
if (initCount == 0) if (!s_initialized) D3D::Shutdown();
{
D3D::Shutdown();
}
} }
void Initialize(void *init) void Initialize(void *init)
@ -268,15 +211,38 @@ void Initialize(void *init)
SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init; SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init;
frameCount = 0; frameCount = 0;
g_VideoInitialize = *_pVideoInitialize; g_VideoInitialize = *_pVideoInitialize;
Init();
g_Config.Load(FULL_CONFIG_DIR "gfx_dx9.ini");
g_Config.GameIniLoad(globals->game_ini);
UpdateProjectionHack(g_Config.iPhackvalue); // DX9 projection hack could be disabled by commenting out this line
// create the window
if (!g_Config.RenderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, _T("Loading - Please wait."));
else
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, _T("Loading - Please wait."));
if (g_VideoInitialize.pWindowHandle == NULL)
{
ERROR_LOG(VIDEO, "An error has occurred while trying to create the window.");
return;
}
EmuWindow::Show();
g_VideoInitialize.pPeekMessages = Callback_PeekMessages;
g_VideoInitialize.pUpdateFPSDisplay = UpdateFPSDisplay;
if (FAILED(D3D::Init()))
{
MessageBox(GetActiveWindow(), _T("Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed."), _T("Fatal Error"), MB_OK);
return;
}
InitXFBConvTables();
OSD::AddMessage("Dolphin Direct3D9 Video Plugin.", 5000);
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages; _pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay; _pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle; _pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
s_initialized = true;
OSD::AddMessage("Dolphin Direct3D9 Video Plugin.", 5000);
} }
void Video_Prepare(void) void Video_Prepare()
{ {
Renderer::Init(); Renderer::Init();
TextureCache::Init(); TextureCache::Init();
@ -291,19 +257,23 @@ void Video_Prepare(void)
PixelShaderManager::Init(); PixelShaderManager::Init();
} }
void Shutdown(void) void Shutdown()
{ {
s_efbAccessRequested = FALSE;
Fifo_Shutdown(); Fifo_Shutdown();
OpcodeDecoder_Shutdown();
VertexManager::Shutdown(); VertexManager::Shutdown();
VertexShaderManager::Shutdown();
VertexLoaderManager::Shutdown(); VertexLoaderManager::Shutdown();
VertexShaderCache::Shutdown(); VertexShaderCache::Shutdown();
VertexShaderManager::Shutdown();
PixelShaderCache::Shutdown(); PixelShaderCache::Shutdown();
PixelShaderManager::Shutdown(); PixelShaderManager::Shutdown();
TextureCache::Shutdown(); TextureCache::Shutdown();
OpcodeDecoder_Shutdown();
Renderer::Shutdown(); Renderer::Shutdown();
DeInit(); D3D::Shutdown();
EmuWindow::Close();
s_initialized = false;
} }
void DoState(unsigned char **ptr, int mode) { void DoState(unsigned char **ptr, int mode) {

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,24 @@
// //
#include "resource.h" #include "resource.h"
#include <windows.h> #include <windows.h>
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Dialog // Dialog
@ -18,23 +36,27 @@ BEGIN
LTEXT "Will not work correctly on older GPU:s.",IDC_STATIC,7,47,170,8 LTEXT "Will not work correctly on older GPU:s.",IDC_STATIC,7,47,170,8
END END
IDD_SETTINGS DIALOGEX 0, 0, 231, 141 IDD_SETTINGS DIALOGEX 0, 0, 231, 174
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 0, 0, 0x0 FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN BEGIN
LTEXT "&Graphics card:",IDC_STATIC,7,9,61,8 LTEXT "&Graphics card:",IDC_STATIC,7,9,61,8
COMBOBOX IDC_ADAPTER,68,7,156,84,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_ADAPTER,68,7,156,84,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "&Fullscreen",IDC_FULLSCREENENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,25,141,8 CONTROL "&Fullscreen",IDC_FULLSCREENENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,25,56,8
CONTROL "&V-Sync",IDC_VSYNC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,38,141,8 CONTROL "&V-Sync",IDC_VSYNC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,38,141,8
CONTROL "&Render to main window",IDC_RENDER_TO_MAINWINDOW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,50,141,8 CONTROL "&Render to main window",IDC_RENDER_TO_MAINWINDOW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,50,141,8
LTEXT "Full&screen resolution:",IDC_STATIC,7,63,69,8 LTEXT "Full&screen resolution:",IDC_STATIC,7,98,69,8
COMBOBOX IDC_RESOLUTION,87,62,137,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_RESOLUTION,87,98,137,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Windowed resolution:",IDC_STATIC,7,82,74,8 LTEXT "&Windowed resolution:",IDC_STATIC,7,117,74,8
COMBOBOX IDC_RESOLUTIONWINDOWED,87,81,137,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_RESOLUTIONWINDOWED,87,116,137,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Rotate windowed mode 90 degrees (for &Ikaruga)",IDC_CHECK1, CONTROL "Rotate windowed mode 90 degrees (for &Ikaruga)",IDC_CHECK1,
"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_DISABLED | WS_TABSTOP,87,97,137,17 "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_DISABLED | WS_TABSTOP,87,132,137,17
LTEXT "&Anti-alias mode:",IDC_STATIC,7,122,61,8 LTEXT "&Anti-alias mode:",IDC_STATIC,7,157,61,8
COMBOBOX IDC_ANTIALIASMODE,68,121,156,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_ANTIALIASMODE,68,155,156,73,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Aspect Ratio:",IDC_STATIC,7,66,52,8
CONTROL "4:3",IDC_ASPECT_4_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,66,59,11
CONTROL "16:9",IDC_ASPECT_16_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,68,80,49,11
CONTROL "&Widescreen Hack",IDC_WIDESCREEN_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,128,81,73,10
END END
IDD_DEBUGGER DIALOGEX 0, 0, 234, 254 IDD_DEBUGGER DIALOGEX 0, 0, 234, 254
@ -57,36 +79,27 @@ BEGIN
GROUPBOX "&Settings",IDC_STATIC,7,7,192,81 GROUPBOX "&Settings",IDC_STATIC,7,7,192,81
CONTROL "&Wireframe",IDC_WIREFRAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,19,79,9 CONTROL "&Wireframe",IDC_WIREFRAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,19,79,9
CONTROL "&Overlay some statistics",IDC_OVERLAYSTATS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,31,88,9 CONTROL "&Overlay some statistics",IDC_OVERLAYSTATS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,31,88,9
CONTROL "Overlay &Projection Statistics",IDC_OVERLAYPROJSTATS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,42,118,9 CONTROL "Overlay &Projection Statistics",IDC_OVERLAYPROJSTATS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,42,118,9
CONTROL "Show s&hader compilation errors",IDC_SHOWSHADERERRORS, CONTROL "Show s&hader compilation errors",IDC_SHOWSHADERERRORS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,53,127,9 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,53,127,9
GROUPBOX "&Data dumping",IDC_STATIC,7,91,192,42 GROUPBOX "&Data dumping",IDC_STATIC,7,91,192,42
CONTROL "Dump &textures",IDC_TEXDUMP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,104,70,9 CONTROL "Dump &textures",IDC_TEXDUMP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,104,70,9
// EDITTEXT IDC_TEXDUMPPATH,25,116,148,12,ES_AUTOHSCROLL
// PUSHBUTTON "...",IDC_BROWSETEXDUMPPATH,176,116,14,13
CONTROL "Dump Frames to User/Dump/Frames",IDC_DUMPFRAMES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,116,138,9 CONTROL "Dump Frames to User/Dump/Frames",IDC_DUMPFRAMES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,116,138,9
GROUPBOX "Texture Format Overlay",IDC_STATIC,7,136,192,30 GROUPBOX "Texture Format Overlay",IDC_STATIC,7,136,192,30
CONTROL "Enable Overlay",IDC_TEXFMT_OVERLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,148,74,10 CONTROL "Enable Overlay",IDC_TEXFMT_OVERLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,148,74,10
CONTROL "Centered",IDC_TEXFMT_CENTER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,110,148,82,10 CONTROL "Centered",IDC_TEXFMT_CENTER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,110,148,82,10
END END
IDD_ENHANCEMENTS DIALOGEX 0, 0, 207, 175 IDD_ENHANCEMENTS DIALOGEX 0, 0, 224, 175
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
GROUPBOX "Texture &filtering",IDC_STATIC,7,7,193,50 GROUPBOX "Texture &filtering",IDC_STATIC,7,7,210,50
CONTROL "Force &bi/trilinear (breaks video in several Wii games)",IDC_FORCEFILTERING, CONTROL "Force &bi/trilinear (breaks video in several Wii games)",IDC_FORCEFILTERING,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,20,170,9 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,20,192,9
CONTROL "Enable 16x &anisotropy filtering",IDC_FORCEANISOTROPY, CONTROL "Enable 16x &anisotropy filtering",IDC_FORCEANISOTROPY,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,35,110,10 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,35,110,10
GROUPBOX "Texture &enhancements",IDC_STATIC,7,61,193,34
CONTROL "Pre-&upscale:",IDC_PREUPSCALE,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,16,76,54,10
COMBOBOX IDC_PREUPSCALETYPE,74,74,117,49,CBS_DROPDOWNLIST | CBS_SORT | WS_DISABLED | WS_VSCROLL | WS_TABSTOP
GROUPBOX "&Postprocess image",IDC_STATIC,7,102,192,59
LTEXT "Effe&ct:",IDC_STATIC,14,118,36,8
COMBOBOX IDC_POSTPROCESSEFFECT,74,117,117,71,CBS_DROPDOWNLIST | WS_DISABLED | WS_VSCROLL | WS_TABSTOP
LTEXT "Pa&ram 1",IDC_PPPARAM1LABEL2,14,141,35,8
CONTROL "",IDC_PPPARAM1,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | WS_DISABLED | WS_TABSTOP,68,137,127,15
END END
@ -115,7 +128,7 @@ BEGIN
VERTGUIDE, 81 VERTGUIDE, 81
VERTGUIDE, 87 VERTGUIDE, 87
TOPMARGIN, 7 TOPMARGIN, 7
BOTTOMMARGIN, 134 BOTTOMMARGIN, 167
END END
IDD_DEBUGGER, DIALOG IDD_DEBUGGER, DIALOG
@ -140,7 +153,7 @@ BEGIN
IDD_ENHANCEMENTS, DIALOG IDD_ENHANCEMENTS, DIALOG
BEGIN BEGIN
LEFTMARGIN, 7 LEFTMARGIN, 7
RIGHTMARGIN, 200 RIGHTMARGIN, 217
VERTGUIDE, 16 VERTGUIDE, 16
VERTGUIDE, 74 VERTGUIDE, 74
TOPMARGIN, 7 TOPMARGIN, 7
@ -148,3 +161,44 @@ BEGIN
END END
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
À
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -128,11 +128,6 @@ void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const
} }
} }
void RenderToXFB(const BPCmd &bp, const EFBRectangle &rc, const float &yScale, const float &xfbLines, u32 xfbAddr, const u32 &dstWidth, const u32 &dstHeight)
{
Renderer::RenderToXFB(xfbAddr, dstWidth, dstHeight, rc);
}
void ClearScreen(const BPCmd &bp, const EFBRectangle &rc) void ClearScreen(const BPCmd &bp, const EFBRectangle &rc)
{ {
bool colorEnable = bpmem.blendmode.colorupdate; bool colorEnable = bpmem.blendmode.colorupdate;

View File

@ -307,7 +307,7 @@ bool Renderer::Init()
// Adjust all heights with this ratio, the resulting height will be the same as H or EFB_HEIGHT. I.e. // Adjust all heights with this ratio, the resulting height will be the same as H or EFB_HEIGHT. I.e.
// 768 (-1) for 1024x768 etc. // 768 (-1) for 1024x768 etc.
m_FrameBufferHeight *= 528.0 / 480.0; m_FrameBufferHeight *= (float)EFB_HEIGHT / 480.0;
// Ensure a minimum target size so that the native res target always fits // Ensure a minimum target size so that the native res target always fits
if (m_FrameBufferWidth < EFB_WIDTH) m_FrameBufferWidth = EFB_WIDTH; if (m_FrameBufferWidth < EFB_WIDTH) m_FrameBufferWidth = EFB_WIDTH;
@ -989,29 +989,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
#endif #endif
// Place messages on the picture, then copy it to the screen // Place messages on the picture, then copy it to the screen
SwapBuffers();
RestoreAPIState();
GL_REPORT_ERRORD();
g_Config.iSaveTargetId = 0;
bool last_copy_efb_to_ram = g_ActiveConfig.bCopyEFBToRAM;
UpdateActiveConfig();
if (last_copy_efb_to_ram != g_ActiveConfig.bCopyEFBToRAM)
TextureMngr::ClearRenderTargets();
// For testing zbuffer targets.
// Renderer::SetZBufferRender();
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget, GetTargetWidth(), GetTargetHeight());
}
// We can now draw whatever we want on top of the picture. Then we copy the final picture to the output.
// ----------------------------
void Renderer::SwapBuffers()
{
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Count FPS. // Count FPS.
// ------------- // -------------
@ -1084,8 +1061,21 @@ void Renderer::SwapBuffers()
g_framebufferManager.SetFramebuffer(0); g_framebufferManager.SetFramebuffer(0);
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
}
RestoreAPIState();
GL_REPORT_ERRORD();
g_Config.iSaveTargetId = 0;
bool last_copy_efb_to_ram = g_ActiveConfig.bCopyEFBToRAM;
UpdateActiveConfig();
if (last_copy_efb_to_ram != g_ActiveConfig.bCopyEFBToRAM)
TextureMngr::ClearRenderTargets();
// For testing zbuffer targets.
// Renderer::SetZBufferRender();
// SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, s_FakeZTarget, GetTargetWidth(), GetTargetHeight());
}
// Create On-Screen-Messages // Create On-Screen-Messages
void Renderer::DrawDebugText() void Renderer::DrawDebugText()