DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (e5ef045527c6)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "WebGL2Context.h"

#include "GLContext.h"
#include "WebGLContextUtils.h"
#include "WebGLFormats.h"

namespace mozilla {

void WebGL2Context::GetInternalformatParameter(JSContext* cx, GLenum target,
                                               GLenum internalformat,
                                               GLenum pname,
                                               JS::MutableHandleValue retval,
                                               ErrorResult& out_rv) {
  const FuncScope funcScope(*this, "getInternalfomratParameter");
  retval.setObjectOrNull(nullptr);

  if (IsContextLost()) return;

  if (target != LOCAL_GL_RENDERBUFFER) {
    ErrorInvalidEnum("`target` must be RENDERBUFFER.");
    return;
  }

  // GLES 3.0.4 $4.4.4 p212:
  // "An internal format is color-renderable if it is one of the formats from
  // table 3.13
  //  noted as color-renderable or if it is unsized format RGBA or RGB."

  GLenum sizedFormat;
  switch (internalformat) {
    case LOCAL_GL_RGB:
      sizedFormat = LOCAL_GL_RGB8;
      break;
    case LOCAL_GL_RGBA:
      sizedFormat = LOCAL_GL_RGBA8;
      break;
    default:
      sizedFormat = internalformat;
      break;
  }

  // In RenderbufferStorage, we allow DEPTH_STENCIL. Therefore, it is accepted
  // for internalformat as well. Please ignore the conformance test fail for
  // DEPTH_STENCIL.

  const auto usage = mFormatUsage->GetRBUsage(sizedFormat);
  if (!usage) {
    ErrorInvalidEnum(
        "`internalformat` must be color-, depth-, or stencil-renderable, was: "
        "0x%04x.",
        internalformat);
    return;
  }

  if (pname != LOCAL_GL_SAMPLES) {
    ErrorInvalidEnum("`pname` must be SAMPLES.");
    return;
  }
  std::vector<GLint> samples;
  const auto maxSamples = usage->MaxSamples(*gl);
  if (maxSamples) {  // It might be force-set to 0 for validation reasons!
    GLint sampleCount = 0;
    gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
                             LOCAL_GL_NUM_SAMPLE_COUNTS, 1, &sampleCount);
    samples.resize(uint32_t(sampleCount));
    gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalformat,
                             LOCAL_GL_SAMPLES, samples.size(), samples.data());
  }

  JSObject* obj =
      dom::Int32Array::Create(cx, this, samples.size(), samples.data());
  if (!obj) {
    out_rv = NS_ERROR_OUT_OF_MEMORY;
  }

  retval.setObjectOrNull(obj);
}

}  // namespace mozilla