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 "WebGLVertexArrayFake.h"
9 #include "WebGLBuffer.h"
10 #include "WebGLContext.h"
14 WebGLVertexArrayFake::WebGLVertexArrayFake(WebGLContext
* webgl
)
15 : WebGLVertexArray(webgl
) {}
17 void WebGLVertexArrayFake::BindVertexArray() {
18 // Go through and re-bind all buffers and setup all
19 // vertex attribute pointers
20 const auto& gl
= mContext
->gl
;
22 mContext
->mBoundVertexArray
= this;
24 static_assert(IsBufferTargetLazilyBound(LOCAL_GL_ARRAY_BUFFER
));
25 static_assert(!IsBufferTargetLazilyBound(LOCAL_GL_ELEMENT_ARRAY_BUFFER
));
27 const auto fnBind
= [&](const GLenum target
, WebGLBuffer
* const buffer
) {
28 gl
->fBindBuffer(target
, buffer
? buffer
->mGLName
: 0);
31 fnBind(LOCAL_GL_ELEMENT_ARRAY_BUFFER
, mElementArrayBuffer
);
33 const bool useDivisor
=
34 mContext
->IsWebGL2() ||
35 mContext
->IsExtensionEnabled(WebGLExtensionID::ANGLE_instanced_arrays
);
37 for (const auto i
: IntegerRange(mContext
->MaxVertexAttribs())) {
38 const auto& binding
= mBindings
[i
];
39 const auto& desc
= mDescs
[i
];
41 if (binding
.layout
.isArray
) {
42 gl
->fEnableVertexAttribArray(i
);
44 gl
->fDisableVertexAttribArray(i
);
48 gl
->fVertexAttribDivisor(i
, binding
.layout
.divisor
);
51 fnBind(LOCAL_GL_ARRAY_BUFFER
, binding
.buffer
);
52 DoVertexAttribPointer(*gl
, i
, desc
);
55 fnBind(LOCAL_GL_ARRAY_BUFFER
, nullptr);
58 } // namespace mozilla