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"
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"
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
)) {
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();
39 ErrorInvalidValue("`index` (%u) must be < %s (%u)", index
,
40 "MAX_DRAW_BUFFERS", limit
);
44 std::array
<GLint
, 4> data
= {};
45 gl
->fGetIntegeri_v(pname
, index
, data
.data());
47 if (pname
== LOCAL_GL_COLOR_WRITEMASK
) {
48 val
= (bool(data
[0]) << 0 | bool(data
[1]) << 1 | bool(data
[2]) << 2 |
56 const auto* bindings
= &mIndexedUniformBufferBindings
;
57 const char* limitStr
= "MAX_UNIFORM_BUFFER_BINDINGS";
59 case LOCAL_GL_UNIFORM_BUFFER_START
:
60 case LOCAL_GL_UNIFORM_BUFFER_SIZE
:
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";
70 ErrorInvalidEnumArg("pname", pname
);
74 if (index
>= bindings
->size()) {
75 ErrorInvalidValue("`index` must be < %s.", limitStr
);
78 const auto& binding
= (*bindings
)[index
];
81 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START
:
82 case LOCAL_GL_UNIFORM_BUFFER_START
:
83 return Some(binding
.mRangeStart
);
86 case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
87 case LOCAL_GL_UNIFORM_BUFFER_SIZE
:
88 return Some(binding
.mRangeSize
);
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