1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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"
9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 #include "WebGLBuffer.h"
11 #include "WebGLContext.h"
12 #include "WebGLVertexArrayGL.h"
13 #include "WebGLVertexArrayFake.h"
17 WebGLVertexArray
* WebGLVertexArray::Create(WebGLContext
* webgl
) {
18 if (webgl
->gl
->IsSupported(gl::GLFeature::vertex_array_object
)) {
19 return new WebGLVertexArrayGL(webgl
);
21 return new WebGLVertexArrayFake(webgl
);
24 WebGLVertexArray::WebGLVertexArray(WebGLContext
* const webgl
)
25 : WebGLContextBoundObject(webgl
) {
26 const webgl::VertAttribPointerDesc defaultDesc
;
27 const webgl::VertAttribPointerCalculated defaultCalc
;
28 for (const auto i
: IntegerRange(mContext
->MaxVertexAttribs())) {
29 AttribPointer(i
, nullptr, defaultDesc
, defaultCalc
);
33 WebGLVertexArray::~WebGLVertexArray() = default;
35 Maybe
<double> WebGLVertexArray::GetVertexAttrib(const uint32_t index
,
36 const GLenum pname
) const {
37 const auto& binding
= mBindings
[index
];
38 const auto& desc
= mDescs
[index
];
41 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE
:
42 return Some(desc
.byteStrideOrZero
);
44 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE
:
45 return Some(desc
.channels
);
47 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE
:
48 return Some(desc
.type
);
50 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
51 return Some(desc
.intFunc
);
53 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_DIVISOR
:
54 return Some(binding
.layout
.divisor
);
56 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED
:
57 return Some(binding
.layout
.isArray
);
59 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED
:
60 return Some(desc
.normalized
);
62 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER
:
63 return Some(binding
.layout
.byteOffset
);
70 } // namespace mozilla