Bug 1671598 [wpt PR 26128] - [AspectRatio] Fix divide by zero with a small float...
[gecko.git] / dom / canvas / WebGL2ContextUniforms.cpp
blob2a23ac93076fdb9f51336c4605963b8c4678a19c
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 "WebGL2Context.h"
8 #include "GLContext.h"
9 #include "js/Array.h" // JS::NewArrayObject
10 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
11 #include "mozilla/RefPtr.h"
12 #include "WebGLBuffer.h"
13 #include "WebGLContext.h"
14 #include "WebGLProgram.h"
15 #include "WebGLTransformFeedback.h"
16 #include "WebGLVertexArray.h"
18 namespace mozilla {
20 // -------------------------------------------------------------------------
21 // Uniform Buffer Objects and Transform Feedback Buffers
23 Maybe<double> WebGL2Context::GetIndexedParameter(const GLenum pname,
24 const uint32_t index) const {
25 const FuncScope funcScope(*this, "getIndexedParameter");
26 if (IsContextLost()) return {};
28 const auto* bindings = &mIndexedUniformBufferBindings;
29 const char* limitStr = "MAX_UNIFORM_BUFFER_BINDINGS";
30 switch (pname) {
31 case LOCAL_GL_UNIFORM_BUFFER_START:
32 case LOCAL_GL_UNIFORM_BUFFER_SIZE:
33 break;
35 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
36 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
37 bindings = &(mBoundTransformFeedback->mIndexedBindings);
38 limitStr = "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS";
39 break;
41 default:
42 ErrorInvalidEnumInfo("pname", pname);
43 return {};
46 if (index >= bindings->size()) {
47 ErrorInvalidValue("`index` must be < %s.", limitStr);
48 return {};
50 const auto& binding = (*bindings)[index];
52 switch (pname) {
53 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
54 case LOCAL_GL_UNIFORM_BUFFER_START:
55 return Some(binding.mRangeStart);
56 break;
58 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
59 case LOCAL_GL_UNIFORM_BUFFER_SIZE:
60 return Some(binding.mRangeSize);
62 default:
63 MOZ_CRASH("impossible");
67 void WebGL2Context::UniformBlockBinding(WebGLProgram& program,
68 GLuint uniformBlockIndex,
69 GLuint uniformBlockBinding) {
70 const FuncScope funcScope(*this, "uniformBlockBinding");
71 if (IsContextLost()) return;
73 if (!ValidateObject("program", program)) return;
75 program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding);
78 } // namespace mozilla