1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/WebGLVertexArray.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "WebGLContext.h" 1.10 +#include "WebGLBuffer.h" 1.11 +#include "WebGLVertexArray.h" 1.12 +#include "mozilla/dom/WebGLRenderingContextBinding.h" 1.13 +#include "GLContext.h" 1.14 + 1.15 +using namespace mozilla; 1.16 + 1.17 +JSObject* 1.18 +WebGLVertexArray::WrapObject(JSContext *cx) { 1.19 + return dom::WebGLVertexArrayBinding::Wrap(cx, this); 1.20 +} 1.21 + 1.22 +WebGLVertexArray::WebGLVertexArray(WebGLContext* context) 1.23 + : WebGLContextBoundObject(context) 1.24 + , mGLName(0) 1.25 + , mHasEverBeenBound(false) 1.26 +{ 1.27 + SetIsDOMBinding(); 1.28 +} 1.29 + 1.30 +void WebGLVertexArray::Delete() { 1.31 + if (mGLName != 0) { 1.32 + mBoundElementArrayBuffer = nullptr; 1.33 + 1.34 + mContext->MakeContextCurrent(); 1.35 + mContext->gl->fDeleteVertexArrays(1, &mGLName); 1.36 + LinkedListElement<WebGLVertexArray>::removeFrom(mContext->mVertexArrays); 1.37 + } 1.38 + 1.39 + mBoundElementArrayBuffer = nullptr; 1.40 + mAttribs.Clear(); 1.41 +} 1.42 + 1.43 +bool WebGLVertexArray::EnsureAttrib(GLuint index, const char *info) 1.44 +{ 1.45 + if (index >= GLuint(mContext->mGLMaxVertexAttribs)) { 1.46 + if (index == GLuint(-1)) { 1.47 + mContext->ErrorInvalidValue("%s: index -1 is invalid. That probably comes from a getAttribLocation() call, " 1.48 + "where this return value -1 means that the passed name didn't correspond to an active attribute in " 1.49 + "the specified program.", info); 1.50 + } else { 1.51 + mContext->ErrorInvalidValue("%s: index %d is out of range", info, index); 1.52 + } 1.53 + return false; 1.54 + } 1.55 + else if (index >= mAttribs.Length()) { 1.56 + mAttribs.SetLength(index + 1); 1.57 + } 1.58 + 1.59 + return true; 1.60 +} 1.61 + 1.62 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(WebGLVertexArray, 1.63 + mAttribs, 1.64 + mBoundElementArrayBuffer) 1.65 + 1.66 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray, AddRef) 1.67 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray, Release)