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
Conflicts:
src/libGLESv2/ProgramBinary.cpp
git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2157 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 1f417f5..a4b0810 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -900,7 +900,7 @@
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
bool usesFragColor = fragmentShader->mUsesFragColor;
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.");
return false;
@@ -912,6 +912,12 @@
const int registersNeeded = registers + (fragmentShader->mUsesFragCoord ? 1 : 0) + (fragmentShader->mUsesPointCoord ? 1 : 0);
+ // Two cases when writing to gl_FragColor and using ESSL 1.0:
+ // - with a 3.0 context, the output color is copied to channel 0
+ // - with a 2.0 context, the output color is broadcast to all channels
+ const bool broadcast = (fragmentShader->mUsesFragColor && mRenderer->getCurrentClientVersion() < 3);
+ const unsigned int numRenderTargets = (broadcast || usesMRT ? mRenderer->getMaxRenderTargets() : 1);
+
if (registersNeeded > maxVaryingVectors)
{
infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord");
@@ -959,8 +965,6 @@
std::string varyingHLSL = generateVaryingHLSL(fragmentShader, varyingSemantic);
- const unsigned int renderTargetCount = usesMRT ? mRenderer->getMaxRenderTargets() : 1;
-
// special varyings that use reserved registers
int reservedRegisterIndex = registers;
std::string fragCoordSemantic;
@@ -1189,9 +1193,9 @@
"struct PS_OUTPUT\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"
@@ -1300,16 +1304,11 @@
"\n"
" PS_OUTPUT output;\n";
- // Two cases when writing to gl_FragColor and using ESSL 1.0:
- // - with a 3.0 context, the output color is copied to channel 0
- // - with a 2.0 context using EXT_draw_buffers, the output color is broadcast to all channels
- const bool broadcast = fragmentShader->mUsesFragColor && mRenderer->getCurrentClientVersion() < 3;
-
- for (unsigned int i = 0; i < renderTargetCount; i++)
+ for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
{
- unsigned int sourceColor = !broadcast ? 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"