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
|
|
|
|
2016-07-22 09:25:41 +03:00
|
|
|
#include <vector>
|
|
|
|
|
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"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLRenderbuffer.h"
|
2016-07-22 09:25:41 +03:00
|
|
|
#include "WebGLStrongTypes.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLTexture.h"
|
2016-07-22 09:25:41 +03:00
|
|
|
#include "WebGLTypes.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;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
template<typename T>
|
|
|
|
class PlacementArray;
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
} // namespace gl
|
|
|
|
|
|
|
|
class WebGLFBAttachPoint final
|
2015-07-15 03:37:28 +03:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
friend class WebGLFramebuffer;
|
2015-07-15 03:37:28 +03:00
|
|
|
public:
|
|
|
|
WebGLFramebuffer* const mFB;
|
2015-11-25 07:15:29 +03:00
|
|
|
const GLenum mAttachmentPoint;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
2018-03-29 03:16:23 +03:00
|
|
|
private:
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLRefPtr<WebGLTexture> mTexturePtr;
|
|
|
|
WebGLRefPtr<WebGLRenderbuffer> mRenderbufferPtr;
|
|
|
|
TexImageTarget mTexImageTarget;
|
2015-07-03 04:55:43 +03:00
|
|
|
GLint mTexImageLayer;
|
2016-07-14 22:13:19 +03:00
|
|
|
uint32_t mTexImageLevel;
|
2015-07-15 03:37:28 +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
|
|
|
WebGLFBAttachPoint();
|
|
|
|
WebGLFBAttachPoint(WebGLFramebuffer* fb, GLenum attachmentPoint);
|
2018-03-29 03:16:23 +03:00
|
|
|
explicit WebGLFBAttachPoint(WebGLFBAttachPoint&) = default; // Make this private.
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
public:
|
|
|
|
~WebGLFBAttachPoint();
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void Unlink();
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
bool IsDefined() const;
|
|
|
|
bool IsDeleteRequested() const;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatUsageInfo* Format() const;
|
2016-02-13 06:31:58 +03:00
|
|
|
uint32_t Samples() const;
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
bool HasAlpha() const;
|
|
|
|
bool IsReadableFloat() const;
|
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
void Clear(const char* funcName);
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
void SetTexImage(const char* funcName, WebGLTexture* tex, TexImageTarget target,
|
|
|
|
GLint level, GLint layer = 0);
|
|
|
|
void SetRenderbuffer(const char* funcName, WebGLRenderbuffer* rb);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLTexture* Texture() const { return mTexturePtr; }
|
|
|
|
WebGLRenderbuffer* Renderbuffer() const { return mRenderbufferPtr; }
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
TexImageTarget ImageTarget() const {
|
|
|
|
return mTexImageTarget;
|
|
|
|
}
|
2015-07-03 04:55:43 +03:00
|
|
|
GLint Layer() const {
|
|
|
|
return mTexImageLayer;
|
|
|
|
}
|
2016-07-14 22:13:19 +03:00
|
|
|
uint32_t MipLevel() const {
|
2015-07-15 03:37:28 +03:00
|
|
|
return mTexImageLevel;
|
|
|
|
}
|
2015-12-15 03:11:59 +03:00
|
|
|
void AttachmentName(nsCString* out) const;
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
bool HasUninitializedImageData() const;
|
2016-07-19 10:36:54 +03:00
|
|
|
void SetImageDataStatus(WebGLImageDataStatus x) const;
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void Size(uint32_t* const out_width, uint32_t* const out_height) const;
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
bool HasImage() const;
|
2015-12-15 03:11:59 +03:00
|
|
|
bool IsComplete(WebGLContext* webgl, nsCString* const out_info) const;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-09-09 01:56:58 +03:00
|
|
|
void Resolve(gl::GLContext* gl) const;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
JS::Value 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-11-25 07:15:29 +03:00
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
void OnBackingStoreRespecified(const char* funcName) const;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-12-30 14:02:14 +03:00
|
|
|
bool IsEquivalentForFeedback(const WebGLFBAttachPoint& other) const {
|
|
|
|
if (!IsDefined() || !other.IsDefined())
|
|
|
|
return false;
|
2016-12-22 11:08:14 +03:00
|
|
|
|
|
|
|
#define _(X) X == other.X
|
|
|
|
return ( _(mRenderbufferPtr) &&
|
|
|
|
_(mTexturePtr) &&
|
|
|
|
_(mTexImageTarget.get()) &&
|
|
|
|
_(mTexImageLevel) &&
|
|
|
|
_(mTexImageLayer) );
|
|
|
|
#undef _
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
struct Ordered {
|
|
|
|
const WebGLFBAttachPoint& mRef;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-09-02 03:51:08 +03:00
|
|
|
explicit Ordered(const WebGLFBAttachPoint& ref)
|
2016-07-19 10:36:54 +03:00
|
|
|
: mRef(ref)
|
|
|
|
{ }
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool operator<(const Ordered& other) const {
|
|
|
|
MOZ_ASSERT(mRef.IsDefined() && other.mRef.IsDefined());
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#define ORDER_BY(X) if (X != other.X) return X < other.X;
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
ORDER_BY(mRef.mRenderbufferPtr)
|
|
|
|
ORDER_BY(mRef.mTexturePtr)
|
|
|
|
ORDER_BY(mRef.mTexImageTarget.get())
|
|
|
|
ORDER_BY(mRef.mTexImageLevel)
|
|
|
|
ORDER_BY(mRef.mTexImageLayer)
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#undef ORDER_BY
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2015-07-15 03:37:28 +03:00
|
|
|
};
|
|
|
|
|
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>
|
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;
|
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
private:
|
|
|
|
uint64_t mNumFBStatusInvals;
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
protected:
|
|
|
|
#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
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLFBAttachPoint mDepthAttachment;
|
|
|
|
WebGLFBAttachPoint mStencilAttachment;
|
|
|
|
WebGLFBAttachPoint mDepthStencilAttachment;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
// In theory, this number can be unbounded based on the driver. However, no driver
|
|
|
|
// appears to expose more than 8. We might as well stop there too, for now.
|
|
|
|
// (http://opengl.gpuinfo.org/gl_stats_caps_single.php?listreportsbycap=GL_MAX_COLOR_ATTACHMENTS)
|
|
|
|
static const size_t kMaxColorAttachments = 8; // jgilbert's MacBook Pro exposes 8.
|
|
|
|
WebGLFBAttachPoint mColorAttachments[kMaxColorAttachments];
|
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
|
|
|
std::vector<const WebGLFBAttachPoint*> mColorDrawBuffers; // Non-null
|
|
|
|
const WebGLFBAttachPoint* mColorReadBuffer; // Null if NONE
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-03-25 02:00:28 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
struct ResolvedData {
|
|
|
|
// IsFeedback
|
|
|
|
std::vector<const WebGLFBAttachPoint*> texDrawBuffers; // Non-null
|
|
|
|
std::set<WebGLFBAttachPoint::Ordered> drawSet;
|
|
|
|
std::set<WebGLFBAttachPoint::Ordered> readSet;
|
|
|
|
|
2016-09-02 03:51:08 +03:00
|
|
|
explicit ResolvedData(const WebGLFramebuffer& parent);
|
2016-07-19 10:36:54 +03:00
|
|
|
};
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
mutable UniquePtr<const ResolvedData> mResolvedCompleteData;
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
////
|
2015-05-21 02:50:28 +03:00
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
public:
|
2016-07-19 10:36:54 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLFramebuffer)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLFramebuffer)
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
WebGLFramebuffer(WebGLContext* webgl, GLuint fbo);
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLContext* GetParentObject() const { return mContext; }
|
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
|
|
|
|
|
2015-03-25 02:00:28 +03:00
|
|
|
private:
|
|
|
|
~WebGLFramebuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2012-12-09 15:58:41 +04:00
|
|
|
void Delete();
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-07-03 04:55:43 +03:00
|
|
|
|
2017-06-23 00:45:11 +03:00
|
|
|
bool HasDuplicateAttachments() const;
|
2014-01-23 07:59:34 +04:00
|
|
|
bool HasDefinedAttachments() const;
|
2015-12-15 03:11:59 +03:00
|
|
|
bool HasIncompleteAttachments(nsCString* const out_info) const;
|
2014-01-23 07:59:34 +04:00
|
|
|
bool AllImageRectsMatch() const;
|
2016-02-13 06:31:58 +03:00
|
|
|
bool AllImageSamplesMatch() const;
|
2015-12-15 03:11:59 +03:00
|
|
|
FBStatus PrecheckFramebufferStatus(nsCString* const out_info) const;
|
2016-07-14 22:13:19 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
protected:
|
2016-07-19 10:36:54 +03:00
|
|
|
Maybe<WebGLFBAttachPoint*> GetAttachPoint(GLenum attachment); // Fallible
|
|
|
|
Maybe<WebGLFBAttachPoint*> GetColorAttachPoint(GLenum attachment); // Fallible
|
2016-09-09 01:56:58 +03:00
|
|
|
void ResolveAttachments() const;
|
|
|
|
void RefreshDrawBuffers() const;
|
|
|
|
void RefreshReadBuffer() const;
|
2016-07-19 10:36:54 +03:00
|
|
|
bool ResolveAttachmentData(const char* funcName) const;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
public:
|
2017-01-12 04:10:48 +03:00
|
|
|
void DetachTexture(const char* funcName, const WebGLTexture* tex);
|
|
|
|
void DetachRenderbuffer(const char* funcName, const WebGLRenderbuffer* rb);
|
2017-12-19 05:30:56 +03:00
|
|
|
bool ValidateAndInitAttachments(const char* funcName) const;
|
2016-12-22 13:22:12 +03:00
|
|
|
bool ValidateClearBufferType(const char* funcName, GLenum buffer, uint32_t drawBuffer,
|
|
|
|
GLenum funcType) const;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
bool ValidateForColorRead(const char* funcName,
|
|
|
|
const webgl::FormatUsageInfo** out_format,
|
|
|
|
uint32_t* out_width, uint32_t* out_height) const;
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////
|
|
|
|
// Getters
|
2013-10-02 04:30:05 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#define GETTER(X) const decltype(m##X)& X() const { return m##X; }
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
GETTER(DepthAttachment)
|
|
|
|
GETTER(StencilAttachment)
|
|
|
|
GETTER(DepthStencilAttachment)
|
|
|
|
GETTER(ColorDrawBuffers)
|
|
|
|
GETTER(ColorReadBuffer)
|
|
|
|
GETTER(ResolvedCompleteData)
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
#undef GETTER
|
|
|
|
|
2018-03-27 06:21:31 +03:00
|
|
|
const auto& ColorAttachment0() const {
|
|
|
|
return mColorAttachments[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& AnyDepthAttachment() const {
|
|
|
|
if (mDepthStencilAttachment.IsDefined())
|
|
|
|
return mDepthStencilAttachment;
|
|
|
|
return mDepthAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& AnyStencilAttachment() const {
|
|
|
|
if (mDepthStencilAttachment.IsDefined())
|
|
|
|
return mDepthStencilAttachment;
|
|
|
|
return mStencilAttachment;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////////////////
|
|
|
|
// Invalidation
|
2012-12-09 15:58:41 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
bool IsResolvedComplete() const { return bool(mResolvedCompleteData); }
|
2017-01-12 04:10:48 +03:00
|
|
|
void InvalidateFramebufferStatus(const char* funcName);
|
2016-09-09 01:56:58 +03:00
|
|
|
void RefreshResolvedData();
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
////////////////
|
|
|
|
// WebGL funcs
|
|
|
|
|
2017-12-21 03:47:17 +03:00
|
|
|
bool IsCheckFramebufferStatusComplete(const char* const funcName) const {
|
|
|
|
return CheckFramebufferStatus(funcName) == LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
FBStatus CheckFramebufferStatus(const char* funcName) const;
|
2016-07-19 10:36:54 +03:00
|
|
|
void FramebufferRenderbuffer(const char* funcName, GLenum attachment, GLenum rbtarget,
|
|
|
|
WebGLRenderbuffer* rb);
|
|
|
|
void FramebufferTexture2D(const char* funcName, GLenum attachment,
|
|
|
|
GLenum texImageTarget, WebGLTexture* tex, GLint level);
|
|
|
|
void FramebufferTextureLayer(const char* funcName, GLenum attachment,
|
|
|
|
WebGLTexture* tex, GLint level, GLint layer);
|
|
|
|
void DrawBuffers(const char* funcName, const dom::Sequence<GLenum>& buffers);
|
|
|
|
void ReadBuffer(const char* funcName, GLenum attachPoint);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
JS::Value GetAttachmentParameter(const char* funcName, JSContext* cx, GLenum target,
|
|
|
|
GLenum attachment, GLenum pname,
|
|
|
|
ErrorResult* const out_error);
|
2016-07-19 10:36:54 +03:00
|
|
|
|
|
|
|
static void BlitFramebuffer(WebGLContext* webgl,
|
2017-12-19 05:30:56 +03:00
|
|
|
GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
|
|
|
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
2016-07-19 10:36:54 +03:00
|
|
|
GLbitfield mask, GLenum filter);
|
2012-12-09 15:58:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#endif // WEBGL_FRAMEBUFFER_H_
|