tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebGL2ContextRenderbuffers.cpp (2253B)


      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 "GLContext.h"
      8 #include "WebGL2Context.h"
      9 #include "WebGLContextUtils.h"
     10 #include "WebGLFormats.h"
     11 
     12 namespace mozilla {
     13 
     14 Maybe<std::vector<int32_t>> WebGL2Context::GetInternalformatParameter(
     15    GLenum target, GLenum internalformat, GLenum pname) const {
     16  const FuncScope funcScope(*this, "getInternalformatParameter");
     17  if (IsContextLost()) return Nothing();
     18 
     19  if (target != LOCAL_GL_RENDERBUFFER) {
     20    ErrorInvalidEnum("`target` must be RENDERBUFFER.");
     21    return Nothing();
     22  }
     23 
     24  // GLES 3.0.4 $4.4.4 p212:
     25  // "An internal format is color-renderable if it is one of the formats from
     26  // table 3.13
     27  //  noted as color-renderable or if it is unsized format RGBA or RGB."
     28 
     29  GLenum sizedFormat;
     30  switch (internalformat) {
     31    case LOCAL_GL_RGB:
     32      sizedFormat = LOCAL_GL_RGB8;
     33      break;
     34    case LOCAL_GL_RGBA:
     35      sizedFormat = LOCAL_GL_RGBA8;
     36      break;
     37    default:
     38      sizedFormat = internalformat;
     39      break;
     40  }
     41 
     42  // In RenderbufferStorage, we allow DEPTH_STENCIL. Therefore, it is accepted
     43  // for internalformat as well. Please ignore the conformance test fail for
     44  // DEPTH_STENCIL.
     45 
     46  const auto usage = mFormatUsage->GetRBUsage(sizedFormat);
     47  if (!usage) {
     48    ErrorInvalidEnum(
     49        "`internalformat` must be color-, depth-, or stencil-renderable, was: "
     50        "0x%04x.",
     51        internalformat);
     52    return Nothing();
     53  }
     54 
     55  if (pname != LOCAL_GL_SAMPLES) {
     56    ErrorInvalidEnum("`pname` must be SAMPLES.");
     57    return Nothing();
     58  }
     59 
     60  std::vector<int32_t> ret;
     61  GLint sampleCount = 0;
     62  gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
     63                           LOCAL_GL_NUM_SAMPLE_COUNTS, 1, &sampleCount);
     64  if (sampleCount) {
     65    ret.resize(sampleCount);
     66    gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
     67                             LOCAL_GL_SAMPLES, ret.size(), ret.data());
     68  }
     69 
     70  return Some(ret);
     71 }
     72 
     73 }  // namespace mozilla