michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WebGLContext.h" michael@0: #include "WebGLBuffer.h" michael@0: #include "WebGLVertexArray.h" michael@0: #include "mozilla/dom/WebGLRenderingContextBinding.h" michael@0: #include "GLContext.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: JSObject* michael@0: WebGLVertexArray::WrapObject(JSContext *cx) { michael@0: return dom::WebGLVertexArrayBinding::Wrap(cx, this); michael@0: } michael@0: michael@0: WebGLVertexArray::WebGLVertexArray(WebGLContext* context) michael@0: : WebGLContextBoundObject(context) michael@0: , mGLName(0) michael@0: , mHasEverBeenBound(false) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: void WebGLVertexArray::Delete() { michael@0: if (mGLName != 0) { michael@0: mBoundElementArrayBuffer = nullptr; michael@0: michael@0: mContext->MakeContextCurrent(); michael@0: mContext->gl->fDeleteVertexArrays(1, &mGLName); michael@0: LinkedListElement::removeFrom(mContext->mVertexArrays); michael@0: } michael@0: michael@0: mBoundElementArrayBuffer = nullptr; michael@0: mAttribs.Clear(); michael@0: } michael@0: michael@0: bool WebGLVertexArray::EnsureAttrib(GLuint index, const char *info) michael@0: { michael@0: if (index >= GLuint(mContext->mGLMaxVertexAttribs)) { michael@0: if (index == GLuint(-1)) { michael@0: mContext->ErrorInvalidValue("%s: index -1 is invalid. That probably comes from a getAttribLocation() call, " michael@0: "where this return value -1 means that the passed name didn't correspond to an active attribute in " michael@0: "the specified program.", info); michael@0: } else { michael@0: mContext->ErrorInvalidValue("%s: index %d is out of range", info, index); michael@0: } michael@0: return false; michael@0: } michael@0: else if (index >= mAttribs.Length()) { michael@0: mAttribs.SetLength(index + 1); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(WebGLVertexArray, michael@0: mAttribs, michael@0: mBoundElementArrayBuffer) michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray, AddRef) michael@0: NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray, Release)