コード例 #1
0
bool WebGLTexture::IsMipAndCubeComplete(const uint32_t maxLevel,
                                        const bool ensureInit,
                                        bool* const out_initFailed) const {
  *out_initFailed = false;

  // Reference dimensions based on baseLevel.
  auto ref = BaseImageInfo();
  MOZ_ASSERT(ref.mWidth && ref.mHeight && ref.mDepth);

  for (auto level = mBaseMipmapLevel; level <= maxLevel; ++level) {
    // GLES 3.0.4, p161
    // "A cube map texture is mipmap complete if each of the six texture images,
    // considered individually, is mipmap complete."

    for (uint8_t face = 0; face < mFaceCount; face++) {
      auto& cur = ImageInfoAtFace(face, level);

      // "* The set of mipmap arrays `level_base` through `q` (where `q`
      //    is defined the "Mipmapping" discussion of section 3.8.10) were
      //    each specified with the same effective internal format."

      // "* The dimensions of the arrays follow the sequence described in
      //    the "Mipmapping" discussion of section 3.8.10."

      if (cur.mWidth != ref.mWidth || cur.mHeight != ref.mHeight ||
          cur.mDepth != ref.mDepth || cur.mFormat != ref.mFormat) {
        return false;
      }

      if (MOZ_UNLIKELY(ensureInit && !cur.mHasData)) {
        auto imageTarget = mTarget.get();
        if (imageTarget == LOCAL_GL_TEXTURE_CUBE_MAP) {
          imageTarget = LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
        }
        if (!ZeroTextureData(mContext, mGLName, imageTarget, level, cur.mFormat,
                             cur.mWidth, cur.mHeight, cur.mDepth)) {
          mContext->ErrorOutOfMemory("Failed to zero tex image data.");
          *out_initFailed = true;
          return false;
        }
        cur.mHasData = true;
      }
    }

    const auto next = ref.NextMip(mTarget.get());
    if (!next) break;
    ref = next.ref();
  }

  return true;
}
コード例 #2
0
bool WebGLTexture::EnsureImageDataInitialized(const TexImageTarget target,
                                              const uint32_t level) {
  auto& imageInfo = ImageInfoAt(target, level);
  if (!imageInfo.IsDefined()) return true;

  if (imageInfo.mHasData) return true;

  if (!ZeroTextureData(mContext, mGLName, target, level, imageInfo.mFormat,
                       imageInfo.mWidth, imageInfo.mHeight, imageInfo.mDepth)) {
    return false;
  }
  imageInfo.mHasData = true;
  return true;
}
コード例 #3
0
bool
WebGLTexture::InitializeImageData(const char* funcName, TexImageTarget target,
                                  uint32_t level)
{
    auto& imageInfo = ImageInfoAt(target, level);
    MOZ_ASSERT(imageInfo.IsDefined());
    MOZ_ASSERT(!imageInfo.IsDataInitialized());

    const auto& usage = imageInfo.mFormat;
    const auto& width = imageInfo.mWidth;
    const auto& height = imageInfo.mHeight;
    const auto& depth = imageInfo.mDepth;

    if (!ZeroTextureData(mContext, funcName, mGLName, target, level, usage, 0, 0, 0,
                         width, height, depth))
    {
        return false;
    }

    imageInfo.SetIsDataInitialized(true, this);
    return true;
}