2012-10-04 13:35:54 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2012-12-03 16:13:47 -08:00
|
|
|
#include "WebGLTexture.h"
|
2014-04-30 14:30:21 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#include <algorithm>
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2014-04-30 14:30:21 -07:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2014-04-30 14:30:21 -07:00
|
|
|
#include "mozilla/Scoped.h"
|
2013-11-25 19:25:25 -08:00
|
|
|
#include "ScopedGLHelpers.h"
|
2014-04-30 14:30:21 -07:00
|
|
|
#include "WebGLContext.h"
|
2014-05-01 20:15:58 -07:00
|
|
|
#include "WebGLContextUtils.h"
|
2013-10-11 06:16:43 -07:00
|
|
|
#include "WebGLTexelConversions.h"
|
2014-04-30 14:30:21 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
namespace mozilla {
|
2012-10-04 13:35:54 -07:00
|
|
|
|
|
|
|
JSObject*
|
2014-11-16 18:21:04 -08:00
|
|
|
WebGLTexture::WrapObject(JSContext* cx) {
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::WebGLTextureBinding::Wrap(cx, this);
|
2012-10-04 13:35:54 -07:00
|
|
|
}
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::WebGLTexture(WebGLContext* webgl, GLuint tex)
|
2014-11-16 18:21:04 -08:00
|
|
|
: WebGLBindableName<TexTarget>(tex)
|
2014-11-13 20:03:50 -08:00
|
|
|
, WebGLContextBoundObject(webgl)
|
2012-12-03 16:13:47 -08:00
|
|
|
, mMinFilter(LOCAL_GL_NEAREST_MIPMAP_LINEAR)
|
|
|
|
, mMagFilter(LOCAL_GL_LINEAR)
|
|
|
|
, mWrapS(LOCAL_GL_REPEAT)
|
|
|
|
, mWrapT(LOCAL_GL_REPEAT)
|
|
|
|
, mFacesCount(0)
|
|
|
|
, mMaxLevelWithCustomImages(0)
|
|
|
|
, mHaveGeneratedMipmap(false)
|
2014-07-14 16:55:56 -07:00
|
|
|
, mImmutable(false)
|
2014-10-16 13:07:01 -07:00
|
|
|
, mBaseMipmapLevel(0)
|
|
|
|
, mMaxMipmapLevel(1000)
|
2013-10-11 06:16:43 -07:00
|
|
|
, mFakeBlackStatus(WebGLTextureFakeBlackStatus::IncompleteTexture)
|
2012-12-03 16:13:47 -08:00
|
|
|
{
|
|
|
|
mContext->mTextures.insertBack(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::Delete()
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
mImageInfos.Clear();
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteTextures(1, &mGLName);
|
|
|
|
LinkedListElement<WebGLTexture>::removeFrom(mContext->mTextures);
|
|
|
|
}
|
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
size_t
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::ImageInfo::MemoryUsage() const
|
|
|
|
{
|
2013-10-11 06:16:43 -07:00
|
|
|
if (mImageDataStatus == WebGLImageDataStatus::NoImageData)
|
2012-12-03 16:13:47 -08:00
|
|
|
return 0;
|
2014-11-13 20:03:50 -08:00
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
size_t bitsPerTexel = GetBitsPerTexel(mEffectiveInternalFormat);
|
|
|
|
return size_t(mWidth) * size_t(mHeight) * size_t(mDepth) * bitsPerTexel / 8;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
size_t
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::MemoryUsage() const
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
if (IsDeleted())
|
|
|
|
return 0;
|
2014-11-13 20:03:50 -08:00
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
size_t result = 0;
|
2012-12-03 16:13:47 -08:00
|
|
|
for(size_t face = 0; face < mFacesCount; face++) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for(size_t level = 0; level <= mMaxLevelWithCustomImages; level++) {
|
|
|
|
result += ImageInfoAtFace(face, level).MemoryUsage();
|
2014-10-16 13:04:35 -07:00
|
|
|
}
|
2014-11-13 20:03:50 -08:00
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-16 13:07:01 -07:00
|
|
|
static inline size_t
|
2014-11-13 20:03:50 -08:00
|
|
|
MipmapLevelsForSize(const WebGLTexture::ImageInfo& info)
|
2014-10-16 13:07:01 -07:00
|
|
|
{
|
|
|
|
GLsizei size = std::max(std::max(info.Width(), info.Height()), info.Depth());
|
|
|
|
|
|
|
|
// Find floor(log2(size)). (ES 3.0.4, 3.8 - Mipmapping).
|
|
|
|
return mozilla::FloorLog2(size);
|
|
|
|
}
|
|
|
|
|
2012-12-03 16:13:47 -08:00
|
|
|
bool
|
2014-10-13 16:42:20 -07:00
|
|
|
WebGLTexture::DoesMipmapHaveAllLevelsConsistentlyDefined(TexImageTarget texImageTarget) const
|
|
|
|
{
|
2014-10-16 13:07:01 -07:00
|
|
|
// We could not have generated a mipmap if the base image wasn't defined.
|
2012-12-03 16:13:47 -08:00
|
|
|
if (mHaveGeneratedMipmap)
|
|
|
|
return true;
|
|
|
|
|
2014-10-16 13:07:01 -07:00
|
|
|
if (!IsMipmapRangeValid())
|
|
|
|
return false;
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
// We want a copy here so we can modify it temporarily.
|
2014-11-13 20:03:50 -08:00
|
|
|
ImageInfo expected = ImageInfoAt(texImageTarget,
|
|
|
|
EffectiveBaseMipmapLevel());
|
2014-10-16 13:07:01 -07:00
|
|
|
if (!expected.IsPositive())
|
|
|
|
return false;
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-10-16 13:07:01 -07:00
|
|
|
// If Level{max} is > mMaxLevelWithCustomImages, then check if we are
|
|
|
|
// missing any image levels.
|
|
|
|
if (mMaxMipmapLevel > mMaxLevelWithCustomImages) {
|
|
|
|
if (MipmapLevelsForSize(expected) > mMaxLevelWithCustomImages)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks if custom images are all defined up to the highest level and
|
|
|
|
// have the expected dimensions.
|
2014-11-13 20:03:50 -08:00
|
|
|
for (size_t level = EffectiveBaseMipmapLevel();
|
|
|
|
level <= EffectiveMaxMipmapLevel(); ++level)
|
|
|
|
{
|
2013-10-01 17:30:38 -07:00
|
|
|
const ImageInfo& actual = ImageInfoAt(texImageTarget, level);
|
2012-12-03 16:13:47 -08:00
|
|
|
if (actual != expected)
|
|
|
|
return false;
|
2014-10-16 13:07:01 -07:00
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
expected.mWidth = std::max(1, expected.mWidth / 2);
|
|
|
|
expected.mHeight = std::max(1, expected.mHeight / 2);
|
|
|
|
expected.mDepth = std::max(1, expected.mDepth / 2);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// If the current level has size 1x1, we can stop here: The spec doesn't
|
|
|
|
// seem to forbid the existence of extra useless levels.
|
2014-10-13 16:42:20 -07:00
|
|
|
if (actual.mWidth == 1 &&
|
|
|
|
actual.mHeight == 1 &&
|
|
|
|
actual.mDepth == 1)
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
return true;
|
2014-10-13 16:42:20 -07:00
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
2014-10-16 13:07:01 -07:00
|
|
|
return true;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::Bind(TexTarget texTarget)
|
|
|
|
{
|
|
|
|
// This function should only be called by bindTexture(). It assumes that the
|
|
|
|
// GL context is already current.
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-05-06 20:11:18 -07:00
|
|
|
bool firstTimeThisTextureIsBound = !HasEverBeenBound();
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-05-06 20:11:18 -07:00
|
|
|
if (firstTimeThisTextureIsBound) {
|
2014-11-13 20:03:50 -08:00
|
|
|
BindTo(texTarget);
|
|
|
|
} else if (texTarget != Target()) {
|
|
|
|
mContext->ErrorInvalidOperation("bindTexture: This texture has already"
|
|
|
|
" been bound to a different target.");
|
|
|
|
// Very important to return here before modifying texture state! This
|
|
|
|
// was the place when I lost a whole day figuring very strange "invalid
|
|
|
|
// write" crashes.
|
2012-12-03 16:13:47 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-06 20:11:18 -07:00
|
|
|
GLuint name = GLName();
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->gl->fBindTexture(texTarget.get(), name);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
|
|
|
if (firstTimeThisTextureIsBound) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mFacesCount = (texTarget == LOCAL_GL_TEXTURE_CUBE_MAP) ? 6 : 1;
|
2012-12-03 16:13:47 -08:00
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(0);
|
2013-10-11 06:16:43 -07:00
|
|
|
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// Thanks to the WebKit people for finding this out: GL_TEXTURE_WRAP_R
|
|
|
|
// is not present in GLES 2, but is present in GL and it seems as if for
|
|
|
|
// cube maps we need to set it to GL_CLAMP_TO_EDGE to get the expected
|
|
|
|
// GLES behavior.
|
|
|
|
if (mTarget == LOCAL_GL_TEXTURE_CUBE_MAP && !mContext->gl->IsGLES()) {
|
|
|
|
mContext->gl->fTexParameteri(texTarget.get(),
|
|
|
|
LOCAL_GL_TEXTURE_WRAP_R,
|
|
|
|
LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::SetImageInfo(TexImageTarget texImageTarget, GLint level,
|
|
|
|
GLsizei width, GLsizei height, GLsizei depth,
|
|
|
|
TexInternalFormat effectiveInternalFormat,
|
|
|
|
WebGLImageDataStatus status)
|
2012-12-03 16:13:47 -08:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_ASSERT(depth == 1 || texImageTarget == LOCAL_GL_TEXTURE_3D);
|
|
|
|
MOZ_ASSERT(TexImageTargetToTexTarget(texImageTarget) == mTarget);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(level);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
ImageInfoAt(texImageTarget, level) = ImageInfo(width, height, depth,
|
|
|
|
effectiveInternalFormat,
|
|
|
|
status);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (level > 0)
|
2012-12-03 16:13:47 -08:00
|
|
|
SetCustomMipmap();
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// Invalidate framebuffer status cache.
|
2014-03-03 23:14:35 -08:00
|
|
|
NotifyFBsStatusChanged();
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::SetGeneratedMipmap()
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
if (!mHaveGeneratedMipmap) {
|
|
|
|
mHaveGeneratedMipmap = true;
|
2013-10-11 06:16:43 -07:00
|
|
|
SetFakeBlackStatus(WebGLTextureFakeBlackStatus::Unknown);
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::SetCustomMipmap()
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
if (mHaveGeneratedMipmap) {
|
2014-10-16 13:07:01 -07:00
|
|
|
if (!IsMipmapRangeValid())
|
|
|
|
return;
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// If we were in GeneratedMipmap mode and are now switching to
|
|
|
|
// CustomMipmap mode, we now need to compute all the mipmap image info.
|
2014-10-16 13:07:01 -07:00
|
|
|
ImageInfo imageInfo = ImageInfoAtFace(0, EffectiveBaseMipmapLevel());
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_ASSERT(mContext->IsWebGL2() || imageInfo.IsPowerOfTwo(),
|
|
|
|
"This texture is NPOT, so how could GenerateMipmap() ever"
|
|
|
|
" accept it?");
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
size_t maxRelativeLevel = MipmapLevelsForSize(imageInfo);
|
|
|
|
size_t maxLevel = EffectiveBaseMipmapLevel() + maxRelativeLevel;
|
|
|
|
EnsureMaxLevelWithCustomImagesAtLeast(maxLevel);
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
for (size_t level = EffectiveBaseMipmapLevel() + 1;
|
|
|
|
level <= EffectiveMaxMipmapLevel(); ++level)
|
|
|
|
{
|
2014-10-13 16:42:20 -07:00
|
|
|
imageInfo.mWidth = std::max(imageInfo.mWidth / 2, 1);
|
|
|
|
imageInfo.mHeight = std::max(imageInfo.mHeight / 2, 1);
|
|
|
|
imageInfo.mDepth = std::max(imageInfo.mDepth / 2, 1);
|
2014-11-13 20:03:50 -08:00
|
|
|
for(size_t face = 0; face < mFacesCount; ++face) {
|
2013-10-01 17:30:38 -07:00
|
|
|
ImageInfoAtFace(face, level) = imageInfo;
|
2014-11-13 20:03:50 -08:00
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mHaveGeneratedMipmap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::AreAllLevel0ImageInfosEqual() const
|
|
|
|
{
|
2012-12-03 16:13:47 -08:00
|
|
|
for (size_t face = 1; face < mFacesCount; ++face) {
|
2013-10-01 17:30:38 -07:00
|
|
|
if (ImageInfoAtFace(face, 0) != ImageInfoAtFace(0, 0))
|
2012-12-03 16:13:47 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::IsMipmapComplete() const
|
|
|
|
{
|
2014-10-13 16:42:20 -07:00
|
|
|
MOZ_ASSERT(mTarget == LOCAL_GL_TEXTURE_2D ||
|
|
|
|
mTarget == LOCAL_GL_TEXTURE_3D);
|
|
|
|
return DoesMipmapHaveAllLevelsConsistentlyDefined(LOCAL_GL_TEXTURE_2D);
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::IsCubeComplete() const
|
|
|
|
{
|
2014-10-13 16:42:20 -07:00
|
|
|
MOZ_ASSERT(mTarget == LOCAL_GL_TEXTURE_CUBE_MAP);
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
const ImageInfo& first = ImageInfoAt(LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
|
|
0);
|
2012-12-03 16:13:47 -08:00
|
|
|
if (!first.IsPositive() || !first.IsSquare())
|
|
|
|
return false;
|
2014-11-13 20:03:50 -08:00
|
|
|
|
2012-12-03 16:13:47 -08:00
|
|
|
return AreAllLevel0ImageInfosEqual();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::IsMipmapCubeComplete() const
|
|
|
|
{
|
|
|
|
// In particular, this checks that this is a cube map:
|
|
|
|
if (!IsCubeComplete())
|
2012-12-03 16:13:47 -08:00
|
|
|
return false;
|
2014-11-13 20:03:50 -08:00
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2014-11-13 20:03:50 -08:00
|
|
|
const TexImageTarget face = TexImageTargetForTargetAndFace(LOCAL_GL_TEXTURE_CUBE_MAP,
|
|
|
|
i);
|
2014-10-13 16:42:20 -07:00
|
|
|
if (!DoesMipmapHaveAllLevelsConsistentlyDefined(face))
|
2012-12-03 16:13:47 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-16 13:07:01 -07:00
|
|
|
bool
|
|
|
|
WebGLTexture::IsMipmapRangeValid() const
|
|
|
|
{
|
|
|
|
// In ES3, if a texture is immutable, the mipmap levels are clamped.
|
|
|
|
if (IsImmutable())
|
|
|
|
return true;
|
|
|
|
if (mBaseMipmapLevel > std::min(mMaxLevelWithCustomImages, mMaxMipmapLevel))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLTextureFakeBlackStatus
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::ResolvedFakeBlackStatus()
|
|
|
|
{
|
|
|
|
if (MOZ_LIKELY(mFakeBlackStatus != WebGLTextureFakeBlackStatus::Unknown))
|
2013-10-11 06:16:43 -07:00
|
|
|
return mFakeBlackStatus;
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
// Determine if the texture needs to be faked as a black texture.
|
2014-10-16 13:07:01 -07:00
|
|
|
// See 3.8.2 Shader Execution in the OpenGL ES 2.0.24 spec, and 3.8.13 in
|
|
|
|
// the OpenGL ES 3.0.4 spec.
|
|
|
|
if (!IsMipmapRangeValid()) {
|
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
|
|
|
return mFakeBlackStatus;
|
|
|
|
}
|
2014-11-13 20:03:50 -08:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLImageDataStatus status = ImageInfoAtFace(face, EffectiveBaseMipmapLevel()).mImageDataStatus;
|
|
|
|
if (status == WebGLImageDataStatus::NoImageData) {
|
|
|
|
// In case of undefined texture image, we don't print any message
|
|
|
|
// because this is a very common and often legitimate case
|
|
|
|
// (asynchronous texture loading).
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
|
|
|
return mFakeBlackStatus;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
const char preamble[] = "A texture is going to be rendered as if it were"
|
|
|
|
" black, as per the OpenGL ES 2.0.24 spec section"
|
|
|
|
" 3.8.2, because it";
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-10-13 16:42:20 -07:00
|
|
|
if (mTarget == LOCAL_GL_TEXTURE_2D ||
|
|
|
|
mTarget == LOCAL_GL_TEXTURE_3D)
|
2013-10-11 06:16:43 -07:00
|
|
|
{
|
2014-10-13 16:42:20 -07:00
|
|
|
int dim = mTarget == LOCAL_GL_TEXTURE_2D ? 2 : 3;
|
2014-11-13 20:03:50 -08:00
|
|
|
if (DoesMinFilterRequireMipmap()) {
|
2014-10-13 16:42:20 -07:00
|
|
|
if (!IsMipmapComplete()) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a %dD texture, with a"
|
|
|
|
" minification filter requiring a"
|
|
|
|
" mipmap, and is not mipmap complete"
|
|
|
|
" (as defined in section 3.7.10).",
|
|
|
|
preamble, dim);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2014-11-13 20:03:50 -08:00
|
|
|
} else if (!mContext->IsWebGL2() &&
|
|
|
|
!ImageInfoBase().IsPowerOfTwo())
|
|
|
|
{
|
|
|
|
mContext->GenerateWarning("%s is a %dD texture, with a"
|
|
|
|
" minification filter requiring a"
|
|
|
|
" mipmap, and either its width or"
|
|
|
|
" height is not a power of two.",
|
|
|
|
preamble, dim);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
2014-11-13 20:03:50 -08:00
|
|
|
} else {
|
|
|
|
// No mipmap required here.
|
2014-09-18 16:14:22 -07:00
|
|
|
if (!ImageInfoBase().IsPositive()) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a %dD texture and its width or"
|
|
|
|
" height is equal to zero.",
|
|
|
|
preamble, dim);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2014-11-13 20:03:50 -08:00
|
|
|
} else if (!AreBothWrapModesClampToEdge() &&
|
|
|
|
!mContext->IsWebGL2() &&
|
|
|
|
!ImageInfoBase().IsPowerOfTwo())
|
|
|
|
{
|
|
|
|
mContext->GenerateWarning("%s is a %dD texture, with a"
|
|
|
|
" minification filter not requiring a"
|
|
|
|
" mipmap, with its width or height"
|
|
|
|
" not a power of two, and with a wrap"
|
|
|
|
" mode different from CLAMP_TO_EDGE.",
|
|
|
|
preamble, dim);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
}
|
2014-11-13 20:03:50 -08:00
|
|
|
} else {
|
|
|
|
// Cube map
|
2014-10-14 19:10:15 -07:00
|
|
|
bool legalImageSize = true;
|
|
|
|
if (!mContext->IsWebGL2()) {
|
|
|
|
for (size_t face = 0; face < mFacesCount; ++face)
|
|
|
|
legalImageSize &= ImageInfoAtFace(face, 0).IsPowerOfTwo();
|
|
|
|
}
|
2012-12-03 16:13:47 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (DoesMinFilterRequireMipmap()) {
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!IsMipmapCubeComplete()) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a cube map texture, with a"
|
|
|
|
" minification filter requiring a"
|
|
|
|
" mipmap, and is not mipmap cube"
|
|
|
|
" complete (as defined in section"
|
|
|
|
" 3.7.10).", preamble);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2014-10-14 19:10:15 -07:00
|
|
|
} else if (!legalImageSize) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a cube map texture, with a"
|
|
|
|
" minification filter requiring a"
|
|
|
|
" mipmap, and either the width or the"
|
|
|
|
" height of some level 0 image is not"
|
|
|
|
" a power of two.", preamble);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2013-06-10 13:00:46 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
|
|
|
else // no mipmap required
|
|
|
|
{
|
|
|
|
if (!IsCubeComplete()) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a cube map texture, with a"
|
|
|
|
" minification filter not requiring a"
|
|
|
|
" mipmap, and is not cube complete"
|
|
|
|
" (as defined in section 3.7.10).",
|
|
|
|
preamble);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2014-10-14 19:10:15 -07:00
|
|
|
} else if (!AreBothWrapModesClampToEdge() && !legalImageSize) {
|
2014-11-13 20:03:50 -08:00
|
|
|
mContext->GenerateWarning("%s is a cube map texture, with a"
|
|
|
|
" minification filter not requiring a"
|
|
|
|
" mipmap, with some level 0 image"
|
|
|
|
" having width or height not a power"
|
|
|
|
" of two, and with a wrap mode"
|
|
|
|
" different from CLAMP_TO_EDGE.",
|
|
|
|
preamble);
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
2013-06-10 13:00:46 -07:00
|
|
|
}
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 16:52:58 -07:00
|
|
|
TexType type = TypeFromInternalFormat(ImageInfoBase().mEffectiveInternalFormat);
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
const char* badFormatText = nullptr;
|
|
|
|
const char* extText = nullptr;
|
|
|
|
|
2014-10-07 16:52:58 -07:00
|
|
|
if (type == LOCAL_GL_FLOAT &&
|
2014-04-25 19:34:07 -07:00
|
|
|
!Context()->IsExtensionEnabled(WebGLExtensionID::OES_texture_float_linear))
|
2013-10-11 06:16:43 -07:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
badFormatText = "FLOAT";
|
|
|
|
extText = "OES_texture_float_linear";
|
2014-10-07 16:52:58 -07:00
|
|
|
} else if (type == LOCAL_GL_HALF_FLOAT &&
|
2014-04-25 19:34:07 -07:00
|
|
|
!Context()->IsExtensionEnabled(WebGLExtensionID::OES_texture_half_float_linear))
|
2014-01-23 13:47:37 -08:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
badFormatText = "HALF_FLOAT";
|
|
|
|
extText = "OES_texture_half_float_linear";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* badFilterText = nullptr;
|
|
|
|
if (badFormatText) {
|
2014-01-23 13:47:37 -08:00
|
|
|
if (mMinFilter == LOCAL_GL_LINEAR ||
|
|
|
|
mMinFilter == LOCAL_GL_LINEAR_MIPMAP_LINEAR ||
|
|
|
|
mMinFilter == LOCAL_GL_LINEAR_MIPMAP_NEAREST ||
|
|
|
|
mMinFilter == LOCAL_GL_NEAREST_MIPMAP_LINEAR)
|
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
badFilterText = "minification";
|
|
|
|
} else if (mMagFilter == LOCAL_GL_LINEAR) {
|
|
|
|
badFilterText = "magnification";
|
2014-01-23 13:47:37 -08:00
|
|
|
}
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (badFilterText) {
|
|
|
|
mContext->GenerateWarning("%s is a texture with a linear %s filter,"
|
|
|
|
" which is not compatible with format %s by"
|
|
|
|
" default. Try enabling the %s extension, if"
|
|
|
|
" supported.", preamble, badFilterText,
|
|
|
|
badFormatText, extText);
|
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::IncompleteTexture;
|
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
// We have exhausted all cases of incomplete textures, where we would need opaque black.
|
|
|
|
// We may still need transparent black in case of uninitialized image data.
|
|
|
|
bool hasUninitializedImageData = false;
|
|
|
|
for (size_t level = 0; level <= mMaxLevelWithCustomImages; ++level) {
|
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
2014-11-13 20:03:50 -08:00
|
|
|
bool cur = (ImageInfoAtFace(face, level).mImageDataStatus == WebGLImageDataStatus::UninitializedImageData);
|
|
|
|
hasUninitializedImageData |= cur;
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (hasUninitializedImageData) {
|
2013-10-11 06:16:43 -07:00
|
|
|
bool hasAnyInitializedImageData = false;
|
|
|
|
for (size_t level = 0; level <= mMaxLevelWithCustomImages; ++level) {
|
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
|
|
|
if (ImageInfoAtFace(face, level).mImageDataStatus == WebGLImageDataStatus::InitializedImageData) {
|
|
|
|
hasAnyInitializedImageData = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasAnyInitializedImageData) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasAnyInitializedImageData) {
|
2014-11-13 20:03:50 -08:00
|
|
|
/* The texture contains some initialized image data, and some
|
|
|
|
* uninitialized image data. In this case, we have no choice but to
|
|
|
|
* initialize all image data now. Fortunately, in this case we know
|
|
|
|
* that we can't be dealing with a depth texture per
|
|
|
|
* WEBGL_depth_texture and ANGLE_depth_texture (which allow only one
|
|
|
|
* image per texture) so we can assume that glTexImage2D is able to
|
|
|
|
* upload data to images.
|
|
|
|
*/
|
|
|
|
for (size_t level = 0; level <= mMaxLevelWithCustomImages; ++level)
|
|
|
|
{
|
2013-10-11 06:16:43 -07:00
|
|
|
for (size_t face = 0; face < mFacesCount; ++face) {
|
2014-11-13 20:03:50 -08:00
|
|
|
TexImageTarget imageTarget = TexImageTargetForTargetAndFace(mTarget,
|
|
|
|
face);
|
2013-10-11 06:16:43 -07:00
|
|
|
const ImageInfo& imageInfo = ImageInfoAt(imageTarget, level);
|
2014-11-13 20:03:50 -08:00
|
|
|
if (imageInfo.mImageDataStatus == WebGLImageDataStatus::UninitializedImageData)
|
|
|
|
{
|
2014-10-14 19:10:15 -07:00
|
|
|
EnsureNoUninitializedImageData(imageTarget, level);
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::NotNeeded;
|
|
|
|
} else {
|
|
|
|
// The texture only contains uninitialized image data. In this case,
|
|
|
|
// we can use a black texture for it.
|
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::UninitializedImageData;
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
2013-06-10 13:00:46 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
// we have exhausted all cases where we do need fakeblack, so if the status is still unknown,
|
|
|
|
// that means that we do NOT need it.
|
|
|
|
if (mFakeBlackStatus == WebGLTextureFakeBlackStatus::Unknown) {
|
|
|
|
mFakeBlackStatus = WebGLTextureFakeBlackStatus::NotNeeded;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(mFakeBlackStatus != WebGLTextureFakeBlackStatus::Unknown);
|
|
|
|
return mFakeBlackStatus;
|
2012-12-03 16:13:47 -08:00
|
|
|
}
|
|
|
|
|
2014-04-30 14:30:21 -07:00
|
|
|
static bool
|
2014-11-13 20:03:50 -08:00
|
|
|
ClearByMask(WebGLContext* webgl, GLbitfield mask)
|
2014-04-30 14:30:21 -07:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
gl::GLContext* gl = webgl->GL();
|
2014-04-30 14:30:21 -07:00
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
|
|
|
|
GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
return false;
|
|
|
|
|
2014-04-30 14:30:23 -07:00
|
|
|
bool colorAttachmentsMask[WebGLContext::kMaxColorAttachments] = {false};
|
2014-04-30 14:30:21 -07:00
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
colorAttachmentsMask[0] = true;
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
webgl->ForceClearFramebufferWithDefaultValues(mask, colorAttachmentsMask);
|
2014-04-30 14:30:21 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// `mask` from glClear.
|
|
|
|
static bool
|
2014-11-13 20:03:50 -08:00
|
|
|
ClearWithTempFB(WebGLContext* webgl, GLuint tex,
|
2014-09-18 16:14:22 -07:00
|
|
|
TexImageTarget texImageTarget, GLint level,
|
2014-09-23 10:48:27 -07:00
|
|
|
TexInternalFormat baseInternalFormat,
|
2014-04-30 14:30:21 -07:00
|
|
|
GLsizei width, GLsizei height)
|
|
|
|
{
|
2014-10-13 16:42:20 -07:00
|
|
|
MOZ_ASSERT(texImageTarget == LOCAL_GL_TEXTURE_2D);
|
2014-04-30 14:30:21 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
gl::GLContext* gl = webgl->GL();
|
2014-04-30 14:30:21 -07:00
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
|
|
|
|
gl::ScopedFramebuffer fb(gl);
|
|
|
|
gl::ScopedBindFramebuffer autoFB(gl, fb.FB());
|
|
|
|
GLbitfield mask = 0;
|
|
|
|
|
2014-09-23 10:48:27 -07:00
|
|
|
switch (baseInternalFormat.get()) {
|
2014-04-30 14:30:21 -07:00
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_BGR:
|
|
|
|
case LOCAL_GL_BGRA:
|
|
|
|
mask = LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
|
2014-09-18 16:14:22 -07:00
|
|
|
texImageTarget.get(), tex, level);
|
2014-04-30 14:30:21 -07:00
|
|
|
break;
|
2014-12-08 08:36:19 -08:00
|
|
|
case LOCAL_GL_DEPTH_COMPONENT32_OES:
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT24_OES:
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT16:
|
2014-04-30 14:30:21 -07:00
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
mask = LOCAL_GL_DEPTH_BUFFER_BIT;
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT,
|
2014-09-18 16:14:22 -07:00
|
|
|
texImageTarget.get(), tex, level);
|
2014-04-30 14:30:21 -07:00
|
|
|
break;
|
|
|
|
|
2014-12-08 08:36:19 -08:00
|
|
|
case LOCAL_GL_DEPTH24_STENCIL8:
|
2014-04-30 14:30:21 -07:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
mask = LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT,
|
2014-09-18 16:14:22 -07:00
|
|
|
texImageTarget.get(), tex, level);
|
2014-04-30 14:30:21 -07:00
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_STENCIL_ATTACHMENT,
|
2014-09-18 16:14:22 -07:00
|
|
|
texImageTarget.get(), tex, level);
|
2014-04-30 14:30:21 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mask);
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (ClearByMask(webgl, mask))
|
2014-04-30 14:30:21 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Failed to simply build an FB from the tex, but maybe it needs a
|
|
|
|
// color buffer to be complete.
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
// Nope, it already had one.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl::ScopedRenderbuffer rb(gl);
|
|
|
|
{
|
|
|
|
gl::ScopedBindRenderbuffer(gl, rb.RB());
|
|
|
|
gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER,
|
|
|
|
LOCAL_GL_RGBA4,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
|
|
|
|
LOCAL_GL_RENDERBUFFER, rb.RB());
|
|
|
|
mask |= LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
|
|
|
|
// Last chance!
|
2014-11-13 20:03:50 -08:00
|
|
|
return ClearByMask(webgl, mask);
|
2014-04-30 14:30:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLTexture::EnsureNoUninitializedImageData(TexImageTarget imageTarget,
|
|
|
|
GLint level)
|
2013-10-11 06:16:43 -07:00
|
|
|
{
|
|
|
|
const ImageInfo& imageInfo = ImageInfoAt(imageTarget, level);
|
2014-10-14 19:10:15 -07:00
|
|
|
if (!imageInfo.HasUninitializedImageData())
|
|
|
|
return;
|
2013-10-11 06:16:43 -07:00
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// Try to clear with glClear.
|
2014-10-13 16:42:20 -07:00
|
|
|
if (imageTarget == LOCAL_GL_TEXTURE_2D) {
|
2014-11-13 20:03:50 -08:00
|
|
|
bool cleared = ClearWithTempFB(mContext, GLName(), imageTarget, level,
|
2014-10-13 16:42:20 -07:00
|
|
|
imageInfo.mEffectiveInternalFormat,
|
|
|
|
imageInfo.mHeight, imageInfo.mWidth);
|
|
|
|
if (cleared) {
|
2014-11-13 20:03:50 -08:00
|
|
|
SetImageDataStatus(imageTarget, level,
|
|
|
|
WebGLImageDataStatus::InitializedImageData);
|
2014-10-13 16:42:20 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-04-30 14:30:28 -07:00
|
|
|
}
|
2014-04-30 14:30:21 -07:00
|
|
|
|
|
|
|
// That didn't work. Try uploading zeros then.
|
2014-09-18 16:14:22 -07:00
|
|
|
gl::ScopedBindTexture autoBindTex(mContext->gl, GLName(), mTarget.get());
|
2014-04-30 14:30:21 -07:00
|
|
|
|
2014-10-07 16:52:58 -07:00
|
|
|
size_t bitspertexel = GetBitsPerTexel(imageInfo.mEffectiveInternalFormat);
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_ASSERT((bitspertexel % 8) == 0); // That would only happen for
|
|
|
|
// compressed images, which cannot use
|
|
|
|
// deferred initialization.
|
2014-10-07 16:52:58 -07:00
|
|
|
size_t bytespertexel = bitspertexel / 8;
|
2013-10-11 06:16:43 -07:00
|
|
|
CheckedUint32 checked_byteLength
|
|
|
|
= WebGLContext::GetImageSize(
|
|
|
|
imageInfo.mHeight,
|
|
|
|
imageInfo.mWidth,
|
2014-10-13 16:42:20 -07:00
|
|
|
imageInfo.mDepth,
|
2014-10-07 16:52:58 -07:00
|
|
|
bytespertexel,
|
2013-10-11 06:16:43 -07:00
|
|
|
mContext->mPixelStoreUnpackAlignment);
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_ASSERT(checked_byteLength.isValid()); // Should have been checked
|
|
|
|
// earlier.
|
2014-10-15 20:11:30 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
// Infallible for now.
|
|
|
|
UniquePtr<uint8_t> zeros((uint8_t*)moz_xcalloc(1,
|
|
|
|
checked_byteLength.value()));
|
2013-10-31 10:00:32 -07:00
|
|
|
|
2014-05-01 20:15:58 -07:00
|
|
|
gl::GLContext* gl = mContext->gl;
|
|
|
|
GLenum driverInternalFormat = LOCAL_GL_NONE;
|
|
|
|
GLenum driverFormat = LOCAL_GL_NONE;
|
2014-10-07 16:52:58 -07:00
|
|
|
GLenum driverType = LOCAL_GL_NONE;
|
2014-11-13 20:03:50 -08:00
|
|
|
DriverFormatsFromEffectiveInternalFormat(gl,
|
|
|
|
imageInfo.mEffectiveInternalFormat,
|
|
|
|
&driverInternalFormat,
|
|
|
|
&driverFormat, &driverType);
|
2014-05-01 20:15:58 -07:00
|
|
|
|
2014-03-07 13:16:34 -08:00
|
|
|
mContext->GetAndFlushUnderlyingGLErrors();
|
2014-10-13 16:42:20 -07:00
|
|
|
if (imageTarget == LOCAL_GL_TEXTURE_3D) {
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_ASSERT(mImmutable,
|
|
|
|
"Shouldn't be possible to have non-immutable-format 3D"
|
|
|
|
" textures in WebGL");
|
|
|
|
gl->fTexSubImage3D(imageTarget.get(), level, 0, 0, 0, imageInfo.mWidth,
|
|
|
|
imageInfo.mHeight, imageInfo.mDepth, driverFormat,
|
|
|
|
driverType, zeros.get());
|
2014-10-13 16:42:20 -07:00
|
|
|
} else {
|
|
|
|
if (mImmutable) {
|
2014-11-13 20:03:50 -08:00
|
|
|
gl->fTexSubImage2D(imageTarget.get(), level, 0, 0, imageInfo.mWidth,
|
|
|
|
imageInfo.mHeight, driverFormat, driverType,
|
|
|
|
zeros.get());
|
2014-10-13 16:42:20 -07:00
|
|
|
} else {
|
|
|
|
gl->fTexImage2D(imageTarget.get(), level, driverInternalFormat,
|
2014-11-13 20:03:50 -08:00
|
|
|
imageInfo.mWidth, imageInfo.mHeight, 0,
|
|
|
|
driverFormat, driverType, zeros.get());
|
2014-10-13 16:42:20 -07:00
|
|
|
}
|
2014-10-09 13:07:07 -07:00
|
|
|
}
|
2014-03-07 13:16:34 -08:00
|
|
|
GLenum error = mContext->GetAndFlushUnderlyingGLErrors();
|
2014-04-30 14:30:21 -07:00
|
|
|
if (error) {
|
2014-11-13 20:03:50 -08:00
|
|
|
// Should only be OUT_OF_MEMORY. Anyway, there's no good way to recover
|
|
|
|
// from this here.
|
2014-04-30 14:30:23 -07:00
|
|
|
printf_stderr("Error: 0x%4x\n", error);
|
2014-11-13 20:03:50 -08:00
|
|
|
MOZ_CRASH(); // Errors on texture upload have been related to video
|
|
|
|
// memory exposure in the past.
|
2014-04-30 14:30:21 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
|
|
|
SetImageDataStatus(imageTarget, level, WebGLImageDataStatus::InitializedImageData);
|
2014-04-30 14:30:21 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
2014-04-30 14:30:21 -07:00
|
|
|
void
|
|
|
|
WebGLTexture::SetFakeBlackStatus(WebGLTextureFakeBlackStatus x)
|
|
|
|
{
|
2014-04-30 14:30:28 -07:00
|
|
|
mFakeBlackStatus = x;
|
|
|
|
mContext->SetFakeBlackStatus(WebGLContextFakeBlackStatus::Unknown);
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
|
|
|
|
2012-10-04 13:35:54 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTexture)
|
|
|
|
|
2013-08-29 08:39:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLTexture, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLTexture, Release)
|
2014-11-13 20:03:50 -08:00
|
|
|
|
|
|
|
} // namespace mozilla
|