Bug 1787199 [wpt PR 35620] - Add tests for `VisibilityStateEntry`, a=testonly
[gecko.git] / dom / canvas / WebGL2ContextRenderbuffers.cpp
blob0203ad5c572a50b0a247fbb8029fcf5251db31a8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebGL2Context.h"
9 #include "GLContext.h"
10 #include "WebGLContextUtils.h"
11 #include "WebGLFormats.h"
13 namespace mozilla {
15 Maybe<std::vector<int32_t>> WebGL2Context::GetInternalformatParameter(
16 GLenum target, GLenum internalformat, GLenum pname) const {
17 const FuncScope funcScope(*this, "getInternalfomratParameter");
18 if (IsContextLost()) return Nothing();
20 if (target != LOCAL_GL_RENDERBUFFER) {
21 ErrorInvalidEnum("`target` must be RENDERBUFFER.");
22 return Nothing();
25 // GLES 3.0.4 $4.4.4 p212:
26 // "An internal format is color-renderable if it is one of the formats from
27 // table 3.13
28 // noted as color-renderable or if it is unsized format RGBA or RGB."
30 GLenum sizedFormat;
31 switch (internalformat) {
32 case LOCAL_GL_RGB:
33 sizedFormat = LOCAL_GL_RGB8;
34 break;
35 case LOCAL_GL_RGBA:
36 sizedFormat = LOCAL_GL_RGBA8;
37 break;
38 default:
39 sizedFormat = internalformat;
40 break;
43 // In RenderbufferStorage, we allow DEPTH_STENCIL. Therefore, it is accepted
44 // for internalformat as well. Please ignore the conformance test fail for
45 // DEPTH_STENCIL.
47 const auto usage = mFormatUsage->GetRBUsage(sizedFormat);
48 if (!usage) {
49 ErrorInvalidEnum(
50 "`internalformat` must be color-, depth-, or stencil-renderable, was: "
51 "0x%04x.",
52 internalformat);
53 return Nothing();
56 if (pname != LOCAL_GL_SAMPLES) {
57 ErrorInvalidEnum("`pname` must be SAMPLES.");
58 return Nothing();
61 std::vector<int32_t> ret;
62 GLint sampleCount = 0;
63 gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
64 LOCAL_GL_NUM_SAMPLE_COUNTS, 1, &sampleCount);
65 if (sampleCount) {
66 ret.resize(sampleCount);
67 gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
68 LOCAL_GL_SAMPLES, ret.size(), ret.data());
71 return Some(ret);
74 } // namespace mozilla