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
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
#include "GLContext.h"
|
|
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.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
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
|
WebGLFramebuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2015-03-17 07:32:52 +03:00
|
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
|
return dom::WebGLFramebufferBinding::Wrap(cx, this, aGivenProto);
|
2015-03-17 07:32:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl, GLuint fbo)
|
|
|
|
|
: WebGLBindableName<FBTarget>(fbo)
|
|
|
|
|
, WebGLContextBoundObject(webgl)
|
|
|
|
|
, mStatus(0)
|
|
|
|
|
, mDepthAttachment(LOCAL_GL_DEPTH_ATTACHMENT)
|
|
|
|
|
, mStencilAttachment(LOCAL_GL_STENCIL_ATTACHMENT)
|
|
|
|
|
, mDepthStencilAttachment(LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
|
|
|
|
, mReadBufferMode(LOCAL_GL_COLOR_ATTACHMENT0)
|
|
|
|
|
{
|
|
|
|
|
mContext->mFramebuffers.insertBack(this);
|
|
|
|
|
|
|
|
|
|
mColorAttachments.SetLength(1);
|
|
|
|
|
mColorAttachments[0].mAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebGLFramebuffer::Attachment::Attachment(FBAttachment attachmentPoint)
|
|
|
|
|
: mAttachmentPoint(attachmentPoint)
|
2014-09-19 03:14:22 +04:00
|
|
|
|
, mTexImageTarget(LOCAL_GL_NONE)
|
2015-03-17 07:32:52 +03:00
|
|
|
|
, mNeedsFinalize(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
WebGLFramebuffer::Attachment::~Attachment()
|
2014-07-30 23:52:07 +04:00
|
|
|
|
{}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
void
|
|
|
|
|
WebGLFramebuffer::Attachment::Reset()
|
2014-07-30 23:52:07 +04:00
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mTexturePtr = nullptr;
|
|
|
|
|
mRenderbufferPtr = nullptr;
|
2014-07-30 23:52:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::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-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::IsDefined() const
|
2014-09-23 21:48:27 +04:00
|
|
|
|
{
|
|
|
|
|
return Renderbuffer() ||
|
|
|
|
|
(Texture() && Texture()->HasImageInfoAt(ImageTarget(), 0));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::HasAlpha() const
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-02-14 03:07:59 +04:00
|
|
|
|
MOZ_ASSERT(HasImage());
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (Texture() &&
|
|
|
|
|
Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel))
|
|
|
|
|
{
|
|
|
|
|
return FormatHasAlpha(Texture()->ImageInfoAt(mTexImageTarget,
|
|
|
|
|
mTexImageLevel).EffectiveInternalFormat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Renderbuffer())
|
2014-09-23 21:48:27 +04:00
|
|
|
|
return FormatHasAlpha(Renderbuffer()->InternalFormat());
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 00:38:42 +04:00
|
|
|
|
GLenum
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::GetFormatForAttachment(const WebGLFramebuffer::Attachment& attachment) const
|
2014-08-21 00:38:42 +04:00
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(attachment.IsDefined());
|
|
|
|
|
MOZ_ASSERT(attachment.Texture() || attachment.Renderbuffer());
|
|
|
|
|
|
|
|
|
|
if (attachment.Texture()) {
|
|
|
|
|
const WebGLTexture& tex = *attachment.Texture();
|
2014-09-19 03:14:22 +04:00
|
|
|
|
MOZ_ASSERT(tex.HasImageInfoAt(attachment.ImageTarget(), 0));
|
2014-08-21 00:38:42 +04:00
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
const WebGLTexture::ImageInfo& imgInfo = tex.ImageInfoAt(attachment.ImageTarget(),
|
|
|
|
|
0);
|
2014-10-08 03:52:58 +04:00
|
|
|
|
return imgInfo.EffectiveInternalFormat().get();
|
2014-08-21 00:38:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attachment.Renderbuffer())
|
|
|
|
|
return attachment.Renderbuffer()->InternalFormat();
|
|
|
|
|
|
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 03:52:58 +04:00
|
|
|
|
TexInternalFormat
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::EffectiveInternalFormat() const
|
2014-03-08 01:26:17 +04:00
|
|
|
|
{
|
2014-05-07 07:11:18 +04:00
|
|
|
|
const WebGLTexture* tex = Texture();
|
|
|
|
|
if (tex && tex->HasImageInfoAt(mTexImageTarget, mTexImageLevel)) {
|
2014-11-14 07:03:50 +03:00
|
|
|
|
return tex->ImageInfoAt(mTexImageTarget,
|
|
|
|
|
mTexImageLevel).EffectiveInternalFormat();
|
2014-03-08 01:26:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 07:11:18 +04:00
|
|
|
|
const WebGLRenderbuffer* rb = Renderbuffer();
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (rb)
|
2014-10-08 03:52:58 +04:00
|
|
|
|
return rb->InternalFormat();
|
2014-03-08 01:26:17 +04:00
|
|
|
|
|
2014-10-08 03:52:58 +04:00
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::IsReadableFloat() const
|
2014-10-08 03:52:58 +04:00
|
|
|
|
{
|
|
|
|
|
TexInternalFormat internalformat = EffectiveInternalFormat();
|
|
|
|
|
MOZ_ASSERT(internalformat != LOCAL_GL_NONE);
|
|
|
|
|
TexType type = TypeFromInternalFormat(internalformat);
|
|
|
|
|
return type == LOCAL_GL_FLOAT ||
|
2015-02-25 01:09:09 +03:00
|
|
|
|
type == LOCAL_GL_HALF_FLOAT_OES ||
|
2014-10-08 03:52:58 +04:00
|
|
|
|
type == LOCAL_GL_HALF_FLOAT;
|
2014-03-08 01:26:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::SetTexImage(WebGLTexture* tex,
|
|
|
|
|
TexImageTarget target, GLint level)
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2012-12-09 15:58:41 +04:00
|
|
|
|
mTexturePtr = tex;
|
|
|
|
|
mRenderbufferPtr = nullptr;
|
2013-10-02 04:30:38 +04:00
|
|
|
|
mTexImageTarget = target;
|
|
|
|
|
mTexImageLevel = level;
|
2014-03-12 03:10:59 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mNeedsFinalize = true;
|
2014-03-12 03:10:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::SetRenderbuffer(WebGLRenderbuffer* rb)
|
2014-03-12 03:10:59 +04:00
|
|
|
|
{
|
|
|
|
|
mTexturePtr = nullptr;
|
|
|
|
|
mRenderbufferPtr = rb;
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mNeedsFinalize = true;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::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
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (Renderbuffer())
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return Renderbuffer()->HasUninitializedImageData();
|
2014-02-14 03:07:59 +04:00
|
|
|
|
|
|
|
|
|
if (Texture()) {
|
2014-01-23 07:59:34 +04:00
|
|
|
|
MOZ_ASSERT(Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel));
|
2014-11-14 07:03:50 +03:00
|
|
|
|
return Texture()->ImageInfoAt(mTexImageTarget,
|
|
|
|
|
mTexImageLevel).HasUninitializedImageData();
|
2013-10-11 17:16:43 +04:00
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "Should not get here.");
|
|
|
|
|
return false;
|
2013-10-11 17:16:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::SetImageDataStatus(WebGLImageDataStatus newStatus)
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
|
|
|
|
if (!HasImage())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-02-14 03:07:59 +04:00
|
|
|
|
if (Renderbuffer()) {
|
|
|
|
|
Renderbuffer()->SetImageDataStatus(newStatus);
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return;
|
2014-02-14 03:07:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Texture()) {
|
2014-11-14 07:03:50 +03:00
|
|
|
|
Texture()->SetImageDataStatus(mTexImageTarget, mTexImageLevel,
|
|
|
|
|
newStatus);
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return;
|
2013-10-11 17:16:43 +04:00
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "Should not get here.");
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::HasImage() const
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2013-10-02 04:30:38 +04:00
|
|
|
|
if (Texture() && Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel))
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return true;
|
2014-02-14 03:07:59 +04:00
|
|
|
|
|
|
|
|
|
if (Renderbuffer())
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
const WebGLRectangleObject&
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::RectangleObject() const
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
|
MOZ_ASSERT(HasImage(),
|
|
|
|
|
"Make sure it has an image before requesting the rectangle.");
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
if (Texture()) {
|
|
|
|
|
MOZ_ASSERT(Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel));
|
|
|
|
|
return Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel);
|
2014-02-14 03:07:59 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (Renderbuffer())
|
2014-01-23 07:59:34 +04:00
|
|
|
|
return *Renderbuffer();
|
|
|
|
|
|
|
|
|
|
MOZ_CRASH("Should not get here.");
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
// The following IsValidFBOTextureXXX functions check the internal format that
|
|
|
|
|
// is used by GL or GL ES texture formats. This corresponds to the state that
|
|
|
|
|
// is stored in WebGLTexture::ImageInfo::InternalFormat()
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
|
|
|
|
static inline bool
|
2014-10-08 03:52:58 +04:00
|
|
|
|
IsValidFBOTextureDepthFormat(GLenum internalformat)
|
2014-01-24 10:28:47 +04:00
|
|
|
|
{
|
2014-10-08 03:52:58 +04:00
|
|
|
|
return IsGLDepthFormat(internalformat);
|
2014-01-24 07:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2014-10-08 03:52:58 +04:00
|
|
|
|
IsValidFBOTextureDepthStencilFormat(GLenum internalformat)
|
2014-01-24 10:28:47 +04:00
|
|
|
|
{
|
2014-10-08 03:52:58 +04:00
|
|
|
|
return IsGLDepthStencilFormat(internalformat);
|
2014-01-24 07:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
// The following IsValidFBORenderbufferXXX functions check the internal format
|
|
|
|
|
// that is stored by WebGLRenderbuffer::InternalFormat(). Valid values can be
|
|
|
|
|
// found in WebGLContext::RenderbufferStorage.
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
|
|
|
|
static inline bool
|
2014-01-24 10:28:47 +04:00
|
|
|
|
IsValidFBORenderbufferDepthFormat(GLenum internalFormat)
|
|
|
|
|
{
|
2014-01-24 07:53:53 +04:00
|
|
|
|
return internalFormat == LOCAL_GL_DEPTH_COMPONENT16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2014-01-24 10:28:47 +04:00
|
|
|
|
IsValidFBORenderbufferDepthStencilFormat(GLenum internalFormat)
|
|
|
|
|
{
|
|
|
|
|
return internalFormat == LOCAL_GL_DEPTH_STENCIL;
|
2014-01-24 07:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2014-01-24 10:28:47 +04:00
|
|
|
|
IsValidFBORenderbufferStencilFormat(GLenum internalFormat)
|
|
|
|
|
{
|
2014-01-24 07:53:53 +04:00
|
|
|
|
return internalFormat == LOCAL_GL_STENCIL_INDEX8;
|
2013-11-05 01:05:04 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-22 02:04:08 +03:00
|
|
|
|
bool
|
|
|
|
|
WebGLContext::IsFormatValidForFB(GLenum sizedFormat) const
|
|
|
|
|
{
|
|
|
|
|
switch (sizedFormat) {
|
|
|
|
|
case LOCAL_GL_RGB8:
|
|
|
|
|
case LOCAL_GL_RGBA8:
|
|
|
|
|
case LOCAL_GL_RGB565:
|
|
|
|
|
case LOCAL_GL_RGB5_A1:
|
|
|
|
|
case LOCAL_GL_RGBA4:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_SRGB8:
|
|
|
|
|
case LOCAL_GL_SRGB8_ALPHA8_EXT:
|
|
|
|
|
return IsExtensionEnabled(WebGLExtensionID::EXT_sRGB);
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB32F:
|
|
|
|
|
case LOCAL_GL_RGBA32F:
|
|
|
|
|
return IsExtensionEnabled(WebGLExtensionID::WEBGL_color_buffer_float);
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB16F:
|
|
|
|
|
case LOCAL_GL_RGBA16F:
|
|
|
|
|
return IsExtensionEnabled(WebGLExtensionID::EXT_color_buffer_half_float);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::IsComplete() const
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
|
|
|
|
if (!HasImage())
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
const WebGLRectangleObject& rect = RectangleObject();
|
|
|
|
|
|
|
|
|
|
if (!rect.Width() ||
|
|
|
|
|
!rect.Height())
|
|
|
|
|
{
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return false;
|
2014-01-23 07:59:34 +04:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-02-14 03:07:59 +04:00
|
|
|
|
if (Texture()) {
|
|
|
|
|
MOZ_ASSERT(Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel));
|
2014-01-24 07:53:53 +04:00
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo =
|
2014-02-14 03:07:59 +04:00
|
|
|
|
Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel);
|
2014-11-22 02:04:08 +03:00
|
|
|
|
GLenum sizedFormat = imageInfo.EffectiveInternalFormat().get();
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_ATTACHMENT)
|
2014-11-22 02:04:08 +03:00
|
|
|
|
return IsValidFBOTextureDepthFormat(sizedFormat);
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_STENCIL_ATTACHMENT) {
|
|
|
|
|
// Textures can't have the correct format for stencil buffers.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-08-20 00:24:39 +04:00
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
2014-11-22 02:04:08 +03:00
|
|
|
|
return IsValidFBOTextureDepthStencilFormat(sizedFormat);
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0 &&
|
2014-09-25 19:21:33 +04:00
|
|
|
|
mAttachmentPoint <= FBAttachment(LOCAL_GL_COLOR_ATTACHMENT0 - 1 +
|
|
|
|
|
WebGLContext::kMaxColorAttachments))
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-11-22 02:04:08 +03:00
|
|
|
|
WebGLContext* webgl = Texture()->Context();
|
|
|
|
|
return webgl->IsFormatValidForFB(sizedFormat);
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
MOZ_ASSERT(false, "Invalid WebGL attachment point?");
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 03:07:59 +04:00
|
|
|
|
if (Renderbuffer()) {
|
|
|
|
|
GLenum internalFormat = Renderbuffer()->InternalFormat();
|
2014-01-24 07:53:53 +04:00
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_ATTACHMENT)
|
|
|
|
|
return IsValidFBORenderbufferDepthFormat(internalFormat);
|
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_STENCIL_ATTACHMENT)
|
|
|
|
|
return IsValidFBORenderbufferStencilFormat(internalFormat);
|
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
|
|
|
|
return IsValidFBORenderbufferDepthStencilFormat(internalFormat);
|
|
|
|
|
|
|
|
|
|
if (mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0 &&
|
2014-09-25 19:21:33 +04:00
|
|
|
|
mAttachmentPoint <= FBAttachment(LOCAL_GL_COLOR_ATTACHMENT0 - 1 +
|
|
|
|
|
WebGLContext::kMaxColorAttachments))
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-11-22 02:04:08 +03:00
|
|
|
|
WebGLContext* webgl = Renderbuffer()->Context();
|
|
|
|
|
return webgl->IsFormatValidForFB(internalFormat);
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
MOZ_ASSERT(false, "Invalid WebGL attachment point?");
|
|
|
|
|
return false;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
MOZ_ASSERT(false, "Should not get here.");
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment::FinalizeAttachment(gl::GLContext* gl,
|
2014-11-14 07:03:50 +03:00
|
|
|
|
FBAttachment attachmentLoc) const
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (!mNeedsFinalize)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mNeedsFinalize = false;
|
|
|
|
|
|
2014-03-12 03:10:59 +04:00
|
|
|
|
if (!HasImage()) {
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (attachmentLoc == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
|
LOCAL_GL_DEPTH_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
|
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
|
LOCAL_GL_STENCIL_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
|
|
|
|
} else {
|
|
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
|
attachmentLoc.get(),
|
2014-03-12 03:10:59 +04:00
|
|
|
|
LOCAL_GL_RENDERBUFFER, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
MOZ_ASSERT(HasImage());
|
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
|
if (Texture()) {
|
2014-10-27 02:40:37 +03:00
|
|
|
|
MOZ_ASSERT(gl == Texture()->Context()->GL());
|
2014-03-12 03:10:59 +04:00
|
|
|
|
|
2014-09-19 03:14:22 +04:00
|
|
|
|
const GLenum imageTarget = ImageTarget().get();
|
|
|
|
|
const GLint mipLevel = MipLevel();
|
|
|
|
|
const GLuint glName = Texture()->GLName();
|
|
|
|
|
|
2013-10-02 04:31:09 +04:00
|
|
|
|
if (attachmentLoc == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
|
2015-03-17 07:32:52 +03:00
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
|
LOCAL_GL_DEPTH_ATTACHMENT, imageTarget,
|
|
|
|
|
glName, mipLevel);
|
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
|
LOCAL_GL_STENCIL_ATTACHMENT, imageTarget,
|
|
|
|
|
glName, mipLevel);
|
2013-10-02 04:31:09 +04:00
|
|
|
|
} else {
|
2014-09-25 19:21:33 +04:00
|
|
|
|
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, attachmentLoc.get(),
|
2014-09-19 03:14:22 +04:00
|
|
|
|
imageTarget, glName, mipLevel);
|
2013-10-02 04:31:09 +04:00
|
|
|
|
}
|
2013-10-02 04:30:05 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Renderbuffer()) {
|
2013-10-02 04:31:09 +04:00
|
|
|
|
Renderbuffer()->FramebufferRenderbuffer(attachmentLoc);
|
2013-10-02 04:30:05 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
MOZ_ASSERT(false, "Should not get here.");
|
2013-10-02 04:30:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
void
|
|
|
|
|
WebGLFramebuffer::Delete()
|
2014-06-24 11:15:44 +04:00
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
DetachAllAttachments();
|
|
|
|
|
mColorAttachments.Clear();
|
|
|
|
|
mDepthAttachment.Reset();
|
|
|
|
|
mStencilAttachment.Reset();
|
|
|
|
|
mDepthStencilAttachment.Reset();
|
|
|
|
|
|
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
|
mContext->gl->fDeleteFramebuffers(1, &mGLName);
|
|
|
|
|
LinkedListElement<WebGLFramebuffer>::removeFrom(mContext->mFramebuffers);
|
2015-03-17 04:03:40 +03:00
|
|
|
|
}
|
2015-03-16 22:48:52 +03:00
|
|
|
|
|
2015-03-17 04:03:40 +03:00
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::DetachAttachment(WebGLFramebuffer::Attachment& attachment)
|
2015-03-17 04:03:40 +03:00
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (attachment.Texture())
|
|
|
|
|
attachment.Texture()->DetachFrom(this, attachment.mAttachmentPoint);
|
|
|
|
|
|
|
|
|
|
if (attachment.Renderbuffer()) {
|
|
|
|
|
attachment.Renderbuffer()->DetachFrom(this,
|
|
|
|
|
attachment.mAttachmentPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-17 04:22:17 +03:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
void
|
|
|
|
|
WebGLFramebuffer::DetachAllAttachments()
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < mColorAttachments.Length(); i++) {
|
|
|
|
|
DetachAttachment(mColorAttachments[i]);
|
2014-06-24 11:15:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
DetachAttachment(mDepthAttachment);
|
|
|
|
|
DetachAttachment(mStencilAttachment);
|
|
|
|
|
DetachAttachment(mDepthStencilAttachment);
|
2014-06-24 11:15:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::FramebufferRenderbuffer(FBAttachment attachPoint,
|
2014-09-25 19:21:33 +04:00
|
|
|
|
RBTarget rbtarget,
|
2014-11-14 07:03:50 +03:00
|
|
|
|
WebGLRenderbuffer* rb)
|
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-03-04 11:14:35 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (!mContext->ValidateObjectAllowNull("framebufferRenderbuffer: renderbuffer",
|
|
|
|
|
rb))
|
|
|
|
|
{
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return;
|
2015-03-17 07:32:52 +03:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
/* Get the requested attachment. If result is NULL, attachment is invalid
|
|
|
|
|
* and an error is generated.
|
|
|
|
|
*
|
|
|
|
|
* Don't use GetAttachment(...) here because it opt builds it returns
|
|
|
|
|
* mColorAttachment[0] for invalid attachment, which we really don't want to
|
|
|
|
|
* mess with.
|
|
|
|
|
*/
|
|
|
|
|
Attachment* attachment = GetAttachmentOrNull(attachPoint);
|
|
|
|
|
if (!attachment)
|
|
|
|
|
return; // Error generated internally to GetAttachmentOrNull.
|
|
|
|
|
|
|
|
|
|
// Invalidate cached framebuffer status and inform texture of its new
|
|
|
|
|
// attachment.
|
|
|
|
|
mStatus = 0;
|
|
|
|
|
|
|
|
|
|
// Detach current:
|
|
|
|
|
if (attachment->Texture())
|
|
|
|
|
attachment->Texture()->DetachFrom(this, attachPoint);
|
|
|
|
|
else if (attachment->Renderbuffer())
|
|
|
|
|
attachment->Renderbuffer()->DetachFrom(this, attachPoint);
|
|
|
|
|
|
|
|
|
|
// Attach new:
|
|
|
|
|
if (rb)
|
|
|
|
|
rb->AttachTo(this, attachPoint);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
attachment->SetRenderbuffer(rb);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::FramebufferTexture2D(FBAttachment attachPoint,
|
2014-09-19 03:14:22 +04:00
|
|
|
|
TexImageTarget texImageTarget,
|
2014-11-14 07:03:50 +03:00
|
|
|
|
WebGLTexture* tex, GLint level)
|
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-03-04 11:14:35 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (!mContext->ValidateObjectAllowNull("framebufferTexture2D: texture",
|
|
|
|
|
tex))
|
|
|
|
|
{
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return;
|
2015-03-17 07:32:52 +03:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (tex) {
|
|
|
|
|
bool isTexture2D = tex->Target() == LOCAL_GL_TEXTURE_2D;
|
2014-09-19 03:14:22 +04:00
|
|
|
|
bool isTexTarget2D = texImageTarget == LOCAL_GL_TEXTURE_2D;
|
2013-10-31 21:01:41 +04:00
|
|
|
|
if (isTexture2D != isTexTarget2D) {
|
2014-11-14 07:03:50 +03:00
|
|
|
|
mContext->ErrorInvalidOperation("framebufferTexture2D: Mismatched"
|
|
|
|
|
" texture and texture target.");
|
|
|
|
|
return;
|
2013-10-31 21:01:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (level != 0) {
|
|
|
|
|
mContext->ErrorInvalidValue("framebufferTexture2D: Level must be 0.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
/* Get the requested attachment. If result is NULL, attachment is invalid
|
|
|
|
|
* and an error is generated.
|
|
|
|
|
*
|
|
|
|
|
* Don't use GetAttachment(...) here because it opt builds it returns
|
|
|
|
|
* mColorAttachment[0] for invalid attachment, which we really don't want to
|
|
|
|
|
* mess with.
|
|
|
|
|
*/
|
|
|
|
|
Attachment* attachment = GetAttachmentOrNull(attachPoint);
|
|
|
|
|
if (!attachment)
|
|
|
|
|
return; // Error generated internally to GetAttachmentOrNull.
|
|
|
|
|
|
|
|
|
|
// Invalidate cached framebuffer status and inform texture of its new
|
|
|
|
|
// attachment.
|
|
|
|
|
mStatus = 0;
|
|
|
|
|
|
|
|
|
|
// Detach current:
|
|
|
|
|
if (attachment->Texture())
|
|
|
|
|
attachment->Texture()->DetachFrom(this, attachPoint);
|
|
|
|
|
else if (attachment->Renderbuffer())
|
|
|
|
|
attachment->Renderbuffer()->DetachFrom(this, attachPoint);
|
|
|
|
|
|
|
|
|
|
// Attach new:
|
|
|
|
|
if (tex)
|
|
|
|
|
tex->AttachTo(this, attachPoint);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
attachment->SetTexImage(tex, texImageTarget, level);
|
2014-03-04 11:14:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
WebGLFramebuffer::Attachment*
|
|
|
|
|
WebGLFramebuffer::GetAttachmentOrNull(FBAttachment attachPoint)
|
2014-03-04 11:14:35 +04:00
|
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
|
switch (attachPoint.get()) {
|
2015-03-17 07:32:52 +03:00
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
|
return &mDepthStencilAttachment;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
|
return &mDepthAttachment;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
|
return &mStencilAttachment;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mContext->ValidateFramebufferAttachment(this, attachPoint.get(),
|
|
|
|
|
"getAttachmentOrNull"))
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t colorAttachmentId = attachPoint.get() - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
|
EnsureColorAttachments(colorAttachmentId);
|
2014-03-04 11:14:35 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
return &mColorAttachments[colorAttachmentId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const WebGLFramebuffer::Attachment&
|
|
|
|
|
WebGLFramebuffer::GetAttachment(FBAttachment attachPoint) const
|
|
|
|
|
{
|
|
|
|
|
switch (attachPoint.get()) {
|
2014-11-14 07:03:50 +03:00
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return mDepthStencilAttachment;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return mDepthAttachment;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2012-12-09 15:58:41 +04:00
|
|
|
|
return mStencilAttachment;
|
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (!mContext->ValidateFramebufferAttachment(this, attachPoint.get(),
|
|
|
|
|
"getAttachment"))
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
|
return mColorAttachments[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t colorAttachmentId = attachPoint.get() - LOCAL_GL_COLOR_ATTACHMENT0;
|
|
|
|
|
if (colorAttachmentId >= mColorAttachments.Length()) {
|
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
|
return mColorAttachments[0];
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
return mColorAttachments[colorAttachmentId];
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::DetachTexture(const WebGLTexture* tex)
|
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
if (mColorAttachments[i].Texture() == tex) {
|
|
|
|
|
FramebufferTexture2D(LOCAL_GL_COLOR_ATTACHMENT0+i,
|
|
|
|
|
LOCAL_GL_TEXTURE_2D, nullptr, 0);
|
|
|
|
|
// It might be attached in multiple places, so don't break.
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-17 04:22:17 +03:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (mDepthAttachment.Texture() == tex) {
|
|
|
|
|
FramebufferTexture2D(LOCAL_GL_DEPTH_ATTACHMENT, LOCAL_GL_TEXTURE_2D,
|
|
|
|
|
nullptr, 0);
|
|
|
|
|
}
|
|
|
|
|
if (mStencilAttachment.Texture() == tex) {
|
|
|
|
|
FramebufferTexture2D(LOCAL_GL_STENCIL_ATTACHMENT, LOCAL_GL_TEXTURE_2D,
|
|
|
|
|
nullptr, 0);
|
|
|
|
|
}
|
|
|
|
|
if (mDepthStencilAttachment.Texture() == tex) {
|
|
|
|
|
FramebufferTexture2D(LOCAL_GL_DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_TEXTURE_2D, nullptr, 0);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::DetachRenderbuffer(const WebGLRenderbuffer* rb)
|
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
if (mColorAttachments[i].Renderbuffer() == rb) {
|
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_COLOR_ATTACHMENT0+i,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, nullptr);
|
|
|
|
|
// It might be attached in multiple places, so don't break.
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-17 04:22:17 +03:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (mDepthAttachment.Renderbuffer() == rb) {
|
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_DEPTH_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, nullptr);
|
|
|
|
|
}
|
|
|
|
|
if (mStencilAttachment.Renderbuffer() == rb) {
|
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_STENCIL_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, nullptr);
|
|
|
|
|
}
|
|
|
|
|
if (mDepthStencilAttachment.Renderbuffer() == rb) {
|
|
|
|
|
FramebufferRenderbuffer(LOCAL_GL_DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
|
LOCAL_GL_RENDERBUFFER, nullptr);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::HasDefinedAttachments() const
|
|
|
|
|
{
|
|
|
|
|
bool hasAttachments = false;
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
hasAttachments |= mColorAttachments[i].IsDefined();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
hasAttachments |= mDepthAttachment.IsDefined();
|
|
|
|
|
hasAttachments |= mStencilAttachment.IsDefined();
|
|
|
|
|
hasAttachments |= mDepthStencilAttachment.IsDefined();
|
|
|
|
|
|
|
|
|
|
return hasAttachments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
IsIncomplete(const WebGLFramebuffer::Attachment& cur)
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-02-14 03:07:59 +04:00
|
|
|
|
return cur.IsDefined() && !cur.IsComplete();
|
2014-01-23 07:59:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLFramebuffer::HasIncompleteAttachments() const
|
|
|
|
|
{
|
|
|
|
|
bool hasIncomplete = false;
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
hasIncomplete |= IsIncomplete(mColorAttachments[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
hasIncomplete |= IsIncomplete(mDepthAttachment);
|
|
|
|
|
hasIncomplete |= IsIncomplete(mStencilAttachment);
|
|
|
|
|
hasIncomplete |= IsIncomplete(mDepthStencilAttachment);
|
|
|
|
|
|
|
|
|
|
return hasIncomplete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const WebGLRectangleObject&
|
|
|
|
|
WebGLFramebuffer::GetAnyRectObject() const
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(HasDefinedAttachments());
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
if (mColorAttachments[i].HasImage())
|
|
|
|
|
return mColorAttachments[i].RectangleObject();
|
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
if (mDepthAttachment.HasImage())
|
|
|
|
|
return mDepthAttachment.RectangleObject();
|
|
|
|
|
|
|
|
|
|
if (mStencilAttachment.HasImage())
|
|
|
|
|
return mStencilAttachment.RectangleObject();
|
|
|
|
|
|
|
|
|
|
if (mDepthStencilAttachment.HasImage())
|
|
|
|
|
return mDepthStencilAttachment.RectangleObject();
|
|
|
|
|
|
|
|
|
|
MOZ_CRASH("Should not get here.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
2015-03-17 07:32:52 +03:00
|
|
|
|
RectsMatch(const WebGLFramebuffer::Attachment& attachment,
|
2014-01-23 07:59:34 +04:00
|
|
|
|
const WebGLRectangleObject& rect)
|
|
|
|
|
{
|
|
|
|
|
return attachment.RectangleObject().HasSameDimensionsAs(rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLFramebuffer::AllImageRectsMatch() const
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(HasDefinedAttachments());
|
|
|
|
|
MOZ_ASSERT(!HasIncompleteAttachments());
|
|
|
|
|
|
|
|
|
|
const WebGLRectangleObject& rect = GetAnyRectObject();
|
|
|
|
|
|
|
|
|
|
// Alright, we have *a* rect, let's check all the others.
|
|
|
|
|
bool imageRectsMatch = true;
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < (size_t)mColorAttachments.Length(); i++) {
|
|
|
|
|
if (mColorAttachments[i].HasImage())
|
|
|
|
|
imageRectsMatch &= RectsMatch(mColorAttachments[i], rect);
|
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
if (mDepthAttachment.HasImage())
|
|
|
|
|
imageRectsMatch &= RectsMatch(mDepthAttachment, rect);
|
|
|
|
|
|
|
|
|
|
if (mStencilAttachment.HasImage())
|
|
|
|
|
imageRectsMatch &= RectsMatch(mStencilAttachment, rect);
|
|
|
|
|
|
|
|
|
|
if (mDepthStencilAttachment.HasImage())
|
|
|
|
|
imageRectsMatch &= RectsMatch(mDepthStencilAttachment, rect);
|
|
|
|
|
|
|
|
|
|
return imageRectsMatch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const WebGLRectangleObject&
|
|
|
|
|
WebGLFramebuffer::RectangleObject() const
|
|
|
|
|
{
|
|
|
|
|
// If we're using this as the RectObj of an FB, we need to be sure the FB
|
|
|
|
|
// has a consistent rect.
|
|
|
|
|
MOZ_ASSERT(AllImageRectsMatch(), "Did you mean `GetAnyRectObject`?");
|
|
|
|
|
return GetAnyRectObject();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-25 19:21:33 +04:00
|
|
|
|
FBStatus
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::PrecheckFramebufferStatus() 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
|
|
|
|
|
|
|
|
|
|
if (HasIncompleteAttachments())
|
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
|
|
|
|
|
|
|
|
if (!AllImageRectsMatch())
|
2014-02-14 03:07:59 +04:00
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; // Inconsistent sizes
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
|
if (HasDepthStencilConflict())
|
2014-01-23 07:59:34 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-25 19:21:33 +04:00
|
|
|
|
FBStatus
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::CheckFramebufferStatus() const
|
|
|
|
|
{
|
2014-03-04 11:14:35 +04:00
|
|
|
|
if (mStatus != 0)
|
|
|
|
|
return mStatus;
|
|
|
|
|
|
2014-09-25 19:21:33 +04:00
|
|
|
|
mStatus = PrecheckFramebufferStatus().get();
|
2014-03-04 11:14:35 +04:00
|
|
|
|
if (mStatus != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
|
return mStatus;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
// Looks good on our end. Let's ask the driver.
|
2013-10-02 04:31:37 +04:00
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
|
|
|
|
|
|
// Ok, attach our chosen flavor of {DEPTH, STENCIL, DEPTH_STENCIL}.
|
|
|
|
|
FinalizeAttachments();
|
|
|
|
|
|
2015-02-25 01:09:09 +03:00
|
|
|
|
// TODO: This should not be unconditionally GL_FRAMEBUFFER.
|
2014-03-04 11:14:35 +04:00
|
|
|
|
mStatus = mContext->gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
|
return mStatus;
|
2014-01-23 07:59:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-01 06:51:43 +04:00
|
|
|
|
bool
|
|
|
|
|
WebGLFramebuffer::HasCompletePlanes(GLbitfield mask)
|
|
|
|
|
{
|
|
|
|
|
if (CheckFramebufferStatus() != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
|
return false;
|
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
|
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
|
|
|
|
|
mContext->mBoundReadFramebuffer == this);
|
|
|
|
|
|
2014-03-01 06:51:43 +04:00
|
|
|
|
bool hasPlanes = true;
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
|
hasPlanes &= ColorAttachmentCount() &&
|
|
|
|
|
ColorAttachment(0).IsDefined();
|
|
|
|
|
}
|
2014-03-01 06:51:43 +04:00
|
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT) {
|
2015-03-17 07:32:52 +03:00
|
|
|
|
hasPlanes &= DepthAttachment().IsDefined() ||
|
|
|
|
|
DepthStencilAttachment().IsDefined();
|
2014-03-01 06:51:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT) {
|
2015-03-17 07:32:52 +03:00
|
|
|
|
hasPlanes &= StencilAttachment().IsDefined() ||
|
|
|
|
|
DepthStencilAttachment().IsDefined();
|
2014-03-01 06:51:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasPlanes;
|
|
|
|
|
}
|
2014-01-23 07:59:34 +04:00
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLFramebuffer::CheckAndInitializeAttachments()
|
|
|
|
|
{
|
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 (CheckFramebufferStatus() != LOCAL_GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Cool! We've checked out ok. Just need to initialize.
|
2015-03-17 07:32:52 +03:00
|
|
|
|
const size_t colorAttachmentCount = mColorAttachments.Length();
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
// Check if we need to initialize anything
|
2013-06-22 03:44:17 +04:00
|
|
|
|
{
|
2014-01-23 07:59:34 +04:00
|
|
|
|
bool hasUninitializedAttachments = false;
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < colorAttachmentCount; i++) {
|
|
|
|
|
if (mColorAttachments[i].HasImage())
|
|
|
|
|
hasUninitializedAttachments |= mColorAttachments[i].HasUninitializedImageData();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
if (mDepthAttachment.HasImage())
|
|
|
|
|
hasUninitializedAttachments |= mDepthAttachment.HasUninitializedImageData();
|
|
|
|
|
if (mStencilAttachment.HasImage())
|
|
|
|
|
hasUninitializedAttachments |= mStencilAttachment.HasUninitializedImageData();
|
|
|
|
|
if (mDepthStencilAttachment.HasImage())
|
|
|
|
|
hasUninitializedAttachments |= mDepthStencilAttachment.HasUninitializedImageData();
|
|
|
|
|
|
|
|
|
|
if (!hasUninitializedAttachments)
|
2013-06-22 03:44:17 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
// Get buffer-bit-mask and color-attachment-mask-list
|
2012-12-09 15:58:41 +04:00
|
|
|
|
uint32_t mask = 0;
|
2014-05-01 01:30:23 +04:00
|
|
|
|
bool colorAttachmentsMask[WebGLContext::kMaxColorAttachments] = { false };
|
2015-03-17 07:32:52 +03:00
|
|
|
|
MOZ_ASSERT(colorAttachmentCount <= WebGLContext::kMaxColorAttachments);
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < colorAttachmentCount; i++) {
|
|
|
|
|
if (mColorAttachments[i].HasUninitializedImageData()) {
|
|
|
|
|
colorAttachmentsMask[i] = true;
|
|
|
|
|
mask |= LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
|
if (mDepthAttachment.HasUninitializedImageData() ||
|
|
|
|
|
mDepthStencilAttachment.HasUninitializedImageData())
|
2012-12-09 15:58:41 +04:00
|
|
|
|
{
|
|
|
|
|
mask |= LOCAL_GL_DEPTH_BUFFER_BIT;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
|
if (mStencilAttachment.HasUninitializedImageData() ||
|
|
|
|
|
mDepthStencilAttachment.HasUninitializedImageData())
|
2012-12-09 15:58:41 +04:00
|
|
|
|
{
|
|
|
|
|
mask |= LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
// Clear!
|
2013-06-22 03:44:17 +04:00
|
|
|
|
mContext->ForceClearFramebufferWithDefaultValues(mask, colorAttachmentsMask);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
|
// Mark all the uninitialized images as initialized.
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < colorAttachmentCount; i++) {
|
|
|
|
|
if (mColorAttachments[i].HasUninitializedImageData())
|
|
|
|
|
mColorAttachments[i].SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
|
if (mDepthAttachment.HasUninitializedImageData())
|
|
|
|
|
mDepthAttachment.SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
|
|
|
|
|
if (mStencilAttachment.HasUninitializedImageData())
|
|
|
|
|
mStencilAttachment.SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
|
|
|
|
|
if (mDepthStencilAttachment.HasUninitializedImageData())
|
|
|
|
|
mDepthStencilAttachment.SetImageDataStatus(WebGLImageDataStatus::InitializedImageData);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
void WebGLFramebuffer::EnsureColorAttachments(size_t colorAttachmentId)
|
2014-01-23 07:59:34 +04:00
|
|
|
|
{
|
2014-05-01 01:30:23 +04:00
|
|
|
|
MOZ_ASSERT(colorAttachmentId < WebGLContext::kMaxColorAttachments);
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
size_t currentAttachmentCount = mColorAttachments.Length();
|
|
|
|
|
if (colorAttachmentId < currentAttachmentCount)
|
2013-06-22 03:44:17 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mColorAttachments.SetLength(colorAttachmentId + 1);
|
|
|
|
|
|
|
|
|
|
for (size_t i = colorAttachmentId; i >= currentAttachmentCount; i--) {
|
|
|
|
|
mColorAttachments[i].mAttachmentPoint = LOCAL_GL_COLOR_ATTACHMENT0 + i;
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
2015-03-17 07:32:52 +03:00
|
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
void
|
|
|
|
|
WebGLFramebuffer::NotifyAttachableChanged() const
|
|
|
|
|
{
|
|
|
|
|
// Attachment has changed, so invalidate cached status
|
|
|
|
|
mStatus = 0;
|
2014-03-04 11:14:35 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 08:02:07 +04:00
|
|
|
|
static void
|
2014-11-14 07:03:50 +03:00
|
|
|
|
FinalizeDrawAndReadBuffers(gl::GLContext* gl, bool isColorBufferDefined)
|
2014-01-24 08:02:07 +04:00
|
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
|
MOZ_ASSERT(gl, "Expected a valid GLContext ptr.");
|
2014-01-24 08:02:07 +04:00
|
|
|
|
// GLES don't support DrawBuffer()/ReadBuffer.
|
|
|
|
|
// According to http://www.opengl.org/wiki/Framebuffer_Object
|
|
|
|
|
//
|
|
|
|
|
// Each draw buffers must either specify color attachment points that have images
|
|
|
|
|
// attached or must be GL_NONE. (GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER when false).
|
|
|
|
|
//
|
|
|
|
|
// If the read buffer is set, then it must specify an attachment point that has an
|
|
|
|
|
// image attached. (GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER when false).
|
|
|
|
|
//
|
|
|
|
|
// Note that this test is not performed if OpenGL 4.2 or ARB_ES2_compatibility is
|
|
|
|
|
// available.
|
2014-11-14 07:03:50 +03:00
|
|
|
|
if (gl->IsGLES() ||
|
|
|
|
|
gl->IsSupported(gl::GLFeature::ES2_compatibility) ||
|
|
|
|
|
gl->IsAtLeast(gl::ContextProfile::OpenGL, 420))
|
2014-01-24 08:02:07 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(djg): Assert that fDrawBuffer/fReadBuffer is not NULL.
|
2014-11-14 07:03:50 +03:00
|
|
|
|
GLenum colorBufferSource = isColorBufferDefined ? LOCAL_GL_COLOR_ATTACHMENT0
|
|
|
|
|
: LOCAL_GL_NONE;
|
|
|
|
|
gl->fDrawBuffer(colorBufferSource);
|
|
|
|
|
gl->fReadBuffer(colorBufferSource);
|
2014-01-24 08:02:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
|
void
|
2014-01-23 07:59:34 +04:00
|
|
|
|
WebGLFramebuffer::FinalizeAttachments() const
|
|
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
|
gl::GLContext* gl = mContext->gl;
|
2014-03-12 03:10:59 +04:00
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
for (size_t i = 0; i < ColorAttachmentCount(); i++) {
|
|
|
|
|
ColorAttachment(i).FinalizeAttachment(gl, LOCAL_GL_COLOR_ATTACHMENT0+i);
|
2015-03-17 04:22:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
DepthAttachment().FinalizeAttachment(gl, LOCAL_GL_DEPTH_ATTACHMENT);
|
|
|
|
|
StencilAttachment().FinalizeAttachment(gl, LOCAL_GL_STENCIL_ATTACHMENT);
|
|
|
|
|
DepthStencilAttachment().FinalizeAttachment(gl,
|
|
|
|
|
LOCAL_GL_DEPTH_STENCIL_ATTACHMENT);
|
|
|
|
|
|
|
|
|
|
FinalizeDrawAndReadBuffers(gl, ColorAttachment(0).IsDefined());
|
2013-10-02 04:30:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
|
bool
|
|
|
|
|
WebGLFramebuffer::ValidateForRead(const char* info, TexInternalFormat* const out_format)
|
|
|
|
|
{
|
|
|
|
|
if (mReadBufferMode == LOCAL_GL_NONE) {
|
|
|
|
|
mContext->ErrorInvalidOperation("%s: Read buffer mode must not be"
|
|
|
|
|
" NONE.", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
const auto& attachment = GetAttachment(mReadBufferMode);
|
2015-02-19 03:57:05 +03:00
|
|
|
|
|
|
|
|
|
if (!CheckAndInitializeAttachments()) {
|
|
|
|
|
mContext->ErrorInvalidFramebufferOperation("readPixels: incomplete framebuffer");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLenum readPlaneBits = LOCAL_GL_COLOR_BUFFER_BIT;
|
|
|
|
|
if (!HasCompletePlanes(readPlaneBits)) {
|
|
|
|
|
mContext->ErrorInvalidOperation("readPixels: Read source attachment doesn't have the"
|
|
|
|
|
" correct color/depth/stencil type.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
if (!attachment.IsDefined()) {
|
2015-02-19 03:57:05 +03:00
|
|
|
|
mContext->ErrorInvalidOperation("readPixels: ");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 07:32:52 +03:00
|
|
|
|
*out_format = attachment.EffectiveInternalFormat();
|
2015-02-19 03:57:05 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-22 03:44:17 +04:00
|
|
|
|
inline void
|
2015-03-17 07:32:52 +03:00
|
|
|
|
ImplCycleCollectionUnlink(mozilla::WebGLFramebuffer::Attachment& field)
|
2013-06-22 03:44:17 +04:00
|
|
|
|
{
|
2015-03-17 07:32:52 +03:00
|
|
|
|
field.mTexturePtr = nullptr;
|
|
|
|
|
field.mRenderbufferPtr = nullptr;
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void
|
2014-11-14 07:03:50 +03:00
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mozilla::WebGLFramebuffer::Attachment& 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-17 07:32:52 +03:00
|
|
|
|
CycleCollectionNoteChild(callback, field.mTexturePtr.get(), name, flags);
|
|
|
|
|
CycleCollectionNoteChild(callback, field.mRenderbufferPtr.get(), name,
|
|
|
|
|
flags);
|
2013-06-22 03:44:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLFramebuffer,
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mColorAttachments,
|
2014-11-14 07:03:50 +03:00
|
|
|
|
mDepthAttachment,
|
|
|
|
|
mStencilAttachment,
|
2015-03-17 07:32:52 +03:00
|
|
|
|
mDepthStencilAttachment)
|
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
|