Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLVertexArray.cpp
blob67b424b2e50e50a335a64a485beaa8c6e0b94fe2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLVertexArray.h"
8 #include "WebGLContext.h"
9 #include "WebGLBuffer.h"
10 #include "WebGLVertexArrayGL.h"
11 #include "WebGLVertexArrayFake.h"
12 #include "mozilla/dom/WebGLRenderingContextBinding.h"
13 #include "GLContext.h"
15 using namespace mozilla;
17 JSObject*
18 WebGLVertexArray::WrapObject(JSContext *cx) {
19 return dom::WebGLVertexArrayBinding::Wrap(cx, this);
22 WebGLVertexArray::WebGLVertexArray(WebGLContext* context)
23 : WebGLBindableName()
24 , WebGLContextBoundObject(context)
26 SetIsDOMBinding();
27 context->mVertexArrays.insertBack(this);
30 WebGLVertexArray*
31 WebGLVertexArray::Create(WebGLContext* context)
33 WebGLVertexArray* array;
34 if (context->gl->IsSupported(gl::GLFeature::vertex_array_object)) {
35 array = new WebGLVertexArrayGL(context);
36 } else {
37 array = new WebGLVertexArrayFake(context);
40 return array;
43 void
44 WebGLVertexArray::Delete()
46 DeleteImpl();
48 LinkedListElement<WebGLVertexArray>::removeFrom(mContext->mVertexArrays);
49 mElementArrayBuffer = nullptr;
50 mAttribs.Clear();
53 bool
54 WebGLVertexArray::EnsureAttrib(GLuint index, const char *info)
56 if (index >= GLuint(mContext->mGLMaxVertexAttribs)) {
57 if (index == GLuint(-1)) {
58 mContext->ErrorInvalidValue("%s: index -1 is invalid. That probably comes from a getAttribLocation() call, "
59 "where this return value -1 means that the passed name didn't correspond to an active attribute in "
60 "the specified program.", info);
61 } else {
62 mContext->ErrorInvalidValue("%s: index %d is out of range", info, index);
64 return false;
66 else if (index >= mAttribs.Length()) {
67 mAttribs.SetLength(index + 1);
70 return true;
73 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLVertexArray,
74 mAttribs,
75 mElementArrayBuffer)
77 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray, AddRef)
78 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray, Release)