Scale the vertex coordinates when the viewport has been clamped.

TRAC #22649
Signed-off-by: Geoff Lang
Signed-off-by: Shannon Woods
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1952 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 5ed62aa..14a38d4 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -100,7 +100,7 @@
         }
         else
         {
-            mUniformRegister = 2;   // Reserve registers for dx_DepthRange and dx_HalfPixelSize
+            mUniformRegister = 2;   // Reserve registers for dx_DepthRange and dx_ViewAdjust
         }
     }
     else
@@ -629,7 +629,7 @@
                 out << "uniform float3 dx_DepthRange : register(c0);\n";
             }
 
-            out << "uniform float2 dx_HalfPixelSize : register(c1);\n"
+            out << "uniform float4 dx_ViewAdjust : register(c1);\n"
                    "\n";
         }
 
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index b21e999..6a83793 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -1317,8 +1317,8 @@
                       "    gl_main();\n"
                       "\n"
                       "    VS_OUTPUT output;\n"
-                      "    output.gl_Position.x = gl_Position.x - dx_HalfPixelSize.x * gl_Position.w;\n"
-                      "    output.gl_Position.y = -(gl_Position.y + dx_HalfPixelSize.y * gl_Position.w);\n"
+                      "    output.gl_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
+                      "    output.gl_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
                       "    output.gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
                       "    output.gl_Position.w = gl_Position.w;\n";
     }
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index 493de7e..30cb109 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -72,7 +72,7 @@
 struct dx_VertexConstants
 {
     float depthRange[4];
-    float halfPixelSize[4];
+    float viewAdjust[4];
 };
 
 struct dx_PixelConstants
diff --git a/src/libGLESv2/renderer/Renderer9.cpp b/src/libGLESv2/renderer/Renderer9.cpp
index 9763897..49954ac 100644
--- a/src/libGLESv2/renderer/Renderer9.cpp
+++ b/src/libGLESv2/renderer/Renderer9.cpp
@@ -1093,8 +1093,10 @@
         dx_VertexConstants vc = {0};
         dx_PixelConstants pc = {0};
 
-        vc.halfPixelSize[0] = 1.0f / dxViewport.Width;
-        vc.halfPixelSize[1] = -1.0f / dxViewport.Height;
+        vc.viewAdjust[0] = (float)((actualViewport.width - (int)dxViewport.Width) + 2 * (actualViewport.x - (int)dxViewport.X) - 1) / dxViewport.Width;
+        vc.viewAdjust[1] = (float)((actualViewport.height - (int)dxViewport.Height) + 2 * (actualViewport.y - (int)dxViewport.Y) - 1) / dxViewport.Height;
+        vc.viewAdjust[2] = (float)actualViewport.width / dxViewport.Width;
+        vc.viewAdjust[3] = (float)actualViewport.height / dxViewport.Height;
 
         pc.viewCoords[0] = actualViewport.width  * 0.5f;
         pc.viewCoords[1] = actualViewport.height * 0.5f;
@@ -2273,12 +2275,12 @@
 
 unsigned int Renderer9::getReservedVertexUniformVectors() const
 {
-	return 2;   // dx_HalfPixelSize and dx_DepthRange.
+    return 2;   // dx_ViewAdjust and dx_DepthRange.
 }
 
 unsigned int Renderer9::getReservedFragmentUniformVectors() const
 {
-	return 3;   // dx_ViewCoords, dx_DepthFront and dx_DepthRange.
+    return 3;   // dx_ViewCoords, dx_DepthFront and dx_DepthRange.
 }
 
 unsigned int Renderer9::getMaxVertexUniformVectors() const