mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 15:19:42 -06:00
small code reorganization.
Now efb to ram display correctly but still is misaligned by one pixel please test and give me feedback git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4618 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -33,22 +33,6 @@ const bool renderFog = false;
|
||||
|
||||
using namespace D3D;
|
||||
|
||||
static const D3DTEXTUREFILTERTYPE d3dMipFilters[4] =
|
||||
{
|
||||
D3DTEXF_NONE,
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_LINEAR, //reserved
|
||||
};
|
||||
|
||||
static const D3DTEXTUREADDRESS d3dClamps[4] =
|
||||
{
|
||||
D3DTADDRESS_CLAMP,
|
||||
D3DTADDRESS_WRAP,
|
||||
D3DTADDRESS_MIRROR,
|
||||
D3DTADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
namespace BPFunctions
|
||||
{
|
||||
|
||||
@ -69,9 +53,7 @@ void SetScissor(const BPCmd &bp)
|
||||
|
||||
void SetLineWidth(const BPCmd &bp)
|
||||
{
|
||||
// We can't change line width in D3D unless we use ID3DXLine
|
||||
float psize = float(bpmem.lineptwidth.pointsize) * 6.0f;
|
||||
D3D::SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&psize));
|
||||
Renderer::SetLineWidth();
|
||||
}
|
||||
|
||||
void SetDepthMode(const BPCmd &bp)
|
||||
@ -85,7 +67,7 @@ void SetBlendMode(const BPCmd &bp)
|
||||
}
|
||||
void SetDitherMode(const BPCmd &bp)
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither);
|
||||
Renderer::SetDitherMode();
|
||||
}
|
||||
void SetLogicOpMode(const BPCmd &bp)
|
||||
{
|
||||
@ -102,16 +84,15 @@ void CopyEFB(const BPCmd &bp, const EFBRectangle &rc, const u32 &address, const
|
||||
if (!g_ActiveConfig.bEFBCopyDisable)
|
||||
{
|
||||
//uncomment this to see the efb to ram work in progress
|
||||
/*if (g_ActiveConfig.bCopyEFBToRAM)
|
||||
if (g_ActiveConfig.bCopyEFBToRAM)
|
||||
{
|
||||
// To RAM, not implemented yet
|
||||
//ToRam
|
||||
TextureConverter::EncodeToRam(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc);
|
||||
}
|
||||
else // To D3D Texture*/
|
||||
else // To D3D Texture
|
||||
{
|
||||
TextureCache::CopyRenderTargetToTexture(address, fromZBuffer, isIntensityFmt, copyfmt, scaleByHalf, rc);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +116,7 @@ void ClearScreen(const BPCmd &bp, const EFBRectangle &rc)
|
||||
|
||||
void RestoreRenderState(const BPCmd &bp)
|
||||
{
|
||||
//Renderer::SetRenderMode(Renderer::RM_Normal);
|
||||
Renderer::RestoreAPIState();
|
||||
}
|
||||
|
||||
bool GetConfig(const int &type)
|
||||
@ -161,40 +142,8 @@ u8 *GetPointer(const u32 &address)
|
||||
|
||||
void SetSamplerState(const BPCmd &bp)
|
||||
{
|
||||
const FourTexUnits &tex = bpmem.tex[(bp.address & 0xE0) == 0xA0];
|
||||
int stage = (bp.address & 3);//(addr>>4)&2;
|
||||
const TexMode0 &tm0 = tex.texMode0[stage];
|
||||
|
||||
D3DTEXTUREFILTERTYPE min, mag, mip;
|
||||
if (g_ActiveConfig.bForceFiltering)
|
||||
{
|
||||
min = mag = mip = D3DTEXF_LINEAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mip = d3dMipFilters[tm0.min_filter & 3];
|
||||
}
|
||||
if ((bp.address & 0xE0) == 0xA0)
|
||||
stage += 4;
|
||||
|
||||
if (mag == D3DTEXF_LINEAR && min == D3DTEXF_LINEAR &&
|
||||
g_ActiveConfig.iMaxAnisotropy > 1)
|
||||
{
|
||||
min = D3DTEXF_ANISOTROPIC;
|
||||
}
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MINFILTER, min);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
|
||||
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
|
||||
//wip
|
||||
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
|
||||
//char temp[256];
|
||||
//sprintf(temp,"lod %f",tm0.lod_bias/4.0f);
|
||||
//g_VideoInitialize.pLog(temp);
|
||||
Renderer::SetSamplerState(stage,(bp.address & 0xE0) == 0xA0);
|
||||
}
|
||||
|
||||
void SetInterlacingMode(const BPCmd &bp)
|
||||
|
@ -398,16 +398,16 @@ void drawShadedTexQuad(IDirect3DTexture9 *texture,
|
||||
{
|
||||
SaveRenderStates();
|
||||
D3D::SetTexture(0, 0);
|
||||
float u1=((float)rSource->left+1.0f)/(float) SourceWidth;
|
||||
float u2=((float)rSource->right-1.0f)/(float) SourceWidth;
|
||||
float v1=((float)rSource->top+1.0f)/(float) SourceHeight;
|
||||
float v2=((float)rSource->bottom-1.0f)/(float) SourceHeight;
|
||||
float u1=((float)rSource->left)/(float) SourceWidth;
|
||||
float u2=((float)rSource->right)/(float) SourceWidth;
|
||||
float v1=((float)rSource->top)/(float) SourceHeight;
|
||||
float v2=((float)rSource->bottom)/(float) SourceHeight;
|
||||
|
||||
struct Q2DVertex { float x,y,z,rhw,u,v; } coords[4] = {
|
||||
{(float)rDest->left-0.5f, (float)rDest->top-0.5f, 0.0f, 1.0f, u1, v1},
|
||||
{(float)rDest->right-0.5f, (float)rDest->top-0.5f, 0.0f,1.0f, u2, v1},
|
||||
{(float)rDest->right-0.5f, (float)rDest->bottom-0.5f, 0.0f,1.0f, u2, v2},
|
||||
{(float)rDest->left-0.5f, (float)rDest->bottom-0.5f, 0.0f,1.0f, u1, v2}
|
||||
{(float)rDest->left - 0.5f, (float)rDest->top- 0.5f, 0.0f, 1.0f, u1, v1},
|
||||
{(float)rDest->right- 0.5f, (float)rDest->top- 0.5f, 0.0f,1.0f, u2, v1},
|
||||
{(float)rDest->right- 0.5f, (float)rDest->bottom- 0.5f, 0.0f,1.0f, u2, v2},
|
||||
{(float)rDest->left- 0.5f, (float)rDest->bottom- 0.5f, 0.0f,1.0f, u1, v2}
|
||||
};
|
||||
HRESULT hr = 0;
|
||||
hr = dev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
|
||||
|
@ -111,7 +111,21 @@ static const D3DCMPFUNC d3dCmpFuncs[8] =
|
||||
D3DCMP_ALWAYS
|
||||
};
|
||||
|
||||
static const D3DTEXTUREFILTERTYPE d3dMipFilters[4] =
|
||||
{
|
||||
D3DTEXF_NONE,
|
||||
D3DTEXF_POINT,
|
||||
D3DTEXF_LINEAR,
|
||||
D3DTEXF_LINEAR, //reserved
|
||||
};
|
||||
|
||||
static const D3DTEXTUREADDRESS d3dClamps[4] =
|
||||
{
|
||||
D3DTADDRESS_CLAMP,
|
||||
D3DTADDRESS_WRAP,
|
||||
D3DTADDRESS_MIRROR,
|
||||
D3DTADDRESS_WRAP //reserved
|
||||
};
|
||||
|
||||
void SetupDeviceObjects()
|
||||
{
|
||||
@ -243,10 +257,10 @@ void dumpMatrix(D3DXMATRIX &mtx)
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
{
|
||||
TargetRectangle result;
|
||||
result.left = (rc.left * s_target_width) / EFB_WIDTH ;
|
||||
result.top = (rc.top * s_target_height) / EFB_HEIGHT;
|
||||
result.right = (rc.right * s_target_width) / EFB_WIDTH ;
|
||||
result.bottom = (rc.bottom * s_target_height) / EFB_HEIGHT;
|
||||
result.left = (int)ceilf((((float)rc.left * s_target_width) / (float)EFB_WIDTH)-0.5f) ;
|
||||
result.top = (int)ceilf((((float)rc.top * s_target_height) / (float)EFB_HEIGHT)-0.5f);
|
||||
result.right = (int)floorf((((float)rc.right * s_target_width) / (float)EFB_WIDTH)+0.5f) ;
|
||||
result.bottom = (int)floorf((((float)rc.bottom * s_target_height) / (float)EFB_HEIGHT)+0.5f);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -764,8 +778,22 @@ void UpdateViewport()
|
||||
vp.Width = Width;
|
||||
vp.Height = Height;
|
||||
//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;
|
||||
vp.MinZ = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
|
||||
vp.MaxZ = xfregs.rawViewport[5] / 16777216.0f;
|
||||
if(vp.MinZ < 0.0f)
|
||||
vp.MinZ = 0.0f;
|
||||
if(vp.MinZ > 1.0f)
|
||||
vp.MinZ = 1.0f;
|
||||
if(vp.MaxZ < 0.0f)
|
||||
vp.MaxZ = 0.0f;
|
||||
if(vp.MaxZ > 1.0f)
|
||||
vp.MaxZ = 1.0f;
|
||||
if(vp.MinZ > vp.MaxZ)
|
||||
{
|
||||
float temp = vp.MinZ;
|
||||
vp.MinZ = vp.MaxZ;
|
||||
vp.MaxZ = temp;
|
||||
}
|
||||
D3D::dev->SetViewport(&vp);
|
||||
}
|
||||
|
||||
@ -888,7 +916,7 @@ void Renderer::RestoreAPIState()
|
||||
// Gets us back into a more game-like state.
|
||||
|
||||
UpdateViewport();
|
||||
|
||||
D3D::SetRenderState(D3DRS_CULLMODE, d3dCullModes[bpmem.genMode.cullmode]);
|
||||
if (bpmem.zmode.testenable) D3D::SetRenderState(D3DRS_ZENABLE, TRUE);
|
||||
if (bpmem.zmode.updateenable) D3D::SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
||||
|
||||
@ -932,3 +960,62 @@ void Renderer::SetDepthMode()
|
||||
D3D::SetRenderState(D3DRS_ZWRITEENABLE, FALSE); // ??
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetLogicOpMode()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void Renderer::SetDitherMode()
|
||||
{
|
||||
D3D::SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither);
|
||||
}
|
||||
|
||||
void Renderer::SetLineWidth()
|
||||
{
|
||||
// We can't change line width in D3D unless we use ID3DXLine
|
||||
float psize = float(bpmem.lineptwidth.pointsize) * 6.0f;
|
||||
D3D::SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&psize));
|
||||
}
|
||||
|
||||
void Renderer::SetSamplerState(int stage,int texindex)
|
||||
{
|
||||
const FourTexUnits &tex = bpmem.tex[texindex];
|
||||
const TexMode0 &tm0 = tex.texMode0[stage];
|
||||
|
||||
D3DTEXTUREFILTERTYPE min, mag, mip;
|
||||
if (g_ActiveConfig.bForceFiltering)
|
||||
{
|
||||
min = mag = mip = D3DTEXF_LINEAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
min = (tm0.min_filter & 4) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mag = tm0.mag_filter ? D3DTEXF_LINEAR : D3DTEXF_POINT;
|
||||
mip = d3dMipFilters[tm0.min_filter & 3];
|
||||
}
|
||||
if (texindex)
|
||||
stage += 4;
|
||||
|
||||
if (mag == D3DTEXF_LINEAR && min == D3DTEXF_LINEAR &&
|
||||
g_ActiveConfig.iMaxAnisotropy > 1)
|
||||
{
|
||||
min = D3DTEXF_ANISOTROPIC;
|
||||
}
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MINFILTER, min);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MAGFILTER, mag);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_MIPFILTER, mip);
|
||||
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSU, d3dClamps[tm0.wrap_s]);
|
||||
D3D::SetSamplerState(stage, D3DSAMP_ADDRESSV, d3dClamps[tm0.wrap_t]);
|
||||
//wip
|
||||
//dev->SetSamplerState(stage,D3DSAMP_MIPMAPLODBIAS,tm0.lod_bias/4.0f);
|
||||
//char temp[256];
|
||||
//sprintf(temp,"lod %f",tm0.lod_bias/4.0f);
|
||||
//g_VideoInitialize.pLog(temp);
|
||||
}
|
||||
|
||||
void Renderer::SetInterlacingMode()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
Reference in New Issue
Block a user