Exemplo n.º 1
0
bool
WebGLTexture::EnsureLevelInitialized(const char* funcName, uint32_t level)
{
    if (mTarget != LOCAL_GL_TEXTURE_CUBE_MAP)
        return EnsureImageDataInitialized(funcName, mTarget.get(), level);

    for (GLenum texImageTarget = LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
         texImageTarget <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
         ++texImageTarget)
    {
        if (!EnsureImageDataInitialized(funcName, texImageTarget, level))
            return false;
    }
    return true;
}
Exemplo n.º 2
0
bool
WebGLTexture::GetFakeBlackType(const char* funcName, uint32_t texUnit,
                               FakeBlackType* const out_fakeBlack)
{
    const char* incompleteReason;
    if (!IsComplete(texUnit, &incompleteReason)) {
        if (incompleteReason) {
            mContext->GenerateWarning("%s: Active texture %u for target 0x%04x is"
                                      " 'incomplete', and will be rendered as"
                                      " RGBA(0,0,0,1), as per the GLES 2.0.24 $3.8.2: %s",
                                      funcName, texUnit, mTarget.get(),
                                      incompleteReason);
        }
        *out_fakeBlack = FakeBlackType::RGBA0001;
        return true;
    }

    // We may still want FakeBlack as an optimization for uninitialized image data.
    bool hasUninitializedData = false;
    bool hasInitializedData = false;

    const auto maxLevel = MaxEffectiveMipmapLevel(texUnit);
    MOZ_ASSERT(mBaseMipmapLevel <= maxLevel);
    for (uint32_t level = mBaseMipmapLevel; level <= maxLevel; level++) {
        for (uint8_t face = 0; face < mFaceCount; face++) {
            const auto& cur = ImageInfoAtFace(face, level);
            if (cur.IsDataInitialized())
                hasInitializedData = true;
            else
                hasUninitializedData = true;
        }
    }
    MOZ_ASSERT(hasUninitializedData || hasInitializedData);

    if (!hasUninitializedData) {
        *out_fakeBlack = FakeBlackType::None;
        return true;
    }

    if (!hasInitializedData) {
        const auto format = ImageInfoAtFace(0, mBaseMipmapLevel).mFormat->format;
        if (format->isColorFormat) {
            *out_fakeBlack = (format->hasAlpha ? FakeBlackType::RGBA0000
                                               : FakeBlackType::RGBA0001);
            return true;
        }

        mContext->GenerateWarning("%s: Active texture %u for target 0x%04x is"
                                  " uninitialized, and will be (perhaps slowly) cleared"
                                  " by the implementation.",
                                  funcName, texUnit, mTarget.get());
    } else {
        mContext->GenerateWarning("%s: Active texture %u for target 0x%04x contains"
                                  " TexImages with uninitialized data along with"
                                  " TexImages with initialized data, forcing the"
                                  " implementation to (slowly) initialize the"
                                  " uninitialized TexImages.",
                                  funcName, texUnit, mTarget.get());
    }

    GLenum baseImageTarget = mTarget.get();
    if (baseImageTarget == LOCAL_GL_TEXTURE_CUBE_MAP)
        baseImageTarget = LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;

    for (uint32_t level = mBaseMipmapLevel; level <= maxLevel; level++) {
        for (uint8_t face = 0; face < mFaceCount; face++) {
            TexImageTarget imageTarget = baseImageTarget + face;
            if (!EnsureImageDataInitialized(funcName, imageTarget, level))
                return false; // The world just exploded.
        }
    }

    *out_fakeBlack = FakeBlackType::None;
    return true;
}