|
1 /* -*- Mode: C++; tab-width: 20; 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/. */ |
|
5 |
|
6 #include "WebGLContext.h" |
|
7 #include "WebGLBuffer.h" |
|
8 #include "WebGLVertexArray.h" |
|
9 #include "mozilla/dom/WebGLRenderingContextBinding.h" |
|
10 #include "GLContext.h" |
|
11 |
|
12 using namespace mozilla; |
|
13 |
|
14 JSObject* |
|
15 WebGLVertexArray::WrapObject(JSContext *cx) { |
|
16 return dom::WebGLVertexArrayBinding::Wrap(cx, this); |
|
17 } |
|
18 |
|
19 WebGLVertexArray::WebGLVertexArray(WebGLContext* context) |
|
20 : WebGLContextBoundObject(context) |
|
21 , mGLName(0) |
|
22 , mHasEverBeenBound(false) |
|
23 { |
|
24 SetIsDOMBinding(); |
|
25 } |
|
26 |
|
27 void WebGLVertexArray::Delete() { |
|
28 if (mGLName != 0) { |
|
29 mBoundElementArrayBuffer = nullptr; |
|
30 |
|
31 mContext->MakeContextCurrent(); |
|
32 mContext->gl->fDeleteVertexArrays(1, &mGLName); |
|
33 LinkedListElement<WebGLVertexArray>::removeFrom(mContext->mVertexArrays); |
|
34 } |
|
35 |
|
36 mBoundElementArrayBuffer = nullptr; |
|
37 mAttribs.Clear(); |
|
38 } |
|
39 |
|
40 bool WebGLVertexArray::EnsureAttrib(GLuint index, const char *info) |
|
41 { |
|
42 if (index >= GLuint(mContext->mGLMaxVertexAttribs)) { |
|
43 if (index == GLuint(-1)) { |
|
44 mContext->ErrorInvalidValue("%s: index -1 is invalid. That probably comes from a getAttribLocation() call, " |
|
45 "where this return value -1 means that the passed name didn't correspond to an active attribute in " |
|
46 "the specified program.", info); |
|
47 } else { |
|
48 mContext->ErrorInvalidValue("%s: index %d is out of range", info, index); |
|
49 } |
|
50 return false; |
|
51 } |
|
52 else if (index >= mAttribs.Length()) { |
|
53 mAttribs.SetLength(index + 1); |
|
54 } |
|
55 |
|
56 return true; |
|
57 } |
|
58 |
|
59 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(WebGLVertexArray, |
|
60 mAttribs, |
|
61 mBoundElementArrayBuffer) |
|
62 |
|
63 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray, AddRef) |
|
64 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray, Release) |