b=593850; [webgl] fix gl-object-get-calls test; r=bjacob
authorVladimir Vukicevic <vladimir@pobox.com>
Mon, 13 Sep 2010 08:55:07 -0700
changeset 53696 fc24a510cbd0a760482df376910d5f238f1805f6
parent 53695 3a70f1b0e89405f1fa3b4620c798d2d2b77b81dd
child 53697 1e28bb98f18815ff99015d99399530cb28ca877c
push idunknown
push userunknown
push dateunknown
reviewersbjacob
bugs593850
milestone2.0b6pre
b=593850; [webgl] fix gl-object-get-calls test; r=bjacob
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -1384,28 +1384,32 @@ WebGLContext::GetActiveUniform(nsIWebGLP
 }
 
 NS_IMETHODIMP
 WebGLContext::GetAttachedShaders(nsIWebGLProgram *pobj, nsIVariant **retval)
 {
     *retval = nsnull;
 
     WebGLProgram *prog;
-    if (!GetConcreteObject("getAttachedShaders", pobj, &prog))
+    PRBool isNull;
+    if (!GetConcreteObject("getAttachedShaders", pobj, &prog, &isNull)) 
         return NS_OK;
 
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     MakeContextCurrent();
 
-    if (prog->AttachedShaders().Length() == 0) {
+    if (isNull) {
+        wrval->SetAsVoid();
+        // note no return, we still want to return the variant
+        ErrorInvalidValue("getAttachedShaders: invalid program");
+    } else if (prog->AttachedShaders().Length() == 0) {
         wrval->SetAsEmptyArray();
-    }
-    else {
+    } else {
         wrval->SetAsArray(nsIDataType::VTYPE_INTERFACE,
                         &NS_GET_IID(nsIWebGLShader),
                         prog->AttachedShaders().Length(),
                         const_cast<void*>( // @#$% SetAsArray doesn't accept a const void*
                             static_cast<const void*>(
                                 prog->AttachedShaders().Elements()
                             )
                         )
@@ -1790,16 +1794,20 @@ WebGLContext::GetFramebufferAttachmentPa
                 return ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname);
         }
     } else if (atype == LOCAL_GL_NONE) {
         switch (pname) {
             case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
                 wrval->SetAsInt32(atype);
                 break;
 
+            case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
+                wrval->SetAsEmpty();
+                break;
+
             default:
                 return ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname);
         }
     } else { // GL bug? should never happen
         return NS_ERROR_FAILURE;
     }
 
     *retval = wrval.forget().get();
@@ -2254,27 +2262,32 @@ WebGLContext::GetUniformLocation(nsIWebG
     return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::GetVertexAttrib(WebGLuint index, WebGLenum pname, nsIVariant **retval)
 {
     *retval = nsnull;
 
+    if (index >= mAttribBuffers.Length())
+        return ErrorInvalidValue("getVertexAttrib: invalid index");
+
     nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
     NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
 
     MakeContextCurrent();
 
     switch (pname) {
-        // int
+        case LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
+            wrval->SetAsISupports(mAttribBuffers[index].buf);
+            break;
+
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE:
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE:
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE:
-        case LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
         {
             PRInt32 i = 0;
             gl->fGetVertexAttribiv(index, pname, (GLint*) &i);
             wrval->SetAsInt32(i);
         }
             break;
 
         case LOCAL_GL_CURRENT_VERTEX_ATTRIB:
@@ -2287,41 +2300,53 @@ WebGLContext::GetVertexAttrib(WebGLuint 
                 vec[1] = mVertexAttrib0Vector[1];
                 vec[2] = mVertexAttrib0Vector[2];
                 vec[3] = mVertexAttrib0Vector[3];
             }
             wrval->SetAsArray(nsIDataType::VTYPE_FLOAT, nsnull,
                               4, vec);
         }
             break;
+
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED:
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
         {
             PRInt32 i = 0;
             gl->fGetVertexAttribiv(index, pname, (GLint*) &i);
             wrval->SetAsBool(PRBool(i));
         }
             break;
 
-        // not supported; doesn't make sense to return a pointer unless we have some kind of buffer object abstraction
         case LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER:
+            wrval->SetAsUint32(mAttribBuffers[index].byteOffset);
+            break;
+
         default:
             return ErrorInvalidEnumInfo("getVertexAttrib: parameter", pname);
     }
 
     *retval = wrval.forget().get();
 
     return NS_OK;
 }
 
 /* GLuint getVertexAttribOffset (in GLuint index, in GLenum pname); */
 NS_IMETHODIMP
 WebGLContext::GetVertexAttribOffset(WebGLuint index, WebGLenum pname, WebGLuint *retval)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+    *retval = 0;
+
+    if (index >= mAttribBuffers.Length())
+        return ErrorInvalidValue("getVertexAttribOffset: invalid index");
+
+    if (pname != LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER)
+        return ErrorInvalidEnum("getVertexAttribOffset: bad parameter");
+
+    *retval = mAttribBuffers[index].byteOffset;
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 WebGLContext::Hint(WebGLenum target, WebGLenum mode)
 {
     return NS_OK;
 }