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
;
18 WebGLVertexArray::WrapObject(JSContext
*cx
) {
19 return dom::WebGLVertexArrayBinding::Wrap(cx
, this);
22 WebGLVertexArray::WebGLVertexArray(WebGLContext
* context
)
24 , WebGLContextBoundObject(context
)
27 context
->mVertexArrays
.insertBack(this);
31 WebGLVertexArray::Create(WebGLContext
* context
)
33 WebGLVertexArray
* array
;
34 if (context
->gl
->IsSupported(gl::GLFeature::vertex_array_object
)) {
35 array
= new WebGLVertexArrayGL(context
);
37 array
= new WebGLVertexArrayFake(context
);
44 WebGLVertexArray::Delete()
48 LinkedListElement
<WebGLVertexArray
>::removeFrom(mContext
->mVertexArrays
);
49 mElementArrayBuffer
= nullptr;
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
);
62 mContext
->ErrorInvalidValue("%s: index %d is out of range", info
, index
);
66 else if (index
>= mAttribs
.Length()) {
67 mAttribs
.SetLength(index
+ 1);
73 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLVertexArray
,
77 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray
, AddRef
)
78 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray
, Release
)