Enable broadcasting gl_FragColor to all draw buffer color attachments in ES2 contexts.

TRAC #22888 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2052 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f4b9c7a7
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 1 #define MINOR_VERSION 1
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 2037 #define BUILD_REVISION 2038
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -1165,7 +1165,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1165,7 +1165,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets; bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
bool usesFragColor = fragmentShader->mUsesFragColor; bool usesFragColor = fragmentShader->mUsesFragColor;
bool usesFragData = fragmentShader->mUsesFragData; bool usesFragData = fragmentShader->mUsesFragData;
if (usesMRT && usesFragColor && usesFragData) if (usesFragColor && usesFragData)
{ {
infoLog.append("Cannot use both gl_FragColor and gl_FragData in the same fragment shader."); infoLog.append("Cannot use both gl_FragColor and gl_FragData in the same fragment shader.");
return false; return false;
...@@ -1177,6 +1177,10 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1177,6 +1177,10 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
const int registersNeeded = registers + (fragmentShader->mUsesFragCoord ? 1 : 0) + (fragmentShader->mUsesPointCoord ? 1 : 0); const int registersNeeded = registers + (fragmentShader->mUsesFragCoord ? 1 : 0) + (fragmentShader->mUsesPointCoord ? 1 : 0);
// The output color is broadcast to all enabled draw buffers when writing to gl_FragColor
const bool broadcast = fragmentShader->mUsesFragColor;
const unsigned int numRenderTargets = (broadcast || usesMRT ? mRenderer->getMaxRenderTargets() : 1);
if (registersNeeded > maxVaryingVectors) if (registersNeeded > maxVaryingVectors)
{ {
infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord"); infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord");
...@@ -1222,8 +1226,6 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1222,8 +1226,6 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR"; std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR";
std::string positionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION"; std::string positionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION";
const unsigned int renderTargetCount = usesMRT ? mRenderer->getMaxRenderTargets() : 1;
// special varyings that use reserved registers // special varyings that use reserved registers
int reservedRegisterIndex = registers; int reservedRegisterIndex = registers;
std::string fragCoordSemantic; std::string fragCoordSemantic;
...@@ -1472,9 +1474,9 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1472,9 +1474,9 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
"struct PS_OUTPUT\n" "struct PS_OUTPUT\n"
"{\n"; "{\n";
for (unsigned int i = 0; i < renderTargetCount; i++) for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
{ {
pixelHLSL += " float4 gl_Color" + str(i) + " : " + targetSemantic + str(i) + ";\n"; pixelHLSL += " float4 gl_Color" + str(renderTargetIndex) + " : " + targetSemantic + str(renderTargetIndex) + ";\n";
} }
pixelHLSL += "};\n" pixelHLSL += "};\n"
...@@ -1583,11 +1585,11 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1583,11 +1585,11 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
"\n" "\n"
" PS_OUTPUT output;\n"; " PS_OUTPUT output;\n";
for (unsigned int i = 0; i < renderTargetCount; i++) for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
{ {
unsigned int sourceColor = fragmentShader->mUsesFragData ? i : 0; unsigned int sourceColorIndex = broadcast ? 0 : renderTargetIndex;
pixelHLSL += " output.gl_Color" + str(i) + " = gl_Color[" + str(sourceColor) + "];\n"; pixelHLSL += " output.gl_Color" + str(renderTargetIndex) + " = gl_Color[" + str(sourceColorIndex) + "];\n";
} }
pixelHLSL += "\n" pixelHLSL += "\n"
......
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