Fixed gl_FragCoord.y calculation

TRAC #19349 ANGLEBUG=272 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@925 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e7289839
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 924
#define BUILD_REVISION 925
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -188,7 +188,7 @@ void OutputHLSL::header()
if (mUsesFragCoord)
{
out << "uniform float4 dx_Viewport;\n"
out << "uniform float4 dx_Coord;\n"
"uniform float2 dx_Depth;\n";
}
......
......@@ -1798,11 +1798,13 @@ bool Context::applyRenderTarget(bool ignoreViewport)
GLfloat xy[2] = {1.0f / viewport.Width, -1.0f / viewport.Height};
programObject->setUniform2fv(halfPixelSize, 1, xy);
GLint viewport = programObject->getDxViewportLocation();
GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f,
// These values are used for computing gl_FragCoord in Program::linkVaryings(). The approach depends on Shader Model 3.0 support.
GLint coord = programObject->getDxCoordLocation();
float h = mSupportsShaderModel3 ? mRenderTargetDesc.Height : mState.viewportHeight / 2.0f;
GLfloat whxy[4] = {mState.viewportWidth / 2.0f, h,
(float)mState.viewportX + mState.viewportWidth / 2.0f,
(float)mState.viewportY + mState.viewportHeight / 2.0f};
programObject->setUniform4fv(viewport, 1, whxy);
programObject->setUniform4fv(coord, 1, whxy);
GLint depth = programObject->getDxDepthLocation();
GLfloat dz[2] = {(zFar - zNear) / 2.0f, (zNear + zFar) / 2.0f};
......
......@@ -65,7 +65,7 @@ enum
MAX_TEXTURE_IMAGE_UNITS = 16,
MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF = 4, // For devices supporting vertex texture fetch
MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF,
MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Viewport, dx_Depth, and dx_DepthRange. dx_PointOrLines and dx_FrontCCW use separate bool registers.
MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Coord, dx_Depth, and dx_DepthRange. dx_PointOrLines and dx_FrontCCW use separate bool registers.
MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 3,
MAX_DRAW_BUFFERS = 1,
......
......@@ -1600,13 +1600,20 @@ bool Program::linkVaryings()
if (mFragmentShader->mUsesFragCoord)
{
mPixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
if (sm3) {
if (sm3)
{
// dx_Coord.y contains the render target height. See Context::applyRenderTarget()
mPixelHLSL += " gl_FragCoord.x = input.dx_VPos.x + 0.5;\n"
" gl_FragCoord.y = 2.0 * dx_Viewport.y - input.dx_VPos.y - 0.5;\n";
} else {
mPixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Viewport.x + dx_Viewport.z;\n"
" gl_FragCoord.y = -(input.gl_FragCoord.y * rhw) * dx_Viewport.y + dx_Viewport.w;\n";
" gl_FragCoord.y = dx_Coord.y - input.dx_VPos.y - 0.5;\n";
}
else
{
// dx_Coord contains the viewport width/2, height/2, center.x and center.y. See Context::applyRenderTarget()
mPixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Coord.x + dx_Coord.z;\n"
" gl_FragCoord.y = -(input.gl_FragCoord.y * rhw) * dx_Coord.y + dx_Coord.w;\n";
}
mPixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n"
" gl_FragCoord.w = rhw;\n";
}
......@@ -1732,7 +1739,7 @@ void Program::link()
// are reserved prefixes, and do not receive additional decoration
mDxDepthRangeLocation = getUniformLocation("dx_DepthRange");
mDxDepthLocation = getUniformLocation("dx_Depth");
mDxViewportLocation = getUniformLocation("dx_Viewport");
mDxCoordLocation = getUniformLocation("dx_Coord");
mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize");
mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW");
mDxPointsOrLinesLocation = getUniformLocation("dx_PointsOrLines");
......@@ -2420,7 +2427,7 @@ void Program::unlink(bool destroy)
mDxDepthRangeLocation = -1;
mDxDepthLocation = -1;
mDxViewportLocation = -1;
mDxCoordLocation = -1;
mDxHalfPixelSizeLocation = -1;
mDxFrontCCWLocation = -1;
mDxPointsOrLinesLocation = -1;
......@@ -2841,9 +2848,9 @@ GLint Program::getDxDepthLocation() const
return mDxDepthLocation;
}
GLint Program::getDxViewportLocation() const
GLint Program::getDxCoordLocation() const
{
return mDxViewportLocation;
return mDxCoordLocation;
}
GLint Program::getDxHalfPixelSizeLocation() const
......
......@@ -103,7 +103,7 @@ class Program
GLint getDxDepthRangeLocation() const;
GLint getDxDepthLocation() const;
GLint getDxViewportLocation() const;
GLint getDxCoordLocation() const;
GLint getDxHalfPixelSizeLocation() const;
GLint getDxFrontCCWLocation() const;
GLint getDxPointsOrLinesLocation() const;
......@@ -207,7 +207,7 @@ class Program
GLint mDxDepthRangeLocation;
GLint mDxDepthLocation;
GLint mDxViewportLocation;
GLint mDxCoordLocation;
GLint mDxHalfPixelSizeLocation;
GLint mDxFrontCCWLocation;
GLint mDxPointsOrLinesLocation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment