/src/mozilla-central/dom/canvas/WebGL2ContextRenderbuffers.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "WebGL2Context.h" |
8 | | |
9 | | #include "GLContext.h" |
10 | | #include "WebGLContextUtils.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | void |
15 | | WebGL2Context::GetInternalformatParameter(JSContext* cx, GLenum target, |
16 | | GLenum internalformat, GLenum pname, |
17 | | JS::MutableHandleValue retval, |
18 | | ErrorResult& out_rv) |
19 | 0 | { |
20 | 0 | const FuncScope funcScope(*this, "getInternalfomratParameter"); |
21 | 0 | retval.setObjectOrNull(nullptr); |
22 | 0 |
|
23 | 0 | if (IsContextLost()) |
24 | 0 | return; |
25 | 0 | |
26 | 0 | if (target != LOCAL_GL_RENDERBUFFER) { |
27 | 0 | ErrorInvalidEnum("`target` must be RENDERBUFFER."); |
28 | 0 | return; |
29 | 0 | } |
30 | 0 | |
31 | 0 | // GLES 3.0.4 $4.4.4 p212: |
32 | 0 | // "An internal format is color-renderable if it is one of the formats from table 3.13 |
33 | 0 | // noted as color-renderable or if it is unsized format RGBA or RGB." |
34 | 0 | |
35 | 0 | GLenum sizedFormat; |
36 | 0 | switch (internalformat) { |
37 | 0 | case LOCAL_GL_RGB: |
38 | 0 | sizedFormat = LOCAL_GL_RGB8; |
39 | 0 | break; |
40 | 0 | case LOCAL_GL_RGBA: |
41 | 0 | sizedFormat = LOCAL_GL_RGBA8; |
42 | 0 | break; |
43 | 0 | default: |
44 | 0 | sizedFormat = internalformat; |
45 | 0 | break; |
46 | 0 | } |
47 | 0 | |
48 | 0 | // In RenderbufferStorage, we allow DEPTH_STENCIL. Therefore, it is accepted for |
49 | 0 | // internalformat as well. Please ignore the conformance test fail for DEPTH_STENCIL. |
50 | 0 | |
51 | 0 | const auto usage = mFormatUsage->GetRBUsage(sizedFormat); |
52 | 0 | if (!usage) { |
53 | 0 | ErrorInvalidEnum("`internalformat` must be color-, depth-, or stencil-renderable, was: 0x%04x.", |
54 | 0 | internalformat); |
55 | 0 | return; |
56 | 0 | } |
57 | 0 | |
58 | 0 | if (pname != LOCAL_GL_SAMPLES) { |
59 | 0 | ErrorInvalidEnum("`pname` must be SAMPLES."); |
60 | 0 | return; |
61 | 0 | } |
62 | 0 | |
63 | 0 | GLint* samples = nullptr; |
64 | 0 | GLint sampleCount = 0; |
65 | 0 | gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat, |
66 | 0 | LOCAL_GL_NUM_SAMPLE_COUNTS, 1, &sampleCount); |
67 | 0 | if (sampleCount > 0) { |
68 | 0 | samples = new GLint[sampleCount]; |
69 | 0 | gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat, LOCAL_GL_SAMPLES, |
70 | 0 | sampleCount, samples); |
71 | 0 | } |
72 | 0 |
|
73 | 0 | JSObject* obj = dom::Int32Array::Create(cx, this, sampleCount, samples); |
74 | 0 | if (!obj) { |
75 | 0 | out_rv = NS_ERROR_OUT_OF_MEMORY; |
76 | 0 | } |
77 | 0 |
|
78 | 0 | delete[] samples; |
79 | 0 |
|
80 | 0 | retval.setObjectOrNull(obj); |
81 | 0 | } |
82 | | |
83 | | } // namespace mozilla |