space changes, merge #defines, language fix, and code reorder/cleanup :P

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5614 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
luisr142004
2010-06-05 01:38:22 +00:00
parent c98f8a96d2
commit 2e783d9769
42 changed files with 1870 additions and 1793 deletions

View File

@ -24,187 +24,197 @@
#include "TextureConverter.h"
#undef CHECK
#define CHECK(hr,Message) if (FAILED(hr)) { PanicAlert(__FUNCTION__ " FAIL: %s" ,Message); }
#define CHECK(hr, Message) if (FAILED(hr)) { PanicAlert(__FUNCTION__ " FAIL: %s" , Message); }
FramebufferManager FBManager;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorRTSurface()
{
return s_efb_color_surface;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorRTSurface()
{
return s_efb_color_surface;
}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthRTSurface()
{
return s_efb_depth_surface;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthRTSurface()
{
return s_efb_depth_surface;
}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorOffScreenRTSurface()
{
return s_efb_color_OffScreenReadBuffer;
}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthOffScreenRTSurface()
{
return s_efb_depth_OffScreenReadBuffer;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorOffScreenRTSurface()
{
return s_efb_color_OffScreenReadBuffer;
}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorReadSurface()
{
return s_efb_color_ReadBuffer;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthOffScreenRTSurface()
{
return s_efb_depth_OffScreenReadBuffer;
}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthReadSurface()
{
return s_efb_depth_ReadBuffer;
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBColorReadSurface()
{
return s_efb_color_ReadBuffer;
}
D3DFORMAT FramebufferManager::GetEFBDepthRTSurfaceFormat(){return s_efb_depth_surface_Format;}
D3DFORMAT FramebufferManager::GetEFBDepthReadSurfaceFormat(){return s_efb_depth_ReadBuffer_Format;}
D3DFORMAT FramebufferManager::GetEFBColorRTSurfaceFormat(){return s_efb_color_surface_Format;}
LPDIRECT3DSURFACE9 FramebufferManager::GetEFBDepthReadSurface()
{
return s_efb_depth_ReadBuffer;
}
D3DFORMAT FramebufferManager::GetEFBDepthRTSurfaceFormat()
{
return s_efb_depth_surface_Format;
}
D3DFORMAT FramebufferManager::GetEFBDepthReadSurfaceFormat()
{
return s_efb_depth_ReadBuffer_Format;
}
D3DFORMAT FramebufferManager::GetEFBColorRTSurfaceFormat()
{
return s_efb_color_surface_Format;
}
LPDIRECT3DTEXTURE9 FramebufferManager::GetEFBColorTexture(const EFBRectangle& sourceRc)
{
return s_efb_color_texture;
}
LPDIRECT3DTEXTURE9 FramebufferManager::GetEFBDepthTexture(const EFBRectangle &sourceRc)
{
return s_efb_depth_texture;
}
void FramebufferManager::Create()
{
{
// Simplest possible setup to start with.
int target_width = Renderer::GetFullTargetWidth();
int target_height = Renderer::GetFullTargetHeight();
s_efb_color_surface_Format = D3DFMT_A8R8G8B8;
//get the framebuffer texture
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &s_efb_color_texture, NULL);
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &s_efb_color_texture, NULL);
if(s_efb_color_texture)
{
hr = s_efb_color_texture->GetSurfaceLevel(0,&s_efb_color_surface);
}
CHECK(hr,"Create Color Texture");
hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &s_efb_colorRead_texture, NULL);
CHECK(hr,"Create Color Read Texture");
hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface);
}
CHECK(hr, "Create Color Texture");
hr = D3D::dev->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &s_efb_colorRead_texture, NULL);
CHECK(hr, "Create Color Read Texture");
if(s_efb_colorRead_texture)
{
s_efb_colorRead_texture->GetSurfaceLevel(0,&s_efb_color_ReadBuffer);
s_efb_colorRead_texture->GetSurfaceLevel(0, &s_efb_color_ReadBuffer);
}
//create an offscreen surface that we can lock to retrieve the data
hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb_color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb_color_OffScreenReadBuffer, NULL );
CHECK(hr,"Create Color offScreen Surface");
hr = D3D::dev->CreateOffscreenPlainSurface(1, 1, s_efb_color_surface_Format, D3DPOOL_SYSTEMMEM, &s_efb_color_OffScreenReadBuffer, NULL);
CHECK(hr, "Create Color offScreen Surface");
//Select Zbuffer format supported by hadware.
if (g_ActiveConfig.bEFBAccessEnable)
{
{
D3DFORMAT *DepthTexFormats = new D3DFORMAT[5];
DepthTexFormats[0] = FOURCC_INTZ;
DepthTexFormats[0] = FOURCC_INTZ;
DepthTexFormats[1] = FOURCC_DF24;
DepthTexFormats[2] = FOURCC_RAWZ;
DepthTexFormats[3] = FOURCC_DF16;
DepthTexFormats[4] = D3DFMT_D24X8;
for(int i = 0;i<5;i++)
for(int i = 0; i < 5; i++)
{
s_efb_depth_surface_Format = DepthTexFormats[i];
//get the framebuffer Depth texture
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb_depth_surface_Format,
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_DEPTHSTENCIL, s_efb_depth_surface_Format,
D3DPOOL_DEFAULT, &s_efb_depth_texture, NULL);
if (!FAILED(hr)) break;
}
if (!FAILED(hr))
break;
}
CHECK(hr,"Depth Color Texture");
//get the Surface
if(s_efb_depth_texture)
{
s_efb_depth_texture->GetSurfaceLevel(0,&s_efb_depth_surface);
s_efb_depth_texture->GetSurfaceLevel(0, &s_efb_depth_surface);
}
//create a 4x4 pixel texture to work as a buffer for peeking
if(s_efb_depth_surface_Format == FOURCC_RAWZ || s_efb_depth_surface_Format == D3DFMT_D24X8)
{
DepthTexFormats[0] = D3DFMT_A8R8G8B8;
DepthTexFormats[0] = D3DFMT_A8R8G8B8;
}
else
{
DepthTexFormats[0] = D3DFMT_R32F;
}
DepthTexFormats[1] = D3DFMT_A8R8G8B8;
DepthTexFormats[1] = D3DFMT_A8R8G8B8;
for(int i = 0;i<2;i++)
for(int i = 0; i < 2; i++)
{
s_efb_depth_ReadBuffer_Format = DepthTexFormats[i];
//get the framebuffer Depth texture
hr = D3D::dev->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, s_efb_depth_ReadBuffer_Format,
hr = D3D::dev->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, s_efb_depth_ReadBuffer_Format,
D3DPOOL_DEFAULT, &s_efb_depthRead_texture, NULL);
if (!FAILED(hr)) break;
if (!FAILED(hr))
break;
}
CHECK(hr,"Create Depth Read texture");
CHECK(hr, "Create Depth Read texture");
if(s_efb_depthRead_texture)
{
s_efb_depthRead_texture->GetSurfaceLevel(0,&s_efb_depth_ReadBuffer);
s_efb_depthRead_texture->GetSurfaceLevel(0, &s_efb_depth_ReadBuffer);
}
//create an offscreen surface that we can lock to retrieve the data
hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb_depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb_depth_OffScreenReadBuffer, NULL );
CHECK(hr,"Create Depth offScreen Surface");
delete [] DepthTexFormats;
hr = D3D::dev->CreateOffscreenPlainSurface(4, 4, s_efb_depth_ReadBuffer_Format, D3DPOOL_SYSTEMMEM, &s_efb_depth_OffScreenReadBuffer, NULL);
CHECK(hr, "Create Depth offScreen Surface");
delete [] DepthTexFormats;
}
else
{
s_efb_depth_surface_Format = D3DFMT_D24X8;
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, s_efb_depth_surface_Format,
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, s_efb_depth_surface_Format,
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
CHECK(hr,"CreateDepthStencilSurface");
}
CHECK(hr, "CreateDepthStencilSurface");
}
}
void FramebufferManager::Destroy()
{
{
if (s_efb_depth_surface)
s_efb_depth_surface->Release();
s_efb_depth_surface=NULL;
s_efb_depth_surface = NULL;
if (s_efb_color_surface)
s_efb_color_surface->Release();
s_efb_color_surface=NULL;
s_efb_color_surface = NULL;
if (s_efb_color_ReadBuffer)
s_efb_color_ReadBuffer->Release();
s_efb_color_ReadBuffer=NULL;
s_efb_color_ReadBuffer = NULL;
if (s_efb_depth_ReadBuffer)
s_efb_depth_ReadBuffer->Release();
s_efb_depth_ReadBuffer=NULL;
s_efb_depth_ReadBuffer = NULL;
if (s_efb_color_OffScreenReadBuffer)
s_efb_color_OffScreenReadBuffer->Release();
s_efb_color_OffScreenReadBuffer=NULL;
s_efb_color_OffScreenReadBuffer = NULL;
if (s_efb_depth_OffScreenReadBuffer)
s_efb_depth_OffScreenReadBuffer->Release();
s_efb_depth_OffScreenReadBuffer=NULL;
s_efb_depth_OffScreenReadBuffer = NULL;
if (s_efb_color_texture)
s_efb_color_texture->Release();
s_efb_color_texture=NULL;
s_efb_color_texture = NULL;
if (s_efb_colorRead_texture)
s_efb_colorRead_texture->Release();
s_efb_colorRead_texture=NULL;
s_efb_colorRead_texture = NULL;
if (s_efb_depth_texture)
s_efb_depth_texture->Release();
s_efb_depth_texture=NULL;
s_efb_depth_texture = NULL;
if (s_efb_depthRead_texture)
s_efb_depthRead_texture->Release();
s_efb_depthRead_texture=NULL;
s_efb_depthRead_texture = NULL;
for (VirtualXFBListType::iterator it = m_virtualXFBList.begin(); it != m_virtualXFBList.end(); ++it)
{
@ -213,7 +223,7 @@ void FramebufferManager::Destroy()
}
m_virtualXFBList.clear();
if(m_realXFBSource.texture)
m_realXFBSource.texture->Release();
m_realXFBSource.texture->Release();
m_realXFBSource.texture = NULL;
}
@ -255,7 +265,7 @@ FramebufferManager::VirtualXFBListType::iterator FramebufferManager::findVirtual
void FramebufferManager::replaceVirtualXFB()
{
VirtualXFBListType::iterator it = m_virtualXFBList.begin();
VirtualXFBListType::iterator it = m_virtualXFBList.begin();
s32 srcLower = it->xfbAddr;
s32 srcUpper = it->xfbAddr + 2 * it->xfbWidth * it->xfbHeight;
@ -276,7 +286,7 @@ void FramebufferManager::replaceVirtualXFB()
it->xfbWidth = 0;
}
else if (addrRangesOverlap(srcLower, srcUpper, dstLower, dstUpper))
{
{
s32 upperOverlap = (srcUpper - dstLower) / lineSize;
s32 lowerOverlap = (dstUpper - srcLower) / lineSize;
@ -343,15 +353,15 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
it->xfbSource.srcAddr = xfbAddr;
it->xfbSource.srcWidth = fbWidth;
it->xfbSource.srcHeight = fbHeight;
it->xfbSource.srcHeight = fbHeight;
if(it->xfbSource.texWidth != target_width || it->xfbSource.texHeight != target_height || !(it->xfbSource.texture))
{
if(it->xfbSource.texture)
it->xfbSource.texture->Release();
it->xfbSource.texture = NULL;
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &(it->xfbSource.texture), NULL);
hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &(it->xfbSource.texture), NULL);
}
@ -370,8 +380,8 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
{
// Create a new Virtual XFB and place it at the front of the list.
D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &xfbTexture, NULL);
D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &xfbTexture, NULL);
VirtualXFB newVirt;
newVirt.xfbAddr = xfbAddr;
@ -380,7 +390,7 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
newVirt.xfbSource.texture = xfbTexture;
newVirt.xfbSource.texWidth = target_width;
newVirt.xfbSource.texHeight = target_height;
newVirt.xfbSource.texHeight = target_height;
// Add the new Virtual XFB to the list
@ -399,14 +409,14 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
if(!xfbTexture)
return;
LPDIRECT3DTEXTURE9 read_texture = GetEFBColorTexture(sourceRc);
Renderer::ResetAPIState(); // reset any game specific settings
LPDIRECT3DSURFACE9 Rendersurf = NULL;
xfbTexture->GetSurfaceLevel(0,&Rendersurf);
xfbTexture->GetSurfaceLevel(0, &Rendersurf);
D3D::dev->SetDepthStencilSurface(NULL);
D3D::dev->SetRenderTarget(0, Rendersurf);
D3D::dev->SetRenderTarget(0, Rendersurf);
D3DVIEWPORT9 vp;
vp.X = 0;
@ -424,27 +434,25 @@ void FramebufferManager::copyToVirtualXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight
D3D::ChangeSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
D3D::ChangeSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
D3D::drawShadedTexQuad(
read_texture,
read_texture,
&sourcerect,
Renderer::GetFullTargetWidth() ,
Renderer::GetFullTargetHeight(),
target_width,
target_height,
PixelShaderCache::GetColorCopyProgram( g_ActiveConfig.iMultisampleMode),
VertexShaderCache::GetSimpleVertexShader( g_ActiveConfig.iMultisampleMode));
Renderer::GetFullTargetWidth(),
Renderer::GetFullTargetHeight(),
target_width,
target_height,
PixelShaderCache::GetColorCopyProgram( g_ActiveConfig.iMultisampleMode),
VertexShaderCache::GetSimpleVertexShader( g_ActiveConfig.iMultisampleMode));
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
D3D::SetTexture(0,NULL);
D3D::SetTexture(0, NULL);
D3D::dev->SetRenderTarget(0, GetEFBColorRTSurface());
D3D::dev->SetDepthStencilSurface(GetEFBDepthRTSurface());
D3D::dev->SetDepthStencilSurface(GetEFBDepthRTSurface());
Renderer::RestoreAPIState();
Rendersurf->Release();
Rendersurf->Release();
}
const XFBSource** FramebufferManager::getRealXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32 &xfbCount)
@ -456,12 +464,12 @@ const XFBSource** FramebufferManager::getRealXFBSource(u32 xfbAddr, u32 fbWidth,
m_realXFBSource.srcAddr = xfbAddr;
m_realXFBSource.srcWidth = fbWidth;
m_realXFBSource.srcHeight = fbHeight;
m_realXFBSource.srcHeight = fbHeight;
if (!m_realXFBSource.texture)
{
D3D::dev->CreateTexture(fbWidth, fbHeight, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &m_realXFBSource.texture, NULL);
D3D::dev->CreateTexture(fbWidth, fbHeight, 1, D3DUSAGE_RENDERTARGET, s_efb_color_surface_Format,
D3DPOOL_DEFAULT, &m_realXFBSource.texture, NULL);
}
// Decode YUYV data from GameCube RAM