Compiler - implement gl_FragCoord

TRAC #11381 Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/trunk@21 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 998dd9ff
...@@ -56,12 +56,16 @@ void OutputHLSL::header() ...@@ -56,12 +56,16 @@ void OutputHLSL::header()
} }
} }
out << "uniform float4 gl_Window;\n"
"uniform float2 gl_Depth;\n"
"\n";
out << uniforms; out << uniforms;
out << "\n" out << "\n"
"struct PS_INPUT\n" // FIXME: Prevent name clashes "struct PS_INPUT\n" // FIXME: Prevent name clashes
"{\n"; "{\n";
out << varyingInput; out << varyingInput;
out << "};\n" out << " float4 gl_FragCoord : TEXCOORD" << HLSL_FRAG_COORD_SEMANTIC << ";\n"
"};\n"
"\n"; "\n";
out << varyingGlobals; out << varyingGlobals;
out << "\n" out << "\n"
...@@ -71,6 +75,7 @@ void OutputHLSL::header() ...@@ -71,6 +75,7 @@ void OutputHLSL::header()
"};\n" "};\n"
"\n" "\n"
"static float4 gl_Color[1] = {float4(0, 0, 0, 0)};\n" "static float4 gl_Color[1] = {float4(0, 0, 0, 0)};\n"
"static float4 gl_FragCoord = float4(0, 0, 0, 0);\n"
"\n" "\n"
"float4 gl_texture2D(sampler2D s, float2 t)\n" "float4 gl_texture2D(sampler2D s, float2 t)\n"
"{\n" "{\n"
...@@ -141,13 +146,13 @@ void OutputHLSL::header() ...@@ -141,13 +146,13 @@ void OutputHLSL::header()
} }
} }
out << "uniform float2 gl_HalfPixelSize;\n"; out << "uniform float2 gl_HalfPixelSize;\n"
out << "\n"; "\n";
out << uniforms; out << uniforms;
out << "\n"; out << "\n";
out << globals; out << globals;
out << "\n"; out << "\n"
out << "struct VS_INPUT\n" // FIXME: Prevent name clashes "struct VS_INPUT\n" // FIXME: Prevent name clashes
"{\n"; "{\n";
out << attributeInput; out << attributeInput;
out << "};\n" out << "};\n"
...@@ -157,7 +162,8 @@ void OutputHLSL::header() ...@@ -157,7 +162,8 @@ void OutputHLSL::header()
"struct VS_OUTPUT\n" // FIXME: Prevent name clashes "struct VS_OUTPUT\n" // FIXME: Prevent name clashes
"{\n" "{\n"
" float4 gl_Position : POSITION;\n" " float4 gl_Position : POSITION;\n"
" float gl_PointSize : PSIZE;\n"; " float gl_PointSize : PSIZE;\n"
" float4 gl_FragCoord : TEXCOORD" << HLSL_FRAG_COORD_SEMANTIC << ";\n";
out << varyingOutput; out << varyingOutput;
out << "};\n" out << "};\n"
"\n" "\n"
...@@ -624,7 +630,12 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -624,7 +630,12 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (language == EShLangFragment) if (language == EShLangFragment)
{ {
out << "PS_OUTPUT main(PS_INPUT input)\n" // FIXME: Prevent name clashes out << "PS_OUTPUT main(PS_INPUT input)\n" // FIXME: Prevent name clashes
"{\n"; "{\n"
" float rhw = 1.0 / input.gl_FragCoord.w;\n"
" gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * gl_Window.x + gl_Window.z;\n"
" gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * gl_Window.y + gl_Window.w;\n"
" gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * gl_Depth.x + gl_Depth.y;\n"
" gl_FragCoord.w = rhw;\n";
for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++) for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
{ {
...@@ -728,7 +739,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -728,7 +739,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
" output.gl_Position.y = -(gl_Position.y - gl_HalfPixelSize.y * gl_Position.w);\n" " output.gl_Position.y = -(gl_Position.y - gl_HalfPixelSize.y * gl_Position.w);\n"
" output.gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n" " output.gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
" output.gl_Position.w = gl_Position.w;\n" " output.gl_Position.w = gl_Position.w;\n"
" output.gl_PointSize = gl_PointSize;\n"; " output.gl_PointSize = gl_PointSize;\n"
" output.gl_FragCoord = gl_Position;\n";
TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel(); TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
namespace sh namespace sh
{ {
enum
{
HLSL_FRAG_COORD_SEMANTIC = 15 // Semantic index assigned to the gl_FragCoord varying
};
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
public: public:
......
...@@ -796,6 +796,14 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -796,6 +796,14 @@ bool Context::applyRenderTarget(bool ignoreViewport)
GLfloat xy[2] = {1.0f / description.Width, 1.0f / description.Height}; GLfloat xy[2] = {1.0f / description.Width, 1.0f / description.Height};
programObject->setUniform2fv(halfPixelSize, 1, (GLfloat*)&xy); programObject->setUniform2fv(halfPixelSize, 1, (GLfloat*)&xy);
GLuint window = programObject->getUniformLocation("gl_Window");
GLfloat whxy[4] = {viewportWidth / 2.0f, viewportHeight / 2.0f, (float)viewportX + viewportWidth / 2.0f, (float)viewportY + viewportHeight / 2.0f};
programObject->setUniform4fv(window, 1, (GLfloat*)&whxy);
GLuint depth = programObject->getUniformLocation("gl_Depth");
GLfloat dz[2] = {(zFar - zNear) / 2.0f, (zNear + zFar) / 2.0f};
programObject->setUniform2fv(depth, 1, (GLfloat*)&dz);
GLuint near = programObject->getUniformLocation("gl_DepthRange.near"); GLuint near = programObject->getUniformLocation("gl_DepthRange.near");
programObject->setUniform1fv(near, 1, &zNear); programObject->setUniform1fv(near, 1, &zNear);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "main.h" #include "main.h"
#include "Shaderlang.h" #include "Shaderlang.h"
#include "OutputHLSL.h"
#include "debug.h" #include "debug.h"
namespace gl namespace gl
...@@ -236,7 +237,7 @@ const char *VertexShader::linkHLSL(const char *pixelHLSL) ...@@ -236,7 +237,7 @@ const char *VertexShader::linkHLSL(const char *pixelHLSL)
unsigned int semanticIndex; unsigned int semanticIndex;
int matches = sscanf(input, "%s : TEXCOORD%d;", varyingName, &semanticIndex); int matches = sscanf(input, "%s : TEXCOORD%d;", varyingName, &semanticIndex);
if (matches == 2) if (matches == 2 && semanticIndex != sh::HLSL_FRAG_COORD_SEMANTIC)
{ {
ASSERT(semanticIndex < MAX_VARYING_VECTORS); ASSERT(semanticIndex < MAX_VARYING_VECTORS);
char *varying = strstr(output, varyingName); char *varying = strstr(output, varyingName);
......
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