summaryrefslogtreecommitdiff
path: root/Source/Plugins
diff options
context:
space:
mode:
authorRodolfo Osvaldo Bogado <rodolfoosvaldobogado@gmail.com>2009-11-27 19:42:27 +0000
committerRodolfo Osvaldo Bogado <rodolfoosvaldobogado@gmail.com>2009-11-27 19:42:27 +0000
commit5e31f22e50a2dddc0b0a7e5b2fcb515c4e574e60 (patch)
treece9b12f4dc7dfd79170009e3548ed1a76ed7b289 /Source/Plugins
parentf69184b88722cd65364937611a481860f7f7f3c0 (diff)
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
Diffstat (limited to 'Source/Plugins')
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp65
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp16
-rw-r--r--Source/Plugins/Plugin_VideoDX9/Src/Render.cpp101
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp50
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp5
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/Render.cpp76
6 files changed, 194 insertions, 119 deletions
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp
index 33ddb44aec..e8f04c1c87 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp
@@ -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)
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
index c972eb07f4..580a4411e1 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
@@ -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);
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
index c464866320..b01b44d6a5 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
@@ -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
+}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
index ee663307e5..02cca6592e 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp
@@ -34,14 +34,6 @@ namespace BPFunctions
// Reference: Yet Another Gamecube Documentation
// ----------------------------------------------
-static const GLenum glCmpFuncs[8] = {
- GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS
-};
-
-static const GLenum glLogicOpCodes[16] = {
- GL_CLEAR, GL_AND, GL_AND_REVERSE, GL_COPY, GL_AND_INVERTED, GL_NOOP, GL_XOR,
- GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET
-};
void FlushPipeline()
{
@@ -49,17 +41,9 @@ void FlushPipeline()
}
void SetGenerationMode(const BPCmd &bp)
{
- // none, ccw, cw, ccw
- if (bpmem.genMode.cullmode > 0)
- {
- glEnable(GL_CULL_FACE);
- glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
- }
- else
- glDisable(GL_CULL_FACE);
+ Renderer::SetGenerationMode();
}
-
void SetScissor(const BPCmd &bp)
{
if (!Renderer::SetScissorRect())
@@ -68,26 +52,11 @@ void SetScissor(const BPCmd &bp)
}
void SetLineWidth(const BPCmd &bp)
{
- float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f;
- if (bpmem.lineptwidth.linesize > 0)
- glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
- if (bpmem.lineptwidth.pointsize > 0)
- glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f);
+ Renderer::SetLineWidth();
}
void SetDepthMode(const BPCmd &bp)
{
- if (bpmem.zmode.testenable)
- {
- glEnable(GL_DEPTH_TEST);
- glDepthMask(bpmem.zmode.updateenable ? GL_TRUE : GL_FALSE);
- glDepthFunc(glCmpFuncs[bpmem.zmode.func]);
- }
- else
- {
- // if the test is disabled write is disabled too
- glDisable(GL_DEPTH_TEST);
- glDepthMask(GL_FALSE);
- }
+ Renderer::SetDepthMode();
}
void SetBlendMode(const BPCmd &bp)
{
@@ -95,20 +64,11 @@ void SetBlendMode(const BPCmd &bp)
}
void SetDitherMode(const BPCmd &bp)
{
- if (bpmem.blendmode.dither)
- glEnable(GL_DITHER);
- else
- glDisable(GL_DITHER);
+ Renderer::SetDitherMode();
}
void SetLogicOpMode(const BPCmd &bp)
{
- if (bpmem.blendmode.logicopenable)
- {
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
- }
- else
- glDisable(GL_COLOR_LOGIC_OP);
+ Renderer::SetLogicOpMode();
}
void SetColorMask(const BPCmd &bp)
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
index 4bae505087..0539d148be 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
@@ -118,9 +118,12 @@ void PixelShaderCache::Init()
"TEMP R1;\n"
"TEMP R2;\n"
"PARAM K0 = { 65535.0, 255.0,1.0,16777215.0};\n"
+ "PARAM K1 = { 0.999999940395355224609375, 1.0000000596046483281045155587504,0.0,0.0};\n"
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
- "MUL R0, R2.x, K0;\n"
+ "MUL R0, R2.x, K1.x;\n"
+ "MUL R0, R0.x, K0;\n"
"FRC R0, R0;\n"
+ "MUL R0, R0, K1.y;\n"
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
index 6fd6aaa9d4..c573db1daf 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp
@@ -154,6 +154,15 @@ static const GLenum glDestFactors[8] = {
GL_ONE_MINUS_DST_ALPHA
};
+static const GLenum glCmpFuncs[8] = {
+ GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS
+};
+
+static const GLenum glLogicOpCodes[16] = {
+ GL_CLEAR, GL_AND, GL_AND_REVERSE, GL_COPY, GL_AND_INVERTED, GL_NOOP, GL_XOR,
+ GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET
+};
+
void SetDefaultRectTexParams()
{
// Set some standard texture filter modes.
@@ -1374,3 +1383,70 @@ void UpdateViewport()
glViewport(GLx, GLy, GLWidth, GLHeight);
glDepthRange(GLNear, GLFar);
}
+
+void Renderer::SetGenerationMode()
+{
+ // none, ccw, cw, ccw
+ if (bpmem.genMode.cullmode > 0)
+ {
+ glEnable(GL_CULL_FACE);
+ glFrontFace(bpmem.genMode.cullmode == 2 ? GL_CCW : GL_CW);
+ }
+ else
+ glDisable(GL_CULL_FACE);
+}
+
+void Renderer::SetDepthMode()
+{
+ if (bpmem.zmode.testenable)
+ {
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(bpmem.zmode.updateenable ? GL_TRUE : GL_FALSE);
+ glDepthFunc(glCmpFuncs[bpmem.zmode.func]);
+ }
+ else
+ {
+ // if the test is disabled write is disabled too
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+ }
+}
+
+void Renderer::SetLogicOpMode()
+{
+ if (bpmem.blendmode.logicopenable)
+ {
+ glEnable(GL_COLOR_LOGIC_OP);
+ glLogicOp(glLogicOpCodes[bpmem.blendmode.logicmode]);
+ }
+ else
+ glDisable(GL_COLOR_LOGIC_OP);
+}
+
+void Renderer::SetDitherMode()
+{
+ if (bpmem.blendmode.dither)
+ glEnable(GL_DITHER);
+ else
+ glDisable(GL_DITHER);
+}
+
+
+void Renderer::SetLineWidth()
+{
+ float fratio = xfregs.rawViewport[0] != 0 ? ((float)Renderer::GetTargetWidth() / EFB_WIDTH) : 1.0f;
+ if (bpmem.lineptwidth.linesize > 0)
+ glLineWidth((float)bpmem.lineptwidth.linesize * fratio / 6.0f); // scale by ratio of widths
+ if (bpmem.lineptwidth.pointsize > 0)
+ glPointSize((float)bpmem.lineptwidth.pointsize * fratio / 6.0f);
+}
+
+void Renderer::SetSamplerState(int stage,int texindex)
+{
+ // TODO
+}
+
+void Renderer::SetInterlacingMode()
+{
+ // TODO
+}