Line data Source code
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/. */
5 :
6 : #include "WebGLVertexArray.h"
7 :
8 : #include "GLContext.h"
9 : #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 : #include "WebGLBuffer.h"
11 : #include "WebGLContext.h"
12 : #include "WebGLVertexArrayGL.h"
13 : #include "WebGLVertexArrayFake.h"
14 :
15 : namespace mozilla {
16 :
17 : JSObject*
18 0 : WebGLVertexArray::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
19 : {
20 0 : return dom::WebGLVertexArrayObjectBinding::Wrap(cx, this, givenProto);
21 : }
22 :
23 0 : WebGLVertexArray::WebGLVertexArray(WebGLContext* webgl)
24 : : WebGLRefCountedObject(webgl)
25 0 : , mGLName(0)
26 : {
27 0 : mAttribs.SetLength(mContext->mGLMaxVertexAttribs);
28 0 : mContext->mVertexArrays.insertBack(this);
29 0 : }
30 :
31 0 : WebGLVertexArray::~WebGLVertexArray()
32 : {
33 0 : MOZ_ASSERT(IsDeleted());
34 0 : }
35 :
36 : void
37 0 : WebGLVertexArray::AddBufferBindCounts(int8_t addVal) const
38 : {
39 0 : const GLenum target = 0; // Anything non-TF is fine.
40 0 : WebGLBuffer::AddBindCount(target, mElementArrayBuffer.get(), addVal);
41 0 : for (const auto& attrib : mAttribs) {
42 0 : WebGLBuffer::AddBindCount(target, attrib.mBuf.get(), addVal);
43 : }
44 0 : }
45 :
46 : WebGLVertexArray*
47 0 : WebGLVertexArray::Create(WebGLContext* webgl)
48 : {
49 : WebGLVertexArray* array;
50 0 : if (webgl->gl->IsSupported(gl::GLFeature::vertex_array_object)) {
51 0 : array = new WebGLVertexArrayGL(webgl);
52 : } else {
53 0 : array = new WebGLVertexArrayFake(webgl);
54 : }
55 0 : return array;
56 : }
57 :
58 : void
59 0 : WebGLVertexArray::Delete()
60 : {
61 0 : DeleteImpl();
62 :
63 0 : LinkedListElement<WebGLVertexArray>::removeFrom(mContext->mVertexArrays);
64 0 : mElementArrayBuffer = nullptr;
65 0 : mAttribs.Clear();
66 0 : }
67 :
68 : bool
69 0 : WebGLVertexArray::IsVertexArray() const
70 : {
71 0 : return IsVertexArrayImpl();
72 : }
73 :
74 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLVertexArray,
75 : mAttribs,
76 : mElementArrayBuffer)
77 :
78 0 : NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLVertexArray, AddRef)
79 0 : NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLVertexArray, Release)
80 :
81 : } // namespace mozilla
|