From bcb31b09d38463f8a7a515858a2143477bfc8935 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 25 Nov 2013 15:01:18 +0100 Subject: [PATCH] TextureConverter: Use gl_FragCoord instead of uv0 --- .../OGL/Src/TextureConverter.cpp | 29 ++++++++----------- .../Src/TextureConversionShader.cpp | 12 +++----- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp index 161468d2b0..08932f562e 100644 --- a/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/Src/TextureConverter.cpp @@ -41,17 +41,6 @@ static SHADER s_yuyvToRgbProgram; // Not all slots are taken - but who cares. const u32 NUM_ENCODING_PROGRAMS = 64; static SHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; -static int s_encodingUniform_loc[NUM_ENCODING_PROGRAMS]; - -static const char *VProgram = - "VARYOUT vec2 uv0;\n" - "uniform vec4 copy_position;\n" // left, top, right, bottom - "void main()\n" - "{\n" - " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" - " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" - " uv0 = mix(copy_position.xy, copy_position.zw, rawpos);\n" - "}\n"; void CreatePrograms() { @@ -158,8 +147,14 @@ SHADER &GetOrCreateEncodingShader(u32 format) } #endif + const char *VProgram = + "void main()\n" + "{\n" + " vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n" + " gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n" + "}\n"; + ProgramShaderCache::CompileShader(s_encodingPrograms[format], VProgram, shader); - s_encodingUniform_loc[format] = glGetUniformLocation(s_encodingPrograms[format].glprogid, "copy_position"); } return s_encodingPrograms[format]; } @@ -200,7 +195,7 @@ void Shutdown() void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight, int readStride, - bool toTexture, bool linearFilter, int uniform_loc) + bool toTexture, bool linearFilter) { @@ -230,8 +225,6 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc, glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight); - glUniform4f(uniform_loc, sourceRc.left, sourceRc.top, sourceRc.right, sourceRc.bottom); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); GL_REPORT_ERRORD(); @@ -323,7 +316,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, TexDecoder_GetBlockWidthInTexels(format); EncodeToRamUsingShader(source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, - true, bScaleByHalf > 0 && !bFromZBuffer, s_encodingUniform_loc[format]); + true, bScaleByHalf > 0 && !bFromZBuffer); return size_in_bytes; // TODO: D3D11 is calculating this value differently! } @@ -334,10 +327,12 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des s_rgbToYuyvProgram.Bind(); + glUniform4f(s_rgbToYuyvUniform_loc, sourceRc.left, sourceRc.top, sourceRc.right, sourceRc.bottom); + // We enable linear filtering, because the gamecube does filtering in the vertical direction when // yscale is enabled. // Otherwise we get jaggies when a game uses yscaling (most PAL games) - EncodeToRamUsingShader(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, true, s_rgbToYuyvUniform_loc); + EncodeToRamUsingShader(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, 0, false, true); FramebufferManager::SetFramebuffer(0); TextureCache::DisableStage(0); g_renderer->RestoreAPIState(); diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index c78b854535..a6f63ad6ee 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -75,7 +75,6 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, "uniform sampler2D samp0;\n"); WRITE(p, " out vec4 ocol0;\n"); - WRITE(p, " VARYIN float2 uv0;\n"); WRITE(p, "void main()\n"); } else // D3D @@ -84,13 +83,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, "Texture2D Tex0 : register(t0);\n"); WRITE(p,"void main(\n"); - WRITE(p," out float4 ocol0 : SV_Target,\n"); - WRITE(p," in float2 uv0 : TEXCOORD0)\n"); + WRITE(p," out float4 ocol0 : SV_Target)\n"); } WRITE(p, "{\n" " float2 sampleUv;\n" - " float2 uv1 = floor(uv0);\n"); + " float2 uv1 = floor(gl_FragCoord.xy);\n"); WRITE(p, " uv1.x = uv1.x * %d.0;\n", samples); @@ -133,7 +131,6 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, "uniform sampler2D samp0;\n"); WRITE(p, " out float4 ocol0;\n"); - WRITE(p, " VARYIN float2 uv0;\n"); WRITE(p, "void main()\n"); } else @@ -142,14 +139,13 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, "Texture2D Tex0 : register(t0);\n"); WRITE(p,"void main(\n"); - WRITE(p," out float4 ocol0 : SV_Target,\n"); - WRITE(p," in float2 uv0 : TEXCOORD0)\n"); + WRITE(p," out float4 ocol0 : SV_Target)\n"); } WRITE(p, "{\n" " float2 sampleUv;\n" - " float2 uv1 = floor(uv0);\n"); + " float2 uv1 = floor(gl_FragCoord.xy);\n"); WRITE(p, " float yl = floor(uv1.y / %d.0);\n", blkH); WRITE(p, " float yb = yl * %d.0;\n", blkH);