WebGLVertexArray.cpp (2139B)
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/. */ 5 6 #include "WebGLVertexArray.h" 7 8 #include "GLContext.h" 9 #include "WebGLBuffer.h" 10 #include "WebGLContext.h" 11 #include "WebGLVertexArrayFake.h" 12 #include "WebGLVertexArrayGL.h" 13 #include "mozilla/dom/WebGLRenderingContextBinding.h" 14 15 namespace mozilla { 16 17 WebGLVertexArray* WebGLVertexArray::Create(WebGLContext* webgl) { 18 if (webgl->gl->IsSupported(gl::GLFeature::vertex_array_object)) { 19 return new WebGLVertexArrayGL(webgl); 20 } 21 return new WebGLVertexArrayFake(webgl); 22 } 23 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); 30 } 31 } 32 33 WebGLVertexArray::~WebGLVertexArray() = default; 34 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]; 39 40 switch (pname) { 41 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE: 42 return Some(desc.byteStrideOrZero); 43 44 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE: 45 return Some(desc.channels); 46 47 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE: 48 return Some(desc.type); 49 50 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_INTEGER: 51 return Some(desc.intFunc); 52 53 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_DIVISOR: 54 return Some(binding.layout.divisor); 55 56 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED: 57 return Some(binding.layout.isArray); 58 59 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: 60 return Some(desc.normalized); 61 62 case LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER: 63 return Some(binding.layout.byteOffset); 64 65 default: 66 return {}; 67 } 68 } 69 70 } // namespace mozilla