2012-10-05 00:35:54 +04: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-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>
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "GLContext.h"
|
2016-07-19 10:36:54 +03:00
|
|
|
#include "GLScreenBuffer.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.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"
|
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
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLFBAttachPoint::WebGLFBAttachPoint()
|
|
|
|
: mFB(nullptr)
|
|
|
|
, mAttachmentPoint(0)
|
|
|
|
, mTexImageTarget(LOCAL_GL_NONE)
|
|
|
|
, mTexImageLayer(0)
|
|
|
|
, mTexImageLevel(0)
|
|
|
|
{ }
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLFBAttachPoint::WebGLFBAttachPoint(WebGLFramebuffer* fb, GLenum attachmentPoint)
|
2015-03-25 02:00:28 +03:00
|
|
|
: mFB(fb)
|
|
|
|
, mAttachmentPoint(attachmentPoint)
|
2014-09-19 03:14:22 +04:00
|
|
|
, mTexImageTarget(LOCAL_GL_NONE)
|
2016-01-12 21:16:59 +03:00
|
|
|
, mTexImageLayer(0)
|
|
|
|
, mTexImageLevel(0)
|
2015-03-25 02:00:28 +03:00
|
|
|
{ }
|
2014-07-30 23:52:07 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::~WebGLFBAttachPoint()
|
2014-07-30 23:52:07 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mFB, "Should have been Init'd.");
|
2015-03-25 02:00:28 +03:00
|
|
|
MOZ_ASSERT(!mRenderbufferPtr);
|
|
|
|
MOZ_ASSERT(!mTexturePtr);
|
2014-07-30 23:52:07 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
WebGLFBAttachPoint::Unlink()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
bool
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::IsDeleteRequested() const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2012-12-09 15:58:41 +04:00
|
|
|
return Texture() ? Texture()->IsDeleteRequested()
|
|
|
|
: Renderbuffer() ? Renderbuffer()->IsDeleteRequested()
|
|
|
|
: false;
|
|
|
|
}
|
|
|
|
|
2014-09-23 21:48:27 +04:00
|
|
|
bool
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::IsDefined() const
|
2014-09-23 21:48:27 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
/*
|
|
|
|
return (Renderbuffer() && Renderbuffer()->IsDefined()) ||
|
|
|
|
(Texture() && Texture()->ImageInfoAt(mTexImageTarget,
|
|
|
|
mTexImageLevel).IsDefined());
|
|
|
|
*/
|
|
|
|
return (Renderbuffer() || Texture());
|
2014-09-23 21:48:27 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatUsageInfo*
|
|
|
|
WebGLFBAttachPoint::Format() const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(IsDefined());
|
2014-02-14 03:07:59 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (Texture())
|
|
|
|
return Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).mFormat;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
if (Renderbuffer())
|
2015-11-25 07:15:29 +03:00
|
|
|
return Renderbuffer()->Format();
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
uint32_t
|
|
|
|
WebGLFBAttachPoint::Samples() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsDefined());
|
|
|
|
|
|
|
|
if (mRenderbufferPtr)
|
|
|
|
return mRenderbufferPtr->Samples();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool
|
|
|
|
WebGLFBAttachPoint::HasAlpha() const
|
|
|
|
{
|
2016-07-09 00:57:18 +03:00
|
|
|
return Format()->format->a;
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool
|
|
|
|
WebGLFBAttachPoint::IsReadableFloat() const
|
2014-03-08 01:26:17 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
auto formatUsage = Format();
|
|
|
|
MOZ_ASSERT(formatUsage);
|
2014-03-08 01:26:17 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto format = formatUsage->format;
|
2016-07-09 00:57:18 +03:00
|
|
|
if (!format->IsColorFormat())
|
2015-11-25 07:15:29 +03:00
|
|
|
return false;
|
2014-03-08 01:26:17 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return format->componentType == webgl::ComponentType::Float;
|
2014-10-08 03:52:58 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
WebGLFBAttachPoint::Clear()
|
2014-10-08 03:52:58 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mRenderbufferPtr) {
|
|
|
|
MOZ_ASSERT(!mTexturePtr);
|
|
|
|
mRenderbufferPtr->UnmarkAttachment(*this);
|
|
|
|
} else if (mTexturePtr) {
|
|
|
|
mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel).RemoveAttachPoint(this);
|
|
|
|
}
|
2014-03-08 01:26:17 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
mTexturePtr = nullptr;
|
|
|
|
mRenderbufferPtr = nullptr;
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
OnBackingStoreRespecified();
|
2015-03-25 02:00:28 +03:00
|
|
|
}
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
void
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLFBAttachPoint::SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level,
|
|
|
|
GLint layer)
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
Clear();
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
mTexturePtr = tex;
|
2013-10-02 04:30:38 +04:00
|
|
|
mTexImageTarget = target;
|
|
|
|
mTexImageLevel = level;
|
2015-07-03 04:55:43 +03:00
|
|
|
mTexImageLayer = layer;
|
2014-03-12 03:10:59 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mTexturePtr) {
|
|
|
|
mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel).AddAttachPoint(this);
|
|
|
|
}
|
2014-03-12 03:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::SetRenderbuffer(WebGLRenderbuffer* rb)
|
2014-03-12 03:10:59 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
Clear();
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2014-03-12 03:10:59 +04:00
|
|
|
mRenderbufferPtr = rb;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mRenderbufferPtr) {
|
|
|
|
mRenderbufferPtr->MarkAttachment(*this);
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::HasUninitializedImageData() const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
|
|
|
if (!HasImage())
|
2013-10-11 17:16:43 +04:00
|
|
|
return false;
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mRenderbufferPtr)
|
|
|
|
return mRenderbufferPtr->HasUninitializedImageData();
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(mTexturePtr);
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto& imageInfo = mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel);
|
|
|
|
MOZ_ASSERT(imageInfo.IsDefined());
|
|
|
|
|
|
|
|
return !imageInfo.IsDataInitialized();
|
2013-10-11 17:16:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLFBAttachPoint::SetImageDataStatus(WebGLImageDataStatus newStatus) const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
|
|
|
if (!HasImage())
|
|
|
|
return;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mRenderbufferPtr) {
|
|
|
|
mRenderbufferPtr->mImageDataStatus = newStatus;
|
2014-01-23 07:59:34 +04:00
|
|
|
return;
|
2014-02-14 03:07:59 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(mTexturePtr);
|
|
|
|
|
|
|
|
auto& imageInfo = mTexturePtr->ImageInfoAt(mTexImageTarget, mTexImageLevel);
|
|
|
|
MOZ_ASSERT(imageInfo.IsDefined());
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool isDataInitialized = (newStatus == WebGLImageDataStatus::InitializedImageData);
|
|
|
|
imageInfo.SetIsDataInitialized(isDataInitialized, mTexturePtr);
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
bool
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint::HasImage() const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
if (Texture() && Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).IsDefined())
|
2014-01-23 07:59:34 +04:00
|
|
|
return true;
|
2014-02-14 03:07:59 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (Renderbuffer() && Renderbuffer()->IsDefined())
|
2014-01-23 07:59:34 +04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
WebGLFBAttachPoint::Size(uint32_t* const out_width, uint32_t* const out_height) const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(HasImage());
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (Renderbuffer()) {
|
|
|
|
*out_width = Renderbuffer()->Width();
|
|
|
|
*out_height = Renderbuffer()->Height();
|
|
|
|
return;
|
2014-02-14 03:07:59 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(Texture());
|
|
|
|
MOZ_ASSERT(Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).IsDefined());
|
|
|
|
const auto& imageInfo = Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel);
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
*out_width = imageInfo.mWidth;
|
|
|
|
*out_height = imageInfo.mHeight;
|
2015-11-24 08:55:59 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
WebGLFBAttachPoint::OnBackingStoreRespecified() const
|
2015-11-24 08:55:59 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
mFB->InvalidateFramebufferStatus();
|
2013-11-05 01:05:04 +04:00
|
|
|
}
|
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
void
|
|
|
|
WebGLFBAttachPoint::AttachmentName(nsCString* out) const
|
|
|
|
{
|
|
|
|
switch (mAttachmentPoint) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
out->AssignLiteral("DEPTH_ATTACHMENT");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
out->AssignLiteral("STENCIL_ATTACHMENT");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
out->AssignLiteral("DEPTH_STENCIL_ATTACHMENT");
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
|
|
|
|
out->AssignLiteral("COLOR_ATTACHMENT");
|
|
|
|
const uint32_t n = mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
out->AppendInt(n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 02:04:08 +03:00
|
|
|
bool
|
2015-12-15 03:11:59 +03:00
|
|
|
WebGLFBAttachPoint::IsComplete(WebGLContext* webgl, nsCString* const out_info) const
|
2014-11-22 02:04:08 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(IsDefined());
|
2014-11-22 02:04:08 +03:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
if (!HasImage()) {
|
|
|
|
AttachmentName(out_info);
|
|
|
|
out_info->AppendLiteral("'s image is not defined");
|
2014-01-23 07:59:34 +04:00
|
|
|
return false;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
Size(&width, &height);
|
2015-12-15 03:11:59 +03:00
|
|
|
if (!width || !height) {
|
|
|
|
AttachmentName(out_info);
|
|
|
|
out_info->AppendLiteral(" has no width or height");
|
2015-11-24 06:27:13 +03:00
|
|
|
return false;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
const auto formatUsage = Format();
|
2016-06-06 23:43:18 +03:00
|
|
|
if (!formatUsage->IsRenderable()) {
|
2015-12-15 03:11:59 +03:00
|
|
|
nsAutoCString attachName;
|
|
|
|
AttachmentName(&attachName);
|
|
|
|
|
|
|
|
*out_info = nsPrintfCString("%s has an effective format of %s, which is not"
|
|
|
|
" renderable",
|
|
|
|
attachName.BeginReading(), formatUsage->format->name);
|
2015-11-25 07:15:29 +03:00
|
|
|
return false;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2014-01-24 07:53:53 +04: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;
|
|
|
|
}
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2015-12-15 03:11:59 +03:00
|
|
|
if (!hasRequiredBits) {
|
|
|
|
AttachmentName(out_info);
|
|
|
|
out_info->AppendLiteral("'s format is missing required color/depth/stencil bits");
|
|
|
|
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) {
|
|
|
|
AttachmentName(out_info);
|
|
|
|
out_info->AppendLiteral("'s format has depth or stencil bits when it"
|
|
|
|
" shouldn't");
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-24 08:55:59 +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
|
|
|
}
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
void
|
2016-09-09 01:56:58 +03:00
|
|
|
WebGLFBAttachPoint::Resolve(gl::GLContext* gl) const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2016-09-08 00:17:53 +03:00
|
|
|
if (!HasImage())
|
2014-03-12 03:10:59 +04:00
|
|
|
return;
|
2013-10-02 04:30:05 +04:00
|
|
|
|
|
|
|
if (Renderbuffer()) {
|
2016-09-09 01:56:58 +03:00
|
|
|
Renderbuffer()->DoFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint);
|
2013-10-02 04:30:05 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(Texture());
|
|
|
|
|
|
|
|
MOZ_ASSERT(gl == Texture()->mContext->GL());
|
|
|
|
|
|
|
|
const auto& texName = Texture()->mGLName;
|
|
|
|
|
2016-09-01 23:52:27 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
const auto fnAttach2D = [&](GLenum attachmentPoint) {
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, attachmentPoint,
|
|
|
|
mTexImageTarget.get(), texName, mTexImageLevel);
|
2016-09-01 23:52:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
switch (mTexImageTarget.get()) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
2016-09-01 23:52:27 +03:00
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
fnAttach2D(LOCAL_GL_DEPTH_ATTACHMENT);
|
|
|
|
fnAttach2D(LOCAL_GL_STENCIL_ATTACHMENT);
|
|
|
|
} else {
|
|
|
|
fnAttach2D(mAttachmentPoint);
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
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:
|
|
|
|
// If we have fFramebufferTextureLayer, we can rely on having
|
|
|
|
// DEPTH_STENCIL_ATTACHMENT.
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fFramebufferTextureLayer(LOCAL_GL_FRAMEBUFFER, mAttachmentPoint, texName,
|
|
|
|
mTexImageLevel, mTexImageLayer);
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-10-02 04:30:05 +04:00
|
|
|
}
|
|
|
|
|
2015-08-06 09:31:00 +03:00
|
|
|
JS::Value
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLFBAttachPoint::GetParameter(const char* funcName, WebGLContext* webgl, JSContext* cx,
|
|
|
|
GLenum target, GLenum attachment, GLenum pname,
|
2016-07-19 10:36:54 +03:00
|
|
|
ErrorResult* const out_error) const
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool hasAttachment = (mTexturePtr || mRenderbufferPtr);
|
|
|
|
if (!hasAttachment) {
|
|
|
|
// Divergent between GLES 3 and 2.
|
|
|
|
|
|
|
|
// GLES 2.0.25 p127:
|
|
|
|
// "If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, then querying any
|
|
|
|
// other pname will generate INVALID_ENUM."
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
return JS::Int32Value(LOCAL_GL_NONE);
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
|
|
if (webgl->IsWebGL2())
|
|
|
|
return JS::NullValue();
|
|
|
|
|
|
|
|
break;
|
2015-08-06 09:31:00 +03:00
|
|
|
|
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()) {
|
|
|
|
webgl->ErrorInvalidOperation("%s: No attachment at %s.", funcName,
|
2016-12-22 06:42:07 +03:00
|
|
|
attachmentName.BeginReading());
|
2015-11-25 07:15:29 +03:00
|
|
|
} else {
|
|
|
|
webgl->ErrorInvalidEnum("%s: No attachment at %s.", funcName,
|
2016-12-22 06:42:07 +03:00
|
|
|
attachmentName.BeginReading());
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
return JS::Int32Value(mTexturePtr ? LOCAL_GL_TEXTURE
|
|
|
|
: LOCAL_GL_RENDERBUFFER);
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
|
|
return (mTexturePtr ? webgl->WebGLObjectAsJSValue(cx, mTexturePtr.get(),
|
|
|
|
*out_error)
|
|
|
|
: webgl->WebGLObjectAsJSValue(cx, mRenderbufferPtr.get(),
|
|
|
|
*out_error));
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
//////
|
2015-08-06 09:31:00 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mTexturePtr)
|
2015-08-06 09:31:00 +03:00
|
|
|
return JS::Int32Value(MipLevel());
|
|
|
|
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) {
|
2015-08-06 09:31:00 +03:00
|
|
|
face = ImageTarget().get();
|
|
|
|
}
|
|
|
|
return JS::Int32Value(face);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
//////
|
|
|
|
|
2015-08-06 09:31:00 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
|
2016-07-09 01:48:36 +03:00
|
|
|
if (webgl->IsWebGL2() && mTexturePtr) {
|
2015-08-06 09:31:00 +03:00
|
|
|
int32_t layer = 0;
|
2015-11-25 07:15:29 +03:00
|
|
|
if (ImageTarget() == LOCAL_GL_TEXTURE_2D_ARRAY ||
|
|
|
|
ImageTarget() == LOCAL_GL_TEXTURE_3D)
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
|
|
|
layer = Layer();
|
|
|
|
}
|
|
|
|
return JS::Int32Value(layer);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
webgl->ErrorInvalidEnum("%s: Invalid pname: 0x%04x", funcName, pname);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
const auto usage = Format();
|
2016-12-23 00:19:03 +03:00
|
|
|
if (!usage) {
|
|
|
|
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING)
|
|
|
|
return JS::NumberValue(LOCAL_GL_LINEAR);
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
return JS::NullValue();
|
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);
|
|
|
|
|
2016-07-22 01:37:00 +03:00
|
|
|
if (format->componentType == webgl::ComponentType::Special) {
|
|
|
|
// Special format is used for DS mixed format(e.g. D24S8 and D32FS8).
|
2016-11-10 05:08:05 +03:00
|
|
|
MOZ_ASSERT(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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 01:48:36 +03:00
|
|
|
switch (format->componentType) {
|
|
|
|
case webgl::ComponentType::None:
|
|
|
|
ret = LOCAL_GL_NONE;
|
|
|
|
break;
|
|
|
|
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;
|
2016-07-22 01:37:00 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "No matched component type");
|
|
|
|
break;
|
2016-07-09 01:48:36 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Missing case.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::Int32Value(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)
|
2016-11-30 05:30:28 +03:00
|
|
|
: WebGLRefCountedObject(webgl)
|
2015-05-21 02:50:28 +03:00
|
|
|
, mGLName(fbo)
|
|
|
|
#ifdef ANDROID
|
|
|
|
, mIsFB(false)
|
|
|
|
#endif
|
2016-07-19 10:36:54 +03:00
|
|
|
, mDepthAttachment(this, LOCAL_GL_DEPTH_ATTACHMENT)
|
|
|
|
, mStencilAttachment(this, LOCAL_GL_STENCIL_ATTACHMENT)
|
|
|
|
, mDepthStencilAttachment(this, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
2015-03-17 04:03:40 +03:00
|
|
|
{
|
2015-03-25 02:00:28 +03:00
|
|
|
mContext->mFramebuffers.insertBack(this);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto& cur : mColorAttachments) {
|
|
|
|
new (&cur) WebGLFBAttachPoint(this, LOCAL_GL_COLOR_ATTACHMENT0 + i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mColorDrawBuffers.push_back(&mColorAttachments[0]);
|
|
|
|
mColorReadBuffer = &mColorAttachments[0];
|
2015-03-17 07:32:52 +03:00
|
|
|
}
|
2015-03-17 04:22:17 +03:00
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
void
|
2015-03-25 02:00:28 +03:00
|
|
|
WebGLFramebuffer::Delete()
|
2015-03-17 07:32:52 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
InvalidateFramebufferStatus();
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
mDepthAttachment.Clear();
|
|
|
|
mStencilAttachment.Clear();
|
|
|
|
mDepthStencilAttachment.Clear();
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
for (auto& cur : mColorAttachments) {
|
2015-11-25 07:15:29 +03:00
|
|
|
cur.Clear();
|
2014-06-24 11:15:44 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteFramebuffers(1, &mGLName);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
LinkedListElement<WebGLFramebuffer>::removeFrom(mContext->mFramebuffers);
|
2015-05-21 02:50:28 +03:00
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
mIsFB = false;
|
|
|
|
#endif
|
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)
|
2015-07-03 04:55:43 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
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
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mContext->mImplMaxColorAttachments <= kMaxColorAttachments);
|
|
|
|
if (colorId >= mContext->mImplMaxColorAttachments)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
Maybe<WebGLFBAttachPoint*>
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLFramebuffer::GetAttachPoint(GLenum attachPoint)
|
2014-03-04 11:14:35 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
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
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#define FOR_EACH_ATTACHMENT(X) \
|
|
|
|
X(mDepthAttachment); \
|
|
|
|
X(mStencilAttachment); \
|
|
|
|
X(mDepthStencilAttachment); \
|
|
|
|
\
|
|
|
|
for (auto& cur : mColorAttachments) { \
|
|
|
|
X(cur); \
|
2013-06-22 03:44:17 +04:00
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
|
|
void
|
2014-01-23 07:59:34 +04:00
|
|
|
WebGLFramebuffer::DetachTexture(const WebGLTexture* tex)
|
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnDetach = [&](WebGLFBAttachPoint& attach) {
|
|
|
|
if (attach.Texture() == tex) {
|
|
|
|
attach.Clear();
|
|
|
|
}
|
|
|
|
};
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
FOR_EACH_ATTACHMENT(fnDetach)
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-23 07:59:34 +04:00
|
|
|
WebGLFramebuffer::DetachRenderbuffer(const WebGLRenderbuffer* rb)
|
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnDetach = [&](WebGLFBAttachPoint& attach) {
|
|
|
|
if (attach.Renderbuffer() == rb) {
|
|
|
|
attach.Clear();
|
|
|
|
}
|
|
|
|
};
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
FOR_EACH_ATTACHMENT(fnDetach)
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Completeness
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
bool
|
2014-01-23 07:59:34 +04:00
|
|
|
WebGLFramebuffer::HasDefinedAttachments() const
|
|
|
|
{
|
|
|
|
bool hasAttachments = false;
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto func = [&](const WebGLFBAttachPoint& attach) {
|
|
|
|
hasAttachments |= attach.IsDefined();
|
|
|
|
};
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
FOR_EACH_ATTACHMENT(func)
|
2014-01-23 07:59:34 +04:00
|
|
|
return hasAttachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-12-15 03:11:59 +03:00
|
|
|
WebGLFramebuffer::HasIncompleteAttachments(nsCString* const out_info) const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
bool hasIncomplete = false;
|
|
|
|
const auto func = [&](const WebGLFBAttachPoint& cur) {
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!cur.IsDefined())
|
2016-07-19 10:36:54 +03:00
|
|
|
return; // Not defined, so can't count as incomplete.
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
hasIncomplete |= !cur.IsComplete(mContext, out_info);
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
FOR_EACH_ATTACHMENT(func)
|
2014-01-23 07:59:34 +04:00
|
|
|
return hasIncomplete;
|
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool
|
|
|
|
WebGLFramebuffer::AllImageRectsMatch() const
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2016-02-13 06:31:58 +03:00
|
|
|
MOZ_ASSERT(HasDefinedAttachments());
|
|
|
|
DebugOnly<nsCString> fbStatusInfo;
|
|
|
|
MOZ_ASSERT(!HasIncompleteAttachments(&fbStatusInfo));
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
bool needsInit = true;
|
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool hasMismatch = false;
|
|
|
|
const auto func = [&](const WebGLFBAttachPoint& attach) {
|
2016-02-13 06:31:58 +03:00
|
|
|
if (!attach.HasImage())
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
|
|
|
uint32_t curWidth;
|
|
|
|
uint32_t curHeight;
|
|
|
|
attach.Size(&curWidth, &curHeight);
|
|
|
|
|
|
|
|
if (needsInit) {
|
|
|
|
needsInit = false;
|
|
|
|
width = curWidth;
|
|
|
|
height = curHeight;
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
2016-02-13 06:31:58 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
hasMismatch |= (curWidth != width ||
|
|
|
|
curHeight != height);
|
2016-02-13 06:31:58 +03:00
|
|
|
};
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
FOR_EACH_ATTACHMENT(func)
|
|
|
|
return !hasMismatch;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-13 06:31:58 +03:00
|
|
|
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;
|
|
|
|
const auto func = [&](const WebGLFBAttachPoint& attach) {
|
2016-02-13 06:31:58 +03:00
|
|
|
if (!attach.HasImage())
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
|
|
|
const uint32_t curSamples = attach.Samples();
|
|
|
|
|
|
|
|
if (needsInit) {
|
|
|
|
needsInit = false;
|
|
|
|
samples = curSamples;
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
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
|
|
|
FOR_EACH_ATTACHMENT(func)
|
|
|
|
return !hasMismatch;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#undef FOR_EACH_ATTACHMENT
|
|
|
|
|
2014-09-25 19:21:33 +04:00
|
|
|
FBStatus
|
2015-12-15 03:11:59 +03:00
|
|
|
WebGLFramebuffer::PrecheckFramebufferStatus(nsCString* const out_info) const
|
2012-12-09 15:58:41 +04:00
|
|
|
{
|
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
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mContext->IsWebGL2()) {
|
|
|
|
MOZ_ASSERT(!mDepthStencilAttachment.IsDefined());
|
|
|
|
} else {
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto depthOrStencilCount = int(mDepthAttachment.IsDefined()) +
|
|
|
|
int(mStencilAttachment.IsDefined()) +
|
|
|
|
int(mDepthStencilAttachment.IsDefined());
|
|
|
|
if (depthOrStencilCount > 1)
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Validation
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLFramebuffer::ValidateAndInitAttachments(const char* funcName)
|
2014-01-23 07:59:34 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
2014-03-04 11:14:35 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fbStatus = CheckFramebufferStatus(funcName);
|
|
|
|
if (fbStatus == LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
return true;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->ErrorInvalidFramebufferOperation("%s: Framebuffer must be"
|
|
|
|
" complete.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-02 04:31:37 +04:00
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
bool
|
|
|
|
WebGLFramebuffer::ValidateClearBufferType(const char* funcName, GLenum buffer,
|
|
|
|
uint32_t drawBuffer, GLenum funcType) const
|
|
|
|
{
|
|
|
|
if (buffer != LOCAL_GL_COLOR)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const auto& attach = mColorAttachments[drawBuffer];
|
|
|
|
if (!count(mResolvedCompleteData->colorDrawBuffers.begin(),
|
|
|
|
mResolvedCompleteData->colorDrawBuffers.end(),
|
|
|
|
&attach))
|
|
|
|
{
|
|
|
|
return true; // DRAW_BUFFERi set to NONE.
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum attachType;
|
|
|
|
switch (attach.Format()->format->componentType) {
|
|
|
|
case webgl::ComponentType::Int:
|
|
|
|
attachType = LOCAL_GL_INT;
|
|
|
|
break;
|
|
|
|
case webgl::ComponentType::UInt:
|
|
|
|
attachType = LOCAL_GL_UNSIGNED_INT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
attachType = LOCAL_GL_FLOAT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachType != funcType) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: This attachment is of type 0x%04x, but"
|
|
|
|
" this function is of type 0x%04x.",
|
|
|
|
funcName, attachType, funcType);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool
|
|
|
|
WebGLFramebuffer::ValidateForRead(const char* funcName,
|
|
|
|
const webgl::FormatUsageInfo** const out_format,
|
|
|
|
uint32_t* const out_width, uint32_t* const out_height)
|
|
|
|
{
|
|
|
|
if (!ValidateAndInitAttachments(funcName))
|
|
|
|
return false;
|
2013-10-02 04:31:37 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!mColorReadBuffer) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: READ_BUFFER must not be NONE.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!mColorReadBuffer->IsDefined()) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is not defined.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
if (mColorReadBuffer->Samples()) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is multisampled.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
*out_format = mColorReadBuffer->Format();
|
|
|
|
mColorReadBuffer->Size(out_width, out_height);
|
|
|
|
return true;
|
2014-01-23 07:59:34 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Resolution and caching
|
|
|
|
|
|
|
|
void
|
2016-09-09 01:56:58 +03:00
|
|
|
WebGLFramebuffer::ResolveAttachments() const
|
2014-03-01 06:51:43 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& gl = mContext->gl;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2016-09-08 00:17:53 +03:00
|
|
|
// Nuke attachment points.
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2016-09-08 00:17:53 +03:00
|
|
|
for (uint32_t i = 0; i < mContext->mImplMaxColorAttachments; i++) {
|
|
|
|
const GLenum attachEnum = LOCAL_GL_COLOR_ATTACHMENT0 + i;
|
2016-09-09 01:56:58 +03:00
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, attachEnum,
|
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
2015-12-15 03:11:59 +03:00
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
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);
|
|
|
|
|
2016-09-08 00:17:53 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
for (const auto& attach : mColorAttachments) {
|
2016-09-09 01:56:58 +03:00
|
|
|
attach.Resolve(gl);
|
2016-09-08 00:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
mDepthAttachment.Resolve(gl);
|
|
|
|
mStencilAttachment.Resolve(gl);
|
|
|
|
mDepthStencilAttachment.Resolve(gl);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool
|
|
|
|
WebGLFramebuffer::ResolveAttachmentData(const char* funcName) const
|
|
|
|
{
|
2016-07-07 01:08:20 +03:00
|
|
|
//////
|
2014-01-23 07:59:34 +04:00
|
|
|
// Check if we need to initialize anything
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnIs3D = [&](const WebGLFBAttachPoint& attach) {
|
|
|
|
const auto& tex = attach.Texture();
|
|
|
|
if (!tex)
|
2016-07-07 01:08:20 +03:00
|
|
|
return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& info = tex->ImageInfoAt(attach.ImageTarget(), attach.MipLevel());
|
2016-07-07 01:08:20 +03:00
|
|
|
if (info.mDepth == 1)
|
|
|
|
return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-07 01:08:20 +03:00
|
|
|
return true;
|
|
|
|
};
|
2014-01-23 07:59:34 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
uint32_t clearBits = 0;
|
2016-07-19 10:36:54 +03:00
|
|
|
std::vector<const WebGLFBAttachPoint*> attachmentsToClear;
|
|
|
|
std::vector<const WebGLFBAttachPoint*> colorAttachmentsToClear;
|
|
|
|
std::vector<const WebGLFBAttachPoint*> tex3DAttachmentsToInit;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnGather = [&](const WebGLFBAttachPoint& attach, GLenum attachClearBits) {
|
2016-07-07 01:08:20 +03:00
|
|
|
if (!attach.HasUninitializedImageData())
|
2016-07-19 10:36:54 +03:00
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (fnIs3D(attach)) {
|
|
|
|
tex3DAttachmentsToInit.push_back(&attach);
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-07 01:08:20 +03:00
|
|
|
clearBits |= attachClearBits;
|
2016-07-19 10:36:54 +03:00
|
|
|
attachmentsToClear.push_back(&attach);
|
|
|
|
return true;
|
2016-07-07 01:08:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
for (auto& cur : mColorDrawBuffers) {
|
|
|
|
if (fnGather(*cur, LOCAL_GL_COLOR_BUFFER_BIT)) {
|
|
|
|
colorAttachmentsToClear.push_back(cur);
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fnGather(mDepthAttachment, LOCAL_GL_DEPTH_BUFFER_BIT);
|
|
|
|
fnGather(mStencilAttachment, LOCAL_GL_STENCIL_BUFFER_BIT);
|
|
|
|
fnGather(mDepthStencilAttachment, LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT);
|
2016-07-07 01:08:20 +03:00
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
for (const auto& attach : tex3DAttachmentsToInit) {
|
|
|
|
const auto& tex = attach->Texture();
|
|
|
|
if (!tex->InitializeImageData(funcName, attach->ImageTarget(),
|
|
|
|
attach->MipLevel()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-07 01:08:20 +03:00
|
|
|
if (clearBits) {
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnDrawBuffers = [&](const std::vector<const WebGLFBAttachPoint*>& src)
|
|
|
|
{
|
|
|
|
std::vector<GLenum> enumList;
|
|
|
|
|
|
|
|
for (const auto& cur : src) {
|
|
|
|
const auto& attachEnum = cur->mAttachmentPoint;
|
|
|
|
const GLenum attachId = attachEnum - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
|
|
|
|
while (enumList.size() < attachId) {
|
|
|
|
enumList.push_back(LOCAL_GL_NONE);
|
|
|
|
}
|
|
|
|
enumList.push_back(attachEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->gl->fDrawBuffers(enumList.size(), enumList.data());
|
|
|
|
};
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
|
|
|
// Clear
|
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
const bool hasDrawBuffers = mContext->HasDrawBuffers();
|
|
|
|
if (hasDrawBuffers) {
|
|
|
|
fnDrawBuffers(colorAttachmentsToClear);
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-07 01:08:20 +03:00
|
|
|
{
|
|
|
|
gl::ScopedBindFramebuffer autoBind(mContext->gl, mGLName);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-07 01:08:20 +03:00
|
|
|
mContext->ForceClearFramebufferWithDefaultValues(clearBits, false);
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
if (hasDrawBuffers) {
|
|
|
|
RefreshDrawBuffers();
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// Mark initialized.
|
|
|
|
for (const auto& cur : attachmentsToClear) {
|
2016-07-07 01:08:20 +03:00
|
|
|
cur->SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
|
|
|
|
}
|
2015-03-25 02:00:28 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return true;
|
2014-03-04 11:14:35 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLFramebuffer::ResolvedData::ResolvedData(const WebGLFramebuffer& parent)
|
|
|
|
: hasSampleBuffers(false)
|
|
|
|
, depthBuffer(nullptr)
|
|
|
|
, stencilBuffer(nullptr)
|
2014-01-24 08:02:07 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
if (parent.mDepthAttachment.IsDefined()) {
|
|
|
|
depthBuffer = &parent.mDepthAttachment;
|
|
|
|
}
|
|
|
|
if (parent.mStencilAttachment.IsDefined()) {
|
|
|
|
stencilBuffer = &parent.mStencilAttachment;
|
|
|
|
}
|
|
|
|
if (parent.mDepthStencilAttachment.IsDefined()) {
|
|
|
|
depthBuffer = &parent.mDepthStencilAttachment;
|
|
|
|
stencilBuffer = &parent.mDepthStencilAttachment;
|
2014-01-24 08:02:07 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2014-01-24 08:02:07 +04:00
|
|
|
|
2016-12-17 04:48:06 +03:00
|
|
|
colorDrawBuffers.reserve(parent.mColorDrawBuffers.size());
|
2016-07-19 10:36:54 +03:00
|
|
|
texDrawBuffers.reserve(parent.mColorDrawBuffers.size() + 2); // +2 for depth+stencil.
|
|
|
|
|
|
|
|
const auto fnCommon = [&](const WebGLFBAttachPoint& attach) {
|
|
|
|
if (!attach.IsDefined())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hasSampleBuffers |= bool(attach.Samples());
|
|
|
|
|
|
|
|
if (attach.Texture()) {
|
|
|
|
texDrawBuffers.push_back(&attach);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
////
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto fnDepthStencil = [&](const WebGLFBAttachPoint& attach) {
|
|
|
|
if (!fnCommon(attach))
|
|
|
|
return;
|
|
|
|
|
2016-09-02 03:51:08 +03:00
|
|
|
drawSet.insert(WebGLFBAttachPoint::Ordered(attach));
|
|
|
|
readSet.insert(WebGLFBAttachPoint::Ordered(attach));
|
2016-07-19 10:36:54 +03:00
|
|
|
};
|
2014-03-12 03:10:59 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fnDepthStencil(parent.mDepthAttachment);
|
|
|
|
fnDepthStencil(parent.mStencilAttachment);
|
|
|
|
fnDepthStencil(parent.mDepthStencilAttachment);
|
|
|
|
|
2016-12-17 04:48:06 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
for (const auto& pAttach : parent.mColorDrawBuffers) {
|
|
|
|
const auto& attach = *pAttach;
|
|
|
|
if (!fnCommon(attach))
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawSet.insert(WebGLFBAttachPoint::Ordered(attach));
|
|
|
|
colorDrawBuffers.push_back(&attach);
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent.mColorReadBuffer) {
|
2016-12-17 04:48:06 +03:00
|
|
|
const auto& attach = *parent.mColorReadBuffer;
|
|
|
|
if (!fnCommon(attach))
|
|
|
|
return;
|
|
|
|
|
|
|
|
readSet.insert(WebGLFBAttachPoint::Ordered(attach));
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-09 01:56:58 +03:00
|
|
|
WebGLFramebuffer::RefreshResolvedData()
|
2016-07-19 10:36:54 +03:00
|
|
|
{
|
|
|
|
if (mResolvedCompleteData) {
|
|
|
|
mResolvedCompleteData.reset(new ResolvedData(*this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Entrypoints
|
|
|
|
|
|
|
|
FBStatus
|
|
|
|
WebGLFramebuffer::CheckFramebufferStatus(const char* funcName)
|
|
|
|
{
|
|
|
|
if (IsResolvedComplete())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
|
|
|
|
// Ok, let's try to resolve it!
|
2015-03-17 07:32:52 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
nsCString statusInfo;
|
|
|
|
FBStatus ret = PrecheckFramebufferStatus(&statusInfo);
|
|
|
|
do {
|
|
|
|
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Looks good on our end. Let's ask the driver.
|
|
|
|
gl::GLContext* const gl = mContext->gl;
|
|
|
|
gl->MakeCurrent();
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
const ScopedFBRebinder autoFB(mContext);
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGLName);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
ResolveAttachments(); // OK, attach everything properly!
|
|
|
|
RefreshDrawBuffers();
|
|
|
|
RefreshReadBuffer();
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
ret = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
if (ret != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
2016-09-09 01:56:58 +03:00
|
|
|
const nsPrintfCString text("Bad status according to the driver: 0x%04x",
|
|
|
|
ret.get());
|
|
|
|
statusInfo = text;
|
2016-07-19 10:36:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ResolveAttachmentData(funcName)) {
|
|
|
|
ret = LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
|
|
|
statusInfo.AssignLiteral("Failed to lazily-initialize attachment data.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mResolvedCompleteData.reset(new ResolvedData(*this));
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
MOZ_ASSERT(ret != LOCAL_GL_FRAMEBUFFER_COMPLETE);
|
|
|
|
mContext->GenerateWarning("%s: Framebuffer not complete. (status: 0x%04x) %s",
|
|
|
|
funcName, ret.get(), statusInfo.BeginReading());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
void
|
|
|
|
WebGLFramebuffer::RefreshDrawBuffers() const
|
|
|
|
{
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::draw_buffers))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
std::vector<GLenum> driverBuffers(mContext->mImplMaxDrawBuffers, LOCAL_GL_NONE);
|
|
|
|
for (const auto& attach : mColorDrawBuffers) {
|
|
|
|
if (attach->HasImage()) {
|
|
|
|
const uint32_t index = attach->mAttachmentPoint - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
driverBuffers[index] = attach->mAttachmentPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fDrawBuffers(driverBuffers.size(), driverBuffers.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLFramebuffer::RefreshReadBuffer() const
|
|
|
|
{
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::read_buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Prior to GL4.1, having a no-image FB attachment that's selected by ReadBuffer
|
|
|
|
// yields a framebuffer status of FRAMEBUFFER_INCOMPLETE_READ_BUFFER.
|
|
|
|
// We could workaround this only on affected versions, but it's easier be
|
|
|
|
// unconditional.
|
|
|
|
GLenum driverBuffer = LOCAL_GL_NONE;
|
|
|
|
if (mColorReadBuffer && mColorReadBuffer->HasImage()) {
|
|
|
|
driverBuffer = mColorReadBuffer->mAttachmentPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fReadBuffer(driverBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
void
|
|
|
|
WebGLFramebuffer::DrawBuffers(const char* funcName, const dom::Sequence<GLenum>& buffers)
|
|
|
|
{
|
|
|
|
if (buffers.Length() > mContext->mImplMaxDrawBuffers) {
|
|
|
|
// "An INVALID_VALUE error is generated if `n` is greater than MAX_DRAW_BUFFERS."
|
|
|
|
mContext->ErrorInvalidValue("%s: `buffers` must have a length <="
|
|
|
|
" MAX_DRAW_BUFFERS.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
std::vector<const WebGLFBAttachPoint*> newColorDrawBuffers;
|
|
|
|
newColorDrawBuffers.reserve(buffers.Length());
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
for (size_t i = 0; i < buffers.Length(); i++) {
|
|
|
|
// "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.
|
|
|
|
|
|
|
|
// 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 &&
|
|
|
|
cur < mContext->LastColorAttachmentEnum());
|
|
|
|
if (cur != LOCAL_GL_BACK &&
|
|
|
|
!isColorEnum)
|
|
|
|
{
|
|
|
|
mContext->ErrorInvalidEnum("%s: Unexpected enum in buffers.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->ErrorInvalidOperation("%s: `buffers[i]` must be NONE or"
|
|
|
|
" COLOR_ATTACHMENTi.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-25 02:00:28 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 10:15:54 +03:00
|
|
|
////
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->MakeContextCurrent();
|
2016-09-09 01:56:58 +03:00
|
|
|
|
|
|
|
mColorDrawBuffers.swap(newColorDrawBuffers);
|
|
|
|
RefreshDrawBuffers(); // Calls glDrawBuffers.
|
|
|
|
RefreshResolvedData();
|
2013-10-02 04:30:05 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
void
|
|
|
|
WebGLFramebuffer::ReadBuffer(const char* funcName, GLenum attachPoint)
|
2015-02-19 03:57:05 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& maybeAttach = GetColorAttachPoint(attachPoint);
|
|
|
|
if (!maybeAttach) {
|
2016-09-01 23:53:51 +03:00
|
|
|
const char text[] = "%s: `mode` must be a COLOR_ATTACHMENTi, for 0 <= i <"
|
|
|
|
" MAX_DRAW_BUFFERS.";
|
|
|
|
if (attachPoint == LOCAL_GL_BACK) {
|
|
|
|
mContext->ErrorInvalidOperation(text, funcName);
|
|
|
|
} else {
|
|
|
|
mContext->ErrorInvalidEnum(text, funcName);
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-09-09 01:56:58 +03:00
|
|
|
const auto& attach = maybeAttach.value(); // Might be nullptr.
|
2015-02-19 03:57:05 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
////
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
2016-09-09 01:56:58 +03:00
|
|
|
|
|
|
|
mColorReadBuffer = attach;
|
|
|
|
RefreshReadBuffer(); // Calls glReadBuffer.
|
|
|
|
RefreshResolvedData();
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLFramebuffer::FramebufferRenderbuffer(const char* funcName, GLenum attachEnum,
|
|
|
|
GLenum rbtarget, WebGLRenderbuffer* rb)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
|
|
|
|
|
|
|
// `attachment`
|
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
2016-12-07 03:34:39 +03:00
|
|
|
if (!maybeAttach || !maybeAttach.value()) {
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
|
|
|
|
return;
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& attach = maybeAttach.value();
|
2015-02-19 03:57:05 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// `rbTarget`
|
|
|
|
if (rbtarget != LOCAL_GL_RENDERBUFFER) {
|
|
|
|
mContext->ErrorInvalidEnumInfo("framebufferRenderbuffer: rbtarget:", rbtarget);
|
|
|
|
return;
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// `rb`
|
2016-11-30 05:30:28 +03:00
|
|
|
if (rb && !mContext->ValidateObject("framebufferRenderbuffer: rb", *rb))
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// End of validation.
|
|
|
|
|
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mDepthAttachment.SetRenderbuffer(rb);
|
|
|
|
mStencilAttachment.SetRenderbuffer(rb);
|
|
|
|
} else {
|
|
|
|
attach->SetRenderbuffer(rb);
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateFramebufferStatus();
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
void
|
|
|
|
WebGLFramebuffer::FramebufferTexture2D(const char* funcName, GLenum attachEnum,
|
|
|
|
GLenum texImageTarget, WebGLTexture* tex,
|
|
|
|
GLint level)
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
|
|
|
|
|
|
|
// `attachment`
|
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
2016-12-07 03:34:39 +03:00
|
|
|
if (!maybeAttach || !maybeAttach.value()) {
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
|
|
|
|
return;
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& attach = maybeAttach.value();
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// `texImageTarget`
|
|
|
|
if (texImageTarget != LOCAL_GL_TEXTURE_2D &&
|
|
|
|
(texImageTarget < LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X ||
|
|
|
|
texImageTarget > LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))
|
|
|
|
{
|
|
|
|
mContext->ErrorInvalidEnumInfo("framebufferTexture2D: texImageTarget:",
|
|
|
|
texImageTarget);
|
|
|
|
return;
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// `texture`
|
|
|
|
if (tex) {
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!mContext->ValidateObject("framebufferTexture2D: texture", *tex))
|
|
|
|
return;
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!tex->HasEverBeenBound()) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: `texture` has never been bound.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TexTarget destTexTarget = TexImageTargetToTexTarget(texImageTarget);
|
|
|
|
if (tex->Target() != destTexTarget) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: Mismatched texture and texture target.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// `level`
|
|
|
|
if (level < 0)
|
|
|
|
return mContext->ErrorInvalidValue("%s: `level` must not be negative.", funcName);
|
|
|
|
|
|
|
|
if (mContext->IsWebGL2()) {
|
|
|
|
/* GLES 3.0.4 p208:
|
|
|
|
* If textarget is one of TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
|
|
* TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
|
|
* TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
|
|
* or TEXTURE_CUBE_MAP_NEGATIVE_Z, then level must be greater
|
|
|
|
* than or equal to zero and less than or equal to log2 of the
|
|
|
|
* value of MAX_CUBE_MAP_TEXTURE_SIZE. If textarget is TEXTURE_2D,
|
|
|
|
* level must be greater than or equal to zero and no larger than
|
|
|
|
* log2 of the value of MAX_TEXTURE_SIZE. Otherwise, an
|
|
|
|
* INVALID_VALUE error is generated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (texImageTarget == LOCAL_GL_TEXTURE_2D) {
|
|
|
|
if (uint32_t(level) > FloorLog2(mContext->mImplMaxTextureSize))
|
|
|
|
return mContext->ErrorInvalidValue("%s: `level` is too large.", funcName);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(texImageTarget >= LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
|
|
|
|
texImageTarget <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
|
|
|
|
|
|
|
|
if (uint32_t(level) > FloorLog2(mContext->mImplMaxCubeMapTextureSize))
|
|
|
|
return mContext->ErrorInvalidValue("%s: `level` is too large.", funcName);
|
|
|
|
}
|
|
|
|
} else if (level != 0) {
|
|
|
|
return mContext->ErrorInvalidValue("%s: `level` must be 0.", funcName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of validation.
|
|
|
|
|
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mDepthAttachment.SetTexImage(tex, texImageTarget, level);
|
|
|
|
mStencilAttachment.SetTexImage(tex, texImageTarget, level);
|
|
|
|
} else {
|
|
|
|
attach->SetTexImage(tex, texImageTarget, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateFramebufferStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLFramebuffer::FramebufferTextureLayer(const char* funcName, GLenum attachEnum,
|
|
|
|
WebGLTexture* tex, GLint level, GLint layer)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
|
|
|
|
|
|
|
// `attachment`
|
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
2016-12-07 03:34:39 +03:00
|
|
|
if (!maybeAttach || !maybeAttach.value()) {
|
2016-07-19 10:36:54 +03:00
|
|
|
mContext->ErrorInvalidEnum("%s: Bad `attachment`: 0x%x.", funcName, attachEnum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto& attach = maybeAttach.value();
|
|
|
|
|
|
|
|
// `level`, `layer`
|
|
|
|
if (layer < 0)
|
|
|
|
return mContext->ErrorInvalidValue("%s: `layer` must be >= 0.", funcName);
|
|
|
|
|
|
|
|
if (level < 0)
|
|
|
|
return mContext->ErrorInvalidValue("%s: `level` must be >= 0.", funcName);
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
// `texture`
|
2016-07-19 10:36:54 +03:00
|
|
|
TexImageTarget texImageTarget = LOCAL_GL_TEXTURE_3D;
|
|
|
|
if (tex) {
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!mContext->ValidateObject("framebufferTextureLayer: texture", *tex))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tex->HasEverBeenBound()) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: `texture` has never been bound.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
texImageTarget = tex->Target().get();
|
|
|
|
switch (texImageTarget.get()) {
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
|
|
|
if (uint32_t(layer) >= mContext->mImplMax3DTextureSize) {
|
|
|
|
mContext->ErrorInvalidValue("%s: `layer` must be < %s.", funcName,
|
|
|
|
"MAX_3D_TEXTURE_SIZE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uint32_t(level) > FloorLog2(mContext->mImplMax3DTextureSize)) {
|
|
|
|
mContext->ErrorInvalidValue("%s: `level` must be <= log2(%s).", funcName,
|
|
|
|
"MAX_3D_TEXTURE_SIZE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
if (uint32_t(layer) >= mContext->mImplMaxArrayTextureLayers) {
|
|
|
|
mContext->ErrorInvalidValue("%s: `layer` must be < %s.", funcName,
|
|
|
|
"MAX_ARRAY_TEXTURE_LAYERS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uint32_t(level) > FloorLog2(mContext->mImplMaxTextureSize)) {
|
|
|
|
mContext->ErrorInvalidValue("%s: `level` must be <= log2(%s).", funcName,
|
|
|
|
"MAX_TEXTURE_SIZE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mContext->ErrorInvalidOperation("%s: `texture` must be a TEXTURE_3D or"
|
|
|
|
" TEXTURE_2D_ARRAY.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of validation.
|
|
|
|
|
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
mDepthAttachment.SetTexImage(tex, texImageTarget, level, layer);
|
|
|
|
mStencilAttachment.SetTexImage(tex, texImageTarget, level, layer);
|
|
|
|
} else {
|
|
|
|
attach->SetTexImage(tex, texImageTarget, level, layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateFramebufferStatus();
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLFramebuffer::GetAttachmentParameter(const char* funcName, JSContext* cx,
|
2016-07-19 10:36:54 +03:00
|
|
|
GLenum target, GLenum attachEnum, GLenum pname,
|
|
|
|
ErrorResult* const out_error)
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto maybeAttach = GetAttachPoint(attachEnum);
|
2016-09-02 02:19:50 +03:00
|
|
|
if (!maybeAttach || attachEnum == LOCAL_GL_NONE) {
|
2015-11-25 07:15:29 +03:00
|
|
|
mContext->ErrorInvalidEnum("%s: Can only query COLOR_ATTACHMENTi,"
|
|
|
|
" DEPTH_ATTACHMENT, DEPTH_STENCIL_ATTACHMENT, or"
|
|
|
|
" STENCIL_ATTACHMENT for a framebuffer.",
|
|
|
|
funcName);
|
2015-08-06 09:31:00 +03:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
auto attach = maybeAttach.value();
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mContext->IsWebGL2() && attachEnum == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
2015-11-25 07:15:29 +03:00
|
|
|
// There are a couple special rules for this one.
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (pname == LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE) {
|
|
|
|
mContext->ErrorInvalidOperation("%s: Querying"
|
|
|
|
" FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE"
|
|
|
|
" against DEPTH_STENCIL_ATTACHMENT is an"
|
|
|
|
" error.",
|
|
|
|
funcName);
|
2015-08-06 09:31:00 +03:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (mDepthAttachment.Renderbuffer() != mStencilAttachment.Renderbuffer() ||
|
|
|
|
mDepthAttachment.Texture() != mStencilAttachment.Texture())
|
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
mContext->ErrorInvalidOperation("%s: DEPTH_ATTACHMENT and STENCIL_ATTACHMENT"
|
|
|
|
" have different objects bound.",
|
|
|
|
funcName);
|
|
|
|
return JS::NullValue();
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
attach = &mDepthAttachment;
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
return attach->GetParameter(funcName, mContext, cx, target, attachEnum, pname,
|
|
|
|
out_error);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////////
|
2016-07-14 22:13:19 +03:00
|
|
|
|
2016-07-19 10:36:54 +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();
|
|
|
|
|
|
|
|
const auto effFormat = (options.alpha ? webgl::EffectiveFormat::RGBA8
|
|
|
|
: webgl::EffectiveFormat::RGB8);
|
|
|
|
*out_color = webgl::GetFormat(effFormat);
|
|
|
|
|
|
|
|
*out_depth = nullptr;
|
|
|
|
*out_stencil = nullptr;
|
|
|
|
if (options.depth && options.stencil) {
|
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH24_STENCIL8);
|
|
|
|
*out_stencil = *out_depth;
|
|
|
|
} else {
|
|
|
|
if (options.depth) {
|
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT16);
|
|
|
|
}
|
|
|
|
if (options.stencil) {
|
|
|
|
*out_stencil = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl,
|
|
|
|
const WebGLFramebuffer* srcFB, GLint srcX0, GLint srcY0,
|
|
|
|
GLint srcX1, GLint srcY1,
|
|
|
|
const WebGLFramebuffer* dstFB, GLint dstX0, GLint dstY0,
|
|
|
|
GLint dstX1, GLint dstY1,
|
|
|
|
GLbitfield mask, GLenum filter)
|
2016-07-14 22:13:19 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "blitFramebuffer";
|
|
|
|
auto& gl = webgl->gl;
|
|
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
// Collect data
|
|
|
|
|
|
|
|
const auto fnGetFormat = [](const WebGLFBAttachPoint* cur) -> const webgl::FormatInfo*
|
2016-07-14 22:13:19 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!cur)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
MOZ_ASSERT(cur->IsDefined());
|
|
|
|
return cur->Format()->format;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool srcSampleBuffers;
|
|
|
|
const webgl::FormatInfo* srcColorFormat;
|
|
|
|
const webgl::FormatInfo* srcDepthFormat;
|
|
|
|
const webgl::FormatInfo* srcStencilFormat;
|
|
|
|
|
|
|
|
if (srcFB) {
|
|
|
|
srcSampleBuffers = srcFB->mResolvedCompleteData->hasSampleBuffers;
|
|
|
|
|
|
|
|
srcColorFormat = fnGetFormat(srcFB->mColorReadBuffer);
|
|
|
|
srcDepthFormat = fnGetFormat(srcFB->mResolvedCompleteData->depthBuffer);
|
|
|
|
srcStencilFormat = fnGetFormat(srcFB->mResolvedCompleteData->stencilBuffer);
|
|
|
|
} else {
|
|
|
|
srcSampleBuffers = false; // Always false.
|
|
|
|
|
|
|
|
GetBackbufferFormats(webgl, &srcColorFormat, &srcDepthFormat, &srcStencilFormat);
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
bool dstSampleBuffers;
|
|
|
|
const webgl::FormatInfo* dstDepthFormat;
|
|
|
|
const webgl::FormatInfo* dstStencilFormat;
|
|
|
|
bool dstHasColor = false;
|
|
|
|
bool colorFormatsMatch = true;
|
|
|
|
bool colorTypesMatch = true;
|
|
|
|
|
2016-11-15 06:23:50 +03:00
|
|
|
const auto fnNarrowComponentType = [&](const webgl::FormatInfo* format) {
|
|
|
|
switch (format->componentType) {
|
|
|
|
case webgl::ComponentType::NormInt:
|
|
|
|
case webgl::ComponentType::NormUInt:
|
|
|
|
return webgl::ComponentType::Float;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return format->componentType;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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);
|
2016-11-15 06:23:50 +03:00
|
|
|
colorTypesMatch &= ( fnNarrowComponentType(dstFormat) ==
|
|
|
|
fnNarrowComponentType(srcColorFormat) );
|
2016-07-19 10:36:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (dstFB) {
|
|
|
|
dstSampleBuffers = dstFB->mResolvedCompleteData->hasSampleBuffers;
|
2016-07-14 22:13:19 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
dstDepthFormat = fnGetFormat(dstFB->mResolvedCompleteData->depthBuffer);
|
|
|
|
dstStencilFormat = fnGetFormat(dstFB->mResolvedCompleteData->stencilBuffer);
|
|
|
|
|
2016-12-17 04:48:06 +03:00
|
|
|
for (const auto& cur : dstFB->mResolvedCompleteData->colorDrawBuffers) {
|
|
|
|
fnCheckColorFormat(cur->Format()->format);
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
} else {
|
|
|
|
dstSampleBuffers = bool(gl->Screen()->Samples());
|
|
|
|
|
|
|
|
const webgl::FormatInfo* dstColorFormat;
|
|
|
|
GetBackbufferFormats(webgl, &dstColorFormat, &dstDepthFormat, &dstStencilFormat);
|
|
|
|
|
|
|
|
fnCheckColorFormat(dstColorFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
// Clear unused buffer bits
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT &&
|
|
|
|
!srcColorFormat && !dstHasColor)
|
|
|
|
{
|
|
|
|
mask ^= LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
|
|
|
|
!srcDepthFormat && !dstDepthFormat)
|
|
|
|
{
|
|
|
|
mask ^= LOCAL_GL_DEPTH_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
|
|
|
|
!srcStencilFormat && !dstStencilFormat)
|
|
|
|
{
|
|
|
|
mask ^= LOCAL_GL_STENCIL_BUFFER_BIT;
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
|
|
|
// Validation
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
if (srcColorFormat && filter == LOCAL_GL_LINEAR) {
|
|
|
|
const auto& type = srcColorFormat->componentType;
|
|
|
|
if (type == webgl::ComponentType::Int ||
|
|
|
|
type == webgl::ComponentType::UInt)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: `filter` is LINEAR and READ_BUFFER"
|
|
|
|
" contains integer data.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!colorTypesMatch) {
|
|
|
|
webgl->ErrorInvalidOperation("%s: Color component types (fixed/float/uint/"
|
|
|
|
"int) must match.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const GLbitfield depthAndStencilBits = LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
if (bool(mask & depthAndStencilBits) &&
|
|
|
|
filter != LOCAL_GL_NEAREST)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: DEPTH_BUFFER_BIT and STENCIL_BUFFER_BIT can"
|
|
|
|
" only be used with NEAREST filtering.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
|
|
|
|
dstDepthFormat != srcDepthFormat)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: Depth buffer formats must match if selected.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
|
|
|
|
dstStencilFormat != srcStencilFormat)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: Stencil buffer formats must match if selected.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
if (dstSampleBuffers) {
|
|
|
|
webgl->ErrorInvalidOperation("%s: DRAW_FRAMEBUFFER may not have multiple"
|
|
|
|
" samples.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcSampleBuffers) {
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT &&
|
|
|
|
!colorFormatsMatch)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: Color buffer formats must match if"
|
|
|
|
" selected, when reading from a multisampled"
|
|
|
|
" source.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstX0 != srcX0 ||
|
|
|
|
dstX1 != srcX1 ||
|
|
|
|
dstY0 != srcY0 ||
|
|
|
|
dstY1 != srcY1)
|
|
|
|
{
|
|
|
|
webgl->ErrorInvalidOperation("%s: If the source is multisampled, then the"
|
|
|
|
" source and dest regions must match exactly.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
// Check for feedback
|
|
|
|
|
|
|
|
if (srcFB && dstFB) {
|
2016-12-22 11:08:14 +03:00
|
|
|
const WebGLFBAttachPoint* feedback = nullptr;
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
for (const auto& cur : dstFB->mResolvedCompleteData->colorDrawBuffers) {
|
|
|
|
if (srcFB->mColorReadBuffer->IsEquivalent(*cur)) {
|
|
|
|
feedback = cur;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
2016-12-22 11:08:14 +03:00
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-12-22 11:08:14 +03:00
|
|
|
const auto& srcDepthBuffer = srcFB->mResolvedCompleteData->depthBuffer;
|
|
|
|
const auto& dstDepthBuffer = dstFB->mResolvedCompleteData->depthBuffer;
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
|
|
|
|
srcDepthBuffer->IsEquivalent(*dstDepthBuffer))
|
2016-07-19 10:36:54 +03:00
|
|
|
{
|
2016-12-22 11:08:14 +03:00
|
|
|
feedback = dstDepthBuffer;
|
2016-07-19 10:36:54 +03:00
|
|
|
}
|
|
|
|
|
2016-12-22 11:08:14 +03:00
|
|
|
const auto& srcStencilBuffer = srcFB->mResolvedCompleteData->stencilBuffer;
|
|
|
|
const auto& dstStencilBuffer = dstFB->mResolvedCompleteData->stencilBuffer;
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
|
|
|
|
srcStencilBuffer->IsEquivalent(*dstStencilBuffer))
|
|
|
|
{
|
|
|
|
feedback = dstStencilBuffer;
|
|
|
|
}
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2016-12-22 11:08:14 +03:00
|
|
|
if (feedback) {
|
2016-07-19 10:36:54 +03:00
|
|
|
webgl->ErrorInvalidOperation("%s: Feedback detected into DRAW_FRAMEBUFFER's"
|
|
|
|
" 0x%04x attachment.",
|
2016-12-22 11:08:14 +03:00
|
|
|
funcName, feedback->mAttachmentPoint);
|
2016-07-19 10:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (!srcFB && !dstFB) {
|
|
|
|
webgl->ErrorInvalidOperation("%s: Feedback with default framebuffer.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
gl->MakeCurrent();
|
2016-12-24 05:54:04 +03:00
|
|
|
webgl->OnBeforeReadCall();
|
2016-12-21 10:31:22 +03:00
|
|
|
WebGLContext::ScopedDrawCallWrapper wrapper(*webgl);
|
2016-07-19 10:36:54 +03:00
|
|
|
gl->fBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
|
|
|
|
dstX0, dstY0, dstX1, dstY1,
|
|
|
|
mask, filter);
|
2016-07-14 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Goop.
|
|
|
|
|
|
|
|
JSObject*
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
|
2015-03-25 02:00:28 +03:00
|
|
|
{
|
2015-07-15 03:37:28 +03:00
|
|
|
return dom::WebGLFramebufferBinding::Wrap(cx, this, givenProto);
|
2015-03-25 02:00:28 +03:00
|
|
|
}
|
|
|
|
|
2013-06-22 03:44:17 +04:00
|
|
|
inline void
|
2015-07-15 03:37:28 +03:00
|
|
|
ImplCycleCollectionUnlink(mozilla::WebGLFBAttachPoint& field)
|
2013-06-22 03:44:17 +04:00
|
|
|
{
|
2015-03-25 02:00:28 +03:00
|
|
|
field.Unlink();
|
2013-06-22 03:44:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2014-11-14 07:03:50 +03:00
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
2015-07-15 03:37:28 +03:00
|
|
|
mozilla::WebGLFBAttachPoint& field,
|
2014-11-14 07:03:50 +03:00
|
|
|
const char* name,
|
|
|
|
uint32_t flags = 0)
|
2013-06-22 03:44:17 +04:00
|
|
|
{
|
2015-03-25 02:00:28 +03:00
|
|
|
CycleCollectionNoteChild(callback, field.Texture(), name, flags);
|
|
|
|
CycleCollectionNoteChild(callback, field.Renderbuffer(), name, flags);
|
2013-06-22 03:44:17 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
template<typename C>
|
|
|
|
inline void
|
|
|
|
ImplCycleCollectionUnlink(C& field)
|
|
|
|
{
|
|
|
|
for (auto& cur : field) {
|
|
|
|
cur.Unlink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename C>
|
|
|
|
inline void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
|
|
|
C& field,
|
|
|
|
const char* name,
|
|
|
|
uint32_t flags = 0)
|
|
|
|
{
|
|
|
|
for (auto& cur : field) {
|
|
|
|
ImplCycleCollectionTraverse(callback, cur, name, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLFramebuffer,
|
2014-11-14 07:03:50 +03:00
|
|
|
mDepthAttachment,
|
|
|
|
mStencilAttachment,
|
2015-03-25 02:00:28 +03:00
|
|
|
mDepthStencilAttachment,
|
2016-07-19 10:36:54 +03:00
|
|
|
mColorAttachments)
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLFramebuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLFramebuffer, Release)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|