b=612334; fix webgl program-test test; r=bjacob
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 16 Nov 2010 20:33:04 -0800
changeset 57637 9d379645288791c6362235ab8698bd52ca5b260a
parent 57636 929ce36f005b860fb411d84cf9d13b2d30665e7d
child 57638 c00572802887a2047d4c53fd51d1ecc40a7ae465
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersbjacob
bugs612334
milestone2.0b8pre
b=612334; fix webgl program-test test; r=bjacob
content/canvas/src/WebGLContext.h
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -1248,29 +1248,29 @@ public:
         return PR_TRUE;
     }
 
     // return true if the shader was found and removed
     PRBool DetachShader(WebGLShader *shader) {
         return mAttachedShaders.RemoveElement(shader);
     }
 
-    PRBool HasBothShaderTypesAttached() {
-        PRBool haveVertex = PR_FALSE;
-        PRBool haveFrag = PR_FALSE;
+    PRBool HasAttachedShaderOfType(GLenum shaderType) {
         for (PRUint32 i = 0; i < mAttachedShaders.Length(); ++i) {
-            if (mAttachedShaders[i]->ShaderType() == LOCAL_GL_FRAGMENT_SHADER)
-                haveFrag = PR_TRUE;
-            else if (mAttachedShaders[i]->ShaderType() == LOCAL_GL_VERTEX_SHADER)
-                haveVertex = PR_TRUE;
-            if (haveFrag && haveVertex)
+            if (mAttachedShaders[i]->ShaderType() == shaderType) {
                 return PR_TRUE;
+            }
         }
+        return PR_FALSE;
+    }
 
-        return PR_FALSE;
+    PRBool HasBothShaderTypesAttached() {
+        return
+            HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) &&
+            HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER);
     }
 
     PRBool NextGeneration()
     {
         if (!(mGeneration+1).valid())
             return PR_FALSE; // must exit without changing mGeneration
         ++mGeneration;
         mMapUniformLocations.Clear();
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -157,16 +157,22 @@ WebGLContext::AttachShader(nsIWebGLProgr
 
     WebGLuint progname, shadername;
     WebGLProgram *program;
     WebGLShader *shader;
     if (!GetConcreteObjectAndGLName("attachShader: program", pobj, &program, &progname) ||
         !GetConcreteObjectAndGLName("attachShader: shader", shobj, &shader, &shadername))
         return NS_OK;
 
+    // Per GLSL ES 2.0, we can only have one of each type of shader
+    // attached.  This renders the next test somewhat moot, but we'll
+    // leave it for when we support more than one shader of each type.
+    if (program->HasAttachedShaderOfType(shader->ShaderType()))
+        return ErrorInvalidOperation("AttachShader: only one of each type of shader may be attached to a program");
+
     if (!program->AttachShader(shader))
         return ErrorInvalidOperation("AttachShader: shader is already attached");
 
     MakeContextCurrent();
 
     gl->fAttachShader(progname, shadername);
 
     return NS_OK;