2012-12-09 15:58:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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/. */
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#ifndef WEBGL_FRAMEBUFFER_H_
|
|
|
|
#define WEBGL_FRAMEBUFFER_H_
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
#include "WebGLObjectModel.h"
|
2014-09-19 03:14:22 +04:00
|
|
|
#include "WebGLStrongTypes.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
#include "WebGLTexture.h"
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
class WebGLFramebuffer;
|
2012-12-09 15:58:41 +04:00
|
|
|
class WebGLRenderbuffer;
|
2014-11-14 07:03:50 +03:00
|
|
|
class WebGLTexture;
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
class WebGLFBAttachPoint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebGLFramebuffer* const mFB;
|
|
|
|
private:
|
|
|
|
WebGLRefPtr<WebGLTexture> mTexturePtr;
|
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
|
|
|
|
FBAttachment mAttachmentPoint;
|
|
|
|
TexImageTarget mTexImageTarget;
|
|
|
|
GLint mTexImageLevel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
WebGLFBAttachPoint(WebGLFramebuffer* fb, FBAttachment attachmentPoint);
|
|
|
|
~WebGLFBAttachPoint();
|
|
|
|
|
|
|
|
void Unlink() {
|
|
|
|
mRenderbufferPtr = nullptr;
|
|
|
|
mTexturePtr = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDefined() const;
|
|
|
|
bool IsDeleteRequested() const;
|
|
|
|
|
|
|
|
TexInternalFormat EffectiveInternalFormat() const;
|
|
|
|
|
|
|
|
bool HasAlpha() const;
|
|
|
|
bool IsReadableFloat() const;
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
SetRenderbuffer(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTexImage(WebGLTexture* tex, TexImageTarget target, GLint level);
|
|
|
|
void SetRenderbuffer(WebGLRenderbuffer* rb);
|
|
|
|
|
|
|
|
const WebGLTexture* Texture() const {
|
|
|
|
return mTexturePtr;
|
|
|
|
}
|
|
|
|
WebGLTexture* Texture() {
|
|
|
|
return mTexturePtr;
|
|
|
|
}
|
|
|
|
const WebGLRenderbuffer* Renderbuffer() const {
|
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
|
|
|
WebGLRenderbuffer* Renderbuffer() {
|
|
|
|
return mRenderbufferPtr;
|
|
|
|
}
|
|
|
|
TexImageTarget ImageTarget() const {
|
|
|
|
return mTexImageTarget;
|
|
|
|
}
|
|
|
|
GLint MipLevel() const {
|
|
|
|
return mTexImageLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasUninitializedImageData() const;
|
|
|
|
void SetImageDataStatus(WebGLImageDataStatus x);
|
|
|
|
|
|
|
|
const WebGLRectangleObject& RectangleObject() const;
|
|
|
|
|
|
|
|
bool HasImage() const;
|
|
|
|
bool IsComplete() const;
|
|
|
|
|
|
|
|
void FinalizeAttachment(gl::GLContext* gl,
|
|
|
|
FBAttachment attachmentLoc) const;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WebGLFramebuffer final
|
2013-08-29 19:39:17 +04:00
|
|
|
: public nsWrapperCache
|
2012-12-09 15:58:41 +04:00
|
|
|
, public WebGLRefCountedObject<WebGLFramebuffer>
|
|
|
|
, public LinkedListElement<WebGLFramebuffer>
|
|
|
|
, public WebGLContextBoundObject
|
2014-07-30 23:52:07 +04:00
|
|
|
, public SupportsWeakPtr<WebGLFramebuffer>
|
2012-12-09 15:58:41 +04:00
|
|
|
{
|
2015-05-21 02:50:28 +03:00
|
|
|
friend class WebGLContext;
|
|
|
|
|
2012-12-09 15:58:41 +04:00
|
|
|
public:
|
2015-04-24 19:43:01 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLFramebuffer)
|
2014-07-30 23:52:07 +04:00
|
|
|
|
2015-05-21 02:50:28 +03:00
|
|
|
const GLuint mGLName;
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
private:
|
|
|
|
mutable GLenum mStatus;
|
|
|
|
|
|
|
|
GLenum mReadBufferMode;
|
|
|
|
|
|
|
|
// No need to chase pointers for the oft-used color0.
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint mColorAttachment0;
|
|
|
|
WebGLFBAttachPoint mDepthAttachment;
|
|
|
|
WebGLFBAttachPoint mStencilAttachment;
|
|
|
|
WebGLFBAttachPoint mDepthStencilAttachment;
|
|
|
|
nsTArray<WebGLFBAttachPoint> mMoreColorAttachments;
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2015-05-21 02:50:28 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Bug 1140459: Some drivers (including our test slaves!) don't
|
|
|
|
// give reasonable answers for IsRenderbuffer, maybe others.
|
|
|
|
// This shows up on Android 2.3 emulator.
|
|
|
|
//
|
|
|
|
// So we track the `is a Framebuffer` state ourselves.
|
|
|
|
bool mIsFB;
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
public:
|
|
|
|
WebGLFramebuffer(WebGLContext* webgl, GLuint fbo);
|
|
|
|
|
|
|
|
private:
|
|
|
|
~WebGLFramebuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebGLRectangleObject& GetAnyRectObject() const;
|
|
|
|
|
|
|
|
public:
|
2012-12-09 15:58:41 +04:00
|
|
|
void Delete();
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void FramebufferRenderbuffer(FBAttachment attachment, RBTarget rbtarget,
|
|
|
|
WebGLRenderbuffer* rb);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-09-25 19:21:33 +04:00
|
|
|
void FramebufferTexture2D(FBAttachment attachment,
|
2014-11-14 07:03:50 +03:00
|
|
|
TexImageTarget texImageTarget, WebGLTexture* tex,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLint level);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
bool HasDefinedAttachments() const;
|
|
|
|
bool HasIncompleteAttachments() const;
|
|
|
|
bool AllImageRectsMatch() const;
|
2014-09-25 19:21:33 +04:00
|
|
|
FBStatus PrecheckFramebufferStatus() const;
|
|
|
|
FBStatus CheckFramebufferStatus() const;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
GLenum
|
2015-07-15 03:37:28 +03:00
|
|
|
GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
|
|
|
bool HasDepthStencilConflict() const {
|
|
|
|
return int(mDepthAttachment.IsDefined()) +
|
|
|
|
int(mStencilAttachment.IsDefined()) +
|
|
|
|
int(mDepthStencilAttachment.IsDefined()) >= 2;
|
|
|
|
}
|
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
size_t ColorAttachmentCount() const {
|
2015-03-25 02:00:28 +03:00
|
|
|
return 1 + mMoreColorAttachments.Length();
|
2013-10-02 04:30:05 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
const WebGLFBAttachPoint& ColorAttachment(size_t colorAttachmentId) const {
|
2015-03-25 02:00:28 +03:00
|
|
|
MOZ_ASSERT(colorAttachmentId < ColorAttachmentCount());
|
|
|
|
return colorAttachmentId ? mMoreColorAttachments[colorAttachmentId - 1]
|
|
|
|
: mColorAttachment0;
|
2012-12-09 15:58:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
const WebGLFBAttachPoint& DepthAttachment() const {
|
2012-12-09 15:58:41 +04:00
|
|
|
return mDepthAttachment;
|
|
|
|
}
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
const WebGLFBAttachPoint& StencilAttachment() const {
|
2012-12-09 15:58:41 +04:00
|
|
|
return mStencilAttachment;
|
|
|
|
}
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
const WebGLFBAttachPoint& DepthStencilAttachment() const {
|
2012-12-09 15:58:41 +04:00
|
|
|
return mDepthStencilAttachment;
|
|
|
|
}
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint& GetAttachPoint(FBAttachment attachPointEnum);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
void DetachTexture(const WebGLTexture* tex);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
void DetachRenderbuffer(const WebGLRenderbuffer* rb);
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
const WebGLRectangleObject& RectangleObject() const;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-01-23 07:59:34 +04:00
|
|
|
WebGLContext* GetParentObject() const {
|
2012-12-09 15:58:41 +04:00
|
|
|
return Context();
|
|
|
|
}
|
|
|
|
|
2013-10-02 04:30:05 +04:00
|
|
|
void FinalizeAttachments() const;
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-03-01 06:51:43 +04:00
|
|
|
// mask mirrors glClear.
|
|
|
|
bool HasCompletePlanes(GLbitfield mask);
|
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
bool CheckAndInitializeAttachments();
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool CheckColorAttachmentNumber(FBAttachment attachment,
|
|
|
|
const char* funcName) const;
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
void EnsureColorAttachPoints(size_t colorAttachmentId);
|
2015-03-17 04:03:40 +03:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
void InvalidateFramebufferStatus() const {
|
|
|
|
mStatus = 0;
|
2015-03-17 07:32:52 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
bool ValidateForRead(const char* info, TexInternalFormat* const out_format);
|
2012-12-09 15:58:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#endif // WEBGL_FRAMEBUFFER_H_
|