Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / WebGLVertexArrayFake.cpp
blob3a498ea209071202cd8090a5bcd1c9ba9693123e
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"
8 #include "GLContext.h"
9 #include "WebGLBuffer.h"
10 #include "WebGLContext.h"
12 namespace mozilla {
14 static void BindBuffer(gl::GLContext* const gl, const GLenum target,
15 WebGLBuffer* const buffer) {
16 gl->fBindBuffer(target, buffer ? buffer->mGLName : 0);
19 WebGLVertexArrayFake::WebGLVertexArrayFake(WebGLContext* webgl)
20 : WebGLVertexArray(webgl) {}
22 void WebGLVertexArray::DoVertexAttrib(const uint32_t index,
23 const uint32_t vertOffset) const {
24 const auto& gl = mContext->gl;
26 const bool useDivisor =
27 mContext->IsWebGL2() ||
28 mContext->IsExtensionEnabled(WebGLExtensionID::ANGLE_instanced_arrays);
30 const auto& binding = mBindings.at(index);
31 const auto& desc = mDescs.at(index);
33 if (binding.layout.isArray) {
34 gl->fEnableVertexAttribArray(index);
35 } else {
36 gl->fDisableVertexAttribArray(index);
39 if (useDivisor) {
40 gl->fVertexAttribDivisor(index, binding.layout.divisor);
43 static_assert(IsBufferTargetLazilyBound(LOCAL_GL_ARRAY_BUFFER));
44 BindBuffer(gl, LOCAL_GL_ARRAY_BUFFER, binding.buffer);
46 auto desc2 = desc;
47 if (!binding.layout.divisor) {
48 desc2.byteOffset += binding.layout.byteStride * vertOffset;
50 DoVertexAttribPointer(*gl, index, desc2);
52 BindBuffer(gl, LOCAL_GL_ARRAY_BUFFER, nullptr);
55 void WebGLVertexArrayFake::BindVertexArray() {
56 // Go through and re-bind all buffers and setup all
57 // vertex attribute pointers
58 const auto& gl = mContext->gl;
60 mContext->mBoundVertexArray = this;
62 static_assert(IsBufferTargetLazilyBound(LOCAL_GL_ARRAY_BUFFER));
63 static_assert(!IsBufferTargetLazilyBound(LOCAL_GL_ELEMENT_ARRAY_BUFFER));
65 BindBuffer(gl, LOCAL_GL_ELEMENT_ARRAY_BUFFER, mElementArrayBuffer);
67 for (const auto i : IntegerRange(mContext->MaxVertexAttribs())) {
68 DoVertexAttrib(i);
72 } // namespace mozilla