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 #ifndef WEBGLVERTEXARRAY_H_
7 #define WEBGLVERTEXARRAY_H_
9 #include "WebGLBindableName.h"
10 #include "WebGLObjectModel.h"
11 #include "WebGLBuffer.h"
12 #include "WebGLVertexAttribData.h"
14 #include "nsWrapperCache.h"
16 #include "mozilla/LinkedList.h"
20 class WebGLVertexArrayFake
;
22 class WebGLVertexArray
23 : public nsWrapperCache
24 , public WebGLBindableName
25 , public WebGLRefCountedObject
<WebGLVertexArray
>
26 , public LinkedListElement
<WebGLVertexArray
>
27 , public WebGLContextBoundObject
29 // -----------------------------------------------------------------------------
32 static WebGLVertexArray
* Create(WebGLContext
* context
);
34 void BindVertexArray() {
35 /* Bind to dummy value to signal that this vertex array has
37 BindTo(LOCAL_GL_VERTEX_ARRAY_BINDING
);
38 BindVertexArrayImpl();
41 virtual void GenVertexArray() = 0;
42 virtual void BindVertexArrayImpl() = 0;
44 GLuint
GLName() const { return mGLName
; }
46 // -------------------------------------------------------------------------
47 // IMPLEMENT PARENT CLASSES
51 virtual void DeleteImpl() = 0;
53 WebGLContext
* GetParentObject() const {
57 virtual JSObject
* WrapObject(JSContext
*cx
) MOZ_OVERRIDE
;
59 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLVertexArray
)
60 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLVertexArray
)
62 // -------------------------------------------------------------------------
65 bool EnsureAttrib(GLuint index
, const char *info
);
66 bool HasAttrib(GLuint index
) {
67 return index
< mAttribs
.Length();
69 bool IsAttribArrayEnabled(GLuint index
) {
70 return HasAttrib(index
) && mAttribs
[index
].enabled
;
74 // -----------------------------------------------------------------------------
77 WebGLVertexArray(WebGLContext
* context
);
79 virtual ~WebGLVertexArray() {
80 MOZ_ASSERT(IsDeleted());
83 // -------------------------------------------------------------------------
86 nsTArray
<WebGLVertexAttribData
> mAttribs
;
87 WebGLRefPtr
<WebGLBuffer
> mElementArrayBuffer
;
89 // -------------------------------------------------------------------------
92 friend class WebGLVertexArrayFake
;
93 friend class WebGLContext
;
96 } // namespace mozilla