Bug 1326378 - Infer indexed frag output location from base location on OSX. - r=ethlin draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 29 Dec 2016 23:08:37 -0800
changeset 454776 a25031f93e145867c74bc712eb54b8dd504a8af5
parent 454768 89e2f45810c8a686dbf70c4c540be6acd1c2a756
child 540807 2c92ba11c6aa53d07adcdcd3c70b4f0f7ec7d737
push id40038
push userbmo:jgilbert@mozilla.com
push dateFri, 30 Dec 2016 07:09:02 +0000
reviewersethlin
bugs1326378
milestone53.0a1
Bug 1326378 - Infer indexed frag output location from base location on OSX. - r=ethlin MozReview-Commit-ID: Ar07ZnNhu5d
dom/canvas/WebGLProgram.cpp
--- 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);
 }