2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-10-05 00:35:54 +04:00
|
|
|
/* 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-09 15:58:41 +04:00
|
|
|
#include "WebGLFramebuffer.h"
|
2014-07-15 03:55:33 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// You know it's going to be fun when these two show up:
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
|
2019-06-15 08:18:05 +03:00
|
|
|
#include "GLBlitHelper.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "GLContext.h"
|
2016-07-19 10:36:54 +03:00
|
|
|
#include "GLScreenBuffer.h"
|
2019-06-15 08:18:05 +03:00
|
|
|
#include "MozFramebuffer.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/IntegerRange.h"
|
2015-12-15 03:11:59 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2014-07-15 03:55:33 +04:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLContextUtils.h"
|
2013-06-22 03:44:17 +04:00
|
|
|
#include "WebGLExtensions.h"
|
2020-01-09 01:19:14 +03:00
|
|
|
#include "WebGLFormats.h"
|
2013-06-11 00:00:35 +04:00
|
|
|
#include "WebGLRenderbuffer.h"
|
2013-06-22 03:44:17 +04:00
|
|
|
#include "WebGLTexture.h"
|
2014-07-15 03:55:33 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
static bool ShouldDeferAttachment(const WebGLContext* const webgl,
|
|
|
|
const GLenum attachPoint) {
|
|
|
|
if (webgl->IsWebGL2()) return false;
|
|
|
|
|
|
|
|
switch (attachPoint) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
WebGLFBAttachPoint::WebGLFBAttachPoint() = default;
|
|
|
|
WebGLFBAttachPoint::WebGLFBAttachPoint(WebGLFBAttachPoint&) = default;
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
WebGLFBAttachPoint::WebGLFBAttachPoint(const WebGLContext* const webgl,
|
|
|
|
const GLenum attachmentPoint)
|
|
|
|
: mAttachmentPoint(attachmentPoint),
|
|
|
|
mDeferAttachment(ShouldDeferAttachment(webgl, mAttachmentPoint)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::~WebGLFBAttachPoint() {
|
2015-03-25 02:00:28 +03:00
|
|
|
MOZ_ASSERT(!mRenderbufferPtr);
|
|
|
|
MOZ_ASSERT(!mTexturePtr);
|
2014-07-30 23:52:07 +04:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:48:21 +03:00
|
|
|
void WebGLFBAttachPoint::Clear() { Set(nullptr, {}); }
|
|
|
|
|
|
|
|
void WebGLFBAttachPoint::Set(gl::GLContext* const gl,
|
|
|
|
const webgl::FbAttachInfo& toAttach) {
|
|
|
|
mRenderbufferPtr = toAttach.rb;
|
|
|
|
mTexturePtr = toAttach.tex;
|
|
|
|
mTexImageLayer = AssertedCast<uint32_t>(toAttach.zLayer);
|
|
|
|
mTexImageZLayerCount = AssertedCast<uint8_t>(toAttach.zLayerCount);
|
|
|
|
mTexImageLevel = AssertedCast<uint8_t>(toAttach.mipLevel);
|
|
|
|
mIsMultiview = toAttach.isMultiview;
|
|
|
|
|
|
|
|
if (gl && !mDeferAttachment) {
|
2019-05-23 10:57:29 +03:00
|
|
|
DoAttachment(gl);
|
2019-05-23 05:43:11 +03:00
|
|
|
}
|
2019-05-23 10:57:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const webgl::ImageInfo* WebGLFBAttachPoint::GetImageInfo() const {
|
2019-05-23 23:48:21 +03:00
|
|
|
if (mTexturePtr) {
|
|
|
|
const auto target = Texture()->Target();
|
|
|
|
uint8_t face = 0;
|
|
|
|
if (target == LOCAL_GL_TEXTURE_CUBE_MAP) {
|
|
|
|
face = Layer() % 6;
|
|
|
|
}
|
|
|
|
return &mTexturePtr->ImageInfoAtFace(face, mTexImageLevel);
|
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
if (mRenderbufferPtr) return &mRenderbufferPtr->ImageInfo();
|
|
|
|
return nullptr;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebGLFBAttachPoint::IsComplete(WebGLContext* webgl,
|
|
|
|
nsCString* const out_info) const {
|
2018-10-17 07:18:15 +03:00
|
|
|
MOZ_ASSERT(HasAttachment());
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto fnWriteErrorInfo = [&](const char* const text) {
|
2018-10-19 02:52:39 +03:00
|
|
|
WebGLContext::EnumName(mAttachmentPoint, out_info);
|
2019-05-23 23:48:21 +03:00
|
|
|
out_info->AppendLiteral(": ");
|
2018-10-17 07:18:15 +03:00
|
|
|
out_info->AppendASCII(text);
|
|
|
|
};
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = *GetImageInfo();
|
|
|
|
if (!imageInfo.mWidth || !imageInfo.mHeight) {
|
|
|
|
fnWriteErrorInfo("Attachment has no width or height.");
|
2015-11-24 06:27:13 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
MOZ_ASSERT(imageInfo.IsDefined());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& tex = Texture();
|
|
|
|
if (tex) {
|
|
|
|
// ES 3.0 spec, pg 213 has giant blocks of text that bake down to requiring
|
|
|
|
// that attached tex images are within the valid mip-levels of the texture.
|
|
|
|
// While it draws distinction to only test non-immutable textures, that's
|
|
|
|
// because immutable textures are *always* texture-complete. We need to
|
|
|
|
// check immutable textures though, because checking completeness is also
|
|
|
|
// when we zero invalidated/no-data tex images.
|
2019-05-23 23:48:21 +03:00
|
|
|
const auto attachedMipLevel = MipLevel();
|
|
|
|
|
|
|
|
const bool withinValidMipLevels = [&]() {
|
2018-10-17 07:18:15 +03:00
|
|
|
const bool ensureInit = false;
|
|
|
|
const auto texCompleteness = tex->CalcCompletenessInfo(ensureInit);
|
|
|
|
if (!texCompleteness) // OOM
|
2017-01-10 17:32:00 +03:00
|
|
|
return false;
|
2018-10-17 07:18:15 +03:00
|
|
|
if (!texCompleteness->levels) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto baseLevel = tex->BaseMipmapLevel();
|
|
|
|
const auto maxLevel = baseLevel + texCompleteness->levels - 1;
|
2019-05-23 23:48:21 +03:00
|
|
|
return baseLevel <= attachedMipLevel && attachedMipLevel <= maxLevel;
|
2018-11-30 13:46:48 +03:00
|
|
|
}();
|
2019-05-23 23:48:21 +03:00
|
|
|
if (!withinValidMipLevels) {
|
|
|
|
fnWriteErrorInfo("Attached mip level is invalid for texture.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& levelInfo = tex->ImageInfoAtFace(0, attachedMipLevel);
|
|
|
|
const auto faceDepth = levelInfo.mDepth * tex->FaceCount();
|
|
|
|
const bool withinValidZLayers = Layer() + ZLayerCount() - 1 < faceDepth;
|
|
|
|
if (!withinValidZLayers) {
|
|
|
|
fnWriteErrorInfo("Attached z layer is invalid for texture.");
|
2018-10-17 07:18:15 +03:00
|
|
|
return false;
|
2017-01-10 17:32:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& formatUsage = imageInfo.mFormat;
|
|
|
|
if (!formatUsage->IsRenderable()) {
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto info = nsPrintfCString(
|
2018-10-17 07:18:15 +03:00
|
|
|
"Attachment has an effective format of %s,"
|
|
|
|
" which is not renderable.",
|
|
|
|
formatUsage->format->name);
|
|
|
|
fnWriteErrorInfo(info.BeginReading());
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-07-09 08:21:30 +03:00
|
|
|
if (!formatUsage->IsExplicitlyRenderable()) {
|
|
|
|
webgl->WarnIfImplicit(formatUsage->GetExtensionID());
|
|
|
|
}
|
2017-01-10 17:32:00 +03:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
const auto format = formatUsage->format;
|
|
|
|
|
|
|
|
bool hasRequiredBits;
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
switch (mAttachmentPoint) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2016-07-09 00:57:18 +03:00
|
|
|
hasRequiredBits = format->d;
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2016-07-09 00:57:18 +03:00
|
|
|
hasRequiredBits = format->s;
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
2014-08-20 00:24:39 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
MOZ_ASSERT(!webgl->IsWebGL2());
|
2016-07-09 00:57:18 +03:00
|
|
|
hasRequiredBits = (format->d && format->s);
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
|
2016-07-09 00:57:18 +03:00
|
|
|
hasRequiredBits = format->IsColorFormat();
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
if (!hasRequiredBits) {
|
2018-10-17 07:18:15 +03:00
|
|
|
fnWriteErrorInfo(
|
|
|
|
"Attachment's format is missing required color/depth/stencil"
|
|
|
|
" bits.");
|
2015-12-15 03:11:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!webgl->IsWebGL2()) {
|
|
|
|
bool hasSurplusPlanes = false;
|
|
|
|
|
|
|
|
switch (mAttachmentPoint) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2016-07-09 00:57:18 +03:00
|
|
|
hasSurplusPlanes = format->s;
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2016-07-09 00:57:18 +03:00
|
|
|
hasSurplusPlanes = format->d;
|
2015-12-15 03:11:59 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasSurplusPlanes) {
|
2018-10-17 07:18:15 +03:00
|
|
|
fnWriteErrorInfo(
|
|
|
|
"Attachment has depth or stencil bits when it shouldn't.");
|
2015-12-15 03:11:59 +03:00
|
|
|
return false;
|
2015-11-24 08:55:59 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
return true;
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
void WebGLFBAttachPoint::DoAttachment(gl::GLContext* const gl) const {
|
2013-10-02 04:30:05 +04:00
|
|
|
if (Renderbuffer()) {
|
2018-10-17 07:18:15 +03:00
|
|
|
Renderbuffer()->DoFramebufferRenderbuffer(mAttachmentPoint);
|
2013-10-02 04:30:05 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (!Texture()) {
|
|
|
|
MOZ_ASSERT(mAttachmentPoint != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
|
|
|
|
// WebGL 2 doesn't have a real attachment for this, and WebGL 1 is defered
|
|
|
|
// and only DoAttachment if HasAttachment.
|
2016-09-01 23:52:27 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint,
|
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-01 23:52:27 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& texName = Texture()->mGLName;
|
2016-09-01 23:52:27 +03:00
|
|
|
|
2019-05-23 23:48:21 +03:00
|
|
|
switch (Texture()->Target().get()) {
|
2016-07-19 10:36:54 +03:00
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
2019-05-23 23:48:21 +03:00
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP: {
|
|
|
|
TexImageTarget imageTarget = LOCAL_GL_TEXTURE_2D;
|
|
|
|
if (Texture()->Target() == LOCAL_GL_TEXTURE_CUBE_MAP) {
|
|
|
|
imageTarget = LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + Layer();
|
|
|
|
}
|
|
|
|
|
2016-09-01 23:52:27 +03:00
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
2019-05-23 23:48:21 +03:00
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
LOCAL_GL_DEPTH_ATTACHMENT, imageTarget.get(),
|
|
|
|
texName, MipLevel());
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
LOCAL_GL_STENCIL_ATTACHMENT,
|
|
|
|
imageTarget.get(), texName, MipLevel());
|
2016-09-01 23:52:27 +03:00
|
|
|
} else {
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint,
|
2019-05-23 23:48:21 +03:00
|
|
|
imageTarget.get(), texName, MipLevel());
|
2016-09-01 23:52:27 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
2019-05-23 23:48:21 +03:00
|
|
|
}
|
2013-10-02 04:30:05 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
2019-05-23 23:48:21 +03:00
|
|
|
if (ZLayerCount() != 1) {
|
|
|
|
gl->fFramebufferTextureMultiview(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint,
|
|
|
|
texName, MipLevel(), Layer(),
|
|
|
|
ZLayerCount());
|
|
|
|
} else {
|
|
|
|
gl->fFramebufferTextureLayer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint,
|
|
|
|
texName, MipLevel(), Layer());
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-10-02 04:30:05 +04:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
Maybe<double> WebGLFBAttachPoint::GetParameter(WebGLContext* webgl,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum pname) const {
|
2018-10-17 07:18:15 +03:00
|
|
|
if (!HasAttachment()) {
|
2015-11-25 07:15:29 +03:00
|
|
|
// Divergent between GLES 3 and 2.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 2.0.25 p127:
|
|
|
|
// "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then
|
|
|
|
// querying any other pname will generate INVALID_ENUM."
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4 p240:
|
|
|
|
// "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no
|
|
|
|
// framebuffer is bound to target. In this case querying pname
|
|
|
|
// FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all other
|
|
|
|
// queries will generate an INVALID_OPERATION error."
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(LOCAL_GL_NONE);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
2020-01-09 01:19:14 +03:00
|
|
|
if (webgl->IsWebGL2()) return Nothing();
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-12-22 06:42:07 +03:00
|
|
|
nsCString attachmentName;
|
|
|
|
WebGLContext::EnumName(attachment, &attachmentName);
|
2015-11-25 07:15:29 +03:00
|
|
|
if (webgl->IsWebGL2()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidOperation("No attachment at %s.",
|
2016-12-22 06:42:07 +03:00
|
|
|
attachmentName.BeginReading());
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnum("No attachment at %s.",
|
2016-12-22 06:42:07 +03:00
|
|
|
attachmentName.BeginReading());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
bool isPNameValid = false;
|
2015-08-06 09:31:00 +03:00
|
|
|
switch (pname) {
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(mTexturePtr ? LOCAL_GL_TEXTURE : LOCAL_GL_RENDERBUFFER);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
//////
|
2015-08-06 09:31:00 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
|
2020-01-09 01:19:16 +03:00
|
|
|
if (mTexturePtr) return Some(AssertedCast<uint32_t>(MipLevel()));
|
2015-08-06 09:31:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mTexturePtr) {
|
|
|
|
GLenum face = 0;
|
|
|
|
if (mTexturePtr->Target() == LOCAL_GL_TEXTURE_CUBE_MAP) {
|
2019-05-23 23:48:21 +03:00
|
|
|
face = LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + Layer();
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(face);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
break;
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
//////
|
|
|
|
|
2015-08-06 09:31:00 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
|
2019-05-23 23:48:21 +03:00
|
|
|
if (webgl->IsWebGL2()) {
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(AssertedCast<int32_t>(Layer()));
|
2019-05-23 23:48:21 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR:
|
|
|
|
if (webgl->IsExtensionEnabled(WebGLExtensionID::OVR_multiview2)) {
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(AssertedCast<int32_t>(Layer()));
|
2019-05-23 23:48:21 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR:
|
|
|
|
if (webgl->IsExtensionEnabled(WebGLExtensionID::OVR_multiview2)) {
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(AssertedCast<uint32_t>(ZLayerCount()));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
break;
|
2016-07-09 01:48:36 +03:00
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
|
|
|
|
isPNameValid = webgl->IsWebGL2();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
|
|
|
|
isPNameValid = (webgl->IsWebGL2() ||
|
|
|
|
webgl->IsExtensionEnabled(WebGLExtensionID::EXT_sRGB));
|
|
|
|
break;
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!isPNameValid) {
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnum("Invalid pname: 0x%04x", pname);
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = *GetImageInfo();
|
|
|
|
const auto& usage = imageInfo.mFormat;
|
2016-12-23 00:19:03 +03:00
|
|
|
if (!usage) {
|
|
|
|
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING)
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(LOCAL_GL_LINEAR);
|
2016-12-23 00:19:03 +03:00
|
|
|
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2016-12-23 00:19:03 +03:00
|
|
|
}
|
2016-07-09 01:48:36 +03:00
|
|
|
|
2016-07-22 01:37:00 +03:00
|
|
|
auto format = usage->format;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
GLint ret = 0;
|
2016-07-09 01:48:36 +03:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
|
|
|
|
ret = format->r;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
|
|
|
|
ret = format->g;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
|
|
|
|
ret = format->b;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
|
|
|
|
ret = format->a;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
|
|
|
|
ret = format->d;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
|
|
|
|
ret = format->s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
|
|
|
|
ret = (format->isSRGB ? LOCAL_GL_SRGB : LOCAL_GL_LINEAR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
|
|
|
|
MOZ_ASSERT(attachment != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (format->unsizedFormat == webgl::UnsizedFormat::DEPTH_STENCIL) {
|
2016-07-22 01:37:00 +03:00
|
|
|
MOZ_ASSERT(attachment == LOCAL_GL_DEPTH_ATTACHMENT ||
|
|
|
|
attachment == LOCAL_GL_STENCIL_ATTACHMENT);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-22 01:37:00 +03:00
|
|
|
if (attachment == LOCAL_GL_DEPTH_ATTACHMENT) {
|
|
|
|
switch (format->effectiveFormat) {
|
|
|
|
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
|
|
|
|
format =
|
|
|
|
webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT24);
|
|
|
|
break;
|
|
|
|
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
|
|
|
|
format =
|
|
|
|
webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT32F);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "no matched DS format");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (attachment == LOCAL_GL_STENCIL_ATTACHMENT) {
|
|
|
|
switch (format->effectiveFormat) {
|
|
|
|
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
|
|
|
|
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
|
|
|
|
format = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "no matched DS format");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-22 01:37:00 +03:00
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
switch (format->componentType) {
|
|
|
|
case webgl::ComponentType::Int:
|
|
|
|
ret = LOCAL_GL_INT;
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::UInt:
|
|
|
|
ret = LOCAL_GL_UNSIGNED_INT;
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::NormInt:
|
|
|
|
ret = LOCAL_GL_SIGNED_NORMALIZED;
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::NormUInt:
|
|
|
|
ret = LOCAL_GL_UNSIGNED_NORMALIZED;
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::Float:
|
|
|
|
ret = LOCAL_GL_FLOAT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Missing case.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
return Some(ret);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-03-25 02:00:28 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// WebGLFramebuffer
|
2015-03-17 07:32:52 +03:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl, GLuint fbo)
|
2020-01-09 01:19:16 +03:00
|
|
|
: WebGLContextBoundObject(webgl),
|
2015-05-21 02:50:28 +03:00
|
|
|
mGLName(fbo),
|
2018-10-17 07:18:15 +03:00
|
|
|
mDepthAttachment(webgl, LOCAL_GL_DEPTH_ATTACHMENT),
|
|
|
|
mStencilAttachment(webgl, LOCAL_GL_STENCIL_ATTACHMENT),
|
|
|
|
mDepthStencilAttachment(webgl, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mAttachments.push_back(&mDepthAttachment);
|
|
|
|
mAttachments.push_back(&mStencilAttachment);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (!webgl->IsWebGL2()) {
|
|
|
|
// Only WebGL1 has a separate depth+stencil attachment point.
|
|
|
|
mAttachments.push_back(&mDepthStencilAttachment);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
size_t i = 0;
|
|
|
|
for (auto& cur : mColorAttachments) {
|
2018-10-17 07:18:15 +03:00
|
|
|
new (&cur) WebGLFBAttachPoint(webgl, LOCAL_GL_COLOR_ATTACHMENT0 + i);
|
2016-07-19 10:36:54 +03:00
|
|
|
i++;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
mAttachments.push_back(&cur);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
mColorDrawBuffers.push_back(&mColorAttachments[0]);
|
|
|
|
mColorReadBuffer = &mColorAttachments[0];
|
2015-03-17 07:32:52 +03:00
|
|
|
}
|
2015-03-17 04:22:17 +03:00
|
|
|
|
2020-04-07 21:48:13 +03:00
|
|
|
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl,
|
|
|
|
UniquePtr<gl::MozFramebuffer> fbo)
|
|
|
|
: WebGLContextBoundObject(webgl),
|
|
|
|
mGLName(fbo->mFB),
|
|
|
|
mOpaque(std::move(fbo)),
|
|
|
|
mColorReadBuffer(nullptr) {
|
|
|
|
// Opaque Framebuffer is guaranteed to be complete at this point.
|
|
|
|
// Cache the Completeness info.
|
|
|
|
CompletenessInfo info;
|
|
|
|
info.width = mOpaque->mSize.width;
|
|
|
|
info.height = mOpaque->mSize.height;
|
|
|
|
info.hasFloat32 = false;
|
|
|
|
info.zLayerCount = 1;
|
|
|
|
info.isMultiview = false;
|
|
|
|
|
|
|
|
mCompletenessInfo = Some(std::move(info));
|
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
WebGLFramebuffer::~WebGLFramebuffer() {
|
2018-10-17 07:18:15 +03:00
|
|
|
InvalidateCaches();
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
mDepthAttachment.Clear();
|
|
|
|
mStencilAttachment.Clear();
|
|
|
|
mDepthStencilAttachment.Clear();
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
for (auto& cur : mColorAttachments) {
|
2018-07-27 07:46:33 +03:00
|
|
|
cur.Clear();
|
2014-06-24 11:15:44 +04:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
if (!mContext) return;
|
2020-04-07 21:48:13 +03:00
|
|
|
// If opaque, fDeleteFramebuffers is called in the destructor of
|
|
|
|
// MozFramebuffer.
|
|
|
|
if (!mOpaque) {
|
|
|
|
mContext->gl->fDeleteFramebuffers(1, &mGLName);
|
|
|
|
}
|
2014-06-24 11:15:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2014-03-04 11:14:35 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
Maybe<WebGLFBAttachPoint*> WebGLFramebuffer::GetColorAttachPoint(
|
|
|
|
GLenum attachPoint) {
|
|
|
|
if (attachPoint == LOCAL_GL_NONE) return Some<WebGLFBAttachPoint*>(nullptr);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (attachPoint < LOCAL_GL_COLOR_ATTACHMENT0) return Nothing();
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const size_t colorId = attachPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
MOZ_ASSERT(mContext->Limits().maxColorDrawBuffers <= kMaxColorAttachments);
|
|
|
|
if (colorId >= mContext->MaxValidDrawBuffers()) return Nothing();
|
2015-07-03 04:55:43 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
return Some(&mColorAttachments[colorId]);
|
2015-07-03 04:55:43 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
Maybe<WebGLFBAttachPoint*> WebGLFramebuffer::GetAttachPoint(
|
|
|
|
GLenum attachPoint) {
|
|
|
|
switch (attachPoint) {
|
2014-11-14 07:03:50 +03:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
2016-07-19 10:36:54 +03:00
|
|
|
return Some(&mDepthStencilAttachment);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2016-07-19 10:36:54 +03:00
|
|
|
return Some(&mDepthAttachment);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2016-07-19 10:36:54 +03:00
|
|
|
return Some(&mStencilAttachment);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
default:
|
2016-07-19 10:36:54 +03:00
|
|
|
return GetColorAttachPoint(attachPoint);
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
void WebGLFramebuffer::DetachTexture(const WebGLTexture* tex) {
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& attach : mAttachments) {
|
|
|
|
if (attach->Texture() == tex) {
|
|
|
|
attach->Clear();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
InvalidateCaches();
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
void WebGLFramebuffer::DetachRenderbuffer(const WebGLRenderbuffer* rb) {
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& attach : mAttachments) {
|
|
|
|
if (attach->Renderbuffer() == rb) {
|
|
|
|
attach->Clear();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
InvalidateCaches();
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Completeness
|
|
|
|
|
2017-06-23 00:45:11 +03:00
|
|
|
bool WebGLFramebuffer::HasDuplicateAttachments() const {
|
2018-10-17 07:18:15 +03:00
|
|
|
std::set<WebGLFBAttachPoint::Ordered> uniqueAttachSet;
|
2017-06-23 00:45:11 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& attach : mColorAttachments) {
|
|
|
|
if (!attach.HasAttachment()) continue;
|
2017-06-23 00:45:11 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const WebGLFBAttachPoint::Ordered ordered(attach);
|
2017-06-23 00:45:11 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const bool didInsert = uniqueAttachSet.insert(ordered).second;
|
|
|
|
if (!didInsert) return true;
|
|
|
|
}
|
2017-06-23 00:45:11 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
return false;
|
2017-06-23 00:45:11 +03:00
|
|
|
}
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
bool WebGLFramebuffer::HasDefinedAttachments() const {
|
|
|
|
bool hasAttachments = false;
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& attach : mAttachments) {
|
|
|
|
hasAttachments |= attach->HasAttachment();
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
return hasAttachments;
|
|
|
|
}
|
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
bool WebGLFramebuffer::HasIncompleteAttachments(
|
|
|
|
nsCString* const out_info) const {
|
2016-07-19 10:36:54 +03:00
|
|
|
bool hasIncomplete = false;
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& cur : mAttachments) {
|
|
|
|
if (!cur->HasAttachment())
|
|
|
|
continue; // Not defined, so can't count as incomplete.
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
hasIncomplete |= !cur->IsComplete(mContext, out_info);
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
return hasIncomplete;
|
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool WebGLFramebuffer::AllImageRectsMatch() const {
|
|
|
|
MOZ_ASSERT(HasDefinedAttachments());
|
|
|
|
DebugOnly<nsCString> fbStatusInfo;
|
|
|
|
MOZ_ASSERT(!HasIncompleteAttachments(&fbStatusInfo));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool needsInit = true;
|
2018-10-17 07:18:15 +03:00
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool hasMismatch = false;
|
|
|
|
for (const auto& attach : mAttachments) {
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = attach->GetImageInfo();
|
|
|
|
if (!imageInfo) continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& curWidth = imageInfo->mWidth;
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& curHeight = imageInfo->mHeight;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (needsInit) {
|
2016-02-13 06:31:58 +03:00
|
|
|
needsInit = false;
|
|
|
|
width = curWidth;
|
2016-07-19 10:36:54 +03:00
|
|
|
height = curHeight;
|
2018-10-17 07:18:15 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
hasMismatch |= (curWidth != width || curHeight != height);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
return !hasMismatch;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool WebGLFramebuffer::AllImageSamplesMatch() const {
|
2014-01-23 07:59:34 +04:00
|
|
|
MOZ_ASSERT(HasDefinedAttachments());
|
2015-12-15 03:11:59 +03:00
|
|
|
DebugOnly<nsCString> fbStatusInfo;
|
|
|
|
MOZ_ASSERT(!HasIncompleteAttachments(&fbStatusInfo));
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool needsInit = true;
|
|
|
|
uint32_t samples = 0;
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool hasMismatch = false;
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& attach : mAttachments) {
|
|
|
|
const auto& imageInfo = attach->GetImageInfo();
|
|
|
|
if (!imageInfo) continue;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& curSamples = imageInfo->mSamples;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
|
|
|
if (needsInit) {
|
|
|
|
needsInit = false;
|
|
|
|
samples = curSamples;
|
2018-10-17 07:18:15 +03:00
|
|
|
continue;
|
2016-02-13 06:31:58 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
hasMismatch |= (curSamples != samples);
|
2016-02-13 06:31:58 +03:00
|
|
|
};
|
2016-07-19 10:36:54 +03:00
|
|
|
return !hasMismatch;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
FBStatus WebGLFramebuffer::PrecheckFramebufferStatus(
|
|
|
|
nsCString* const out_info) const {
|
2015-01-13 02:05:21 +03:00
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
2014-01-23 07:59:34 +04:00
|
|
|
if (!HasDefinedAttachments())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; // No
|
|
|
|
// attachments
|
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
if (HasIncompleteAttachments(out_info))
|
2014-01-23 07:59:34 +04:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
|
|
|
2016-01-29 03:41:00 +03:00
|
|
|
if (!AllImageRectsMatch())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; // Inconsistent sizes
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
if (!AllImageSamplesMatch())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; // Inconsistent samples
|
|
|
|
|
2017-06-23 00:45:11 +03:00
|
|
|
if (HasDuplicateAttachments()) return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mContext->IsWebGL2()) {
|
2018-10-17 07:18:15 +03:00
|
|
|
MOZ_ASSERT(!mDepthStencilAttachment.HasAttachment());
|
|
|
|
if (mDepthAttachment.HasAttachment() &&
|
|
|
|
mStencilAttachment.HasAttachment()) {
|
|
|
|
if (!mDepthAttachment.IsEquivalentForFeedback(mStencilAttachment))
|
2015-11-25 07:15:29 +03:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto depthOrStencilCount =
|
|
|
|
int(mDepthAttachment.HasAttachment()) +
|
|
|
|
int(mStencilAttachment.HasAttachment()) +
|
|
|
|
int(mDepthStencilAttachment.HasAttachment());
|
|
|
|
if (depthOrStencilCount > 1) return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2019-05-23 23:48:21 +03:00
|
|
|
{
|
|
|
|
const WebGLFBAttachPoint* example = nullptr;
|
|
|
|
for (const auto& x : mAttachments) {
|
|
|
|
if (!x->HasAttachment()) continue;
|
|
|
|
if (!example) {
|
|
|
|
example = x;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (x->ZLayerCount() != example->ZLayerCount()) {
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Validation
|
|
|
|
|
2019-01-23 20:53:43 +03:00
|
|
|
bool WebGLFramebuffer::ValidateAndInitAttachments(
|
|
|
|
const GLenum incompleteFbError) const {
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
2014-03-04 11:14:35 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto fbStatus = CheckFramebufferStatus();
|
2016-07-19 10:36:54 +03:00
|
|
|
if (fbStatus == LOCAL_GL_FRAMEBUFFER_COMPLETE) return true;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2019-01-23 20:53:43 +03:00
|
|
|
mContext->GenerateError(incompleteFbError, "Framebuffer must be complete.");
|
2016-07-19 10:36:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-02 04:31:37 +04:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
bool WebGLFramebuffer::ValidateClearBufferType(
|
|
|
|
GLenum buffer, uint32_t drawBuffer,
|
|
|
|
const webgl::AttribBaseType funcType) const {
|
2016-12-22 13:22:12 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR) return true;
|
|
|
|
|
|
|
|
const auto& attach = mColorAttachments[drawBuffer];
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = attach.GetImageInfo();
|
|
|
|
if (!imageInfo) return true;
|
2016-12-30 14:02:14 +03:00
|
|
|
|
|
|
|
if (!count(mColorDrawBuffers.begin(), mColorDrawBuffers.end(), &attach))
|
2016-12-22 13:22:12 +03:00
|
|
|
return true; // DRAW_BUFFERi set to NONE.
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
auto attachType = webgl::AttribBaseType::Float;
|
2018-10-17 07:18:15 +03:00
|
|
|
switch (imageInfo->mFormat->format->componentType) {
|
2016-12-22 13:22:12 +03:00
|
|
|
case webgl::ComponentType::Int:
|
2020-01-09 01:19:16 +03:00
|
|
|
attachType = webgl::AttribBaseType::Int;
|
2016-12-22 13:22:12 +03:00
|
|
|
break;
|
|
|
|
case webgl::ComponentType::UInt:
|
2020-01-09 01:19:16 +03:00
|
|
|
attachType = webgl::AttribBaseType::Uint;
|
2016-12-22 13:22:12 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (attachType != funcType) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
2020-01-09 01:19:16 +03:00
|
|
|
"This attachment is of type %s, but"
|
|
|
|
" this function is of type %s.",
|
|
|
|
ToString(attachType), ToString(funcType));
|
2016-12-22 13:22:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
bool WebGLFramebuffer::ValidateForColorRead(
|
|
|
|
const webgl::FormatUsageInfo** const out_format, uint32_t* const out_width,
|
2017-12-19 05:30:56 +03:00
|
|
|
uint32_t* const out_height) const {
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!mColorReadBuffer) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation("READ_BUFFER must not be NONE.");
|
2016-07-19 10:36:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2019-05-23 23:48:21 +03:00
|
|
|
if (mColorReadBuffer->ZLayerCount() > 1) {
|
|
|
|
mContext->GenerateError(LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION,
|
|
|
|
"The READ_BUFFER attachment has multiple views.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = mColorReadBuffer->GetImageInfo();
|
|
|
|
if (!imageInfo) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"The READ_BUFFER attachment is not defined.");
|
2016-07-19 10:36:54 +03:00
|
|
|
return false;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (imageInfo->mSamples) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"The READ_BUFFER attachment is multisampled.");
|
2016-12-23 04:08:35 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
*out_format = imageInfo->mFormat;
|
|
|
|
*out_width = imageInfo->mWidth;
|
|
|
|
*out_height = imageInfo->mHeight;
|
2016-07-19 10:36:54 +03:00
|
|
|
return true;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Resolution and caching
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
void WebGLFramebuffer::DoDeferredAttachments() const {
|
|
|
|
if (mContext->IsWebGL2()) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT,
|
2016-07-19 10:36:54 +03:00
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
LOCAL_GL_STENCIL_ATTACHMENT,
|
2016-07-19 10:36:54 +03:00
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto fn = [&](const WebGLFBAttachPoint& attach) {
|
|
|
|
MOZ_ASSERT(attach.mDeferAttachment);
|
|
|
|
if (attach.HasAttachment()) {
|
|
|
|
attach.DoAttachment(gl);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Only one of these will have an attachment.
|
|
|
|
fn(mDepthAttachment);
|
|
|
|
fn(mStencilAttachment);
|
|
|
|
fn(mDepthStencilAttachment);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
void WebGLFramebuffer::ResolveAttachmentData() const {
|
|
|
|
// GLES 3.0.5 p188:
|
|
|
|
// The result of clearing integer color buffers with `Clear` is undefined.
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// Two different approaches:
|
|
|
|
// On WebGL 2, we have glClearBuffer, and *must* use it for integer buffers,
|
|
|
|
// so let's just use it for all the buffers. One WebGL 1, we might not have
|
|
|
|
// glClearBuffer,
|
2016-12-17 04:48:06 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// WebGL 1 is easier, because we can just call glClear, possibly with
|
|
|
|
// glDrawBuffers.
|
2016-12-17 04:48:06 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const webgl::ScopedPrepForResourceClear scopedPrep(*mContext);
|
2016-12-17 04:48:06 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (mContext->IsWebGL2()) {
|
|
|
|
const uint32_t uiZeros[4] = {};
|
|
|
|
const int32_t iZeros[4] = {};
|
|
|
|
const float fZeros[4] = {};
|
|
|
|
const float fOne[] = {1.0f};
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
for (const auto& cur : mAttachments) {
|
|
|
|
const auto& imageInfo = cur->GetImageInfo();
|
2019-07-31 02:32:29 +03:00
|
|
|
if (!imageInfo || !imageInfo->mUninitializedSlices)
|
2018-10-17 07:18:15 +03:00
|
|
|
continue; // Nothing attached, or already has data.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto fnClearBuffer = [&]() {
|
|
|
|
const auto& format = imageInfo->mFormat->format;
|
|
|
|
MOZ_ASSERT(format->estimatedBytesPerPixel <= sizeof(uiZeros));
|
|
|
|
MOZ_ASSERT(format->estimatedBytesPerPixel <= sizeof(iZeros));
|
|
|
|
MOZ_ASSERT(format->estimatedBytesPerPixel <= sizeof(fZeros));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
switch (cur->mAttachmentPoint) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
gl->fClearBufferfv(LOCAL_GL_DEPTH, 0, fOne);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2018-10-17 07:18:15 +03:00
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
gl->fClearBufferiv(LOCAL_GL_STENCIL, 0, iZeros);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(cur->mAttachmentPoint !=
|
|
|
|
LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
|
|
|
|
const uint32_t drawBuffer =
|
|
|
|
cur->mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
MOZ_ASSERT(drawBuffer <= 100);
|
|
|
|
switch (format->componentType) {
|
|
|
|
case webgl::ComponentType::Int:
|
|
|
|
gl->fClearBufferiv(LOCAL_GL_COLOR, drawBuffer, iZeros);
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::UInt:
|
|
|
|
gl->fClearBufferuiv(LOCAL_GL_COLOR, drawBuffer, uiZeros);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fClearBufferfv(LOCAL_GL_COLOR, drawBuffer, fZeros);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-01-12 04:10:48 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (imageInfo->mDepth > 1) {
|
|
|
|
const auto& tex = cur->Texture();
|
2019-05-23 23:48:21 +03:00
|
|
|
const gl::ScopedFramebuffer scopedFB(gl);
|
|
|
|
const gl::ScopedBindFramebuffer scopedBindFB(gl, scopedFB.FB());
|
2019-07-31 02:32:29 +03:00
|
|
|
for (const auto z : IntegerRange(imageInfo->mDepth)) {
|
|
|
|
if ((*imageInfo->mUninitializedSlices)[z]) {
|
|
|
|
gl->fFramebufferTextureLayer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
cur->mAttachmentPoint, tex->mGLName,
|
|
|
|
cur->MipLevel(), z);
|
|
|
|
fnClearBuffer();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
} else {
|
|
|
|
fnClearBuffer();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-03-27 17:10:45 +03:00
|
|
|
imageInfo->mUninitializedSlices = Nothing();
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
uint32_t clearBits = 0;
|
|
|
|
std::vector<GLenum> drawBufferForClear;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
const auto fnGather = [&](const WebGLFBAttachPoint& attach,
|
|
|
|
const uint32_t attachClearBits) {
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = attach.GetImageInfo();
|
2019-07-31 02:32:29 +03:00
|
|
|
if (!imageInfo || !imageInfo->mUninitializedSlices) return false;
|
2015-03-17 07:32:52 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
clearBits |= attachClearBits;
|
2020-03-27 17:10:45 +03:00
|
|
|
imageInfo->mUninitializedSlices = Nothing(); // Just mark it now.
|
2016-07-19 10:36:54 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
for (const auto& cur : mColorAttachments) {
|
|
|
|
if (fnGather(cur, LOCAL_GL_COLOR_BUFFER_BIT)) {
|
|
|
|
const uint32_t id = cur.mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
MOZ_ASSERT(id <= 100);
|
|
|
|
drawBufferForClear.resize(id + 1); // Pads with zeros!
|
|
|
|
drawBufferForClear[id] = cur.mAttachmentPoint;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
(void)fnGather(mDepthAttachment, LOCAL_GL_DEPTH_BUFFER_BIT);
|
|
|
|
(void)fnGather(mStencilAttachment, LOCAL_GL_STENCIL_BUFFER_BIT);
|
|
|
|
(void)fnGather(mDepthStencilAttachment,
|
|
|
|
LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
//////
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
if (!clearBits) return;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
if (gl->IsSupported(gl::GLFeature::draw_buffers)) {
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fDrawBuffers(drawBufferForClear.size(), drawBufferForClear.data());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fClear(clearBits);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
RefreshDrawBuffers();
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
WebGLFramebuffer::CompletenessInfo::~CompletenessInfo() {
|
2019-07-04 07:34:45 +03:00
|
|
|
if (!this->fb) return;
|
|
|
|
const auto& fb = *this->fb;
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto& webgl = fb.mContext;
|
2018-10-17 07:18:15 +03:00
|
|
|
fb.mNumFBStatusInvals++;
|
2016-09-09 01:56:58 +03:00
|
|
|
if (fb.mNumFBStatusInvals > webgl->mMaxAcceptableFBStatusInvals) {
|
|
|
|
webgl->GeneratePerfWarning(
|
|
|
|
"FB was invalidated after being complete %u"
|
2019-07-04 07:34:45 +03:00
|
|
|
" times. [webgl.perf.max-acceptable-fb-status-invals]",
|
2016-09-09 01:56:58 +03:00
|
|
|
uint32_t(fb.mNumFBStatusInvals));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2016-09-09 01:56:58 +03:00
|
|
|
// Entrypoints
|
|
|
|
|
|
|
|
FBStatus WebGLFramebuffer::CheckFramebufferStatus() const {
|
2020-04-07 21:48:13 +03:00
|
|
|
if (MOZ_UNLIKELY(mOpaque && !mInOpaqueRAF)) {
|
|
|
|
// Opaque Framebuffers are considered incomplete outside of a RAF.
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
if (mCompletenessInfo) return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
|
|
|
|
// Ok, let's try to resolve it!
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
nsCString statusInfo;
|
|
|
|
FBStatus ret = PrecheckFramebufferStatus(&statusInfo);
|
|
|
|
do {
|
|
|
|
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE) break;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
// Looks good on our end. Let's ask the driver.
|
2016-12-23 04:08:35 +03:00
|
|
|
gl::GLContext* const gl = mContext->gl;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const ScopedFBRebinder autoFB(mContext);
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGLName);
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-18 10:15:54 +03:00
|
|
|
////
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
DoDeferredAttachments();
|
|
|
|
RefreshDrawBuffers();
|
|
|
|
RefreshReadBuffer();
|
2013-10-02 04:30:05 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
ret = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
2015-02-19 03:57:05 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
|
|
|
const nsPrintfCString text("Bad status according to the driver: 0x%04x",
|
|
|
|
ret.get());
|
2018-07-27 07:46:33 +03:00
|
|
|
statusInfo = text;
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
ResolveAttachmentData();
|
2015-02-19 03:57:05 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// Sweet, let's cache that.
|
2019-07-04 07:34:45 +03:00
|
|
|
auto info = CompletenessInfo{this, UINT32_MAX, UINT32_MAX};
|
2018-10-17 07:18:15 +03:00
|
|
|
mCompletenessInfo.ResetInvalidators({});
|
2018-07-27 07:46:33 +03:00
|
|
|
mCompletenessInfo.AddInvalidator(*this);
|
2017-07-17 23:52:00 +03:00
|
|
|
|
2019-02-01 02:39:12 +03:00
|
|
|
const auto fnIsFloat32 = [](const webgl::FormatInfo& info) {
|
|
|
|
if (info.componentType != webgl::ComponentType::Float) return false;
|
|
|
|
return info.r == 32;
|
|
|
|
};
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
for (const auto& cur : mAttachments) {
|
|
|
|
const auto& tex = cur->Texture();
|
|
|
|
const auto& rb = cur->Renderbuffer();
|
2018-10-17 07:18:15 +03:00
|
|
|
if (tex) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mCompletenessInfo.AddInvalidator(*tex);
|
2017-07-17 23:52:00 +03:00
|
|
|
info.texAttachments.push_back(cur);
|
2018-10-17 07:18:15 +03:00
|
|
|
} else if (rb) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mCompletenessInfo.AddInvalidator(*rb);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-07-17 23:52:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = cur->GetImageInfo();
|
|
|
|
MOZ_ASSERT(imageInfo);
|
|
|
|
info.width = std::min(info.width, imageInfo->mWidth);
|
|
|
|
info.height = std::min(info.height, imageInfo->mHeight);
|
2019-02-01 02:39:12 +03:00
|
|
|
info.hasFloat32 |= fnIsFloat32(*imageInfo->mFormat->format);
|
2019-05-23 23:48:21 +03:00
|
|
|
info.zLayerCount = cur->ZLayerCount();
|
|
|
|
info.isMultiview = cur->IsMultiview();
|
2017-07-17 23:52:00 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
mCompletenessInfo = Some(std::move(info));
|
2019-07-04 07:34:45 +03:00
|
|
|
info.fb = nullptr; // Don't trigger the invalidation warning.
|
2016-07-19 10:36:54 +03:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
} while (false);
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
MOZ_ASSERT(ret != LOCAL_GL_FRAMEBUFFER_COMPLETE);
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->GenerateWarning("Framebuffer not complete. (status: 0x%04x) %s",
|
2018-10-17 07:18:15 +03:00
|
|
|
ret.get(), statusInfo.BeginReading());
|
|
|
|
return ret;
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
void WebGLFramebuffer::RefreshDrawBuffers() const {
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::draw_buffers)) return;
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// Prior to GL4.1, having a no-image FB attachment that's selected by
|
|
|
|
// DrawBuffers yields a framebuffer status of
|
|
|
|
// FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER. We could workaround this only on
|
|
|
|
// affected versions, but it's easier be unconditional.
|
2020-01-09 01:19:16 +03:00
|
|
|
std::vector<GLenum> driverBuffers(mContext->Limits().maxColorDrawBuffers,
|
|
|
|
LOCAL_GL_NONE);
|
2016-07-19 10:36:54 +03:00
|
|
|
for (const auto& attach : mColorDrawBuffers) {
|
|
|
|
if (attach->HasAttachment()) {
|
|
|
|
const uint32_t index =
|
|
|
|
attach->mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
2018-10-17 07:18:15 +03:00
|
|
|
driverBuffers[index] = attach->mAttachmentPoint;
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
gl->fDrawBuffers(driverBuffers.size(), driverBuffers.data());
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
void WebGLFramebuffer::RefreshReadBuffer() const {
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2016-12-07 03:34:39 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::read_buffer)) return;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
// Prior to GL4.1, having a no-image FB attachment that's selected by
|
2016-09-09 01:56:58 +03:00
|
|
|
// ReadBuffer yields a framebuffer status of
|
|
|
|
// FRAMEBUFFER_INCOMPLETE_READ_BUFFER. We could workaround this only on
|
2016-07-19 10:36:54 +03:00
|
|
|
// affected versions, but it's easier be unconditional.
|
2016-09-09 01:56:58 +03:00
|
|
|
GLenum driverBuffer = LOCAL_GL_NONE;
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mColorReadBuffer && mColorReadBuffer->HasAttachment()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
driverBuffer = mColorReadBuffer->mAttachmentPoint;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
gl->fReadBuffer(driverBuffer);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
void WebGLFramebuffer::DrawBuffers(const std::vector<GLenum>& buffers) {
|
|
|
|
if (buffers.size() > mContext->MaxValidDrawBuffers()) {
|
2017-07-27 10:48:58 +03:00
|
|
|
// "An INVALID_VALUE error is generated if `n` is greater than
|
2018-07-27 07:46:33 +03:00
|
|
|
// MAX_DRAW_BUFFERS."
|
|
|
|
mContext->ErrorInvalidValue(
|
|
|
|
"`buffers` must have a length <="
|
2016-07-19 10:36:54 +03:00
|
|
|
" MAX_DRAW_BUFFERS.");
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
std::vector<const WebGLFBAttachPoint*> newColorDrawBuffers;
|
2020-01-09 01:19:16 +03:00
|
|
|
newColorDrawBuffers.reserve(buffers.size());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
for (const auto i : IntegerRange(buffers.size())) {
|
2016-07-19 10:36:54 +03:00
|
|
|
// "If the GL is bound to a draw framebuffer object, the `i`th buffer listed
|
|
|
|
// in bufs must be COLOR_ATTACHMENTi or NONE. Specifying a buffer out of
|
|
|
|
// order, BACK, or COLOR_ATTACHMENTm where `m` is greater than or equal to
|
|
|
|
// the value of MAX_COLOR_ATTACHMENTS, will generate the error
|
|
|
|
// INVALID_OPERATION.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// WEBGL_draw_buffers:
|
|
|
|
// "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater
|
|
|
|
// than or equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter." This
|
|
|
|
// means that if buffers.Length() isn't larger than MaxDrawBuffers, it won't
|
|
|
|
// be larger than MaxColorAttachments.
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto& cur = buffers[i];
|
|
|
|
if (cur == LOCAL_GL_COLOR_ATTACHMENT0 + i) {
|
|
|
|
const auto& attach = mColorAttachments[i];
|
|
|
|
newColorDrawBuffers.push_back(&attach);
|
|
|
|
} else if (cur != LOCAL_GL_NONE) {
|
2016-12-23 04:08:35 +03:00
|
|
|
const bool isColorEnum = (cur >= LOCAL_GL_COLOR_ATTACHMENT0 &&
|
2016-07-19 10:36:54 +03:00
|
|
|
cur < mContext->LastColorAttachmentEnum());
|
2016-12-23 04:08:35 +03:00
|
|
|
if (cur != LOCAL_GL_BACK && !isColorEnum) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidEnum("Unexpected enum in buffers.");
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"`buffers[i]` must be NONE or"
|
|
|
|
" COLOR_ATTACHMENTi.");
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
mColorDrawBuffers = std::move(newColorDrawBuffers);
|
2018-10-17 07:18:15 +03:00
|
|
|
RefreshDrawBuffers(); // Calls glDrawBuffers.
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2020-01-17 06:40:19 +03:00
|
|
|
bool WebGLFramebuffer::IsDrawBufferEnabled(const uint32_t slotId) const {
|
|
|
|
const auto attachEnum = LOCAL_GL_COLOR_ATTACHMENT0 + slotId;
|
|
|
|
for (const auto& cur : mColorDrawBuffers) {
|
|
|
|
if (cur->mAttachmentPoint == attachEnum) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
void WebGLFramebuffer::ReadBuffer(GLenum attachPoint) {
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& maybeAttach = GetColorAttachPoint(attachPoint);
|
2016-09-02 02:19:50 +03:00
|
|
|
if (!maybeAttach) {
|
|
|
|
const char text[] =
|
|
|
|
"`mode` must be a COLOR_ATTACHMENTi, for 0 <= i <"
|
2016-09-01 23:53:51 +03:00
|
|
|
" MAX_DRAW_BUFFERS.";
|
2016-09-02 02:19:50 +03:00
|
|
|
if (attachPoint == LOCAL_GL_BACK) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(text);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidEnum(text);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& attach = maybeAttach.value(); // Might be nullptr.
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
mColorReadBuffer = attach;
|
2016-07-19 10:36:54 +03:00
|
|
|
RefreshReadBuffer(); // Calls glReadBuffer.
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
bool WebGLFramebuffer::FramebufferAttach(const GLenum attachEnum,
|
2019-05-23 23:48:21 +03:00
|
|
|
const webgl::FbAttachInfo& toAttach) {
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-04-07 21:48:13 +03:00
|
|
|
if (MOZ_UNLIKELY(mOpaque)) {
|
|
|
|
// An opaque framebuffer's attachments cannot be inspected or changed.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// `attachment`
|
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
2020-01-09 01:19:16 +03:00
|
|
|
if (!maybeAttach || !maybeAttach.value()) return false;
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto& attach = maybeAttach.value();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGLName);
|
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
2019-05-23 23:48:21 +03:00
|
|
|
mDepthAttachment.Set(gl, toAttach);
|
|
|
|
mStencilAttachment.Set(gl, toAttach);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2019-05-23 23:48:21 +03:00
|
|
|
attach->Set(gl, toAttach);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
InvalidateCaches();
|
2020-01-09 01:19:16 +03:00
|
|
|
return true;
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
Maybe<double> WebGLFramebuffer::GetAttachmentParameter(GLenum attachEnum,
|
|
|
|
GLenum pname) {
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
|
|
|
if (!maybeAttach || attachEnum == LOCAL_GL_NONE) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidEnum(
|
|
|
|
"Can only query COLOR_ATTACHMENTi,"
|
2015-11-25 07:15:29 +03:00
|
|
|
" DEPTH_ATTACHMENT, DEPTH_STENCIL_ATTACHMENT, or"
|
2018-07-27 07:46:33 +03:00
|
|
|
" STENCIL_ATTACHMENT for a framebuffer.");
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2020-04-07 21:48:13 +03:00
|
|
|
if (MOZ_UNLIKELY(mOpaque)) {
|
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"An opaque framebuffer's attachments cannot be inspected or changed.");
|
|
|
|
return Nothing();
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
auto attach = maybeAttach.value();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
// There are a couple special rules for this one.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Querying"
|
2015-11-25 07:15:29 +03:00
|
|
|
" FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
|
|
|
|
" against DEPTH_STENCIL_ATTACHMENT is an"
|
2018-07-27 07:46:33 +03:00
|
|
|
" error.");
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mDepthAttachment.Renderbuffer() != mStencilAttachment.Renderbuffer() ||
|
|
|
|
mDepthAttachment.Texture() != mStencilAttachment.Texture()) {
|
|
|
|
mContext->ErrorInvalidOperation(
|
2018-07-27 07:46:33 +03:00
|
|
|
"DEPTH_ATTACHMENT and STENCIL_ATTACHMENT"
|
|
|
|
" have different objects bound.");
|
2020-01-09 01:19:14 +03:00
|
|
|
return Nothing();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
attach = &mDepthAttachment;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
return attach->GetParameter(mContext, attachEnum, pname);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
////////////////////
|
2018-10-17 07:18:15 +03:00
|
|
|
|
|
|
|
static void GetBackbufferFormats(const WebGLContext* webgl,
|
|
|
|
const webgl::FormatInfo** const out_color,
|
|
|
|
const webgl::FormatInfo** const out_depth,
|
|
|
|
const webgl::FormatInfo** const out_stencil) {
|
|
|
|
const auto& options = webgl->Options();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto effFormat = (options.alpha ? webgl::EffectiveFormat::RGBA8
|
2016-07-19 10:36:54 +03:00
|
|
|
: webgl::EffectiveFormat::RGB8);
|
2018-10-17 07:18:15 +03:00
|
|
|
*out_color = webgl::GetFormat(effFormat);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
*out_depth = nullptr;
|
|
|
|
*out_stencil = nullptr;
|
2018-10-17 07:18:15 +03:00
|
|
|
if (options.depth && options.stencil) {
|
2016-07-19 10:36:54 +03:00
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH24_STENCIL8);
|
2018-10-17 07:18:15 +03:00
|
|
|
*out_stencil = *out_depth;
|
|
|
|
} else {
|
2016-07-19 10:36:54 +03:00
|
|
|
if (options.depth) {
|
2018-10-17 07:18:15 +03:00
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT16);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
if (options.stencil) {
|
2018-10-17 07:18:15 +03:00
|
|
|
*out_stencil = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/*static*/
|
2020-11-23 22:54:41 +03:00
|
|
|
void WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl, GLint _srcX0,
|
|
|
|
GLint _srcY0, GLint _srcX1, GLint _srcY1,
|
|
|
|
GLint _dstX0, GLint _dstY0, GLint _dstX1,
|
|
|
|
GLint _dstY1, GLbitfield mask,
|
2019-02-26 01:05:29 +03:00
|
|
|
GLenum filter) {
|
2020-11-23 22:54:41 +03:00
|
|
|
auto srcP0 = ivec2{_srcX0, _srcY0};
|
|
|
|
auto srcP1 = ivec2{_srcX1, _srcY1};
|
|
|
|
auto dstP0 = ivec2{_dstX0, _dstY0};
|
|
|
|
auto dstP1 = ivec2{_dstX1, _dstY1};
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const GLbitfield depthAndStencilBits =
|
|
|
|
LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
if (bool(mask & depthAndStencilBits) && filter == LOCAL_GL_LINEAR) {
|
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"DEPTH_BUFFER_BIT and STENCIL_BUFFER_BIT can"
|
|
|
|
" only be used with NEAREST filtering.");
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
const auto& srcFB = webgl->mBoundReadFramebuffer;
|
|
|
|
const auto& dstFB = webgl->mBoundDrawFramebuffer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
// Collect data
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto fnGetFormat =
|
2017-01-12 03:03:56 +03:00
|
|
|
[](const WebGLFBAttachPoint& cur,
|
2016-12-30 14:02:14 +03:00
|
|
|
bool* const out_hasSamples) -> const webgl::FormatInfo* {
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& imageInfo = cur.GetImageInfo();
|
|
|
|
if (!imageInfo) return nullptr; // No attachment.
|
|
|
|
*out_hasSamples = bool(imageInfo->mSamples);
|
|
|
|
return imageInfo->mFormat->format;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
bool srcHasSamples = false;
|
|
|
|
bool srcIsFilterable = true;
|
2016-07-19 10:36:54 +03:00
|
|
|
const webgl::FormatInfo* srcColorFormat;
|
|
|
|
const webgl::FormatInfo* srcDepthFormat;
|
|
|
|
const webgl::FormatInfo* srcStencilFormat;
|
2019-06-15 08:18:05 +03:00
|
|
|
gfx::IntSize srcSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (srcFB) {
|
2019-05-23 23:48:21 +03:00
|
|
|
const auto& info = *srcFB->GetCompletenessInfo();
|
|
|
|
if (info.zLayerCount != 1) {
|
2020-03-27 17:10:45 +03:00
|
|
|
webgl->GenerateError(
|
|
|
|
LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION,
|
|
|
|
"Source framebuffer cannot have more than one multiview layer.");
|
2019-05-23 23:48:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
srcColorFormat = nullptr;
|
|
|
|
if (srcFB->mColorReadBuffer) {
|
|
|
|
const auto& imageInfo = srcFB->mColorReadBuffer->GetImageInfo();
|
|
|
|
if (imageInfo) {
|
|
|
|
srcIsFilterable &= imageInfo->mFormat->isFilterable;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
srcColorFormat = fnGetFormat(*(srcFB->mColorReadBuffer), &srcHasSamples);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-10-17 07:18:15 +03:00
|
|
|
srcDepthFormat = fnGetFormat(srcFB->DepthAttachment(), &srcHasSamples);
|
|
|
|
srcStencilFormat = fnGetFormat(srcFB->StencilAttachment(), &srcHasSamples);
|
|
|
|
MOZ_ASSERT(!srcFB->DepthStencilAttachment().HasAttachment());
|
2019-06-15 08:18:05 +03:00
|
|
|
srcSize = {info.width, info.height};
|
2018-10-17 07:18:15 +03:00
|
|
|
} else {
|
2016-12-30 14:02:14 +03:00
|
|
|
srcHasSamples = false; // Always false.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
GetBackbufferFormats(webgl, &srcColorFormat, &srcDepthFormat,
|
|
|
|
&srcStencilFormat);
|
2020-01-09 01:19:16 +03:00
|
|
|
const auto& size = webgl->DrawingBufferSize();
|
|
|
|
srcSize = {size.x, size.y};
|
2018-10-17 07:18:15 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
////
|
2018-10-17 07:18:15 +03:00
|
|
|
|
|
|
|
bool dstHasSamples = false;
|
2016-07-19 10:36:54 +03:00
|
|
|
const webgl::FormatInfo* dstDepthFormat;
|
|
|
|
const webgl::FormatInfo* dstStencilFormat;
|
|
|
|
bool dstHasColor = false;
|
|
|
|
bool colorFormatsMatch = true;
|
|
|
|
bool colorTypesMatch = true;
|
2019-06-15 08:18:05 +03:00
|
|
|
bool colorSrgbMatches = true;
|
|
|
|
gfx::IntSize dstSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnCheckColorFormat = [&](const webgl::FormatInfo* dstFormat) {
|
2016-12-17 04:48:06 +03:00
|
|
|
MOZ_ASSERT(dstFormat->r || dstFormat->g || dstFormat->b || dstFormat->a);
|
2016-07-19 10:36:54 +03:00
|
|
|
dstHasColor = true;
|
|
|
|
colorFormatsMatch &= (dstFormat == srcColorFormat);
|
2018-10-17 07:18:15 +03:00
|
|
|
colorTypesMatch &=
|
|
|
|
srcColorFormat && (dstFormat->baseType == srcColorFormat->baseType);
|
2019-06-15 08:18:05 +03:00
|
|
|
colorSrgbMatches &=
|
|
|
|
srcColorFormat && (dstFormat->isSRGB == srcColorFormat->isSRGB);
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (dstFB) {
|
2016-12-30 14:02:14 +03:00
|
|
|
for (const auto& cur : dstFB->mColorDrawBuffers) {
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& format = fnGetFormat(*cur, &dstHasSamples);
|
2016-12-30 14:02:14 +03:00
|
|
|
if (!format) continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-30 14:02:14 +03:00
|
|
|
fnCheckColorFormat(format);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
dstDepthFormat = fnGetFormat(dstFB->DepthAttachment(), &dstHasSamples);
|
|
|
|
dstStencilFormat = fnGetFormat(dstFB->StencilAttachment(), &dstHasSamples);
|
|
|
|
MOZ_ASSERT(!dstFB->DepthStencilAttachment().HasAttachment());
|
2019-06-15 08:18:05 +03:00
|
|
|
|
|
|
|
const auto& info = *dstFB->GetCompletenessInfo();
|
2020-02-23 07:22:54 +03:00
|
|
|
if (info.isMultiview) {
|
2020-03-27 17:10:45 +03:00
|
|
|
webgl->GenerateError(
|
|
|
|
LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION,
|
|
|
|
"Destination framebuffer cannot have multiview attachments.");
|
2020-02-23 07:22:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-06-15 08:18:05 +03:00
|
|
|
dstSize = {info.width, info.height};
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-10-17 07:18:15 +03:00
|
|
|
dstHasSamples = webgl->Options().antialias;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const webgl::FormatInfo* dstColorFormat;
|
|
|
|
GetBackbufferFormats(webgl, &dstColorFormat, &dstDepthFormat,
|
2018-10-17 07:18:15 +03:00
|
|
|
&dstStencilFormat);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fnCheckColorFormat(dstColorFormat);
|
2019-06-15 08:18:05 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
const auto& size = webgl->DrawingBufferSize();
|
|
|
|
dstSize = {size.x, size.y};
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
// Clear unused buffer bits
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT && !srcColorFormat && !dstHasColor) {
|
|
|
|
mask ^= LOCAL_GL_COLOR_BUFFER_BIT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT && !srcDepthFormat && !dstDepthFormat) {
|
|
|
|
mask ^= LOCAL_GL_DEPTH_BUFFER_BIT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT && !srcStencilFormat &&
|
|
|
|
!dstStencilFormat) {
|
|
|
|
mask ^= LOCAL_GL_STENCIL_BUFFER_BIT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
// Validation
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
if (dstHasSamples) {
|
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"DRAW_FRAMEBUFFER may not have multiple"
|
|
|
|
" samples.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
bool requireFilterable = (filter == LOCAL_GL_LINEAR);
|
|
|
|
if (srcHasSamples) {
|
|
|
|
requireFilterable = false; // It picks one.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT && dstHasColor && !colorFormatsMatch) {
|
2018-10-17 07:18:15 +03:00
|
|
|
webgl->ErrorInvalidOperation(
|
2018-07-27 07:46:33 +03:00
|
|
|
"Color buffer formats must match if"
|
2018-10-17 07:18:15 +03:00
|
|
|
" selected, when reading from a multisampled"
|
|
|
|
" source.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-23 22:54:41 +03:00
|
|
|
if (srcP0 != dstP0 || srcP1 != dstP1) {
|
2018-10-17 07:18:15 +03:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"If the source is multisampled, then the"
|
|
|
|
" source and dest regions must match exactly.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
// -
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
2018-10-17 07:18:15 +03:00
|
|
|
if (requireFilterable && !srcIsFilterable) {
|
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"`filter` is LINEAR and READ_BUFFER"
|
|
|
|
" contains integer data.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!colorTypesMatch) {
|
2018-10-17 07:18:15 +03:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"Color component types (float/uint/"
|
2018-07-27 07:46:33 +03:00
|
|
|
"int) must match.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
/* GLES 3.0.4, p199:
|
|
|
|
* Calling BlitFramebuffer will result in an INVALID_OPERATION error if
|
|
|
|
* mask includes DEPTH_BUFFER_BIT or STENCIL_BUFFER_BIT, and the source
|
|
|
|
* and destination depth and stencil buffer formats do not match.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2016-07-19 10:36:54 +03:00
|
|
|
* jgilbert: The wording is such that if only DEPTH_BUFFER_BIT is specified,
|
|
|
|
* the stencil formats must match. This seems wrong. It could be a spec bug,
|
|
|
|
* or I could be missing an interaction in one of the earlier paragraphs.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT && dstDepthFormat &&
|
2016-12-30 14:02:14 +03:00
|
|
|
dstDepthFormat != srcDepthFormat) {
|
2018-10-17 07:18:15 +03:00
|
|
|
webgl->ErrorInvalidOperation(
|
2018-07-27 07:46:33 +03:00
|
|
|
"Depth buffer formats must match if selected.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT && dstStencilFormat &&
|
2016-12-30 14:02:14 +03:00
|
|
|
dstStencilFormat != srcStencilFormat) {
|
2018-10-17 07:18:15 +03:00
|
|
|
webgl->ErrorInvalidOperation(
|
2018-07-27 07:46:33 +03:00
|
|
|
"Stencil buffer formats must match if selected.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
// Check for feedback
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (srcFB && dstFB) {
|
2016-12-22 11:08:14 +03:00
|
|
|
const WebGLFBAttachPoint* feedback = nullptr;
|
2018-10-17 07:18:15 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
2018-10-17 07:18:15 +03:00
|
|
|
MOZ_ASSERT(srcFB->mColorReadBuffer->HasAttachment());
|
|
|
|
for (const auto& cur : dstFB->mColorDrawBuffers) {
|
|
|
|
if (srcFB->mColorReadBuffer->IsEquivalentForFeedback(*cur)) {
|
2018-07-27 07:46:33 +03:00
|
|
|
feedback = cur;
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
|
2018-07-27 07:46:33 +03:00
|
|
|
srcFB->DepthAttachment().IsEquivalentForFeedback(
|
|
|
|
dstFB->DepthAttachment())) {
|
|
|
|
feedback = &dstFB->DepthAttachment();
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
|
2018-07-27 07:46:33 +03:00
|
|
|
srcFB->StencilAttachment().IsEquivalentForFeedback(
|
|
|
|
dstFB->StencilAttachment())) {
|
|
|
|
feedback = &dstFB->StencilAttachment();
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2016-12-30 14:02:14 +03:00
|
|
|
if (feedback) {
|
|
|
|
webgl->ErrorInvalidOperation(
|
2018-10-17 07:18:15 +03:00
|
|
|
"Feedback detected into DRAW_FRAMEBUFFER's"
|
2016-07-19 10:36:54 +03:00
|
|
|
" 0x%04x attachment.",
|
2018-07-27 07:46:33 +03:00
|
|
|
feedback->mAttachmentPoint);
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (!srcFB && !dstFB) {
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidOperation("Feedback with default framebuffer.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2019-06-15 08:18:05 +03:00
|
|
|
// -
|
2020-11-23 22:54:41 +03:00
|
|
|
// Mutually constrain src and dst rects for eldritch blits.
|
|
|
|
|
2020-12-07 13:17:57 +03:00
|
|
|
[&] {
|
|
|
|
using fvec2 = avec2<float>; // Switch to float, because there's no perfect
|
|
|
|
// solution anyway.
|
2020-11-23 22:54:41 +03:00
|
|
|
|
|
|
|
const auto zero2f = fvec2{0, 0};
|
|
|
|
const auto srcSizef = AsVec(srcSize).StaticCast<fvec2>();
|
|
|
|
const auto dstSizef = AsVec(dstSize).StaticCast<fvec2>();
|
|
|
|
|
|
|
|
const auto srcP0f = srcP0.StaticCast<fvec2>();
|
|
|
|
const auto srcP1f = srcP1.StaticCast<fvec2>();
|
|
|
|
const auto dstP0f = dstP0.StaticCast<fvec2>();
|
|
|
|
const auto dstP1f = dstP1.StaticCast<fvec2>();
|
|
|
|
|
|
|
|
const auto srcRectDiff = srcP1f - srcP0f;
|
|
|
|
const auto dstRectDiff = dstP1f - dstP0f;
|
|
|
|
|
|
|
|
// Skip if zero-sized.
|
|
|
|
if (!srcRectDiff.x || !srcRectDiff.y || !dstRectDiff.x || !dstRectDiff.y) {
|
2020-12-07 13:17:57 +03:00
|
|
|
srcP0 = srcP1 = dstP0 = dstP1 = {0, 0};
|
2020-11-23 22:54:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp the rect points
|
|
|
|
const auto srcQ0 = srcP0f.ClampMinMax(zero2f, srcSizef);
|
|
|
|
const auto srcQ1 = srcP1f.ClampMinMax(zero2f, srcSizef);
|
|
|
|
|
|
|
|
// Normalized to the [0,1] abstact copy rect
|
|
|
|
const auto srcQ0Norm = (srcQ0 - srcP0f) / srcRectDiff;
|
|
|
|
const auto srcQ1Norm = (srcQ1 - srcP0f) / srcRectDiff;
|
|
|
|
|
|
|
|
// Map into dst
|
|
|
|
const auto srcQ0InDst = dstP0f + srcQ0Norm * dstRectDiff;
|
|
|
|
const auto srcQ1InDst = dstP0f + srcQ1Norm * dstRectDiff;
|
|
|
|
|
|
|
|
// Clamp the rect points
|
|
|
|
const auto dstQ0 = srcQ0InDst.ClampMinMax(zero2f, dstSizef);
|
|
|
|
const auto dstQ1 = srcQ1InDst.ClampMinMax(zero2f, dstSizef);
|
|
|
|
|
|
|
|
// Alright, time to go back to src!
|
|
|
|
// Normalized to the [0,1] abstact copy rect
|
|
|
|
const auto dstQ0Norm = (dstQ0 - dstP0f) / dstRectDiff;
|
|
|
|
const auto dstQ1Norm = (dstQ1 - dstP0f) / dstRectDiff;
|
|
|
|
|
|
|
|
// Map into src
|
|
|
|
const auto dstQ0InSrc = srcP0f + dstQ0Norm * srcRectDiff;
|
|
|
|
const auto dstQ1InSrc = srcP0f + dstQ1Norm * srcRectDiff;
|
|
|
|
|
|
|
|
const auto srcQ0Constrained = dstQ0InSrc.ClampMinMax(zero2f, srcSizef);
|
|
|
|
const auto srcQ1Constrained = dstQ1InSrc.ClampMinMax(zero2f, srcSizef);
|
|
|
|
|
|
|
|
// Round, don't floor:
|
|
|
|
srcP0 = (srcQ0Constrained + 0.5).StaticCast<ivec2>();
|
|
|
|
srcP1 = (srcQ1Constrained + 0.5).StaticCast<ivec2>();
|
|
|
|
dstP0 = (dstQ0 + 0.5).StaticCast<ivec2>();
|
|
|
|
dstP1 = (dstQ1 + 0.5).StaticCast<ivec2>();
|
|
|
|
}();
|
|
|
|
|
|
|
|
bool inBounds = true;
|
2020-12-07 13:17:57 +03:00
|
|
|
inBounds &= (srcP0 == srcP0.Clamp({0, 0}, AsVec(srcSize)));
|
|
|
|
inBounds &= (srcP1 == srcP1.Clamp({0, 0}, AsVec(srcSize)));
|
|
|
|
inBounds &= (dstP0 == dstP0.Clamp({0, 0}, AsVec(dstSize)));
|
|
|
|
inBounds &= (dstP1 == dstP1.Clamp({0, 0}, AsVec(dstSize)));
|
2020-11-23 22:54:41 +03:00
|
|
|
if (!inBounds) {
|
2020-12-07 13:17:57 +03:00
|
|
|
webgl->ErrorImplementationBug(
|
|
|
|
"Subrects still not within src and dst after constraining.");
|
2020-11-23 22:54:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
// Execute as constrained
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
const auto& gl = webgl->gl;
|
2017-12-19 05:30:56 +03:00
|
|
|
const ScopedDrawCallWrapper wrapper(*webgl);
|
2020-11-23 22:54:41 +03:00
|
|
|
|
|
|
|
gl->fBlitFramebuffer(srcP0.x, srcP0.y, srcP1.x, srcP1.y, dstP0.x, dstP0.y,
|
|
|
|
dstP1.x, dstP1.y, mask, filter);
|
2019-01-26 03:55:57 +03:00
|
|
|
|
2019-06-15 08:18:05 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT && !colorSrgbMatches && !gl->IsGLES() &&
|
|
|
|
gl->Version() < 440) {
|
|
|
|
// Mostly for Mac.
|
|
|
|
// Remember, we have to filter in the *linear* format blit.
|
|
|
|
|
|
|
|
// src -Blit-> fbB -DrawBlit-> fbC -Blit-> dst
|
|
|
|
|
|
|
|
const auto fbB = gl::MozFramebuffer::Create(gl, {1, 1}, 0, false);
|
|
|
|
const auto fbC = gl::MozFramebuffer::Create(gl, {1, 1}, 0, false);
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
auto sizeBC = srcSize;
|
|
|
|
GLenum formatC = LOCAL_GL_RGBA8;
|
|
|
|
if (srcColorFormat->isSRGB) {
|
|
|
|
// srgb -> linear
|
|
|
|
} else {
|
|
|
|
// linear -> srgb
|
|
|
|
sizeBC = dstSize;
|
|
|
|
formatC = LOCAL_GL_SRGB8_ALPHA8;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto fnSetTex = [&](const gl::MozFramebuffer& fb,
|
|
|
|
const GLenum format) {
|
|
|
|
const gl::ScopedBindTexture bindTex(gl, fb.ColorTex());
|
|
|
|
gl->fTexStorage2D(LOCAL_GL_TEXTURE_2D, 1, format, sizeBC.width,
|
|
|
|
sizeBC.height);
|
|
|
|
};
|
|
|
|
fnSetTex(*fbB, srcColorFormat->sizedFormat);
|
|
|
|
fnSetTex(*fbC, formatC);
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
{
|
|
|
|
const gl::ScopedBindFramebuffer bindFb(gl);
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER, fbB->mFB);
|
|
|
|
|
|
|
|
if (srcColorFormat->isSRGB) {
|
|
|
|
// srgb -> linear
|
2020-11-23 22:54:41 +03:00
|
|
|
gl->fBlitFramebuffer(srcP0.x, srcP0.y, srcP1.x, srcP1.y, srcP0.x,
|
|
|
|
srcP0.y, srcP1.x, srcP1.y,
|
|
|
|
LOCAL_GL_COLOR_BUFFER_BIT, LOCAL_GL_NEAREST);
|
2019-06-15 08:18:05 +03:00
|
|
|
} else {
|
|
|
|
// linear -> srgb
|
2020-11-23 22:54:41 +03:00
|
|
|
gl->fBlitFramebuffer(srcP0.x, srcP0.y, srcP1.x, srcP1.y, dstP0.x,
|
|
|
|
dstP0.y, dstP1.x, dstP1.y,
|
|
|
|
LOCAL_GL_COLOR_BUFFER_BIT, filter);
|
2019-06-15 08:18:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto& blitHelper = *gl->BlitHelper();
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER, fbC->mFB);
|
|
|
|
blitHelper.DrawBlitTextureToFramebuffer(fbB->ColorTex(), sizeBC, sizeBC);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const gl::ScopedBindFramebuffer bindFb(gl);
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER, fbC->mFB);
|
|
|
|
|
|
|
|
if (srcColorFormat->isSRGB) {
|
|
|
|
// srgb -> linear
|
2020-11-23 22:54:41 +03:00
|
|
|
gl->fBlitFramebuffer(srcP0.x, srcP0.y, srcP1.x, srcP1.y, dstP0.x,
|
|
|
|
dstP0.y, dstP1.x, dstP1.y,
|
|
|
|
LOCAL_GL_COLOR_BUFFER_BIT, filter);
|
2019-06-15 08:18:05 +03:00
|
|
|
} else {
|
|
|
|
// linear -> srgb
|
2020-11-23 22:54:41 +03:00
|
|
|
gl->fBlitFramebuffer(dstP0.x, dstP0.y, dstP1.x, dstP1.y, dstP0.x,
|
|
|
|
dstP0.y, dstP1.x, dstP1.y,
|
|
|
|
LOCAL_GL_COLOR_BUFFER_BIT, LOCAL_GL_NEAREST);
|
2019-06-15 08:18:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 03:55:57 +03:00
|
|
|
// -
|
|
|
|
// glBlitFramebuffer ignores glColorMask!
|
|
|
|
|
|
|
|
if (!webgl->mBoundDrawFramebuffer && webgl->mNeedsFakeNoAlpha) {
|
|
|
|
if (!webgl->mScissorTestEnabled) {
|
|
|
|
gl->fEnable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
if (webgl->mRasterizerDiscardEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_RASTERIZER_DISCARD);
|
|
|
|
}
|
2020-11-23 22:54:41 +03:00
|
|
|
|
|
|
|
const auto dstRectMin = MinExtents(dstP0, dstP1);
|
|
|
|
const auto dstRectMax = MaxExtents(dstP0, dstP1);
|
|
|
|
const auto dstRectSize = dstRectMax - dstRectMin;
|
|
|
|
const WebGLContext::ScissorRect dstRect = {dstRectMin.x, dstRectMin.y,
|
|
|
|
dstRectSize.x, dstRectSize.y};
|
2019-01-26 03:55:57 +03:00
|
|
|
dstRect.Apply(*gl);
|
|
|
|
|
2020-11-23 22:54:41 +03:00
|
|
|
gl->fClearColor(0, 0, 0, 1);
|
|
|
|
webgl->DoColorMask(1 << 3);
|
2019-01-26 03:55:57 +03:00
|
|
|
gl->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
if (!webgl->mScissorTestEnabled) {
|
|
|
|
gl->fDisable(LOCAL_GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
if (webgl->mRasterizerDiscardEnabled) {
|
|
|
|
gl->fEnable(LOCAL_GL_RASTERIZER_DISCARD);
|
|
|
|
}
|
|
|
|
webgl->mScissorRect.Apply(*gl);
|
|
|
|
gl->fClearColor(webgl->mColorClearValue[0], webgl->mColorClearValue[1],
|
|
|
|
webgl->mColorClearValue[2], webgl->mColorClearValue[3]);
|
|
|
|
}
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|