diff --git a/Source/Core/VideoCommon/Src/Render.h b/Source/Core/VideoCommon/Src/Render.h index 54bfa72133..379364066a 100644 --- a/Source/Core/VideoCommon/Src/Render.h +++ b/Source/Core/VideoCommon/Src/Render.h @@ -56,6 +56,11 @@ public: static bool SetScissorRect(); static void SetGenerationMode(); static void SetDepthMode(); + static void SetLogicOpMode(); + static void SetDitherMode(); + static void SetLineWidth(); + static void SetSamplerState(int stage,int texindex); + static void SetInterlacingMode(); // Live resolution change static bool Allow2x(); static bool AllowCustom(); diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 4d310f98cd..f54d428a2b 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -168,7 +168,7 @@ const char *GenerateVertexShader(u32 components, bool D3D) WRITE(p, " float4 blend_indices : BLENDINDICES,\n"); } else - WRITE(p, " float posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB); + WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB); } WRITE(p, " float4 rawpos : POSITION) {\n"); WRITE(p, "VS_OUTPUT o;\n"); @@ -180,6 +180,11 @@ const char *GenerateVertexShader(u32 components, bool D3D) WRITE(p, "int4 indices = D3DCOLORtoUBYTE4(blend_indices);\n" "int posmtx = indices.x;\n"); } + else + { + WRITE(p, "int posmtx = fposmtx;\n"); + } + WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos),1);\n"); if (components & VB_HAS_NRMALL) { @@ -188,34 +193,30 @@ const char *GenerateVertexShader(u32 components, bool D3D) } if (components & VB_HAS_NRM0) - WRITE(p, "float3 _norm0 = float3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n" - "float3 norm0 = normalize(_norm0);\n"); + WRITE(p, "float3 _norm0 = normalize(float3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0)));\n"); if (components & VB_HAS_NRM1) - WRITE(p, "float3 _norm1 = float3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n"); - //"half3 norm1 = normalize(_norm1);\n"); + WRITE(p, "float3 _norm1 = float3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n"); if (components & VB_HAS_NRM2) WRITE(p, "float3 _norm2 = float3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n"); - //"half3 norm2 = normalize(_norm2);\n"); + } else { WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1.0f);\n"); if (components & VB_HAS_NRM0) - WRITE(p, "float3 _norm0 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n" - "float3 norm0 = normalize(_norm0);\n"); + WRITE(p, "float3 _norm0 = normalize(float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0)));\n"); if (components & VB_HAS_NRM1) - WRITE(p, "float3 _norm1 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n"); - //"half3 norm1 = normalize(_norm1);\n"); + WRITE(p, "float3 _norm1 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n"); if (components & VB_HAS_NRM2) WRITE(p, "float3 _norm2 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n"); - //"half3 norm2 = normalize(_norm2);\n"); + } if (!(components & VB_HAS_NRM0)) - WRITE(p, "float3 _norm0 = float3(0.0f,0.0f,0.0f), norm0 = float3(0.0f,0.0f,0.0f);\n"); + WRITE(p, "float3 _norm0 = float3(0.0f,0.0f,0.0f);\n"); WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n"); - WRITE(p, "float4 mat;\n" // = half4(1,1,1,1), lacc = half4(0,0,0,0);\n" + WRITE(p, "float4 mat,lacc;\n" // = half4(1,1,1,1), lacc = half4(0,0,0,0);\n" "float3 ldir, h;\n" "float dist, dist2, attn;\n"); @@ -228,7 +229,7 @@ const char *GenerateVertexShader(u32 components, bool D3D) WRITE(p, "{\n"); - WRITE(p, "float4 lacc = float4(1.0f,1.0f,1.0f,1.0f);\n"); + WRITE(p, "lacc = float4(1.0f,1.0f,1.0f,1.0f);\n"); if (color.matsource) {// from vertex if (components & (VB_HAS_COL0 << j)) WRITE(p, "mat = color%d;\n", j); @@ -303,18 +304,15 @@ const char *GenerateVertexShader(u32 components, bool D3D) if (color.enablelighting != alpha.enablelighting) { if (color.enablelighting) - //WRITE(p, "o.colors[%d].xyz = mat.xyz * clamp(lacc.xyz,float3(0.0f,0.0f,0.0f),float3(1.0f,1.0f,1.0f));\n" WRITE(p, "o.colors[%d].xyz = mat.xyz * saturate(lacc.xyz);\n" "o.colors[%d].w = mat.w;\n", j, j); else WRITE(p, "o.colors[%d].xyz = mat.xyz;\n" - //"o.colors[%d].w = mat.w * clamp(lacc.w,0.0f,1.0f);\n", j, j); - "o.colors[%d].w = mat.w * saturate(lacc.w);\n", j, j); + "o.colors[%d].w = mat.w * saturate(lacc.w);\n", j, j); } else { if (alpha.enablelighting) - //WRITE(p, "o.colors[%d] = mat * clamp(lacc, float4(0.0f,0.0f,0.0f,0.0f), float4(1.0f,1.0f,1.0f,1.0f));\n", j); - WRITE(p, "o.colors[%d] = mat * saturate(lacc);\n", j); + WRITE(p, "o.colors[%d] = mat * saturate(lacc);\n", j); else WRITE(p, "o.colors[%d] = mat;\n", j); } @@ -431,12 +429,14 @@ const char *GenerateVertexShader(u32 components, bool D3D) WRITE(p, "o.tex3.w = o.pos.w;\n"); } - if (!D3D) { + if (D3D) + { + WRITE(p, "o.pos.z = o.pos.z + o.pos.w;\n"); + } + else + { // scale to gl clip space - which is -o.pos.w to o.pos.w, hence the addition. WRITE(p, "o.pos.z = (o.pos.z * 2.0f) + o.pos.w;\n"); - } else { - - WRITE(p, "o.pos.z = o.pos.z + o.pos.w;\n"); } WRITE(p, "return o;\n}\n"); @@ -462,7 +462,7 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char case LIGHTDIF_SIGN: case LIGHTDIF_CLAMP: WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", index); - WRITE(p, "%s.%s += %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n", + WRITE(p, "%s.%s += %sdot(ldir, _norm0)) * "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle); break; default: _assert_(0); @@ -479,7 +479,7 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, float3(1.0f,dist,dist2));\n", index, index); } else if (chan.attnfunc == 1) { // specular - WRITE(p, "attn = dot(norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0.0f ? max(0.0f, dot(norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0.0f;\n", index, index); + WRITE(p, "attn = dot(_norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0.0f ? max(0.0f, dot(_norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0.0f;\n", index, index); WRITE(p, "ldir = float3(1,attn,attn*attn);\n"); WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, ldir)) / dot("I_LIGHTS".lights[%d].distatt.xyz, ldir);\n", index, index); } @@ -490,7 +490,7 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char break; case LIGHTDIF_SIGN: case LIGHTDIF_CLAMP: - WRITE(p, "%s.%s += attn * %sdot(ldir, norm0)) * "I_LIGHTS".lights[%d].col.%s;\n", + WRITE(p, "%s.%s += attn * %sdot(ldir, _norm0)) * "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle); break; default: _assert_(0); 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 +}