Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / WebGL2ContextUniforms.cpp
blob5f647a20b84f5955b25664c4ef2717c71f4d845a
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 if (IsExtensionEnabled(WebGLExtensionID::OES_draw_buffers_indexed)) {
29 switch (pname) {
30 case LOCAL_GL_BLEND_EQUATION_RGB:
31 case LOCAL_GL_BLEND_EQUATION_ALPHA:
32 case LOCAL_GL_BLEND_SRC_RGB:
33 case LOCAL_GL_BLEND_SRC_ALPHA:
34 case LOCAL_GL_BLEND_DST_RGB:
35 case LOCAL_GL_BLEND_DST_ALPHA:
36 case LOCAL_GL_COLOR_WRITEMASK: {
37 const auto limit = MaxValidDrawBuffers();
38 if (index >= limit) {
39 ErrorInvalidValue("`index` (%u) must be < %s (%u)", index,
40 "MAX_DRAW_BUFFERS", limit);
41 return {};
44 std::array<GLint, 4> data = {};
45 gl->fGetIntegeri_v(pname, index, data.data());
46 auto val = data[0];
47 if (pname == LOCAL_GL_COLOR_WRITEMASK) {
48 val = (bool(data[0]) << 0 | bool(data[1]) << 1 | bool(data[2]) << 2 |
49 bool(data[3]) << 3);
51 return Some(val);
56 const auto* bindings = &mIndexedUniformBufferBindings;
57 const char* limitStr = "MAX_UNIFORM_BUFFER_BINDINGS";
58 switch (pname) {
59 case LOCAL_GL_UNIFORM_BUFFER_START:
60 case LOCAL_GL_UNIFORM_BUFFER_SIZE:
61 break;
63 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
64 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
65 bindings = &(mBoundTransformFeedback->mIndexedBindings);
66 limitStr = "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS";
67 break;
69 default:
70 ErrorInvalidEnumArg("pname", pname);
71 return {};
74 if (index >= bindings->size()) {
75 ErrorInvalidValue("`index` must be < %s.", limitStr);
76 return {};
78 const auto& binding = (*bindings)[index];
80 switch (pname) {
81 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
82 case LOCAL_GL_UNIFORM_BUFFER_START:
83 return Some(binding.mRangeStart);
84 break;
86 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
87 case LOCAL_GL_UNIFORM_BUFFER_SIZE:
88 return Some(binding.mRangeSize);
90 default:
91 MOZ_CRASH("impossible");
95 void WebGL2Context::UniformBlockBinding(WebGLProgram& program,
96 GLuint uniformBlockIndex,
97 GLuint uniformBlockBinding) {
98 const FuncScope funcScope(*this, "uniformBlockBinding");
99 if (IsContextLost()) return;
101 if (!ValidateObject("program", program)) return;
103 program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding);
106 } // namespace mozilla