Bug 1326378 - Infer indexed frag output location from base location on OSX. - r=ethlin
MozReview-Commit-ID: Ar07ZnNhu5d
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -648,35 +648,62 @@ WebGLProgram::GetAttribLocation(const ns
const webgl::AttribInfo* info;
if (!LinkInfo()->FindAttrib(userName, &info))
return -1;
return GLint(info->mLoc);
}
+static GLint
+GetFragDataByUserName(const WebGLProgram* prog,
+ const nsCString& userName)
+{
+ nsCString mappedName;
+ if (!prog->LinkInfo()->MapFragDataName(userName, &mappedName))
+ return -1;
+
+ return prog->mContext->gl->fGetFragDataLocation(prog->mGLName, mappedName.BeginReading());
+}
+
GLint
WebGLProgram::GetFragDataLocation(const nsAString& userName_wide) const
{
if (!ValidateGLSLVariableName(userName_wide, mContext, "getFragDataLocation"))
return -1;
if (!IsLinked()) {
mContext->ErrorInvalidOperation("getFragDataLocation: `program` must be linked.");
return -1;
}
+
+ const auto& gl = mContext->gl;
+ gl->MakeCurrent();
+
const NS_LossyConvertUTF16toASCII userName(userName_wide);
- nsCString mappedName;
- if (!LinkInfo()->MapFragDataName(userName, &mappedName))
- return -1;
+#ifdef XP_MACOSX
+ if (gl->WorkAroundDriverBugs()) {
+ // OSX doesn't return locs for indexed names, just the base names.
+ // Indicated by failure in: conformance2/programs/gl-get-frag-data-location.html
+ bool isArray;
+ size_t arrayIndex;
+ nsCString baseUserName;
+ if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex))
+ return -1;
- gl::GLContext* gl = mContext->GL();
- gl->MakeCurrent();
- return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading());
+ if (arrayIndex >= mContext->mImplMaxDrawBuffers)
+ return -1;
+
+ const auto baseLoc = GetFragDataByUserName(this, baseUserName);
+ const auto loc = baseLoc + GLint(arrayIndex);
+ return loc;
+ }
+#endif
+ return GetFragDataByUserName(this, userName);
}
void
WebGLProgram::GetProgramInfoLog(nsAString* const out) const
{
CopyASCIItoUTF16(mLinkLog, *out);
}